From 7958e6f353747d425c9a95782d7fdca9d91e15ee Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Tue, 22 Sep 2026 22:46:16 -0500 Subject: [PATCH] Size species arrays from the generated mechanism on AMD Generic (non-case-optimized) amdflang builds declared every species array with a fixed AMD_NUM_SPECIES_MAX = 60 bound, and sys_size arrays with AMD_SYS_SIZE_MAX = 70, because the species count was not known when the guards were written. The toolchain now writes build/include//thermochem.fpp with m_thermochem's species count (NUM_SPECIES) and whether chemistry is on (CHEMISTRY). Species arrays are declared dimension(${NUM_SPECIES}$) on every backend, so the USING_AMD species branches collapse to one declaration and carry the mechanism's exact count. Chemistry pins num_fluids to 1, so the sys_size fallback becomes 10 + NUM_SPECIES there; other builds keep 70. The species-count check goes away with the bound. Fypp searches the including file's directory before -I paths, so the default thermochem.fpp for toolchain-less Fypp runs lives in src/common/include/defaults/, searched last. Done with Claude Code. --- cmake/Fypp.cmake | 1 + src/common/include/defaults/thermochem.fpp | 4 ++ src/common/include/shared_parallel_macros.fpp | 12 ++-- src/common/m_checker_common.fpp | 9 +-- src/common/m_chemistry.fpp | 58 +++++----------- src/common/m_variables_conversion.fpp | 42 ++++++----- src/simulation/m_cbc.fpp | 55 ++++++++------- src/simulation/m_compute_cbc.fpp | 69 +++++++++---------- src/simulation/m_ibm.fpp | 23 +++---- src/simulation/m_riemann_solver_hll.fpp | 18 +++-- src/simulation/m_riemann_solver_hllc.fpp | 61 ++++++++-------- src/simulation/m_riemann_solver_lf.fpp | 18 +++-- src/simulation/m_riemann_state.fpp | 19 ++--- toolchain/mfc/run/input.py | 11 ++- 14 files changed, 177 insertions(+), 223 deletions(-) create mode 100644 src/common/include/defaults/thermochem.fpp diff --git a/cmake/Fypp.cmake b/cmake/Fypp.cmake index 9519268b87..03cc237af7 100644 --- a/cmake/Fypp.cmake +++ b/cmake/Fypp.cmake @@ -114,6 +114,7 @@ macro(HANDLE_SOURCES target useCommon) -I "${${target}_DIR}/include" -I "${common_DIR}/include" -I "${common_DIR}" + -I "${common_DIR}/include/defaults" -D MFC_${CMAKE_Fortran_COMPILER_ID} -D MFC_${${target}_UPPER} -D MFC_COMPILER="${CMAKE_Fortran_COMPILER_ID}" diff --git a/src/common/include/defaults/thermochem.fpp b/src/common/include/defaults/thermochem.fpp new file mode 100644 index 0000000000..81ae970118 --- /dev/null +++ b/src/common/include/defaults/thermochem.fpp @@ -0,0 +1,4 @@ +! Default for Fypp runs outside the toolchain (e.g. documentation). Searched last, so the +! build/include//thermochem.fpp the toolchain writes from m_thermochem takes precedence. +#:set NUM_SPECIES = 1 +#:set CHEMISTRY = False diff --git a/src/common/include/shared_parallel_macros.fpp b/src/common/include/shared_parallel_macros.fpp index 0882db1718..8c05cd1dec 100644 --- a/src/common/include/shared_parallel_macros.fpp +++ b/src/common/include/shared_parallel_macros.fpp @@ -8,12 +8,12 @@ #:set USING_CCE = (MFC_COMPILER == CCE_COMPILER_ID) #:set USING_AMD = (MFC_COMPILER == AMD_COMPILER_ID) -#! Fallback extents the USING_AMD guards substitute for device-global array bounds when case -#! optimization is off. They are not independent: sys_size counts the species, so AMD_SYS_SIZE_MAX -#! must cover 3*num_fluids + num_vels + 1 + AMD_NUM_SPECIES_MAX. Keep them here rather than as -#! literals at each declaration, so raising one cannot silently outgrow the other. -#:set AMD_NUM_SPECIES_MAX = 60 -#:set AMD_SYS_SIZE_MAX = 70 +#! NUM_SPECIES (m_thermochem's species count) and CHEMISTRY, written per build by the toolchain. +#:include 'thermochem.fpp' + +#! Fallback extent the USING_AMD guards substitute for sys_size arrays when case optimization is off. +#! Chemistry pins num_fluids to 1, leaving at most 10 flow variables beside the species. +#:set AMD_SYS_SIZE_MAX = 10 + NUM_SPECIES if CHEMISTRY else 70 #:def ASSERT_LIST(data, datatype) #:assert data is not None diff --git a/src/common/m_checker_common.fpp b/src/common/m_checker_common.fpp index f1c96e915d..83e1adf4aa 100644 --- a/src/common/m_checker_common.fpp +++ b/src/common/m_checker_common.fpp @@ -54,14 +54,7 @@ contains #:if not MFC_CASE_OPTIMIZATION @:PROHIBIT(num_fluids > 3, "num_fluids <= 3 for AMDFLang when Case optimization is off") @:PROHIBIT((bubbles_euler .or. bubbles_lagrange) .and. nb > 3, "nb <= 3 for AMDFLang when Case optimization is off") - @:PROHIBIT(chemistry .and. num_species > ${AMD_NUM_SPECIES_MAX}$, & - & "num_species <= ${AMD_NUM_SPECIES_MAX}$ for AMDFLang when Case optimization is off") - ! The sys_size bound is not independent of the one above it. Chemistry pins num_fluids to 1, so with - ! num_vels <= 3 the species terminate sys_size at 2*1 + 3 + 1 + 60 = 66 for five equations and - ! 3*1 + 3 + 1 + 60 = 67 for six; 70 covers both with room, and hypoelastic stresses would add up to six - ! more. It had no check of its own while the species cap was ten, because sys_size could not then reach - ! the dimension(20) the guard gives every sys_size array; HLLC's star states have no other bound, so - ! raising one cap without the other overruns them with nothing to say so. + ! HLLC's star states and the CBC L vectors have no other bound. @:PROHIBIT(sys_size > ${AMD_SYS_SIZE_MAX}$, & & "sys_size <= ${AMD_SYS_SIZE_MAX}$ for AMDFLang when Case optimization is off") #:endif diff --git a/src/common/m_chemistry.fpp b/src/common/m_chemistry.fpp index 687b2a1180..0be1ea4d99 100644 --- a/src/common/m_chemistry.fpp +++ b/src/common/m_chemistry.fpp @@ -114,14 +114,8 @@ contains integer :: eqn real(wp) :: T real(wp) :: rho, omega_m - - #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Ys - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: omega - #:else - real(wp), dimension(num_species) :: Ys - real(wp), dimension(num_species) :: omega - #:endif + real(wp), dimension(${NUM_SPECIES}$) :: Ys + real(wp), dimension(${NUM_SPECIES}$) :: omega $:GPU_PARALLEL_LOOP(collapse=3, private='[Ys, omega, eqn, T, rho, omega_m]', copyin='[bounds]') do z = bounds(3)%beg, bounds(3)%end @@ -172,13 +166,8 @@ contains ! stiff_target: fractional net composition change per sub-step targeted when sizing the adaptive ! nsub. An uncalibrated engineering default -- alpha-QSS is unconditionally stable, so it trades ! accuracy for cost (never stability), and the cost is bounded by reaction_substeps_max. - real(wp), parameter :: stiff_target = 0.5_wp - - #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Ys, cdot, ddot, y0, prod0, Lloss, alp - #:else - real(wp), dimension(num_species) :: Ys, cdot, ddot, y0, prod0, Lloss, alp - #:endif + real(wp), parameter :: stiff_target = 0.5_wp + real(wp), dimension(${NUM_SPECIES}$) :: Ys, cdot, ddot, y0, prod0, Lloss, alp if (chem_params%adap_substeps) then ! Pass 1: per-rank local stiffness probe -> adapt nsub for this step, no MPI. Each rank @@ -320,31 +309,22 @@ contains !> Compute species mass diffusion fluxes at cell interfaces using mixture-averaged diffusivities. subroutine s_compute_chemistry_diffusion_flux(idir, q_prim_qp, flux_src_vf, irx, iry, irz, q_T_sf) - type(scalar_field), dimension(sys_size), intent(in) :: q_prim_qp + 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 - type(scalar_field), intent(in) :: q_T_sf - - #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Xs_L, Xs_R, Xs_cell, Ys_L, Ys_R, Ys_cell - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: mass_diffusivities_mixavg1, mass_diffusivities_mixavg2 - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: mass_diffusivities_mixavg_Cell, dXk_dxi, h_l, h_r, h_k - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Mass_Diffu_Flux, dYk_dxi - #:else - 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, dYk_dxi - #:endif - - real(wp) :: Mass_Diffu_Energy - real(wp) :: MW_L, MW_R, MW_cell, 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 - real(wp) :: Cp_L, Cp_R - real(wp) :: diffusivity_L, diffusivity_R, diffusivity_cell - real(wp) :: hmix_L, hmix_R, dh_dxi - integer :: x, y, z, i, n, eqn + type(int_bounds_info), intent(in) :: irx, iry, irz + integer, intent(in) :: idir + type(scalar_field), intent(in) :: q_T_sf + 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, dYk_dxi + real(wp) :: Mass_Diffu_Energy + real(wp) :: MW_L, MW_R, MW_cell, 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 + real(wp) :: Cp_L, Cp_R + real(wp) :: diffusivity_L, diffusivity_R, diffusivity_cell + real(wp) :: hmix_L, hmix_R, dh_dxi + integer :: x, y, z, i, n, eqn integer, dimension(3) :: offsets isc1 = irx; isc2 = iry; isc3 = irz diff --git a/src/common/m_variables_conversion.fpp b/src/common/m_variables_conversion.fpp index 3ace076444..87c3d2654c 100644 --- a/src/common/m_variables_conversion.fpp +++ b/src/common/m_variables_conversion.fpp @@ -393,12 +393,11 @@ contains #:if USING_AMD and not MFC_CASE_OPTIMIZATION real(wp), dimension(3) :: alpha_K, alpha_rho_K real(wp), dimension(3) :: nRtmp - real(wp) :: rhoYks(1:${AMD_NUM_SPECIES_MAX}$) #:else real(wp), dimension(num_fluids) :: alpha_K, alpha_rho_K real(wp), dimension(nb) :: nRtmp - real(wp) :: rhoYks(1:num_species) #:endif + real(wp) :: rhoYks(1:${NUM_SPECIES}$) real(wp), dimension(2) :: Re_K real(wp) :: rho_K, gamma_K, pi_inf_K, qv_K, dyn_pres_K real(wp) :: vftmp, nbub_sc @@ -948,28 +947,27 @@ contains ! functions, the shear and volume Reynolds numbers and the Weber numbers #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(3) :: alpha_rho_K - real(wp), dimension(3) :: alpha_K - real(wp), dimension(3) :: vel_K - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Y_K + real(wp), dimension(3) :: alpha_rho_K + real(wp), dimension(3) :: alpha_K + real(wp), dimension(3) :: vel_K #:else - real(wp), dimension(num_fluids) :: alpha_rho_K - real(wp), dimension(num_fluids) :: alpha_K - real(wp), dimension(num_vels) :: vel_K - real(wp), dimension(num_species) :: Y_K + real(wp), dimension(num_fluids) :: alpha_rho_K + real(wp), dimension(num_fluids) :: alpha_K + real(wp), dimension(num_vels) :: vel_K #:endif - real(wp) :: rho_K - real(wp) :: vel_K_sum - real(wp) :: pres_K - real(wp) :: E_K - real(wp) :: gamma_K - real(wp) :: pi_inf_K - real(wp) :: qv_K - real(wp), dimension(2) :: Re_K - real(wp) :: G_K - real(wp) :: blkmod1_K, blkmod2_K, K_K - real(wp) :: T_K, mix_mol_weight, R_gas - integer :: i, j, k, l !< Generic loop iterators + real(wp), dimension(${NUM_SPECIES}$) :: Y_K + real(wp) :: rho_K + real(wp) :: vel_K_sum + real(wp) :: pres_K + real(wp) :: E_K + real(wp) :: gamma_K + real(wp) :: pi_inf_K + real(wp) :: qv_K + real(wp), dimension(2) :: Re_K + real(wp) :: G_K + real(wp) :: blkmod1_K, blkmod2_K, K_K + real(wp) :: T_K, mix_mol_weight, R_gas + integer :: i, j, k, l !< Generic loop iterators is1b = is1%beg; is1e = is1%end is2b = is2%beg; is2e = is2%end diff --git a/src/simulation/m_cbc.fpp b/src/simulation/m_cbc.fpp index 7bddbdc317..1e3ece1686 100644 --- a/src/simulation/m_cbc.fpp +++ b/src/simulation/m_cbc.fpp @@ -483,36 +483,35 @@ contains real(wp), dimension(sys_size) :: L #:endif #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(3) :: alpha_rho, dalpha_rho_ds, mf - real(wp), dimension(3) :: vel, dvel_ds - real(wp), dimension(3) :: adv_local, dadv_ds - real(wp), dimension(3) :: dadv_dt - real(wp), dimension(3) :: dvel_dt - real(wp), dimension(3) :: dalpha_rho_dt - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Ys, h_k, dYs_dt, dYs_ds, Xs, Gamma_i, Cp_i + real(wp), dimension(3) :: alpha_rho, dalpha_rho_ds, mf + real(wp), dimension(3) :: vel, dvel_ds + real(wp), dimension(3) :: adv_local, dadv_ds + real(wp), dimension(3) :: dadv_dt + real(wp), dimension(3) :: dvel_dt + real(wp), dimension(3) :: dalpha_rho_dt #:else - real(wp), dimension(num_fluids) :: alpha_rho, dalpha_rho_ds, mf - real(wp), dimension(num_vels) :: vel, dvel_ds - real(wp), dimension(num_fluids) :: adv_local, dadv_ds - real(wp), dimension(num_fluids) :: dadv_dt - real(wp), dimension(num_dims) :: dvel_dt - real(wp), dimension(num_fluids) :: dalpha_rho_dt - real(wp), dimension(num_species) :: Ys, h_k, dYs_dt, dYs_ds, Xs, Gamma_i, Cp_i + real(wp), dimension(num_fluids) :: alpha_rho, dalpha_rho_ds, mf + real(wp), dimension(num_vels) :: vel, dvel_ds + real(wp), dimension(num_fluids) :: adv_local, dadv_ds + real(wp), dimension(num_fluids) :: dadv_dt + real(wp), dimension(num_dims) :: dvel_dt + real(wp), dimension(num_fluids) :: dalpha_rho_dt #:endif - real(wp), dimension(2) :: Re_cbc - real(wp), dimension(3) :: lambda - real(wp) :: rho !< Cell averaged density - real(wp) :: pres !< Cell averaged pressure - real(wp) :: E !< Cell averaged energy - real(wp) :: gamma !< Cell averaged specific heat ratio - real(wp) :: pi_inf !< Cell averaged liquid stiffness - real(wp) :: qv !< Cell averaged fluid reference energy - real(wp) :: c - real(wp) :: Ma - real(wp) :: T, sum_Enthalpies - real(wp) :: Cv, Cp, e_mix, Mw, R_gas - real(wp) :: vel_K_sum, vel_dv_dt_sum - integer :: i, j, k, r !< Generic loop iterators + real(wp), dimension(${NUM_SPECIES}$) :: Ys, h_k, dYs_dt, dYs_ds, Xs, Gamma_i, Cp_i + real(wp), dimension(2) :: Re_cbc + real(wp), dimension(3) :: lambda + real(wp) :: rho !< Cell averaged density + real(wp) :: pres !< Cell averaged pressure + real(wp) :: E !< Cell averaged energy + real(wp) :: gamma !< Cell averaged specific heat ratio + real(wp) :: pi_inf !< Cell averaged liquid stiffness + real(wp) :: qv !< Cell averaged fluid reference energy + real(wp) :: c + real(wp) :: Ma + real(wp) :: T, sum_Enthalpies + real(wp) :: Cv, Cp, e_mix, Mw, R_gas + real(wp) :: vel_K_sum, vel_dv_dt_sum + integer :: i, j, k, r !< Generic loop iterators ! Reshaping of inputted data and association of the FD and PI coefficients, or CBC coefficients, respectively, hinging on ! selected CBC coordinate direction diff --git a/src/simulation/m_compute_cbc.fpp b/src/simulation/m_compute_cbc.fpp index 792224e8a8..0a24c524ed 100644 --- a/src/simulation/m_compute_cbc.fpp +++ b/src/simulation/m_compute_cbc.fpp @@ -112,13 +112,9 @@ contains #:else real(wp), dimension(sys_size), intent(inout) :: L #:endif - #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$), intent(in) :: dYs_ds - #:else - real(wp), dimension(num_species), intent(in) :: dYs_ds - #:endif - real(wp), intent(in) :: lambda_factor, lambda2 - integer :: i + real(wp), dimension(${NUM_SPECIES}$), intent(in) :: dYs_ds + real(wp), intent(in) :: lambda_factor, lambda2 + integer :: i if (.not. chemistry) return @@ -164,19 +160,18 @@ contains real(wp), dimension(sys_size), intent(inout) :: L #:endif #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(3), intent(in) :: mf, dalpha_rho_ds - real(wp), dimension(3), intent(in) :: dvel_ds - real(wp), dimension(3), intent(in) :: dadv_ds - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$), intent(in) :: dYs_ds + real(wp), dimension(3), intent(in) :: mf, dalpha_rho_ds + real(wp), dimension(3), intent(in) :: dvel_ds + real(wp), dimension(3), intent(in) :: dadv_ds #:else - real(wp), dimension(num_fluids), intent(in) :: mf, dalpha_rho_ds - real(wp), dimension(num_dims), intent(in) :: dvel_ds - real(wp), dimension(num_fluids), intent(in) :: dadv_ds - real(wp), dimension(num_species), intent(in) :: dYs_ds + real(wp), dimension(num_fluids), intent(in) :: mf, dalpha_rho_ds + real(wp), dimension(num_dims), intent(in) :: dvel_ds + real(wp), dimension(num_fluids), intent(in) :: dadv_ds #:endif - real(wp), intent(in) :: rho, c - real(wp), intent(in) :: dpres_ds - real(wp) :: lambda_factor + real(wp), dimension(${NUM_SPECIES}$), intent(in) :: dYs_ds + real(wp), intent(in) :: rho, c + real(wp), intent(in) :: dpres_ds + real(wp) :: lambda_factor lambda_factor = (5.e-1_wp - 5.e-1_wp*sign(1._wp, lambda(1))) L(1) = lambda_factor*lambda(1)*(dpres_ds - rho*c*dvel_ds(dir_idx(1))) @@ -228,18 +223,17 @@ contains real(wp), dimension(sys_size), intent(inout) :: L #:endif #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(3), intent(in) :: mf, dalpha_rho_ds - real(wp), dimension(3), intent(in) :: dvel_ds - real(wp), dimension(3), intent(in) :: dadv_ds - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$), intent(in) :: dYs_ds + real(wp), dimension(3), intent(in) :: mf, dalpha_rho_ds + real(wp), dimension(3), intent(in) :: dvel_ds + real(wp), dimension(3), intent(in) :: dadv_ds #:else - real(wp), dimension(num_fluids), intent(in) :: mf, dalpha_rho_ds - real(wp), dimension(num_dims), intent(in) :: dvel_ds - real(wp), dimension(num_fluids), intent(in) :: dadv_ds - real(wp), dimension(num_species), intent(in) :: dYs_ds + real(wp), dimension(num_fluids), intent(in) :: mf, dalpha_rho_ds + real(wp), dimension(num_dims), intent(in) :: dvel_ds + real(wp), dimension(num_fluids), intent(in) :: dadv_ds #:endif - real(wp), intent(in) :: rho, c - real(wp), intent(in) :: dpres_ds + real(wp), dimension(${NUM_SPECIES}$), intent(in) :: dYs_ds + real(wp), intent(in) :: rho, c + real(wp), intent(in) :: dpres_ds L(1) = f_base_L1(lambda, rho, c, dpres_ds, dvel_ds) call s_fill_density_L(L, 1._wp, lambda(2), c, mf, dalpha_rho_ds, dpres_ds) @@ -338,18 +332,17 @@ contains real(wp), dimension(sys_size), intent(inout) :: L #:endif #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(3), intent(in) :: mf, dalpha_rho_ds - real(wp), dimension(3), intent(in) :: dvel_ds - real(wp), dimension(3), intent(in) :: dadv_ds - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$), intent(in) :: dYs_ds + real(wp), dimension(3), intent(in) :: mf, dalpha_rho_ds + real(wp), dimension(3), intent(in) :: dvel_ds + real(wp), dimension(3), intent(in) :: dadv_ds #:else - real(wp), dimension(num_fluids), intent(in) :: mf, dalpha_rho_ds - real(wp), dimension(num_dims), intent(in) :: dvel_ds - real(wp), dimension(num_fluids), intent(in) :: dadv_ds - real(wp), dimension(num_species), intent(in) :: dYs_ds + real(wp), dimension(num_fluids), intent(in) :: mf, dalpha_rho_ds + real(wp), dimension(num_dims), intent(in) :: dvel_ds + real(wp), dimension(num_fluids), intent(in) :: dadv_ds #:endif - real(wp), intent(in) :: rho, c - real(wp), intent(in) :: dpres_ds + real(wp), dimension(${NUM_SPECIES}$), intent(in) :: dYs_ds + real(wp), intent(in) :: rho, c + real(wp), intent(in) :: dpres_ds L(1) = f_base_L1(lambda, rho, c, dpres_ds, dvel_ds) call s_fill_density_L(L, 1._wp, lambda(2), c, mf, dalpha_rho_ds, dpres_ds) diff --git a/src/simulation/m_ibm.fpp b/src/simulation/m_ibm.fpp index 543a0fa6a6..cd051ed774 100644 --- a/src/simulation/m_ibm.fpp +++ b/src/simulation/m_ibm.fpp @@ -248,20 +248,19 @@ contains real(wp) :: c_IP #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(3) :: Gs - real(wp), dimension(3) :: alpha_rho_IP, alpha_IP - real(wp), dimension(3) :: r_IP, v_IP, pb_IP, mv_IP - real(wp), dimension(18) :: nmom_IP - real(wp), dimension(12) :: presb_IP, massv_IP - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Ys_IP + real(wp), dimension(3) :: Gs + real(wp), dimension(3) :: alpha_rho_IP, alpha_IP + real(wp), dimension(3) :: r_IP, v_IP, pb_IP, mv_IP + real(wp), dimension(18) :: nmom_IP + real(wp), dimension(12) :: presb_IP, massv_IP #:else - real(wp), dimension(num_fluids) :: Gs - real(wp), dimension(num_fluids) :: alpha_rho_IP, alpha_IP - real(wp), dimension(nb) :: r_IP, v_IP, pb_IP, mv_IP - real(wp), dimension(nb*nmom) :: nmom_IP - real(wp), dimension(nb*nnode) :: presb_IP, massv_IP - real(wp), dimension(num_species) :: Ys_IP + real(wp), dimension(num_fluids) :: Gs + real(wp), dimension(num_fluids) :: alpha_rho_IP, alpha_IP + real(wp), dimension(nb) :: r_IP, v_IP, pb_IP, mv_IP + real(wp), dimension(nb*nmom) :: nmom_IP + real(wp), dimension(nb*nnode) :: presb_IP, massv_IP #:endif + real(wp), dimension(${NUM_SPECIES}$) :: Ys_IP real(wp) :: alpha_q, alpha_rho_q, e_q real(wp) :: T_IP, mw_IP, e_IP !< Image-point temperature, mixture MW, and mass-specific internal energy (chemistry) ! Primitive variables at the image point associated with a ghost point, interpolated from surrounding fluid cells. diff --git a/src/simulation/m_riemann_solver_hll.fpp b/src/simulation/m_riemann_solver_hll.fpp index 969d6996ae..67e12af706 100644 --- a/src/simulation/m_riemann_solver_hll.fpp +++ b/src/simulation/m_riemann_solver_hll.fpp @@ -42,18 +42,16 @@ contains type(int_bounds_info), intent(in) :: ix, iy, iz #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(3) :: alpha_rho_L, alpha_rho_R - real(wp), dimension(3) :: vel_L, vel_R - real(wp), dimension(3) :: alpha_L, alpha_R - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Ys_L, Ys_R, R_species, h_iL, h_iR - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Cp_iL, Cp_iR, Xs_L, Xs_R, Gamma_iL, Gamma_iR + real(wp), dimension(3) :: alpha_rho_L, alpha_rho_R + real(wp), dimension(3) :: vel_L, vel_R + real(wp), dimension(3) :: alpha_L, alpha_R #:else - real(wp), dimension(num_fluids) :: alpha_rho_L, alpha_rho_R - real(wp), dimension(num_vels) :: vel_L, vel_R - real(wp), dimension(num_fluids) :: alpha_L, alpha_R - real(wp), dimension(num_species) :: Ys_L, Ys_R, R_species, h_iL, h_iR - real(wp), dimension(num_species) :: Cp_iL, Cp_iR, Xs_L, Xs_R, Gamma_iL, Gamma_iR + real(wp), dimension(num_fluids) :: alpha_rho_L, alpha_rho_R + real(wp), dimension(num_vels) :: vel_L, vel_R + real(wp), dimension(num_fluids) :: alpha_L, alpha_R #:endif + real(wp), dimension(${NUM_SPECIES}$) :: Ys_L, Ys_R, R_species, h_iL, h_iR + real(wp), dimension(${NUM_SPECIES}$) :: Cp_iL, Cp_iR, Xs_L, Xs_R, Gamma_iL, Gamma_iR real(wp) :: rho_L, rho_R real(wp) :: pres_L, pres_R real(wp) :: E_L, E_R diff --git a/src/simulation/m_riemann_solver_hllc.fpp b/src/simulation/m_riemann_solver_hllc.fpp index d96c8da7e1..c682c103a1 100644 --- a/src/simulation/m_riemann_solver_hllc.fpp +++ b/src/simulation/m_riemann_solver_hllc.fpp @@ -56,39 +56,34 @@ contains real(wp), dimension(num_dims) :: vel_L, vel_R #:endif - real(wp) :: rho_L, rho_R - real(wp) :: pres_L, pres_R - real(wp) :: E_L, E_R - real(wp) :: H_L, H_R - #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Ys_L, Ys_R, Xs_L, Xs_R, Gamma_iL, Gamma_iR, Cp_iL, Cp_iR, R_species, & - & h_iL, h_iR - #:else - real(wp), dimension(num_species) :: Ys_L, Ys_R, Xs_L, Xs_R, Gamma_iL, Gamma_iR, Cp_iL, Cp_iR, R_species, h_iL, h_iR - #:endif - real(wp) :: c_sum_Yi_Phi - real(wp) :: T_L, T_R - real(wp) :: MW_L, MW_R - real(wp) :: R_gas_L, R_gas_R - real(wp) :: Cp_L, Cp_R - real(wp) :: Cv_L, Cv_R - real(wp) :: Gamm_L, Gamm_R - real(wp) :: Y_L, Y_R - real(wp) :: gamma_L, gamma_R - real(wp) :: pi_inf_L, pi_inf_R - real(wp) :: qv_L, qv_R - real(wp) :: c_L, c_R - real(wp), dimension(2) :: Re_L, Re_R - real(wp) :: rho_avg - real(wp) :: H_avg - real(wp) :: gamma_avg - real(wp) :: qv_avg - real(wp) :: c_avg - real(wp) :: s_L, s_R, s_M, s_P, s_S - real(wp) :: xi_L, xi_R !< Left and right wave speeds functions - real(wp) :: xi_L_m1, xi_R_m1 !< xi_L/R - 1, computed without cancellation - real(wp) :: xi_M, xi_P - real(wp) :: xi_MP, xi_PP + real(wp) :: rho_L, rho_R + real(wp) :: pres_L, pres_R + real(wp) :: E_L, E_R + real(wp) :: H_L, H_R + real(wp), dimension(${NUM_SPECIES}$) :: Ys_L, Ys_R, Xs_L, Xs_R, Gamma_iL, Gamma_iR, Cp_iL, Cp_iR, R_species, h_iL, h_iR + real(wp) :: c_sum_Yi_Phi + real(wp) :: T_L, T_R + real(wp) :: MW_L, MW_R + real(wp) :: R_gas_L, R_gas_R + real(wp) :: Cp_L, Cp_R + real(wp) :: Cv_L, Cv_R + real(wp) :: Gamm_L, Gamm_R + real(wp) :: Y_L, Y_R + real(wp) :: gamma_L, gamma_R + real(wp) :: pi_inf_L, pi_inf_R + real(wp) :: qv_L, qv_R + real(wp) :: c_L, c_R + real(wp), dimension(2) :: Re_L, Re_R + real(wp) :: rho_avg + real(wp) :: H_avg + real(wp) :: gamma_avg + real(wp) :: qv_avg + real(wp) :: c_avg + real(wp) :: s_L, s_R, s_M, s_P, s_S + real(wp) :: xi_L, xi_R !< Left and right wave speeds functions + real(wp) :: xi_L_m1, xi_R_m1 !< xi_L/R - 1, computed without cancellation + real(wp) :: xi_M, xi_P + real(wp) :: xi_MP, xi_PP #:if not MFC_CASE_OPTIMIZATION and USING_AMD real(wp), dimension(3) :: R0_L, R0_R real(wp), dimension(3) :: V0_L, V0_R diff --git a/src/simulation/m_riemann_solver_lf.fpp b/src/simulation/m_riemann_solver_lf.fpp index 82dd930592..edc38c1317 100644 --- a/src/simulation/m_riemann_solver_lf.fpp +++ b/src/simulation/m_riemann_solver_lf.fpp @@ -37,21 +37,19 @@ contains type(int_bounds_info), intent(in) :: ix, iy, iz #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(3) :: alpha_rho_L, alpha_rho_R - real(wp), dimension(3) :: vel_L, vel_R - real(wp), dimension(3) :: alpha_L, alpha_R - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Ys_L, Ys_R - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Cp_iL, Cp_iR, Xs_L, Xs_R, Gamma_iL, Gamma_iR + real(wp), dimension(3) :: alpha_rho_L, alpha_rho_R + real(wp), dimension(3) :: vel_L, vel_R + real(wp), dimension(3) :: alpha_L, alpha_R real(wp), dimension(3, 3) :: vel_grad_L, vel_grad_R !< Averaged velocity gradient tensor `d(vel_i)/d(coord_j)`. #:else - real(wp), dimension(num_fluids) :: alpha_rho_L, alpha_rho_R - real(wp), dimension(num_vels) :: vel_L, vel_R - real(wp), dimension(num_fluids) :: alpha_L, alpha_R - real(wp), dimension(num_species) :: Ys_L, Ys_R - real(wp), dimension(num_species) :: Cp_iL, Cp_iR, Xs_L, Xs_R, Gamma_iL, Gamma_iR + real(wp), dimension(num_fluids) :: alpha_rho_L, alpha_rho_R + real(wp), dimension(num_vels) :: vel_L, vel_R + real(wp), dimension(num_fluids) :: alpha_L, alpha_R !> Averaged velocity gradient tensor `d(vel_i)/d(coord_j)`. real(wp), dimension(num_dims, num_dims) :: vel_grad_L, vel_grad_R #:endif + real(wp), dimension(${NUM_SPECIES}$) :: Ys_L, Ys_R + real(wp), dimension(${NUM_SPECIES}$) :: Cp_iL, Cp_iR, Xs_L, Xs_R, Gamma_iL, Gamma_iR real(wp) :: rho_L, rho_R real(wp) :: pres_L, pres_R real(wp) :: E_L, E_R diff --git a/src/simulation/m_riemann_state.fpp b/src/simulation/m_riemann_state.fpp index 6677cd012c..aeb34c8a9f 100644 --- a/src/simulation/m_riemann_state.fpp +++ b/src/simulation/m_riemann_state.fpp @@ -227,20 +227,11 @@ contains !! molecular_weights array into a declare-target routine. !> Species enthalpies and heat capacities, evaluated by the caller. m_thermochem is called from the loop body rather than !! from here: CCE faults the GPU on that call one routine deeper. - #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$), intent(in) :: Ys_L, Ys_R, R_species, h_iL, h_iR, Cp_iL, Cp_iR - #:else - real(wp), dimension(num_species), intent(in) :: Ys_L, Ys_R, R_species, h_iL, h_iR, Cp_iL, Cp_iR - #:endif - real(wp), intent(out) :: gamma_avg !< Mixture Cp/Cv, replacing the density-weighted average - real(wp), intent(out) :: c_sum_Yi_Phi - - #:if not MFC_CASE_OPTIMIZATION and USING_AMD - real(wp), dimension(${AMD_NUM_SPECIES_MAX}$) :: Yi_avg, Phi_avg, h_avg_2 - #:else - real(wp), dimension(num_species) :: Yi_avg, Phi_avg, h_avg_2 - #:endif - real(wp) :: Cp_avg, Cv_avg, T_avg, eps + real(wp), dimension(${NUM_SPECIES}$), intent(in) :: Ys_L, Ys_R, R_species, h_iL, h_iR, Cp_iL, Cp_iR + real(wp), intent(out) :: gamma_avg !< Mixture Cp/Cv, replacing the density-weighted average + real(wp), intent(out) :: c_sum_Yi_Phi + real(wp), dimension(${NUM_SPECIES}$) :: Yi_avg, Phi_avg, h_avg_2 + real(wp) :: Cp_avg, Cv_avg, T_avg, eps eps = 0.001_wp diff --git a/toolchain/mfc/run/input.py b/toolchain/mfc/run/input.py index a1fcb26772..81d3df9578 100644 --- a/toolchain/mfc/run/input.py +++ b/toolchain/mfc/run/input.py @@ -32,13 +32,13 @@ def generate_inp(self, target) -> None: # Save .inp input file common.file_write(f"{self.dirpath}/{target.name}.inp", self.get_inp(target)) - def __save_fpp(self, target, contents: str) -> None: + def __save_fpp(self, target, contents: str, name: str = "case.fpp") -> None: inc_dir = os.path.join(target.get_staging_dirpath(self), "include", target.name) common.create_directory(inc_dir) - fpp_path = os.path.join(inc_dir, "case.fpp") + fpp_path = os.path.join(inc_dir, name) - cons.print("Writing a (new) custom case.fpp file.") + cons.print(f"Writing a (new) custom {name} file.") common.file_write(fpp_path, contents, True) def get_cantera_solution(self): @@ -100,6 +100,11 @@ def generate_fpp(self, target) -> None: common.file_write(os.path.join(modules_dir, "m_thermochem.f90"), thermochem_code, True) + # m_thermochem's species count as a Fypp literal for array extents, and whether the species + # enter sys_size. + chemistry = self.params.get("chemistry", "F") == "T" + self.__save_fpp(target, f"#:set NUM_SPECIES = {sol.n_species}\n#:set CHEMISTRY = {chemistry}\n", "thermochem.fpp") + cons.unindent() def validate_constraints(self, target) -> None: