create.py 2.62 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
""" @package examples/cosmo_box_gravity_only_3d/create.py
Code that creates 3d cosmologiacl box ICs;
some ICs provided, but can be created also at startup if 
ic_creation is set to 'music' or 'ngenic'.

created by Rainer Weinberger, last modified 25.02.2019
"""


""" load libraries """
import sys    # needed for exit codes
import numpy as np    # scientific computing package
import h5py    # hdf5 format
import os  # operating system interface
from subprocess import call # execute bash commands

## create new ics with 'music' or 'ngenic' or just 'copy' existing ones to the run directory
ic_creation='copy'


""" input """
simulation_directory = str(sys.argv[1])
Rainer Weinberger's avatar
Rainer Weinberger committed
23
print("create.py " + simulation_directory)
24
25
26
27
28


""" initial conditions: either copy or create with code """
if ic_creation == 'copy':
    ## copy and use provided initial conditions
Rainer Weinberger's avatar
Rainer Weinberger committed
29
    call(['cp', simulation_directory+'/L50n32/ics', simulation_directory+'/ics'])
30
31
32
33
34
35
36
37
38
39
40
41
42
    
elif ic_creation == 'music':
    ## create new initial conditions with the MUSIC code
    status = call(['hg', 'clone', 'https://bitbucket.org/ohahn/music', simulation_directory+'/music'])
    if status != 0:
        print('CREATE: ERROR: hg clone failed!')
        sys.exit(status)
    cwd = os.getcwd()
    os.chdir(simulation_directory+'/music/')
    status = call(['make'])
    if status != 0:
        print('CREATE: ERROR: make failed!')
        sys.exit(status)
Rainer Weinberger's avatar
Rainer Weinberger committed
43
    status = call(['./MUSIC',cwd+'/param_music.txt'])
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    if status != 0:
        print('CREATE: ERROR: execution failed!')
        sys.exit(status)
    os.chdir(cwd)
    
elif ic_creation == 'ngenic':
    ## create new initial conditions with the N-GenIC code
    status = call(['git', 'clone', 'https://gitlab.mpcdf.mpg.de/ext-c2c74fbfcdff/ngenic.git', simulation_directory+'/ngenic'])
    if status != 0:
        print('CREATE: ERROR: git clone failed!')
        sys.exit(status)
    cwd = os.getcwd()
    os.chdir(simulation_directory+'/ngenic/')
    status = call(['make'])
    if status != 0:
        print('CREATE: ERROR: make failed!')
        sys.exit(status)
Rainer Weinberger's avatar
Rainer Weinberger committed
61
    status = call(['mpiexec','-np','1','./N-GenIC',cwd+'/param_ngenic.txt'])
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    if status != 0:
        print('CREATE: ERROR: execution failed!')
        sys.exit(status)
    os.chdir(cwd)
else:
    print("CREATE: ERROR: no valid option for ic creation! choose 'copy', 'music' or 'ngenic'")
    exit(1)


""" set output times z=1,0"""
outputTimes = np.array([0.5, 1], dtype=np.float64)
ones = np.ones(outputTimes.shape, dtype=np.int)


""" write output list file """
data = np.array([outputTimes, ones]).T
np.savetxt(simulation_directory+"/output_list.txt",data, fmt="%g %1.f" )


""" normal exit """
sys.exit(0)