forked from N-BodyShop/changa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cooling_grackle.c
765 lines (678 loc) · 25.3 KB
/
cooling_grackle.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
#ifndef NOCOOLING
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <assert.h>
/*
* Cooling code originally written by James Wadsley, McMaster
* University for GASOLINE.
*/
/* Usage/Interfaces:
Functions starting with
Cool are public: intended to be used by outside callers
cl are private: only intended for using by cooling routine itself
* The COOL class will contain data which is constant across
* all processors, and will be contained in a Charm++ NodeGroup.
* The clDerivsData structure will contain data that changes from
* particle to particle. This includes both particle data and the
* Integrator context. The integrator context has to be per Treepiece
* because each will be separately integrating a particle producing
* separate intermediate data.
*/
#include "cooling.h"
#define mh 1.67262171e-24
#define kboltz 1.3806504e-16
COOL *CoolInit( )
{
COOL *cl;
cl = (COOL *) malloc(sizeof(COOL));
assert(cl!=NULL);
#ifdef CONFIG_BFLOAT_8
assert(sizeof(gr_float)==8);
#else
#ifdef CONFIG_BFLOAT_4
assert(sizeof(gr_float)==4);
#else
fprintf(stderr,"Cooling Grackle: gr_float type not defined\n");
assert(0);
#endif
#endif
cl->pgrackle_data = &grackle_data;
return cl;
}
/**
* Per thread initialization of cooling
* @param cl Initialized COOL structure.
*/
clDerivsData *CoolDerivsInit(COOL *cl)
{
clDerivsData *Data;
double dEMin;
assert(cl != NULL);
Data = malloc(sizeof(clDerivsData));
assert(Data != NULL);
return Data;
}
void CoolFinalize(COOL *cl )
{
free(cl);
}
/**
* Deallocate memory for per-thread data.
*/
void CoolDerivsFinalize(clDerivsData *clData)
{
free(clData);
}
void clInitConstants( COOL *cl, double dGmPerCcUnit, double dComovingGmPerCcUnit,
double dErgPerGmUnit, double dSecUnit, double dKpcUnit, COOLPARAM CoolParam)
{
assert(cl!=NULL);
grackle_verbose = CoolParam.grackle_verbose;
cl->my_units.comoving_coordinates = CoolParam.bComoving; // 1 if cosmological sim, 0 if not
cl->my_units.density_units = dGmPerCcUnit;
cl->my_units.length_units = dKpcUnit*3.0857e21; // cm
cl->my_units.time_units = dSecUnit;
cl->my_units.velocity_units = cl->my_units.length_units / cl->my_units.time_units;
cl->my_units.a_units = 1.0; // units for the expansion factor
/* Erg per Gm unit is calculated as velocity units^2 */
cl->dErgPerGmUnit = dErgPerGmUnit; // too useful not to keep
cl->diErgPerGmUnit = 1/dErgPerGmUnit;
cl->dSecUnit = dSecUnit;
cl->dComovingGmPerCcUnit = dComovingGmPerCcUnit;
cl->dErgPerGmPerSecUnit = dErgPerGmUnit/dSecUnit;
// Second, create a chemistry object for parameters and rate data.
if (set_default_chemistry_parameters() == 0) {
fprintf(stderr, "Grackle Error in set_default_chemistry_parameters.\n");
assert(0);
}
cl->pgrackle_data->use_grackle = CoolParam.use_grackle; // chemistry on
cl->pgrackle_data->with_radiative_cooling = CoolParam.with_radiative_cooling; // cooling on
cl->pgrackle_data->primordial_chemistry = CoolParam.primordial_chemistry; // 0-3 molecular network with H, He, D
if (CoolParam.primordial_chemistry > GRACKLE_PRIMORDIAL_CHEMISTRY_MAX) {
fprintf(stderr,"Must compile so that GRACKLE_PRIMORDIAL_CHEMISTRY_MAX >= primordial_chemistry parameter used\n");
assert(GRACKLE_PRIMORDIAL_CHEMISTRY_MAX >= CoolParam.primordial_chemistry);
};
cl->pgrackle_data->metal_cooling = CoolParam.metal_cooling; // metal cooling on
cl->pgrackle_data->UVbackground = CoolParam.UVbackground; // UV background on
strncpy( cl->grackle_data_file, CoolParam.grackle_data_file, MAXPATHLEN ); // Permanent local copy
cl->pgrackle_data->grackle_data_file = cl->grackle_data_file; // hdf5 cloudy data file (pointer to permanent copy)
{
double initial_redshift = 0.;
double a_value = 1. / (1. + initial_redshift);
// Finally, initialize the chemistry object.
if (initialize_chemistry_data(&cl->my_units, a_value) == 0) {
fprintf(stderr, "Grackle Error in initialize_chemistry_data.\n");
assert(0);
}
}
}
/*Returns baryonic fraction for a given species*/
double COOL_ARRAY0(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
if(cl->pgrackle_data->primordial_chemistry > 0)
return (cp->HI);
else
#endif
return 0;
}
double COOL_ARRAY1(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
if(cl->pgrackle_data->primordial_chemistry > 0)
return (cp->HII);
else
#endif
return 0;
}
double COOL_ARRAY2(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
if(cl->pgrackle_data->primordial_chemistry > 0)
return (cp->HeI);
else
#endif
return 0;
}
double COOL_ARRAY3(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
if(cl->pgrackle_data->primordial_chemistry > 0)
return (cp->HeII);
else
#endif
return 0;
}
double COOL_ARRAY4(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
if(cl->pgrackle_data->primordial_chemistry > 0)
return (cp->HeIII);
else
#endif
return 0;
}
double COOL_ARRAY5(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
if(cl->pgrackle_data->primordial_chemistry > 0)
return (cp->e);
else
#endif
return 0;
}
double COOL_ARRAY6(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
if(cl->pgrackle_data->primordial_chemistry > 1)
return (cp->HM);
else
#endif
return 0;
}
double COOL_ARRAY7(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
if(cl->pgrackle_data->primordial_chemistry > 1)
return (cp->H2I);
else
#endif
return 0;
}
double COOL_ARRAY8(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
if(cl->pgrackle_data->primordial_chemistry > 1)
return (cp->H2II);
else
#endif
return 0;
}
double COOL_ARRAY9(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
if(cl->pgrackle_data->primordial_chemistry > 2)
return (cp->DI);
else
#endif
return 0;
}
double COOL_ARRAY10(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
if(cl->pgrackle_data->primordial_chemistry > 2)
return (cp->DII);
else
#endif
return 0;
}
double COOL_ARRAY11(COOL *cl, COOLPARTICLE *cp, double ZMetal) {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
if(cl->pgrackle_data->primordial_chemistry > 2)
return (cp->HDI);
else
#endif
return 0;
}
void CoolTableReadInfo( COOLPARAM *CoolParam, int cntTable, int *nTableColumns, char *suffix ) {
*nTableColumns = 0;
}
void CoolTableRead( COOL *Cool, int nData, void *vData) {
assert(0);
}
void CoolInitRatesTable( COOL *cl, COOLPARAM CoolParam ) {
}
void CoolSetTime( COOL *cl, double dTime, double z ) {
double a_value = 1. / (1. + z);
cl->dTime = dTime;
cl->z = z;
cl->a = a_value;
/*
if (initialize_chemistry_data(&cl->my_units, a_value) == 0) {
fprintf(stderr, "Grackle Error in initialize_chemistry_data.\n");
assert(0);
}
*/
}
void CoolDefaultParticleData( COOLPARTICLE *cp )
{
/* Never used I think - just to set values */
double tiny_number = 1.e-20;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
// gr_float HI, HII, HeI, HeII, HeII, e;
cp->HI = 0.76;
cp->HII = tiny_number;
cp->HeI = 0.24;
cp->HeII = tiny_number;
cp->HeIII = tiny_number;
cp->e = tiny_number;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
// gr_float HM, H2I, H2II;
cp->HM = tiny_number;
cp->H2I = tiny_number;
cp->H2II = tiny_number;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
// gr_float DI, DII, HDI
cp->DI = 2.0 * 3.4e-5;
cp->DII = tiny_number;
cp->HDI = tiny_number;
#endif
#endif
#endif
}
void CoolInitEnergyAndParticleData( COOL *cl, COOLPARTICLE *cp, double *E, double dDensity, double dTemp, double ZMetal) {
double tiny_number = 1.e-20;
/* Ionization fractions arbitrary -- should be set to eqm or some early universe model (e ~ 1e-5) */
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
// gr_float HI, HII, HeI, HeII, HeII, e;
double fNonMetal = 1-ZMetal; // see make_consistent_g in solve_rate_cool.F
cp->HI = fNonMetal * cl->pgrackle_data->HydrogenFractionByMass;
cp->HII = tiny_number;
cp->HeI = fNonMetal * (1.0 - cl->pgrackle_data->HydrogenFractionByMass); //(from c_example.c -- fails to do He increase w/ Z)
cp->HeII = tiny_number;
cp->HeIII = tiny_number;
cp->e = tiny_number;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
// gr_float HM, H2I, H2II;
cp->HM = tiny_number * dDensity;
cp->H2I = tiny_number * dDensity;
cp->H2II = tiny_number * dDensity;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
// gr_float DI, DII, HDI
cp->DI = 2.0 * 3.4e-5 * dDensity;
cp->DII = tiny_number * dDensity;
cp->HDI = tiny_number * dDensity;
#endif
#endif
#endif
// solar metallicity
// metal_density[i] = grackle_data.SolarMetalFractionByMass * density[i];
// No routine in Grackle to use to set up energy sensibly
// Energy: erg per gm --> code units assumes neutral gas (as above)
// This is not called after checkpoints so should be ok
*E = dTemp*(kboltz*1.5/(1.2*mh))*cl->diErgPerGmUnit;
// printf("Grackle %d \n",GRACKLE_PRIMORDIAL_CHEMISTRY_MAX);
// printf("%g %g %g %g %g %g %g %g %g\n",dDensity,*E,cp->HI,cp->HII,cp->HeI,cp->HeII,cp->HeIII,cp->e);
double Tnew=0;
int its=0;
while (its++ < 20 && fabs(Tnew/dTemp-1) > 1e-2) {
Tnew = CoolCodeEnergyToTemperature( cl, cp, *E, dDensity, ZMetal );
*E = *E*dTemp/Tnew;
}
assert(its<20);
// printf("dTemp %g (K) Tnew %g (K) Energy %g (erg/g) mu %g \n",dTemp,Tnew,*E*cl->dErgPerGmUnit,Tnew/dTemp*1.2);
}
void CoolIntegrateEnergy(COOL *cl, clDerivsData *clData, COOLPARTICLE *cp, double *E,
double ExternalHeat, double rho, double ZMetal, double *rp, double tStep ) {
assert(0);
}
void CoolIntegrateEnergyCode(COOL *cl, clDerivsData *clData, COOLPARTICLE *cp, double *E,
double ExternalHeat, double rho, double ZMetal, double *rp, double tStep ) {
double dt = tStep/cl->dSecUnit; // back into code units
int zero[]={0,0,0},one[]={1,1,1};
gr_float density = rho, energy = *E,
x_velocity=0, y_velocity=0, z_velocity=0,
HI_density, HII_density, HM_density,
HeI_density, HeII_density, HeIII_density,
H2I_density, H2II_density,
DI_density, DII_density, HDI_density,
e_density, metal_density;
/* Negative dt indicates cooling shutoff, we still need to
calculate the abundances */
if(dt < 0.0) dt = -dt;
metal_density = ZMetal*density;
if (cl->pgrackle_data->primordial_chemistry==0) {
/*
int solve_chemistry_table(code_units *my_units, double a_value, double dt_value,
int grid_rank, int *grid_dimension, int *grid_start, int *grid_end,
gr_float *density, gr_float *internal_energy,
gr_float *x_velocity, gr_float *y_velocity, gr_float *z_velocity, gr_float *metal_density);
*/
if (solve_chemistry_table(&(cl->my_units), cl->a, 0.5*dt,
1, one, zero, zero,
&density, &energy,
&x_velocity, &y_velocity, &z_velocity,
&metal_density)== 0) {
fprintf(stderr, "Grackle Error in solve_chemistry.\n");
assert(0);
}
}
else {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
HI_density = cp->HI*density;
HII_density = cp->HII*density;
HeI_density = cp->HeI*density;
HeII_density = cp->HeII*density;
HeIII_density = cp->HeIII*density;
e_density = cp->e*density;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
HM_density = cp->HM*density;
H2I_density = cp->H2I*density;
H2II_density = cp->H2II*density;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
DI_density = cp->DI*density;
DII_density = cp->DII*density;
HDI_density = cp->HDI*density;
#endif
#endif
#endif
/*
solve_chemistry(&(cl->my_units),
a_value, dt,
grid_rank, grid_dimension,
grid_start, grid_end,
density, energy,
x_velocity, y_velocity, z_velocity,
HI_density, HII_density, HM_density,
HeI_density, HeII_density, HeIII_density,
H2I_density, H2II_density,
DI_density, DII_density, HDI_density,
e_density, metal_density) */
if (solve_chemistry(&(cl->my_units),
cl->a, 0.5*dt,
1, one, zero, zero,
&density, &energy,
&x_velocity, &y_velocity, &z_velocity,
&HI_density, &HII_density, &HM_density,
&HeI_density, &HeII_density, &HeIII_density,
&H2I_density, &H2II_density,
&DI_density, &DII_density, &HDI_density,
&e_density, &metal_density)== 0) {
fprintf(stderr, "Grackle Error in solve_chemistry.\n");
assert(0);
}
}
energy += ExternalHeat*dt; /* Gnedin suggestion */
if(energy <= 0.0) {
double dEold = energy - ExternalHeat*dt;
energy = dEold*exp(ExternalHeat*dt/dEold);
}
density = rho;
x_velocity=0; y_velocity=0; z_velocity=0;
metal_density = ZMetal*density;
if (cl->pgrackle_data->primordial_chemistry==0) {
if (solve_chemistry_table(&(cl->my_units), cl->a, 0.5*dt,
1, one, zero, zero,
&density, &energy,
&x_velocity, &y_velocity, &z_velocity,
&metal_density)== 0) {
fprintf(stderr, "Grackle Error in solve_chemistry.\n");
assert(0);
}
}
else {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
HI_density = cp->HI*density;
HII_density = cp->HII*density;
HeI_density = cp->HeI*density;
HeII_density = cp->HeII*density;
HeIII_density = cp->HeIII*density;
e_density = cp->e*density;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
HM_density = cp->HM*density;
H2I_density = cp->H2I*density;
H2II_density = cp->H2II*density;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
DI_density = cp->DI*density;
DII_density = cp->DII*density;
HDI_density = cp->HDI*density;
#endif
#endif
#endif
if (solve_chemistry(&(cl->my_units),
cl->a, 0.5*dt,
1, one, zero, zero,
&density, &energy,
&x_velocity, &y_velocity, &z_velocity,
&HI_density, &HII_density, &HM_density,
&HeI_density, &HeII_density, &HeIII_density,
&H2I_density, &H2II_density,
&DI_density, &DII_density, &HDI_density,
&e_density, &metal_density)== 0) {
fprintf(stderr, "Grackle Error in solve_chemistry.\n");
assert(0);
}
}
assert(energy > 0.0);
*E = energy;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
float dinv = 1./density;
cp->HI = HI_density*dinv;
cp->HII = HII_density*dinv;
cp->HeI = HeI_density*dinv;
cp->HeII = HeII_density*dinv;
cp->e = e_density*dinv;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
cp->HM = HM_density*dinv;
cp->H2I = H2I_density*dinv;
cp->H2II = H2II_density*dinv;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
cp->DI = DI_density*dinv;
cp->DII = DII_density*dinv;
cp->HDI = HDI_density*dinv;
#endif
#endif
#endif
}
double CoolHeatingRate( COOL *cl, COOLPARTICLE *cp, double T, double dDensity, double ZMetal, double rkpc) {
assert(0);
}
double CoolCoolingCode(COOL *cl, COOLPARTICLE *cp, double ECode,
double rhoCode, double ZMetal, double *posCode ) {
assert(0);
}
double CoolHeatingCode(COOL *cl, COOLPARTICLE *cp, double ECode,
double rhoCode, double ZMetal, double *posCode ) {
assert(0);
}
void CoolAddParams( COOLPARAM *CoolParam, PRM prm ) {
CoolParam->bDoIonOutput = 1;
prmAddParam(prm,"bDoIonOutput",paramBool,&CoolParam->bDoIonOutput,sizeof(int),
"Iout","enable/disable Ion outputs (cooling only) = +Iout");
CoolParam->grackle_verbose = 0;
prmAddParam(prm,"grackle_verbose",paramBool,&CoolParam->grackle_verbose,sizeof(int),"grackle_verbose",
"on = +grackle_verbose [off]");
CoolParam->use_grackle = 1;
prmAddParam(prm,"use_grackle",paramBool,&CoolParam->use_grackle,sizeof(int),"use_grackle",
"on = +use_grackle");
CoolParam->with_radiative_cooling = 1;
prmAddParam(prm,"with_radiative_cooling",paramBool,&CoolParam->with_radiative_cooling,sizeof(int),"with_radiative_cooling",
"on = +with_radiative_cooling");
CoolParam->primordial_chemistry = 0;
prmAddParam(prm,"primordial_chemistry",paramInt,&CoolParam->primordial_chemistry,sizeof(int),"primordial_chemistry",
"-primordial_chemistry=0 [values 0,1,2,3]");
CoolParam->metal_cooling = 1;
prmAddParam(prm,"metal_cooling",paramBool,&CoolParam->metal_cooling,sizeof(int),"metal_cooling",
"on = +metal_cooling");
CoolParam->UVbackground = 1;
prmAddParam(prm,"UVbackground",paramBool,&CoolParam->UVbackground,sizeof(int),"UVbackground",
"on = +UVbackground");
CoolParam->bComoving = 1;
prmAddParam(prm,"bComoving",paramBool,&CoolParam->bComoving,sizeof(int),"bComoving",
"on = +bComoving");
strcpy(CoolParam->grackle_data_file,"CloudyData_UVB=HM2012.h5\0");
prmAddParam(prm,"grackle_data_file",paramString,&CoolParam->grackle_data_file,256,"grackle_data_file",
"<cooling table file> (file in hdf5 format, e.g. CloudyData_UVB=HM2012.h5)");
}
#if 0
/* Not needed for ChaNGa */
void CoolLogParams( COOLPARAM *CoolParam, LOGGER *lgr) {
LogParams(lgr, "COOLING", "bDoIonOutput: %d",CoolParam->bDoIonOutput);
LogParams(lgr, "COOLING", "grackle_verbose: %d",CoolParam->grackle_verbose);
LogParams(lgr, "COOLING", "use_grackle: %d",CoolParam->use_grackle);
LogParams(lgr, "COOLING", "with_radiative_cooling: %d",CoolParam->with_radiative_cooling);
LogParams(lgr, "COOLING", "primorial_chemistry: %d (MAX %d) ",CoolParam->primordial_chemistry,GRACKLE_PRIMORDIAL_CHEMISTRY_MAX);
LogParams(lgr, "COOLING", "metal_cooling: %d",CoolParam->metal_cooling);
LogParams(lgr, "COOLING", "UVbackground: %d",CoolParam->UVbackground);
LogParams(lgr, "COOLING", "bComoving: %d",CoolParam->bComoving);
LogParams(lgr, "COOLING", "grackle_data_file: %s",CoolParam->grackle_data_file);
}
#endif
void CoolOutputArray( COOLPARAM *CoolParam, int cnt, int *type, char *suffix ) {
#if 0
char *extensions[]= { "HI", "HII", "HeI", "HeII", "HeIII", "e",
"HM", "H2I", "H2II",
"DI", "DII", "HDI" };
*type = OUT_NULL;
if (!CoolParam->bDoIonOutput) return;
/*
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX<1)
float dummy;
#endif
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
gr_float HI, HII, HeI, HeII, HeII, e;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
gr_float HM, H2I, H2II;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
gr_float DI, DII, HDI
#endif
#endif
#endif
*/
switch (cnt) {
case 11:
case 10:
case 9:
if (CoolParam->primordial_chemistry<3) return;
case 8:
case 7:
case 6:
if (CoolParam->primordial_chemistry<2) return;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
if (CoolParam->primordial_chemistry<1) return;
*type = OUT_COOL_ARRAY0+cnt;
sprintf(suffix,extensions[cnt]);
return;
}
#endif
}
double CoolCodeEnergyToTemperature( COOL *cl, COOLPARTICLE *cp, double E, double rho, double ZMetal ) {
int one[]={1,1,1};
int zero[]={0,0,0};
gr_float density = rho, energy = E,
x_velocity=0, y_velocity=0, z_velocity=0,
HI_density, HII_density, HM_density,
HeI_density, HeII_density, HeIII_density,
H2I_density, H2II_density,
DI_density, DII_density, HDI_density,
e_density, metal_density, temperature;
metal_density = ZMetal*density;
if (cl->pgrackle_data->primordial_chemistry==0) {
/*
calculate_temperature_table(code_units *my_units, int grid_rank, int *grid_dimension,
gr_float *density, gr_float *internal_energy, gr_float *metal_density, gr_float *temperature);*/
if (calculate_temperature_table(&cl->my_units, cl->a,
1, one, zero, zero,
&density, &energy, &metal_density, &temperature) == 0) {
fprintf(stderr, "Grackle Error in calculate_temperature.\n");
assert(0);
}
}
else {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
HI_density = cp->HI*density;
HII_density = cp->HII*density;
HeI_density = cp->HeI*density;
HeII_density = cp->HeII*density;
HeIII_density = cp->HeIII*density;
e_density = cp->e*density;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
HM_density = cp->HM*density;
H2I_density = cp->H2I*density;
H2II_density = cp->H2II*density;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
DI_density = cp->DI*density;
DII_density = cp->DII*density;
HDI_density = cp->HDI*density;
#endif
#endif
#endif
if (calculate_temperature(&cl->my_units, cl->a,
1, one, zero, zero,
&density, &energy,
&HI_density, &HII_density, &HM_density,
&HeI_density, &HeII_density, &HeIII_density,
&H2I_density, &H2II_density,
&DI_density, &DII_density, &HDI_density,
&e_density, &metal_density,
&temperature) == 0) {
fprintf(stderr, "Grackle Error in calculate_temperature.\n");
assert(0);
}
}
return ((double) temperature);
}
// Currently a MACRO -- assumes gamma=5/3
// Should use: Grackle calculate_pressure if H2 > 0
/*
void CoolCodePressureOnDensitySoundSpeed( COOL *cl, COOLPARTICLE *cp, double uPred, double fDensity, double gamma, double gammam1, double *PoverRho, double *c ) {
}
*/
/* Code heating - cooling rate excluding external heating (PdV, etc..) */
double CoolEdotInstantCode(COOL *cl, COOLPARTICLE *cp, double ECode,
double rhoCode, double ZMetal, double *posCode ) {
int zero[]={0,0,0},one[]={1,1,1};
gr_float density = rhoCode, energy = ECode,
x_velocity=0, y_velocity=0, z_velocity=0,
HI_density, HII_density, HM_density,
HeI_density, HeII_density, HeIII_density,
H2I_density, H2II_density,
DI_density, DII_density, HDI_density,
e_density, metal_density, cooling_time;
metal_density = ZMetal*density;
if (cl->pgrackle_data->primordial_chemistry==0) {
/*
int calculate_cooling_time_table(code_units *my_units, double a_value,
int grid_rank, int *grid_dimension, int *grid_start, int *grid_end,
gr_float *density, gr_float *internal_energy,
gr_float *x_velocity, gr_float *y_velocity, gr_float *z_velocity, gr_float *metal_density, gr_float *cooling_time); */
if (calculate_cooling_time_table(&cl->my_units, cl->a,
1, one, zero, zero,
&density, &energy,
&x_velocity, &y_velocity, &z_velocity, &metal_density, &cooling_time) == 0) {
fprintf(stderr, "Grackle Error in calculate_cooling_time_table.\n");
assert(0);
}
}
else {
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=1)
HI_density = cp->HI*density;
HII_density = cp->HII*density;
HeI_density = cp->HeI*density;
HeII_density = cp->HeII*density;
HeIII_density = cp->HeIII*density;
e_density = cp->e*density;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=2)
HM_density = cp->HM*density;
H2I_density = cp->H2I*density;
H2II_density = cp->H2II*density;
#if (GRACKLE_PRIMORDIAL_CHEMISTRY_MAX>=3)
DI_density = cp->DI*density;
DII_density = cp->DII*density;
HDI_density = cp->HDI*density;
#endif
#endif
#endif
/*
calculate_cooling_time(code_units *my_units, double a_value,
int grid_rank, int *grid_dimension, int *grid_start, int *grid_end,
gr_float *density, gr_float *internal_energy,
gr_float *x_velocity, gr_float *y_velocity, gr_float *z_velocity,
gr_float *HI_density, gr_float *HII_density, gr_float *HM_density,
gr_float *HeI_density, gr_float *HeII_density, gr_float *HeIII_density,
gr_float *H2I_density, gr_float *H2II_density, gr_float *DI_density, gr_float *DII_density,
gr_float *HDI_density, gr_float *e_density, gr_float *metal_density, gr_float *cooling_time);
*/
if (calculate_cooling_time(&cl->my_units, cl->a,
1, one, zero, zero,
&density, &energy,
&x_velocity, &y_velocity, &z_velocity,
&HI_density, &HII_density, &HM_density,
&HeI_density, &HeII_density, &HeIII_density,
&H2I_density, &H2II_density,
&DI_density, &DII_density, &HDI_density,
&e_density, &metal_density,
&cooling_time) == 0) {
fprintf(stderr, "Grackle Error in calculate_cooling_time.\n");
assert(0);
}
}
return (ECode/cooling_time); /* Edot (erg/g/s) undoes code in cool_multi_time_g.F */
}
#endif /* NOCOOLING */