@@ -30,6 +30,13 @@ module m_cbc
30
30
31
31
use m_compute_cbc
32
32
33
+ use m_thermochem, only: &
34
+ get_mixture_energy_mass, get_mixture_specific_heat_cv_mass, &
35
+ get_mixture_specific_heat_cp_mass, gas_constant, &
36
+ get_mixture_molecular_weight, get_species_enthalpies_rt, &
37
+ molecular_weights, get_species_specific_heats_r, &
38
+ get_mole_fractions, get_species_specific_heats_r
39
+
33
40
implicit none
34
41
35
42
private; public :: s_initialize_cbc_module, s_cbc, s_finalize_cbc_module
@@ -96,7 +103,8 @@ module m_cbc
96
103
integer :: dj
97
104
integer :: bcxb, bcxe, bcyb, bcye, bczb, bcze
98
105
integer :: cbc_dir, cbc_loc
99
- !$acc declare create(dj, bcxb, bcxe, bcyb, bcye, bczb, bcze, cbc_dir, cbc_loc)
106
+ integer :: flux_cbc_index
107
+ !$acc declare create(dj, bcxb, bcxe, bcyb, bcye, bczb, bcze, cbc_dir, cbc_loc, flux_cbc_index)
100
108
101
109
!! GRCBC inputs for subsonic inflow and outflow conditions consisting of
102
110
!! inflow velocities, pressure, density and void fraction as well as
@@ -124,6 +132,13 @@ contains
124
132
integer :: i
125
133
logical :: is_cbc
126
134
135
+ if (chemistry) then
136
+ flux_cbc_index = sys_size
137
+ else
138
+ flux_cbc_index = adv_idx%end
139
+ end if
140
+ !$acc update device(flux_cbc_index)
141
+
127
142
call s_any_cbc_boundaries(is_cbc)
128
143
129
144
if (is_cbc .eqv. .false.) return
@@ -153,7 +168,7 @@ contains
153
168
154
169
@:ALLOCATE(F_rsx_vf(0:buff_size, &
155
170
is2%beg:is2%end, &
156
- is3%beg:is3%end, 1:adv_idx%end ))
171
+ is3%beg:is3%end, 1:flux_cbc_index ))
157
172
158
173
@:ALLOCATE(F_src_rsx_vf(0:buff_size, &
159
174
is2%beg:is2%end, &
@@ -163,7 +178,7 @@ contains
163
178
164
179
@:ALLOCATE(flux_rsx_vf_l(-1:buff_size, &
165
180
is2%beg:is2%end, &
166
- is3%beg:is3%end, 1:adv_idx%end ))
181
+ is3%beg:is3%end, 1:flux_cbc_index ))
167
182
168
183
@:ALLOCATE(flux_src_rsx_vf_l(-1:buff_size, &
169
184
is2%beg:is2%end, &
@@ -196,7 +211,7 @@ contains
196
211
197
212
@:ALLOCATE(F_rsy_vf(0:buff_size, &
198
213
is2%beg:is2%end, &
199
- is3%beg:is3%end, 1:adv_idx%end ))
214
+ is3%beg:is3%end, 1:flux_cbc_index ))
200
215
201
216
@:ALLOCATE(F_src_rsy_vf(0:buff_size, &
202
217
is2%beg:is2%end, &
@@ -206,7 +221,7 @@ contains
206
221
207
222
@:ALLOCATE(flux_rsy_vf_l(-1:buff_size, &
208
223
is2%beg:is2%end, &
209
- is3%beg:is3%end, 1:adv_idx%end ))
224
+ is3%beg:is3%end, 1:flux_cbc_index ))
210
225
211
226
@:ALLOCATE(flux_src_rsy_vf_l(-1:buff_size, &
212
227
is2%beg:is2%end, &
@@ -241,7 +256,7 @@ contains
241
256
242
257
@:ALLOCATE(F_rsz_vf(0:buff_size, &
243
258
is2%beg:is2%end, &
244
- is3%beg:is3%end, 1:adv_idx%end ))
259
+ is3%beg:is3%end, 1:flux_cbc_index ))
245
260
246
261
@:ALLOCATE(F_src_rsz_vf(0:buff_size, &
247
262
is2%beg:is2%end, &
@@ -251,7 +266,7 @@ contains
251
266
252
267
@:ALLOCATE(flux_rsz_vf_l(-1:buff_size, &
253
268
is2%beg:is2%end, &
254
- is3%beg:is3%end, 1:adv_idx%end ))
269
+ is3%beg:is3%end, 1:flux_cbc_index ))
255
270
256
271
@:ALLOCATE(flux_src_rsz_vf_l(-1:buff_size, &
257
272
is2%beg:is2%end, &
@@ -651,6 +666,9 @@ contains
651
666
real(wp) :: qv !< Cell averaged fluid reference energy
652
667
real(wp) :: c
653
668
real(wp) :: Ma
669
+ real(wp) :: T, sum_Enthalpies
670
+ real(wp) :: Cv, Cp, e_mix, Mw, R_gas
671
+ real(wp), dimension(num_species) :: Ys, h_k, dYs_dt, dYs_ds, Xs, Gamma_i, Cp_i
654
672
655
673
real(wp) :: vel_K_sum, vel_dv_dt_sum
656
674
@@ -684,7 +702,7 @@ contains
684
702
is1, is2, is3, idwbuff(2)%beg, idwbuff(3)%beg)
685
703
686
704
!$acc parallel loop collapse(3) gang vector default(present)
687
- do i = 1, advxe
705
+ do i = 1, flux_cbc_index
688
706
do r = is3%beg, is3%end
689
707
do k = is2%beg, is2%end
690
708
flux_rs${XYZ}$_vf_l(0, k, r, i) = F_rs${XYZ}$_vf(0, k, r, i) &
@@ -715,7 +733,7 @@ contains
715
733
is1, is2, is3, idwbuff(2)%beg, idwbuff(3)%beg)
716
734
717
735
!$acc parallel loop collapse(4) gang vector default(present)
718
- do i = 1, advxe
736
+ do i = 1, flux_cbc_index
719
737
do j = 0, 1
720
738
do r = is3%beg, is3%end
721
739
do k = is2%beg, is2%end
@@ -757,7 +775,7 @@ contains
757
775
end if
758
776
759
777
! FD2 or FD4 of RHS at j = 0
760
- !$acc parallel loop collapse(2) gang vector default(present) private(alpha_rho, vel, adv, mf, dvel_ds, dadv_ds, Re_cbc, dalpha_rho_ds,dvel_dt, dadv_dt, dalpha_rho_dt,L, lambda)
778
+ !$acc parallel loop collapse(2) gang vector default(present) private(alpha_rho, vel, adv, mf, dvel_ds, dadv_ds, Re_cbc, dalpha_rho_ds,dvel_dt, dadv_dt, dalpha_rho_dt,L, lambda,Ys,dYs_dt,dYs_ds,h_k,Cp_i,Gamma_i,Xs )
761
779
do r = is3%beg, is3%end
762
780
do k = is2%beg, is2%end
763
781
@@ -796,7 +814,33 @@ contains
796
814
mf(i) = alpha_rho(i)/rho
797
815
end do
798
816
799
- E = gamma*pres + pi_inf + 5e-1_wp*rho*vel_K_sum
817
+ if (chemistry) then
818
+ !$acc loop seq
819
+ do i = chemxb, chemxe
820
+ Ys(i - chemxb + 1) = q_prim_rs${XYZ}$_vf(0, k, r, i)
821
+ end do
822
+
823
+ call get_mixture_molecular_weight(Ys, Mw)
824
+ R_gas = gas_constant/Mw
825
+ T = pres/rho/R_gas
826
+ call get_mixture_specific_heat_cp_mass(T, Ys, Cp)
827
+ call get_mixture_energy_mass(T, Ys, e_mix)
828
+ E = rho*e_mix + 5e-1_wp*rho*vel_K_sum
829
+ if (chem_params%gamma_method == 1) then
830
+ !> gamma_method = 1: Ref. Section 2.3.1 Formulation of doi:10.7907/ZKW8-ES97.
831
+ call get_mole_fractions(Mw, Ys, Xs)
832
+ call get_species_specific_heats_r(T, Cp_i)
833
+ Gamma_i = Cp_i/(Cp_i - 1.0_wp)
834
+ gamma = sum(Xs(:)/(Gamma_i(:) - 1.0_wp))
835
+ else if (chem_params%gamma_method == 2) then
836
+ !> gamma_method = 2: c_p / c_v where c_p, c_v are specific heats.
837
+ call get_mixture_specific_heat_cv_mass(T, Ys, Cv)
838
+ gamma = 1.0_wp/(Cp/Cv - 1.0_wp)
839
+ end if
840
+ else
841
+ E = gamma*pres + pi_inf + 5e-1_wp*rho*vel_K_sum
842
+ end if
843
+
800
844
H = (E + pres)/rho
801
845
802
846
! Compute mixture sound speed
@@ -820,6 +864,13 @@ contains
820
864
dadv_ds(i) = 0._wp
821
865
end do
822
866
867
+ if (chemistry) then
868
+ !$acc loop seq
869
+ do i = 1, num_species
870
+ dYs_ds(i) = 0._wp
871
+ end do
872
+ end if
873
+
823
874
!$acc loop seq
824
875
do j = 0, buff_size
825
876
@@ -845,6 +896,15 @@ contains
845
896
fd_coef_${XYZ}$ (j, cbc_loc) + &
846
897
dadv_ds(i)
847
898
end do
899
+
900
+ if (chemistry) then
901
+ !$acc loop seq
902
+ do i = 1, num_species
903
+ dYs_ds(i) = q_prim_rs${XYZ}$_vf(j, k, r, chemxb - 1 + i)* &
904
+ fd_coef_${XYZ}$ (j, cbc_loc) + &
905
+ dYs_ds(i)
906
+ end do
907
+ end if
848
908
end do
849
909
850
910
! First-Order Temporal Derivatives of Primitive Variables
@@ -859,7 +919,7 @@ contains
859
919
call s_compute_slip_wall_L(lambda, L, rho, c, mf, dalpha_rho_ds, dpres_ds, dvel_ds, dadv_ds)
860
920
else if ((cbc_loc == -1 .and. bc${XYZ}$b == BC_CHAR_NR_SUB_BUFFER) .or. &
861
921
(cbc_loc == 1 .and. bc${XYZ}$e == BC_CHAR_NR_SUB_BUFFER)) then
862
- call s_compute_nonreflecting_subsonic_buffer_L(lambda, L, rho, c, mf, dalpha_rho_ds, dpres_ds, dvel_ds, dadv_ds)
922
+ call s_compute_nonreflecting_subsonic_buffer_L(lambda, L, rho, c, mf, dalpha_rho_ds, dpres_ds, dvel_ds, dadv_ds, dYs_ds )
863
923
else if ((cbc_loc == -1 .and. bc${XYZ}$b == BC_CHAR_NR_SUB_INFLOW) .or. &
864
924
(cbc_loc == 1 .and. bc${XYZ}$e == BC_CHAR_NR_SUB_INFLOW)) then
865
925
call s_compute_nonreflecting_subsonic_inflow_L(lambda, L, rho, c, mf, dalpha_rho_ds, dpres_ds, dvel_ds, dadv_ds)
@@ -883,7 +943,7 @@ contains
883
943
end if
884
944
else if ((cbc_loc == -1 .and. bc${XYZ}$b == BC_CHAR_NR_SUB_OUTFLOW) .or. &
885
945
(cbc_loc == 1 .and. bc${XYZ}$e == BC_CHAR_NR_SUB_OUTFLOW)) then
886
- call s_compute_nonreflecting_subsonic_outflow_L(lambda, L, rho, c, mf, dalpha_rho_ds, dpres_ds, dvel_ds, dadv_ds)
946
+ call s_compute_nonreflecting_subsonic_outflow_L(lambda, L, rho, c, mf, dalpha_rho_ds, dpres_ds, dvel_ds, dadv_ds, dYs_ds )
887
947
! Add GRCBC for Subsonic Outflow (Pressure)
888
948
if (bc_${XYZ}$%grcbc_out) then
889
949
L(advxe) = c*(1._wp - Ma)*(pres - pres_out(${CBC_DIR}$))/Del_out(${CBC_DIR}$)
@@ -904,7 +964,7 @@ contains
904
964
call s_compute_supersonic_inflow_L(lambda, L, rho, c, mf, dalpha_rho_ds, dpres_ds, dvel_ds, dadv_ds)
905
965
else if ((cbc_loc == -1 .and. bc${XYZ}$b == BC_CHAR_SUP_OUTFLOW) .or. &
906
966
(cbc_loc == 1 .and. bc${XYZ}$e == BC_CHAR_SUP_OUTFLOW)) then
907
- call s_compute_supersonic_outflow_L(lambda, L, rho, c, mf, dalpha_rho_ds, dpres_ds, dvel_ds, dadv_ds)
967
+ call s_compute_supersonic_outflow_L(lambda, L, rho, c, mf, dalpha_rho_ds, dpres_ds, dvel_ds, dadv_ds, dYs_ds )
908
968
end if
909
969
910
970
! Be careful about the cylindrical coordinate!
@@ -935,6 +995,13 @@ contains
935
995
vel_dv_dt_sum = vel_dv_dt_sum + vel(i)*dvel_dt(i)
936
996
end do
937
997
998
+ if (chemistry) then
999
+ !$acc loop seq
1000
+ do i = 1, num_species
1001
+ dYs_dt(i) = -1._wp*L(chemxb + i - 1)
1002
+ end do
1003
+ end if
1004
+
938
1005
! The treatment of void fraction source is unclear
939
1006
if (cyl_coord .and. cbc_dir == 2 .and. cbc_loc == 1) then
940
1007
!$acc loop seq
@@ -978,13 +1045,31 @@ contains
978
1045
+ rho*dvel_dt(i - contxe))
979
1046
end do
980
1047
981
- flux_rs${XYZ}$_vf_l(-1, k, r, E_idx) = flux_rs${XYZ}$_vf_l(0, k, r, E_idx) &
982
- + ds(0)*(pres*dgamma_dt &
983
- + gamma*dpres_dt &
984
- + dpi_inf_dt &
985
- + dqv_dt &
986
- + rho*vel_dv_dt_sum &
987
- + 5e-1_wp*drho_dt*vel_K_sum)
1048
+ if (chemistry) then
1049
+ ! Evolution of LODI equation of energy for real gases adjusted to perfect gas, doi:10.1006/jcph.2002.6990
1050
+ call get_species_enthalpies_rt(T, h_k)
1051
+ sum_Enthalpies = 0._wp
1052
+ !$acc loop seq
1053
+ do i = 1, num_species
1054
+ h_k(i) = h_k(i)*gas_constant/molecular_weights(i)*T
1055
+ sum_Enthalpies = sum_Enthalpies + (rho*h_k(i) - pres*Mw/molecular_weights(i)*Cp/R_gas)*dYs_dt(i)
1056
+ end do
1057
+ flux_rs${XYZ}$_vf_l(-1, k, r, E_idx) = flux_rs${XYZ}$_vf_l(0, k, r, E_idx) &
1058
+ + ds(0)*((E/rho + pres/rho)*drho_dt + rho*vel_dv_dt_sum + Cp*T*L(2)/(c*c) + sum_Enthalpies)
1059
+ !$acc loop seq
1060
+ do i = 1, num_species
1061
+ flux_rs${XYZ}$_vf_l(-1, k, r, i - 1 + chemxb) = flux_rs${XYZ}$_vf_l(0, k, r, chemxb + i - 1) &
1062
+ + ds(0)*(drho_dt*Ys(i) + rho*dYs_dt(i))
1063
+ end do
1064
+ else
1065
+ flux_rs${XYZ}$_vf_l(-1, k, r, E_idx) = flux_rs${XYZ}$_vf_l(0, k, r, E_idx) &
1066
+ + ds(0)*(pres*dgamma_dt &
1067
+ + gamma*dpres_dt &
1068
+ + dpi_inf_dt &
1069
+ + dqv_dt &
1070
+ + rho*vel_dv_dt_sum &
1071
+ + 5e-1_wp*drho_dt*vel_K_sum)
1072
+ end if
988
1073
989
1074
if (riemann_solver == 1) then
990
1075
!$acc loop seq
@@ -1106,7 +1191,7 @@ contains
1106
1191
end do
1107
1192
1108
1193
!$acc parallel loop collapse(4) gang vector default(present)
1109
- do i = 1, advxe
1194
+ do i = 1, flux_cbc_index
1110
1195
do r = is3%beg, is3%end
1111
1196
do k = is2%beg, is2%end
1112
1197
do j = -1, buff_size
@@ -1182,7 +1267,7 @@ contains
1182
1267
end do
1183
1268
1184
1269
!$acc parallel loop collapse(4) gang vector default(present)
1185
- do i = 1, advxe
1270
+ do i = 1, flux_cbc_index
1186
1271
do r = is3%beg, is3%end
1187
1272
do k = is2%beg, is2%end
1188
1273
do j = -1, buff_size
@@ -1258,7 +1343,7 @@ contains
1258
1343
end do
1259
1344
1260
1345
!$acc parallel loop collapse(4) gang vector default(present)
1261
- do i = 1, advxe
1346
+ do i = 1, flux_cbc_index
1262
1347
do r = is3%beg, is3%end
1263
1348
do k = is2%beg, is2%end
1264
1349
do j = -1, buff_size
@@ -1339,7 +1424,7 @@ contains
1339
1424
if (cbc_dir == 1) then
1340
1425
1341
1426
!$acc parallel loop collapse(4) gang vector default(present)
1342
- do i = 1, advxe
1427
+ do i = 1, flux_cbc_index
1343
1428
do r = is3%beg, is3%end
1344
1429
do k = is2%beg, is2%end
1345
1430
do j = -1, buff_size
@@ -1390,7 +1475,7 @@ contains
1390
1475
elseif (cbc_dir == 2) then
1391
1476
1392
1477
!$acc parallel loop collapse(4) gang vector default(present)
1393
- do i = 1, advxe
1478
+ do i = 1, flux_cbc_index
1394
1479
do r = is3%beg, is3%end
1395
1480
do k = is2%beg, is2%end
1396
1481
do j = -1, buff_size
@@ -1443,7 +1528,7 @@ contains
1443
1528
else
1444
1529
1445
1530
!$acc parallel loop collapse(4) gang vector default(present)
1446
- do i = 1, advxe
1531
+ do i = 1, flux_cbc_index
1447
1532
do r = is3%beg, is3%end
1448
1533
do k = is2%beg, is2%end
1449
1534
do j = -1, buff_size
0 commit comments