Skip to content

Commit

Permalink
CheMFC fixes for HLL+Advection & Pressure/Energy
Browse files Browse the repository at this point in the history
Co-authored-by: Dimitrios Adam <[email protected]>
  • Loading branch information
henryleberre and IamImbact98 committed Oct 16, 2024
1 parent b0d9461 commit 96bb43d
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 129 deletions.
3 changes: 2 additions & 1 deletion src/common/m_thermochem.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module m_thermochem
num_species, species_names, gas_constant, mol_weights, &
get_temperature, get_net_production_rates, get_pressure, &
get_mixture_molecular_weight, get_mixture_energy_mass, &
get_temperature
get_mixture_specific_heat_cv_mass, get_mixture_specific_heat_cp_mass, &
get_species_enthalpies_rt
#:endif

implicit none
Expand Down
33 changes: 18 additions & 15 deletions src/common/m_variables_conversion.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,21 @@ contains
!! @param pres Pressure to calculate
!! @param stress Shear Stress
!! @param mom Momentum
subroutine s_compute_pressure(energy, alf, dyn_p, pi_inf, gamma, rho, qv, rhoYks, pres, stress, mom, G)
subroutine s_compute_pressure(energy, alf, dyn_p, pi_inf, gamma, rho, qv, rhoYks, pres, T, stress, mom, G)

!$acc routine seq

real(kind(0d0)), intent(in) :: energy, alf
real(kind(0d0)), intent(in) :: dyn_p
real(kind(0d0)), intent(in) :: pi_inf, gamma, rho, qv
real(kind(0d0)), intent(out) :: pres
real(kind(0d0)), intent(out) :: pres, T
real(kind(0d0)), intent(in), optional :: stress, mom, G

! Chemistry
integer :: i
real(kind(0d0)), dimension(1:num_species), intent(in) :: rhoYks
real(kind(0d0)) :: E_e
real(kind(0d0)) :: T
real(kind(0d0)) :: e_Per_Kg, Pdyn_Per_Kg
real(kind(0d0)), dimension(1:num_species) :: Y_rs

integer :: s !< Generic loop iterator
Expand Down Expand Up @@ -189,12 +190,11 @@ contains
Y_rs(i) = rhoYks(i)/rho
end do

if (sum(Y_rs) > 1d-16) then
call get_temperature(.true., energy - dyn_p, 1200d0, Y_rs, T)
call get_pressure(rho, T, Y_rs, pres)
else
pres = 0d0
end if
e_Per_Kg = energy/rho
Pdyn_Per_Kg = dyn_p/rho

call get_temperature(e_Per_Kg - Pdyn_Per_Kg, 1200d0, Y_rs, .true., T)
call get_pressure(rho, T, Y_rs, pres)

#:endif

Expand Down Expand Up @@ -886,7 +886,7 @@ contains

real(kind(0d0)) :: G_K

real(kind(0d0)) :: pres, Yksum
real(kind(0d0)) :: pres, Yksum, T

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

Expand Down Expand Up @@ -1004,9 +1004,12 @@ contains

call s_compute_pressure(qK_cons_vf(E_idx)%sf(j, k, l), &
qK_cons_vf(alf_idx)%sf(j, k, l), &
dyn_pres_K, pi_inf_K, gamma_K, rho_K, qv_K, rhoYks, pres)
dyn_pres_K, pi_inf_K, gamma_K, rho_K, qv_K, rhoYks, pres, T)

qK_prim_vf(E_idx)%sf(j, k, l) = pres
if (chemistry) then
qK_prim_vf(tempxb)%sf(j, k, l) = T
end if

if (bubbles) then
!$acc loop seq
Expand Down Expand Up @@ -1117,7 +1120,7 @@ contains
integer :: spec

real(kind(0d0)), dimension(num_species) :: Ys
real(kind(0d0)) :: temperature, e_mix, mix_mol_weight, T
real(kind(0d0)) :: e_mix, mix_mol_weight, T

#ifndef MFC_SIMULATION
! Converting the primitive variables to the conservative variables
Expand Down Expand Up @@ -1158,13 +1161,13 @@ contains
end do

call get_mixture_molecular_weight(Ys, mix_mol_weight)
T = q_prim_vf(E_idx)%sf(j, k, l)*mix_mol_weight/(gas_constant*rho)
T = q_prim_vf(tempxb)%sf(j, k, l)
call get_mixture_energy_mass(T, Ys, e_mix)

q_cons_vf(E_idx)%sf(j, k, l) = &
dyn_pres + e_mix
dyn_pres + rho*e_mix

q_cons_vf(tempxb)%sf(j, k, l) = T
q_cons_vf(tempxb)%sf(j, k, l) = q_prim_vf(tempxb)%sf(j, k, l)
#:else
! Computing the energy from the pressure
if ((model_eqns /= 4) .and. (bubbles .neqv. .true.)) then
Expand Down
29 changes: 21 additions & 8 deletions src/post_process/m_start_up.f90
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,32 @@ subroutine s_save_data(t_step, varname, pres, c, H)
! ----------------------------------------------------------------------

! Adding the species' concentrations to the formatted database file ----
do i = 1, num_species
if (chem_wrt_Y(i) .or. prim_vars_wrt) then
q_sf = q_prim_vf(chemxb + i - 1)%sf(-offset_x%beg:m + offset_x%end, &
-offset_y%beg:n + offset_y%end, &
-offset_z%beg:p + offset_z%end)
if (chemistry) then
do i = 1, num_species
if (chem_wrt_Y(i) .or. prim_vars_wrt) then
q_sf = q_prim_vf(chemxb + i - 1)%sf(-offset_x%beg:m + offset_x%end, &
-offset_y%beg:n + offset_y%end, &
-offset_z%beg:p + offset_z%end)

write (varname, '(A,A)') 'Y_', trim(species_names(i))
call s_write_variable_to_formatted_database_file(varname, t_step)

varname(:) = ' '

end if
end do

if (chem_wrt_T) then
q_sf = q_prim_vf(tempxb)%sf(-offset_x%beg:m + offset_x%end, &
-offset_y%beg:n + offset_y%end, &
-offset_z%beg:p + offset_z%end)

write (varname, '(A,A)') 'Y_', trim(species_names(i))
write (varname, '(A)') 'T'
call s_write_variable_to_formatted_database_file(varname, t_step)

varname(:) = ' '

end if
end do
end if

! Adding the flux limiter function to the formatted database file
do i = 1, E_idx - mom_idx%beg
Expand Down
4 changes: 2 additions & 2 deletions src/pre_process/m_data_output.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ contains
real(kind(0d0)) :: nbub !< Temporary bubble number density
real(kind(0d0)) :: gamma, lit_gamma, pi_inf, qv !< Temporary EOS params
real(kind(0d0)) :: rho !< Temporary density
real(kind(0d0)) :: pres !< Temporary pressure
real(kind(0d0)) :: pres, Temp !< Temporary pressure

real(kind(0d0)) :: nR3
real(kind(0d0)) :: ntmp
Expand Down Expand Up @@ -273,7 +273,7 @@ contains
q_cons_vf(E_idx)%sf(j, 0, 0), &
q_cons_vf(alf_idx)%sf(j, 0, 0), &
0.5d0*(q_cons_vf(mom_idx%beg)%sf(j, 0, 0)**2.d0)/rho, &
pi_inf, gamma, rho, qv, rhoYks, pres)
pi_inf, gamma, rho, qv, rhoYks, pres, Temp)
write (2, FMT) x_cb(j), pres
else if ((i >= bub_idx%beg) .and. (i <= bub_idx%end) .and. bubbles) then

Expand Down
2 changes: 1 addition & 1 deletion src/simulation/m_cbc.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ contains
real(kind(0d0)), dimension(num_fluids) :: adv, dadv_ds
real(kind(0d0)), dimension(sys_size) :: L
real(kind(0d0)), dimension(3) :: lambda
real(kind(0d0)), dimension(num_species) :: Y_s

real(kind(0d0)) :: rho !< Cell averaged density
real(kind(0d0)) :: pres !< Cell averaged pressure
Expand Down Expand Up @@ -803,7 +804,6 @@ contains
end do

E = gamma*pres + pi_inf + 5d-1*rho*vel_K_sum

H = (E + pres)/rho

! Compute mixture sound speed
Expand Down
72 changes: 17 additions & 55 deletions src/simulation/m_chemistry.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,41 +55,6 @@ contains

end subroutine s_finalize_chemistry_module

#:for NORM_DIR, XYZ in [(1, 'x'), (2, 'y'), (3, 'z')]
subroutine s_compute_chemistry_rhs_${XYZ}$ (flux_n, rhs_vf, flux_src_vf, q_prim_vf)

