Skip to content
Snippets Groups Projects
Commit 39f40fda authored by David Hendriks's avatar David Hendriks
Browse files

moved some files, updated tutorial

parent 216cc2e6
No related branches found
No related tags found
No related merge requests found
Showing with 67 additions and 26 deletions
...@@ -3,47 +3,44 @@ ...@@ -3,47 +3,44 @@
## prerequisites/documents/scripts: ## prerequisites/documents/scripts:
* This doc * This doc
* nbody6++\_manual.pdf * nbody6++\_manual.pdf
* nbody6++ itself: * nbody6++ itself: todo
* readout script: * readout scripts: todo
* config generator script: `python_scripts_for_nbody6/nbody6_config_generator.py` * Mcluster
* python, pip, a virtualenvironment and having the content of requirements.txt installed
## Tutorial ## Tutorial
### Set up config ### General
We will go through the configuration file, and what all the variables mean, but they are also described in nbody6++\_manual.pdf. We will go through the configuration file, and what all the variables mean, but they are also described in nbody6++\_manual.pdf.
The formatting for the config file is very plain, but I have created a script to generate the config files called `python_scripts_for_nbody6/nbody6_config_generator.py` The formatting for the config file is very plain, but we utilise a handy software package called mcluster (@Mcluster) to generate initial settings for nbody6++ simulations. It accepts command line arguments to construct these config files, which saves us a headache in arranging the numbers correctly. We will use a script made by David that does some extra things for you. The usage is explained below (@custom script and usage). After the configuration has been generated, we can start an nbody6 simulation with this configuration. The steps are explained bellow (@feeding config to nbody6))
Better idea: the software package `mcluster` does this job for us. it will generate a file that nbody6 can read in, plus some initialisation summaries.
With the `-h` option you can see the variables that can be customized, and in the `McLusterManual.pdf` most of the options are explained.
# Official #### Mcluster
To run mcluster: To run mcluster:
``` ```
./vol/ph/astro/dhendriks/mcluster/mcluster [OPTIONS] ./vol/ph/astro/dhendriks/mcluster/mcluster [OPTIONS]
``` ```
It will generate (at least) 2 files, one of which should be used as an input for nbody6 It will generate (at least) 2 files, one of which should be used as an input for nbody6
With `mcluster -h` you can see the options that are customizable.
# Custom script and usage: #### Custom script and usage:
To generate a set up: To generate a set up:
* Run `mcluster_script.sh <name of setup>` in the directory you want nbody6 to store your data. * Run `<path to mclusterscript dir>/mcluster_script.sh <name of setup>` in the directory you want nbody6 to store your data.
* run `<path to nbody6> < <name of setup>.input
* Optionally, you can do the following command: `screen -S <session name>' and then run '<path to nbody6> < <name of setup>.input` (type `man screen` for some explanation, or look it up on google)
* Let the code run.
You want to run the above command in the directory you want the data of nbody6 to be outputted.
#### feeding config to nbody6
IMPORTANT: execute the below commands in a directory designed to store the output. Nbody6++ automatically outputs the files to the directory it has been called from.
### To run the code: To run a simulation we must pass the config file to the executable of nbody6++. Like this:
To run a simulation we must pass the config file to the executable of nbody6++. `<path to nbody6> < <name of setup>.input`
```
./vol/ph/astro_code/dhendriks/nbody6 < "full path to configuration file."
```
An example would be:
`/vol/ph/astro_code/dhendriks/nbody6 < /vol/ph/astro_code/dhendriks/work_dir/nbody6/default.input`
Based on the input configuration this file will run until it gets terminated (by the code or by you). Based on the input configuration this file will run until it gets terminated (by the code or by you).
### Reading out the data: Optionally, you can do the following command: `screen -S <session name>' and then run '<path to nbody6> < <name of setup>.input` (type `man screen` for some explanation, or look it up on google)
As Nbody6 outputs the data as fortran binaries, we first need to
Now, the code runs, and you should leave it alone (or detach the terminal) until it is done.
### Reading out the data:
Nbody6 outputs in a couple of data formats: ascii/plain text, binary, and optionally hdf5. We have configured it to output the main file to hdf5, so that we dont have to manually read out the binaries. Some other files are plaintext so we can access them quite easily. We created 2 example scripts: `python_scripts_for_nbody6/hdf5_readout_nbody6pp_example.py` for reading out hdf5 files, and `python_scripts_for_nbody6/ascii_readout_nbody6pp_example.py` for reading out normal files with pandas.
\ No newline at end of file
...@@ -8,17 +8,19 @@ import pandas as pd ...@@ -8,17 +8,19 @@ import pandas as pd
# Point to the source directory. # Point to the source directory.
source_dir = '/vol/ph/astro_code/dhendriks/work_dir/nbody6' source_dir = '/vol/ph/astro_code/dhendriks/work_dir/nbody6'
filename = 'sev.83_0'
# Create the header line labels and data line labels # Create the header line labels and data line labels
header_line_labels = ['NS', 'TIME[Myr]'] header_line_labels = ['NS', 'TIME[Myr]']
N_LABEL = ['TIME[NB]', 'I', 'NAME', 'K*', 'RI[RC]', 'M[M*]', 'Log10(L[L*])', 'LOG10(RS[R*])' , 'LOG10(Teff[K]'] N_LABEL = ['TIME[NB]', 'I', 'NAME', 'K*', 'RI[RC]', 'M[M*]', 'Log10(L[L*])', 'LOG10(RS[R*])' , 'LOG10(Teff[K]']
# Go through file # Go through file
with open(os.path.join(source_dir, 'sev.83_0'), 'r') as f: with open(os.path.join(source_dir, filename), 'r') as f:
header_1_data = f.readline().split() header_1_data = f.readline().split()
data = [] data = []
for line in f: for line in f:
data.append(line.split()) data.append(line.split())
df = pd.DataFrame(data, columns=N_LABEL) df = pd.DataFrame(data, columns=N_LABEL)
\ No newline at end of file
import h5py
def hdf_recursive(hdf_obj, prefix=''):
for key in list(hdf_obj.keys()):
item = hdf_obj[key]
path = '{}/{}'.format(prefix, key)
if isinstance(item, h5py.Dataset):
yield (path, item)
elif isinstance(item, h5py.Group):
yield from hdf_recursive(item, path)
\ No newline at end of file
import h5py
import os
from extra_functions import *
source_dir = '/vol/ph/astro_code/dhendriks/work_dir/nbody6'
filename = 'snap.40_0.h5part'
f = h5py.File(os.path.join(source_dir, filename), 'r')
# For a tree view of the file
for (path, dset) in hdf_recursive(f):
print(path, dset)
# # List all groups
print("Keys: %s" % f.keys())
a_group_key = list(f.keys())[0]
# Get the data of e.g. step 0
data_step0 = list(f['Step#0'])
print(data_step0)
# get the data of e.g. binaries in step 0
data_step0_binaries = list(f['Step#0']['Binaries'])
print(data_step0_binaries)
# get the data of e.g. the eccentricity of binaries in step 0
data_step0_binaries_ecc = list(f['Step#0']['Binaries']['ECC'])
print(data_step0_binaries_ecc)
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment