Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
global.h
1
4#ifndef GLOBAL_H
5#define GLOBAL_H
6
7#include <string>
8
9#include "../grid/grid_enum.h" // defines NSCALARS
10#include "cholla_config.h"
11
12#ifdef PARTICLES
13 #include <cstdint>
14#endif // PARTICLES
15
16#if PRECISION == 1
17 #ifndef TYPEDEF_DEFINED_REAL
18typedef float Real;
19 #endif
20#endif
21#if PRECISION == 2
22 #ifndef TYPEDEF_DEFINED_REAL
23typedef double Real;
24 #endif
25#endif
26
27#define MAXLEN 2048
28#define TINY_NUMBER 1.0e-20
29#define MP 1.672622e-24 // mass of proton, grams
30#define KB 1.380658e-16 // boltzmann constant, cgs
31// #define GN 6.67259e-8 // gravitational constant, cgs
32#define GN 4.49451e-18 // gravitational constant, kpc^3 / M_sun / kyr^2
33#define C_L 0.306594593 // speed of light in kpc/kyr
34
35#define MYR 31.536e12 // Myears in secs
36#define KPC 3.086e16 // kpc in km
37#define G_COSMO 4.300927161e-06; // gravitational constant, kpc km^2 s^-2 Msun^-1
38#define MSUN_CGS 1.98847e33; // Msun in gr
39#define KPC_CGS 3.086e21; // kpc in cm
40#define KM_CGS 1e5; // km in cm
41#define MH 1.67262171e-24 // Mass of hydrogen [g]
42
43#define TIME_UNIT 3.15569e10 // 1 kyr in s
44#define LENGTH_UNIT 3.08567758e21 // 1 kpc in cm
45#define MASS_UNIT 1.98847e33 // 1 solar mass in grams
46#define DENSITY_UNIT (MASS_UNIT / (LENGTH_UNIT * LENGTH_UNIT * LENGTH_UNIT))
47#define FORCE_UNIT (MASS_UNIT * LENGTH_UNIT / TIME_UNIT / TIME_UNIT)
48#define VELOCITY_UNIT (LENGTH_UNIT / TIME_UNIT)
49#define ENERGY_UNIT (DENSITY_UNIT * VELOCITY_UNIT * VELOCITY_UNIT)
50#define PRESSURE_UNIT (DENSITY_UNIT * VELOCITY_UNIT * VELOCITY_UNIT)
51#define SP_ENERGY_UNIT (VELOCITY_UNIT * VELOCITY_UNIT)
52#define MAGNETIC_FIELD_UNIT (sqrt(MASS_UNIT / LENGTH_UNIT) / TIME_UNIT)
53
54#define LOG_FILE_NAME "run_output.log"
55
56// mean molecular weight
57#define MU 0.6
58// Parameters for Enzo dual Energy Condition
59// - Prior to GH PR #356, DE_ETA_1 nominally had a value of 0.001 in all
60// simulations (in practice, the value of DE_ETA_1 had minimal significance
61// in those simulations). In PR #356, we revised the internal-energy
62// synchronization to account for the value of DE_ETA_1. This was necessary
63// for non-cosmology simulations.
64// - In Cosmological simulation, we set DE_ETA_1 to a large number (it doesn't
65// really matter what, as long as its >=1) to maintain the older behavior
66// - In the future, we run tests and revisit the choice of DE_ETA_1 in
67// cosmological simulations
68#ifdef COSMOLOGY
69 #define DE_ETA_1 10.0
70#else
71 #define DE_ETA_1 \
72 0.001 // Ratio of U to E for which Internal Energy is used to compute the
73 // Pressure. This also affects when the Internal Energy is used for
74 // the update.
75#endif
76
77#define DE_ETA_2 \
78 0.035 // Ratio of U to max(E_local) used to select which Internal Energy is
79 // used for the update.
80
81// Maximum time step for cosmological simulations
82#define MAX_DELTA_A 0.001
83#define MAX_EXPANSION_RATE 0.01 // Limit delta(a)/a
84
85#ifdef MHD
86 #define N_MHD_FIELDS 3
87#else
88 #define N_MHD_FIELDS 0
89#endif // MHD
90
91// Inital Chemistry fractions
92#define INITIAL_FRACTION_HI 0.75984603480
93#define INITIAL_FRACTION_HII 1.53965115054e-4
94#define INITIAL_FRACTION_HEI 0.24000000008
95#define INITIAL_FRACTION_HEII 9.59999999903e-15
96#define INITIAL_FRACTION_HEIII 9.59999999903e-18
97#define INITIAL_FRACTION_ELECTRON 1.53965115054e-4
98#define INITIAL_FRACTION_METAL 1.00000000000e-10
99
100// Default Particles Compiler Flags
101#define PARTICLES_LONG_INTS
102#define PARTICLES_KDK
103
104#ifdef GRAVITY
105 #ifdef GRAVITY_5_POINTS_GRADIENT
106 #ifdef PARTICLES
107 #define N_GHOST_POTENTIAL \
108 3 // 3 ghost cells are needed for 5 point gradient, ( one is for the
109 // CIC interpolation of the potential )
110 #else
111 #define N_GHOST_POTENTIAL 2 // 2 ghost cells are needed for 5 point gradient
112 #endif // PARTICLES
113
114 #else
115 #ifdef PARTICLES
116 #define N_GHOST_POTENTIAL \
117 2 // 2 ghost cells are needed for 3 point gradient, ( one is for the
118 // CIC interpolation of the potential )
119 #else
120 #define N_GHOST_POTENTIAL 1 // 1 ghost cells are needed for 3 point gradient
121 #endif // PARTICLES
122 #endif // GRAVITY_5_POINTS_GRADIENT
123
124typedef long int grav_int_t;
125#endif
126
127#ifdef PARTICLES_LONG_INTS
128typedef long int part_int_t;
129#else
130typedef int part_int_t;
131#endif // PARTICLES_LONG_INTS
132
133#include <vector>
134typedef std::vector<Real> real_vector_t;
135typedef std::vector<part_int_t> int_vector_t;
136
137#ifdef PARTICLES
138 #ifdef MPI_CHOLLA
139// Constants for the inital size of the buffers for particles transfer
140// and the number of data transferred for each particle
141extern int N_PARTICLES_TRANSFER;
142extern int N_DATA_PER_PARTICLE_TRANSFER;
143 #endif // MPI_CHOLLA
144
145 #ifdef AVERAGE_SLOW_CELLS
146 #define SLOW_FACTOR 10
147 #endif // AVERAGE_SLOW_CELLS
148
149#endif // PARTICLES
150
151#define SIGN(a) (((a) < 0.) ? -1. : 1.)
152
153/* Global variables */
154extern Real gama; // Ratio of specific heats
155extern Real C_cfl; // CFL number (0 - 0.5)
156extern Real t_comm;
157extern Real t_other;
158
159extern float *cooling_table;
160extern float *heating_table;
161
164extern void Set_Gammas(Real gamma_in);
165
168extern double Get_Time(void);
169
172extern int Sgn(Real x);
173
174/* Global variables for mpi (but they are also initialized to sensible defaults when not using mpi)
175 *
176 * It may make sense to move these back into mpi_routines (but reorganizing the ifdef statements
177 * would take some work). It may make sense to also put these into their own namespace.
178 */
179extern int procID; /*process rank*/
180extern int nproc; /*number of processes executing simulation*/
181extern int root; /*rank of root process*/
182
183/* Used when MPI_CHOLLA is not defined to initialize a subset of the global mpi-related variables
184 * that still meaningful in non-mpi simulations.
185 */
186void Init_Global_Parallel_Vars_No_MPI();
187
188// forward-declare ParameterMap (it's primarily used to construct Parameters)
189class ParameterMap;
190
224 explicit Parameters(ParameterMap &pmap);
225
226 // List the parameters
227 int nx;
228 int ny;
229 int nz;
230 double tout;
231 double outstep;
232 int n_steps_output;
233 Real gamma;
234 char init[MAXLEN];
235 int nfile;
236 // At the moment, the following flag is only meaningful when GRAVITY and GRAVITY_ANALYTIC_COMP
237 // are defined. In other cases, we force this to initialize to a sensible value
238 bool gas_only_use_static_grav;
239 bool output_always = false;
240 int n_steps_limit = -1; // Note that negative values indicate that there is no limit
241#ifdef STATIC_GRAV
242 int custom_grav = 0; // flag to set specific static gravity field
243#endif
244 Real xmin;
245 Real ymin;
246 Real zmin;
247 Real xlen;
248 Real ylen;
249 Real zlen;
250 int xl_bcnd;
251 int xu_bcnd;
252 int yl_bcnd;
253 int yu_bcnd;
254 int zl_bcnd;
255 int zu_bcnd;
256#ifdef MPI_CHOLLA
257 int xlg_bcnd;
258 int xug_bcnd;
259 int ylg_bcnd;
260 int yug_bcnd;
261 int zlg_bcnd;
262 int zug_bcnd;
263#endif /*MPI_CHOLLA*/
264 char custom_bcnd[MAXLEN];
265 char indir[MAXLEN]; // Folder to load Initial conditions from
266 Real rho;
267 Real vx;
268 Real vy;
269 Real vz;
270 Real P;
271 Real A;
272 Real Bx;
273 Real By;
274 Real Bz;
275 Real rho_l;
276 Real vx_l;
277 Real vy_l;
278 Real vz_l;
279 Real P_l;
280 Real Bx_l;
281 Real By_l;
282 Real Bz_l;
283 Real rho_r;
284 Real vx_r;
285 Real vy_r;
286 Real vz_r;
287 Real P_r;
288 Real Bx_r;
289 Real By_r;
290 Real Bz_r;
291 Real diaph;
292 Real rEigenVec_rho;
293 Real rEigenVec_MomentumX;
294 Real rEigenVec_MomentumY;
295 Real rEigenVec_MomentumZ;
296 Real rEigenVec_E;
297 Real rEigenVec_Bx;
298 Real rEigenVec_By;
299 Real rEigenVec_Bz;
300 Real pitch;
301 Real yaw;
302 Real polarization;
303 Real radius;
304 Real P_blast;
305 Real wave_length;
306#ifdef PARTICLES
307 // The random seed for particle simulations. With the default of 0 then a
308 // machine dependent seed will be generated.
309 std::uint_fast64_t prng_seed = 0;
310#endif // PARTICLES
311#ifdef COSMOLOGY
312 Real H0;
313 Real Omega_M;
314 Real Omega_L;
315 Real Omega_b;
316 Real Omega_R;
317 Real w0;
318 Real wa;
319 Real Init_redshift;
320 Real End_redshift;
321
322 std::string wDE_file; // File with equation of state as function of redshift
323
324 // File for the scale_factor output values for cosmological simulations
325 char scale_outputs_file[MAXLEN];
326 #define EXPANSION_HISTORY_FILE_NAME "expansion_history.txt"
327#endif // COSMOLOGY
328#ifdef TILED_INITIAL_CONDITIONS
329 Real tile_length;
330#endif // TILED_INITIAL_CONDITIONS
331
332 // Set the MPI Processes grid [n_proc_x, n_proc_y, n_proc_z] (if they aren't provided, they are set to 0)
333 int n_proc_x;
334 int n_proc_y;
335 int n_proc_z;
336
337 int bc_potential_type;
338#if defined(COOLING_GRACKLE) || defined(CHEMISTRY_GPU)
339 char UVB_rates_file[MAXLEN]; // File for the UVB photoheating and
340 // photoionization rates of HI, HeI and HeII
341#endif
342 Real temperature_floor = 0;
343 Real density_floor = 0;
344 Real scalar_floor = 0;
345#ifdef ANALYSIS
346 char analysis_scale_outputs_file[MAXLEN]; // File for the scale_factor output
347 // values for cosmological
348 // simulations {{}}
349 char analysisdir[MAXLEN];
350 int lya_skewers_stride;
351 Real lya_Pk_d_log_k;
352 #ifdef OUTPUT_SKEWERS
353 char skewersdir[MAXLEN];
354 #endif
355#endif
356#ifdef SCALAR
357 #ifdef DUST
358 Real grain_radius;
359 #endif
360#endif
361};
362
364void Warn_Unused_Params(ParameterMap &pmap);
365
369extern int Is_Param_Valid(const char *name);
370
371#endif // GLOBAL_H
A class that provides map-like access to parameter files.
Definition ParameterMap.h:74
Definition global.h:217