From 77b40a47c33b75c559e7e86bc1062ed0d5f96131 Mon Sep 17 00:00:00 2001 From: Dimitrios Adam Date: Thu, 29 May 2025 16:33:06 -0400 Subject: [PATCH 1/5] Pre_process Speedup_Test --- examples/1D_CJ_Wabe/case.py | 121 ++++++++++++++++++++++++ examples/1D_Lefe/case.py | 120 +++++++++++++++++++++++ src/common/m_chemistry.fpp | 26 +++++ src/pre_process/m_initial_condition.fpp | 5 +- 4 files changed, 268 insertions(+), 4 deletions(-) create mode 100644 examples/1D_CJ_Wabe/case.py create mode 100644 examples/1D_Lefe/case.py diff --git a/examples/1D_CJ_Wabe/case.py b/examples/1D_CJ_Wabe/case.py new file mode 100644 index 0000000000..683ad34434 --- /dev/null +++ b/examples/1D_CJ_Wabe/case.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +# References: +# + https://doi.org/10.1016/j.ijhydene.2023.03.190: Verification of numerical method +# + https://doi.org/10.1016/j.compfluid.2013.10.014: 4.7. Multi-species reactive shock tube + +import json, argparse +import cantera as ct + +parser = argparse.ArgumentParser(prog="1D_reactive_shocktube", formatter_class=argparse.ArgumentDefaultsHelpFormatter) + +parser.add_argument( + "--mfc", + type=json.loads, + default="{}", + metavar="DICT", + help="MFC's toolchain's internal state.", +) +parser.add_argument( + "--no-chem", + dest="chemistry", + default=True, + action="store_false", + help="Disable chemistry.", +) +parser.add_argument("--scale", type=float, default=1, help="Scale.") + +args = parser.parse_args() + +ctfile = "h2o2.yaml" +sol_L = ct.Solution(ctfile) +sol_L.DPX = 0.351340, 182070.11, "H2:2,O2:1,AR:7" + +sol_R = ct.Solution(ctfile) +sol_R.DPX = 0.08498, 6670, "H2:2,O2:1,AR:7" + +u_l = 1250.90 +u_r = 0 + +L = 0.18 +Nx = 3000 * args.scale +dx = L / Nx +dt = dx / abs(600) * 0.02*0.5 +Tend = 230e-6 + +NT = int(Tend / dt) +SAVE_COUNT = 100 +NS = NT // SAVE_COUNT + +case = { + # Logistics + "run_time_info": "T", + # Computational Domain Parameters + "x_domain%beg": 0, + "x_domain%end": L, + "m": Nx, + "n": 0, + "p": 0, + "dt": float(dt), + "t_step_start": 0, + "t_step_stop": 180000, + "t_step_save": 5000, + "t_step_print": 600, + "parallel_io": "F" if args.mfc.get("mpi", True) else "F", + # Simulation Algorithm Parameters + "model_eqns": 2, + "num_fluids": 1, + "num_patches": 2, + "mpp_lim": "F", + "mixture_err": "F", + "time_stepper": 3, + "weno_order": 5, + "weno_eps": 1e-16, + "weno_avg": "F", + "mapped_weno": "T", + "mp_weno": "T", + "riemann_solver": 2, + "wave_speeds": 1, + "avg_state": 2, + "bc_x%beg": -2, + "bc_x%end": -3, + # Chemistry + "chemistry": "T" if not args.chemistry else "T", + "chem_params%diffusion": "F", + "chem_params%reactions": "T", + "cantera_file": ctfile, + # Formatted Database Files Structure Parameters + "format": 1, + "precision": 2, + "prim_vars_wrt": "T", + "chem_wrt_T": "T", + "patch_icpp(1)%geometry": 1, + "patch_icpp(1)%x_centroid": L/2 , + "patch_icpp(1)%length_x": L , + "patch_icpp(1)%vel(1)": 0, + "patch_icpp(1)%pres": sol_R.P, + "patch_icpp(1)%alpha(1)": 1, + "patch_icpp(1)%alpha_rho(1)": sol_R.density, + + # ========================================================================== + 'patch_icpp(2)%geometry' : 15, + 'patch_icpp(2)%hcid' : 101, + "patch_icpp(2)%x_centroid": 0.015, + "patch_icpp(2)%length_x": 0.03, + "patch_icpp(2)%vel(1)": u_l, + "patch_icpp(2)%pres": sol_L.P, + "patch_icpp(2)%alpha(1)": 1, + "patch_icpp(2)%alpha_rho(1)": sol_L.density, + "patch_icpp(2)%alter_patch(1)": "T", + # Fluids Physical Parameters + "fluid_pp(1)%gamma": 1.0e00 / (4.4e00 - 1.0e00), + "fluid_pp(1)%pi_inf": 0, +} + +if args.chemistry: + for i in range(len(sol_L.Y)): + case[f"chem_wrt_Y({i + 1})"] = "T" + case[f"patch_icpp(1)%Y({i+1})"] = sol_R.Y[i] + case[f"patch_icpp(2)%Y({i+1})"] = sol_L.Y[i] + +if __name__ == "__main__": + print(json.dumps(case)) diff --git a/examples/1D_Lefe/case.py b/examples/1D_Lefe/case.py new file mode 100644 index 0000000000..3dd978359d --- /dev/null +++ b/examples/1D_Lefe/case.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3 +# References: +# + https://doi.org/10.1016/j.ijhydene.2023.03.190: Verification of numerical method +# + https://doi.org/10.1016/j.compfluid.2013.10.014: 4.7. Multi-species reactive shock tube + +import json, argparse +import cantera as ct + +parser = argparse.ArgumentParser(prog="1D_reactive_shocktube", formatter_class=argparse.ArgumentDefaultsHelpFormatter) + +parser.add_argument( + "--mfc", + type=json.loads, + default="{}", + metavar="DICT", + help="MFC's toolchain's internal state.", +) +parser.add_argument( + "--no-chem", + dest="chemistry", + default=True, + action="store_false", + help="Disable chemistry.", +) +parser.add_argument("--scale", type=float, default=1, help="Scale.") + +args = parser.parse_args() + +ctfile = "h2o2.yaml" +sol_L = ct.Solution(ctfile) +sol_L.TPX =2300, 304000, "H2:2,O2:1,AR:7" + +sol_R = ct.Solution(ctfile) +sol_R.TPX = 298, 6670, "H2:2,O2:1,AR:7" + +u_l = 0 +u_r = 0 + +L = 0.24 +Nx = 6000 * args.scale +dx = L / Nx +dt = dx / abs(600) * 0.02*0.5 +Tend = 300e-6 + +NT = int(Tend / dt) +SAVE_COUNT = 100 +NS = NT // SAVE_COUNT + +case = { + # Logistics + "run_time_info": "T", + # Computational Domain Parameters + "x_domain%beg": 0, + "x_domain%end": L, + "m": Nx, + "n": 0, + "p": 0, + "dt": float(dt), + "t_step_start": 0, + "t_step_stop": NT, + "t_step_save": 10000, + "t_step_print": 600, + "parallel_io": "F" if args.mfc.get("mpi", True) else "F", + # Simulation Algorithm Parameters + "model_eqns": 2, + "num_fluids": 1, + "num_patches": 2, + "mpp_lim": "F", + "mixture_err": "F", + "time_stepper": 3, + "weno_order": 5, + "weno_eps": 1e-16, + "weno_avg": "F", + "mapped_weno": "T", + "mp_weno": "T", + "riemann_solver": 2, + "wave_speeds": 1, + "avg_state": 2, + "bc_x%beg": -2, + "bc_x%end": -3, + # Chemistry + "chemistry": "T" if not args.chemistry else "T", + "chem_params%diffusion": "F", + "chem_params%reactions": "T", + "cantera_file": ctfile, + # Formatted Database Files Structure Parameters + "format": 1, + "precision": 2, + "prim_vars_wrt": "T", + "chem_wrt_T": "T", + "patch_icpp(1)%geometry": 1, + "patch_icpp(1)%x_centroid": L/2 , + "patch_icpp(1)%length_x": L , + "patch_icpp(1)%vel(1)": 0, + "patch_icpp(1)%pres": sol_R.P, + "patch_icpp(1)%alpha(1)": 1, + "patch_icpp(1)%alpha_rho(1)": sol_R.density, + + # ========================================================================== + 'patch_icpp(2)%geometry' : 1, + "patch_icpp(2)%x_centroid": 0.020, + "patch_icpp(2)%length_x": 0.040, + "patch_icpp(2)%vel(1)": 0, + "patch_icpp(2)%pres": sol_L.P, + "patch_icpp(2)%alpha(1)": 1, + "patch_icpp(2)%alpha_rho(1)": sol_L.density, + "patch_icpp(2)%alter_patch(1)": "T", + # Fluids Physical Parameters + "fluid_pp(1)%gamma": 1.0e00 / (4.4e00 - 1.0e00), + "fluid_pp(1)%pi_inf": 0, +} + +if args.chemistry: + for i in range(len(sol_L.Y)): + case[f"chem_wrt_Y({i + 1})"] = "T" + case[f"patch_icpp(1)%Y({i+1})"] = sol_R.Y[i] + case[f"patch_icpp(2)%Y({i+1})"] = sol_L.Y[i] + +if __name__ == "__main__": + print(json.dumps(case)) diff --git a/src/common/m_chemistry.fpp b/src/common/m_chemistry.fpp index 1cdc837348..8eff6451c3 100644 --- a/src/common/m_chemistry.fpp +++ b/src/common/m_chemistry.fpp @@ -58,6 +58,32 @@ contains end subroutine s_compute_q_T_sf + subroutine s_compute_T_from_primitives(q_T_sf, q_cons_vf, idwint) + + type(scalar_field), intent(inout) :: q_T_sf + type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf + type(int_bounds_info), dimension(1:3), intent(in) :: bounds + + integer :: x, y, z, i + real(wp), dimension(num_species) :: Ys + real(wp) :: mix_mol_weight + + do z = bounds(3)%beg, bounds(3)%end + do y = bounds(2)%beg, bounds(2)%end + do x = bounds(1)%beg, bounds(1)%end + !$acc loop seq + do i = chemxb, chemxe + Ys(i - chemxb + 1) = q_prim_vf(i)%sf(x, y, z) + end do + + call get_mixture_molecular_weight(Ys, mix_mol_weight) + q_T_sf%sf(x, y, z) = q_prim_vf(E_idx)%sf(x, y, z)*mix_mol_weight/(gas_constant*q_prim_vf(1)%sf(x, y, z)) + end do + end do + end do + + end subroutine s_compute_T_from_primitives + subroutine s_compute_chemistry_reaction_flux(rhs_vf, q_cons_qp, q_T_sf, q_prim_qp, bounds) type(scalar_field), dimension(sys_size), intent(inout) :: rhs_vf diff --git a/src/pre_process/m_initial_condition.fpp b/src/pre_process/m_initial_condition.fpp index 67e07a2542..4d16b8850d 100644 --- a/src/pre_process/m_initial_condition.fpp +++ b/src/pre_process/m_initial_condition.fpp @@ -175,9 +175,6 @@ contains !! primitive variables are converted to conservative ones. subroutine s_generate_initial_condition - ! First, compute the temperature field from the conservative variables. - if (chemistry) call s_compute_q_T_sf(q_T_sf, q_cons_vf, idwint) - ! Converting the conservative variables to the primitive ones given ! preexisting initial condition data files were read in on start-up if (old_ic) then @@ -198,7 +195,7 @@ contains ! Converting the primitive variables to the conservative ones call s_convert_primitive_to_conservative_variables(q_prim_vf, q_cons_vf) - if (chemistry) call s_compute_q_T_sf(q_T_sf, q_cons_vf, idwint) + if (chemistry) call s_compute_T_from_primitives(q_T_sf, q_cons_vf, idwint) if (qbmm .and. .not. polytropic) then !Initialize pb and mv From cbdfaf3019b809bbc5214e5b50ecee3be8ebc4b2 Mon Sep 17 00:00:00 2001 From: Dimitrios Adam Date: Thu, 29 May 2025 16:49:17 -0400 Subject: [PATCH 2/5] Small bugs --- src/common/m_chemistry.fpp | 5 +++-- src/pre_process/m_initial_condition.fpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/m_chemistry.fpp b/src/common/m_chemistry.fpp index 8eff6451c3..6e6f759c24 100644 --- a/src/common/m_chemistry.fpp +++ b/src/common/m_chemistry.fpp @@ -9,7 +9,8 @@ module m_chemistry use m_thermochem, only: & - num_species, molecular_weights, get_temperature, get_net_production_rates + num_species, molecular_weights, get_temperature, get_net_production_rates, & + gas_constant use m_global_parameters @@ -58,7 +59,7 @@ contains end subroutine s_compute_q_T_sf - subroutine s_compute_T_from_primitives(q_T_sf, q_cons_vf, idwint) + subroutine s_compute_T_from_primitives(q_T_sf, q_prim_vf, bounds) type(scalar_field), intent(inout) :: q_T_sf type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf diff --git a/src/pre_process/m_initial_condition.fpp b/src/pre_process/m_initial_condition.fpp index 4d16b8850d..844487329d 100644 --- a/src/pre_process/m_initial_condition.fpp +++ b/src/pre_process/m_initial_condition.fpp @@ -195,7 +195,7 @@ contains ! Converting the primitive variables to the conservative ones call s_convert_primitive_to_conservative_variables(q_prim_vf, q_cons_vf) - if (chemistry) call s_compute_T_from_primitives(q_T_sf, q_cons_vf, idwint) + if (chemistry) call s_compute_T_from_primitives(q_T_sf, q_prim_vf, idwint) if (qbmm .and. .not. polytropic) then !Initialize pb and mv From 1af40a883279ead92228c7b05e317973c62ad63d Mon Sep 17 00:00:00 2001 From: Dimitrios Adam Date: Thu, 29 May 2025 17:01:45 -0400 Subject: [PATCH 3/5] ... --- src/common/m_chemistry.fpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/m_chemistry.fpp b/src/common/m_chemistry.fpp index 6e6f759c24..1e8ea388cc 100644 --- a/src/common/m_chemistry.fpp +++ b/src/common/m_chemistry.fpp @@ -10,7 +10,7 @@ module m_chemistry use m_thermochem, only: & num_species, molecular_weights, get_temperature, get_net_production_rates, & - gas_constant + gas_constant, get_mixture_molecular_weight use m_global_parameters From 7af87397817141db9c62c1d8b07c67cb85bbe547 Mon Sep 17 00:00:00 2001 From: Dimitrios Adam Date: Thu, 29 May 2025 23:02:34 -0400 Subject: [PATCH 4/5] Small Changes --- examples/1D_CJ_Wabe/case.py | 121 ------------------------------------ examples/1D_Lefe/case.py | 120 ----------------------------------- 2 files changed, 241 deletions(-) delete mode 100644 examples/1D_CJ_Wabe/case.py delete mode 100644 examples/1D_Lefe/case.py diff --git a/examples/1D_CJ_Wabe/case.py b/examples/1D_CJ_Wabe/case.py deleted file mode 100644 index 683ad34434..0000000000 --- a/examples/1D_CJ_Wabe/case.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env python3 -# References: -# + https://doi.org/10.1016/j.ijhydene.2023.03.190: Verification of numerical method -# + https://doi.org/10.1016/j.compfluid.2013.10.014: 4.7. Multi-species reactive shock tube - -import json, argparse -import cantera as ct - -parser = argparse.ArgumentParser(prog="1D_reactive_shocktube", formatter_class=argparse.ArgumentDefaultsHelpFormatter) - -parser.add_argument( - "--mfc", - type=json.loads, - default="{}", - metavar="DICT", - help="MFC's toolchain's internal state.", -) -parser.add_argument( - "--no-chem", - dest="chemistry", - default=True, - action="store_false", - help="Disable chemistry.", -) -parser.add_argument("--scale", type=float, default=1, help="Scale.") - -args = parser.parse_args() - -ctfile = "h2o2.yaml" -sol_L = ct.Solution(ctfile) -sol_L.DPX = 0.351340, 182070.11, "H2:2,O2:1,AR:7" - -sol_R = ct.Solution(ctfile) -sol_R.DPX = 0.08498, 6670, "H2:2,O2:1,AR:7" - -u_l = 1250.90 -u_r = 0 - -L = 0.18 -Nx = 3000 * args.scale -dx = L / Nx -dt = dx / abs(600) * 0.02*0.5 -Tend = 230e-6 - -NT = int(Tend / dt) -SAVE_COUNT = 100 -NS = NT // SAVE_COUNT - -case = { - # Logistics - "run_time_info": "T", - # Computational Domain Parameters - "x_domain%beg": 0, - "x_domain%end": L, - "m": Nx, - "n": 0, - "p": 0, - "dt": float(dt), - "t_step_start": 0, - "t_step_stop": 180000, - "t_step_save": 5000, - "t_step_print": 600, - "parallel_io": "F" if args.mfc.get("mpi", True) else "F", - # Simulation Algorithm Parameters - "model_eqns": 2, - "num_fluids": 1, - "num_patches": 2, - "mpp_lim": "F", - "mixture_err": "F", - "time_stepper": 3, - "weno_order": 5, - "weno_eps": 1e-16, - "weno_avg": "F", - "mapped_weno": "T", - "mp_weno": "T", - "riemann_solver": 2, - "wave_speeds": 1, - "avg_state": 2, - "bc_x%beg": -2, - "bc_x%end": -3, - # Chemistry - "chemistry": "T" if not args.chemistry else "T", - "chem_params%diffusion": "F", - "chem_params%reactions": "T", - "cantera_file": ctfile, - # Formatted Database Files Structure Parameters - "format": 1, - "precision": 2, - "prim_vars_wrt": "T", - "chem_wrt_T": "T", - "patch_icpp(1)%geometry": 1, - "patch_icpp(1)%x_centroid": L/2 , - "patch_icpp(1)%length_x": L , - "patch_icpp(1)%vel(1)": 0, - "patch_icpp(1)%pres": sol_R.P, - "patch_icpp(1)%alpha(1)": 1, - "patch_icpp(1)%alpha_rho(1)": sol_R.density, - - # ========================================================================== - 'patch_icpp(2)%geometry' : 15, - 'patch_icpp(2)%hcid' : 101, - "patch_icpp(2)%x_centroid": 0.015, - "patch_icpp(2)%length_x": 0.03, - "patch_icpp(2)%vel(1)": u_l, - "patch_icpp(2)%pres": sol_L.P, - "patch_icpp(2)%alpha(1)": 1, - "patch_icpp(2)%alpha_rho(1)": sol_L.density, - "patch_icpp(2)%alter_patch(1)": "T", - # Fluids Physical Parameters - "fluid_pp(1)%gamma": 1.0e00 / (4.4e00 - 1.0e00), - "fluid_pp(1)%pi_inf": 0, -} - -if args.chemistry: - for i in range(len(sol_L.Y)): - case[f"chem_wrt_Y({i + 1})"] = "T" - case[f"patch_icpp(1)%Y({i+1})"] = sol_R.Y[i] - case[f"patch_icpp(2)%Y({i+1})"] = sol_L.Y[i] - -if __name__ == "__main__": - print(json.dumps(case)) diff --git a/examples/1D_Lefe/case.py b/examples/1D_Lefe/case.py deleted file mode 100644 index 3dd978359d..0000000000 --- a/examples/1D_Lefe/case.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python3 -# References: -# + https://doi.org/10.1016/j.ijhydene.2023.03.190: Verification of numerical method -# + https://doi.org/10.1016/j.compfluid.2013.10.014: 4.7. Multi-species reactive shock tube - -import json, argparse -import cantera as ct - -parser = argparse.ArgumentParser(prog="1D_reactive_shocktube", formatter_class=argparse.ArgumentDefaultsHelpFormatter) - -parser.add_argument( - "--mfc", - type=json.loads, - default="{}", - metavar="DICT", - help="MFC's toolchain's internal state.", -) -parser.add_argument( - "--no-chem", - dest="chemistry", - default=True, - action="store_false", - help="Disable chemistry.", -) -parser.add_argument("--scale", type=float, default=1, help="Scale.") - -args = parser.parse_args() - -ctfile = "h2o2.yaml" -sol_L = ct.Solution(ctfile) -sol_L.TPX =2300, 304000, "H2:2,O2:1,AR:7" - -sol_R = ct.Solution(ctfile) -sol_R.TPX = 298, 6670, "H2:2,O2:1,AR:7" - -u_l = 0 -u_r = 0 - -L = 0.24 -Nx = 6000 * args.scale -dx = L / Nx -dt = dx / abs(600) * 0.02*0.5 -Tend = 300e-6 - -NT = int(Tend / dt) -SAVE_COUNT = 100 -NS = NT // SAVE_COUNT - -case = { - # Logistics - "run_time_info": "T", - # Computational Domain Parameters - "x_domain%beg": 0, - "x_domain%end": L, - "m": Nx, - "n": 0, - "p": 0, - "dt": float(dt), - "t_step_start": 0, - "t_step_stop": NT, - "t_step_save": 10000, - "t_step_print": 600, - "parallel_io": "F" if args.mfc.get("mpi", True) else "F", - # Simulation Algorithm Parameters - "model_eqns": 2, - "num_fluids": 1, - "num_patches": 2, - "mpp_lim": "F", - "mixture_err": "F", - "time_stepper": 3, - "weno_order": 5, - "weno_eps": 1e-16, - "weno_avg": "F", - "mapped_weno": "T", - "mp_weno": "T", - "riemann_solver": 2, - "wave_speeds": 1, - "avg_state": 2, - "bc_x%beg": -2, - "bc_x%end": -3, - # Chemistry - "chemistry": "T" if not args.chemistry else "T", - "chem_params%diffusion": "F", - "chem_params%reactions": "T", - "cantera_file": ctfile, - # Formatted Database Files Structure Parameters - "format": 1, - "precision": 2, - "prim_vars_wrt": "T", - "chem_wrt_T": "T", - "patch_icpp(1)%geometry": 1, - "patch_icpp(1)%x_centroid": L/2 , - "patch_icpp(1)%length_x": L , - "patch_icpp(1)%vel(1)": 0, - "patch_icpp(1)%pres": sol_R.P, - "patch_icpp(1)%alpha(1)": 1, - "patch_icpp(1)%alpha_rho(1)": sol_R.density, - - # ========================================================================== - 'patch_icpp(2)%geometry' : 1, - "patch_icpp(2)%x_centroid": 0.020, - "patch_icpp(2)%length_x": 0.040, - "patch_icpp(2)%vel(1)": 0, - "patch_icpp(2)%pres": sol_L.P, - "patch_icpp(2)%alpha(1)": 1, - "patch_icpp(2)%alpha_rho(1)": sol_L.density, - "patch_icpp(2)%alter_patch(1)": "T", - # Fluids Physical Parameters - "fluid_pp(1)%gamma": 1.0e00 / (4.4e00 - 1.0e00), - "fluid_pp(1)%pi_inf": 0, -} - -if args.chemistry: - for i in range(len(sol_L.Y)): - case[f"chem_wrt_Y({i + 1})"] = "T" - case[f"patch_icpp(1)%Y({i+1})"] = sol_R.Y[i] - case[f"patch_icpp(2)%Y({i+1})"] = sol_L.Y[i] - -if __name__ == "__main__": - print(json.dumps(case)) From e43093f5bddb007c6b464e58328b0bd69d1e3494 Mon Sep 17 00:00:00 2001 From: Dimitrios Adam Date: Thu, 29 May 2025 23:29:18 -0400 Subject: [PATCH 5/5] Formatting --- src/common/m_chemistry.fpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/m_chemistry.fpp b/src/common/m_chemistry.fpp index 1e8ea388cc..d61c42b1af 100644 --- a/src/common/m_chemistry.fpp +++ b/src/common/m_chemistry.fpp @@ -64,7 +64,7 @@ contains type(scalar_field), intent(inout) :: q_T_sf type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf type(int_bounds_info), dimension(1:3), intent(in) :: bounds - + integer :: x, y, z, i real(wp), dimension(num_species) :: Ys real(wp) :: mix_mol_weight