From 29a76c65403ad6761d8636a54dc8e48d8d139125 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Wed, 6 Mar 2024 13:47:33 -0500 Subject: [PATCH] CarpetX: Correct fallback conditions for ENO stencils --- CarpetX/src/prolongate_3d_rf2_impl.hxx | 65 +++++++++++--------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/CarpetX/src/prolongate_3d_rf2_impl.hxx b/CarpetX/src/prolongate_3d_rf2_impl.hxx index 5296ea124..49a76c0c8 100644 --- a/CarpetX/src/prolongate_3d_rf2_impl.hxx +++ b/CarpetX/src/prolongate_3d_rf2_impl.hxx @@ -1298,7 +1298,7 @@ void prolongate_3d_rf2()(crse, 0, off[2]); }); + // Check whether we need to fall back bool need_fallback = false; { const std::array sradi = @@ -1352,6 +1360,8 @@ void prolongate_3d_rf2 sradk = interp1d().stencil_radius(shift[2], off[2]); + // Fallback condition 1: The interpolated value introduces a new + // extremum CCTK_REAL minval = +1 / CCTK_REAL(0), maxval = -1 / CCTK_REAL(0); for (int dk = sradk[0]; dk <= sradk[1]; ++dk) { for (int dj = sradj[0]; dj <= sradj[1]; ++dj) { @@ -1366,23 +1376,19 @@ void prolongate_3d_rf2 maxval; - if constexpr (INTPI == CONS) { + // Fallback condition 2 (checked for every direction in + // which the operator is conservative): The slope of the + // values at the stencil points changes sign anywhere in + // the stencil + + if constexpr (INTPI == CONS || INTPI == ENO) { bool need_fallback_i = false; for (int dk = sradk[0]; dk <= sradk[1]; ++dk) { for (int dj = sradj[0]; dj <= sradj[1]; ++dj) { - // using std::signbit; - // const bool s0 = signbit( - // crse(icrse[0] + 1, icrse[1] + dj, icrse[2] + dk) - - // crse(icrse[0] + 0, icrse[1] + dj, icrse[2] + dk)); const CCTK_REAL s0 = crse(icrse[0] + 1, icrse[1] + dj, icrse[2] + dk) - crse(icrse[0] + 0, icrse[1] + dj, icrse[2] + dk); for (int di = sradi[0] + 2; di <= sradi[1]; ++di) { - // const bool s = signbit( - // crse(icrse[0] + di, icrse[1] + dj, icrse[2] + dk) - - // crse(icrse[0] + (di - 1), icrse[1] + dj, - // icrse[2] + dk)); - // need_fallback_i |= s != s0; const CCTK_REAL s = crse(icrse[0] + di, icrse[1] + dj, icrse[2] + dk) - crse(icrse[0] + (di - 1), icrse[1] + dj, @@ -1394,23 +1400,14 @@ void prolongate_3d_rf2