-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradiation.f90
2026 lines (1631 loc) · 106 KB
/
radiation.f90
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
module radiation
use precision, only: dp
use input, only: pi, bb_source_temperature, pl_source_index, S_star, R_solar, L_solar, pl_input_flux,&
ion_freq_HI, ion_freq_HeI, ion_freq_HeII, &
sigma_HI_at_ion_freq, sigma_HeI_at_ion_freq, sigma_HeII_at_ion_freq
use cgsconstants, only: sigma_SB, hplanck, k_B, two_pi_over_c_square
use romberg, only: scalar_romberg, vector_romberg, romberg_initialisation
use type, only: photrates
use array, only: bb_photo_thick_integrand, bb_photo_thin_integrand, &
pl_photo_thick_integrand, pl_photo_thin_integrand, &
bb_heat_thick_integrand_HI, bb_heat_thick_integrand_HeI, &
bb_heat_thick_integrand_HeII, bb_heat_thin_integrand_HI, &
bb_heat_thin_integrand_HeI, bb_heat_thin_integrand_HeII, &
pl_heat_thick_integrand_HI, pl_heat_thick_integrand_HeI, &
pl_heat_thick_integrand_HeII, pl_heat_thin_integrand_HI, &
pl_heat_thin_integrand_HeI, pl_heat_thin_integrand_HeII, &
bb_photo_thick_table, bb_photo_thin_table, &
pl_photo_thick_table, pl_photo_thin_table, &
bb_heat_thick_table, bb_heat_thin_table, &
pl_heat_thick_table, pl_heat_thin_table
implicit none
integer,parameter :: NumFreq = 512 ! Number of integration points in each of the frequency bins
integer,parameter :: NumTau = 2000 ! Number of table points for the optical depth
integer,parameter :: NumBndin1 = 1 ! Number of frequency sub-bins in interval 1
integer,parameter :: NumBndin2 = 26 ! Number of frequency sub-bins in interval 2
integer,parameter :: NumBndin3 = 20 ! Number of frequency sub-bins in interval 3
integer,parameter :: NumFreqBnd=NumBndin1+NumBndin2+NumBndin3 ! Total number of frequency bins
integer,parameter :: NumheatBin=NumBndin1+NumBndin2*2+NumBndin3*3 ! Total number of heating bins
! Parameters defining the optical depth entries in the table.
real(kind=dp),parameter :: minlogtau = -20.0 ! Table position starts at log10(minlogtau)
real(kind=dp),parameter :: maxlogtau = 4.0 ! Table position ends at log10(maxlogtau)
real(kind=dp),parameter :: dlogtau = (maxlogtau-minlogtau)/real(NumTau) ! dlogtau is the step size in log10(tau)
! Some boring variables
real(kind=dp), dimension(1:3) :: CR1, CR2, bR1, dR1, aR2, bR2, y1R, y2R
real(kind=dp) :: xeb
! Stellar properties
real(kind=dp) :: R_star
real(kind=dp) :: L_star
real(kind=dp) :: bb_total_flux ! black body total flux
! Power law source properties
real(kind=dp) :: pl_minfreq ! Minimum frequency for integration of total power
real(kind=dp) :: pl_maxfreq ! Maximum frequency for integration of total power
real(kind=dp) :: pl_scaling ! The scaling of the flux
real(kind=dp) :: Edd_Efficiency ! Eddinton efficieny
real(kind=dp) :: source_ionzing_photon_rate ! The rate of ionizing photon generated from the source
real(kind=dp), dimension(:), allocatable :: delta_freq ! Frequency width of integration
real(kind=dp), dimension(:), allocatable :: freq_max ! Maximum freqeucny of integration
real(kind=dp), dimension(:), allocatable :: freq_min ! Minimum freqeucny of integration
! Power law fit parameter for frequency range 1:3
real(kind=dp), dimension(:), allocatable :: pl_index_cross_section_HI ! Power law index of cross section of HI
real(kind=dp), dimension(:), allocatable :: pl_index_cross_section_HeI ! Power law index of cross section of HeI
real(kind=dp), dimension(:), allocatable :: pl_index_cross_section_HeII ! Power law index of cross section of HeII
! Cross section of atoms
real(kind=dp), dimension(:), allocatable :: sigma_HI ! Cross section of HI
real(kind=dp), dimension(:), allocatable :: sigma_HeI ! Cross section of HeI
real(kind=dp), dimension(:), allocatable :: sigma_HeII ! Cross section of HeII
! Parameters related to fraction of ionization and heating from different species
real(kind=dp), dimension(:), allocatable :: f1ion_HI ! Parameters related to ionization
real(kind=dp), dimension(:), allocatable :: f1ion_HeI ! Parameters related to ionization
real(kind=dp), dimension(:), allocatable :: f1ion_HeII ! Parameters related to ionization
real(kind=dp), dimension(:), allocatable :: f2ion_HI ! Parameters related to ionization
real(kind=dp), dimension(:), allocatable :: f2ion_HeI ! Parameters related to ionization
real(kind=dp), dimension(:), allocatable :: f2ion_HeII ! Parameters related to ionization
real(kind=dp), dimension(:), allocatable :: f2heat_HI ! Parameters related to heating
real(kind=dp), dimension(:), allocatable :: f2heat_HeI ! Parameters related to heating
real(kind=dp), dimension(:), allocatable :: f2heat_HeII ! Parameters related to heating
real(kind=dp), dimension(:), allocatable :: f1heat_HI ! Parameters related to heating
real(kind=dp), dimension(:), allocatable :: f1heat_HeI ! Parameters related to heating
real(kind=dp), dimension(:), allocatable :: f1heat_HeII ! Parameters related to heating
! tablepos helps to locate correct position of the photoionization and heating tables
type tablepos
real(kind=dp), dimension(NumFreqBnd) :: tau
real(kind=dp), dimension(NumFreqBnd) :: odpos
real(kind=dp), dimension(NumFreqBnd) :: residual
integer, dimension(NumFreqBnd) :: ipos
integer, dimension(NumFreqBnd) :: ipos_p1
end type tablepos
contains
subroutine photo_table_setup()
!
call setup_scalingfactors ()
call romberg_initialisation(NumFreq)
call spec_diagnosis ()
call spec_integration ()
end subroutine photo_table_setup
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Calculates properties of the black body spectrum
subroutine spec_diagnosis ()
integer :: i_freq
real(kind=dp) :: h_over_kT, freq_step
real(kind=dp) :: bb_photo_flux, pl_photo_flux
real(kind=dp) :: S_star_unscaled, S_scaling
real(kind=dp) :: L_star_ion ! Black body ionizing luminosity
real(kind=dp), dimension(0:NumFreq) :: frequency, weight
real(kind=dp), dimension(0:NumFreq) :: bb_photon, bb_energy
real(kind=dp), dimension(0:NumFreq) :: pl_photon, pl_energy
! Find total flux (Stefan-Boltzmann law)
bb_total_flux = sigma_SB*bb_source_temperature**4
! Assign some fiducial values for R_star and L_star,
! these are scaled to correspond to S_star in routine spec_diag
R_star = R_solar
L_star = R_star*R_star*(4.0d0*pi*bb_total_flux)
! This is h/kT (unit 1/Hz, or sec)
h_over_kT = hplanck/(k_B*bb_source_temperature)
! Frequency step width
freq_step = (freq_max(NumFreqBnd)-freq_min(1))/real(NumFreq)
! Fill the arrays (frequency, weight, spectrum)
do i_freq = 0,NumFreq
frequency(i_freq) = ion_freq_HI+freq_step*real(i_freq)
weight(i_freq) = freq_step
enddo
do i_freq = 0,NumFreq
if (frequency(i_freq)*h_over_kT .le. 709.0_dp) then
bb_photon(i_freq) = two_pi_over_c_square*frequency(i_freq)*frequency(i_freq)/ &
(exp(frequency(i_freq)*h_over_kT)-1.0_dp)
else
bb_photon(i_freq) = two_pi_over_c_square*frequency(i_freq)*frequency(i_freq)/ &
(exp((frequency(i_freq)*h_over_kT)/2.0_dp))/ &
(exp((frequency(i_freq)*h_over_kT)/2.0_dp))
endif
enddo
! Black-body flux (photon sense)
bb_photo_flux = scalar_romberg(bb_photon,weight,NumFreq,NumFreq,0)
S_star_unscaled = 4.0*pi*R_star*R_star*bb_photo_flux
S_scaling = S_star/S_star_unscaled
R_star = sqrt(S_scaling)*R_star
L_star = S_scaling*L_star
!Find out the power law scaling factor for the case Eddinton luminosity efficiency is provided.
do i_freq=0,NumFreq
! this power-law is in number of photon sense
pl_photon(i_freq) = frequency(i_freq)**(-pl_source_index)
enddo
pl_photo_flux = scalar_romberg(pl_photon,weight,NumFreq,NumFreq,0) ! This power-law flux is not normalized (photon sense).
pl_scaling = pl_input_flux/pl_photo_flux
end subroutine spec_diagnosis
! Generate photoionization tables and heating tables
subroutine spec_integration ()
implicit none
integer :: i_freq, i_tau, i_subband
real(kind=dp) :: R_star2, h_over_kT
real(kind=dp), dimension(0:NumTau) :: tau
real(kind=dp), dimension(0:NumTau) :: answer
real(kind=dp), dimension(0:NumFreq) :: exponent_HI
real(kind=dp), dimension(0:NumFreq) :: exponent_HeI
real(kind=dp), dimension(0:NumFreq) :: exponent_HeII
real(kind=dp), dimension(0:NumFreq) :: frequency
real(kind=dp), dimension(0:NumFreq, 0:NumTau) :: weight
! Photoionization integrand as a function of frequency and tau
allocate(bb_photo_thick_integrand(0:NumFreq, 0:NumTau))
allocate(bb_photo_thin_integrand(0:NumFreq, 0:NumTau))
allocate(pl_photo_thick_integrand(0:NumFreq, 0:NumTau))
allocate(pl_photo_thin_integrand(0:NumFreq, 0:NumTau))
! Heating integrand as a function of frequency and tau
allocate(bb_heat_thick_integrand_HI(0:NumFreq, 0:NumTau))
allocate(bb_heat_thick_integrand_HeI(0:NumFreq, 0:NumTau))
allocate(bb_heat_thick_integrand_HeII(0:NumFreq, 0:NumTau))
allocate(bb_heat_thin_integrand_HI(0:NumFreq, 0:NumTau))
allocate(bb_heat_thin_integrand_HeI(0:NumFreq, 0:NumTau))
allocate(bb_heat_thin_integrand_HeII(0:NumFreq, 0:NumTau))
allocate(pl_heat_thick_integrand_HI(0:NumFreq, 0:NumTau))
allocate(pl_heat_thick_integrand_HeI(0:NumFreq, 0:NumTau))
allocate(pl_heat_thick_integrand_HeII(0:NumFreq, 0:NumTau))
allocate(pl_heat_thin_integrand_HI(0:NumFreq, 0:NumTau))
allocate(pl_heat_thin_integrand_HeI(0:NumFreq, 0:NumTau))
allocate(pl_heat_thin_integrand_HeII(0:NumFreq, 0:NumTau))
! Photoionization table as a function of photo sub-bin and tau
allocate(bb_photo_thick_table(0:NumTau, 1:NumFreqBnd))
allocate(bb_photo_thin_table(0:NumTau, 1:NumFreqBnd))
allocate(pl_photo_thick_table(0:NumTau, 1:NumFreqBnd))
allocate(pl_photo_thin_table(0:NumTau, 1:NumFreqBnd))
! Heating table as a function of heating sub-bin and tau
allocate(bb_heat_thick_table(0:NumTau, 1:NumheatBin))
allocate(bb_heat_thin_table(0:NumTau, 1:NumheatBin))
allocate(pl_heat_thick_table(0:NumTau, 1:NumheatBin))
allocate(pl_heat_thin_table(0:NumTau, 1:NumheatBin))
! This is h/kT
h_over_kT=hplanck/(k_B*bb_source_temperature)
! This is R_star^2
R_star2=R_star*R_star
! fill the optical depth array used to fill the tables
! it is filled in NumTau logarithmic steps
! from minlogtau to maxlogtau
do i_tau = 1,NumTau
tau(i_tau) = 10.0**(minlogtau+dlogtau*real(i_tau-1))
enddo
! Position zero corresponds to zero optical depth
tau(0)=0.0
! In frequency band 1, fill in integrands and make tables
! Go through all the sub-bin in band 1
do i_subband=1,NumBndin1
! Assign values to exponent array
do i_freq=0,NumFreq
frequency(i_freq) = freq_min(i_subband)+delta_freq(i_subband)*real(i_freq)
exponent_HI(i_freq) = ((frequency(i_freq)/freq_min(i_subband))**(-pl_index_cross_section_HI(i_subband)))
enddo
! Loop through the tau partition
do i_tau=0,NumTau
! Loop through the frequency partition
do i_freq=0,NumFreq
weight(i_freq,i_tau) = delta_freq(i_subband)
! Assign values to the photo integrands
if (tau(i_tau)*exponent_HI(i_freq) < 700.0) then
bb_photo_thick_integrand(i_freq,i_tau) = 4.0_dp*pi*R_star2*two_pi_over_c_square*frequency(i_freq)* &
frequency(i_freq)*exp(-tau(i_tau)*exponent_HI(i_freq))/ &
(exp(frequency(i_freq)*h_over_kT)-1.0)
!write(*,*)R_star2,frequency(i_freq),tau(i_tau)
bb_photo_thin_integrand(i_freq,i_tau) = 4.0_dp*pi*R_star2*two_pi_over_c_square*frequency(i_freq)* &
frequency(i_freq)*exponent_HI(i_freq)*exp(-tau(i_tau)* &
exponent_HI(i_freq))/(exp(frequency(i_freq)*h_over_kT)-1.0)
pl_photo_thick_integrand(i_freq,i_tau) = pl_scaling*frequency(i_freq)**(-pl_source_index)* &
exp(-tau(i_tau)*exponent_HI(i_freq))
pl_photo_thin_integrand(i_freq,i_tau) = pl_scaling*frequency(i_freq)**(-pl_source_index)*exponent_HI(i_freq) &
*exp(-tau(i_tau)*exponent_HI(i_freq))
else
bb_photo_thick_integrand(i_freq,i_tau) = 0.0
bb_photo_thin_integrand(i_freq,i_tau) = 0.0
pl_photo_thick_integrand(i_freq,i_tau) = 0.0
pl_photo_thin_integrand(i_freq,i_tau) = 0.0
endif
! Assign values to the heating integrands
bb_heat_thick_integrand_HI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HI)* &
bb_photo_thick_integrand(i_freq,i_tau)
bb_heat_thin_integrand_HI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HI)* &
bb_photo_thin_integrand(i_freq,i_tau)
pl_heat_thick_integrand_HI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HI)* &
pl_photo_thick_integrand(i_freq,i_tau)
pl_heat_thin_integrand_HI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HI)* &
pl_photo_thin_integrand(i_freq,i_tau)
enddo
enddo
! Make photo tables
call vector_romberg (bb_photo_thick_integrand,weight,NumFreq,NumFreq,NumTau,answer)
bb_photo_thick_table(:,1) = answer
call vector_romberg (bb_photo_thin_integrand,weight,NumFreq,NumFreq,NumTau,answer)
bb_photo_thin_table(:,1) = answer
call vector_romberg (pl_photo_thick_integrand,weight,NumFreq,NumFreq,NumTau,answer)
pl_photo_thick_table(:,1) = answer
call vector_romberg (pl_photo_thin_integrand,weight,NumFreq,NumFreq,NumTau,answer)
pl_photo_thin_table(:,1) = answer
! Make heating tables
call vector_romberg (bb_heat_thick_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thick_table(:,1) = answer
call vector_romberg (bb_heat_thin_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thin_table(:,1) = answer
call vector_romberg (pl_heat_thick_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thick_table(:,1) = answer
call vector_romberg (pl_heat_thin_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thin_table(:,1) = answer
enddo
! In frequency band 2, fill in integrands and make tables
! Go through all the sub-bin in band 2
do i_subband=NumBndin1+1,NumBndin1+NumBndin2
! Assign values to exponent array
do i_freq=0,NumFreq
frequency(i_freq) = freq_min(i_subband)+delta_freq(i_subband)*real(i_freq)
exponent_HeI(i_freq) = ((frequency(i_freq)/freq_min(i_subband))**(-pl_index_cross_section_HeI(i_subband)))
enddo
! Loop through the tau partition
do i_tau=0,NumTau
! Loop through the frequency partition
do i_freq=0,NumFreq
weight(i_freq,i_tau) = delta_freq(i_subband)
! Assign values to the photo integrands
if (tau(i_tau)*exponent_HeI(i_freq) < 700.0) then
bb_photo_thick_integrand(i_freq,i_tau) = 4.0_dp*pi*R_star2*two_pi_over_c_square*frequency(i_freq)* &
frequency(i_freq)*exp(-(tau(i_tau)*exponent_HeI(i_freq)))/ &
(exp(frequency(i_freq)*h_over_kT)-1.0)
bb_photo_thin_integrand(i_freq,i_tau) = 4.0_dp*pi*R_star2*two_pi_over_c_square*frequency(i_freq)* &
frequency(i_freq)* exponent_HeI(i_freq)*exp(-(tau(i_tau)* &
exponent_HeI(i_freq)))/(exp(frequency(i_freq)*h_over_kT)-1.0)
pl_photo_thick_integrand(i_freq,i_tau) = pl_scaling*frequency(i_freq)**(-pl_source_index)* &
exp(-tau(i_tau)*exponent_HeI(i_freq))
pl_photo_thin_integrand(i_freq,i_tau) = pl_scaling*frequency(i_freq)**(-pl_source_index)*exponent_HeI(i_freq)* &
exp(-tau(i_tau)*exponent_HeI(i_freq))
else
bb_photo_thick_integrand(i_freq,i_tau) = 0.0
bb_photo_thin_integrand(i_freq,i_tau) = 0.0
pl_photo_thick_integrand(i_freq,i_tau) = 0.0
pl_photo_thin_integrand(i_freq,i_tau) = 0.0
endif
! Assign values to the heating integrands
bb_heat_thick_integrand_HI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HI)* &
bb_photo_thick_integrand(i_freq,i_tau)
bb_heat_thick_integrand_HeI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HeI)* &
bb_photo_thick_integrand(i_freq,i_tau)
bb_heat_thin_integrand_HI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HI)* &
bb_photo_thin_integrand(i_freq,i_tau)
bb_heat_thin_integrand_HeI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HeI)* &
bb_photo_thin_integrand(i_freq,i_tau)
pl_heat_thick_integrand_HI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HI)* &
pl_photo_thick_integrand(i_freq,i_tau)
pl_heat_thick_integrand_HeI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HeI)* &
pl_photo_thick_integrand(i_freq,i_tau)
pl_heat_thin_integrand_HI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HI)* &
pl_photo_thin_integrand(i_freq,i_tau)
pl_heat_thin_integrand_HeI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HeI)* &
pl_photo_thin_integrand(i_freq,i_tau)
enddo
enddo
! Make photo tables
call vector_romberg (bb_photo_thick_integrand,weight,NumFreq,NumFreq,NumTau,answer)
bb_photo_thick_table(:,i_subband) = answer
call vector_romberg (bb_photo_thin_integrand,weight,NumFreq,NumFreq,NumTau,answer)
bb_photo_thin_table(:,i_subband) = answer
call vector_romberg (pl_photo_thick_integrand,weight,NumFreq,NumFreq,NumTau,answer)
pl_photo_thick_table(:,i_subband) = answer
call vector_romberg (pl_photo_thin_integrand,weight,NumFreq,NumFreq,NumTau,answer)
pl_photo_thin_table(:,i_subband) = answer
! Make heating tables
call vector_romberg (bb_heat_thick_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thick_table(:,i_subband*2-2) = answer
call vector_romberg (bb_heat_thick_integrand_HeI,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thick_table(:,i_subband*2-1) = answer
call vector_romberg (bb_heat_thin_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thin_table(:,i_subband*2-2) = answer
call vector_romberg (bb_heat_thin_integrand_HeI,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thin_table(:,i_subband*2-1) = answer
call vector_romberg (pl_heat_thick_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thick_table(:,i_subband*2-2) = answer
call vector_romberg (pl_heat_thick_integrand_HeI,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thick_table(:,i_subband*2-1) = answer
call vector_romberg (pl_heat_thin_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thin_table(:,i_subband*2-2) = answer
call vector_romberg (pl_heat_thin_integrand_HeI,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thin_table(:,i_subband*2-1) = answer
enddo
! In frequency band 3, fill in integrands and make tables
! Go through all the sub-bin in band 3
do i_subband=NumBndin1+NumBndin2+1,NumBndin1+NumBndin2+NumBndin3
! Assign values to exponent array
do i_freq=0,NumFreq
frequency(i_freq) = freq_min(i_subband)+delta_freq(i_subband)*real(i_freq)
exponent_HeII(i_freq) = ((frequency(i_freq)/freq_min(i_subband))**(-pl_index_cross_section_HeII(i_subband)))
enddo
! Loop through the tau partition
do i_tau=0,NumTau
! Loop through the frequency partition
do i_freq=0,NumFreq
weight(i_freq,i_tau) = delta_freq(i_subband)
! Assign values to the photo integrands
if (tau(i_tau)*exponent_HeII(i_freq) < 700.0) then
! GM/130729 For these high frequencies this
! BB exponential term can overflow. Test for this.
if (frequency(i_freq)*h_over_kT < 700.0) then
bb_photo_thick_integrand(i_freq,i_tau) = 4.0_dp*pi*R_star2*two_pi_over_c_square*frequency(i_freq)* &
frequency(i_freq)*exp(-tau(i_tau)*exponent_HeII(i_freq))/ &
(exp(frequency(i_freq)*h_over_kT)-1.0)
bb_photo_thin_integrand(i_freq,i_tau) = 4.0_dp*pi*R_star2*two_pi_over_c_square*frequency(i_freq)* &
frequency(i_freq)*exponent_HeII(i_freq)*exp(-tau(i_tau)* &
exponent_HeII(i_freq))/(exp(frequency(i_freq)*h_over_kT)-1.0)
else
bb_photo_thick_integrand(i_freq,i_tau) = 0.0
bb_photo_thin_integrand(i_freq,i_tau) = 0.0
endif
pl_photo_thick_integrand(i_freq,i_tau) = pl_scaling*frequency(i_freq)**(-pl_source_index)* &
exp(-tau(i_tau)*exponent_HeII(i_freq))
pl_photo_thin_integrand(i_freq,i_tau) = pl_scaling*frequency(i_freq)**(-pl_source_index)*exponent_HeII(i_freq)* &
exp(-tau(i_tau)*exponent_HeII(i_freq))
else
bb_photo_thick_integrand(i_freq,i_tau) = 0.0
bb_photo_thin_integrand(i_freq,i_tau) = 0.0
pl_photo_thick_integrand(i_freq,i_tau) = 0.0
pl_photo_thin_integrand(i_freq,i_tau) = 0.0
endif
! Assign values to the heating integrands
bb_heat_thick_integrand_HI(i_freq,i_tau) = 4.0_dp*pi*hplanck*(frequency(i_freq)-ion_freq_HI)* &
bb_photo_thick_integrand(i_freq,i_tau)
bb_heat_thick_integrand_HeI(i_freq,i_tau) = 4.0_dp*pi*hplanck*(frequency(i_freq)-ion_freq_HeI)* &
bb_photo_thick_integrand(i_freq,i_tau)
bb_heat_thick_integrand_HeII(i_freq,i_tau) = 4.0_dp*pi*hplanck*(frequency(i_freq)-ion_freq_HeII)* &
bb_photo_thick_integrand(i_freq,i_tau)
bb_heat_thin_integrand_HI(i_freq,i_tau) = 4.0_dp*pi*hplanck*(frequency(i_freq)-ion_freq_HI)* &
bb_photo_thin_integrand(i_freq,i_tau)
bb_heat_thin_integrand_HeI(i_freq,i_tau) = 4.0_dp*pi*hplanck*(frequency(i_freq)-ion_freq_HeI)* &
bb_photo_thin_integrand(i_freq,i_tau)
bb_heat_thin_integrand_HeII(i_freq,i_tau) = 4.0_dp*pi*hplanck*(frequency(i_freq)-ion_freq_HeII)* &
bb_photo_thin_integrand(i_freq,i_tau)
pl_heat_thick_integrand_HI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HI)* &
pl_photo_thick_integrand(i_freq,i_tau)
pl_heat_thick_integrand_HeI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HeI)* &
pl_photo_thick_integrand(i_freq,i_tau)
pl_heat_thick_integrand_HeII(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HeII)* &
pl_photo_thick_integrand(i_freq,i_tau)
pl_heat_thin_integrand_HI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HI)* &
pl_photo_thin_integrand(i_freq,i_tau)
pl_heat_thin_integrand_HeI(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HeI)* &
pl_photo_thin_integrand(i_freq,i_tau)
pl_heat_thin_integrand_HeII(i_freq,i_tau) = hplanck*(frequency(i_freq)-ion_freq_HeII)* &
pl_photo_thin_integrand(i_freq,i_tau)
enddo
enddo
! Make photo tables
call vector_romberg (bb_photo_thick_integrand,weight,NumFreq,NumFreq,NumTau,answer)
bb_photo_thick_table(:,i_subband) = answer
call vector_romberg (bb_photo_thin_integrand,weight,NumFreq,NumFreq,NumTau,answer)
bb_photo_thin_table(:,i_subband) = answer
call vector_romberg (pl_photo_thick_integrand,weight,NumFreq,NumFreq,NumTau,answer)
pl_photo_thick_table(:,i_subband) = answer
call vector_romberg (pl_photo_thin_integrand,weight,NumFreq,NumFreq,NumTau,answer)
pl_photo_thin_table(:,i_subband) = answer
! Make heating tables
call vector_romberg (bb_heat_thick_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thick_table(:,i_subband*3-NumBndin2-4) = answer
call vector_romberg (bb_heat_thick_integrand_HeI,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thick_table(:,i_subband*3-NumBndin2-3) = answer
call vector_romberg (bb_heat_thick_integrand_HeII,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thick_table(:,i_subband*3-NumBndin2-2) = answer
call vector_romberg (bb_heat_thin_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thin_table(:,i_subband*3-NumBndin2-4) = answer
call vector_romberg (bb_heat_thin_integrand_HeI,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thin_table(:,i_subband*3-NumBndin2-3) = answer
call vector_romberg (bb_heat_thin_integrand_HeII,weight,NumFreq,NumFreq,NumTau,answer)
bb_heat_thin_table(:,i_subband*3-NumBndin2-2) = answer
call vector_romberg (pl_heat_thick_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thick_table(:,i_subband*3-NumBndin2-4) = answer
call vector_romberg (pl_heat_thick_integrand_HeI,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thick_table(:,i_subband*3-NumBndin2-3) = answer
call vector_romberg (pl_heat_thick_integrand_HeII,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thick_table(:,i_subband*3-NumBndin2-2) = answer
call vector_romberg (pl_heat_thin_integrand_HI,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thin_table(:,i_subband*3-NumBndin2-4) = answer
call vector_romberg (pl_heat_thin_integrand_HeI,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thin_table(:,i_subband*3-NumBndin2-3) = answer
call vector_romberg (pl_heat_thin_integrand_HeII,weight,NumFreq,NumFreq,NumTau,answer)
pl_heat_thin_table(:,i_subband*3-NumBndin2-2) = answer
enddo
! deallocate the useless photo integrand
deallocate(bb_photo_thick_integrand)
deallocate(bb_photo_thin_integrand)
deallocate(pl_photo_thick_integrand)
deallocate(pl_photo_thin_integrand)
! deallocate the useless heating integrand
deallocate(bb_heat_thick_integrand_HI)
deallocate(bb_heat_thick_integrand_HeI)
deallocate(bb_heat_thick_integrand_HeII)
deallocate(bb_heat_thin_integrand_HI)
deallocate(bb_heat_thin_integrand_HeI)
deallocate(bb_heat_thin_integrand_HeII)
deallocate(pl_heat_thick_integrand_HI)
deallocate(pl_heat_thick_integrand_HeI)
deallocate(pl_heat_thick_integrand_HeII)
deallocate(pl_heat_thin_integrand_HI)
deallocate(pl_heat_thin_integrand_HeI)
deallocate(pl_heat_thin_integrand_HeII)
end subroutine spec_integration
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! this subroutine calculates photo-ionization rates at a particular sets of column density
subroutine photoion_shell (phi,colum_in_HI,colum_out_HI,colum_in_HeI,colum_out_HeI, &
colum_in_HeII,colum_out_HeII,vol,source_type)
! result of the routine
type(photrates), intent(out) :: phi
! Incoming and outgoing HI column density
real(kind=dp), intent(in) :: colum_in_HI, colum_out_HI
! Incoming and outgoing HeI column density
real(kind=dp), intent(in) :: colum_in_HeI, colum_out_HeI
! Incoming and outgoing HeII column density
real(kind=dp), intent(in) :: colum_in_HeII, colum_out_HeII
! Volume of shell cell
real(kind=dp), intent(in) :: vol
! B for backbody, P for power law
character(len=1), intent(in) :: source_type
integer :: i_tau, i_subband
real(kind=dp) :: i_state = 1.0
real(kind=dp) :: colum_cell_HI
real(kind=dp) :: colum_cell_HeI
real(kind=dp) :: colum_cell_HeII
real(kind=dp), dimension(1:NumFreqBnd) :: tau_in_all
real(kind=dp), dimension(1:NumFreqBnd) :: tau_out_all
real(kind=dp), dimension(1:NumFreqBnd) :: tau_cell_HI
real(kind=dp), dimension(1:NumFreqBnd) :: tau_cell_HeI
real(kind=dp), dimension(1:NumFreqBnd) :: tau_cell_HeII
type(tablepos) :: tau_pos_in, tau_pos_out
! The column densities (HI, HeI, HeII) at current cell
colum_cell_HI = colum_out_HI-colum_in_HI
colum_cell_HeI = colum_out_HeI-colum_in_HeI
colum_cell_HeII = colum_out_HeII-colum_in_HeII
! The optical depths (HI, HeI, HeII) at current cell
do i_subband=1,NumFreqBnd
tau_cell_HI(i_subband) = colum_cell_HI*sigma_HI(i_subband)
tau_cell_HeI(i_subband) = colum_cell_HeI*sigma_HeI(i_subband)
tau_cell_HeII(i_subband) = colum_cell_HeII*sigma_HeII(i_subband)
enddo
! total tau_in (including HI, HeI, HeII)
do i_subband=1,NumFreqBnd
tau_in_all(i_subband) = colum_in_HI*sigma_HI(i_subband)+ &
colum_in_HeI*sigma_HeI(i_subband)+ &
colum_in_HeII*sigma_HeII(i_subband)
enddo
! total tau_out (including HI, HeI, HeII)
do i_subband=1,NumFreqBnd
tau_out_all(i_subband) = colum_out_HI*sigma_HI(i_subband)+ &
colum_out_HeI*sigma_HeI(i_subband)+ &
colum_out_HeII*sigma_HeII(i_subband)
enddo
! find the table positions for the optical depth (ingoing)
do i_subband=1,NumFreqBnd
tau_pos_in%tau(i_subband) = log10(max(1.0e-20_dp,tau_in_all(i_subband)))
tau_pos_in%odpos(i_subband) = min(real(NumTau,dp),max(0.0_dp,1.0+ &
(tau_pos_in%tau(i_subband)-minlogtau)/dlogtau))
tau_pos_in%ipos(i_subband) = int(tau_pos_in%odpos(i_subband))
tau_pos_in%residual(i_subband) = tau_pos_in%odpos(i_subband)-real(tau_pos_in%ipos(i_subband),dp)
tau_pos_in%ipos_p1(i_subband) = min(NumTau,tau_pos_in%ipos(i_subband)+1)
enddo
! find the table positions for the optical depth (outgoing)
do i_subband=1,NumFreqBnd
tau_pos_out%tau(i_subband) = log10(max(1.0e-20_dp,tau_out_all(i_subband)))
tau_pos_out%odpos(i_subband) = min(real(NumTau,dp),max(0.0_dp,1.0+ &
(tau_pos_out%tau(i_subband)-minlogtau)/dlogtau))
tau_pos_out%ipos(i_subband) = int(tau_pos_out%odpos(i_subband))
tau_pos_out%residual(i_subband) = tau_pos_out%odpos(i_subband)-real(tau_pos_out%ipos(i_subband),dp)
tau_pos_out%ipos_p1(i_subband) = min(NumTau,tau_pos_out%ipos(i_subband)+1)
enddo
call lookuptable_shell(tau_pos_in,tau_pos_out,phi,tau_in_all,tau_out_all, &
tau_cell_HI,tau_cell_HeI,tau_cell_HeII,vol, &
source_type,i_state,colum_cell_HI,colum_cell_HeI,colum_cell_HeII)
end subroutine photoion_shell
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! find out the correct position in the photo and heating tables
subroutine lookuptable_shell(tau_pos_in,tau_pos_out,phi,tau_in_all,tau_out_all, &
tau_cell_HI,tau_cell_HeI,tau_cell_HeII,vol, &
source_type,i_state,colum_cell_HI,colum_cell_HeI,colum_cell_HeII)
type(photrates), intent(out) :: phi
type(tablepos), intent(in) :: tau_pos_in, tau_pos_out
real(kind=dp), intent(in) :: vol, i_state
real(kind=dp), intent(in) :: colum_cell_HI, colum_cell_HeI, colum_cell_HeII
real(kind=dp), dimension(NumFreqBnd), intent(in) :: tau_in_all, tau_out_all
character(len=1),intent(in) :: source_type
real(kind=dp), dimension(NumFreqBnd),intent(in) :: tau_cell_HI, tau_cell_HeI, tau_cell_HeII
integer :: n, i_subband, i
real(kind=dp) :: phi_heat_HI, phi_heat_HeI, phi_heat_HeII
real(kind=dp) :: f_heat, f_ion_HI, f_ion_HeI
real(kind=dp) :: phi_photo_in_all, phi_photo_out_all, phi_photo_all
real(kind=dp) :: fra_sum1, fra_sum2, fra_sum3, fra_sum4
real(kind=dp), pointer, dimension(:,:) :: photo_thick_table, photo_thin_table
real(kind=dp), pointer, dimension(:,:) :: heat_thick_table, heat_thin_table
real(kind=dp), dimension(NumBndin1+1:NumBndin1+NumBndin2+NumBndin3) :: scaling_HI
real(kind=dp), dimension(NumBndin1+1:NumBndin1+NumBndin2+NumBndin3) :: scaling_HeI
real(kind=dp), dimension(NumBndin1+NumBndin2+1:NumBndin1+NumBndin2+NumBndin3) :: scaling_HeII
real(kind=dp), dimension(1:NumheatBin) :: scaling
real(kind=dp) :: test1, test2
real(kind=dp) :: tau_photo_limit = 1.0e-7
real(kind=dp) :: tau_heat_limit = 1.0e-4
! pointers point to some variables
if (source_type.eq.'B') then
photo_thick_table => bb_photo_thick_table
photo_thin_table => bb_photo_thin_table
heat_thick_table => bb_heat_thick_table
heat_thin_table => bb_heat_thin_table
elseif (source_type.eq.'P') then
photo_thick_table => pl_photo_thick_table
photo_thin_table => pl_photo_thin_table
heat_thick_table => pl_heat_thick_table
heat_thin_table => pl_heat_thin_table
endif
! initialization
phi%photo_cell_HI = 0.0_dp
phi%photo_cell_HeI = 0.0_dp
phi%photo_cell_HeII = 0.0_dp
phi_heat_HI = 0.0_dp
phi_heat_HeI = 0.0_dp
phi_heat_HeII = 0.0_dp
phi%heat_cell_HI = 0.0_dp
phi%heat_cell_HeI = 0.0_dp
phi%heat_cell_HeII = 0.0_dp
phi%photo_in = 0.0_dp
f_heat = 0.0_dp
f_ion_HI = 0.0_dp
f_ion_HeI = 0.0_dp
! loop through all frequency band
do i_subband=1,NumFreqBnd
! Incoming, outcoming, current cell total photoionization rate
phi_photo_in_all = (photo_thick_table(tau_pos_in%ipos(i_subband),i_subband)+ &
(photo_thick_table(tau_pos_in%ipos_p1(i_subband),i_subband)- &
photo_thick_table(tau_pos_in%ipos(i_subband),i_subband))* &
tau_pos_in%residual(i_subband))
phi%photo_in = phi%photo_in+phi_photo_in_all
! When current cell is optically thick
if (abs(tau_out_all(i_subband)-tau_in_all(i_subband)) .gt. tau_photo_limit) then
phi_photo_out_all = (photo_thick_table(tau_pos_out%ipos(i_subband),i_subband)+ &
(photo_thick_table(tau_pos_out%ipos_p1(i_subband),i_subband)- &
photo_thick_table(tau_pos_out%ipos(i_subband),i_subband))* &
tau_pos_out%residual(i_subband))
phi_photo_all = phi_photo_in_all-phi_photo_out_all
! When current cell is optically thin
else
phi_photo_all = ((photo_thin_table(tau_pos_in%ipos(i_subband),i_subband)+ &
(photo_thin_table(tau_pos_in%ipos_p1(i_subband),i_subband)- &
photo_thin_table(tau_pos_in%ipos_p1(i_subband),i_subband))* &
tau_pos_in%residual(i_subband))* &
(tau_out_all(i_subband)-tau_in_all(i_subband)))
phi_photo_out_all = phi_photo_in_all-phi_photo_all
endif
! Current cell individual photoionization rate of HI, HeI, HeII
select case (i_subband)
! band 1
case (NumBndin1)
phi%photo_cell_HI = phi_photo_all/vol
! band 2
case (NumBndin1+1:NumBndin1+NumBndin2)
call scale_int2(scaling_HI(i_subband),scaling_HeI(i_subband),colum_cell_HI,colum_cell_HeI, i_subband)
phi%photo_cell_HI = phi%photo_cell_HI+scaling_HI(i_subband)*phi_photo_all/vol
phi%photo_cell_HeI = phi%photo_cell_HeI+scaling_HeI(i_subband)*phi_photo_all/vol
! band 3
case (NumBndin1+NumBndin2+1:NumBndin1+NumBndin2+NumBndin3)
call scale_int3(scaling_HI(i_subband),scaling_HeI(i_subband),scaling_HeII(i_subband), &
colum_cell_HI,colum_cell_HeI,colum_cell_HeII,i_subband)
phi%photo_cell_HI = phi%photo_cell_HI+scaling_HI(i_subband)*phi_photo_all/vol
phi%photo_cell_HeI = phi%photo_cell_HeI+scaling_HeI(i_subband)*phi_photo_all/vol
phi%photo_cell_HeII = phi%photo_cell_HeII+scaling_HeII(i_subband)*phi_photo_all/vol
end select
enddo
! in general, I'm following Ricotti et al 2002
CR1 = (/0.3908_dp, 0.0554_dp, 1.0_dp/)
bR1 = (/0.4092_dp, 0.4614_dp, 0.2663_dp/)
dR1 = (/1.7592_dp, 1.6660_dp, 1.3163_dp/)
CR2 = (/0.6941_dp,0.0984_dp,3.9811_dp/)
aR2 = (/0.2_dp,0.2_dp,0.4_dp/)
bR2 = (/0.38_dp,0.38_dp,0.34_dp/)
test1 = 0.0_dp
test2 = 0.0_dp
do i=1,3
y1R(i) = CR1(i)*(1.0_dp-i_state**bR1(i))**dR1(i)
xeb = 1.0_dp-i_state**bR2(i)
y2R(i) = CR2(i)*i_state**aR2(i)*xeb*xeb
enddo
! Current cell individual heating rates of HI, HeI, HeII
do i_subband=1,NumFreqBnd
phi_heat_HI = 0.0_dp
phi_heat_HeI = 0.0_dp
phi_heat_HeII = 0.0_dp
select case (i_subband)
! Incoming, outcoming, current cell HI heating rate at band 1
case (NumBndin1)
phi%heat_in_HI = (heat_thick_table(tau_pos_in%ipos(1),1)+(heat_thick_table(tau_pos_in%ipos_p1(1),1)- &
heat_thick_table(tau_pos_in%ipos(1),1))*tau_pos_in%residual(1))
! When current cell is HI optically thick
if (abs(tau_cell_HI(i_subband)) .gt. tau_heat_limit) then
phi%heat_out_HI = (heat_thick_table(tau_pos_out%ipos(1),1)+(heat_thick_table(tau_pos_out%ipos_p1(1),1)- &
heat_thick_table(tau_pos_out%ipos(1),1))*tau_pos_out%residual(1))
phi_heat_HI = (phi%heat_in_HI-phi%heat_out_HI)/vol
! When current cell is HI optically thin
else
phi_heat_HI = (heat_thin_table(tau_pos_in%ipos(1),1)+(heat_thin_table(tau_pos_in%ipos_p1(1),1)- &
heat_thin_table(tau_pos_in%ipos(1),1))*tau_pos_in%residual(1))* &
(tau_out_all(1)-tau_in_all(1))
phi%heat_out_HI = phi%heat_in_HI+phi_heat_HI
phi_heat_HI = phi_heat_HI/vol
endif
f_heat = phi_heat_HI
! Incoming, outcoming, current cell HI, HeI heating rate at band 2
case (NumBndin1+1:NumBndin1+NumBndin2)
phi%heat_in_HI = (heat_thick_table(tau_pos_in%ipos(i_subband),2*i_subband-2)+ &
(heat_thick_table(tau_pos_in%ipos_p1(i_subband),2*i_subband-2)- &
heat_thick_table(tau_pos_in%ipos(i_subband),2*i_subband-2))* &
tau_pos_in%residual(i_subband))
phi%heat_in_HeI = (heat_thick_table(tau_pos_in%ipos(i_subband),2*i_subband-1)+ &
(heat_thick_table(tau_pos_in%ipos_p1(i_subband),2*i_subband-1)- &
heat_thick_table(tau_pos_in%ipos(i_subband),2*i_subband-1))* &
tau_pos_in%residual(i_subband))
! When current cell is HI optically thick
if (abs(tau_cell_HI(i_subband)) .gt. tau_heat_limit) then
phi%heat_out_HI = (heat_thick_table(tau_pos_out%ipos(i_subband),2*i_subband-2)+ &
(heat_thick_table(tau_pos_out%ipos_p1(i_subband),2*i_subband-2)- &
heat_thick_table(tau_pos_out%ipos(i_subband),2*i_subband-2))* &
tau_pos_out%residual(i_subband))
phi_heat_HI = scaling_HI(i_subband)*(phi%heat_in_HI-phi%heat_out_HI)/vol
! When current cell is HI optically thin
else
phi_heat_HI = scaling_HI(i_subband)*(((heat_thin_table(tau_pos_in%ipos(i_subband),2*i_subband-2)+ &
(heat_thin_table(tau_pos_in%ipos_p1(i_subband),2*i_subband-2)- &
heat_thin_table(tau_pos_in%ipos_p1(i_subband),2*i_subband-2))* &
tau_pos_in%residual(i_subband))*(tau_out_all(i_subband)-tau_in_all(i_subband))))
phi%heat_out_HI = phi%heat_in_HI+phi_heat_HI
phi_heat_HI = phi_heat_HI/vol
endif
! When current cell is HeI optically thick
if (abs(tau_cell_HeI(i_subband)) .gt. tau_heat_limit) then
phi%heat_out_HeI = (heat_thick_table(tau_pos_out%ipos(i_subband),2*i_subband-1)+ &
(heat_thick_table(tau_pos_out%ipos_p1(i_subband),2*i_subband-1)- &
heat_thick_table(tau_pos_out%ipos(i_subband),2*i_subband-1))* &
tau_pos_out%residual(i_subband))
phi_heat_HeI = scaling_HeI(i_subband)*(phi%heat_in_HeI-phi%heat_out_HeI)/vol
! When current cell is HeI optically thin
else
phi_heat_HeI = scaling_HeI(i_subband)*((heat_thin_table(tau_pos_in%ipos(i_subband),2*i_subband-1)+&
(heat_thin_table(tau_pos_in%ipos_p1(i_subband),2*i_subband-1)- &
heat_thin_table(tau_pos_in%ipos_p1(i_subband),2*i_subband-1))* &
tau_pos_in%residual(i_subband))*(tau_out_all(i_subband)-tau_in_all(i_subband)))
phi%heat_out_HeI=phi%heat_in_HeI+phi_heat_HeI
phi_heat_HeI = phi_heat_HeI/vol
endif
fra_sum1 = f1ion_HI(i_subband)*phi_heat_HI+f1ion_HeI(i_subband)*phi_heat_HeI
fra_sum2 = f2ion_HI(i_subband)*phi_heat_HI+f2ion_HeI(i_subband)*phi_heat_HeI
fra_sum3 = f1heat_HI(i_subband)*phi_heat_HI+f1heat_HeI(i_subband)*phi_heat_HeI
fra_sum4 = f2heat_HI(i_subband)*phi_heat_HI+f2heat_HeI(i_subband)*phi_heat_HeI
! These are all cumulative
f_ion_HeI = f_ion_HeI+y1R(2)*fra_sum1-y2R(2)*fra_sum2
f_ion_HI = f_ion_HI+y1R(1)*fra_sum1-y2R(1)*fra_sum2
f_heat = f_heat+phi_heat_HI+phi_heat_HeI-y1R(3)*fra_sum3+y2R(3)*fra_sum4
! Incoming, outcoming, current cell HI, HeI, HeII heating rate at band 3
case (NumBndin1+NumBndin2+1:NumBndin1+NumBndin2+NumBndin3)
phi%heat_in_HI = (heat_thick_table(tau_pos_in%ipos(i_subband),3*i_subband-NumBndin2-4)+ &
(heat_thick_table(tau_pos_in%ipos_p1(i_subband),3*i_subband-NumBndin2-4)- &
heat_thick_table(tau_pos_in%ipos(i_subband),3*i_subband-NumBndin2-4))* &
tau_pos_in%residual(i_subband))
phi%heat_in_HeI = (heat_thick_table(tau_pos_in%ipos(i_subband),3*i_subband-NumBndin2-3)+ &
(heat_thick_table(tau_pos_in%ipos_p1(i_subband),3*i_subband-NumBndin2-3)- &
heat_thick_table(tau_pos_in%ipos(i_subband),3*i_subband-NumBndin2-3))* &
tau_pos_in%residual(i_subband))
phi%heat_in_HeII = (heat_thick_table(tau_pos_in%ipos(i_subband),3*i_subband-NumBndin2-2)+ &
(heat_thick_table(tau_pos_in%ipos_p1(i_subband),3*i_subband-NumBndin2-2)- &
heat_thick_table(tau_pos_in%ipos(i_subband),3*i_subband-NumBndin2-2))* &
tau_pos_in%residual(i_subband))
! When current cell is HI optically thick
if (abs(tau_cell_HI(i_subband)) .gt. tau_heat_limit) then
phi%heat_out_HI = (heat_thick_table(tau_pos_out%ipos(i_subband),3*i_subband-NumBndin2-4)+ &
(heat_thick_table(tau_pos_out%ipos_p1(i_subband),3*i_subband-NumBndin2-4)- &
heat_thick_table(tau_pos_out%ipos(i_subband),3*i_subband-NumBndin2-4))* &
tau_pos_out%residual(i_subband))
phi_heat_HI = scaling_HI(i_subband)*(phi%heat_in_HI-phi%heat_out_HI)/vol
! When current cell is HI optically thin
else
phi_heat_HI = scaling_HI(i_subband)*((heat_thin_table(tau_pos_in%ipos(i_subband),3*i_subband-NumBndin2-4)+ &
(heat_thin_table(tau_pos_in%ipos_p1(i_subband),3*i_subband-NumBndin2-4)- &
heat_thin_table(tau_pos_in%ipos_p1(i_subband),3*i_subband-NumBndin2-4))* &
tau_pos_in%residual(i_subband))*(tau_out_all(i_subband)-tau_in_all(i_subband)))
phi%heat_out_HI = phi%heat_in_HI+phi_heat_HI
phi_heat_HI = phi_heat_HI/vol
endif
! When current cell is HeI optically thick
if (abs(tau_cell_HeI(i_subband)) .gt. tau_heat_limit) then
phi%heat_out_HeI = (heat_thick_table(tau_pos_out%ipos(i_subband),3*i_subband-NumBndin2-3)+ &
(heat_thick_table(tau_pos_out%ipos_p1(i_subband),3*i_subband-NumBndin2-3)- &
heat_thick_table(tau_pos_out%ipos(i_subband),3*i_subband-NumBndin2-3))* &
tau_pos_out%residual(i_subband))
phi_heat_HeI = scaling_HeI(i_subband)*(phi%heat_in_HeI-phi%heat_out_HeI)/vol
! When current cell is HeI optically thin
else
phi_heat_HeI = scaling_HeI(i_subband)*((heat_thin_table(tau_pos_in%ipos(i_subband),3*i_subband-NumBndin2-3)+ &
(heat_thin_table(tau_pos_in%ipos_p1(i_subband),3*i_subband-NumBndin2-3)- &
heat_thin_table(tau_pos_in%ipos_p1(i_subband),3*i_subband-NumBndin2-3))* &
tau_pos_in%residual(i_subband))*(tau_out_all(i_subband)-tau_in_all(i_subband)))
phi%heat_out_HeI = phi%heat_in_HeI+phi_heat_HeI
phi_heat_HeI = phi_heat_HeI/vol
endif
! When current cell is HeII optically thick
if (abs(tau_cell_HeII(i_subband)) .gt. tau_heat_limit) then
phi%heat_out_HeII = (heat_thick_table(tau_pos_out%ipos(i_subband),3*i_subband-NumBndin2-2)+ &
(heat_thick_table(tau_pos_out%ipos_p1(i_subband),3*i_subband-NumBndin2-2)- &
heat_thick_table(tau_pos_out%ipos(i_subband),3*i_subband-NumBndin2-2))* &
tau_pos_out%residual(i_subband))
phi_heat_HeII = scaling_HeII(i_subband)*(phi%heat_in_HeII-phi%heat_out_HeII)/vol
! When current cell is HeII optically thin
else
phi_heat_HeII = scaling_HeII(i_subband)*((heat_thin_table(tau_pos_in%ipos(i_subband),3*i_subband-NumBndin2-2)+ &
(heat_thin_table(tau_pos_in%ipos_p1(i_subband),3*i_subband-NumBndin2-2)- &
heat_thin_table(tau_pos_in%ipos_p1(i_subband),3*i_subband-NumBndin2-2))* &
tau_pos_in%residual(i_subband))*(tau_out_all(i_subband)- tau_in_all(i_subband)))
phi%heat_out_HeII = phi%heat_in_HeII+phi_heat_HeII
phi_heat_HeII = phi_heat_HeII/vol
endif
fra_sum1 = f1ion_HI(i_subband)*phi_heat_HI+f1ion_HeI(i_subband)*phi_heat_HeI+f1ion_HeII(i_subband)*phi_heat_HeII
fra_sum2 = f2ion_HI(i_subband)*phi_heat_HI+f2ion_HeI(i_subband)*phi_heat_HeI+f2ion_HeII(i_subband)*phi_heat_HeII
fra_sum3 = f1heat_HI(i_subband)*phi_heat_HI+f1heat_HeI(i_subband)*phi_heat_HeI+f1heat_HeII(i_subband)*phi_heat_HeII
fra_sum4 = f2heat_HI(i_subband)*phi_heat_HI+f2heat_HeI(i_subband)*phi_heat_HeI+f2heat_HeII(i_subband)*phi_heat_HeII
! These are all cumulative
f_ion_HeI = f_ion_HeI+y1R(2)*fra_sum1-y2R(2)*fra_sum2
f_ion_HI = f_ion_HI+y1R(1)*fra_sum1-y2R(1)*fra_sum2
f_heat = f_heat+phi_heat_HI+phi_heat_HeI+phi_heat_HeII-y1R(3)*fra_sum3+y2R(3)*fra_sum4
end select
enddo
!Total heating rate on current cell
phi%heat = f_heat
!Final HI photoionization rate modified by secondary ionization
phi%photo_cell_HI = phi%photo_cell_HI+f_ion_HI/(ion_freq_HI*hplanck)
!Final HeI photoionization rate modified by secondary ionization
phi%photo_cell_HeI = phi%photo_cell_HeI+f_ion_HeI/(ion_freq_HeI*hplanck)
end subroutine lookuptable_shell
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! this subroutine calculates photo-ionization rates at a particular sets of column density
subroutine photoion_solid_angle (phi,colum_in_HI,colum_out_HI,colum_in_HeI,colum_out_HeI, &
colum_in_HeII,colum_out_HeII,solid_angle,source_type,correction)
! result of the routine
type(photrates), intent(out) :: phi
! Incoming and outgoing HI column density
real(kind=dp), intent(in) :: colum_in_HI, colum_out_HI
! Incoming and outgoing HeI column density
real(kind=dp), intent(in) :: colum_in_HeI, colum_out_HeI
! Incoming and outgoing HeII column density
real(kind=dp), intent(in) :: colum_in_HeII, colum_out_HeII
! Volume of shell cell
real(kind=dp), intent(in) :: solid_angle
! B for backbody, P for power law
character(len=1), intent(in) :: source_type
real(kind=dp), intent(in) :: correction
integer :: i_tau, i_subband
real(kind=dp) :: i_state = 1.0
real(kind=dp) :: colum_cell_HI
real(kind=dp) :: colum_cell_HeI
real(kind=dp) :: colum_cell_HeII
real(kind=dp), dimension(1:NumFreqBnd) :: tau_in_all
real(kind=dp), dimension(1:NumFreqBnd) :: tau_out_all
real(kind=dp), dimension(1:NumFreqBnd) :: tau_cell_HI
real(kind=dp), dimension(1:NumFreqBnd) :: tau_cell_HeI
real(kind=dp), dimension(1:NumFreqBnd) :: tau_cell_HeII
type(tablepos) :: tau_pos_in, tau_pos_out
! The column densities (HI, HeI, HeII) at current cell
colum_cell_HI = colum_out_HI-colum_in_HI
colum_cell_HeI = colum_out_HeI-colum_in_HeI
colum_cell_HeII = colum_out_HeII-colum_in_HeII
! The optical depths (HI, HeI, HeII) at current cell
do i_subband=1,NumFreqBnd
tau_cell_HI(i_subband) = colum_cell_HI*sigma_HI(i_subband)
tau_cell_HeI(i_subband) = colum_cell_HeI*sigma_HeI(i_subband)
tau_cell_HeII(i_subband) = colum_cell_HeII*sigma_HeII(i_subband)
enddo