type(vector_field), dimension(:), intent(IN) :: flux_n
type(scalar_field), dimension(sys_size), intent(INOUT) :: rhs_vf, flux_src_vf, q_prim_vf
type(int_bounds_info) :: ix, iy, iz

integer :: x, y, z
integer :: eqn

integer, parameter :: mx = ${1 if NORM_DIR == 1 else 0}$
integer, parameter :: my = ${1 if NORM_DIR == 2 else 0}$
integer, parameter :: mz = ${1 if NORM_DIR == 3 else 0}$

!$acc parallel loop collapse(4) present(rhs_vf, flux_n)
do x = 0, m
do y = 0, n
do z = 0, p

do eqn = chemxb, chemxe

! \nabla \cdot (F)
rhs_vf(eqn)%sf(x, y, z) = rhs_vf(eqn)%sf(x, y, z) + &
(flux_n(${NORM_DIR}$)%vf(eqn)%sf(x - mx, y - my, z - mz) - &
flux_n(${NORM_DIR}$)%vf(eqn)%sf(x, y, z))/d${XYZ}$ (${XYZ}$)

end do

end do
end do
end do

end subroutine s_compute_chemistry_rhs_${XYZ}$
#:endfor

subroutine s_compute_chemistry_reaction_flux(rhs_vf, q_cons_qp, q_prim_qp)

type(scalar_field), dimension(sys_size), intent(INOUT) :: rhs_vf, q_cons_qp, q_prim_qp
Expand All @@ -104,50 +69,47 @@ contains
real(kind(0d0)) :: dyn_pres
real(kind(0d0)) :: E

real(kind(0d0)) :: rho
real(kind(1.d0)), dimension(num_species) :: Ys
real(kind(1.d0)), dimension(num_species) :: omega
real(kind(0d0)) :: rho, omega_m, omega_T
real(kind(0d0)), dimension(num_species) :: Ys
real(kind(0d0)), dimension(num_species) :: omega
real(kind(0d0)), dimension(num_species) :: enthalpies
real(kind(0d0)) :: cp_mix

#:if chemistry

!$acc parallel loop collapse(4) private(rho)
!$acc parallel loop collapse(3) private(rho)
do x = 0, m
do y = 0, n
do z = 0, p

! Maybe use q_prim_vf instead?
rho = 0d0
do eqn = chemxb, chemxe
rho = rho + q_cons_qp(eqn)%sf(x, y, z)
end do

do eqn = chemxb, chemxe
Ys(eqn - chemxb + 1) = q_cons_qp(eqn)%sf(x, y, z)/rho
Ys(eqn - chemxb + 1) = q_prim_qp(eqn)%sf(x, y, z)
end do

dyn_pres = 0d0

do i = momxb, momxe
dyn_pres = dyn_pres + rho*q_cons_qp(i)%sf(x, y, z)* &
q_cons_qp(i)%sf(x, y, z)/2d0
dyn_pres = dyn_pres + q_cons_qp(i)%sf(x, y, z)* &
q_prim_qp(i)%sf(x, y, z)/2d0
end do

call get_temperature(.true., q_cons_qp(E_idx)%sf(x, y, z) - dyn_pres, &
& q_prim_qp(tempxb)%sf(x, y, z), Ys, T)
call get_temperature(q_cons_qp(E_idx)%sf(x, y, z)/rho - dyn_pres/rho, &
& 1200d0, Ys, .true., T)

call get_net_production_rates(rho, T, Ys, omega)

q_cons_qp(tempxb)%sf(x, y, z) = T
q_prim_qp(tempxb)%sf(x, y, z) = T

!print*, x, y, z, T, rho, Ys, omega, q_cons_qp(E_idx)%sf(x, y, z), dyn_pres
call get_species_enthalpies_rt(T, enthalpies)

do eqn = chemxb, chemxe

rhs_vf(eqn)%sf(x, y, z) = rhs_vf(eqn)%sf(x, y, z) + &
mol_weights(eqn - chemxb + 1)*omega(eqn - chemxb + 1)
omega_m = mol_weights(eqn - chemxb + 1)*omega(eqn - chemxb + 1)
omega_T = omega_m*enthalpies(eqn - chemxb + 1)*gas_constant*T

rhs_vf(eqn)%sf(x, y, z) = rhs_vf(eqn)%sf(x, y, z) + omega_m

end do

Expand All @@ -171,9 +133,9 @@ contains
integer :: eqn

!$acc parallel loop collapse(4)
do x = ix%beg, ix%end
do y = iy%beg, iy%end
do z = iz%beg, iz%end
do x = 0, m
do y = 0, n
do z = 0, p

