Skip to content

Commit 108805c

Browse files
authored
q_T_sf: Chemistry Temperature Optimization (#758)
1 parent f624480 commit 108805c

37 files changed

+1294
-384
lines changed

src/common/m_chemistry.fpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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, bounds)
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+
type(int_bounds_info), dimension(1:3), intent(in) :: bounds
29+
30+
integer :: x, y, z, eqn
31+
real(wp) :: energy, mean_molecular_weight
32+
real(wp), dimension(num_species) :: Ys
33+
34+
do z = bounds(3)%beg, bounds(3)%end
35+
do y = bounds(2)%beg, bounds(2)%end
36+
do x = bounds(1)%beg, bounds(1)%end
37+
!$acc loop seq
38+
do eqn = chemxb, chemxe
39+
Ys(eqn - chemxb + 1) = &
40+
q_cons_vf(eqn)%sf(x, y, z)/q_cons_vf(contxb)%sf(x, y, z)
41+
end do
42+
43+
! e = E - 1/2*|u|^2
44+
! cons. E_idx = \rho E
45+
! cons. contxb = \rho (1-fluid model)
46+
! cons. momxb + i = \rho u_i
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+
0.5_wp*(q_cons_vf(eqn)%sf(x, y, z)/q_cons_vf(contxb)%sf(x, y, z))**2._wp
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, bounds)
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+
type(int_bounds_info), dimension(1:3), intent(in) :: bounds
67+
68+
integer :: x, y, z
69+
integer :: eqn
70+
real(wp) :: T
71+
real(wp) :: rho, omega_m
72+
real(wp), dimension(num_species) :: Ys
73+
real(wp), dimension(num_species) :: omega
74+
75+
!$acc parallel loop collapse(3) gang vector default(present) &
76+
!$acc private(Ys, omega)
77+
do z = bounds(3)%beg, bounds(3)%end
78+
do y = bounds(2)%beg, bounds(2)%end
79+
do x = bounds(1)%beg, bounds(1)%end
80+
81+
!$acc loop seq
82+
do eqn = chemxb, chemxe
83+
Ys(eqn - chemxb + 1) = q_prim_qp(eqn)%sf(x, y, z)
84+
end do
85+
86+
rho = q_cons_qp(contxe)%sf(x, y, z)
87+
T = q_T_sf%sf(x, y, z)
88+
89+
call get_net_production_rates(rho, T, Ys, omega)
90+
91+
!$acc loop seq
92+
do eqn = chemxb, chemxe
93+
94+
omega_m = mol_weights(eqn - chemxb + 1)*omega(eqn - chemxb + 1)
95+
96+
rhs_vf(eqn)%sf(x, y, z) = rhs_vf(eqn)%sf(x, y, z) + omega_m
97+
98+
end do
99+
100+
end do
101+
end do
102+
end do
103+
104+
end subroutine s_compute_chemistry_reaction_flux
105+
106+
end module m_chemistry

src/common/m_constants.fpp

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

33+
! Chemistry
34+
real(wp), parameter :: dflt_T_guess = 1200._wp ! Default guess for temperature (when a previous value is not available)
35+
3336
! IBM+STL interpolation constants
3437
integer, parameter :: Ifactor_2D = 50 !< Multiple factor of the ratio (edge to cell width) for interpolation along edges for 2D models
3538
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: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ contains
128128
real(wp), intent(in) :: energy, alf
129129
real(wp), intent(in) :: dyn_p
130130
real(wp), intent(in) :: pi_inf, gamma, rho, qv
131-
real(wp), intent(out) :: pres, T
131+
real(wp), intent(out) :: pres
132+
real(wp), intent(inout) :: T
132133
real(wp), intent(in), optional :: stress, mom, G
133134

134135
! Chemistry
135136
real(wp), dimension(1:num_species), intent(in) :: rhoYks
136137
real(wp) :: E_e
137138
real(wp) :: e_Per_Kg, Pdyn_Per_Kg
139+
real(wp) :: T_guess
138140
real(wp), dimension(1:num_species) :: Y_rs
139141

140142
integer :: s !< Generic loop iterator
@@ -183,7 +185,9 @@ contains
183185
e_Per_Kg = energy/rho
184186
Pdyn_Per_Kg = dyn_p/rho
185187

