Skip to content

Commit 9d73bfb

Browse files
committed
q_T_sf: Chemistry Temperature Optimization
1 parent d3a852d commit 9d73bfb

34 files changed

+1280
-351
lines changed

src/common/m_chemistry.fpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
!!>
2+
!! @file m_chemistry.f90
3+
!! @brief Contains module m_chemistry
4+
!! @author Henry Le Berre <[email protected]>
5+
6+
#:include 'macros.fpp'
7+
#:include 'case.fpp'
8+
9+
module m_chemistry
10+
11+
use m_thermochem, only: &
12+
num_species, mol_weights, get_temperature, get_net_production_rates
13+
14+
use m_global_parameters
15+
16+
implicit none
17+
18+
contains
19+
20+
subroutine s_compute_q_T_sf(q_T_sf, q_cons_vf)
21+
22+
! Initialize the temperature field at the start of the simulation to
23+
! reasonable values. Temperature is computed the regular way using the
24+
! conservative variables.
25+
26+
type(scalar_field), intent(inout) :: q_T_sf
27+
type(scalar_field), dimension(sys_size), intent(in) :: q_cons_vf
28+
29+
integer :: x, y, z, eqn
30+
real(kind(0d0)) :: energy, mean_molecular_weight
31+
real(kind(0d0)), dimension(num_species) :: Ys
32+
33+
!$acc parallel loop collapse(3) gang vector default(present) &
34+
!$acc private(Ys)
35+
do z = idwbuff(3)%beg, idwbuff(3)%end
36+
do y = idwbuff(2)%beg, idwbuff(2)%end
37+
do x = idwbuff(1)%beg, idwbuff(1)%end
38+
!$acc loop seq
39+
do eqn = chemxb, chemxe
40+
Ys(eqn - chemxb + 1) = &
41+
q_cons_vf(eqn)%sf(x, y, z)/q_cons_vf(contxb)%sf(x, y, z)
42+
end do
43+
44+
! e = E - 1/2*|u|^2
45+
! cons. E_idx = \rho E
46+
! cons. contxb = \rho (1-fluid)
47+
energy = q_cons_vf(E_idx)%sf(x, y, z)/q_cons_vf(contxb)%sf(x, y, z)
48+
!$acc loop seq
49+
do eqn = momxb, momxe
50+
energy = energy - &
51+
5d-1*(q_cons_vf(eqn)%sf(x, y, z)/q_cons_vf(contxb)%sf(x, y, z))**2d0
52+
end do
53+
54+
call get_temperature(energy, dflt_T_guess, Ys, .true., q_T_sf%sf(x, y, z))
55+
end do
56+
end do
57+
end do
58+
59+
end subroutine s_compute_q_T_sf
60+
61+
subroutine s_compute_chemistry_reaction_flux(rhs_vf, q_cons_qp, q_T_sf, q_prim_qp)
62+
63+
type(scalar_field), dimension(sys_size), intent(inout) :: rhs_vf
64+
type(scalar_field), intent(inout) :: q_T_sf
65+
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_qp, q_prim_qp
66+
integer :: x, y, z
67+
integer :: eqn
68+
real(kind(0d0)) :: T
69+
real(kind(0d0)) :: rho, omega_m
70+
real(kind(0d0)), dimension(num_species) :: Ys
71+
real(kind(0d0)), dimension(num_species) :: omega
72+
73+
!$acc parallel loop collapse(3) gang vector default(present) &
74+
!$acc private(Ys, omega)
75+
do z = idwint(3)%beg, idwint(3)%end
76+
do y = idwint(2)%beg, idwint(2)%end
77+
do x = idwint(1)%beg, idwint(1)%end
78+
79+
!$acc loop seq
80+
do eqn = chemxb, chemxe
81+
Ys(eqn - chemxb + 1) = q_prim_qp(eqn)%sf(x, y, z)
82+
end do
83+
84+
rho = q_cons_qp(contxe)%sf(x, y, z)
85+
T = q_T_sf%sf(x, y, z)
86+
87+
call get_net_production_rates(rho, T, Ys, omega)
88+
89+
!$acc loop seq
90+
do eqn = chemxb, chemxe
91+
92+
omega_m = mol_weights(eqn - chemxb + 1)*omega(eqn - chemxb + 1)
93+
94+
rhs_vf(eqn)%sf(x, y, z) = rhs_vf(eqn)%sf(x, y, z) + omega_m
95+
96+
end do
97+
98+
end do
99+
end do
100+
end do
101+
102+
end subroutine s_compute_chemistry_reaction_flux
103+
104+
end module m_chemistry

