-
Notifications
You must be signed in to change notification settings - Fork 0
/
quasilinear_terms.f90
285 lines (184 loc) · 6.42 KB
/
quasilinear_terms.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
MODULE QUASILINEAR_TERMS
!subroutines for quasilinear, collisional and transport evolution of electrons and Langmuir waves
IMPLICIT NONE
CONTAINS
SUBROUTINE quasilinear(f, w, f_new, w_new, coeff2)
! Quasilinear alteration of the electron distribution function
USE CONSTANTS
USE PARAMETERS
IMPLICIT NONE
REAL(KIND=8), DIMENSION(-n_v:, :) :: f_new,f
REAL(KIND=8), DIMENSION(-n_kv:,:) :: w_new,w
REAL(KIND=8), DIMENSION(:) :: coeff2
! REAL(KIND=8), DIMENSION(-n_v:n_v, n_xp+3) :: m1, m2
REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: m1, m2
INTEGER(KIND=4)::i,j
ALLOCATE(m1(-n_v:n_v,n_xp+3))
ALLOCATE(m2(-n_v:n_v,n_xp+3))
DO i = -n_v+2,-1
m1(i,:) = w(i,:)*(f(i+1,:)-f(i,:)) / (velocity(i)*dvdv)
m2(i,:) = w(i-1,:)*(f(i,:)-f(i-1,:)) / (velocity(i-1)*dvdv)
ENDDO
DO i = 1,n_v-2
m1(i,:) = w(i,:)*(f(i+1,:)-f(i,:)) / (velocity(i)*dvdv)
m2(i,:) = w(i-1,:)*(f(i,:)-f(i-1,:)) / (velocity(i-1)*dvdv)
ENDDO
!m1(0,:)=0d0
m1(1,:)=0d0
m1(2,:)=0d0
!m1(:,n_xp+2)=0d0
m2(1,:)=0d0
m2(2,:)=0d0
!m2(:,n_xp+2)=0d0
!no double up on Ghost cells
DO j=3, n_xp+2
DO i = -n_v+2,-1
f_new(i,j) = f_new(i,j) - a1*dt_ql*(m1(i,j)-m2(i,j))
w_new(i,j) = w_new(i,j) + velocity(i)*velocity(i)*dt_ql/dv*coeff2(j) * W(i,j) * (f(i,j)-f(i-1,j))
ENDDO
!
DO i = 1,n_v-2
f_new(i,j) = f_new(i,j) + a1*dt_ql*(m1(i,j)-m2(i,j))
w_new(i,j) = w_new(i,j) + velocity(i)*velocity(i)*dt_ql/dv*coeff2(j) * W(i,j)* (f(i+1,j)-f(i,j))
ENDDO
ENDDO
DEALLOCATE(m1, m2)
END SUBROUTINE quasilinear
SUBROUTINE landau_background(w, w_new, landau_arr)
! resonant interaction of L waves with thermal background electrons
USE CONSTANTS
USE PARAMETERS
IMPLICIT NONE
REAL(KIND=8), DIMENSION(-n_kv:,:) :: w_new,w
REAL(KIND=8), DIMENSION(-n_v:,:), INTENT(IN) ::landau_arr
INTEGER:: j
DO j=3, n_xp+2
w_new(-n_v:n_v,j) = w_new(-n_v:n_v,j) - w(-n_v:n_v,j)*dt_ql*Landau_arr(-n_v:n_v,j)
ENDDO
END SUBROUTINE landau_background
SUBROUTINE collision(f,f_new,w_new,gamma_xp,gamma_xw,w,w_t)
! Collisional Term of the electron distribution function
USE CONSTANTS
USE PARAMETERS
IMPLICIT NONE
REAL(KIND=8), DIMENSION(-n_v:,:), INTENT(IN) :: f
REAL(KIND=8), DIMENSION(-n_v:,:), INTENT(OUT) :: f_new
REAL(KIND=8), DIMENSION(-n_kv:,:), INTENT(IN) :: w, w_t
REAL(KIND=8), DIMENSION(-n_kv:,:), INTENT(OUT) :: w_new
REAL(KIND=8), DIMENSION(:), INTENT(IN) :: gamma_xp,gamma_xw
INTEGER(KIND=4)::i,j
DO j=3, n_xp+2
DO i=1, n_v-1
f_new(i,j) = f_new(i,j)+dt_ql*gamma_xp(j)/dv * &
(f(i+1,j)/(velocity(i+1)*velocity(i+1)) - f(i,j)/(velocity(i)*velocity(i)))
ENDDO
DO i=-n_v+1, -1
f_new(i,j) = f_new(i,j) - dt_ql*gamma_xp(j)/dv * (f(i,j)/(velocity(i)*velocity(i)) &
- f(i-1,j)/(velocity(i-1)*velocity(i-1)))
ENDDO
DO i=-n_kv,n_kv
w_new(i,j) = w_new(i,j) - dt_ql*gamma_xw(j)*(w(i,j)-w_t(i,j))
ENDDO
ENDDO
END SUBROUTINE collision
SUBROUTINE spontaneous(f, w_new, log_v_v_t ,coeff)
! Spontaneous Term of the spectral energy density
USE CONSTANTS
USE PARAMETERS
IMPLICIT NONE
REAL(KIND=8), DIMENSION(-n_v:,:), INTENT(IN) :: f
REAL(KIND=8), DIMENSION(-n_v:), INTENT(IN) :: log_v_v_t
REAL(KIND=8), DIMENSION(-n_kv:,:), INTENT(OUT) :: w_new
REAL(KIND=8), DIMENSION(:) :: coeff
INTEGER(KIND=4)::i
DO i = -n_v,n_v
w_new(i,:) = w_new(i,:) + dt_ql*coeff(:)*velocity(i)*f(i,:)*log_v_v_t(i)
ENDDO
END SUBROUTINE spontaneous
SUBROUTINE radial(f,f_new,r_x)
! Radial Term of the electron distribution function
USE CONSTANTS
USE PARAMETERS
IMPLICIT NONE
REAL(KIND=8), DIMENSION(-n_v:, :), INTENT(IN) :: f
REAL(KIND=8), DIMENSION(-n_v:, :), INTENT(OUT) :: f_new
REAL(KIND=8), DIMENSION(:) :: r_x
INTEGER(KIND=4) :: i
DO i = 3, n_xp+2
f_new(:,i) = f_new(:,i) - dt *2.*velocity*f(:,i)/( r_x(i) + 3.4d9 )
ENDDO
END SUBROUTINE radial
SUBROUTINE vanleer(f,f_new,delta_x)
! Van Leer Transport Term
USE CONSTANTS
USE PARAMETERS
IMPLICIT NONE
REAL(KIND=8), DIMENSION(-n_v:,:), INTENT(IN) :: f
REAL(KIND=8), DIMENSION(-n_v:n_v, n_xp+3), INTENT(OUT) :: f_new
REAL(KIND=8), DIMENSION(:), INTENT(IN) :: delta_x
REAL(KIND=8), DIMENSION(-n_v:n_v) :: d1 = 0.d0, DF1 = 0.d0, d2 = 0.d0, DF2 = 0.d0
REAL(KIND=8), DIMENSION(-n_v:n_v) :: aa_minus = 0.0, aa_plus = 0.0, denom
INTEGER(KIND=4)::i,j
DO j = 3, n_xp+2
d1 = ( f(:,j) - f(:,j-1) )*( f(:,j+1) - f(:,j) )
denom(:)=max(abs(f(:, j+1) - f(:,j-1)), tiny(0.d0))
DF1 = (delta_x(j+1) + delta_x(j))*( f(:,j+1) - f(:,j-1) )/denom(:)/(delta_x(j)*denom(:))* MAX(0.d0,d1(:))
! faster method to check no zero rather than using if statement... Max is intrinsic function
!added protection from divide by zero error
! IF ( d1 > 0.) THEN
! DF1 = d1*(delta_x1+delta_x2)/(delta_x1*(f1(i)-f3(i)))
! ELSE
! DF1 = 0.
! END IF
d2 = ( f(:,j-1) - f(:,j-2) )*( f(:,j) - f(:,j-1) )
denom(:)=max(abs(f(:,j)-f(:,j-2)), tiny(0.d0))
DF2 = (delta_x(j) + delta_x(j-1))*( f(:,j) - f(:,j-2) )/denom(:)/(delta_x(j)*denom(:)) * MAX(0.d0,d2(:))
! IF ( d2 > 0.) THEN
! DF2 = d2*(delta_x2+delta_x3)/(delta_x2*(f2(i)-f4(i)))
! ELSE
! DF2 = 0.
! END IF
aa_minus = velocity*dt/delta_x(j)
aa_plus = velocity*dt/delta_x(j+1)
f_new(:,j) = f_new(:,j) - aa_minus(:)*(f(:,j) - f(:,j-1) + (1.-aa_plus(:))*Df1(:)/2. - (1.-aa_minus(:))*Df2(:)/2.)
ENDDO
END SUBROUTINE vanleer
SUBROUTINE upwind(w, w_new, delta_x)
! Upwind Transport Term
USE CONSTANTS
USE PARAMETERS
IMPLICIT NONE
REAL(KIND=8), DIMENSION(-n_kv:, :), INTENT(IN) :: w
REAL(KIND=8), DIMENSION(-n_kv:, :), INTENT(OUT) :: w_new
REAL(KIND=8), DIMENSION(:), INTENT(IN) :: delta_x
INTEGER(KIND=4)::i,j
DO j=3, n_xp+2
DO i=1, n_kv
w_new(i,j) = w_new(i,j) - 3.*v_t*k_x(i)*dt/max(delta_x(j),tiny(0.d0)) * ( w(i,j) - w(i,j-1) )
ENDDO
DO i=-n_kv, -1
w_new(i,j) = w_new(i,j) - 3.*v_t*k_x(i)*dt/max(delta_x(j+1),tiny(0.d0)) * ( w(i,j+1) - w(i,j) )
ENDDO
ENDDO
END SUBROUTINE upwind
SUBROUTINE inhomogeneity(w, w_new, l)
! calculation of the velocity diffusion term
USE CONSTANTS
USE PARAMETERS
IMPLICIT NONE
REAL(KIND=8), DIMENSION(-n_kv:, :) :: w
REAL(KIND=8), DIMENSION(-n_kv:, :) :: w_new
REAL(KIND=8), DIMENSION(n_xp+3) :: l
INTEGER(KIND=4)::i
REAL(KIND=8):: const
const=v_t*dt_ql
DO i= 1, n_kv-1
w_new(i,:) = w_new(i,:) - const*max(-l, 0.d0) * (W(i,:) - W(i-1,:))/dk_x(i-1)
w_new(i,:) = w_new(i,:) + const*max(l, 0.d0) * (W(i+1,:) - W(i,:))/dk_x(i)
ENDDO
DO i= -n_kv +1, -1
w_new(i,:) = w_new(i,:) + const*max(-l, 0.d0) * (W(i+1,:) - W(i,:))/dk_x(i)
w_new(i,:) = w_new(i,:) - const*max(l, 0.d0) * (W(i,:) - W(i-1,:))/dk_x(i-1)
ENDDO
END SUBROUTINE inhomogeneity
END MODULE QUASILINEAR_TERMS