Skip to content

Multicomponent diffusion fluxes, thermal conduction, and mixture viscosity #934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
26f8438
Diffusion Fluxes
DimAdam-01 Jun 8, 2025
7321195
Debugging
DimAdam-01 Jun 9, 2025
bd73252
....
DimAdam-01 Jun 9, 2025
54a0cc4
dfedfe
DimAdam-01 Jun 10, 2025
5cf3a68
dff
DimAdam-01 Jun 11, 2025
7dd0869
MInor Bugs
DimAdam-01 Jun 11, 2025
ba9a48a
Minor Bugs
DimAdam-01 Jun 11, 2025
d9ee1f0
fef
Jun 11, 2025
52a7936
fkjkfje
Jun 11, 2025
8248f97
ferfe
DimAdam-01 Jun 12, 2025
859c085
Merge branch 'Diffusion' of https://github.com/DimAdam-01/MFC-Adam in…
DimAdam-01 Jun 12, 2025
c604675
Loop stuff
DimAdam-01 Jun 12, 2025
beb8022
...
DimAdam-01 Jun 12, 2025
4232149
Delta Issue
Jun 13, 2025
3c6654e
Small Changes
DimAdam-01 Jun 16, 2025
1f126d6
Small Changes V2
DimAdam-01 Jun 16, 2025
8b63895
...
DimAdam-01 Jun 16, 2025
b7ff1db
Spelling
DimAdam-01 Jun 16, 2025
369ad7a
Merge branch 'MFlowCode:master' into Diffusion
DimAdam-01 Jun 16, 2025
59ca1c7
Merge branch 'master' into Diffusion
sbryngelson Jun 18, 2025
3ed1ca3
Merge branch 'master' into Diffusion
sbryngelson Jun 21, 2025
616a3f4
Merge branch 'master' into Diffusion
sbryngelson Jun 21, 2025
98980bd
Refactoring and Deallocation
DimAdam-01 Jun 21, 2025
31ec1aa
Merge branch 'Diffusion' of https://github.com/DimAdam-01/MFC-Adam in…
DimAdam-01 Jun 21, 2025
2cd25d3
Small Stuff
DimAdam-01 Jun 21, 2025
6cc8fec
Small Changes
DimAdam-01 Jun 21, 2025
132123d
Merge branch 'master' into Diffusion
sbryngelson Jun 21, 2025
1186335
Chem ToolChain
DimAdam-01 Jun 21, 2025
6988404
Merge branch 'Diffusion' of https://github.com/DimAdam-01/MFC-Adam in…
DimAdam-01 Jun 21, 2025
2ccbc6d
...
DimAdam-01 Jun 21, 2025
17b9194
..
DimAdam-01 Jun 22, 2025
cf1b9a2
Diffusion Golden File
DimAdam-01 Jun 23, 2025
326f76e
Small changes
DimAdam-01 Jul 9, 2025
2465fbd
Changing Stuff
DimAdam-01 Jul 9, 2025
2b18cd6
Small_Changes
DimAdam-01 Jul 9, 2025
d707566
Stuff
DimAdam-01 Jul 10, 2025
be3d515
Small Changes V2
DimAdam-01 Jul 10, 2025
6ef589f
Replace tests/ directory with upstream version
DimAdam-01 Jul 11, 2025
5689fd3
Final Changes
DimAdam-01 Jul 11, 2025
71ea1f2
Final Changes v2
DimAdam-01 Jul 11, 2025
7d16c6c
Final Changes v3
DimAdam-01 Jul 11, 2025
61b88ee
Final Changes v4
DimAdam-01 Jul 11, 2025
42e8f58
Small Stuff
DimAdam-01 Jul 12, 2025
86ed984
Small v3
DimAdam-01 Jul 12, 2025
c794936
WhiteSpace
DimAdam-01 Jul 13, 2025
d445357
Small Stuff
DimAdam-01 Jul 13, 2025
ffbbcdf
..
DimAdam-01 Jul 14, 2025
a73b502
Changing case.py for Premixed FLame
DimAdam-01 Jul 14, 2025
c792713
..
DimAdam-01 Jul 14, 2025
222c7cc
Remove duplicate test cases
DimAdam-01 Jul 14, 2025
742a84b
Small Changes
DimAdam-01 Jul 14, 2025
5e5cd04
Tolerances
DimAdam-01 Jul 15, 2025
e4ac18d
Merge branch 'master' into Diffusion
sbryngelson Jul 15, 2025
e0e0705
Small test
DimAdam-01 Jul 16, 2025
8194bbf
Merge branch 'Diffusion' of github.com:DimAdam-01/MFC-Adam into Diffu…
DimAdam-01 Jul 16, 2025
0e8fc03
Newton Raphson Tolerance Frontier Test
DimAdam-01 Jul 16, 2025
eb3872f
Merge remote-tracking branch 'upstream/master' into Diffusion
Aug 21, 2025
aba114a
Small Stuff
Aug 21, 2025
850fc1c
Resolve Merge Issues
Aug 21, 2025
1be6711
Frontier Issue Checking
Aug 22, 2025
cd50df5
Formatting
Aug 22, 2025
6d40d6e
...
Aug 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/1D_inert_shocktube/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"mapped_weno": "T",
"mp_weno": "T",
"riemann_solver": 2,
"wave_speeds": 2,
"avg_state": 1,
"wave_speeds": 1,
"avg_state": 2,
"bc_x%beg": -2,
"bc_x%end": -3,
# Chemistry
Expand Down
168 changes: 167 additions & 1 deletion src/common/m_chemistry.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,37 @@ module m_chemistry

use m_thermochem, only: &
num_species, molecular_weights, get_temperature, get_net_production_rates, &
gas_constant, get_mixture_molecular_weight
get_mole_fractions, get_species_binary_mass_diffusivities, &
get_species_mass_diffusivities_mixavg, gas_constant, get_mixture_molecular_weight, &
get_mixture_energy_mass, get_mixture_thermal_conductivity_mixavg, get_species_enthalpies_rt, &
get_mixture_viscosity_mixavg

use m_global_parameters

implicit none

type(int_bounds_info) :: isc1, isc2, isc3
$:GPU_DECLARE(create='[isc1, isc2, isc3]')
integer, dimension(3) :: offsets
$:GPU_DECLARE(create='[offsets]')

contains

subroutine compute_viscosity_and_inversion(T_L, Ys_L, T_R, Ys_R, Re_L, Re_R)

$:GPU_ROUTINE(function_name='compute_viscosity_and_inversion',parallelism='[seq]', &
& cray_inline=True)

real(wp), intent(inout) :: T_L, T_R, Re_L, Re_R
real(wp), dimension(num_species), intent(inout) :: Ys_R, Ys_L

call get_mixture_viscosity_mixavg(T_L, Ys_L, Re_L)
call get_mixture_viscosity_mixavg(T_R, Ys_R, Re_R)
Re_L = 1.0_wp/Re_L
Re_R = 1.0_wp/Re_R

end subroutine compute_viscosity_and_inversion

subroutine s_compute_q_T_sf(q_T_sf, q_cons_vf, bounds)

! Initialize the temperature field at the start of the simulation to
Expand Down Expand Up @@ -129,4 +152,147 @@ contains

end subroutine s_compute_chemistry_reaction_flux

subroutine s_compute_chemistry_diffusion_flux(idir, q_prim_qp, flux_src_vf, irx, iry, irz)

type(scalar_field), dimension(sys_size), intent(in) :: q_prim_qp
type(scalar_field), dimension(sys_size), intent(inout) :: flux_src_vf
type(int_bounds_info), intent(in) :: irx, iry, irz

integer, intent(in) :: idir

real(wp), dimension(num_species) :: Xs_L, Xs_R, Xs_cell, Ys_L, Ys_R, Ys_cell
real(wp), dimension(num_species) :: mass_diffusivities_mixavg1, mass_diffusivities_mixavg2
real(wp), dimension(num_species) :: mass_diffusivities_mixavg_Cell, dXk_dxi, h_l, h_r, h_k
real(wp), dimension(num_species) :: Mass_Diffu_Flux
real(wp) :: Mass_Diffu_Energy
real(wp) :: MW_L, MW_R, MW_cell, Rgas_L, Rgas_R, T_L, T_R, P_L, P_R, rho_L, rho_R, rho_cell, rho_Vic
real(wp) :: lambda_L, lambda_R, lambda_Cell, dT_dxi, grid_spacing

integer :: x, y, z, i, n, eqn
integer, dimension(3) :: offsets

isc1 = irx; isc2 = iry; isc3 = irz

$:GPU_UPDATE(device='[isc1,isc2,isc3]')

if (chemistry) then
! Set offsets based on direction using array indexing
offsets = 0
offsets(idir) = 1

$:GPU_PARALLEL_LOOP(collapse=3, private='[Ys_L, Ys_R, Ys_cell, &
& Xs_L, Xs_R, mass_diffusivities_mixavg1, mass_diffusivities_mixavg2, &
& mass_diffusivities_mixavg_Cell, h_l, h_r, Xs_cell, h_k, &
& dXk_dxi,Mass_Diffu_Flux]', copyin='[offsets]')
do z = isc3%beg, isc3%end
do y = isc2%beg, isc2%end
do x = isc1%beg, isc1%end
! Calculate grid spacing using direction-based indexing
select case (idir)
case (1)
grid_spacing = x_cc(x + 1) - x_cc(x)
case (2)
grid_spacing = y_cc(y + 1) - y_cc(y)
case (3)
grid_spacing = z_cc(z + 1) - z_cc(z)
end select

! Extract species mass fractions
$:GPU_LOOP(parallelism='[seq]')
do i = chemxb, chemxe
Ys_L(i - chemxb + 1) = q_prim_qp(i)%sf(x, y, z)
Ys_R(i - chemxb + 1) = q_prim_qp(i)%sf(x + offsets(1), y + offsets(2), z + offsets(3))
Ys_cell(i - chemxb + 1) = 0.5_wp*(Ys_L(i - chemxb + 1) + Ys_R(i - chemxb + 1))
end do

! Calculate molecular weights and mole fractions
call get_mixture_molecular_weight(Ys_L, MW_L)
call get_mixture_molecular_weight(Ys_R, MW_R)
MW_cell = 0.5_wp*(MW_L + MW_R)

call get_mole_fractions(MW_L, Ys_L, Xs_L)
call get_mole_fractions(MW_R, Ys_R, Xs_R)

! Calculate gas constants and thermodynamic properties
Rgas_L = gas_constant/MW_L
Rgas_R = gas_constant/MW_R

P_L = q_prim_qp(E_idx)%sf(x, y, z)
P_R = q_prim_qp(E_idx)%sf(x + offsets(1), y + offsets(2), z + offsets(3))

rho_L = q_prim_qp(1)%sf(x, y, z)
rho_R = q_prim_qp(1)%sf(x + offsets(1), y + offsets(2), z + offsets(3))

T_L = P_L/rho_L/Rgas_L
T_R = P_R/rho_R/Rgas_R

rho_cell = 0.5_wp*(rho_L + rho_R)
dT_dxi = (T_R - T_L)/grid_spacing

! Get transport properties
call get_species_mass_diffusivities_mixavg(P_L, T_L, Ys_L, mass_diffusivities_mixavg1)
call get_species_mass_diffusivities_mixavg(P_R, T_R, Ys_R, mass_diffusivities_mixavg2)

call get_mixture_thermal_conductivity_mixavg(T_L, Ys_L, lambda_L)
call get_mixture_thermal_conductivity_mixavg(T_R, Ys_R, lambda_R)

call get_species_enthalpies_rt(T_L, h_l)
call get_species_enthalpies_rt(T_R, h_r)