src/common/m_constants.fpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ module m_constants
2828
real(kind(0d0)), parameter :: broadband_spectral_level_constant = 20d0 !< The constant to scale the spectral level at the lower frequency bound
2929
real(kind(0d0)), parameter :: broadband_spectral_level_growth_rate = 10d0 !< The spectral level constant to correct the magnitude at each frqeuency to ensure the source is overall broadband
3030

31+
! Chemistry
32+
real(kind(0d0)), parameter :: dflt_T_guess = 1200d0 ! Default guess for temperature (when a previous value is not available)
33+
3134
! IBM+STL interpolation constants
3235
integer, parameter :: Ifactor_2D = 50 !< Multiple factor of the ratio (edge to cell width) for interpolation along edges for 2D models
3336
integer, parameter :: Ifactor_3D = 5 !< Multiple factor of the ratio (edge to cell width) for interpolation along edges for 3D models

src/common/m_variables_conversion.fpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ contains
128128
real(kind(0d0)), intent(in) :: energy, alf
129129
real(kind(0d0)), intent(in) :: dyn_p
130130
real(kind(0d0)), intent(in) :: pi_inf, gamma, rho, qv
131-
real(kind(0d0)), intent(out) :: pres, T
131+
real(kind(0d0)), intent(out) :: pres
132+
real(kind(0d0)), intent(inout) :: T
132133
real(kind(0d0)), intent(in), optional :: stress, mom, G
133134

134135
! Chemistry
@@ -183,7 +184,7 @@ contains
183184
e_Per_Kg = energy/rho
184185
Pdyn_Per_Kg = dyn_p/rho
185186

186-
call get_temperature(e_Per_Kg - Pdyn_Per_Kg, 1200d0, Y_rs, .true., T)
187+
call get_temperature(e_Per_Kg - Pdyn_Per_Kg, T, Y_rs, .true., T)
187188
call get_pressure(rho, T, Y_rs, pres)
188189

189190
#:endif
@@ -814,11 +815,13 @@ contains
814815
!! @param iy Index bounds in second coordinate direction
815816
!! @param iz Index bounds in third coordinate direction
816817
subroutine s_convert_conservative_to_primitive_variables(qK_cons_vf, &
818+
q_T_sf, &
817819
qK_prim_vf, &
818820
ibounds, &
819821
gm_alphaK_vf)
820822

821823
type(scalar_field), dimension(sys_size), intent(in) :: qK_cons_vf
824+
type(scalar_field), intent(inout) :: q_T_sf
822825
type(scalar_field), dimension(sys_size), intent(inout) :: qK_prim_vf
823826
type(int_bounds_info), dimension(1:3), intent(in) :: ibounds
824827
type(scalar_field), &
@@ -845,11 +848,11 @@ contains
845848

846849
real(kind(0d0)) :: G_K
847850

848-
real(kind(0d0)) :: pres, Yksum, T
851+
real(kind(0d0)) :: pres, Yksum
849852

850853
integer :: i, j, k, l, q !< Generic loop iterators
851854

852-
real(kind(0.d0)) :: ntmp
855+
real(kind(0.d0)) :: ntmp, T
853856

854857
#:if MFC_CASE_OPTIMIZATION
855858
#ifndef MFC_SIMULATION
@@ -922,8 +925,6 @@ contains
922925
do i = chemxb, chemxe
923926
qK_prim_vf(i)%sf(j, k, l) = max(0d0, qK_cons_vf(i)%sf(j, k, l)/rho_K)
924927
end do
925-
926-
qK_prim_vf(T_idx)%sf(j, k, l) = qK_cons_vf(T_idx)%sf(j, k, l)
927928
else
928929
!$acc loop seq
929930
do i = 1, contxe
@@ -953,15 +954,19 @@ contains
953954
do i = 1, num_species
954955
rhoYks(i) = qK_cons_vf(chemxb + i - 1)%sf(j, k, l)
955956
end do
957+
958+
T = q_T_sf%sf(j, k, l)
956959
end if
957960

958961
call s_compute_pressure(qK_cons_vf(E_idx)%sf(j, k, l), &
959962
qK_cons_vf(alf_idx)%sf(j, k, l), &
960-
dyn_pres_K, pi_inf_K, gamma_K, rho_K, qv_K, rhoYks, pres, T)
963+
dyn_pres_K, pi_inf_K, gamma_K, rho_K, &
964+
qv_K, rhoYks, pres, T)
961965

962966
qK_prim_vf(E_idx)%sf(j, k, l) = pres
967+
963968
if (chemistry) then
964-
qK_prim_vf(T_idx)%sf(j, k, l) = T
969+
q_T_sf%sf(j, k, l) = T
965970
end if
966971

967972
if (bubbles) then
@@ -1119,8 +1124,6 @@ contains
11191124