do eqn = chemxb, chemxe
q_cons_qp(eqn)%sf(x, y, z) = max(0d0, q_cons_qp(eqn)%sf(x, y, z))
Expand Down
13 changes: 7 additions & 6 deletions src/simulation/m_data_output.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ contains
real(kind(0d0)) :: E_e
real(kind(0d0)), dimension(6) :: tau_e
real(kind(0d0)) :: G
real(kind(0d0)) :: dyn_p
real(kind(0d0)) :: dyn_p, Temp

integer :: i, j, k, l, s, q, d !< Generic loop iterator

Expand Down Expand Up @@ -1054,14 +1054,14 @@ contains
call s_compute_pressure( &
q_cons_vf(1)%sf(j - 2, k, l), &
q_cons_vf(alf_idx)%sf(j - 2, k, l), &
dyn_p, pi_inf, gamma, rho, qv, rhoYks(:), pres, &
dyn_p, pi_inf, gamma, rho, qv, rhoYks(:), pres, Temp, &
q_cons_vf(stress_idx%beg)%sf(j - 2, k, l), &
q_cons_vf(mom_idx%beg)%sf(j - 2, k, l), G)
else
call s_compute_pressure( &
q_cons_vf(1)%sf(j - 2, k, l), &
q_cons_vf(alf_idx)%sf(j - 2, k, l), &
dyn_p, pi_inf, gamma, rho, qv, rhoYks(:), pres)
dyn_p, pi_inf, gamma, rho, qv, rhoYks(:), pres, Temp)
end if

if (model_eqns == 4) then
Expand Down Expand Up @@ -1163,13 +1163,14 @@ contains
dyn_p, pi_inf, gamma, rho, qv, &
rhoYks, &
pres, &
Temp, &
q_cons_vf(stress_idx%beg)%sf(j - 2, k - 2, l), &
q_cons_vf(mom_idx%beg)%sf(j - 2, k - 2, l), G)
else
call s_compute_pressure(q_cons_vf(E_idx)%sf(j - 2, k - 2, l), &
q_cons_vf(alf_idx)%sf(j - 2, k - 2, l), &
dyn_p, pi_inf, gamma, rho, qv, &
rhoYks, pres)
rhoYks, pres, Temp)
end if

if (model_eqns == 4) then
Expand Down Expand Up @@ -1253,14 +1254,14 @@ contains
q_cons_vf(1)%sf(j - 2, k - 2, l - 2), &
q_cons_vf(alf_idx)%sf(j - 2, k - 2, l - 2), &
dyn_p, pi_inf, gamma, rho, qv, &
rhoYks, pres, &
rhoYks, pres, Temp, &
q_cons_vf(stress_idx%beg)%sf(j - 2, k - 2, l - 2), &
q_cons_vf(mom_idx%beg)%sf(j - 2, k - 2, l - 2), G)
else
call s_compute_pressure(q_cons_vf(E_idx)%sf(j - 2, k - 2, l - 2), &
q_cons_vf(alf_idx)%sf(j - 2, k - 2, l - 2), &
dyn_p, pi_inf, gamma, rho, qv, &
rhoYks, pres)
rhoYks, pres, Temp)
end if

! Compute mixture sound speed
Expand Down
20 changes: 10 additions & 10 deletions src/simulation/m_global_parameters.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,16 @@ contains
end if
! END: Volume Fraction Model =======================================

if (chemistry) then
species_idx%beg = sys_size + 1
species_idx%end = sys_size + num_species
sys_size = species_idx%end

temperature_idx%beg = sys_size + 1
temperature_idx%end = sys_size + 1
sys_size = temperature_idx%end
end if

if (qbmm .and. .not. polytropic) then
allocate (MPI_IO_DATA%view(1:sys_size + 2*nb*4))
allocate (MPI_IO_DATA%var(1:sys_size + 2*nb*4))
Expand Down Expand Up @@ -1067,16 +1077,6 @@ contains
grid_geometry = 3
end if

if (chemistry) then
species_idx%beg = sys_size + 1
species_idx%end = sys_size + num_species
sys_size = species_idx%end

temperature_idx%beg = sys_size + 1
temperature_idx%end = sys_size + 1
sys_size = temperature_idx%end
end if

momxb = mom_idx%beg
momxe = mom_idx%end
advxb = adv_idx%beg
Expand Down
Loading

0 comments on commit 96bb43d

Please sign in to comment.