changa 3.5
Loading...
Searching...
No Matches
cooling_grackle.h
1#ifndef COOLING_GRACKLE_HINCLUDED
2#define COOLING_GRACKLE_HINCLUDED
3
4/* Global consts */
5
6#include "param.h"
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <sys/param.h> /* for MAXPATHLEN */
13#ifndef MAXPATHLEN
14#define MAXPATHLEN 256
15#endif
16
17// double for variables -- must be consistent with GRACKLE compile
18#define CONFIG_BFLOAT_8
19
20#include "grackle.h"
21
22// Default to tabular only version unless compiled in. Max sensible value for this is 3
23#ifndef GRACKLE_PRIMORDIAL_CHEMISTRY_MAX
24#define GRACKLE_PRIMORDIAL_CHEMISTRY_MAX 1
25#endif
26
27#define CL_NMAXBYTETABLE 56000
28
29typedef struct CoolingParametersStruct {
30 int bDoIonOutput;
31
32// Note many more possible parameters: see chemistry_data.h
33// Note some are probably reset by internal code
34 int grackle_verbose; // verbose flag
35 int use_grackle; // = 1; // chemistry on
36 int with_radiative_cooling; // = 1; // cooling on
37 int primordial_chemistry; // = 3; // molecular network with H, He, D
38 int metal_cooling; // = 1; // metal cooling on
39 int UVbackground; // = 1; // UV background on
40 int cmb_temperature_floor; // default 1
41 int bBrokenGrackleFloor; // Use external CMB floor
42 // assuming Grackle's CMB
43 // floor is broken.
44
45 int bComoving; // part of units
47 char grackle_data_file[MAXPATHLEN]; // "../../input/CloudyData_UVB=HM2012.h5"; // data file
48} COOLPARAM;
49
50
51typedef struct CoolingParticleStruct {
52#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX<1)
53 float dummy;
54#endif
55#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
56 gr_float HI, HII, HeI, HeII, HeIII, e;
57#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
58 gr_float HM, H2I, H2II;
59#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
60 gr_float DI, DII, HDI
61#endif
62#endif
63#endif
64} COOLPARTICLE;
65
66/* Heating Cooling Context */
67
68typedef struct CoolingPKDStruct {
69// not official grackle stuff
70 double dTime;
71 double dSecUnit;
72 double dKpcUnit;
73 double dComovingGmPerCcUnit;
74 double dErgPerGmUnit;
75 double diErgPerGmUnit;
76 double dErgPerGmPerSecUnit;
77// Grackle data
78 char grackle_data_file[MAXPATHLEN]; // "../../input/CloudyData_UVB=HM2012.h5"; // data file
79 chemistry_data *pgrackle_data; // defined in chemistry_data.h, points at global grackle_data
80 code_units my_units; // defined in code_units.h
81 int bFixTempFloor; /* Set CMB temperature floor outside of Grackle */
82#if defined(COOLDEBUG)
83 MDL mdl; /* For diag/debug outputs */
84 struct particle *p; /* particle pointer NEVER TO BE USED EXCEPT FOR DEBUG */
85#endif
86} COOL;
87
88typedef struct clDerivsDataStruct clDerivsData;
89
90struct clDerivsDataStruct {
91 COOL *cl;
92};
93
94COOL *CoolInit( );
95void CoolFinalize( COOL *cl );
96clDerivsData *CoolDerivsInit(COOL *cl);
97void CoolDerivsFinalize(clDerivsData *cld ) ;
98
99void clInitConstants( COOL *cl, double dGMPerCcunit, double dComovingGmPerCcUnit,
100 double dErgPerGmUnit, double dSecUnit, double dKpcUnit, COOLPARAM CoolParam);
101void CoolInitRatesTable( COOL *cl, COOLPARAM CoolParam);
102
103void CoolAddParams( COOLPARAM *CoolParam, PRM );
104void CoolLogParams( COOLPARAM *CoolParam, FILE *fp );
105void CoolOutputArray( COOLPARAM *CoolParam, int, int *, char * );
106
107// GRACKLE_PRIMORDIAL_CHEMISTRY_MAX >=1
108#define COOL_ARRAY0_EXT "HI"
109double COOL_ARRAY0(COOL *cl, COOLPARTICLE *cp, double ZMetal);
110void COOL_SET_ARRAY0(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
111
112#define COOL_ARRAY1_EXT "HII"
113double COOL_ARRAY1(COOL *cl, COOLPARTICLE *cp, double ZMetal);
114void COOL_SET_ARRAY1(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
115
116#define COOL_ARRAY2_EXT "HeI"
117double COOL_ARRAY2(COOL *cl, COOLPARTICLE *cp, double ZMetal);
118void COOL_SET_ARRAY2(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
119
120#define COOL_ARRAY3_EXT "HeII"
121double COOL_ARRAY3(COOL *cl, COOLPARTICLE *cp, double ZMetal);
122void COOL_SET_ARRAY3(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
123#define COOL_SET_ARRAY3( cl_, cp, aa, bb_val ) (assert(0))
124
125#define COOL_ARRAY4_EXT "HeIII"
126double COOL_ARRAY4(COOL *cl, COOLPARTICLE *cp, double ZMetal);
127void COOL_IN_ARRAY4(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
128#define COOL_IN_ARRAY4(w,x,y,z)
129
130#define COOL_ARRAY5_EXT "e"
131double COOL_ARRAY5(COOL *cl, COOLPARTICLE *cp, double ZMetal);
132void COOL_IN_ARRAY5(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
133#define COOL_IN_ARRAY5(w,x,y,z)
134
135// GRACKLE_PRIMORDIAL_CHEMISTRY_MAX >=2
136#define COOL_ARRAY6_EXT "HM"
137double COOL_ARRAY6(COOL *cl, COOLPARTICLE *cp, double ZMetal);
138void COOL_IN_ARRAY6(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
139#define COOL_IN_ARRAY6(w,x,y,z)
140
141#define COOL_ARRAY7_EXT "H2I"
142double COOL_ARRAY7(COOL *cl, COOLPARTICLE *cp, double ZMetal);
143void COOL_IN_ARRAY7(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
144#define COOL_IN_ARRAY7(w,x,y,z)
145
146#define COOL_ARRAY8_EXT "H2II"
147double COOL_ARRAY8(COOL *cl, COOLPARTICLE *cp, double ZMetal);
148void COOL_IN_ARRAY8(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
149#define COOL_IN_ARRAY8(w,x,y,z)
150
151// GRACKLE_PRIMORDIAL_CHEMISTRY_MAX >=3
152#define COOL_ARRAY9_EXT "DI"
153double COOL_ARRAY9(COOL *cl, COOLPARTICLE *cp, double ZMetal);
154void COOL_IN_ARRAY9(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
155#define COOL_IN_ARRAY9(w,x,y,z)
156
157#define COOL_ARRAY10_EXT "DII"
158double COOL_ARRAY10(COOL *cl, COOLPARTICLE *cp, double ZMetal);
159void COOL_IN_ARRAY10(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
160#define COOL_IN_ARRAY10(w,x,y,z)
161
162#define COOL_ARRAY11_EXT "HDI"
163double COOL_ARRAY11(COOL *cl, COOLPARTICLE *cp, double ZMetal);
164void COOL_IN_ARRAY11(COOL *cl, COOLPARTICLE *cp, double ZMetal, double Data);
165#define COOL_IN_ARRAY11(w,x,y,z)
166
167#define COOL_ARRAY12_EXT "dummy"
168#define COOL_ARRAY12(x,y,z) 0
169#define COOL_IN_ARRAY12(w,x,y,z)
170
171#define COOL_ARRAY13_EXT "dummy"
172#define COOL_ARRAY13(x,y,z) 0
173#define COOL_IN_ARRAY13(w,x,y,z)
174
175#define COOL_ARRAY14_EXT "dummy"
176#define COOL_ARRAY14(x,y,z) 0
177#define COOL_IN_ARRAY14(w,x,y,z)
178
179#define COOL_ARRAY15_EXT "dummy"
180#define COOL_ARRAY15(x,y,z) 0
181#define COOL_IN_ARRAY15(w,x,y,z)
182
183double COOL_EDOT( COOL *cl_, COOLPARTICLE *cp_, double ECode_, double rhoCode_, double ZMetal_, double *posCode_ );
184#define COOL_EDOT( cl_, cp_, ECode_, rhoCode_, ZMetal_, posCode_) (CoolCodeWorkToErgPerGmPerSec( cl_, CoolEdotInstantCode( cl_, cp_, ECode_, rhoCode_, ZMetal_, posCode_ )))
185
186double COOL_COOLING( COOL *cl_, COOLPARTICLE *cp_, double ECode_, double rhoCode_, double ZMetal_, double *posCode_ );
187#define COOL_COOLING( cl_, cp_, ECode_, rhoCode_, ZMetal_, posCode_) (CoolCodeWorkToErgPerGmPerSec( cl_, CoolCoolingCode( cl_, cp_, ECode_, rhoCode_, ZMetal_, posCode_ )))
188
189double COOL_HEATING( COOL *cl_, COOLPARTICLE *cp_, double ECode_, double rhoCode_, double ZMetal_, double *posCode_ );
190#define COOL_HEATING( cl_, cp_, ECode_, rhoCode_, ZMetal_, posCode_) (CoolCodeWorkToErgPerGmPerSec( cl_, CoolHeatingCode( cl_, cp_, ECode_, rhoCode_, ZMetal_, posCode_ )))
191
192//void CoolPARTICLEtoPERBARYON(COOL *cl_, PERBARYON *Y, COOLPARTICLE *cp, double ZMetal);
193//void CoolPERBARYONtoPARTICLE(COOL *cl_, PERBARYON *Y, COOLPARTICLE *cp, double ZMetal);
194
195double CoolEnergyToTemperature( COOL *Cool, COOLPARTICLE *cp, double E, double, double ZMetal);
196double CoolCodeEnergyToTemperature( COOL *Cool, COOLPARTICLE *cp, double E,
197 double rho, double ZMetal);
198
199/* Note: nod to cosmology (z parameter) unavoidable unless we want to access cosmo.[ch] from here */
200void CoolSetTime( COOL *Cool, double dTime, double z );
201
202double CoolCodeTimeToSeconds( COOL *Cool, double dCodeTime );
203
204#define CoolCodeTimeToSeconds( Cool, dCodeTime ) ((Cool)->dSecUnit*(dCodeTime))
205
206double CoolSecondsToCodeTime( COOL *Cool, double dTime );
207
208#define CoolSecondsToCodeTime( Cool, dTime ) ((dTime)/(Cool)->dSecUnit)
209
210double CoolCodeEnergyToErgPerGm( COOL *Cool, double dCodeEnergy );
211
212#define CoolCodeEnergyToErgPerGm( Cool, dCodeEnergy ) ((Cool)->dErgPerGmUnit*(dCodeEnergy))
213
214double CoolErgPerGmToCodeEnergy( COOL *Cool, double dEnergy );
215
216#define CoolErgPerGmToCodeEnergy( Cool, dEnergy ) ((Cool)->diErgPerGmUnit*(dEnergy))
217
218double CoolCodeWorkToErgPerGmPerSec( COOL *Cool, double dCodeWork );
219
220#define CoolCodeWorkToErgPerGmPerSec( Cool, dCodeWork ) ((Cool)->dErgPerGmPerSecUnit*(dCodeWork))
221
222double CoolErgPerGmPerSecToCodeWork( COOL *Cool, double dWork );
223
224#define CoolErgPerGmPerSecToCodeWork( Cool, dWork ) ((dWork)/(Cool)->dErgPerGmPerSecUnit)
225
226double CodeDensityToComovingGmPerCc( COOL *Cool, double dCodeDensity );
227
228#define CodeDensityToComovingGmPerCc( Cool, dCodeDensity ) ((Cool)->dComovingGmPerCcUnit*(dCodeDensity))
229
230void CoolIntegrateEnergy(COOL *cl, clDerivsData *cData, COOLPARTICLE *cp, double *E,
231 double ExternalHeating, double rho, double ZMetal, double *rp, double tStep );
232
233void CoolIntegrateEnergyCode(COOL *cl, clDerivsData *cData, COOLPARTICLE *cp, double *E,
234 double ExternalHeating, double rho, double ZMetal, double *r, double tStep );
235
236void CoolDefaultParticleData( COOLPARTICLE *cp );
237
238void CoolInitEnergyAndParticleData( COOL *cl, COOLPARTICLE *cp, double *E, double dDensity, double dTemp, double ZMetal);
239
240/* Deprecated */
241double CoolHeatingRate( COOL *cl, COOLPARTICLE *cp, double E, double dDensity, double ZMetal, double rkpc);
242
243double CoolEdotInstantCode(COOL *cl, COOLPARTICLE *cp, double ECode,
244 double rhoCode, double ZMetal, double *posCode );
245double CoolCoolingCode(COOL *cl, COOLPARTICLE *cp, double ECode,
246 double rhoCode, double ZMetal, double *posCode );
247double CoolHeatingCode(COOL *cl, COOLPARTICLE *cp, double ECode,
248 double rhoCode, double ZMetal, double *posCode );
249
250void CoolCodePressureOnDensitySoundSpeed( COOL *cl, COOLPARTICLE *cp, double uPred, double fDensity, double gamma, double gammam1, double *PoverRho, double *c );
251
252/* Note: gamma should be 5/3 for this to be consistent! */
253#define CoolCodePressureOnDensitySoundSpeed( cl__, cp__, uPred__, fDensity__, gamma__, gammam1__, PoverRho__, c__ ) { \
254 *(PoverRho__) = ((5./3.-1)*(uPred__)); \
255 *(c__) = sqrt((5./3.)*(*(PoverRho__))); }
256
257/*
258double CoolCodePressureOnDensity( COOL *cl, COOLPARTICLE *cp, double uPred, double fDensity, double gammam1 );
259
260#define CoolCodePressureOnDensity( cl, cp, uPred, fDensity, gammam1 ) ((gammam1)*(uPred))
261*/
262
263void CoolTableReadInfo( COOLPARAM *CoolParam, int cntTable, int *nTableColumns, char *suffix );
264
265void CoolTableRead( COOL *Cool, int nData, void *vData);
266
267#ifdef __cplusplus
268}
269#endif
270#endif
Heating/Cooling context: parameters and tables.
Definition cooling_boley.h:83
Input parameters for cooling.
Definition cooling_boley.h:56
double dSolarMetalFractionByMass
Assumed value of solar metallicity.
Definition cooling_grackle.h:46
per-particle cooling data
Definition cooling_boley.h:68
context for calculating cooling derivatives
Definition cooling_boley.h:108
COOL * cl
pointer to cooling context
Definition cooling_boley.h:110