11201125
q_cons_vf(E_idx)%sf(j, k, l) = &
11211126
dyn_pres + rho*e_mix
1122-
1123-
q_cons_vf(T_idx)%sf(j, k, l) = q_prim_vf(T_idx)%sf(j, k, l)
11241127
else
11251128
! Computing the energy from the pressure
11261129
if ((model_eqns /= 4) .and. (bubbles .neqv. .true.)) then

src/post_process/m_data_input.f90

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ end subroutine s_read_abstract_data_files
5151
type(scalar_field), allocatable, dimension(:), public :: q_prim_vf !<
5252
!! Primitive variables
5353

54+
type(scalar_field), public :: q_T_sf !<
55+
!! Temperature field
56+
5457
! type(scalar_field), public :: ib_markers !<
5558
type(integer_field), public :: ib_markers
5659

@@ -1173,6 +1176,12 @@ subroutine s_initialize_data_input_module
11731176
-buff_size:p + buff_size))
11741177
end if
11751178

1179+
if (chemistry) then
1180+
allocate (q_T_sf%sf(-buff_size:m + buff_size, &
1181+
-buff_size:n + buff_size, &
1182+
-buff_size:p + buff_size))
1183+
end if
1184+
11761185
! Simulation is 2D
11771186
else
11781187

@@ -1190,6 +1199,12 @@ subroutine s_initialize_data_input_module
11901199
-buff_size:n + buff_size, &
11911200
0:0))
11921201
end if
1202+
1203+
if (chemistry) then
1204+
allocate (q_T_sf%sf(-buff_size:m + buff_size, &
1205+
-buff_size:n + buff_size, &
1206+
0:0))
1207+
end if
11931208
end if
11941209

11951210
! Simulation is 1D
@@ -1208,6 +1223,10 @@ subroutine s_initialize_data_input_module
12081223
allocate (ib_markers%sf(-buff_size:m + buff_size, 0:0, 0:0))
12091224
end if
12101225

1226+
if (chemistry) then
1227+
allocate (q_T_sf%sf(-buff_size:m + buff_size, 0:0, 0:0))
1228+
end if
1229+
12111230
end if
12121231

12131232
if (parallel_io .neqv. .true.) then
@@ -1236,6 +1255,10 @@ subroutine s_finalize_data_input_module
12361255
deallocate (ib_markers%sf)
12371256
end if
12381257

1258+
if (chemistry) then
1259+
deallocate (q_T_sf%sf)
1260+
end if
1261+
12391262
s_read_data_files => null()
12401263

12411264
end subroutine s_finalize_data_input_module

src/post_process/m_global_parameters.fpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ module m_global_parameters
129129
type(int_bounds_info) :: stress_idx !< Indices of elastic stresses
130130
integer :: c_idx !< Index of color function
131131
type(int_bounds_info) :: species_idx !< Indexes of first & last concentration eqns.
132-
integer :: T_idx !< Index of temperature eqn.
133132
!> @}
134133

135134
! Cell Indices for the (local) interior points (O-m, O-n, 0-p).
@@ -633,13 +632,9 @@ contains
633632
species_idx%beg = sys_size + 1
634633
species_idx%end = sys_size + num_species
635634
sys_size = species_idx%end
636-
637-
T_idx = sys_size + 1
638-
sys_size = T_idx
639635
else
640636
species_idx%beg = 1
641637
species_idx%end = 1
642-
T_idx = 1
643638
end if
644639

645640
momxb = mom_idx%beg

src/post_process/m_start_up.f90

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ module m_start_up
3939

4040
use m_finite_differences
4141

42+
use m_chemistry
43+
4244
! ==========================================================================
4345

4446
implicit none
@@ -168,6 +170,7 @@ subroutine s_perform_time_step(t_step)
168170

169171
! Populating the grid and conservative variables
170172
call s_read_data_files(t_step)
173+
171174
! Populating the buffer regions of the grid variables
172175
if (buff_size > 0) then
173176
call s_populate_grid_variables_buffer_regions()
@@ -178,8 +181,11 @@ subroutine s_perform_time_step(t_step)
178181
call s_populate_conservative_variables_buffer_regions()
179182
end if
180183

184+
! Initialize the Temperature cache.
185+
if (chemistry) call s_compute_q_T_sf(q_T_sf, q_cons_vf)
186+
181187
! Converting the conservative variables to the primitive ones
182-
call s_convert_conservative_to_primitive_variables(q_cons_vf, q_prim_vf, idwbuff)
188+
call s_convert_conservative_to_primitive_variables(q_cons_vf, q_T_sf, q_prim_vf, idwbuff)
183189

184190
end subroutine s_perform_time_step
185191

@@ -311,9 +317,9 @@ subroutine s_save_data(t_step, varname, pres, c, H)
311317
end do
312318

