Skip to content

Commit 98980bd

Browse files
committed
Refactoring and Deallocation
1 parent 59ca1c7 commit 98980bd

File tree

9 files changed

+454
-10
lines changed

9 files changed

+454
-10
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python3
2+
3+
# References:
4+
# + DOI: 10.2514/6.2020-1751: IV.B. Multi-component diffusion
5+
6+
import json
7+
import argparse
8+
import math
9+
10+
import cantera as ct
11+
12+
parser = argparse.ArgumentParser(
13+
prog="1D_MultiComponent_Diffusion",
14+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
15+
16+
parser.add_argument("--mfc", type=json.loads, default='{}', metavar="DICT",
17+
help="MFC's toolchain's internal state.")
18+
parser.add_argument("--no-chem", dest='chemistry', default=True, action="store_false",
19+
help="Disable chemistry.")
20+
21+
args = parser.parse_args()
22+
23+
ctfile = 'grigri.yaml'
24+
25+
L = 0.05
26+
Nx = 100
27+
dx = L / Nx
28+
dt = 0.3e-6
29+
Tend = 0.05
30+
31+
NT = int(Tend / dt)
32+
SAVE_COUNT = 2000
33+
NS = 2000
34+
case = {
35+
'run_time_info' : 'T',
36+
'x_domain%beg' : 0,
37+
'x_domain%end' : +L,
38+
'm' : Nx,
39+
'n' : 0,
40+
'p' : 0,
41+
'dt' : float(dt),
42+
't_step_start' : 0,
43+
't_step_stop' : NT,
44+
't_step_save' : NS,
45+
't_step_print' : NS,
46+
'parallel_io' : 'F',
47+
'model_eqns' : 2,
48+
'num_fluids' : 1,
49+
'num_patches' : 1,
50+
'mpp_lim' : 'F',
51+
'mixture_err' : 'F',
52+
'time_stepper' : 3,
53+
'weno_order' : 5,
54+
'weno_eps' : 1E-16,
55+
'weno_avg' : 'F',
56+
'mapped_weno' : 'T',
57+
'mp_weno' : 'T',
58+
'riemann_solver' : 2,
59+
'wave_speeds' : 2,
60+
'avg_state' : 1,
61+
'bc_x%beg' :-1,
62+
'bc_x%end' :-1,
63+
'chemistry' : 'T' if not args.chemistry else 'T',
64+
'chem_params%diffusion' : 'T',
65+
'chem_params%reactions' : 'F',
66+
'format' : 1,
67+
'precision' : 2,
68+
'prim_vars_wrt' : 'T',
69+
'patch_icpp(1)%geometry' : 1,
70+
'patch_icpp(1)%x_centroid' : L/2,
71+
'patch_icpp(1)%length_x' : L,
72+
'patch_icpp(1)%vel(1)' : '0',
73+
'patch_icpp(1)%pres' : 1.01325e5,
74+
'patch_icpp(1)%alpha(1)' : 1,
75+
'patch_icpp(1)%Y(1)' : '(0.195-0.142)*(1-0.5*exp(-(x-0.05d0/2.0d0)**2/(2.5d0*10.0d0**(-3.0d0))**2))+0.142',
76+
'patch_icpp(1)%Y(2)' : '(0.0-0.1)*(1-0.5*exp(-(x-0.05d0/2.0d0)**2/(2.5d0*10.0d0**(-3.0d0))**2))+0.1',
77+
'patch_icpp(1)%Y(3)' : '(0.214-0.0)*(1-0.5*exp(-(x-0.05d0/2.0d0)**2/(2.5d0*10.0d0**(-3.0d0))**2))+0.0',
78+
'patch_icpp(1)%Y(4)' : '(0.591-0.758)*(1-0.5*exp(-(x-0.05d0/2.0d0)**2/(2.5d0*10.0d0**(-3.0d0))**2))+0.758',
79+
'patch_icpp(1)%alpha_rho(1)' : '1.01325d0*10.0d0**(5.0d0)/(((320.0d0-1350.0d0)*(1.0d0-0.50d0*exp(-(x-0.05d0/2.0d0)**2/(2.5d0*10.0d0**(-3.0d0))**2))+1350.0d0)*8.3144626d0*1000.0d0*( ((0.195d0-0.142d0)*(1.0d0-0.5d0*exp(-(x-0.05d0/2.0d0)**2/(2.5d0*10.0d0**(-3.0d0))**2))+0.142d0)/31.998d0 +((0.0-0.1)*(1-0.5*exp(-(x-0.05d0/2.0d0)**2/(2.5d0*10.0d0**(-3.0d0))**2))+0.1)/18.01508d0+ ((0.214-0.0)*(1-0.5*exp(-(x-0.05d0/2.0d0)**2/(2.5d0*10.0d0**(-3.0d0))**2))+0.0)/16.04256 + ((0.591-0.758)*(1-0.5*exp(-(x-0.05d0/2.0d0)**2/(2.5d0*10.0d0**(-3.0d0))**2))+0.758)/28.0134))',
80+
81+
'fluid_pp(1)%gamma' : 1.0E+00/(1.9326E+00-1.0E+00),
82+
'fluid_pp(1)%pi_inf' : 0,
83+
'cantera_file' : ctfile,
84+
}
85+
86+
if args.chemistry:
87+
for i in range(4):
88+
case[f'chem_wrt_Y({i + 1})'] = 'T'
89+
if __name__ == '__main__':
90+
print(json.dumps(case))
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
description: |-
2+
GRI-Mech Version 3.0 7/30/99 CHEMKIN-II format
3+
See README30 file at anonymous FTP site unix.sri.com, directory gri;
4+
WorldWideWeb home page http://www.me.berkeley.edu/gri_mech/ or
5+
through http://www.gri.org , under 'Basic Research',
6+
for additional information, contacts, and disclaimer
7+
8+
Updated webpage at http://combustion.berkeley.edu/gri-mech/version30/text30.html
9+
10+
generator: ck2yaml
11+
input-files: [gri30.inp, gri30_thermo.dat, gri30_tran.dat]
12+
cantera-version: 2.5.0
13+
date: Wed, 11 Dec 2019 16:59:02 -0500
14+
15+
units: {length: cm, time: s, quantity: mol, activation-energy: cal/mol}
16+
17+
phases:
18+
- name: gri30
19+
thermo: ideal-gas
20+
elements: [O, H, C, N]
21+
species: [O2, H2O, CH4, N2]
22+
kinetics: gas
23+
transport: mixture-averaged
24+
state: {T: 300.0, P: 1 atm}
25+
26+
species:
27+
- name: O2
28+
composition: {O: 2}
29+
thermo:
30+
model: NASA7
31+
temperature-ranges: [200.0, 1000.0, 3500.0]
32+
data:
33+
- [3.78245636, -2.99673416e-03, 9.84730201e-06, -9.68129509e-09, 3.24372837e-12,
34+
-1063.94356, 3.65767573]
35+
- [3.28253784, 1.48308754e-03, -7.57966669e-07, 2.09470555e-10, -2.16717794e-14,
36+
-1088.45772, 5.45323129]
37+
note: TPIS89
38+
transport:
39+
model: gas
40+
geometry: linear
41+
well-depth: 107.4
42+
diameter: 3.458
43+
polarizability: 1.6
44+
rotational-relaxation: 3.8
45+
- name: H2O
46+
composition: {H: 2, O: 1}
47+
thermo:
48+
model: NASA7
49+
temperature-ranges: [200.0, 1000.0, 3500.0]
50+
data:
51+
- [4.19864056, -2.0364341e-03, 6.52040211e-06, -5.48797062e-09, 1.77197817e-12,
52+
-3.02937267e+04, -0.849032208]
53+
- [3.03399249, 2.17691804e-03, -1.64072518e-07, -9.7041987e-11, 1.68200992e-14,
54+
-3.00042971e+04, 4.9667701]
55+
note: L8/89
56+
transport:
57+
model: gas
58+
geometry: nonlinear
59+
well-depth: 572.4
60+
diameter: 2.605
61+
dipole: 1.844
62+
rotational-relaxation: 4.0
63+
- name: CH4
64+
composition: {C: 1, H: 4}
65+
thermo:
66+
model: NASA7
67+
temperature-ranges: [200.0, 1000.0, 3500.0]
68+
data:
69+
- [5.14987613, -0.0136709788, 4.91800599e-05, -4.84743026e-08, 1.66693956e-11,
70+
-1.02466476e+04, -4.64130376]
71+
- [0.074851495, 0.0133909467, -5.73285809e-06, 1.22292535e-09, -1.0181523e-13,
72+
-9468.34459, 18.437318]
73+
note: L8/88
74+
transport:
75+
model: gas
76+
geometry: nonlinear
77+
well-depth: 141.4
78+
diameter: 3.746
79+
polarizability: 2.6
80+
rotational-relaxation: 13.0
81+
- name: N2
82+
composition: {N: 2}
83+
thermo:
84+
model: NASA7
85+
temperature-ranges: [300.0, 1000.0, 5000.0]
86+
data:
87+
- [3.298677, 1.4082404e-03, -3.963222e-06, 5.641515e-09, -2.444854e-12,
88+
-1020.8999, 3.950372]
89+
- [2.92664, 1.4879768e-03, -5.68476e-07, 1.0097038e-10, -6.753351e-15,
90+
-922.7977, 5.980528]
91+
note: '121286'
92+
transport:
93+
model: gas
94+
geometry: linear
95+
well-depth: 97.53
96+
diameter: 3.621
97+
polarizability: 1.76
98+
rotational-relaxation: 4.0
99+
100+
reactions:
101+
- equation: CH4 <=> CH4 # Reaction 1
102+
rate-constant: {A: 1.927e+13, b: -0.32, Ea: 0.0}
103+
- equation: N2 <=> N2 # Reaction 2
104+
rate-constant: {A: 1.927e+13, b: -0.32, Ea: 0.0}
105+
- equation: H2O <=> H2O # Reaction 3
106+
rate-constant: {A: 1.927e+13, b: -0.32, Ea: 0.0}
107+
- equation: O2 <=> O2 # Reaction 4
108+
rate-constant: {A: 1.927e+13, b: -0.32, Ea: 0.0}

src/common/m_chemistry.fpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module m_chemistry
1212
num_species, molecular_weights, get_temperature, get_net_production_rates, &
1313
get_mole_fractions, get_species_binary_mass_diffusivities, &
1414
get_species_mass_diffusivities_mixavg, gas_constant, get_mixture_molecular_weight, &
15-
get_mixture_energy_mass, get_mixture_thermal_conductivity_mixavg, get_species_enthalpies_rt
15+
get_mixture_energy_mass, get_mixture_thermal_conductivity_mixavg, get_species_enthalpies_rt, &
16+
get_mixture_viscosity_mixavg
1617

1718
use m_global_parameters
1819

@@ -25,6 +26,18 @@ module m_chemistry
2526
!$acc declare create(offsets)
2627
contains
2728

29+
subroutine compute_viscosity_and_inversion(T_L, Ys_L, T_R, Ys_R, Re_L, Re_R)
30+
31+
real(wp), intent(inout) :: T_L, T_R, Re_L, Re_R
32+
real(wp), dimension(num_species), intent(inout) :: Ys_R, Ys_L
33+
34+
call get_mixture_viscosity_mixavg(T_L, Ys_L, Re_L)
35+
call get_mixture_viscosity_mixavg(T_R, Ys_R, Re_R)
36+
Re_L = 1.0_wp/Re_L
37+
Re_R = 1.0_wp/Re_R
38+
39+
end subroutine compute_viscosity_and_inversion
40+
2841
subroutine s_compute_q_T_sf(q_T_sf, q_cons_vf, bounds)
2942

3043
! Initialize the temperature field at the start of the simulation to

src/simulation/m_rhs.fpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,10 @@ contains
19841984
end do
19851985
end if
19861986

1987+
if (chem_params%diffusion .and. .not. viscous)
1988+
@:DEALLOCATE(flux_src_n(i)%vf(E_idx)%sf)
1989+
end if
1990+
19871991
if (riemann_solver == 1 .or. riemann_solver == 4) then
19881992
do l = adv_idx%beg + 1, adv_idx%end
19891993
@:DEALLOCATE(flux_src_n(i)%vf(l)%sf)

src/simulation/m_riemann_solvers.fpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module m_riemann_solvers
4747
gas_constant, get_mixture_molecular_weight, &
4848
get_mixture_specific_heat_cv_mass, get_mixture_energy_mass, &
4949
get_species_specific_heats_r, get_species_enthalpies_rt, &
50-
get_mixture_specific_heat_cp_mass, get_mixture_viscosity_mixavg
50+
get_mixture_specific_heat_cp_mass
5151

5252
implicit none
5353

@@ -677,10 +677,7 @@ contains
677677

678678
if (viscous) then
679679
if (chemistry) then
680-
call get_mixture_viscosity_mixavg(T_L, Ys_L, Re_L(1))
681-
call get_mixture_viscosity_mixavg(T_R, Ys_R, Re_R(1))
682-
Re_L(1) = 1.0_wp/Re_L(1)
683-
Re_R(1) = 1.0_wp/Re_R(1)
680+
call compute_viscosity_and_inversion(T_L, Ys_L, T_R, Ys_R, Re_L(1), Re_R(1))
684681
end if
685682
!$acc loop seq
686683
do i = 1, 2
@@ -2692,10 +2689,7 @@ contains
26922689
26932690
if (viscous) then
26942691
if (chemistry) then
2695-
call get_mixture_viscosity_mixavg(T_L, Ys_L, Re_L(1))
2696-
call get_mixture_viscosity_mixavg(T_R, Ys_R, Re_R(1))
2697-
Re_L(1) = 1.0_wp/Re_L(1)
2698-
Re_R(1) = 1.0_wp/Re_R(1)
2692+
call compute_viscosity_and_inversion(T_L, Ys_L, T_R, Ys_R, Re_L(1), Re_R(1))
26992693
end if
27002694
!$acc loop seq
27012695
do i = 1, 2

0 commit comments

Comments
 (0)