From ab44ed3aeeac0c2470ecf20237b1340901495789 Mon Sep 17 00:00:00 2001 From: Ben Wilfong Date: Sun, 22 Nov 2026 12:01:45 -0500 Subject: [PATCH 1/2] Direction diffusive CFL numbers, interface only capillary limit, and compacted run_time.inf output --- docs/documentation/case.md | 2 +- src/common/m_constants.fpp | 2 + src/simulation/m_data_output.fpp | 70 ++++----- src/simulation/m_sim_helpers.fpp | 232 +++++++++++++++++------------ src/simulation/m_time_steppers.fpp | 8 +- 5 files changed, 171 insertions(+), 143 deletions(-) diff --git a/docs/documentation/case.md b/docs/documentation/case.md index e73b78fb55..8784c24700 100644 --- a/docs/documentation/case.md +++ b/docs/documentation/case.md @@ -798,7 +798,7 @@ restart data being resumed from. Pass `-t pre_process` explicitly (as in the res - `cfl_const_dt` enables constant `dt` time-stepping where `dt` results in a specified CFL for the initial condition -- `cfl_target` specifies the target CFL value +- `cfl_target` specifies the target CFL value. It bounds the acoustic number in each direction, and the diffusive numbers \f$D\,\Delta t\sum_d \Delta x_d^{-2}\f$ of viscosity (`VCFL`, \f$D = (4\mu/3 + \mu_b)/\rho\f$) and conduction (`TCFL`, \f$D = k/(\rho c_v)\f$). RK3 remains stable up to about 0.63 (0.5 for RK1 and RK2) - `ramp_ratio` limits how much the adaptive time step can grow from one time step to the next: `dt` is capped at `ramp_ratio` times the previous `dt`. Must be at least 1. When unset, the time step growth is unlimited. diff --git a/src/common/m_constants.fpp b/src/common/m_constants.fpp index 308b668973..51fbbd4a7e 100644 --- a/src/common/m_constants.fpp +++ b/src/common/m_constants.fpp @@ -67,6 +67,8 @@ module m_constants integer, parameter :: amr_restart_blk_own_ints = 4 !> color function gradient magnitude at which to apply the surface tension fluxes real(wp), parameter :: capillary_cutoff = 1.e-6 + !> Volume fraction below which a phase counts as absent for the capillary time-step limit + real(wp), parameter :: capillary_alpha_min = 1.e-3_wp !> Spatial support width of acoustic source, used in s_source_spatial real(wp), parameter :: acoustic_spatial_support_width = 2.5_wp real(wp), parameter :: dflt_vcfl_dt = 100._wp !< value of vcfl_dt when viscosity is off for computing adaptive timestep size diff --git a/src/simulation/m_data_output.fpp b/src/simulation/m_data_output.fpp index a93f483947..c464e657b2 100644 --- a/src/simulation/m_data_output.fpp +++ b/src/simulation/m_data_output.fpp @@ -107,23 +107,12 @@ contains write (3, '(A)') ''; write (3, '(A)') '' - write (3, '(13X,A9,13X,A10,13X,A10,13X,A10)', advance="no") trim('Time-step'), trim('dt'), trim('Time'), trim('ICFL Max') - - if (surface_tension) then - write (3, '(13X,A10)', advance="no") trim('CCFL Max') - end if - - if (heat_conduction) then - write (3, '(13X,A10)', advance="no") trim('TCFL Max') - end if - - if (viscous) then - write (3, '(13X,A10,13X,A16)', advance="no") trim('VCFL Max'), trim('Rc Min') - end if - - if (bubbles_lagrange) then - write (3, '(13X,A10)', advance="no") trim('N Bubbles') - end if + ! Columns two blanks apart; reals to four significant digits (ES10.3), counts exact + write (3, '(A9,3(2X,A10))', advance="no") 'Time-step', 'dt', 'Time', 'ICFL Max' + if (surface_tension) write (3, '(2X,A10)', advance="no") 'CCFL Max' + if (heat_conduction) write (3, '(2X,A10)', advance="no") 'TCFL Max' + if (viscous) write (3, '(2X,A10,2X,A10)', advance="no") 'VCFL Max', 'Rc Min' + if (bubbles_lagrange) write (3, '(2X,A10)', advance="no") 'N Bubbles' write (3, *) ! new line @@ -182,6 +171,7 @@ contains real(wp) :: qv !< Cell-avg. internal energy reference value real(wp) :: c !< Cell-avg. sound speed real(wp), dimension(2) :: Re !< Cell-avg. Reynolds numbers + real(wp) :: Dth !< Cell thermal diffusivity integer :: j, k, l real(wp) :: icfl_max_loc, icfl_max_glb !< ICFL stability extrema on local and global grids real(wp) :: vcfl_max_loc, vcfl_max_glb !< VCFL stability extrema on local and global grids @@ -208,10 +198,10 @@ contains Re_size_loc1 = Re_size(1); Re_size_loc2 = Re_size(2) pw1 = amr_cfl_pow(1); pw2 = amr_cfl_pow(2); pw3 = amr_cfl_pow(3); amr_on = amr ! Computing Stability Criteria at Current Time-step - $:GPU_PARALLEL_LOOP(collapse=3, private='[j, k, l, vel, alpha, alpha_rho, Re, rho, vel_sum, pres, gamma, pi_inf, c, qv, & - & icfl, vcfl, Rc, ccfl, tcfl, fl, mu_frac, include_cell]', reduction='[[icfl_max_loc, vcfl_max_loc, & - & ccfl_max_loc, tcfl_max_loc, mu_frac_max_loc], [Rc_min_loc]]', reductionOp='[max, min]', & - & firstprivate='[Re_size_loc1, Re_size_loc2, pw1, pw2, pw3, amr_on]') + $:GPU_PARALLEL_LOOP(collapse=3, private='[j, k, l, vel, alpha, alpha_rho, Re, Dth, rho, vel_sum, pres, gamma, pi_inf, c, & + & qv, icfl, vcfl, Rc, ccfl, tcfl, fl, mu_frac, include_cell]', reduction='[[icfl_max_loc, & + & vcfl_max_loc, ccfl_max_loc, tcfl_max_loc, mu_frac_max_loc], [Rc_min_loc]]', reductionOp='[max, & + & min]', firstprivate='[Re_size_loc1, Re_size_loc2, pw1, pw2, pw3, amr_on]') do l = 0, p do k = 0, n do j = 0, m @@ -250,7 +240,9 @@ contains Re(1) = 1._wp/max(Re(1), sgm_eps) end if - call s_compute_stability_from_dt(vel, c, rho, Re, alpha, alpha_rho, j, k, l, icfl, vcfl, Rc, ccfl, tcfl) + call s_compute_cell_diffusivity(alpha, alpha_rho, Dth) + call s_compute_stability_from_dt(vel, c, rho, Re, alpha, alpha_rho, Dth, j, k, l, icfl, vcfl, Rc, ccfl, & + & tcfl) if (amr_on) call s_amr_scale_stability(amr_cfl_rf(j, k, l), pw1, pw2, pw3, icfl, vcfl, Rc, ccfl, tcfl) icfl_max_loc = max(icfl_max_loc, icfl) @@ -310,23 +302,11 @@ contains call s_mpi_barrier() ! ensure diagnostic output above is flushed before any rank aborts below if (proc_rank == 0) then - write (3, '(13X,I9,13X,ES10.3,13X,ES10.3,13X,F10.6)', advance="no") t_step, dt, mytime, icfl_max_glb - - if (surface_tension) then - write (3, '(13X,F10.6)', advance="no") ccfl_max_glb - end if - - if (heat_conduction) then - write (3, '(13X,F10.6)', advance="no") tcfl_max_glb - end if - - if (viscous) then - write (3, '(13X,F10.6,13X,ES16.6)', advance="no") vcfl_max_glb, Rc_min_glb - end if - - if (bubbles_lagrange) then - write (3, '(13X,I10)', advance="no") n_el_bubs_glb - end if + write (3, '(I9,3(2X,ES10.3))', advance="no") t_step, dt, mytime, icfl_max_glb + if (surface_tension) write (3, '(2X,ES10.3)', advance="no") ccfl_max_glb + if (heat_conduction) write (3, '(2X,ES10.3)', advance="no") tcfl_max_glb + if (viscous) write (3, '(2X,ES10.3,2X,ES10.3)', advance="no") vcfl_max_glb, Rc_min_glb + if (bubbles_lagrange) write (3, '(2X,I10)', advance="no") n_el_bubs_glb write (3, *) ! new line @@ -413,7 +393,7 @@ contains Re(1) = 1._wp/max(Re(1), sgm_eps) end if - call s_compute_stability_from_dt(vel, c, rho, Re, alpha, alpha_rho, j, k, l, icfl, vcfl, Rc, ccfl, tcfl) + call s_compute_stability_from_dt(vel, c, rho, Re, alpha, alpha_rho, 0._wp, j, k, l, icfl, vcfl, Rc, ccfl, tcfl) if (amr) call s_amr_scale_stability(amr_cfl_rf(j, k, l), amr_cfl_pow(1), amr_cfl_pow(2), amr_cfl_pow(3), & & icfl, vcfl, Rc, ccfl, tcfl) @@ -1963,11 +1943,11 @@ contains write (3, '(A)') ' ' write (3, '(A)') '' - write (3, '(A,F9.6)') 'ICFL Max: ', icfl_max - if (surface_tension) write (3, '(A,F9.6)') 'CCFL Max: ', ccfl_max - if (heat_conduction) write (3, '(A,F9.6)') 'TCFL Max: ', tcfl_max - if (viscous) write (3, '(A,F9.6)') 'VCFL Max: ', vcfl_max - if (viscous) write (3, '(A,ES16.6)') 'Rc Min: ', Rc_min + write (3, '(A,ES10.3)') 'ICFL Max: ', icfl_max + if (surface_tension) write (3, '(A,ES10.3)') 'CCFL Max: ', ccfl_max + if (heat_conduction) write (3, '(A,ES10.3)') 'TCFL Max: ', tcfl_max + if (viscous) write (3, '(A,ES10.3)') 'VCFL Max: ', vcfl_max + if (viscous) write (3, '(A,ES10.3)') 'Rc Min: ', Rc_min call cpu_time(run_time) diff --git a/src/simulation/m_sim_helpers.fpp b/src/simulation/m_sim_helpers.fpp index 21df4d27db..aa0bacba95 100644 --- a/src/simulation/m_sim_helpers.fpp +++ b/src/simulation/m_sim_helpers.fpp @@ -14,8 +14,8 @@ module m_sim_helpers implicit none - private; public :: s_compute_cell_state, s_compute_stability_from_dt, s_compute_dt_from_cfl, s_amr_scale_stability, & - & dt_limiter, dt_limiter_names + private; public :: s_compute_cell_state, s_compute_cell_diffusivity, s_compute_stability_from_dt, s_compute_dt_from_cfl, & + & s_amr_scale_stability, dt_limiter, dt_limiter_names !> Criterion currently limiting the adaptive time step (ICFL, VCFL, CCFL, TCFL, the collision cap, or the ramp limiter) character(len=4) :: dt_limiter = 'none' @@ -23,6 +23,29 @@ module m_sim_helpers contains + !> Brackbill's capillary density (rho_1 + rho_2)/2 from the phase densities of an interface cell. Zero where a phase is absent, + !! so single-phase cells, which carry no capillary force, impose no capillary limit + function f_capillary_rho(alpha, alpha_rho) result(rho_c) + + $:GPU_ROUTINE(parallelism='[seq]') + #:if not MFC_CASE_OPTIMIZATION and USING_AMD + real(wp), dimension(3), intent(in) :: alpha, alpha_rho + #:else + real(wp), dimension(num_fluids), intent(in) :: alpha, alpha_rho + #:endif + real(wp) :: rho_c + integer :: i + + rho_c = 0._wp + if (minval(alpha(1:num_fluids)) < capillary_alpha_min) return + $:GPU_LOOP(parallelism='[seq]') + do i = 1, num_fluids + rho_c = rho_c + alpha_rho(i)/alpha(i) + end do + rho_c = rho_c/real(num_fluids, wp) + + end function f_capillary_rho + !> Computes the modified dtheta for Fourier filtering in azimuthal direction function f_compute_filtered_dtheta(k, l) result(fltr_dtheta) @@ -46,6 +69,38 @@ contains end function f_compute_filtered_dtheta + !> Sum over directions of 1/spacing^2 at cell (j, k, l). An explicit diffusion with diffusivity D is RK-stable for D*dt*sum <= + !! 2.51/4 (RK3; 2/4 for RK1 and RK2), so the diffusive CFL numbers are D*dt*sum + function f_inv_dx2_sum(j, k, l) result(s) + + $:GPU_ROUTINE(parallelism='[seq]') + integer, intent(in) :: j, k, l + real(wp) :: s + + s = 1._wp/dx(j)**2 + if (n > 0) s = s + 1._wp/dy(k)**2 + if (p > 0) then + if (grid_geometry == 3) then + s = s + 1._wp/f_compute_filtered_dtheta(k, l)**2 + else + s = s + 1._wp/dz(l)**2 + end if + end if + + end function f_inv_dx2_sum + + !> Momentum diffusivity of the viscous stress: normal stresses diffuse with (4/3 mu + mu_b)/rho, the largest coefficient + function f_visc_diffusivity(Re_l, rho) result(nu) + + $:GPU_ROUTINE(parallelism='[seq]') + real(wp), dimension(2), intent(in) :: Re_l + real(wp), intent(in) :: rho + real(wp) :: nu + + nu = (4._wp/(3._wp*Re_l(1)) + 1._wp/Re_l(2))/rho + + end function f_visc_diffusivity + !> Computes the mixture coefficients, velocity and pressure of one cell subroutine s_compute_cell_state(q_prim_vf, pres, rho, gamma, pi_inf, Re, alpha, alpha_rho, vel, vel_sum, qv, j, k, l, & & Re_size_loc1, Re_size_loc2) @@ -109,8 +164,36 @@ contains end subroutine s_compute_cell_state + !> Thermal diffusivity k/(rho cv) of cell state (alpha, alpha_rho) for the explicit conduction step limit, zero without it + subroutine s_compute_cell_diffusivity(alpha, alpha_rho, Dth) + + $:GPU_ROUTINE(function_name='s_compute_cell_diffusivity', parallelism='[seq]', cray_inline=True) + + #:if not MFC_CASE_OPTIMIZATION and USING_AMD + real(wp), dimension(3), intent(in) :: alpha, alpha_rho + #:else + real(wp), dimension(num_fluids), intent(in) :: alpha, alpha_rho + #:endif + real(wp), intent(out) :: Dth + real(wp) :: k_mix, rho_cv + integer :: i + + Dth = 0._wp + if (heat_conduction) then + k_mix = 0._wp + rho_cv = 0._wp + $:GPU_LOOP(parallelism='[seq]') + do i = 1, num_fluids + k_mix = k_mix + alpha(i)*fluid_k_therm(i) + rho_cv = rho_cv + alpha_rho(i)*cvs(i) + end do + Dth = k_mix/max(rho_cv, sgm_eps) + end if + + end subroutine s_compute_cell_diffusivity + !> Computes stability criterion for a specified dt - subroutine s_compute_stability_from_dt(vel, c, rho, Re_l, alpha, alpha_rho, j, k, l, icfl, vcfl, Rc, ccfl, tcfl) + subroutine s_compute_stability_from_dt(vel, c, rho, Re_l, alpha, alpha_rho, Dth, j, k, l, icfl, vcfl, Rc, ccfl, tcfl) $:GPU_ROUTINE(parallelism='[seq]') real(wp), intent(in), dimension(num_vels) :: vel @@ -118,6 +201,7 @@ contains real(wp), intent(inout) :: icfl real(wp), intent(inout) :: vcfl, Rc, ccfl, tcfl real(wp), dimension(2), intent(in) :: Re_l + real(wp), intent(in) :: Dth #:if not MFC_CASE_OPTIMIZATION and USING_AMD real(wp), dimension(3), intent(in) :: alpha, alpha_rho #:else @@ -125,8 +209,7 @@ contains #:endif integer, intent(in) :: j, k, l real(wp) :: fltr_dtheta - real(wp) :: k_mix, rho_cv - integer :: i + real(wp) :: rho_c ! Inviscid CFL calculation ! The multi-dimensional CFL terms are written out here rather than @@ -150,68 +233,48 @@ contains ! Viscous calculations if (viscous) then + vcfl = dt*f_visc_diffusivity(Re_l, rho)*f_inv_dx2_sum(j, k, l) if (p > 0) then #:if not MFC_CASE_OPTIMIZATION or num_dims > 2 if (grid_geometry == 3) then fltr_dtheta = f_compute_filtered_dtheta(k, l) - vcfl = maxval(dt/Re_l/rho)/min(dx(j), dy(k), fltr_dtheta)**2._wp Rc = min(dx(j)*(abs(vel(1)) + c), dy(k)*(abs(vel(2)) + c), fltr_dtheta*(abs(vel(3)) + c))/maxval(1._wp/Re_l) else - vcfl = maxval(dt/Re_l/rho)/min(dx(j), dy(k), dz(l))**2._wp Rc = min(dx(j)*(abs(vel(1)) + c), dy(k)*(abs(vel(2)) + c), dz(l)*(abs(vel(3)) + c))/maxval(1._wp/Re_l) end if #:endif else if (n > 0) then - vcfl = maxval(dt/Re_l/rho)/min(dx(j), dy(k))**2._wp Rc = min(dx(j)*(abs(vel(1)) + c), dy(k)*(abs(vel(2)) + c))/maxval(1._wp/Re_l) else - vcfl = maxval(dt/Re_l/rho)/dx(j)**2._wp Rc = dx(j)*(abs(vel(1)) + c)/maxval(1._wp/Re_l) end if end if ! Capillary CFL calculation if (surface_tension) then - if (p > 0) then - #:if not MFC_CASE_OPTIMIZATION or num_dims > 2 - if (grid_geometry == 3) then - fltr_dtheta = f_compute_filtered_dtheta(k, l) - ccfl = dt*sqrt(2._wp*pi*sigma/(rho*min(dx(j), dy(k), fltr_dtheta)**3._wp)) - else - ccfl = dt*sqrt(2._wp*pi*sigma/(rho*min(dx(j), dy(k), dz(l))**3._wp)) - end if - #:endif - else if (n > 0) then - ccfl = dt*sqrt(2._wp*pi*sigma/(rho*min(dx(j), dy(k))**3._wp)) - else - ccfl = dt*sqrt(2._wp*pi*sigma/(rho*dx(j)**3._wp)) - end if - end if - - ! Thermal diffusion CFL - if (heat_conduction) then - k_mix = 0._wp - rho_cv = 0._wp - $:GPU_LOOP(parallelism='[seq]') - do i = 1, num_fluids - k_mix = k_mix + alpha(i)*fluid_k_therm(i) - rho_cv = rho_cv + alpha_rho(i)*cvs(i) - end do - - if (p > 0) then - if (grid_geometry == 3) then - fltr_dtheta = f_compute_filtered_dtheta(k, l) - tcfl = dt*k_mix/(rho_cv*min(dx(j), dy(k), fltr_dtheta)**2._wp) + ccfl = 0._wp + rho_c = f_capillary_rho(alpha, alpha_rho) + if (rho_c > 0._wp) then + if (p > 0) then + #:if not MFC_CASE_OPTIMIZATION or num_dims > 2 + if (grid_geometry == 3) then + fltr_dtheta = f_compute_filtered_dtheta(k, l) + ccfl = dt*sqrt(2._wp*pi*sigma/(rho_c*min(dx(j), dy(k), fltr_dtheta)**3._wp)) + else + ccfl = dt*sqrt(2._wp*pi*sigma/(rho_c*min(dx(j), dy(k), dz(l))**3._wp)) + end if + #:endif + else if (n > 0) then + ccfl = dt*sqrt(2._wp*pi*sigma/(rho_c*min(dx(j), dy(k))**3._wp)) else - tcfl = dt*k_mix/(rho_cv*min(dx(j), dy(k), dz(l))**2._wp) + ccfl = dt*sqrt(2._wp*pi*sigma/(rho_c*dx(j)**3._wp)) end if - else if (n > 0) then - tcfl = dt*k_mix/(rho_cv*min(dx(j), dy(k))**2._wp) - else - tcfl = dt*k_mix/(rho_cv*dx(j)**2._wp) end if end if + ! Thermal diffusion CFL + tcfl = dt*Dth*f_inv_dx2_sum(j, k, l) + end subroutine s_compute_stability_from_dt !> The stability numbers of the finest cell over a coarse cell, from the coarse cell's: rf is its spacing ratio (amr_cfl_rf) and @@ -232,23 +295,22 @@ contains !> Computes the candidate dts for a specified CFL number: max_dt(1) from the inviscid, max_dt(2) the viscous, max_dt(3) the !! capillary, and max_dt(4) the thermal diffusion criterion (huge where the criterion is inactive) - subroutine s_compute_dt_from_cfl(vel, c, max_dt, rho, Re_l, alpha, alpha_rho, j, k, l) + subroutine s_compute_dt_from_cfl(vel, c, max_dt, rho, Re_l, alpha, alpha_rho, Dth, j, k, l) $:GPU_ROUTINE(parallelism='[seq]') real(wp), dimension(num_vels), intent(in) :: vel real(wp), intent(in) :: c, rho real(wp), dimension(4), intent(out) :: max_dt real(wp), dimension(2), intent(in) :: Re_l + real(wp), intent(in) :: Dth #:if not MFC_CASE_OPTIMIZATION and USING_AMD real(wp), dimension(3), intent(in) :: alpha, alpha_rho #:else real(wp), dimension(num_fluids), intent(in) :: alpha, alpha_rho #:endif integer, intent(in) :: j, k, l - real(wp) :: vcfl_dt, ccfl_dt, tcfl_dt + real(wp) :: ccfl_dt, rho_c, hmin real(wp) :: fltr_dtheta - real(wp) :: k_mix, rho_cv - integer :: i max_dt(2) = huge(1._wp) max_dt(3) = huge(1._wp) @@ -275,66 +337,48 @@ contains end if ! Viscous calculations - if (viscous .or. chem_params%transport_dt) then + if (chem_params%transport_dt) then + ! Re from s_compute_transport_dt_re already sums the num_dims directions, so it keeps the min-width form + hmin = dx(j) + if (n > 0) hmin = min(hmin, dy(k)) if (p > 0) then if (grid_geometry == 3) then - fltr_dtheta = f_compute_filtered_dtheta(k, l) - vcfl_dt = cfl_target*(min(dx(j), dy(k), fltr_dtheta)**2._wp)/maxval(1/(rho*Re_l)) + hmin = min(hmin, f_compute_filtered_dtheta(k, l)) else - vcfl_dt = cfl_target*(min(dx(j), dy(k), dz(l))**2._wp)/maxval(1/(rho*Re_l)) + hmin = min(hmin, dz(l)) end if - else if (n > 0) then - vcfl_dt = cfl_target*(min(dx(j), dy(k))**2._wp)/maxval((1/Re_l)/rho) - else - vcfl_dt = cfl_target*(dx(j)**2._wp)/maxval(1/(rho*Re_l)) end if - max_dt(2) = vcfl_dt + max_dt(2) = cfl_target*hmin**2/maxval(1/(rho*Re_l)) + else if (viscous) then + max_dt(2) = cfl_target/(f_visc_diffusivity(Re_l, rho)*f_inv_dx2_sum(j, k, l)) end if ! Capillary CFL calculations if (surface_tension) then - if (p > 0) then - #:if not MFC_CASE_OPTIMIZATION or num_dims > 2 - if (grid_geometry == 3) then - fltr_dtheta = f_compute_filtered_dtheta(k, l) - ccfl_dt = cfl_target*sqrt(rho*min(dx(j), dy(k), fltr_dtheta)**3._wp/(2._wp*pi*sigma)) - else - ccfl_dt = cfl_target*sqrt(rho*min(dx(j), dy(k), dz(l))**3._wp/(2._wp*pi*sigma)) - end if - #:endif - else if (n > 0) then - ccfl_dt = cfl_target*sqrt(rho*min(dx(j), dy(k))**3._wp/(2._wp*pi*sigma)) - else - ccfl_dt = cfl_target*sqrt(rho*dx(j)**3._wp/(2._wp*pi*sigma)) - end if - max_dt(3) = ccfl_dt - end if - - ! Thermal diffusion CFL: dt <= cfl * dx^2 * rho * cv / k - if (heat_conduction) then - k_mix = 0._wp - rho_cv = 0._wp - $:GPU_LOOP(parallelism='[seq]') - do i = 1, num_fluids - k_mix = k_mix + alpha(i)*fluid_k_therm(i) - rho_cv = rho_cv + alpha_rho(i)*cvs(i) - end do - - if (p > 0) then - if (grid_geometry == 3) then - fltr_dtheta = f_compute_filtered_dtheta(k, l) - tcfl_dt = cfl_target*(min(dx(j), dy(k), fltr_dtheta)**2._wp)*rho_cv/max(k_mix, sgm_eps) + ccfl_dt = huge(1._wp) + rho_c = f_capillary_rho(alpha, alpha_rho) + if (rho_c > 0._wp) then + if (p > 0) then + #:if not MFC_CASE_OPTIMIZATION or num_dims > 2 + if (grid_geometry == 3) then + fltr_dtheta = f_compute_filtered_dtheta(k, l) + ccfl_dt = cfl_target*sqrt(rho_c*min(dx(j), dy(k), fltr_dtheta)**3._wp/(2._wp*pi*sigma)) + else + ccfl_dt = cfl_target*sqrt(rho_c*min(dx(j), dy(k), dz(l))**3._wp/(2._wp*pi*sigma)) + end if + #:endif + else if (n > 0) then + ccfl_dt = cfl_target*sqrt(rho_c*min(dx(j), dy(k))**3._wp/(2._wp*pi*sigma)) else - tcfl_dt = cfl_target*(min(dx(j), dy(k), dz(l))**2._wp)*rho_cv/max(k_mix, sgm_eps) + ccfl_dt = cfl_target*sqrt(rho_c*dx(j)**3._wp/(2._wp*pi*sigma)) end if - else if (n > 0) then - tcfl_dt = cfl_target*(min(dx(j), dy(k))**2._wp)*rho_cv/max(k_mix, sgm_eps) - else - tcfl_dt = cfl_target*(dx(j)**2._wp)*rho_cv/max(k_mix, sgm_eps) end if - max_dt(4) = tcfl_dt + max_dt(3) = ccfl_dt end if + ! Thermal diffusion CFL: dt <= cfl/(D sum(1/dx^2)) + if (Dth > 0._wp) max_dt(4) = cfl_target/(Dth*f_inv_dx2_sum(j, k, l)) + end subroutine s_compute_dt_from_cfl end module m_sim_helpers diff --git a/src/simulation/m_time_steppers.fpp b/src/simulation/m_time_steppers.fpp index 6833a11ef4..88feb28e1e 100644 --- a/src/simulation/m_time_steppers.fpp +++ b/src/simulation/m_time_steppers.fpp @@ -741,6 +741,7 @@ contains real(wp) :: qv !< Cell-avg. fluid reference energy real(wp) :: c !< Cell-avg. sound speed real(wp), dimension(2) :: Re !< Cell-avg. Reynolds numbers + real(wp) :: Dth !< Cell thermal diffusivity (s_compute_cell_diffusivity) real(wp), dimension(4) :: max_dt !< Cell dt candidates (inviscid, viscous, capillary, thermal) real(wp) :: icfl_dt_local, vcfl_dt_local, ccfl_dt_local, tcfl_dt_local, coll_dt_local real(wp), dimension(6) :: dt_candidates_loc !< Rank-local dt candidates (ICFL, VCFL, CCFL, TCFL, collision cap, WCOL) @@ -773,8 +774,8 @@ contains if (amr .eqv. ${'.true.' if ON_AMR else '.false.'}$) then $:GPU_PARALLEL_LOOP(collapse=3, firstprivate='[Re_size_loc1, & & Re_size_loc2' + (', pw1, pw2, pw3' if ON_AMR else '') + ']', private='[vel, alpha, & - & alpha_rho, Re, rho, vel_sum, pres, gamma, pi_inf, c, qv, fl, max_dt, is_fluid_cell, Ys, & - & Re_chem, T_cell' + (', rf' if ON_AMR else '') + ']', reduction='[[icfl_dt_local, & + & alpha_rho, Re, Dth, rho, vel_sum, pres, gamma, pi_inf, c, qv, fl, max_dt, is_fluid_cell, & + & Ys, Re_chem, T_cell' + (', rf' if ON_AMR else '') + ']', reduction='[[icfl_dt_local, & & vcfl_dt_local, ccfl_dt_local, tcfl_dt_local], [bad_cell]]', reductionOp='[min, max]') do l = 0, p do k = 0, n @@ -824,7 +825,8 @@ contains Re = Re_chem end if - call s_compute_dt_from_cfl(vel, c, max_dt, rho, Re, alpha, alpha_rho, j, k, l) + call s_compute_cell_diffusivity(alpha, alpha_rho, Dth) + call s_compute_dt_from_cfl(vel, c, max_dt, rho, Re, alpha, alpha_rho, Dth, j, k, l) #:if ON_AMR rf = amr_cfl_rf(j, k, l) max_dt(1) = max_dt(1)/rf**pw1 From c6d286ee4810a6928b29f84ccee56d3b3ca0631e Mon Sep 17 00:00:00 2001 From: Ben Wilfong Date: Sun, 22 Nov 2026 20:44:03 -0500 Subject: [PATCH 2/2] replace functions with subroutines for NVHPC 25.5 --- src/simulation/m_sim_helpers.fpp | 50 ++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/simulation/m_sim_helpers.fpp b/src/simulation/m_sim_helpers.fpp index aa0bacba95..7fe06d289f 100644 --- a/src/simulation/m_sim_helpers.fpp +++ b/src/simulation/m_sim_helpers.fpp @@ -25,16 +25,16 @@ contains !> Brackbill's capillary density (rho_1 + rho_2)/2 from the phase densities of an interface cell. Zero where a phase is absent, !! so single-phase cells, which carry no capillary force, impose no capillary limit - function f_capillary_rho(alpha, alpha_rho) result(rho_c) + subroutine s_compute_capillary_rho(alpha, alpha_rho, rho_c) - $:GPU_ROUTINE(parallelism='[seq]') + $:GPU_ROUTINE(function_name='s_compute_capillary_rho', parallelism='[seq]', cray_inline=True) #:if not MFC_CASE_OPTIMIZATION and USING_AMD real(wp), dimension(3), intent(in) :: alpha, alpha_rho #:else real(wp), dimension(num_fluids), intent(in) :: alpha, alpha_rho #:endif - real(wp) :: rho_c - integer :: i + real(wp), intent(out) :: rho_c + integer :: i rho_c = 0._wp if (minval(alpha(1:num_fluids)) < capillary_alpha_min) return @@ -44,7 +44,7 @@ contains end do rho_c = rho_c/real(num_fluids, wp) - end function f_capillary_rho + end subroutine s_compute_capillary_rho !> Computes the modified dtheta for Fourier filtering in azimuthal direction function f_compute_filtered_dtheta(k, l) result(fltr_dtheta) @@ -71,11 +71,11 @@ contains !> Sum over directions of 1/spacing^2 at cell (j, k, l). An explicit diffusion with diffusivity D is RK-stable for D*dt*sum <= !! 2.51/4 (RK3; 2/4 for RK1 and RK2), so the diffusive CFL numbers are D*dt*sum - function f_inv_dx2_sum(j, k, l) result(s) + subroutine s_compute_inv_dx2_sum(j, k, l, s) - $:GPU_ROUTINE(parallelism='[seq]') - integer, intent(in) :: j, k, l - real(wp) :: s + $:GPU_ROUTINE(function_name='s_compute_inv_dx2_sum', parallelism='[seq]', cray_inline=True) + integer, intent(in) :: j, k, l + real(wp), intent(out) :: s s = 1._wp/dx(j)**2 if (n > 0) s = s + 1._wp/dy(k)**2 @@ -87,19 +87,19 @@ contains end if end if - end function f_inv_dx2_sum + end subroutine s_compute_inv_dx2_sum !> Momentum diffusivity of the viscous stress: normal stresses diffuse with (4/3 mu + mu_b)/rho, the largest coefficient - function f_visc_diffusivity(Re_l, rho) result(nu) + subroutine s_compute_visc_diffusivity(Re_l, rho, nu) - $:GPU_ROUTINE(parallelism='[seq]') + $:GPU_ROUTINE(function_name='s_compute_visc_diffusivity', parallelism='[seq]', cray_inline=True) real(wp), dimension(2), intent(in) :: Re_l real(wp), intent(in) :: rho - real(wp) :: nu + real(wp), intent(out) :: nu nu = (4._wp/(3._wp*Re_l(1)) + 1._wp/Re_l(2))/rho - end function f_visc_diffusivity + end subroutine s_compute_visc_diffusivity !> Computes the mixture coefficients, velocity and pressure of one cell subroutine s_compute_cell_state(q_prim_vf, pres, rho, gamma, pi_inf, Re, alpha, alpha_rho, vel, vel_sum, qv, j, k, l, & @@ -209,7 +209,9 @@ contains #:endif integer, intent(in) :: j, k, l real(wp) :: fltr_dtheta - real(wp) :: rho_c + real(wp) :: rho_c, nu, inv_dx2 + + call s_compute_inv_dx2_sum(j, k, l, inv_dx2) ! Inviscid CFL calculation ! The multi-dimensional CFL terms are written out here rather than @@ -233,7 +235,8 @@ contains ! Viscous calculations if (viscous) then - vcfl = dt*f_visc_diffusivity(Re_l, rho)*f_inv_dx2_sum(j, k, l) + call s_compute_visc_diffusivity(Re_l, rho, nu) + vcfl = dt*nu*inv_dx2 if (p > 0) then #:if not MFC_CASE_OPTIMIZATION or num_dims > 2 if (grid_geometry == 3) then @@ -253,7 +256,7 @@ contains ! Capillary CFL calculation if (surface_tension) then ccfl = 0._wp - rho_c = f_capillary_rho(alpha, alpha_rho) + call s_compute_capillary_rho(alpha, alpha_rho, rho_c) if (rho_c > 0._wp) then if (p > 0) then #:if not MFC_CASE_OPTIMIZATION or num_dims > 2 @@ -273,7 +276,7 @@ contains end if ! Thermal diffusion CFL - tcfl = dt*Dth*f_inv_dx2_sum(j, k, l) + tcfl = dt*Dth*inv_dx2 end subroutine s_compute_stability_from_dt @@ -309,13 +312,15 @@ contains real(wp), dimension(num_fluids), intent(in) :: alpha, alpha_rho #:endif integer, intent(in) :: j, k, l - real(wp) :: ccfl_dt, rho_c, hmin + real(wp) :: ccfl_dt, rho_c, hmin, nu, inv_dx2 real(wp) :: fltr_dtheta max_dt(2) = huge(1._wp) max_dt(3) = huge(1._wp) max_dt(4) = huge(1._wp) + call s_compute_inv_dx2_sum(j, k, l, inv_dx2) + ! Inviscid CFL calculation ! The multi-dimensional CFL terms are written out here rather than ! obtained from a shared helper procedure: NVHPC 25.5's fort2 segfaults @@ -350,13 +355,14 @@ contains end if max_dt(2) = cfl_target*hmin**2/maxval(1/(rho*Re_l)) else if (viscous) then - max_dt(2) = cfl_target/(f_visc_diffusivity(Re_l, rho)*f_inv_dx2_sum(j, k, l)) + call s_compute_visc_diffusivity(Re_l, rho, nu) + max_dt(2) = cfl_target/(nu*inv_dx2) end if ! Capillary CFL calculations if (surface_tension) then ccfl_dt = huge(1._wp) - rho_c = f_capillary_rho(alpha, alpha_rho) + call s_compute_capillary_rho(alpha, alpha_rho, rho_c) if (rho_c > 0._wp) then if (p > 0) then #:if not MFC_CASE_OPTIMIZATION or num_dims > 2 @@ -377,7 +383,7 @@ contains end if ! Thermal diffusion CFL: dt <= cfl/(D sum(1/dx^2)) - if (Dth > 0._wp) max_dt(4) = cfl_target/(Dth*f_inv_dx2_sum(j, k, l)) + if (Dth > 0._wp) max_dt(4) = cfl_target/(Dth*inv_dx2) end subroutine s_compute_dt_from_cfl