forked from N-BodyShop/gasoline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cooling_cosmo.c
1401 lines (1171 loc) · 44.3 KB
/
cooling_cosmo.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
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mode.h"
#ifdef GASOLINE
#ifndef NOCOOLING
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
/* 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
*/
/* General accuracy target */
#define EPS 1e-5
#define MAXABUNDITERATIONS 20
/* Accuracy for Temperature estimation for E,rho assuming eqm abundances */
#define EPSTEMP 1e-5
#define ETAMINTIMESTEP 1e-4
#include "stiff.h"
#if defined(COOLDEBUG) || defined(STARFORM) || defined(SIMPLESF)
#include "pkd.h"
#else
#include "cooling.h"
#endif
#include "outtype.h"
/* Integrator constants */
/* When to use to just do a first order step and quit */
/* Good value to use I think */
#define ECHANGEFRACSMALL 1e-4
/* Accuracy target for intergrators */
#define EPSINTEG 1e-5
#define MAXINTEGITS 20000
#define NDOT_MIN 1e-60
#define CL_eHI (13.60*CL_eV_erg)
#define CL_eHeI (24.59*CL_eV_erg)
#define CL_eHeII (54.42*CL_eV_erg)
#define CL_E2HeII (3.0*13.6*CL_eV_erg)
#define EMUL (1.0001)
COOL *CoolInit( )
{
COOL *cl;
cl = (COOL *) malloc(sizeof(COOL));
assert(cl!=NULL);
cl->nUV = 0;
cl->UV = NULL;
cl->nTable = 0;
cl->RT = NULL;
cl->nTableRead = 0; /* Internal Tables read from Files */
cl->DerivsData = malloc(sizeof(clDerivsData));
assert(cl->DerivsData != NULL);
((clDerivsData *) (cl->DerivsData))->IntegratorContext =
StiffInit( EPSINTEG, 1, cl->DerivsData, clDerivs);
return cl;
}
void CoolFinalize(COOL *cl )
{
StiffFinalize( ((clDerivsData *) (cl->DerivsData))->IntegratorContext );
free(cl->DerivsData);
if (cl->UV != NULL) free(cl->UV);
if (cl->RT != NULL) free(cl->RT);
free(cl);
}
void clInitConstants( COOL *cl, double dGmPerCcUnit, double dComovingGmPerCcUnit,
double dErgPerGmUnit, double dSecUnit, double dKpcUnit, COOLPARAM CoolParam)
{
assert(cl!=NULL);
cl->dGmPerCcUnit = dGmPerCcUnit;
cl->dComovingGmPerCcUnit = dComovingGmPerCcUnit;
cl->dErgPerGmUnit = dErgPerGmUnit;
cl->dSecUnit = dSecUnit;
cl->dErgPerGmPerSecUnit = cl->dErgPerGmUnit / cl->dSecUnit;
cl->diErgPerGmUnit = 1./dErgPerGmUnit;
cl->dKpcUnit = dKpcUnit;
cl->Y_H = 1.0-CoolParam.dMassFracHelium;
cl->Y_He = CoolParam.dMassFracHelium/4;
cl->Y_eMAX = cl->Y_H + cl->Y_He*2;
cl->bUV = CoolParam.bUV;
cl->bUVTableUsesTime = CoolParam.bUVTableUsesTime;
cl->bUVTableLinear = CoolParam.bUVTableUsesTime; /* Linear if using time */
cl->bLowTCool = CoolParam.bLowTCool;
cl->bSelfShield = CoolParam.bSelfShield;
/* Derivs Data Struct */
{
clDerivsData *Data = cl->DerivsData;
assert(Data != NULL);
Data->cl = cl;
Data->Y_Total0 = (cl->Y_H+cl->Y_He)*.9999; /* neutral */
Data->Y_Total1 = (cl->Y_eMAX+cl->Y_H+cl->Y_He)*1.0001; /* Full Ionization */
}
}
void clInitUV(COOL *cl, int nTableColumns, int nTableRows, double *dTableData )
{
int i;
assert(cl!=NULL);
assert(cl->UV == NULL);
assert(nTableColumns == 7);
cl->nUV = nTableRows;
cl->UV = (UVSPECTRUM *) malloc(nTableRows*sizeof(UVSPECTRUM));
assert(cl->UV!=NULL);
for (i=0;i<nTableRows;i++) {
(cl->UV)[i].zTime = dTableData[i*nTableColumns];
(cl->UV)[i].Rate_Phot_HI = dTableData[i*nTableColumns+1];
(cl->UV)[i].Rate_Phot_HeI = dTableData[i*nTableColumns+2];
(cl->UV)[i].Rate_Phot_HeII = dTableData[i*nTableColumns+3];
(cl->UV)[i].Heat_Phot_HI = dTableData[i*nTableColumns+4];
(cl->UV)[i].Heat_Phot_HeI = dTableData[i*nTableColumns+5];
(cl->UV)[i].Heat_Phot_HeII = dTableData[i*nTableColumns+6];
/* Make sure the heating is in units of ergs per ionization */
assert( (cl->UV)[i].Heat_Phot_HI>1e-15 && (cl->UV)[i].Heat_Phot_HI<1e-10);
if (i) assert (((cl->UV)[i-1].zTime > (cl->UV)[i].zTime
&& !cl->bUVTableUsesTime) ||
((cl->UV)[i-1].zTime < (cl->UV)[i].zTime
&& cl->bUVTableUsesTime));
}
}
void clInitRatesTable( COOL *cl, double TMin, double TMax, int nTable ) {
/*-----------------------------------------------------------------
* Function of ln(T) tables:
* cl assumed to be predefined (allocated)
* A table spacing of 1.23e-3 in log(T) eg. nTable=15001 10->1e9 K
* Maximum 1% errors except at discontinuities in the functions.
* Storage for such a table is (15001*15*4|8b) => 0.9|1.7 Mb
*-----------------------------------------------------------------*/
int i;
double DeltaTln, Tln, T;
clDerivsData *Data;
double dEMin;
assert(cl!=NULL);
assert(cl->RT == NULL);
/* Set minimum temperature in integrator */
Data = cl->DerivsData;
dEMin = clThermalEnergy(Data->Y_Total0, TMin);
StiffSetYMin(Data->IntegratorContext, &dEMin);
cl->R.Cool_Coll_HI = CL_eHI*CL_B_gm;
cl->R.Cool_Coll_HeI = CL_eHeI*CL_B_gm;
cl->R.Cool_Coll_HeII = CL_eHeII*CL_B_gm;
cl->R.Cool_Diel_HeII = (CL_E2HeII+CL_eHeI)*CL_B_gm;
cl->nTable = nTable;
cl->TMin = TMin;
cl->TMax = TMax;
cl->TlnMin = log( TMin );
cl->TlnMax = log( TMax );
DeltaTln = ( cl->TlnMax-cl->TlnMin )/( nTable - 1 );
cl->rDeltaTln = 1./DeltaTln;
cl->RT = (RATES_T *) malloc( nTable * sizeof(RATES_T) );
assert(cl->RT != NULL);
for ( i=0; i<nTable; i++ ) {
Tln = cl->TlnMin + DeltaTln*(i-1);
T=exp(Tln);
(cl->RT+i)->Rate_Coll_HI = clRateCollHI( T );
if ( (cl->RT+i)->Rate_Coll_HI < CL_RT_MIN ) (cl->RT+i)->Rate_Coll_HI = CL_RT_MIN;
(cl->RT+i)->Rate_Coll_HeI = clRateCollHeI( T );
if ( (cl->RT+i)->Rate_Coll_HeI < CL_RT_MIN ) (cl->RT+i)->Rate_Coll_HeI = CL_RT_MIN;
(cl->RT+i)->Rate_Coll_HeII = clRateCollHeII( T );
if ( (cl->RT+i)->Rate_Coll_HeII < CL_RT_MIN ) (cl->RT+i)->Rate_Coll_HeII = CL_RT_MIN;
(cl->RT+i)->Rate_Radr_HII = clRateRadrHII( T );
(cl->RT+i)->Rate_Radr_HeII = clRateRadrHeII( T );
(cl->RT+i)->Rate_Radr_HeIII = clRateRadrHeIII( T );
(cl->RT+i)->Rate_Diel_HeII = clRateDielHeII( T );
(cl->RT+i)->Cool_Brem_1 = clCoolBrem1( T );
(cl->RT+i)->Cool_Brem_2 = clCoolBrem2( T );
(cl->RT+i)->Cool_Radr_HII = clCoolRadrHII( T );
(cl->RT+i)->Cool_Radr_HeII = clCoolRadrHeII( T );
(cl->RT+i)->Cool_Radr_HeIII = clCoolRadrHeIII( T );
(cl->RT+i)->Cool_Line_HI = clCoolLineHI( T );
(cl->RT+i)->Cool_Line_HeI = clCoolLineHeI( T );
(cl->RT+i)->Cool_Line_HeII = clCoolLineHeII( T );
(cl->RT+i)->Cool_LowT = clCoolLowT( T );
}
}
void clRatesTableError( COOL *cl ) {
/* This estimates the error for a table of half the size of
* the current one.
* The collisional, dielectric and line cooling rates can all go to
* zero (minimum) and will even for double precision (exp(-1e5/T))
* the critical values that must never get down to zero
* are the radiative recombination rates: Check this before using
* CL_RT_FLOAT float for the table.
*/
int i,j,ierr[15];
double min[15],max[15];
double err,maxerr[15];
CL_RT_FLOAT *p,*p1,*p2;
for (j=0;j<15;j++) {
maxerr[j]=0.0;
min[j]=1e300;
max[j]=-1e300;
}
for ( i=1; i<cl->nTable-1; i+=2 ) {
p = (CL_RT_FLOAT *) &((cl->RT+i)->Rate_Coll_HI);
p1 = (CL_RT_FLOAT *) &((cl->RT+i-1)->Rate_Coll_HI);
p2 = (CL_RT_FLOAT *) &((cl->RT+i+1)->Rate_Coll_HI);
if (i==10001) {
printf(" Comp %i %i %e %e\n",i,(int) sizeof(CL_RT_FLOAT),p[1],(cl->RT+i)->Rate_Coll_HeI);
}
for (j=0;j<15;j++) {
if (p[j] < min[j]) min[j]=p[j];
if (p[j] > max[j]) max[j]=p[j];
err= fabs((0.5*(p1[j]+p2[j])-p[j])/(p[j]+1e-30));
if (err > maxerr[j] ) {
maxerr[j]=err;
ierr[j]=i;
}
}
}
for (j=0;j<15;j++) {
printf("Col %i Max Error: %e at T=%e dlnT=%e (min %e max %e)\n",j,
maxerr[j],exp(cl->TlnMin+ierr[j]/cl->rDeltaTln),2/cl->rDeltaTln,min[j],max[j]);
}
}
#define CL_Ccomp0 0.565e-9
#define CL_Tcmb0 2.735
#define CL_Ccomp (CL_Ccomp0*CL_Tcmb0)
void clRatesRedshift( COOL *cl, double zIn, double dTimeIn ) {
int i;
double xx;
double zTime;
UVSPECTRUM *UV,*UV0;
cl->z = zIn;
cl->dTime = dTimeIn;
cl->dComovingGmPerCcUnit = cl->dGmPerCcUnit*pow(1.+zIn,3.);
cl->R.Cool_Comp = pow((1+zIn)*CL_Ccomp,4.0)*CL_B_gm;
cl->R.Tcmb = CL_Tcmb0*(1+zIn);
cl->R.Cool_LowTFactor = (cl->bLowTCool ? CL_B_gm*cl->Y_H*cl->Y_H/0.001 : 0 );
/* Photo-Ionization rates */
UV = cl->UV;
if (cl->bUV) {
assert( UV != NULL );
if (cl->bUVTableUsesTime) {
/*
** Table in order of increasing time
*/
zTime = dTimeIn;
for ( i=0; i < cl->nUV && zTime >= UV->zTime ; i++,UV++ );
}
else {
/*
** Table in order of high to low redshift
*/
zTime = zIn;
for ( i=0; i < cl->nUV && zTime <= UV->zTime ; i++,UV++ );
}
}
if (!cl->bUV || i==0) {
cl->R.Rate_Phot_HI = CL_RT_MIN;
cl->R.Rate_Phot_HeI = CL_RT_MIN;
cl->R.Rate_Phot_HeII = CL_RT_MIN;
cl->R.Heat_Phot_HI = 0.0;
cl->R.Heat_Phot_HeI = 0.0;
cl->R.Heat_Phot_HeII = 0.0;
return;
}
UV0=UV-1;
if (i == cl->nUV ) {
cl->R.Rate_Phot_HI = UV0->Rate_Phot_HI;
cl->R.Rate_Phot_HeI = UV0->Rate_Phot_HeI;
cl->R.Rate_Phot_HeII = UV0->Rate_Phot_HeII;
cl->R.Heat_Phot_HI = UV0->Heat_Phot_HI*CL_B_gm;
cl->R.Heat_Phot_HeI = UV0->Heat_Phot_HeI*CL_B_gm;
cl->R.Heat_Phot_HeII = UV0->Heat_Phot_HeII*CL_B_gm;
}
else {
if (cl->bUVTableLinear) { /* use Linear interpolation */
xx = (zTime - UV0->zTime)/(UV->zTime - UV0->zTime);
cl->R.Rate_Phot_HI = UV0->Rate_Phot_HI*(1-xx)+UV->Rate_Phot_HI*xx;
cl->R.Rate_Phot_HeI = UV0->Rate_Phot_HeI*(1-xx)+UV->Rate_Phot_HeI*xx;
cl->R.Rate_Phot_HeII = UV0->Rate_Phot_HeII*(1-xx)+UV->Rate_Phot_HeII*xx;
cl->R.Heat_Phot_HI = (UV0->Heat_Phot_HI*(1-xx)+UV->Heat_Phot_HI*xx)*CL_B_gm;
cl->R.Heat_Phot_HeI = (UV0->Heat_Phot_HeI*(1-xx)+UV->Heat_Phot_HeI*xx)*CL_B_gm;
cl->R.Heat_Phot_HeII = (UV0->Heat_Phot_HeII*(1-xx)+UV->Heat_Phot_HeII*xx)*CL_B_gm;
}
else { /* use Log interpolation with 1+zTime */
xx = log((1+zTime)/(1+UV0->zTime))/log((1+UV->zTime)/(1+UV0->zTime));
cl->R.Rate_Phot_HI = pow(UV0->Rate_Phot_HI,1-xx)*pow(UV->Rate_Phot_HI,xx);
cl->R.Rate_Phot_HeI = pow(UV0->Rate_Phot_HeI,1-xx)*pow(UV->Rate_Phot_HeI,xx);
cl->R.Rate_Phot_HeII = pow(UV0->Rate_Phot_HeII,1-xx)*pow(UV->Rate_Phot_HeII,xx);
cl->R.Heat_Phot_HI = pow(UV0->Heat_Phot_HI,1-xx)*pow(UV->Heat_Phot_HI,xx)*CL_B_gm;
cl->R.Heat_Phot_HeI = pow(UV0->Heat_Phot_HeI,1-xx)*pow(UV->Heat_Phot_HeI,xx)*CL_B_gm;
cl->R.Heat_Phot_HeII = pow(UV0->Heat_Phot_HeII,1-xx)*pow(UV->Heat_Phot_HeII,xx)*CL_B_gm;
}
}
if (cl->R.Rate_Phot_HI < CL_RT_MIN) cl->R.Rate_Phot_HI = CL_RT_MIN;
if (cl->R.Rate_Phot_HeI < CL_RT_MIN) cl->R.Rate_Phot_HeI = CL_RT_MIN;
if (cl->R.Rate_Phot_HeII < CL_RT_MIN) cl->R.Rate_Phot_HeII = CL_RT_MIN;
/*
printf("Cooling Rates for t(%1i)=%g, Z=%g: %g %g %g %g %g %g\n",cl->bUVTableUsesTime,dTimeIn,zIn,cl->R.Rate_Phot_HI,cl->R.Rate_Phot_HeI,cl->R.Rate_Phot_HeII,cl->R.Heat_Phot_HI,cl->R.Heat_Phot_HeI,cl->R.Heat_Phot_HeII);
*/
return;
}
double AP_log_den_mp_percm3[] = { -10.25, -9.75, -9.25, -8.75, -8.25, -7.75, -7.25,
-6.75, -6.25, -5.75, -5.25, -4.75, -4.25, -3.75,
-3.25, -2.75, -2.25,
-1.75, -1.25, -0.75, -0.25, 0.25, 0.75, 1.25, 1.75, 2.25 };
double AP_Gamma_HI_factor[] = { 0.99805271764596307, 0.99877911567687988, 0.99589340865612034,
0.99562060764857702, 0.99165170359332663, 0.9900889877822455,
0.98483276828954668, 0.97387675312245325, 0.97885673164000397,
0.98356305803821331, 0.96655786672182487, 0.9634906824933207,
0.95031917373653985, 0.87967606627349137, 0.79917533618355074,
0.61276011113763151, 0.16315185162187529, 0.02493663181368239,
0.0044013580765645335, 0.00024172553511936628, 1.9576102058649783e-10,
0.0, 0.0, 0.0, 0.0, 0.0 };
double AP_Gamma_HeI_factor[] = { 0.99284882980782224, 0.9946618686265097, 0.98641914356740497,
0.98867015777574848, 0.96519214493135597, 0.97188336387980656,
0.97529866247535113 , 0.97412477991428936, 0.97904139838765991,
0.98368372768570034, 0.96677432842215549, 0.96392622083382651,
0.95145730833093178, 0.88213871255482879, 0.80512823597731886,
0.62474472739578646, 0.17222786134467002, 0.025861959933038869,
0.0045265030237581529, 0.00024724339438128221, 1.3040144591221284e-08,
0.0, 0.0, 0.0, 0.0, 0.0};
double AP_Gamma_HeII_factor[] = { 0.97990208047216765, 0.98606251822654412,
0.97657215632444849, 0.97274858503068629, 0.97416108746560681,
0.97716929017896703, 0.97743607605974214, 0.97555305775319012,
0.97874250764784809, 0.97849791914637996, 0.95135572977973504,
0.92948461312852582, 0.89242272355549912, 0.79325512242742746 ,
0.6683745597121028, 0.51605924897038324, 0.1840253816147828,
0.035905775349044489, 0.0045537756654992923, 0.00035933897136804514,
1.2294426136470751e-06, 0.0, 0.0, 0.0, 0.0, 0.0 };
void clRates( COOL *cl, RATE *Rate, double T, double rho ) {
double Tln;
double xTln,wTln0,wTln1;
RATES_T *RT0,*RT1;
int iTln;
if (T >= cl->TMax) T=cl->TMax*(1.0 - EPS);
if (T < cl->TMin) T=cl->TMin;
Tln = log(T);
Rate->T = T;
Rate->Tln = Tln;
xTln = (Tln-cl->TlnMin)*cl->rDeltaTln;
iTln = xTln;
RT0 = (cl->RT+iTln);
RT1 = RT0+1;
wTln1 = xTln-iTln;
wTln0 = 1-wTln1;
Rate->Coll_HI = (wTln0*RT0->Rate_Coll_HI+wTln1*RT1->Rate_Coll_HI);
Rate->Coll_HeI = (wTln0*RT0->Rate_Coll_HeI+wTln1*RT1->Rate_Coll_HeI);
Rate->Coll_HeII = (wTln0*RT0->Rate_Coll_HeII+wTln1*RT1->Rate_Coll_HeII);
Rate->Radr_HII = (wTln0*RT0->Rate_Radr_HII+wTln1*RT1->Rate_Radr_HII);
Rate->Radr_HeII = (wTln0*RT0->Rate_Radr_HeII+wTln1*RT1->Rate_Radr_HeII);
Rate->Diel_HeII = (wTln0*RT0->Rate_Diel_HeII+wTln1*RT1->Rate_Diel_HeII);
Rate->Totr_HeII = Rate->Radr_HeII + Rate->Diel_HeII;
Rate->Radr_HeIII = (wTln0*RT0->Rate_Radr_HeIII+wTln1*RT1->Rate_Radr_HeIII);
Rate->Phot_HI = cl->R.Rate_Phot_HI;
Rate->Phot_HeI = cl->R.Rate_Phot_HeI;
Rate->Phot_HeII = cl->R.Rate_Phot_HeII;
if (cl->bSelfShield) {
double logen_B;
logen_B = log10(rho*CL_B_gm);
if (logen_B > 2.2499) {
Rate->Phot_HI = 0;
Rate->Phot_HeI = 0;
Rate->Phot_HeII = 0;
}
else if (logen_B > -10.25) {
double x = (logen_B+10.25)*2.0;
int ix;
ix = floor(x);
x -= ix;
Rate->Phot_HI *= (AP_Gamma_HI_factor[ix]*(1-x)+AP_Gamma_HI_factor[ix+1]*x);
Rate->Phot_HeI *= (AP_Gamma_HeI_factor[ix]*(1-x)+AP_Gamma_HeI_factor[ix+1]*x);
Rate->Phot_HeII *= (AP_Gamma_HeII_factor[ix]*(1-x)+AP_Gamma_HeII_factor[ix+1]*x);
}
}
}
/* Deprecated except for testing: use EdotInstant */
/* Need density in here to make this work with Self-Shielding */
double clHeatTotal ( COOL *cl, PERBARYON *Y, RATE *Rate ) {
/* erg /gram /sec
Note: QQ_* premultiplied by (CL_B_gm*erg_ev) */
return Y->HI * cl->R.Heat_Phot_HI * Rate->Phot_HI +
Y->HeI * cl->R.Heat_Phot_HeI * Rate->Phot_HeI +
Y->HeII * cl->R.Heat_Phot_HeII * Rate->Phot_HeII;
}
/* Deprecated except for testing: use EdotInstant */
double clCoolTotal ( COOL *cl, PERBARYON *Y, RATE *Rate, double rho, double ZMetal ) {
/* Assumes clRates called previously */
/* erg /gram /sec */
double en_B=rho*CL_B_gm;
double xTln,wTln0,wTln1,LowTCool;
RATES_T *RT0,*RT1;
int iTln;
xTln = (Rate->Tln-cl->TlnMin)*cl->rDeltaTln;
iTln = xTln;
RT0 = (cl->RT+iTln);
RT1 = RT0+1;
wTln1 = xTln-iTln;
wTln0 = 1-wTln1;
if (Rate->T > cl->R.Tcmb)
LowTCool = (wTln0*RT0->Cool_LowT+wTln1*RT1->Cool_LowT)*cl->R.Cool_LowTFactor*en_B*ZMetal;
else
LowTCool = 0;
/* PUT INTO erg/gm/sec */
return Y->e * (
cl->R.Cool_Comp * ( Rate->T - cl->R.Tcmb ) +
en_B * (
(wTln0*RT0->Cool_Brem_1+wTln1*RT1->Cool_Brem_1) * ( Y->HII + Y->HeII ) +
(wTln0*RT0->Cool_Brem_2+wTln1*RT1->Cool_Brem_2) * Y->HeIII +
(wTln0*RT0->Cool_Radr_HII+wTln1*RT1->Cool_Radr_HII) * Y->HII * Rate->Radr_HII +
(wTln0*RT0->Cool_Radr_HeII+wTln1*RT1->Cool_Radr_HeII) * Y->HeII * Rate->Radr_HeII +
(wTln0*RT0->Cool_Radr_HeIII+wTln1*RT1->Cool_Radr_HeIII) * Y->HeIII * Rate->Radr_HeIII +
cl->R.Cool_Coll_HI * Y->HI * Rate->Coll_HI +
cl->R.Cool_Coll_HeI * Y->HeI * Rate->Coll_HeI +
cl->R.Cool_Coll_HeII * Y->HeII * Rate->Coll_HeII +
cl->R.Cool_Diel_HeII * Y->HeII * Rate->Diel_HeII +
(wTln0*RT0->Cool_Line_HI+wTln1*RT1->Cool_Line_HI) * Y->HI +
(wTln0*RT0->Cool_Line_HeI+wTln1*RT1->Cool_Line_HeI) * Y->HeI +
(wTln0*RT0->Cool_Line_HeII+wTln1*RT1->Cool_Line_HeII) * Y->HeII ) ) + LowTCool;
}
COOL_ERGPERSPERGM clTestCool ( COOL *cl, PERBARYON *Y, RATE *Rate, double rho ) {
/* Assumes clRates called previously */
/* erg /gram /sec */
double en_B=rho*CL_B_gm;
double xTln,wTln0,wTln1;
RATES_T *RT0,*RT1;
int iTln;
COOL_ERGPERSPERGM ret;
xTln = (Rate->Tln-cl->TlnMin)*cl->rDeltaTln;
iTln = xTln;
RT0 = (cl->RT+iTln);
RT1 = RT0+1;
wTln1 = xTln-iTln;
wTln0 = 1-wTln1;
/* PUT INTO erg/gm/sec */
ret.compton = Y->e * (
cl->R.Cool_Comp * ( Rate->T - cl->R.Tcmb ));
ret.bremHII = Y->e * en_B * (
(wTln0*RT0->Cool_Brem_1+wTln1*RT1->Cool_Brem_1) * ( Y->HII ));
ret.bremHeII = Y->e * en_B * (
(wTln0*RT0->Cool_Brem_1+wTln1*RT1->Cool_Brem_1) * ( Y->HeII ));
ret.bremHeIII = Y->e * en_B * (
(wTln0*RT0->Cool_Brem_2+wTln1*RT1->Cool_Brem_2) * Y->HeIII );
ret.radrecHII = Y->e * en_B *
(wTln0*RT0->Cool_Radr_HII+wTln1*RT1->Cool_Radr_HII) * Y->HII * Rate->Radr_HII;
ret.radrecHeII = Y->e * en_B *
(wTln0*RT0->Cool_Radr_HeII+wTln1*RT1->Cool_Radr_HeII) * Y->HeII * Rate->Radr_HeII;
ret.radrecHeIII = Y->e * en_B *
(wTln0*RT0->Cool_Radr_HeIII+wTln1*RT1->Cool_Radr_HeIII) * Y->HeIII * Rate->Radr_HeIII;
ret.collionHI = Y->e * en_B *
cl->R.Cool_Coll_HI * Y->HI * Rate->Coll_HI;
ret.collionHeI = Y->e * en_B *
cl->R.Cool_Coll_HeI * Y->HeI * Rate->Coll_HeI;
ret.collionHeII = Y->e * en_B *
cl->R.Cool_Coll_HeII * Y->HeII * Rate->Coll_HeII;
ret.dielrecHeII = Y->e * en_B *
cl->R.Cool_Diel_HeII * Y->HeII * Rate->Diel_HeII;
ret.lineHI = Y->e * en_B *
(wTln0*RT0->Cool_Line_HI+wTln1*RT1->Cool_Line_HI) * Y->HI;
ret.lineHeI = Y->e * en_B *
(wTln0*RT0->Cool_Line_HeI+wTln1*RT1->Cool_Line_HeI) * Y->HeI;
ret.lineHeII = Y->e * en_B *
(wTln0*RT0->Cool_Line_HeII+wTln1*RT1->Cool_Line_HeII) * Y->HeII;
ret.lowT = en_B *
(wTln0*RT0->Cool_LowT+wTln1*RT1->Cool_LowT)*cl->R.Cool_LowTFactor*0.001; /* assume metallicity 0.001 */
return ret;
}
void clPrintCool ( COOL *cl, PERBARYON *Y, RATE *Rate, double rho ) {
/* Assumes clRates called previously */
/* erg /gram /sec */
double en_B=rho*CL_B_gm;
double xTln,wTln0,wTln1;
RATES_T *RT0,*RT1;
int iTln;
xTln = (Rate->Tln-cl->TlnMin)*cl->rDeltaTln;
iTln = xTln;
RT0 = (cl->RT+iTln);
RT1 = RT0+1;
wTln1 = xTln-iTln;
wTln0 = 1-wTln1;
/* PUT INTO erg/gm/sec */
printf("Compton: %e\n",
Y->e * (
cl->R.Cool_Comp * ( Rate->T - cl->R.Tcmb )));
printf("Cool Brem HII %e\n",
Y->e * en_B * (
(wTln0*RT0->Cool_Brem_1+wTln1*RT1->Cool_Brem_1) * ( Y->HII )) );
printf("Cool Brem HeII %e\n",
Y->e * en_B * (
(wTln0*RT0->Cool_Brem_1+wTln1*RT1->Cool_Brem_1) * ( Y->HeII )) );
printf("Cool Brem HeIII %e\n",
Y->e * en_B * (
(wTln0*RT0->Cool_Brem_2+wTln1*RT1->Cool_Brem_2) * Y->HeIII ) );
printf("Radiative Recombination HII %e\n",
Y->e * en_B *
(wTln0*RT0->Cool_Radr_HII+wTln1*RT1->Cool_Radr_HII) * Y->HII * Rate->Radr_HII );
printf("Radiative Recombination HeII %e\n",
Y->e * en_B *
(wTln0*RT0->Cool_Radr_HeII+wTln1*RT1->Cool_Radr_HeII) * Y->HeII * Rate->Radr_HeII);
printf("Radiative Recombination HeIII %e\n",
Y->e * en_B *
(wTln0*RT0->Cool_Radr_HeIII+wTln1*RT1->Cool_Radr_HeIII) * Y->HeIII * Rate->Radr_HeIII);
printf("Collisional Ionization HI %e\n",
Y->e * en_B *
cl->R.Cool_Coll_HI * Y->HI * Rate->Coll_HI);
printf("Collisional Ionization HeI %e\n",
Y->e * en_B *
cl->R.Cool_Coll_HeI * Y->HeI * Rate->Coll_HeI);
printf("Collisional Ionization HeII %e\n",
Y->e * en_B *
cl->R.Cool_Coll_HeII * Y->HeII * Rate->Coll_HeII);
printf("Dielectric Recombination HeII %e\n",
Y->e * en_B * cl->R.Cool_Diel_HeII * Y->HeII * Rate->Diel_HeII);
printf("Line cooling HI %e\n",
Y->e * en_B *
(wTln0*RT0->Cool_Line_HI+wTln1*RT1->Cool_Line_HI) * Y->HI);
printf("Line cooling HeI %e\n",
Y->e * en_B *
(wTln0*RT0->Cool_Line_HeI+wTln1*RT1->Cool_Line_HeI) * Y->HeI);
printf("Line cooling HeII %e\n",
Y->e * en_B *
(wTln0*RT0->Cool_Line_HeII+wTln1*RT1->Cool_Line_HeII) * Y->HeII );
printf("Low T cooling (Z=0.001) %e\n",
en_B *
(wTln0*RT0->Cool_LowT+wTln1*RT1->Cool_LowT)*cl->R.Cool_LowTFactor*0.001);
}
void clPrintCoolFile( COOL *cl, PERBARYON *Y, RATE *Rate, double rho, FILE *fp ) {
/* Assumes clRates called previously */
/* erg /gram /sec */
double en_B=rho*CL_B_gm;
double xTln,wTln0,wTln1;
RATES_T *RT0,*RT1;
int iTln;
xTln = (Rate->Tln-cl->TlnMin)*cl->rDeltaTln;
iTln = xTln;
RT0 = (cl->RT+iTln);
RT1 = RT0+1;
wTln1 = xTln-iTln;
wTln0 = 1-wTln1;
/* PUT INTO erg/gm/sec */
fprintf(fp,"%e ",
Y->e * (
cl->R.Cool_Comp * ( Rate->T - cl->R.Tcmb )));
fprintf(fp,"%e ",
Y->e * en_B * (
(wTln0*RT0->Cool_Brem_1+wTln1*RT1->Cool_Brem_1) * ( Y->HII )) );
fprintf(fp,"%e ",
Y->e * en_B * (
(wTln0*RT0->Cool_Brem_1+wTln1*RT1->Cool_Brem_1) * ( Y->HeII )) );
fprintf(fp,"%e ",
Y->e * en_B * (
(wTln0*RT0->Cool_Brem_2+wTln1*RT1->Cool_Brem_2) * Y->HeIII ) );
fprintf(fp,"%e ",
Y->e * en_B *
(wTln0*RT0->Cool_Radr_HII+wTln1*RT1->Cool_Radr_HII) * Y->HII * Rate->Radr_HII );
fprintf(fp,"%e ",
Y->e * en_B *
(wTln0*RT0->Cool_Radr_HeII+wTln1*RT1->Cool_Radr_HeII) * Y->HeII * Rate->Radr_HeII);
fprintf(fp,"%e ",
Y->e * en_B *
(wTln0*RT0->Cool_Radr_HeIII+wTln1*RT1->Cool_Radr_HeIII) * Y->HeIII * Rate->Radr_HeIII);
fprintf(fp,"%e ",
Y->e * en_B *
cl->R.Cool_Coll_HI * Y->HI * Rate->Coll_HI);
fprintf(fp,"%e ",
Y->e * en_B *
cl->R.Cool_Coll_HeI * Y->HeI * Rate->Coll_HeI);
fprintf(fp,"%e ",
Y->e * en_B *
cl->R.Cool_Coll_HeII * Y->HeII * Rate->Coll_HeII);
fprintf(fp,"%e ",
Y->e * en_B * cl->R.Cool_Diel_HeII * Y->HeII * Rate->Diel_HeII);
fprintf(fp,"%e ",
Y->e * en_B *
(wTln0*RT0->Cool_Line_HI+wTln1*RT1->Cool_Line_HI) * Y->HI);
fprintf(fp,"%e ",
Y->e * en_B *
(wTln0*RT0->Cool_Line_HeI+wTln1*RT1->Cool_Line_HeI) * Y->HeI);
fprintf(fp,"%e ",
Y->e * en_B *
(wTln0*RT0->Cool_Line_HeII+wTln1*RT1->Cool_Line_HeII) * Y->HeII );
fprintf(fp,"%e\n",
en_B *
(wTln0*RT0->Cool_LowT+wTln1*RT1->Cool_LowT)*cl->R.Cool_LowTFactor*0.001);
}
void clAbunds( COOL *cl, PERBARYON *Y, RATE *Rate, double rho ) {
double en_B=rho*CL_B_gm;
double rcirrHI = (Rate->Coll_HI)/(Rate->Radr_HII);
double rcirrHeI = (Rate->Coll_HeI)/(Rate->Totr_HeII);
double rcirrHeII = (Rate->Coll_HeII)/(Rate->Radr_HeIII);
double rpirrHI = (Rate->Phot_HI)/(Rate->Radr_HII * en_B);
double rpirrHeI = (Rate->Phot_HeI)/(Rate->Totr_HeII * en_B);
double rpirrHeII = (Rate->Phot_HeII)/(Rate->Radr_HeIII * en_B);
double yHI = 0.;
double yHeI = 0.;
double yHeII = 0.;
double yH = cl->Y_H;
double yHe = cl->Y_He;
double yeMAX = cl->Y_eMAX;
double rye,ye;
double fHI,fHeI,fHeII,rfHe,yHI_old,yHeII_old;
int i;
for ( i=0 ; i<MAXABUNDITERATIONS ; i++ ) {
yHI_old = yHI;
yHeII_old = yHeII;
ye = (yeMAX-(yHI + 2 * yHeI + yHeII));
if (ye <= 0) {
Y->e = 0;
Y->HI = yH;
Y->HII = 0;
Y->HeI = yHe;
Y->HeII = 0;
Y->HeIII = 0;
Y->Total = yH + yHe;
return;
}
rye = 1/ye;
fHI = rcirrHI + rpirrHI * rye;
fHeI = rcirrHeI + rpirrHeI * rye;
rfHe = 1 / ( 1 + fHeI * (1+rcirrHeII+rpirrHeII*rye) );
yHI = yH / (1.0+fHI);
yHeI = yHe * rfHe;
yHeII = yHe * fHeI * rfHe;
/* fprintf(stderr,"Abund %g %g %g %g\n",yHI,yHeI,yHeII,ye);
fprintf(stderr," Rates %g %g %g \n",rcirrHI,rcirrHeI,rcirrHeII); */
if ( fabs(yHeII_old-yHeII) < EPS * yHeII && fabs(yHI_old-yHI) < EPS * yHI ) break;
}
Y->e = ye;
Y->HI = yHI;
Y->HII = yH / (1.0/fHI+1.0);
Y->HeI = yHeI;
Y->HeII = yHeII;
fHeII = rcirrHeII + rpirrHeII*rye;
Y->HeIII = yHe / ((1.0/fHeI+1.0)/fHeII+1.0);
Y->Total = Y->e + yH + yHe;
}
#define CL_Rgascode 8.2494e7
#define CL_Eerg_gm_degK CL_Rgascode
#define CL_ev_degK 1.0/1.1604e4
#define CL_Eerg_gm_ev CL_Eerg_gm_degK/CL_ev_degK
#define CL_Eerg_gm_degK3_2 1.5*CL_Eerg_gm_degK
/*
* Though 13.6eV is lost to the Gas as radiation during H recombination, calculating the
* Energy using u = E per unit mass = 3/2 n/rho k T requires we don't subtract it there.
* This formulation is useful because then pressure = 2/3 u rho.
* Instead we subtract the 13.6eV for H collisional ionization which actually
* removes no energy from the Gas ( similarly for Helium )
* It also means photoionization doesn't add the 13.6eV, only the excess.
*/
double clThermalEnergy( double Y_Total, double T ) {
return Y_Total*CL_Eerg_gm_degK3_2*T;
}
double clTemperature( double Y_Total, double E ) {
return E/(Y_Total*CL_Eerg_gm_degK3_2);
}
double clTemperaturePrimordial( COOL *cl, double Y_HI, double Y_HeI, double Y_HeII, double E ) {
return clTemperature( 2*cl->Y_H - Y_HI + 3*cl->Y_He - 2*Y_HeI - Y_HeII, E );
}
/*-----------------------------------------------------------------
* Collisional Ionization rates
*-----------------------------------------------------------------*/
/* H + e- -> H+ + 2e- Janev et al. 1987 (Abel 1996) */
double clRateCollHI( double T ) {
double TL,arg;
TL = log(T*CL_eV_per_K);
arg = -32.713967867 + TL*(13.536556 + TL*(-5.73932875 +
TL*(1.56315498 +
TL*(-0.2877056 + TL*(3.48255977e-2 + TL*(-2.63197617e-3 +
TL*(1.11954395e-4 + TL*(-2.03914985e-6))))))));
if (arg < CL_MAX_NEG_EXP_ARG) return 0;
return exp ( arg );
}
/* He + e- -> He+ + 2e- Janev et al. 1987 (Abel 1996) */
double clRateCollHeI( double T ) {
double TL,arg;
TL = log(T*CL_eV_per_K);
arg = -44.09864886 + TL*(23.91596563 + TL*(-10.7532302 +
TL*(3.05803875 +
TL*(-0.56851189 + TL*(6.79539123e-2 + TL*(-5.00905610e-3 +
TL*(2.06723616e-4 + TL*(-3.64916141e-6))))))));
if (arg < CL_MAX_NEG_EXP_ARG) return 0;
return exp( arg );
}
/* He+ + e- -> He++ + 2e- Aladdin Database 1989 (Abel 1996) */
double clRateCollHeII( double T ) {
double TL,arg;
TL = log(T*CL_eV_per_K);
arg = -68.71040990 + TL*(43.93347633 + TL*(-18.4806699 +
TL*(4.70162649 +
TL*(-0.76924663 + TL*(8.113042e-2 + TL*(-5.32402063e-3 +
TL*(1.97570531e-4 + TL*(-3.16558106e-6))))))));
if (arg < CL_MAX_NEG_EXP_ARG) return 0;
return exp( arg );
}
/*-----------------------------------------------------------------
* Radiative Recombination rates
*-----------------------------------------------------------------*/
/* H+ + e- -> H + gam Verner & Ferland 1996 */
double clRateRadrHII( double T ) {
double Tsq = sqrt(T);
return 7.982e-11/( Tsq*0.563615 *
pow(1+Tsq*0.563615,0.252) * pow(1+Tsq*1.192167e-3,1.748));
}
/* He+ + e- -> He + gam radiative Verner & Ferland 1996 */
double clRateRadrHeII( double T ) {
/*
* Note that these functions do not meet perfectly at 1e6 -- 2% difference
* The derivatives are different there also: So the apparent error is large
*/
double Tsq = sqrt(T);
if (T < 1e6)
return 3.294e-11/( Tsq*0.253673 *
pow(1+Tsq*0.253673,0.309) * pow(1+Tsq*1.649348e-4,1.691));
else
return 9.356e-10/( Tsq*4.841607 *
pow(1+Tsq*4.841607,0.2108) * pow(1+Tsq*4.628935e-4,1.7892));
}
/* He+ + e- -> He + gam dielectronic Aldovandi&Pequignot 1973 (Black 1981) */
double clRateDielHeII( double T ) {
double T_inv = 1.0/T,arg;
arg = -4.7e5*T_inv;
if (arg < CL_MAX_NEG_EXP_ARG) return 0;
return 1.9e-3*pow(T,-1.5)*exp(arg)*(1+0.3*exp(-9.4e4*T_inv));
}
/* He++ + e- -> He+ + gam Verner & Ferland 1996 */
double clRateRadrHeIII( double T ) {
double Tsq = sqrt(T);
return 1.891e-10/( Tsq*0.326686 *
pow(1+Tsq*0.326686,0.2476) * pow(1+Tsq*6.004084e-4,1.7524));
}
/*-----------------------------------------------------------------
* Bremsstrahlung
*-----------------------------------------------------------------*/
#define CL_Cbremss1 1.426e-27
#define CL_al 0.79464
#define CL_bl 0.1243
#define CL_ar 2.13164
#define CL_br (-0.1240)
double clCoolBrem1( double T ) {
double Tlog10, Tsq;
Tlog10 = log10(T);
Tsq = sqrt(T);
if (T < 3.2e5)
return Tsq*CL_Cbremss1*(CL_al+CL_bl*Tlog10)*CL_B_gm;
else
return Tsq*CL_Cbremss1*(CL_ar+CL_br*Tlog10)*CL_B_gm;
}
#define CL_alog4 0.602059991
#define CL_alII (4.0*(CL_al-CL_bl*CL_alog4))
#define CL_blII (4.0*CL_bl)
#define CL_arII (4.0*(CL_ar-CL_br*CL_alog4))
#define CL_brII (4.0*CL_br)
double clCoolBrem2( double T ) {
double Tlog10, Tsq;
Tlog10 = log10(T);
Tsq = sqrt(T);
if (T<12.8e5)
return Tsq*CL_Cbremss1*(CL_alII+CL_blII*Tlog10)*CL_B_gm;
else
return Tsq*CL_Cbremss1*(CL_arII+CL_brII*Tlog10)*CL_B_gm;
}
/*-----------------------------------------------------------------
* Cooling multiplier for radiative recombination
*-----------------------------------------------------------------*/
#define CL_aHII 0.0215964
#define CL_b 0.270251
double clCoolRadrHII( double T ) {
double Tpow;
Tpow=pow(T,CL_b);
/* return CL_B_gm*(CL_eHI+exp(-CL_aHII*Tpow)*CL_k_Boltzmann*T); */
/* Though 13.6eV is lost to the Gas as radiation, calculating the
* Energy using u = 3/2 k T requires we don't subtract it here.
*/
return CL_B_gm*(exp(-CL_aHII*Tpow)*CL_k_Boltzmann*T);
}
double clCoolRadrHeII( double T ) {
double Tpow;
Tpow=pow(T,CL_b);
/* return CL_B_gm*(CL_eHeI+exp(-(CL_aHII*pow(13.6/24.59,CL_b))*Tpow)*CL_k_Boltzmann*T); */
return CL_B_gm*(exp(-(CL_aHII*pow(13.6/24.59,CL_b))*Tpow)*CL_k_Boltzmann*T);
}
double clCoolRadrHeIII( double T ) {
double Tpow;
Tpow=pow(T,CL_b);
/* return CL_B_gm*(CL_eHeII+exp(-(CL_aHII*pow(13.6/54.42,CL_b))*Tpow)*CL_k_Boltzmann*T); */
return CL_B_gm*(exp(-(CL_aHII*pow(13.6/54.42,CL_b))*Tpow)*CL_k_Boltzmann*T);
}
/*-----------------------------------------------------------------
* Line Cooling
*-----------------------------------------------------------------*/
/* CEN (1992, Ap.J.Suppl 78,341) ADVOCATES MULTIPLYING EACH OF
* THESE RATES BY Cen_correctn - HE CLAIMS THIS GIVES THE RIGHT
* HIGH T LIMIT FOR PROCESSES INVOLVING A FREE EL INTERACTING
* WITH AN ORBITAL ELECTRON ?? */
#define CL_aHI 7.5e-19
#define CL_bHI 1.18348e05
double clCoolLineHI( double T ) {
double T_inv, arg;
double Cen_correctn = 1.0/(1.0+sqrt(T/1.0e5));
T_inv=1.0/T;
arg = -CL_bHI*T_inv;
if (arg < CL_MAX_NEG_EXP_ARG) return 0;
return CL_B_gm*CL_aHI*exp( arg )*Cen_correctn;
}
#define CL_aHeI 9.10e-27
#define CL_bHeI 1.3179e04
#define CL_p_HeI 0.1687
double clCoolLineHeI( double T ) {
double T_inv,arg;
double Cen_correctn = 1.0/(1.0+sqrt(T/1.0e5));
T_inv=1.0/T;
arg = -CL_bHeI*T_inv;
if (arg < CL_MAX_NEG_EXP_ARG) return 0;
return CL_B_gm*CL_aHeI*exp(-CL_bHeI*T_inv)*pow(T_inv,CL_p_HeI)*Cen_correctn;
}
#define CL_aHeII 5.54e-17
#define CL_bHeII 4.73638e05
#define CL_p_HeII 0.397
double clCoolLineHeII( double T ) {
double T_inv,arg;
double Cen_correctn = 1.0/(1.0+sqrt(T/1.0e5));
T_inv=1.0/T;
arg = -CL_bHeII*T_inv;
if (arg < CL_MAX_NEG_EXP_ARG) return 0;
return CL_B_gm*CL_aHeII*exp(-CL_bHeII*T_inv)*pow(T_inv,CL_p_HeII)*Cen_correctn;
}
double clCoolLowT( double T ) {
double x;
/* Cooling Rate for low T, fit from Bromm et al. MNRAS, 328, 969 (Figure 1). by Maschenko */
/* Fit for metallicity Z = 0.001 -- scales linearly with Z */
/* Returns cooling in erg cm^-3 s^-1 (after multiplied by n_H ^2) */
/* Code uses erg g^-1 s^-1 so need to multiply the return value by Y_H^2 n_B * B_gm */
if (T > 1e4 || T <= 10.001) return 0;
x = log10(log10(log10(T)));
return pow(10.0,-27.81 + 2.928*x - 0.6982*x*x);
}
/* Returns Heating - Cooling excluding External Heating, units of ergs s^-1 g^-1
Public interface CoolEdotInstantCode */
double clEdotInstant( COOL *cl, PERBARYON *Y, RATE *Rate, double rho,
double ZMetal, double *dEdotHeat, double *dEdotCool )
{
double en_B = rho*CL_B_gm;
double xTln,wTln0,wTln1;
RATES_T *RT0,*RT1;
int iTln;
double Edot,ne,LowTCool;
ne = Y->e*en_B;
xTln = (Rate->Tln-cl->TlnMin)*cl->rDeltaTln;
iTln = xTln;
RT0 = (cl->RT+iTln);
RT1 = RT0+1;
wTln1 = (xTln-iTln);
wTln0 = (1-wTln1);
#define DTFRACLOWTCOOL 0.25
if (Rate->T > cl->R.Tcmb*(1+DTFRACLOWTCOOL))
LowTCool = (wTln0*RT0->Cool_LowT+wTln1*RT1->Cool_LowT)*cl->R.Cool_LowTFactor*en_B*ZMetal;
else if (Rate->T < cl->R.Tcmb*(1-DTFRACLOWTCOOL))