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
/
advance.f
663 lines (545 loc) · 24.6 KB
/
advance.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
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
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c NOTE: The comments and equation references correspond to the final
c published version available online at:
c
c http://www.tandfonline.com/doi/full/10.1080/13647830.2012.701019
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
subroutine advance(vel_old,vel_new,scal_old,scal_new,
$ I_R,press_old,press_new,
$ divu_old,divu_new,beta_old,beta_new,
$ beta_for_Y_old,beta_for_Y_new,
$ beta_for_Wbar_old,beta_for_Wbar_new,
$ dx,time,dt,lo,hi,bc,delta_chi,istep)
implicit none
include 'spec.h'
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c state variables held in scal_old and scal_new contain:
c
c 1 = Density
c 2 = Temp
c 3 = RhoH
c 4 = RhoRT (i.e., "ptherm")
c 5:5+Nspec-1 = FirstSpec:LastSpec (rho*Y_k)
c
c For the CHEMH mechanism this code defaults to, Nspec=9 and nscal=13
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c cell-centered, 2 ghost cells
real*8 vel_old(0:nlevs-1,-2:nfine+1)
real*8 vel_new(0:nlevs-1,-2:nfine+1)
real*8 scal_new(0:nlevs-1,-2:nfine+1,nscal)
real*8 scal_old(0:nlevs-1,-2:nfine+1,nscal)
c cell-centered, 1 ghost cell
real*8 I_R(0:nlevs-1,-1:nfine ,0:Nspec)
real*8 beta_old(0:nlevs-1,-1:nfine ,nscal)
real*8 beta_new(0:nlevs-1,-1:nfine ,nscal)
real*8 beta_for_Y_old(0:nlevs-1,-1:nfine ,nscal)
real*8 beta_for_Y_new(0:nlevs-1,-1:nfine ,nscal)
real*8 beta_for_Wbar_old(0:nlevs-1,-1:nfine ,nscal)
real*8 beta_for_Wbar_new(0:nlevs-1,-1:nfine ,nscal)
real*8 divu_old(0:nlevs-1,-1:nfine)
real*8 divu_new(0:nlevs-1,-1:nfine)
c cell-centered, no ghost cells
real*8 delta_chi(0:nlevs-1,0:nfine-1)
real*8 deltaT(0:nlevs-1,0:nfine-1)
c nodal, 1 ghost cell
real*8 press_old(0:nlevs-1,-1:nfine+1)
real*8 press_new(0:nlevs-1,-1:nfine+1)
integer lo(0:nlevs-1)
integer hi(0:nlevs-1)
integer bc(0:nlevs-1,2)
real*8 dx(0:nlevs-1)
real*8 time
real*8 dt(0:nlevs-1)
integer istep
c local variables
c cell-centered, 1 ghost cell
real*8 mu_old(0:nlevs-1,-1:nfine)
real*8 mu_new(0:nlevs-1,-1:nfine)
real*8 gp(0:nlevs-1,-1:nfine)
real*8 visc(0:nlevs-1,-1:nfine)
real*8 I_R_instant(0:nlevs-1,-1:nfine, 0:Nspec)
real*8 diff_old(0:nlevs-1,-1:nfine, nscal)
real*8 diff_new(0:nlevs-1,-1:nfine, nscal)
real*8 diff_hat(0:nlevs-1,-1:nfine, nscal)
real*8 diff_tmp(0:nlevs-1,-1:nfine, nscal)
real*8 tforce(0:nlevs-1,-1:nfine, nscal)
real*8 diffdiff_old(0:nlevs-1,-1:nfine)
real*8 diffdiff_new(0:nlevs-1,-1:nfine)
real*8 diffdiff_hat(0:nlevs-1,-1:nfine)
real*8 divu_effect(0:nlevs-1,-1:nfine)
c cell-centered, no ghost cells
real*8 rhohalf(0:nlevs-1, 0:nfine-1)
real*8 alpha(0:nlevs-1, 0:nfine-1)
real*8 rho_cp(0:nlevs-1, 0:nfine-1)
real*8 vel_Rhs(0:nlevs-1, 0:nfine-1)
real*8 aofs(0:nlevs-1, 0:nfine-1,nscal)
real*8 gamma_lo(0:nlevs-1, 0:nfine-1,Nspec)
real*8 gamma_hi(0:nlevs-1, 0:nfine-1,Nspec)
real*8 gamma_Wbar_lo(0:nlevs-1, 0:nfine-1,Nspec)
real*8 gamma_Wbar_hi(0:nlevs-1, 0:nfine-1,Nspec)
real*8 const_src(0:nlevs-1, 0:nfine-1,nscal)
real*8 lin_src_old(0:nlevs-1, 0:nfine-1,nscal)
real*8 lin_src_new(0:nlevs-1, 0:nfine-1,nscal)
real*8 Rhs(0:nlevs-1, 0:nfine-1,nscal)
real*8 dRhs(0:nlevs-1, 0:nfine-1,0:Nspec)
c nodal, no ghost cells
real*8 macvel(0:nlevs-1, 0:nfine )
real*8 veledge(0:nlevs-1, 0:nfine )
real*8 Y(Nspec),WDOTK(Nspec),C(Nspec),RWRK
integer i,is,misdc,n,rho_flag,IWRK,l,j
real*8 scal_tmp(0:nlevs-1,-2:nfine+1,nscal)
real*8 norm(Nspec),deltaTsum
c "diffdiff" means "differential diffusion", which corresponds to
c sum_m div [ h_m (rho D_m - lambda/cp) grad Y_m ]
c in equation (3)
diffdiff_old = 0.d0
diffdiff_new = 0.d0
print *,'advance: at start of time step',istep
ccccccccccccccccccccccccccccccccccccccccccc
c Step 1: Compute advection velocities
ccccccccccccccccccccccccccccccccccccccccccc
call control_vel(scal_old(0,:,:),dx(0),time,dt(0),istep,lo(0),hi(0))
c compute cell-centered grad pi from nodal pi
do i=lo(0)-1,hi(0)+1
gp(0,i) = (press_old(0,i+1) - press_old(0,i)) / dx(0)
enddo
print *,'... predict edge velocities'
c compute U^{ADV,*}
call pre_mac_predict(vel_old(0,:),scal_old(0,:,:),gp(0,:),
$ macvel(0,:),dx(0),dt(0),lo(0),hi(0),bc(0,:))
c reset delta_chi
delta_chi = 0.d0
ccccccccccccccccccccccccccccccccccccccccccc
c Step 2: Advance thermodynamic variables
ccccccccccccccccccccccccccccccccccccccccccc
c compute transport coefficients at t^n
c rho D_m (for species)
c lambda / cp (for enthalpy)
c lambda (for temperature)
call calc_diffusivities(scal_old(0,:,:),beta_old(0,:,:),
& beta_for_Y_old(0,:,:),
& beta_for_Wbar_old(0,:,:),
& mu_old(0,:),lo(0),hi(0))
c compute diffusion terms at t^n
print *,'... creating the diffusive terms with old data'
c compute div lambda grad T
diff_old(0,:,Temp) = 0.d0
call addDivLambdaGradT(scal_old(0,:,:),beta_old(0,:,:),
& diff_old(0,:,Temp),dx(0),lo(0),hi(0))
c compute conservatively corrected div gamma_m
c also save Gamma_m for computing diffdiff = div h_m Gamma_m later
call get_spec_visc_terms(scal_old(0,:,:),beta_old(0,:,:),
& diff_old(0,:,FirstSpec:),
& gamma_lo(0,:,:),gamma_hi(0,:,:),
& dx(0),lo(0),hi(0))
if (LeEQ1 .eq. 0) then
c compute div h_m Gamma_m
c we pass in conservative Gamma_m via gamma
c we compute h_m using T from the scalar argument
call get_diffdiff_terms(scal_old(0,:,:),
$ gamma_lo(0,:,:),gamma_hi(0,:,:),
$ diffdiff_old(0,:),dx(0),lo(0),hi(0))
end if
c If istep > 1, I_R is instantaneous value at t^n
c Otherwise, I_R is I_R^kmax from previous pressure iteration
if (istep .gt. 1) then
do i=lo(0),hi(0)
do n=1,Nspec
C(n) = scal_old(0,i,FirstSpec+n-1)*invmwt(n)
end do
call CKWC(scal_old(0,i,Temp),C,IWRK,RWRK,WDOTK)
do n=1,Nspec
I_R(0,i,n) = WDOTK(n)*mwt(n)
end do
end do
end if
c non-fancy predictor that simply sets scal_new = scal_old
scal_new = scal_old
beta_new = beta_old
beta_for_Y_new = beta_for_Y_old
beta_for_Wbar_new = beta_for_Wbar_old
diff_new = diff_old
diffdiff_new = diffdiff_old
divu_new = divu_old
C----------------------------------------------------------------
c Begin MISDC iterations
C----------------------------------------------------------------
do misdc = 1, misdc_iterMAX
print *,'... doing SDC iter ',misdc
if (misdc .gt. 1) then
print *,'... compute lagged diff_new, D^{n+1,(k-1)}'
c compute transport coefficients
c rho D_m (for species)
c lambda / cp (for enthalpy)
c lambda (for temperature)
call calc_diffusivities(scal_new(0,:,:),beta_new(0,:,:),
& beta_for_Y_new(0,:,:),
& beta_for_Wbar_new(0,:,:),
& mu_new(0,:),lo(0),hi(0))
c compute div lambda grad T
diff_new(0,:,Temp) = 0.d0
call addDivLambdaGradT(scal_new(0,:,:),beta_new(0,:,:),
& diff_new(0,:,Temp),dx(0),lo(0),hi(0))
c compute a conservative div gamma_m
c save gamma_m for differential diffusion computation
call get_spec_visc_terms(scal_new(0,:,:),beta_new(0,:,:),
& diff_new(0,:,FirstSpec:),
& gamma_lo(0,:,:),gamma_hi(0,:,:),
& dx(0),lo(0),hi(0))
if (LeEQ1 .eq. 0) then
c compute div h_m Gamma_m
c we pass in conservative gamma_m via gamma
c we compute h_m using T from the scalar argument
call get_diffdiff_terms(scal_new(0,:,:),
$ gamma_lo(0,:,:),gamma_hi(0,:,:),
$ diffdiff_new(0,:),dx(0),lo(0),hi(0))
end if
cccccccccccccccccccccccccccccccccccc
c re-compute S^{n+1/2} by averaging old and new
cccccccccccccccccccccccccccccccccccc
print *,'... recompute S^{n+1/2} by averaging'
print *,' old and new'
c instantaneous omegadot for divu calc
do i=lo(0),hi(0)
do n=1,Nspec
C(n) = scal_new(0,i,FirstSpec+n-1)*invmwt(n)
end do
call CKWC(scal_new(0,i,Temp),C,IWRK,RWRK,WDOTK)
do n=1,Nspec
I_R_instant(0,i,n) = WDOTK(n)*mwt(n)
end do
end do
c divu
call calc_divu(scal_new(0,:,:),beta_new(0,:,:),I_R_instant(0,:,:),
& divu_new(0,:),dx(0),lo(0),hi(0))
end if
c time-centered divu
do i=lo(0),hi(0)
divu_effect(0,i) = 0.5d0*(divu_old(0,i) + divu_new(0,i))
end do
cccccccccccccccccccccccccccccccccccc
c update delta_chi and project
cccccccccccccccccccccccccccccccccccc
print *,'... updating S^{n+1/2} and macvel'
print *,' using fancy delta_chi'
c compute ptherm = p(rho,T,Y)
c this is needed for any dpdt-based correction scheme
call compute_pthermo(scal_new(0,:,:),lo(0),hi(0),bc(0,:))
c delta_chi = delta_chi + dpdt_factor*(peos-p0)/(dt*peos)
call add_dpdt(scal_new(0,:,:),scal_new(0,:,RhoRT),
$ delta_chi(0,:),macvel(0,:),dx(0),dt(0),
$ lo(0),hi(0),bc(0,:))
c S_hat^{n+1/2} = S^{n+1/2} + delta_chi
do i=lo(0),hi(0)
divu_effect(0,i) = divu_effect(0,i) + delta_chi(0,i)
end do
c macvel will now satisfy div(umac) = S_hat^{n+1/2}
call macproj(macvel(0,:),scal_old(0,:,Density),
& divu_effect(0,:),dx,lo(0),hi(0),bc(0,:))
print *,'... computing A forcing term = D^n + I_R^{k-1}'
c advective forcing for species
c diff_old carries div Gamma_m
c I_R carries iteratively lagged or time-lagged reactions
do i=lo(0),hi(0)
do n = 1,Nspec
is = FirstSpec + n - 1
tforce(0,i,is) = diff_old(0,i,is) + I_R(0,i,n)
enddo
c advective forcing for enthalpy
c diff_old carries div lambda grad T
c diffdiff_old carries div h_m gamma_m
tforce(0,i,RhoH) = diff_old(0,i,Temp) + diffdiff_old(0,i)
enddo
c compute advective flux divergence
call scal_aofs(scal_old(0,:,:),macvel(0,:),aofs(0,:,:),
$ divu_effect(0,:),tforce(0,:,:),dx(0),dt(0),
$ lo(0),hi(0),bc(0,:))
c update density
print *,'... update rho'
call update_rho(scal_old(0,:,:),scal_new(0,:,:),aofs(0,:,:),
& dt(0),lo(0),hi(0),bc(0,:))
c this is used as the alpha coefficient for species and velocity solver
do i=lo(0),hi(0)
alpha(0,i) = scal_new(0,i,Density)
end do
c compute deferred correcion terms
do i=lo(0),hi(0)
do n=1,Nspec
is = FirstSpec + n - 1
c includes deferred correction term for species
c dRhs for species now holds dt*(I_R + (1/2) div Gamma_m^n + (1/2) div Gamma_m^{(k)} )
dRhs(0,i,n) = dt(0)*(I_R(0,i,n)
& + 0.5d0*(diff_old(0,i,is) - diff_new(0,i,is)))
enddo
c includes deferred correction term for alternate enthalpy formulation
c this is the lambda grad T part and the h_m Gamma_m part
c dRhs for enthalpy now holds :
c (dt/2) div (lambda^n grad T^n - lambda^(k) grad T^(k))
c +(dt/2) div (h_m^n gamma_m^n - h_m^(k) gamma_m^(k))
dRhs(0,i,0) = dt(0)*(
& + 0.5d0*(diff_old(0,i,Temp) - diff_new(0,i,Temp))
& + 0.5d0*(diffdiff_old(0,i) - diffdiff_new(0,i)))
enddo
c new iterative coupled species/enthalpy diffusion algorithm
do l=1,Wbar_iter
print*,'Wbar iter',l
c compute div ( beta_for_Wbar^{(k)} grad Wbar_{AD}^{(k+1),l} )
c also need to save the fluxes themselves for constructing Gamma_m later
call get_spec_visc_terms_Wbar(scal_new(0,:,:),beta_for_Wbar_new(0,:,:),
& diff_tmp(0,:,FirstSpec:),
& gamma_Wbar_lo(0,:,:),
& gamma_Wbar_hi(0,:,:),
& dx(0),lo(0),hi(0))
c construct Rhs for implicit system
do i=lo(0),hi(0)
do n=1,Nspec
is = FirstSpec + n - 1
Rhs(0,i,is) = scal_old(0,i,is) + dt(0)*aofs(0,i,is)
& + dRhs(0,i,n) + dt(0)*diff_tmp(0,i,is)
end do
end do
c Solve implicit system
rho_flag = 2
do n=1,Nspec
is = FirstSpec + n - 1
call cn_solve(scal_new(0,:,:),alpha(0,:),beta_for_Y_new(0,:,:),
$ Rhs(0,:,is),dx(0),dt(0),is,1.d0,
$ rho_flag,.false.,lo(0),hi(0),bc(0,:))
enddo
call set_bc_s(scal_new(0,:,:),lo(0),hi(0),bc(0,:))
c compute conservatively corrected version of div gamma_m
c where gamma_m = beta_for_Y^{(k)} grad \tilde Y_{m,AD}^{(k+1),l+1}
c + beta_for_Wbar^{(k)} grad Wbar_{AD}^{(k+1),l}
c the latter term is already available from the get_spec_visc_terms_Wbar call above
c we save the total fluxes for calculating diffdiff terms for the enthalpy solve
call get_spec_visc_terms_Y_and_Wbar(scal_new(0,:,:),
& beta_for_Y_new(0,:,:),
& diff_hat(0,:,FirstSpec:),
& gamma_Wbar_lo(0,:,:),
& gamma_Wbar_hi(0,:,:),
& gamma_lo(0,:,:),
& gamma_hi(0,:,:),
& dx(0),lo(0),hi(0))
c compute rho^{(k+1)}*Y_{m,AD}^{(k+1),l+1}
do i=lo(0),hi(0)
do n=1,Nspec
is = FirstSpec + n -1
scal_new(0,i,is) = scal_old(0,i,is) + dt(0)*aofs(0,i,is)
& + dRhs(0,i,n) + dt(0)*diff_hat(0,i,is)
end do
end do
c diagnostic stuff
if (l .eq. 1) then
norm = 0.d0
do i=lo(0),hi(0)
do n=1,Nspec
is = FirstSpec + n - 1
norm(n) = norm(n) + abs(scal_new(0,i,is)-scal_old(0,i,is))
end do
end do
print*,'change in rhoY relative to old state'
write(*,1000) (norm(1:Nspec))
else
norm = 0.d0
do i=lo(0),hi(0)
do n=1,Nspec
is = FirstSpec + n - 1
norm(n) = norm(n) + abs(scal_new(0,i,is)-scal_tmp(0,i,is))
end do
end do
print*,'change in rhoY relative to previous change'
write(*,1000) (norm(1:Nspec))
1000 format (1000E11.3)
end if
scal_tmp = scal_new
call set_bc_s(scal_new(0,:,:),lo(0),hi(0),bc(0,:))
end do
c set Rhs(RhoH) to (rhoh)^n + dt*A +
c (dt/2) div (lambda^n grad T^n - lambda^(k) grad T^(k))
c +(dt/2) div (h_m^n gamma_m^n - h_m^(k) gamma_m^(k)
do i=lo(0),hi(0)
Rhs(0,i,RhoH) = scal_old(0,i,RhoH) + dt(0)*aofs(0,i,RhoH) + dRhs(0,i,0)
end do
if (LeEQ1 .eq. 0) then
c compute div h_m^{(k)} Gamma_{m,AD}^{(k+1)}
c we pass in conservative gamma_m via gamma
c we compute h_m using T from the scalar argument
call get_diffdiff_terms(scal_new(0,:,:),
$ gamma_lo(0,:,:),gamma_hi(0,:,:),
$ diffdiff_hat(0,:),dx(0),lo(0),hi(0))
end if
do j=1,deltaT_iter
print*,'deltaT iter',j
c compute rho^{(k+1)}*cp_{AD}^{(k+1),l}
do i=lo(0),hi(0)
do n = 1,Nspec
Y(n) = scal_new(0,i,FirstSpec+n-1) / scal_new(0,i,Density)
enddo
call CKCPBS(scal_new(0,i,Temp),Y,IWRK,RWRK,rho_cp(0,i))
rho_cp(0,i) = rho_cp(0,i)*scal_new(0,i,Density)
end do
c compute div lambda^{(k)} grad T_{AD}^{(k+1),l}
diff_hat(:,:,Temp) = 0.d0
call addDivLambdaGradT(scal_new(0,:,:),beta_new(0,:,:),
$ diff_hat(0,:,Temp),dx(0),lo(0),hi(0))
c build rhs for delta T solve and store it in Rhs(Temp)
c Rhs(RhoH) already holds (rhoh)^n + dt*A
c + (dt/2) div (lambda^n grad T^n - lambda^(k) grad T^(k))
c + (dt/2) div (h_m^n gamma_m^n - h_m^(k) gamma_m^(k))
c make a copy of Rhs(RhoH)
Rhs(:,:,Temp) = Rhs(:,:,RhoH)
c need to subtract rho^(k+1) h_AD^{(k+1),l} from Rhs(Temp)
do i=lo(0),hi(0)
Rhs(0,i,Temp) = Rhs(0,i,Temp) - scal_new(0,i,RhoH)
end do
c need to add dt*div lambda^{(k)} grad T_AD^{(k+1),l} to Rhs(Temp)
do i=lo(0),hi(0)
Rhs(0,i,Temp) = Rhs(0,i,Temp) + dt(0)*diff_hat(0,i,Temp)
end do
c add dt*div h_m^{(k)} Gamma_{m,AD}^{(k+1)}
do i=lo(0),hi(0)
Rhs(0,i,Temp) = Rhs(0,i,Temp) + dt(0)*diffdiff_hat(0,i)
end do
c Solve C-N system for delta T
deltaT = 0.d0
call cn_solve_deltaT(deltaT(0,:),rho_cp(0,:),
$ beta_new(0,:,Temp),
$ Rhs(0,:,Temp),dx(0),dt(0),
$ 1.d0,lo(0),hi(0),bc(0,:))
c diagnostic stuff
deltaTsum = 0.d0
do i=lo(0),hi(0)
deltaTsum = deltaTsum + abs(deltaT(0,i))
end do
print*,'deltaTsum',deltaTsum
do i=lo(0),hi(0)
c update temperature and use EOS to get enthalpy
scal_new(0,i,Temp) = scal_new(0,i,Temp) + deltaT(0,i)
do n = 1,Nspec
Y(n) = scal_new(0,i,FirstSpec+n-1) / scal_new(0,i,Density)
enddo
call CKHBMS(scal_new(0,i,Temp),Y,IWRK,RWRK,scal_new(0,i,RhoH))
scal_new(0,i,RhoH) = scal_new(0,i,RhoH) * scal_new(0,i,Density)
end do
c update enthalpy and use EOS to get temperature
c do i=lo(0),hi(0)
c scal_new(0,i,RhoH) = scal_new(0,i,RhoH) + rho_cp(0,i)*deltaT(0,i)
c end do
c call rhoh_to_temp(scal_new(0,:,:),lo(0),hi(0))
call set_bc_s(scal_new(0,:,:),lo(0),hi(0),bc(0,:))
c end loop over m
end do
c dRhs for was holding :
c (dt/2) div (lambda^n grad T^n - lambda^(k) grad T^(k))
c +(dt/2) div (h_m^n gamma_m^n - h_m^(k) gamma_m^(k))
do i=lo(0),hi(0)
dRhs(0,i,0) = dRhs(0,i,0) / dt(0)
dRhs(0,i,0) = dRhs(0,i,0) + aofs(0,i,RhoH)
& + diff_hat(0,i,Temp) + diffdiff_hat(0,i)
end do
print *,'... react with const sources'
c compute A+D source terms for reaction integration
c do this in alternate enthalpy formulation for diff term
do n = FirstSpec,LastSpec
do i=lo(0),hi(0)
const_src(0,i,n) = aofs(0,i,n)
$ + 0.5d0*(diff_old(0,i,n)+diff_new(0,i,n))
$ + diff_hat(0,i,n) - diff_new(0,i,n)
lin_src_old(0,i,n) = 0.d0
lin_src_new(0,i,n) = 0.d0
enddo
enddo
do i=lo(0),hi(0)
const_src(0,i,RhoH) = dRhs(0,i,0)
lin_src_old(0,i,RhoH) = 0.d0
lin_src_new(0,i,RhoH) = 0.d0
enddo
c solve equations (50), (51) and (52)
call strang_chem(scal_old(0,:,:),scal_new(0,:,:),
$ const_src(0,:,:),lin_src_old(0,:,:),
$ lin_src_new(0,:,:),
$ I_R(0,:,:),dt(0),lo(0),hi(0),bc(0,:))
C----------------------------------------------------------------
c End MISDC iterations
C----------------------------------------------------------------
enddo
C----------------------------------------------------------------
c Step 3: Advance the velocity
C----------------------------------------------------------------
c omegadot for divu_new computation is instantaneous
c value of omegadot at t^{n+1}
do i=lo(0),hi(0)
do n=1,Nspec
C(n) = scal_new(0,i,FirstSpec+n-1)*invmwt(n)
end do
call CKWC(scal_new(0,i,Temp),C,IWRK,RWRK,WDOTK)
do n=1,Nspec
I_R_instant(0,i,n) = WDOTK(n)*mwt(n)
end do
end do
c compute transport coefficients
c rho D_m (for species)
c lambda / cp (for enthalpy)
c lambda (for temperature)
call calc_diffusivities(scal_new(0,:,:),beta_new(0,:,:),
& beta_for_Y_new(0,:,:),
& beta_for_Wbar_new(0,:,:),
& mu_new(0,:),lo(0),hi(0))
c calculate S
call calc_divu(scal_new(0,:,:),beta_new(0,:,:),I_R_instant(0,:,:),
& divu_new(0,:),dx(0),lo(0),hi(0))
print *,'... update velocities'
c get velocity visc terms to use as a forcing term for advection
call get_vel_visc_terms(vel_old(0,:),mu_old(0,:),visc(0,:),dx(0),
$ lo(0),hi(0))
do i=lo(0),hi(0)
visc(0,i) = visc(0,i)/scal_old(0,i,Density)
enddo
c compute velocity edge states
call vel_edge_states(vel_old(0,:),scal_old(0,:,Density),gp(0,:),
$ macvel(0,:),veledge(0,:),dx(0),dt(0),
$ visc(0,:),lo(0),hi(0),bc(0,:))
c calculate rhohalf
do i=lo(0),hi(0)
rhohalf(0,i) = 0.5d0*(scal_old(0,i,Density)+scal_new(0,i,Density))
enddo
c update velocity and set up RHS for C-N diffusion solve
call update_vel(vel_old(0,:),vel_new(0,:),gp(0,:),rhohalf(0,:),
& macvel(0,:),veledge(0,:),alpha(0,:),mu_old(0,:),
& vel_Rhs(0,:),dx(0),dt(0),0.5d0,
& lo(0),hi(0),bc(0,:))
if (is_first_initial_iter .eq. 1) then
c during the first pressure initialization step, use an
c explicit update for diffusion
call get_vel_visc_terms(vel_old(0,:),mu_old(0,:),visc(0,:),
$ dx(0),lo(0),hi(0))
do i=lo(0),hi(0)
vel_new(0,i) = vel_new(0,i) + visc(0,i)*dt(0)/rhohalf(0,i)
enddo
else
c crank-nicolson viscous solve
rho_flag = 1
call cn_solve(vel_new(0,:),alpha(0,:),mu_new(0,:),
$ vel_Rhs(0,:),dx(0),dt(0),1,0.5d0,rho_flag,
$ .true.,lo(0),hi(0),bc(0,:))
endif
c compute ptherm = p(rho,T,Y)
c this is needed for any dpdt-based correction scheme
call compute_pthermo(scal_new(0,:,:),lo(0),hi(0),bc(0,:))
c reset delta_chi for new-time projection
delta_chi = 0.d0
c S_hat^{n+1} = S^{n+1} + dpdt_factor*(ptherm-p0)/(gamma*dt*p0)
c + dpdt_factor*(u dot grad p)/(gamma*p0)
call add_dpdt_nodal(scal_new(0,:,:),scal_new(0,:,RhoRT),
& delta_chi(0,:),vel_new(0,:),dx(0),dt(0),
& lo(0),hi(0),bc(0,:))
c use divu_effect as a temporary holding place for divu_new + delta_chi
do i=lo(0),hi(0)
divu_effect(0,i) = divu_new(0,i) + delta_chi(0,i)
end do
c project cell-centered velocities
print *,'...nodal projection...'
call project_level(vel_new(0,:),rhohalf(0,:),divu_effect(0,:),
& press_old(0,:),press_new(0,:),dx(0),dt(0),
& lo(0),hi(0),bc(0,:))
end