This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_spec_visc_terms.f
302 lines (227 loc) · 9.21 KB
/
get_spec_visc_terms.f
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
subroutine get_spec_visc_terms(scal,beta,visc,gamma_lo,
& gamma_hi,dx,lo,hi)
implicit none
include 'spec.h'
real*8 scal(-2:nfine+1,nscal)
real*8 beta(-1:nfine ,nscal)
real*8 visc(-1:nfine ,Nspec)
real*8 gamma_lo( 0:nfine-1,Nspec)
real*8 gamma_hi( 0:nfine-1,Nspec)
real*8 dx
integer lo,hi
integer i,n,is,IWRK
real*8 beta_lo,beta_hi,RWRK
real*8 dxsqinv
real*8 Y(-1:nfine,Nspec), sum_gamma_lo, sum_gamma_hi, sumRhoY_lo, sumRhoY_hi
real*8 RhoYe_lo, RhoYe_hi
real*8 X(-1:nfine,Nspec)
real*8 scal_X(-2:nfine+1,nscal)
dxsqinv = 1.d0/(dx*dx)
do i=lo-1,hi+1
c compute Y = rho*Y / rho
do n=1,Nspec
Y(i,n) = scal(i,FirstSpec+n-1)/scal(i,Density)
enddo
c convert Y to X
CALL CKYTX(Y(i,:),IWRK,RWRK,X(i,:))
c compute rho*X
do n=1,Nspec
scal_X(i,FirstSpec+n-1) = scal(i,Density)*X(i,n)
end do
enddo
do i=lo,hi
sum_gamma_lo = 0.d0
sum_gamma_hi = 0.d0
sumRhoY_lo = 0.d0
sumRhoY_hi = 0.d0
do n=1,Nspec
is = FirstSpec + n - 1
c compute beta on edges
if (coef_avg_harm.eq.1) then
beta_lo = 2.d0 / (1.d0/beta(i,is)+1.d0/beta(i-1,is))
beta_hi = 2.d0 / (1.d0/beta(i,is)+1.d0/beta(i+1,is))
else
beta_lo = 0.5d0*(beta(i,is) + beta(i-1,is))
beta_hi = 0.5d0*(beta(i,is) + beta(i+1,is))
endif
c compute gamma
gamma_hi(i,n) = beta_hi*(X(i+1,n) - X(i ,n))
gamma_lo(i,n) = beta_lo*(X(i ,n) - X(i-1,n))
c compute div(gamma). If non-unity Le we overwrite this later
visc(i,n) = (gamma_hi(i,n)-gamma_lo(i,n))*dxsqinv
if (LeEQ1 .eq. 0) then
c need to correct fluxes so they add to zero on each face
c build up the sum of species fluxes on lo and hi faces
c this will be "rho * V_c"
sum_gamma_lo = sum_gamma_lo + gamma_lo(i,n)
sum_gamma_hi = sum_gamma_hi + gamma_hi(i,n)
c build up the sum of rho*Y_m
c this will be the density
sumRhoY_lo = sumRhoY_lo+0.5d0*(scal(i-1,is)+scal(i,is))
sumRhoY_hi = sumRhoY_hi+0.5d0*(scal(i,is)+scal(i+1,is))
end if
enddo
if (LeEQ1 .eq. 0) then
c correct the fluxes so they add up to zero before computing visc
do n=1,Nspec
is = FirstSpec + n - 1
c compute rho*Y_m on each face
RhoYe_lo = .5d0*(scal(i-1,is)+scal(i,is))
RhoYe_hi = .5d0*(scal(i,is)+scal(i+1,is))
c set flux = flux - (rho*V_c)*(rho*Y_m)/rho
gamma_lo(i,n) = gamma_lo(i,n)
$ - sum_gamma_lo*RhoYe_lo/sumRhoY_lo
gamma_hi(i,n) = gamma_hi(i,n)
$ - sum_gamma_hi*RhoYe_hi/sumRhoY_hi
c compute div(gamma)
visc(i,n) = (gamma_hi(i,n)-gamma_lo(i,n))*dxsqinv
end do
end if
end do
end
subroutine get_spec_visc_terms_Wbar(scal,beta_for_Wbar,visc,
& gamma_Wbar_lo,gamma_Wbar_hi,
& dx,lo,hi)
implicit none
include 'spec.h'
real*8 scal(-2:nfine+1,nscal)
real*8 beta_for_Wbar(-1:nfine ,nscal)
real*8 visc(-1:nfine ,Nspec)
real*8 gamma_Wbar_lo( 0:nfine-1,Nspec)
real*8 gamma_Wbar_hi( 0:nfine-1,Nspec)
real*8 dx
integer lo,hi
integer i,n,is,IWRK
real*8 beta_for_Wbar_lo,beta_for_Wbar_hi,RWRK
real*8 dxsqinv
real*8 Y(-1:nfine,Nspec)
real*8 Wbar(-1:nfine)
real*8 sum_gamma_lo, sum_gamma_hi, sumRhoY_lo, sumRhoY_hi
real*8 RhoYe_lo, RhoYe_hi
dxsqinv = 1.d0/(dx*dx)
do i=lo-1,hi+1
c compute Y = rho*Y / rho
do n=1,Nspec
Y(i,n) = scal(i,FirstSpec+n-1)/scal(i,Density)
enddo
c convert Y to Wbar
CALL CKMMWY(Y(i,:),IWRK,RWRK,Wbar(i))
enddo
do i=lo,hi
sum_gamma_lo = 0.d0
sum_gamma_hi = 0.d0
sumRhoY_lo = 0.d0
sumRhoY_hi = 0.d0
do n=1,Nspec
is = FirstSpec + n - 1
c compute beta on edges
if (coef_avg_harm.eq.1) then
beta_for_Wbar_lo = 2.d0 / (1.d0/beta_for_Wbar(i,is)+1.d0/beta_for_Wbar(i-1,is))
beta_for_Wbar_hi = 2.d0 / (1.d0/beta_for_Wbar(i,is)+1.d0/beta_for_Wbar(i+1,is))
else
beta_for_Wbar_lo = 0.5d0*(beta_for_Wbar(i,is) + beta_for_Wbar(i-1,is))
beta_for_Wbar_hi = 0.5d0*(beta_for_Wbar(i,is) + beta_for_Wbar(i+1,is))
endif
c compute gamma
gamma_Wbar_hi(i,n) = beta_for_Wbar_hi*(Wbar(i+1) - Wbar(i ))
gamma_Wbar_lo(i,n) = beta_for_Wbar_lo*(Wbar(i ) - Wbar(i-1))
c compute div(gamma).
c no need to conservatively correct these
c we will correct beta grad X after the species diffusion solve
c in fact the algorithm is more stable without the correction here
visc(i,n) = (gamma_Wbar_hi(i,n)-gamma_Wbar_lo(i,n))*dxsqinv
enddo
end do
end
subroutine get_spec_visc_terms_Y_and_Wbar(scal,beta_for_Y,visc,
& gamma_Wbar_lo,
& gamma_Wbar_hi,
& gamma_lo,
& gamma_hi,
& dx,lo,hi)
c compute
c gamma_m = beta_for_y grad Y + gamma_Wbar
c conservatively correct this, then set visc = (1/dxsq)*div(gamma_m)
implicit none
include 'spec.h'
real*8 scal(-2:nfine+1,nscal)
real*8 beta_for_Y(-1:nfine ,nscal)
real*8 visc(-1:nfine ,Nspec)
real*8 gamma_Wbar_lo( 0:nfine-1,Nspec)
real*8 gamma_Wbar_hi( 0:nfine-1,Nspec)
real*8 gamma_lo( 0:nfine-1,Nspec)
real*8 gamma_hi( 0:nfine-1,Nspec)
real*8 dx
integer lo,hi
integer i,n,is,IWRK
real*8 beta_for_Y_lo,beta_for_Y_hi,RWRK
real*8 dxsqinv
real*8 Y(-1:nfine,Nspec), sum_gamma_lo, sum_gamma_hi, sumRhoY_lo, sumRhoY_hi
real*8 RhoYe_lo, RhoYe_hi
real*8 X(-1:nfine,Nspec)
real*8 scal_X(-2:nfine+1,nscal)
dxsqinv = 1.d0/(dx*dx)
do i=lo-1,hi+1
c compute Y = rho*Y / rho
do n=1,Nspec
Y(i,n) = scal(i,FirstSpec+n-1)/scal(i,Density)
enddo
c convert Y to X
CALL CKYTX(Y(i,:),IWRK,RWRK,X(i,:))
c compute rho*X
do n=1,Nspec
scal_X(i,FirstSpec+n-1) = scal(i,Density)*X(i,n)
end do
enddo
do i=lo,hi
sum_gamma_lo = 0.d0
sum_gamma_hi = 0.d0
sumRhoY_lo = 0.d0
sumRhoY_hi = 0.d0
do n=1,Nspec
is = FirstSpec + n - 1
c compute beta on edges
if (coef_avg_harm.eq.1) then
beta_for_Y_lo = 2.d0 / (1.d0/beta_for_Y(i,is)+1.d0/beta_for_Y(i-1,is))
beta_for_Y_hi = 2.d0 / (1.d0/beta_for_Y(i,is)+1.d0/beta_for_Y(i+1,is))
else
beta_for_Y_lo = 0.5d0*(beta_for_Y(i,is) + beta_for_Y(i-1,is))
beta_for_Y_hi = 0.5d0*(beta_for_Y(i,is) + beta_for_Y(i+1,is))
endif
c compute gamma
gamma_hi(i,n) = beta_for_Y_hi*(Y(i+1,n) - Y(i ,n))
gamma_lo(i,n) = beta_for_Y_lo*(Y(i ,n) - Y(i-1,n))
gamma_hi(i,n) = gamma_hi(i,n) + gamma_Wbar_hi(i,n)
gamma_lo(i,n) = gamma_lo(i,n) + gamma_Wbar_lo(i,n)
c compute div(gamma). If non-unity Le we overwrite this later
visc(i,n) = (gamma_hi(i,n)-gamma_lo(i,n))*dxsqinv
if (LeEQ1 .eq. 0) then
c need to correct fluxes so they add to zero on each face
c build up the sum of species fluxes on lo and hi faces
c this will be "rho * V_c"
sum_gamma_lo = sum_gamma_lo + gamma_lo(i,n)
sum_gamma_hi = sum_gamma_hi + gamma_hi(i,n)
c build up the sum of rho*Y_m
c this will be the density
sumRhoY_lo = sumRhoY_lo+0.5d0*(scal(i-1,is)+scal(i,is))
sumRhoY_hi = sumRhoY_hi+0.5d0*(scal(i,is)+scal(i+1,is))
end if
enddo
if (LeEQ1 .eq. 0) then
c correct the fluxes so they add up to zero before computing visc
do n=1,Nspec
is = FirstSpec + n - 1
c compute rho*Y_m on each face
RhoYe_lo = .5d0*(scal(i-1,is)+scal(i,is))
RhoYe_hi = .5d0*(scal(i,is)+scal(i+1,is))
c set flux = flux - (rho*V_c)*(rho*Y_m)/rho
gamma_lo(i,n) = gamma_lo(i,n)
$ - sum_gamma_lo*RhoYe_lo/sumRhoY_lo
gamma_hi(i,n) = gamma_hi(i,n)
$ - sum_gamma_hi*RhoYe_hi/sumRhoY_hi
c compute div(gamma)
visc(i,n) = (gamma_hi(i,n)-gamma_lo(i,n))*dxsqinv
end do
end if
end do
end