From fbc58ec26d63333991e458ec66cf86c2cc8992ff Mon Sep 17 00:00:00 2001 From: "Marc T. Henry de Frahan" Date: Mon, 31 Jan 2022 15:51:16 -0700 Subject: [PATCH] Fix FPE when CFLs are zero (#558) * Fix FPE when CFLs are zero * Abort if using adaptive time stepping and the CFL is small --- amr-wind/core/SimTime.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/amr-wind/core/SimTime.cpp b/amr-wind/core/SimTime.cpp index 3cf41ef838..a38827c19c 100644 --- a/amr-wind/core/SimTime.cpp +++ b/amr-wind/core/SimTime.cpp @@ -95,7 +95,15 @@ void SimTime::set_current_cfl( const amrex::Real cd_cfl = conv_cfl + diff_cfl; const amrex::Real cfl_unit_time = cd_cfl + std::sqrt(cd_cfl * cd_cfl + 4.0 * src_cfl); - amrex::Real dt_new = 2.0 * m_max_cfl / cfl_unit_time; + if ((m_adaptive) && + (cfl_unit_time < std::numeric_limits::epsilon())) { + amrex::Abort( + "CFL is below machine epsilon and the time step is adaptive. " + "Please use a fixed time step or fix the case setup"); + } + amrex::Real dt_new = + 2.0 * m_max_cfl / + amrex::max(cfl_unit_time, std::numeric_limits::epsilon()); // Restrict timestep during initialization phase if (m_is_init) {