-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathcollisions.f90
More file actions
309 lines (238 loc) · 10.1 KB
/
Copy pathcollisions.f90
File metadata and controls
309 lines (238 loc) · 10.1 KB
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
module collisions
use, intrinsic :: iso_fortran_env, only: stderr=>error_unit
use phys_consts, only: wp, lsp, ln, ms, kb, pi, elchrg, qs, debug
implicit none
private
real(wp), parameter :: Csn(lsp,ln) = reshape( &
[-1.0_wp, 6.82e-10_wp, 6.64e-10_wp, -1.0_wp, &
2.44e-10_wp, 4.34e-10_wp, 4.27e-10_wp, 0.69e-10_wp, &
2.58e-10_wp, -1.0_wp, 4.49e-10_wp, 0.74e-10_wp, &
2.31e-10_wp, 4.13e-10_wp, -1.0_wp, 0.65e-10_wp, &
4.42e-10_wp, 7.47e-10_wp, 7.25e-10_wp, 1.45e-10_wp, &
-1.0_wp, 33.6e-10_wp, 32.0e-10_wp, -1.0_wp, &
-1.0_wp, -1.0_wp, -1.0_wp, -1.0_wp], shape(Csn), order=[2,1])
real(wp), parameter :: C2sn1(lsp,ln) = reshape( &
[3.67e-11_wp, 0._wp, 0._wp, 4.63e-12_wp, &
0._wp, 0._wp, 0._wp, 0._wp, &
0._wp, 5.14e-11_wp, 0._wp, 0._wp, &
0._wp, 0._wp, 2.59e-11_wp, 0._wp, &
0._wp, 0._wp, 0._wp, 0._wp, &
6.61e-11_wp, 0._wp, 0._wp, 2.65e-10_wp, &
-1._wp, -1._wp, -1._wp, -1._wp], shape(C2sn1), order=[2,1])
real(wp), parameter :: C2sn2(lsp,ln) = reshape( &
[0.064_wp, 0._wp, 0._wp, -1._wp, &
0._wp, 0._wp, 0._wp, 0._wp, &
0._wp, 0.069_wp, 0._wp, 0._wp, &
0._wp, 0._wp, 0.073_wp, 0._wp, &
0._wp, 0._wp, 0._wp, 0._wp, &
0.047_wp, 0._wp, 0._wp, 0.083_wp, &
-1._wp, -1._wp, -1._wp, -1._wp], shape(C2sn2), order=[2,1])
real(wp), parameter :: Csj(lsp,lsp) = reshape( &
[0.22_wp, 0.26_wp, 0.25_wp, 0.26_wp, 0.22_wp, 0.077_wp, 1.87e-3_wp, &
0.14_wp, 0.16_wp, 0.16_wp, 0.17_wp, 0.13_wp, 0.042_wp, 9.97e-4_wp, &
0.15_wp, 0.17_wp, 0.17_wp, 0.18_wp, 0.14_wp, 0.045_wp, 1.07e-3_wp, &
0.13_wp, 0.16_wp, 0.15_wp, 0.16_wp, 0.12_wp, 0.039_wp, 9.347e-4_wp, &
0.25_wp, 0.28_wp, 0.28_wp, 0.28_wp, 0.24_wp, 0.088_wp, 2.136e-3_wp, &
1.23_wp, 1.25_wp, 1.25_wp, 1.25_wp, 1.23_wp, 0.90_wp, 29.7e-3_wp, &
54.5_wp, 54.5_wp, 54.5_wp, 54.5_wp, 54.5_wp, 54.5_wp, 38.537_wp], shape(Csj), order=[2,1])
public :: thermal_conduct, conductivities, capacitance, maxwell_colln, coulomb_colln
contains
subroutine maxwell_colln(isp,isp2,nn,Tn,Ts,nusn)
!------------------------------------------------------------
!-------COMPUTE MAXWELL COLLISIONS OF ISP WITH ISP2. ION
!-------TEMPERATURE/DENSITY ARRAYS EXPECTED TO INCLUDE GHOST CELLS
!------------------------------------------------------------
!-------Note that it is done on a per species basis
integer, intent(in) :: isp,isp2
real(wp), dimension(:,:,:,:), intent(in) :: nn
real(wp), dimension(:,:,:), intent(in) :: Tn
real(wp), dimension(-1:,-1:,-1:,:), intent(in) :: Ts
real(wp), dimension(1:size(Tn,1),1:size(Tn,2),1:size(Tn,3)), &
intent(out) :: nusn
integer :: lx1,lx2,lx3
real(wp) :: mred
real(wp),dimension(1:size(Tn,1),1:size(Tn,2),1:size(Tn,3)) :: Teff
lx1=size(Ts,1)-4
lx2=size(Ts,2)-4
lx3=size(Ts,3)-4
if (isp<lsp) then !ion-neutral
if (Csn(isp,isp2)<0.0) then !resonant
if (isp==1 .and. isp2==4) then
Teff=Tn+Ts(1:lx1,1:lx2,1:lx3,isp)/16.0
nusn=C2sn1(isp,isp2)*Teff**0.5*nn(:,:,:,isp2)*1e-6_wp
else
Teff=0.5*(Tn+Ts(1:lx1,1:lx2,1:lx3,isp))
nusn=C2sn1(isp,isp2)*(1.0-C2sn2(isp,isp2)*log10(Teff))**2.0* &
(Teff**0.5)*nn(:,:,:,isp2)*1e-6_wp
end if
else !nonresonant
nusn=Csn(isp,isp2)*nn(:,:,:,isp2)*1e-6_wp
end if
else !electron-neutral
Teff=Ts(1:lx1,1:lx2,1:lx3,isp)
select case (isp2)
case (1)
nusn=8.9e-11_wp*(1.0+5.7e-4_wp*Teff)*(Teff**0.5)*nn(:,:,:,isp2)*1e-6_wp
case (2)
nusn=2.33e-11_wp*(1.0-1.21e-4_wp*Teff)*(Teff)*nn(:,:,:,isp2)*1e-6_wp
case (3)
nusn=1.82e-10_wp*(1.0+3.6e-2_wp*(Teff**0.5))*(Teff**0.5)*nn(:,:,:,isp2)*1e-6_wp
case (4)
nusn=4.5e-9_wp*(1.0-1.35e-4_wp*Teff)*(Teff**0.5)*nn(:,:,:,isp2)*1e-6_wp
case default
write(stderr,*) 'ERROR: isp2 value is unknown: ',isp2
error stop
end select
end if
end subroutine maxwell_colln
pure subroutine coulomb_colln(isp,isp2,ns,Ts,vs1,nusj,Phisj,Psisj)
!------------------------------------------------------------
!-------COMPUTE COULOMB COLLISIONS OF ISP WITH ISP2.
!-------TEMPERATURE/DENSITY ARRAYS EXPECTED TO INCLUDE GHOST CELLS
!-------NOTE THAT OTHER PIECES OF THE CODE REQUIRE SELF COLLISIONS
!-------TO BE ZERO TO YIELD CORRECT OUTPUT (SOURCES.MOD)
!------------------------------------------------------------
!-------Note that it is done on a per species basis
integer, intent(in) :: isp,isp2
real(wp), dimension(-1:,-1:,-1:,:), intent(in) :: ns,Ts,vs1
real(wp), dimension(1:size(Ts,1)-4,1:size(Ts,2)-4,1:size(Ts,3)-4), &
intent(out) :: nusj,Phisj,Psisj
integer :: lx1,lx2,lx3
real(wp) :: mred
real(wp),dimension(1:size(Ts,1)-4,1:size(Ts,2)-4,1:size(Ts,3)-4) &
:: Teff,Wsj,Phitmp
lx1=size(Ts,1)-4
lx2=size(Ts,2)-4
lx3=size(Ts,3)-4
if (isp==isp2) then !zero out all self collision terms (would need to be changed if non-Maxwellian distribution used).
nusj = 0
Phisj = 0
Psisj = 0
else
Teff=(ms(isp2)*Ts(1:lx1,1:lx2,1:lx3,isp)+ms(isp)* &
Ts(1:lx1,1:lx2,1:lx3,isp2))/(ms(isp2)+ms(isp))
nusj=Csj(isp,isp2)*ns(1:lx1,1:lx2,1:lx3,isp2)*1e-6_wp/Teff**1.5_wp
mred=ms(isp)*ms(isp2)/(ms(isp)+ms(isp2))
Wsj=abs(vs1(1:lx1,1:lx2,1:lx3,isp)-vs1(1:lx1,1:lx2,1:lx3,isp2))/ &
sqrt(2*kB*Teff/mred)
Psisj=exp(-Wsj**2.0_wp)
where (Wsj<0.1_wp)
Phisj=1.0_wp
elsewhere
Phisj=3.0_wp/4.0_wp*sqrt(pi)*erf(Wsj)/Wsj**3.0_wp-3.0_wp/2.0_wp/Wsj**2.0_wp*Psisj
end where
end if
end subroutine coulomb_colln
subroutine thermal_conduct(isp,Ts,ns,nn,J1,lambda,beta)
!------------------------------------------------------------
!-------COMPUTE THERMAL CONDUCTIVITY. TEMPERATURE ARRAY
!-------IS EXPECTED TO INCLUDE GHOST CELLS
!------------------------------------------------------------
!-------Note that it is done on a per species basis
integer, intent(in) :: isp
real(wp), dimension(-1:,-1:,-1:), intent(in) :: Ts,ns
real(wp), dimension(1:size(Ts,1)-4,1:size(Ts,2)-4,1:size(Ts,3)-4,ln), intent(in) :: nn
real(wp), dimension(1:size(Ts,1)-4,1:size(Ts,2)-4,1:size(Ts,3)-4), intent(in) :: J1
real(wp), dimension(1:size(Ts,1)-4,1:size(Ts,2)-4,1:size(Ts,3)-4), intent(out) :: lambda,beta
integer :: lx1,lx2,lx3
lx1=size(Ts,1)-4
lx2=size(Ts,2)-4
lx3=size(Ts,3)-4
if (isp<lsp) then !ion species
lambda=25.0_wp/8.0_wp*kB**2*Ts(1:lx1,1:lx2,1:lx3)**(5.0_wp/2.0_wp)/ms(isp)/(Csj(isp,isp)*1e-6_wp)
beta=0.0
else !electrons
lambda=elchrg*100.0_wp*7.7e5_wp*Ts(1:lx1,1:lx2,1:lx3)**(5.0_wp/2.0_wp)/ &
(1.0+3.22e4_wp*Ts(1:lx1,1:lx2,1:lx3)**2/ns(1:lx1,1:lx2,1:lx3)* &
(nn(:,:,:,1)*1.1e-16_wp*(1+5.7e-4_wp*Ts(1:lx1,1:lx2,1:lx3)) + &
nn(:,:,:,2)*2.82e-17_wp*sqrt(Ts(1:lx1,1:lx2,1:lx3))* &
(1-1.21e-4_wp*Ts(1:lx1,1:lx2,1:lx3))+nn(:,:,:,3)* &
2.2e-16_wp*(1+3.6e-2_wp*sqrt(Ts(1:lx1,1:lx2,1:lx3))) ))
beta=5.0_wp/2.0_wp*kB/elchrg*J1
end if
end subroutine thermal_conduct
subroutine conductivities(nn,Tn,ns,Ts,vs1,B1,sig0,sigP,sigH,muP,muH,muPvn,muHvn)
!------------------------------------------------------------
!-------COMPUTE THE CONDUCTIVITIES OF THE IONOSPHERE. STATE
!-------VARS. INCLUDE GHOST CELLS
!------------------------------------------------------------
real(wp), dimension(:,:,:,:), intent(in) :: nn
real(wp), dimension(:,:,:), intent(in) :: Tn
real(wp), dimension(-1:,-1:,-1:,:), intent(in) :: ns,Ts,vs1
real(wp), dimension(-1:,-1:,-1:), intent(in) :: B1
real(wp), dimension(1:size(ns,1)-4,1:size(ns,2)-4,1:size(ns,3)-4), intent(out) :: sig0,sigP,sigH
real(wp), dimension(1:size(ns,1)-4,1:size(ns,2)-4,1:size(ns,3)-4,lsp), intent(out) :: muP,muH,muPvn,muHvn
integer :: isp,isp2,lx1,lx2,lx3
real(wp), dimension(1:size(ns,1)-4,1:size(ns,2)-4,1:size(ns,3)-4) :: OMs
real(wp), dimension(1:size(ns,1)-4,1:size(ns,2)-4,1:size(ns,3)-4) :: nu,nuej,Phisj,Psisj,nutmp,mupar,mubase,rho
lx1=size(Ts,1)-4
lx2=size(Ts,2)-4
lx3=size(Ts,3)-4
!MOBILITIES
do isp=1,lsp
! OMs=qs(isp)*abs(B1)/ms(isp)
!! cyclotron, abs() is sketch, needs to be checked.
!! Basically a negative sign here is fine, while abs messes up direction of Hall current
OMs=qs(isp)*B1(1:lx1,1:lx2,1:lx3)/ms(isp)
!! cyclotron, a negative sign from B1 here is fine for cartesian, but for dipole this should be the magnitude
!! since the magnetic field is *assumed* to be along the x1-direction
nu = 0
do isp2=1,ln
call maxwell_colln(isp,isp2,nn,Tn,Ts,nutmp)
nu=nu+nutmp
end do
if (isp<lsp) then
mubase=qs(isp)/ms(isp)/nu !parallel mobility
else
nuej = 0
do isp2=1,lsp
call coulomb_colln(isp,isp2,ns,Ts,vs1,nutmp,Phisj,Psisj)
nuej=nuej+nutmp
end do
mupar=qs(lsp)/ms(lsp)/(nu+nuej)
mubase=qs(lsp)/ms(lsp)/nu
end if
!modified mobilities for neutral wind calculations
muPvn(:,:,:,isp)=nu**2/(nu**2+OMs**2)
muHvn(:,:,:,isp)=-1.0_wp*nu*OMs/(nu**2+OMs**2)
!full mobilities
muP(:,:,:,isp)=mubase*muPvn(:,:,:,isp) !Pederson
muH(:,:,:,isp)=mubase*muHvn(:,:,:,isp) !Hall
end do
!CONDUCTIVITIES
sig0=ns(1:lx1,1:lx2,1:lx3,lsp)*qs(lsp)*mupar !parallel includes only electrons...
sigP = 0
sigH = 0
do isp=1,lsp
rho=ns(1:lx1,1:lx2,1:lx3,isp)*qs(isp)
sigP=sigP+rho*muP(:,:,:,isp)
sigH=sigH+rho*muH(:,:,:,isp)
end do
! sigH=max(sigH,0.0_wp) !to deal with precision issues. This actually causes errors in Cartesian northern hemisphere grids...
end subroutine conductivities
subroutine capacitance(ns,B1,flagcap,incap)
!------------------------------------------------------------
!-------COMPUTE THE INERTIAL CAPACITANCE OF THE IONOSPHERE.
!-------DENSITY/MAG FIELD STATE VARIABLE INCLUDES GHOST CELLS.
!------------------------------------------------------------
real(wp), dimension(-1:,-1:,-1:,:), intent(in) :: ns
real(wp), dimension(-1:,-1:,-1:), intent(in) :: B1
integer, intent(in) :: flagcap
real(wp), dimension(1:size(ns,1)-4,1:size(ns,2)-4,1:size(ns,3)-4), intent(out) :: incap
integer :: lx1,lx2,lx3,isp
lx1=size(ns,1)-4
lx2=size(ns,2)-4
lx3=size(ns,3)-4
incap = 0
do isp=1,lsp
incap=incap+ns(1:lx1,1:lx2,1:lx3,isp)*ms(isp)
end do
incap=incap/B1(1:lx1,1:lx2,1:lx3)**2
if (flagcap==2) then
if (debug) print *, '!!! Augmenting capacitance with a magnetospheric contribution...'
incap=incap + 30.0_wp / 980e3_wp
!! kludge the value to account for a magnetosheric contribution
!! this is just a random guess that makes the KHI examples work well; a better value should be investigated
end if
end subroutine capacitance
end module collisions