MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
params.c
Go to the documentation of this file.
1 #include <math.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <mpi.h>
7 #include <libgenic/allvars.h>
8 #include <libgenic/proto.h>
9 #include <libgadget/physconst.h>
10 #include <libgadget/utils.h>
11 
12 static ParameterSet *
14 {
16 
17  param_declare_string(ps, "FileWithInputSpectrum", REQUIRED, 0, "File containing input power spectrum, from CLASS or CAMB.");
18  param_declare_string(ps, "OutputDir", REQUIRED, 0, "Output directory in which to store the ICs");
19  param_declare_string(ps, "FileBase", REQUIRED, 0, "File name of the ICs.");
20 
21  param_declare_double(ps, "Omega0", REQUIRED, 0.2814, "Total matter density, cdm + baryons + massive neutrinos at z=0.");
22  param_declare_double(ps, "OmegaBaryon", REQUIRED, 0.0464, "Omega Baryon: note this may be used for transfer functions even if gas is not produced.");
23  param_declare_double(ps, "OmegaLambda", REQUIRED, 0.7186, "Dark energy density at z=0");
24  param_declare_double(ps, "HubbleParam", REQUIRED, 0.697, "Hubble parameter");
25  param_declare_int(ps, "ProduceGas", REQUIRED, 0, "Should we create baryon particles?");
26  param_declare_double(ps, "BoxSize", REQUIRED, 0, "Size of box in internal units.");
27  param_declare_double(ps, "Redshift", REQUIRED, 99, "Starting redshift");
28  param_declare_int(ps, "Nmesh", OPTIONAL, 0, "Size of the FFT grid used to estimate displacements. Should be > Ngrid.");
29  param_declare_int(ps, "Ngrid", REQUIRED, 0, "Size of regular grid on which the undisplaced CDM particles are created.");
30  param_declare_int(ps, "NgridGas", OPTIONAL, -1, "Size of regular grid on which the undisplaced gas particles are created.");
31  param_declare_int(ps, "NgridNu", OPTIONAL, 0, "Number of neutrino particles created for hybrid neutrinos.");
32  param_declare_int(ps, "Seed", REQUIRED, 0, "Random number generator seed used for the phases of the Gaussian random field.");
33  param_declare_int(ps, "MakeGlassGas", OPTIONAL, -1, "Generate Glass IC for gas instead of Grid IC.");
34  param_declare_int(ps, "MakeGlassCDM", OPTIONAL, 0, "Generate Glass IC for CDM instead of Grid IC.");
35 
36  param_declare_int(ps, "UnitaryAmplitude", OPTIONAL, 1, "If 0, each Fourier mode in the initial power spectrum is scattered. If 1 each Fourier mode is not scattered and we generate unitary gaussians for the initial phases.");
37  param_declare_int(ps, "WhichSpectrum", OPTIONAL, 2, "Type of spectrum, 2 for file ");
38  param_declare_double(ps, "Omega_fld", OPTIONAL, 0, "Energy density of dark energy fluid.");
39  param_declare_double(ps, "w0_fld", OPTIONAL, -1., "Dark energy equation of state");
40  param_declare_double(ps, "wa_fld", OPTIONAL, 0, "Dark energy evolution parameter");
41  param_declare_double(ps, "Omega_ur", OPTIONAL, 0, "Extra radiation density, eg, a sterile neutrino");
42  param_declare_double(ps, "MNue", OPTIONAL, 0, "First neutrino mass in eV.");
43  param_declare_double(ps, "MNum", OPTIONAL, 0, "Second neutrino mass in eV.");
44  param_declare_double(ps, "MNut", OPTIONAL, 0, "Third neutrino mass in eV.");
45  param_declare_double(ps, "MWDM_therm", OPTIONAL, 0, "Assign a thermal velocity to the DM. Specifies WDM particle mass in keV.");
46  param_declare_double(ps, "Max_nuvel", OPTIONAL, 5000, "Maximum neutrino velocity sampled from the F-D distribution.");
47 
48  param_declare_int(ps, "DifferentTransferFunctions", OPTIONAL, 1, "Use species specific transfer functions for baryon and CDM.");
49  param_declare_int(ps, "ScaleDepVelocity", OPTIONAL, -1, "Use scale dependent velocity transfer functions instead of the scale-independent Zel'dovich approximation. Enabled by default iff DifferentTransferFunctions = 1");
50  param_declare_string(ps, "FileWithTransferFunction", OPTIONAL, "", "File containing CLASS formatted transfer functions with extra metric transfer functions=y.");
51  param_declare_double(ps, "MaxMemSizePerNode", OPTIONAL, 0.6, "Maximum memory per node, in fraction of total memory, or MB if > 1.");
52  param_declare_double(ps, "CMBTemperature", OPTIONAL, 2.7255, "CMB temperature in K");
53  param_declare_double(ps, "RadiationOn", OPTIONAL, 1, "Include radiation in the background.");
54  param_declare_int(ps, "UsePeculiarVelocity", OPTIONAL, 1, "Snapshots will save peculiar velocities to the Velocity field. If 0, then v/sqrt(a) will be used in the ICs to match Gadget-2, but snapshots will save v * a.");
55  param_declare_int(ps, "SavePrePos", OPTIONAL, 1, "Save the pre-displacement positions in the snapshot.");
56  param_declare_int(ps, "InvertPhase", OPTIONAL, 0, "Flip phase for paired simulation");
57  param_declare_int(ps, "PrePosGridCenter", OPTIONAL, 0, "Set pre-displacement positions at the center of the grid");
58  param_declare_int(ps, "ShowBacktrace", OPTIONAL, 1, "Print a backtrace on crash. Hangs on stampede.");
59 
60  param_declare_double(ps, "PrimordialAmp", OPTIONAL, 2.215e-9, "Ignored, but used by external CLASS script to set powr spectrum amplitude.");
61  param_declare_double(ps, "Sigma8", OPTIONAL, -1, "Renormalise Sigma8 to this number if positive");
62  param_declare_double(ps, "InputPowerRedshift", OPTIONAL, -1, "Redshift at which the input power is. Power spectrum will be rescaled to the initial redshift. Negative disables rescaling.");
63  param_declare_double(ps, "PrimordialIndex", OPTIONAL, 0.971, "Tilting power, ignored for tabulated input.");
64  param_declare_double(ps, "PrimordialRunning", OPTIONAL, 0, "Running of the spectral index, ignored for tabulated input, only used to pass parameter to tools/make_class_power.py");
65 
66  param_declare_double(ps, "UnitVelocity_in_cm_per_s", OPTIONAL, 1e5, "Velocity unit in cm/sec. Default is 1 km/s");
67  param_declare_double(ps, "UnitLength_in_cm", OPTIONAL, CM_PER_MPC/1000, "Length unit in cm. Default is 1 kpc");
68  param_declare_double(ps, "UnitMass_in_g", OPTIONAL, 1.989e43, "Mass unit in g. Default is 10^10 M_sun.");
69 
70  param_declare_int(ps, "NumPartPerFile", OPTIONAL, 1024 * 1024 * 128, "Number of particles per striped bigfile. Internal implementation detail.");
71  param_declare_int(ps, "NumWriters", OPTIONAL, 0, "Number of processors allowed to write at one time.");
72  return ps;
73 }
74 
75 void read_parameterfile(char *fname, struct genic_config * GenicConfig, int * ShowBacktrace, double * MaxMemSizePerNode, Cosmology * CP)
76 {
77 
78  /* read parameter file on all processes for simplicty */
80  int ThisTask;
81 
82  if(0 != param_parse_file(ps, fname)) {
83  endrun(0, "Parsing %s failed. \n", fname);
84  }
85  if(0 != param_validate(ps)) {
86  endrun(0, "Validation of %s failed.\n", fname);
87  }
88 
89  message(0, "----------- Running with Parameters ----------\n");
90 
91  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
92  if(ThisTask == 0)
93  param_dump(ps, stdout);
94 
95  message(0, "----------------------------------------------\n");
96 
97  /*Cosmology*/
98  CP->Omega0 = param_get_double(ps, "Omega0");
99  CP->OmegaLambda = param_get_double(ps, "OmegaLambda");
100  CP->OmegaBaryon = param_get_double(ps, "OmegaBaryon");
101  CP->HubbleParam = param_get_double(ps, "HubbleParam");
102  CP->Omega_fld = param_get_double(ps, "Omega_fld");
103  CP->w0_fld = param_get_double(ps,"w0_fld");
104  CP->wa_fld = param_get_double(ps,"wa_fld");
105  CP->Omega_ur = param_get_double(ps, "Omega_ur");
106  if(CP->OmegaLambda > 0 && CP->Omega_fld > 0)
107  endrun(0, "Cannot have OmegaLambda and Omega_fld (evolving dark energy) at the same time!\n");
108  CP->CMBTemperature = param_get_double(ps, "CMBTemperature");
109  CP->RadiationOn = param_get_double(ps, "RadiationOn");
110  CP->MNu[0] = param_get_double(ps, "MNue");
111  CP->MNu[1] = param_get_double(ps, "MNum");
112  CP->MNu[2] = param_get_double(ps, "MNut");
113  GenicConfig->WDM_therm_mass = param_get_double(ps, "MWDM_therm");
114  *MaxMemSizePerNode = param_get_double(ps, "MaxMemSizePerNode");
115  if(*MaxMemSizePerNode <= 1) {
116  (*MaxMemSizePerNode) *= get_physmem_bytes() / (1024 * 1024);
117  }
118 
119  GenicConfig->ProduceGas = param_get_int(ps, "ProduceGas");
120  GenicConfig->InvertPhase = param_get_int(ps, "InvertPhase");
121  /*Unit system*/
122  GenicConfig->units.UnitVelocity_in_cm_per_s = param_get_double(ps, "UnitVelocity_in_cm_per_s");
123  GenicConfig->units.UnitLength_in_cm = param_get_double(ps, "UnitLength_in_cm");
124  GenicConfig->units.UnitMass_in_g = param_get_double(ps, "UnitMass_in_g");
125 
126 
127  *ShowBacktrace = param_get_int(ps, "ShowBacktrace");
128 
129  double Redshift = param_get_double(ps, "Redshift");
130 
131  /*Parameters of the power spectrum*/
132  GenicConfig->PowerP.InputPowerRedshift = param_get_double(ps, "InputPowerRedshift");
133  if(GenicConfig->PowerP.InputPowerRedshift < 0)
134  GenicConfig->PowerP.InputPowerRedshift = Redshift;
135  GenicConfig->PowerP.Sigma8 = param_get_double(ps, "Sigma8");
136  /*Always specify Sigm8 at z=0*/
137  if(GenicConfig->PowerP.Sigma8 > 0)
138  GenicConfig->PowerP.InputPowerRedshift = 0;
139  GenicConfig->PowerP.FileWithInputSpectrum = param_get_string(ps, "FileWithInputSpectrum");
140  GenicConfig->PowerP.FileWithTransferFunction = param_get_string(ps, "FileWithTransferFunction");
141  GenicConfig->PowerP.DifferentTransferFunctions = param_get_int(ps, "DifferentTransferFunctions");
142  GenicConfig->PowerP.ScaleDepVelocity = param_get_int(ps, "ScaleDepVelocity");
143  /* By default ScaleDepVelocity follows DifferentTransferFunctions.*/
144  if(GenicConfig->PowerP.ScaleDepVelocity < 0) {
145  GenicConfig->PowerP.ScaleDepVelocity = GenicConfig->PowerP.DifferentTransferFunctions;
146  }
147  GenicConfig->PowerP.WhichSpectrum = param_get_int(ps, "WhichSpectrum");
148  GenicConfig->PowerP.PrimordialIndex = param_get_double(ps, "PrimordialIndex");
149  GenicConfig->PowerP.PrimordialRunning = param_get_double(ps, "PrimordialRunning");
150 
151  /*Simulation parameters*/
152  GenicConfig->UsePeculiarVelocity = param_get_int(ps, "UsePeculiarVelocity");
153  GenicConfig->SavePrePos = param_get_int(ps, "SavePrePos");
154  GenicConfig->PrePosGridCenter = param_get_int(ps, "PrePosGridCenter");
155  GenicConfig->BoxSize = param_get_double(ps, "BoxSize");
156  GenicConfig->Nmesh = param_get_int(ps, "Nmesh");
157  GenicConfig->Ngrid = param_get_int(ps, "Ngrid");
158  GenicConfig->NgridGas = param_get_int(ps, "NgridGas");
159  if(GenicConfig->NgridGas < 0)
160  GenicConfig->NgridGas = GenicConfig->Ngrid;
161  if(!GenicConfig->ProduceGas)
162  GenicConfig->NgridGas = 0;
163  /*Enable 'hybrid' neutrinos*/
164  GenicConfig->NGridNu = param_get_int(ps, "NgridNu");
165  /* Convert physical km/s at z=0 in an unperturbed universe to
166  * internal gadget (comoving) velocity units at starting redshift.*/
167  GenicConfig->Max_nuvel = param_get_double(ps, "Max_nuvel") * pow(1+Redshift, 1.5) * (GenicConfig->units.UnitVelocity_in_cm_per_s/1e5);
168  GenicConfig->Seed = param_get_int(ps, "Seed");
169  GenicConfig->UnitaryAmplitude = param_get_int(ps, "UnitaryAmplitude");
170  param_get_string2(ps, "OutputDir", GenicConfig->OutputDir, sizeof(GenicConfig->OutputDir));
171  param_get_string2(ps, "FileBase", GenicConfig->InitCondFile, sizeof(GenicConfig->InitCondFile));
172  GenicConfig->MakeGlassGas = param_get_int(ps, "MakeGlassGas");
173  /* We want to use a baryon glass by default if we have different transfer functions,
174  * since that is the way we reproduce the linear growth. Otherwise use a grid by default.*/
175  if(GenicConfig->MakeGlassGas < 0) {
176  if(GenicConfig->PowerP.DifferentTransferFunctions)
177  GenicConfig->MakeGlassGas = 1;
178  else
179  GenicConfig->MakeGlassGas = 0;
180  }
181  GenicConfig->MakeGlassCDM = param_get_int(ps, "MakeGlassCDM");
182 
183  int64_t NumPartPerFile = param_get_int(ps, "NumPartPerFile");
184 
185  int64_t Ngrid = GenicConfig->Ngrid;
186  if(Ngrid < GenicConfig->NgridGas)
187  Ngrid = GenicConfig->NgridGas;
188  GenicConfig->NumFiles = ( Ngrid*Ngrid*Ngrid + NumPartPerFile - 1) / NumPartPerFile;
189  GenicConfig->NumWriters = param_get_int(ps, "NumWriters");
190  if(GenicConfig->PowerP.DifferentTransferFunctions && GenicConfig->PowerP.InputPowerRedshift != Redshift
191  && (GenicConfig->ProduceGas || CP->MNu[0] + CP->MNu[1] + CP->MNu[2]))
192  message(0, "WARNING: Using different transfer functions but also rescaling power to account for linear growth. NOT what you want!\n");
193  if((CP->MNu[0] + CP->MNu[1] + CP->MNu[2] > 0) || GenicConfig->PowerP.DifferentTransferFunctions || GenicConfig->PowerP.ScaleDepVelocity)
194  if(0 == strlen(GenicConfig->PowerP.FileWithTransferFunction))
195  endrun(0,"For massive neutrinos, different transfer functions, or scale dependent growth functions you must specify a transfer function file\n");
196  if(!CP->RadiationOn && (CP->MNu[0] + CP->MNu[1] + CP->MNu[2] > 0))
197  endrun(0,"You want massive neutrinos but no background radiation: this will give an inconsistent cosmology.\n");
198 
199  if(GenicConfig->Nmesh == 0) {
200  GenicConfig->Nmesh = 2*Ngrid;
201  }
202  /*Set some units*/
203  GenicConfig->TimeIC = 1 / (1 + Redshift);
204  double UnitTime_in_s = GenicConfig->units.UnitLength_in_cm / GenicConfig->units.UnitVelocity_in_cm_per_s;
205 
206  CP->Hubble = HUBBLE * UnitTime_in_s;
207 }
void message(int where, const char *fmt,...)
Definition: endrun.c:175
static int ShowBacktrace
Definition: endrun.c:100
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
static ParameterSet * create_parameters(void)
Definition: params.c:13
void read_parameterfile(char *fname, struct genic_config *GenicConfig, int *ShowBacktrace, double *MaxMemSizePerNode, Cosmology *CP)
Definition: params.c:75
double param_get_double(ParameterSet *ps, const char *name)
Definition: paramset.c:336
void param_get_string2(ParameterSet *ps, const char *name, char *dst, size_t len)
Definition: paramset.c:355
void param_declare_double(ParameterSet *ps, const char *name, const enum ParameterFlag required, const double defvalue, const char *help)
Definition: paramset.c:278
void param_declare_int(ParameterSet *ps, const char *name, const enum ParameterFlag required, const int defvalue, const char *help)
Definition: paramset.c:267
int param_parse_file(ParameterSet *ps, const char *filename)
Definition: paramset.c:234
int param_get_int(ParameterSet *ps, const char *name)
Definition: paramset.c:368
void param_declare_string(ParameterSet *ps, const char *name, const enum ParameterFlag required, const char *defvalue, const char *help)
Definition: paramset.c:289
void param_dump(ParameterSet *ps, FILE *stream)
Definition: paramset.c:192
char * param_get_string(ParameterSet *ps, const char *name)
Definition: paramset.c:346
int param_validate(ParameterSet *ps)
Definition: paramset.c:177
ParameterSet * parameter_set_new()
Definition: paramset.c:472
@ OPTIONAL
Definition: paramset.h:8
@ REQUIRED
Definition: paramset.h:7
#define CM_PER_MPC
Definition: physconst.h:20
#define HUBBLE
Definition: physconst.h:25
static Cosmology * CP
Definition: power.c:27
double wa_fld
Definition: cosmology.h:17
double Omega_ur
Definition: cosmology.h:18
double Omega_fld
Definition: cosmology.h:15
double Omega0
Definition: cosmology.h:10
int RadiationOn
Definition: cosmology.h:23
double HubbleParam
Definition: cosmology.h:20
double CMBTemperature
Definition: cosmology.h:9
double OmegaLambda
Definition: cosmology.h:14
double OmegaBaryon
Definition: cosmology.h:19
double MNu[3]
Definition: cosmology.h:25
double Hubble
Definition: cosmology.h:21
double w0_fld
Definition: cosmology.h:16
double UnitMass_in_g
Definition: unitsystem.h:8
double UnitLength_in_cm
Definition: unitsystem.h:10
double UnitVelocity_in_cm_per_s
Definition: unitsystem.h:9
int MakeGlassGas
Definition: allvars.h:28
double Max_nuvel
Definition: allvars.h:26
double BoxSize
Definition: allvars.h:20
int NGridNu
Definition: allvars.h:18
char OutputDir[100]
Definition: allvars.h:36
int Ngrid
Definition: allvars.h:18
int UnitaryAmplitude
Definition: allvars.h:23
struct UnitSystem units
Definition: allvars.h:35
int PrePosGridCenter
Definition: allvars.h:25
int ProduceGas
Definition: allvars.h:21
int MakeGlassCDM
Definition: allvars.h:29
int Nmesh
Definition: allvars.h:19
int SavePrePos
Definition: allvars.h:33
struct power_params PowerP
Definition: allvars.h:34
char InitCondFile[100]
Definition: allvars.h:37
int NgridGas
Definition: allvars.h:18
int Seed
Definition: allvars.h:22
double WDM_therm_mass
Definition: allvars.h:27
int InvertPhase
Definition: allvars.h:24
int UsePeculiarVelocity
Definition: allvars.h:39
int NumFiles
Definition: allvars.h:30
double TimeIC
Definition: allvars.h:38
int NumWriters
Definition: allvars.h:31
int ScaleDepVelocity
Definition: power.h:11
char * FileWithTransferFunction
Definition: power.h:12
int DifferentTransferFunctions
Definition: power.h:10
double PrimordialIndex
Definition: power.h:16
int WhichSpectrum
Definition: power.h:9
double Sigma8
Definition: power.h:14
char * FileWithInputSpectrum
Definition: power.h:13
double InputPowerRedshift
Definition: power.h:15
double PrimordialRunning
Definition: power.h:17
double get_physmem_bytes(void)
Definition: system.c:467
int ThisTask
Definition: test_exchange.c:23