313319
if (chem_wrt_T) then
314-
q_sf = q_prim_vf(T_idx)%sf(-offset_x%beg:m + offset_x%end, &
315-
-offset_y%beg:n + offset_y%end, &
316-
-offset_z%beg:p + offset_z%end)
320+
q_sf = q_T_sf%sf(-offset_x%beg:m + offset_x%end, &
321+
-offset_y%beg:n + offset_y%end, &
322+
-offset_z%beg:p + offset_z%end)
317323

318324
write (varname, '(A)') 'T'
319325
call s_write_variable_to_formatted_database_file(varname, t_step)

src/pre_process/m_assign_variables.fpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,6 @@ contains
189189
Ys(i) = q_prim_vf(chemxb + i - 1)%sf(j, k, l)
190190
end do
191191
end block
192-
193-
call get_mixture_molecular_weight(Ys, mean_molecular_weight)
194-
q_prim_vf(T_idx)%sf(j, k, l) = &
195-
q_prim_vf(E_idx)%sf(j, k, l)*mean_molecular_weight &
196-
/(gas_constant*q_prim_vf(1)%sf(j, k, l))
197192
end if
198193
199194
! Updating the patch identities bookkeeping variable
@@ -568,10 +563,6 @@ contains
568563
Ys(i) = q_prim_vf(chemxb + i - 1)%sf(j, k, l)
569564
end do
570565
end block
571-
572-
call get_mixture_molecular_weight(Ys, mean_molecular_weight)
573-
q_prim_vf(T_idx)%sf(j, k, l) = &
574-
q_prim_vf(E_idx)%sf(j, k, l)*mean_molecular_weight/(gas_constant*q_prim_vf(1)%sf(j, k, l))
575566
end if
576567
577568
! Set streamwise velocity to hyperbolic tangent function of y

src/pre_process/m_data_output.fpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ contains
128128
real(kind(0d0)) :: nbub !< Temporary bubble number density
129129
real(kind(0d0)) :: gamma, lit_gamma, pi_inf, qv !< Temporary EOS params
130130
real(kind(0d0)) :: rho !< Temporary density
131-
real(kind(0d0)) :: pres, Temp !< Temporary pressure
131+
real(kind(0d0)) :: pres, T !< Temporary pressure and temperature
132132

133133
real(kind(0d0)) :: nR3
134134
real(kind(0d0)) :: ntmp
135135

136136
real(kind(0d0)) :: rhoYks(1:num_species) !< Temporary species mass fractions
137137

138+
T = dflt_T_guess
139+
138140
t_step = 0
139141

140142
! Outputting the Locations of the Cell-boundaries ==================
@@ -297,8 +299,6 @@ contains
297299
((i >= adv_idx%beg) .and. (i <= adv_idx%end)) &
298300
.or. &
299301
((i >= chemxb) .and. (i <= chemxe)) &
300-
.or. &
301-
((i == T_idx)) &
302302
) then
303303
write (2, FMT) x_cb(j), q_cons_vf(i)%sf(j, 0, 0)
304304
else if (i == mom_idx%beg) then !u
@@ -310,7 +310,7 @@ contains
310310
q_cons_vf(E_idx)%sf(j, 0, 0), &
311311
q_cons_vf(alf_idx)%sf(j, 0, 0), &
312312
0.5d0*(q_cons_vf(mom_idx%beg)%sf(j, 0, 0)**2.d0)/rho, &
313-
pi_inf, gamma, rho, qv, rhoYks, pres, Temp)
313+
pi_inf, gamma, rho, qv, rhoYks, pres, T)
314314
write (2, FMT) x_cb(j), pres
315315
else if ((i >= bub_idx%beg) .and. (i <= bub_idx%end) .and. bubbles) then
316316

@@ -910,8 +910,6 @@ contains
910910
do i = 1, num_species
911911
write (1, '(I3,A20,A20)') chemxb + i - 1, "Y_{"//trim(species_names(i))//"} \rho", "Y_{"//trim(species_names(i))//"}"
912912
end do
913-
914-
write (1, '(I3,A20,A20)') T_idx, "T", "T"
915913
end if
916914

917915
write (1, '(A)') ""
@@ -923,7 +921,6 @@ contains
923921
if (strxb /= 0) write (1, '("[",I2,",",I2,"]",A)') strxb, strxe, " Stress"
924922
if (intxb /= 0) write (1, '("[",I2,",",I2,"]",A)') intxb, intxe, " Internal Energies"
925923
if (chemxb /= 0) write (1, '("[",I2,",",I2,"]",A)') chemxb, chemxe, " Chemistry"
926-
if (T_idx /= 0) write (1, '("[",I2,",",I2,"]",A)') T_idx, T_idx, " Temperature"
927924

928925
close (1)
929926

0 commit comments

Comments
 (0)