From f1451137f1c25e56444b9a49f7a9de3b73e2ab3f Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 29 Nov 2024 16:46:41 +0100 Subject: [PATCH 1/2] Only initialise data if CHECK --- include/bout/fv_ops.hxx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/bout/fv_ops.hxx b/include/bout/fv_ops.hxx index 464d16117a..eb799bc620 100644 --- a/include/bout/fv_ops.hxx +++ b/include/bout/fv_ops.hxx @@ -83,10 +83,17 @@ Field3D D4DY4_index(const Field3D& f_in, bool bndry_flux = true); */ struct Stencil1D { // Cell centre values +#if CHECK > 0 BoutReal c = BoutNaN, m = BoutNaN, p = BoutNaN, mm = BoutNaN, pp = BoutNaN; // Left and right cell face values BoutReal L = BoutNaN, R = BoutNaN; +#else + BoutReal c, m, p, mm, pp; + + // Left and right cell face values + BoutReal L, R; +#endif }; /*! From 861731664cd05ebcd11c543c85a82a057e094d8e Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 29 Nov 2024 16:47:08 +0100 Subject: [PATCH 2/2] Use ternary expression to avoid initialising with NaN --- include/bout/fv_ops.hxx | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/include/bout/fv_ops.hxx b/include/bout/fv_ops.hxx index eb799bc620..3174c52bdd 100644 --- a/include/bout/fv_ops.hxx +++ b/include/bout/fv_ops.hxx @@ -443,14 +443,12 @@ Field3D Div_f_v(const Field3D& n_in, const Vector3D& v, bool bndry_flux) { if ((i.x() == mesh->xend) && (mesh->lastX())) { // At right boundary in X if (bndry_flux) { - BoutReal flux = BoutNaN; - if (v_R > 0.0) { - // Flux to boundary - flux = v_R * stencil.R; - } else { - // Flux in from boundary - flux = v_R * 0.5 * (n_in[i.xp()] + n_in[i]); - } + const BoutReal flux = v_R > 0.0 ? + // Flux to boundary + v_R * stencil.R + : + // Flux in from boundary + v_R * 0.5 * (n_in[i.xp()] + n_in[i]); result[i] += flux / (coord->dx[i] * coord->J[i]); result[i.xp()] -= flux / (coord->dx[i.xp()] * coord->J[i.xp()]); } @@ -470,14 +468,12 @@ Field3D Div_f_v(const Field3D& n_in, const Vector3D& v, bool bndry_flux) { // At left boundary in X if (bndry_flux) { - BoutReal flux = BoutNaN; - if (v_L < 0.0) { - // Flux to boundary - flux = v_L * stencil.L; - } else { - // Flux in from boundary - flux = v_L * 0.5 * (n_in[i.xm()] + n_in[i]); - } + const BoutReal flux = (v_L < 0.0) ? + // Flux to boundary + v_L * stencil.L + : + // Flux in from boundary + v_L * 0.5 * (n_in[i.xm()] + n_in[i]); result[i] -= flux / (coord->dx[i] * coord->J[i]); result[i.xm()] += flux / (coord->dx[i.xm()] * coord->J[i.xm()]); }