-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod_info.f90
146 lines (103 loc) · 3.54 KB
/
mod_info.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
MODULE Mod_Info
!############################################################################
!# This section contains the initialization subroutines for the info object
!# as well as the subroutines related to the object itself.
!############################################################################
!### Modules to be Included###
USE Mod_InfoDefs
IMPLICIT NONE
CONTAINS
!### Initializes the Info Object ###
SUBROUTINE Info_Init(info)
Type(Infoc), INTENT(INOUT) :: info
!### Read in Namelist ###
CALL Info_AuraData(info)
!### Initialize Physical Units ###
CALL Phys_Init(info%physo)
!### Sanity Checks ###
if (info%cro%nbins .LT. 2) then
write(*,*) 'INFO ERROR: Number of CR bins cannot be less than 2'
STOP
endif
if (info%envo%nphbins .NE. 0 .AND. info%envo%nphbins .LT. 2) then
write(*,*) 'INFO ERROR: Number of ambient photon field bins cannot be less than 2'
STOP
endif
!### Allocate CR Memory ###
CALL Info_InitCR(info%cro)
!### Allocate Ambient Photon Field if needed ###
if (info%envo%nphbins .GT. 2) then
CALL Info_InitEnv(info%envo)
endif
END SUBROUTINE Info_Init
!### Clean up Info Object ###
SUBROUTINE Info_Destroy(info)
Type(Infoc) :: info
!### De-allocate CR Memory
CALL Info_DestroyCR(info%cro)
!### De-allocate Environment Arrays if needed ###
if (info%envo%nphbins .GT. 2) then
CALL Info_DestroyEnv(info%envo)
endif
END SUBROUTINE Info_Destroy
!### Read in Info Namelist ###
SUBROUTINE Info_AuraData(info)
Type(Infoc), INTENT(INOUT) :: info
INTEGER :: ncrbins, nphbins
LOGICAL namelist_exists, verbose
CHARACTER*20 oroot, odump_path
!### Definte the namelist ###
NAMELIST /Information/ ncrbins, nphbins, verbose, oroot, odump_path
!### Make sure the namelist file exists ###
INQUIRE(FILE='AURA.data', EXIST=namelist_exists)
IF (.NOT. namelist_exists) THEN
PRINT '("INFO ERROR: setup namelist file AURA.data is missing")'
STOP
END IF
!### read in the namelist ###
OPEN(UNIT=1, FILE='AURA.data', STATUS="OLD", FORM="FORMATTED")
READ(1, NML=Information)
CLOSE(1)
info%cro%nbins=ncrbins
info%envo%nphbins=nphbins
info%verbose=verbose
info%oroot=oroot
info%odump_path=odump_path
END SUBROUTINE Info_AuraData
!### Allocate Space for CRs ###
SUBROUTINE Info_InitCR(cro)
TYPE(CR), INTENT(INOUT) :: cro
ALLOCATE(cro%n(cro%nbins),cro%e(cro%nbins),cro%g(cro%nbins),cro%ig(cro%nbins),cro%g2(cro%nbins),cro%ig2(cro%nbins),cro%te(cro%nbins),cro%ite(cro%nbins))
END SUBROUTINE Info_InitCR
!### De-Allocate Space for CRs ###
SUBROUTINE Info_DestroyCR(cro)
TYPE(CR), INTENT(INOUT) :: cro
DEALLOCATE(cro%n,cro%e,cro%g,cro%ig,cro%g2,cro%ig2,cro%te,cro%ite)
END SUBROUTINE Info_DestroyCR
!### Allocate Space for Ambient Photon Field ###
SUBROUTINE Info_InitEnv(envo)
TYPE(Env), INTENT(INOUT) :: envo
ALLOCATE(envo%nph(envo%nphbins),envo%nuph(envo%nphbins))
END SUBROUTINE Info_InitEnv
!### De-Allocate Space for Ambient Photon Field ###
SUBROUTINE Info_DestroyEnv(envo)
TYPE(Env), INTENT(INOUT) :: envo
DEALLOCATE(envo%nph,envo%nuph)
END SUBROUTINE Info_DestroyEnv
!### Calculates some useful quantities from the CR spectrum ###
SUBROUTINE Info_CRCalc(physo,cro)
TYPE(CR), INTENT(INOUT) :: cro
TYPE(Phys), INTENT(IN) :: physo
REAL*8 :: imc2
imc2=1d0/(cro%m*physo%c**2)
!### Calculating the Lorentz Factors for the distribution ###
cro%g=cro%e*imc2+1d0
cro%ig=1d0/cro%g
!### Calculating the Total Energy for the distribution ###
cro%te=cro%g*cro%m*physo%c**2
cro%ite=1d0/cro%te
!### Other useful quantities ###
cro%g2=cro%g**2
cro%ig2=1d0/cro%g2
END SUBROUTINE Info_CRCalc
END MODULE Mod_Info