From 3ada451f474369ffeb32beecaef2248f2c559b93 Mon Sep 17 00:00:00 2001 From: Hyeoksu Lee Date: Fri, 25 Jul 2025 14:12:11 -0700 Subject: [PATCH 1/2] Fix broken example 0D_bubblecollapse_adap --- docs/documentation/case.md | 4 +++- examples/0D_bubblecollapse_adap/case.py | 1 + src/common/m_constants.fpp | 2 +- src/simulation/m_global_parameters.fpp | 6 ++++-- src/simulation/m_mpi_proxy.fpp | 3 ++- src/simulation/m_start_up.fpp | 4 ++-- toolchain/mfc/run/case_dicts.py | 1 + 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/documentation/case.md b/docs/documentation/case.md index 8cb8d96ac9..7a7da7a54b 100644 --- a/docs/documentation/case.md +++ b/docs/documentation/case.md @@ -379,6 +379,8 @@ Details of implementation of viscosity in MFC can be found in [Coralic (2015)](r | `mixture_err` | Logical | Mixture properties correction | | `time_stepper` | Integer | Runge--Kutta order [1-3] | | `adap_dt` | Logical | Strang splitting scheme with adaptive time stepping | +| `adap_dt_tol` | Real | Tolerance for adaptive time stepping in Strang splitting scheme| +| `adap_dt_max_iters` | Integer | Max iteration for adaptive time stepping in Strang splitting scheme | | `weno_order` | Integer | WENO order [1,3,5] | | `weno_eps` | Real | WENO perturbation (avoid division by zero) | | `mapped_weno` | Logical | WENO-M (WENO with mapping of nonlinear weights) | @@ -453,7 +455,7 @@ The effect and use of the source term are assessed by [Schmidmayer et al., 2019] - `time_stepper` specifies the order of the Runge-Kutta (RK) time integration scheme that is used for temporal integration in simulation, from the 1st to 5th order by corresponding integer. Note that `time_stepper = 3` specifies the total variation diminishing (TVD), third order RK scheme ([Gottlieb and Shu, 1998](references.md)). -- `adap_dt` activates the Strang operator splitting scheme which splits flux and source terms in time marching, and an adaptive time stepping strategy is implemented for the source term. It requires ``bubbles_euler = 'T'``, ``polytropic = 'T'``, ``adv_n = 'T'`` and `time_stepper = 3`. Additionally, it can be used with ``bubbles_lagrange = 'T'`` and `time_stepper = 3` +- `adap_dt` activates the Strang operator splitting scheme which splits flux and source terms in time marching, and an adaptive time stepping strategy is implemented for the source term. It requires ``bubbles_euler = 'T'``, ``polytropic = 'T'``, ``adv_n = 'T'`` and `time_stepper = 3`. Additionally, it can be used with ``bubbles_lagrange = 'T'`` and `time_stepper = 3`. `adap_dt_tol` and `adap_dt_max_iters` are 1e-4 and 100, respectively, by default. - `weno_order` specifies the order of WENO scheme that is used for spatial reconstruction of variables by an integer of 1, 3, 5, and 7, that correspond to the 1st, 3rd, 5th, and 7th order, respectively. diff --git a/examples/0D_bubblecollapse_adap/case.py b/examples/0D_bubblecollapse_adap/case.py index af7bb051c5..6b3fa639f9 100644 --- a/examples/0D_bubblecollapse_adap/case.py +++ b/examples/0D_bubblecollapse_adap/case.py @@ -118,6 +118,7 @@ "adv_n": "T", # adap_dt "adap_dt": "T", + "adap_dt_max_iters": 200, # Gas compression model "polytropic": "T", "thermal": 1, diff --git a/src/common/m_constants.fpp b/src/common/m_constants.fpp index 3682bbcf56..1bafcac839 100644 --- a/src/common/m_constants.fpp +++ b/src/common/m_constants.fpp @@ -55,7 +55,7 @@ module m_constants ! Strang Splitting constants real(wp), parameter :: dflt_adap_dt_tol = 1.e-4_wp !< Default tolerance for adaptive step size - integer, parameter :: adap_dt_max_iters = 100 !< Maximum number of iterations + ! Constants of the algorithm described by Heirer, E. Hairer S.P.Nørsett G. Wanner, Solving Ordinary Differential Equations I, Chapter II.4 ! to choose the initial time step size for the adaptive time stepping routine real(wp), parameter :: threshold_first_guess = 1.e-5_wp diff --git a/src/simulation/m_global_parameters.fpp b/src/simulation/m_global_parameters.fpp index fa6185c207..b2fe8b3357 100644 --- a/src/simulation/m_global_parameters.fpp +++ b/src/simulation/m_global_parameters.fpp @@ -409,7 +409,8 @@ module m_global_parameters logical :: adv_n !< Solve the number density equation and compute alpha from number density logical :: adap_dt !< Adaptive step size control real(wp) :: adap_dt_tol !< Tolerance to control adaptive step size - $:GPU_DECLARE(create='[adv_n,adap_dt,adap_dt_tol]') + integer :: adap_dt_max_iters !< Maximum number of iterations + $:GPU_DECLARE(create='[adv_n,adap_dt,adap_dt_tol,adap_dt_max_iters]') integer :: bubble_model !< Gilmore or Keller--Miksis bubble model integer :: thermal !< Thermal behavior. 1 = adiabatic, 2 = isotherm, 3 = transfer @@ -676,6 +677,7 @@ contains adv_n = .false. adap_dt = .false. adap_dt_tol = dflt_real + adap_dt_max_iters = 100 pi_fac = 1._wp @@ -1254,7 +1256,7 @@ contains $:GPU_UPDATE(device='[momxb,momxe,advxb,advxe,contxb,contxe, & & bubxb,bubxe,intxb,intxe,sys_size,buff_size,E_idx, & & alf_idx,n_idx,adv_n,adap_dt,pi_fac,strxb,strxe, & - & chemxb,chemxe,c_idx]') + & chemxb,chemxe,c_idx,adap_dt_tol,adap_dt_max_iters]') $:GPU_UPDATE(device='[b_size,xibeg,xiend,tensor_size]') $:GPU_UPDATE(device='[species_idx]') diff --git a/src/simulation/m_mpi_proxy.fpp b/src/simulation/m_mpi_proxy.fpp index fc08409e36..b10626ae0c 100644 --- a/src/simulation/m_mpi_proxy.fpp +++ b/src/simulation/m_mpi_proxy.fpp @@ -99,7 +99,8 @@ contains & 'bc_y%beg', 'bc_y%end', 'bc_z%beg', 'bc_z%end', 'fd_order', & & 'num_probes', 'num_integrals', 'bubble_model', 'thermal', & & 'R0_type', 'num_source', 'relax_model', 'num_ibs', 'n_start', & - & 'num_bc_patches', 'num_igr_iters', 'num_igr_warm_start_iters'] + & 'num_bc_patches', 'num_igr_iters', 'num_igr_warm_start_iters', & + & 'adap_dt_max_iters' ] call MPI_BCAST(${VAR}$, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr) #:endfor diff --git a/src/simulation/m_start_up.fpp b/src/simulation/m_start_up.fpp index 782418b416..352c15f525 100644 --- a/src/simulation/m_start_up.fpp +++ b/src/simulation/m_start_up.fpp @@ -173,7 +173,7 @@ contains relax, relax_model, & palpha_eps, ptgalpha_eps, & R0_type, file_per_process, sigma, & - pi_fac, adv_n, adap_dt, adap_dt_tol, & + pi_fac, adv_n, adap_dt, adap_dt_tol, adap_dt_max_iters, & bf_x, bf_y, bf_z, & k_x, k_y, k_z, w_x, w_y, w_z, p_x, p_y, p_z, & g_x, g_y, g_z, n_start, t_save, t_stop, & @@ -1415,7 +1415,7 @@ contains $:GPU_UPDATE(device='[nb,R0ref,Ca,Web,Re_inv,weight,R0,V0, & & bubbles_euler,polytropic,polydisperse,qbmm,R0_type, & & ptil,bubble_model,thermal,poly_sigma,adv_n,adap_dt, & - & adap_dt_tol,n_idx,pi_fac,low_Mach]') + & adap_dt_tol,adap_dt_max_iters,n_idx,pi_fac,low_Mach]') $:GPU_UPDATE(device='[R_n,R_v,phi_vn,phi_nv,Pe_c,Tw,pv,M_n, & & M_v,k_n,k_v,pb0,mass_n0,mass_v0,Pe_T,Re_trans_T, & & Re_trans_c,Im_trans_T,Im_trans_c,omegaN,mul0,ss, & diff --git a/toolchain/mfc/run/case_dicts.py b/toolchain/mfc/run/case_dicts.py index 43e0199718..e292b1676b 100644 --- a/toolchain/mfc/run/case_dicts.py +++ b/toolchain/mfc/run/case_dicts.py @@ -285,6 +285,7 @@ def analytic(self): 'pi_fac': ParamType.REAL, 'adap_dt': ParamType.LOG, 'adap_dt_tol': ParamType.REAL, + 'adap_dt_max_iters': ParamType.INT, 'ib': ParamType.LOG, 'num_ibs': ParamType.INT, 'n_start': ParamType.INT, From 8044eb2e2bfc3d8bd9409e44d8561b3eec372fe9 Mon Sep 17 00:00:00 2001 From: Hyeoksu Lee Date: Fri, 25 Jul 2025 14:21:43 -0700 Subject: [PATCH 2/2] add dflt_adap_dt_max_iters --- src/common/m_constants.fpp | 1 + src/simulation/m_global_parameters.fpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/m_constants.fpp b/src/common/m_constants.fpp index 1bafcac839..025f07868e 100644 --- a/src/common/m_constants.fpp +++ b/src/common/m_constants.fpp @@ -55,6 +55,7 @@ module m_constants ! Strang Splitting constants real(wp), parameter :: dflt_adap_dt_tol = 1.e-4_wp !< Default tolerance for adaptive step size + integer, parameter :: dflt_adap_dt_max_iters = 100 !< Default max iteration for adaptive step size ! Constants of the algorithm described by Heirer, E. Hairer S.P.Nørsett G. Wanner, Solving Ordinary Differential Equations I, Chapter II.4 ! to choose the initial time step size for the adaptive time stepping routine diff --git a/src/simulation/m_global_parameters.fpp b/src/simulation/m_global_parameters.fpp index b2fe8b3357..c6050d914c 100644 --- a/src/simulation/m_global_parameters.fpp +++ b/src/simulation/m_global_parameters.fpp @@ -677,7 +677,7 @@ contains adv_n = .false. adap_dt = .false. adap_dt_tol = dflt_real - adap_dt_max_iters = 100 + adap_dt_max_iters = dflt_adap_dt_max_iters pi_fac = 1._wp