186-
call get_temperature(e_Per_Kg - Pdyn_Per_Kg, 1200._wp, Y_rs, .true., T)
188+
T_guess = T
189+
190+
call get_temperature(e_Per_Kg - Pdyn_Per_Kg, T_guess, Y_rs, .true., T)
187191
call get_pressure(rho, T, Y_rs, pres)
188192

189193
#:endif
@@ -816,11 +820,13 @@ contains
816820
!! @param iy Index bounds in second coordinate direction
817821
!! @param iz Index bounds in third coordinate direction
818822
subroutine s_convert_conservative_to_primitive_variables(qK_cons_vf, &
823+
q_T_sf, &
819824
qK_prim_vf, &
820825
ibounds, &
821826
gm_alphaK_vf)
822827

823828
type(scalar_field), dimension(sys_size), intent(in) :: qK_cons_vf
829+
type(scalar_field), intent(inout) :: q_T_sf
824830
type(scalar_field), dimension(sys_size), intent(inout) :: qK_prim_vf
825831
type(int_bounds_info), dimension(1:3), intent(in) :: ibounds
826832
type(scalar_field), &
@@ -847,11 +853,11 @@ contains
847853

848854
real(wp) :: G_K
849855

850-
real(wp) :: pres, Yksum, T
856+
real(wp) :: pres, Yksum
851857

852858
integer :: i, j, k, l, q !< Generic loop iterators
853859

854-
real(wp) :: ntmp
860+
real(wp) :: ntmp, T
855861

856862
#:if MFC_CASE_OPTIMIZATION
857863
#ifndef MFC_SIMULATION
@@ -924,8 +930,6 @@ contains
924930
do i = chemxb, chemxe
925931
qK_prim_vf(i)%sf(j, k, l) = max(0._wp, qK_cons_vf(i)%sf(j, k, l)/rho_K)
926932
end do
927-
928-
qK_prim_vf(T_idx)%sf(j, k, l) = qK_cons_vf(T_idx)%sf(j, k, l)
929933
else
930934
!$acc loop seq
931935
do i = 1, contxe
@@ -955,15 +959,19 @@ contains
955959
do i = 1, num_species
956960
rhoYks(i) = qK_cons_vf(chemxb + i - 1)%sf(j, k, l)
957961
end do
962+
963+
T = q_T_sf%sf(j, k, l)
958964
end if
959965

960966
call s_compute_pressure(qK_cons_vf(E_idx)%sf(j, k, l), &
961967
qK_cons_vf(alf_idx)%sf(j, k, l), &
962-
dyn_pres_K, pi_inf_K, gamma_K, rho_K, qv_K, rhoYks, pres, T)
968+
dyn_pres_K, pi_inf_K, gamma_K, rho_K, &
969+
qv_K, rhoYks, pres, T)
963970

964971
qK_prim_vf(E_idx)%sf(j, k, l) = pres
972+
965973
if (chemistry) then
966-
qK_prim_vf(T_idx)%sf(j, k, l) = T
974+
q_T_sf%sf(j, k, l) = T
967975
end if
968976

969977
if (bubbles) then
@@ -1121,8 +1129,6 @@ contains
11211129

11221130
q_cons_vf(E_idx)%sf(j, k, l) = &
11231131
dyn_pres + rho*e_mix
1124-
1125-
q_cons_vf(T_idx)%sf(j, k, l) = q_prim_vf(T_idx)%sf(j, k, l)
11261132
else
11271133
! Computing the energy from the pressure
11281134
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
@@ -130,7 +130,6 @@ module m_global_parameters
130130
type(int_bounds_info) :: stress_idx !< Indices of elastic stresses
131131
integer :: c_idx !< Index of color function
132132
type(int_bounds_info) :: species_idx !< Indexes of first & last concentration eqns.
133-
integer :: T_idx !< Index of temperature eqn.
134133
!> @}
135134

136135
! Cell Indices for the (local) interior points (O-m, O-n, 0-p).
@@ -635,13 +634,9 @@ contains
635634
species_idx%beg = sys_size + 1
636635
species_idx%end = sys_size + num_species
637636
sys_size = species_idx%end
638-
639-
T_idx = sys_size + 1
640-
sys_size = T_idx
641637
else
642638
species_idx%beg = 1
643639
species_idx%end = 1
644-
T_idx = 1
645640
end if
646641

647642
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, idwbuff)
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

0 commit comments

Comments
 (0)