! Calculate species properties and gradients
$:GPU_LOOP(parallelism='[seq]')
do i = chemxb, chemxe
h_l(i - chemxb + 1) = h_l(i - chemxb + 1)*gas_constant*T_L/molecular_weights(i - chemxb + 1)
h_r(i - chemxb + 1) = h_r(i - chemxb + 1)*gas_constant*T_R/molecular_weights(i - chemxb + 1)
Xs_cell(i - chemxb + 1) = 0.5_wp*(Xs_L(i - chemxb + 1) + Xs_R(i - chemxb + 1))
h_k(i - chemxb + 1) = 0.5_wp*(h_l(i - chemxb + 1) + h_r(i - chemxb + 1))
dXk_dxi(i - chemxb + 1) = (Xs_R(i - chemxb + 1) - Xs_L(i - chemxb + 1))/grid_spacing
end do

! Calculate mixture-averaged diffusivities
$:GPU_LOOP(parallelism='[seq]')
do i = chemxb, chemxe
mass_diffusivities_mixavg_Cell(i - chemxb + 1) = &
(mass_diffusivities_mixavg2(i - chemxb + 1) + mass_diffusivities_mixavg1(i - chemxb + 1))/ &
2.0_wp*(1.0_wp - Xs_cell(i - chemxb + 1))/(1.0_wp - Ys_cell(i - chemxb + 1))
end do

lambda_Cell = 0.5_wp*(lambda_R + lambda_L)

! Calculate mass diffusion fluxes
rho_Vic = 0.0_wp
Mass_Diffu_Energy = 0.0_wp

$:GPU_LOOP(parallelism='[seq]')
do eqn = chemxb, chemxe
Mass_Diffu_Flux(eqn - chemxb + 1) = rho_cell*mass_diffusivities_mixavg_Cell(eqn - chemxb + 1)* &
molecular_weights(eqn - chemxb + 1)/MW_cell*dXk_dxi(eqn - chemxb + 1)
rho_Vic = rho_Vic + Mass_Diffu_Flux(eqn - chemxb + 1)
Mass_Diffu_Energy = Mass_Diffu_Energy + h_k(eqn - chemxb + 1)*Mass_Diffu_Flux(eqn - chemxb + 1)
end do

! Apply corrections for mass conservation
$:GPU_LOOP(parallelism='[seq]')
do eqn = chemxb, chemxe
Mass_Diffu_Energy = Mass_Diffu_Energy - h_k(eqn - chemxb + 1)*Ys_cell(eqn - chemxb + 1)*rho_Vic
Mass_Diffu_Flux(eqn - chemxb + 1) = Mass_Diffu_Flux(eqn - chemxb + 1) - rho_Vic*Ys_cell(eqn - chemxb + 1)
end do

! Add thermal conduction contribution
Mass_Diffu_Energy = lambda_Cell*dT_dxi + Mass_Diffu_Energy

! Update flux arrays
flux_src_vf(E_idx)%sf(x, y, z) = flux_src_vf(E_idx)%sf(x, y, z) - Mass_Diffu_Energy

$:GPU_LOOP(parallelism='[seq]')
do eqn = chemxb, chemxe
flux_src_vf(eqn)%sf(x, y, z) = flux_src_vf(eqn)%sf(x, y, z) - Mass_diffu_Flux(eqn - chemxb + 1)
end do
end do
end do
end do
end if

end subroutine s_compute_chemistry_diffusion_flux

end module m_chemistry
3 changes: 1 addition & 2 deletions src/common/m_variables_conversion.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,12 +1639,11 @@ contains
real(wp), intent(out) :: c

real(wp) :: blkmod1, blkmod2
real(wp) :: Tolerance

integer :: q

if (chemistry) then
if (avg_state == 1 .and. abs(c_c) > Tolerance) then
if (avg_state == 1 .and. abs(c_c) > verysmall) then
c = sqrt(c_c - (gamma - 1.0_wp)*(vel_sum - H))
else
c = sqrt((1.0_wp + 1.0_wp/gamma)*pres/rho)
Expand Down
Loading
Loading