From f3882d3f02b984631326427cf82be19be5bdaf13 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 2 Feb 2023 12:42:27 +0100 Subject: [PATCH 1/6] Add some asserts for non parallelised XZ interpolation --- src/mesh/interpolation/bilinear_xz.cxx | 4 ++++ src/mesh/interpolation/hermite_spline_xz.cxx | 4 ++-- src/mesh/interpolation/lagrange_4pt_xz.cxx | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mesh/interpolation/bilinear_xz.cxx b/src/mesh/interpolation/bilinear_xz.cxx index 8445764a8f..4facdac34c 100644 --- a/src/mesh/interpolation/bilinear_xz.cxx +++ b/src/mesh/interpolation/bilinear_xz.cxx @@ -31,6 +31,10 @@ XZBilinear::XZBilinear(int y_offset, Mesh* mesh) : XZInterpolation(y_offset, mesh), w0(localmesh), w1(localmesh), w2(localmesh), w3(localmesh) { + if (localmesh->getNXPE() > 1) { + throw BoutException("Do not support MPI splitting in X"); + } + // Index arrays contain guard cells in order to get subscripts right i_corner.reallocate(localmesh->LocalNx, localmesh->LocalNy, localmesh->LocalNz); k_corner.reallocate(localmesh->LocalNx, localmesh->LocalNy, localmesh->LocalNz); diff --git a/src/mesh/interpolation/hermite_spline_xz.cxx b/src/mesh/interpolation/hermite_spline_xz.cxx index c0040d096e..165d387d66 100644 --- a/src/mesh/interpolation/hermite_spline_xz.cxx +++ b/src/mesh/interpolation/hermite_spline_xz.cxx @@ -101,8 +101,8 @@ class IndConverter { } }; -XZHermiteSpline::XZHermiteSpline(int y_offset, Mesh* mesh) - : XZInterpolation(y_offset, mesh), h00_x(localmesh), h01_x(localmesh), +XZHermiteSpline::XZHermiteSpline(int y_offset, Mesh* meshin) + : XZInterpolation(y_offset, meshin), h00_x(localmesh), h01_x(localmesh), h10_x(localmesh), h11_x(localmesh), h00_z(localmesh), h01_z(localmesh), h10_z(localmesh), h11_z(localmesh) { diff --git a/src/mesh/interpolation/lagrange_4pt_xz.cxx b/src/mesh/interpolation/lagrange_4pt_xz.cxx index 92c14ecfd5..8fa201ba72 100644 --- a/src/mesh/interpolation/lagrange_4pt_xz.cxx +++ b/src/mesh/interpolation/lagrange_4pt_xz.cxx @@ -29,6 +29,10 @@ XZLagrange4pt::XZLagrange4pt(int y_offset, Mesh* mesh) : XZInterpolation(y_offset, mesh), t_x(localmesh), t_z(localmesh) { + if (localmesh->getNXPE() > 1) { + throw BoutException("Do not support MPI splitting in X"); + } + // Index arrays contain guard cells in order to get subscripts right i_corner.reallocate(localmesh->LocalNx, localmesh->LocalNy, localmesh->LocalNz); k_corner.reallocate(localmesh->LocalNx, localmesh->LocalNy, localmesh->LocalNz); From cfe4d40085f21348367b99ab13f674342964c74b Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 9 Aug 2024 11:56:57 +0200 Subject: [PATCH 2/6] Always set region for hermite_spline_xz --- src/mesh/interpolation/hermite_spline_xz.cxx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mesh/interpolation/hermite_spline_xz.cxx b/src/mesh/interpolation/hermite_spline_xz.cxx index 165d387d66..69df6d8906 100644 --- a/src/mesh/interpolation/hermite_spline_xz.cxx +++ b/src/mesh/interpolation/hermite_spline_xz.cxx @@ -346,6 +346,8 @@ Field3D XZHermiteSpline::interpolate(const Field3D& f, const std::string& region ASSERT1(f.getMesh() == localmesh); Field3D f_interp{emptyFrom(f)}; + const auto region2 = fmt::format("RGN_YPAR_{:+d}", y_offset); + #if USE_NEW_WEIGHTS #ifdef HS_USE_PETSC BoutReal* ptr; @@ -355,7 +357,6 @@ Field3D XZHermiteSpline::interpolate(const Field3D& f, const std::string& region VecRestoreArray(rhs, &ptr); MatMult(petscWeights, rhs, result); VecGetArrayRead(result, &cptr); - const auto region2 = y_offset == 0 ? region : fmt::format("RGN_YPAR_{:+d}", y_offset); BOUT_FOR(i, f.getRegion(region2)) { f_interp[i] = cptr[int(i)]; ASSERT2(std::isfinite(cptr[int(i)])); @@ -375,11 +376,10 @@ Field3D XZHermiteSpline::interpolate(const Field3D& f, const std::string& region } } #endif - return f_interp; #else // Derivatives are used for tension and need to be on dimensionless // coordinates - const auto region2 = fmt::format("RGN_YPAR_{:+d}", y_offset); + // f has been communcated, and thus we can assume that the x-boundaries are // also valid in the y-boundary. Thus the differentiated field needs no // extra comms. @@ -418,8 +418,10 @@ Field3D XZHermiteSpline::interpolate(const Field3D& f, const std::string& region ASSERT2(std::isfinite(f_interp[iyp]) || i.x() < localmesh->xstart || i.x() > localmesh->xend); } - return f_interp; #endif + f_interp.setRegion(region2); + ASSERT2(f_interp.getRegionID()); + return f_interp; } Field3D XZHermiteSpline::interpolate(const Field3D& f, const Field3D& delta_x, From 11d0c17abd9579301a4bb455122acf4474ea8457 Mon Sep 17 00:00:00 2001 From: David Bold Date: Mon, 24 Nov 2025 10:35:19 +0100 Subject: [PATCH 3/6] Ensure we only use special name for offsetted regions --- src/mesh/interpolation/hermite_spline_xz.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/interpolation/hermite_spline_xz.cxx b/src/mesh/interpolation/hermite_spline_xz.cxx index 69df6d8906..a5ef9f871d 100644 --- a/src/mesh/interpolation/hermite_spline_xz.cxx +++ b/src/mesh/interpolation/hermite_spline_xz.cxx @@ -346,7 +346,7 @@ Field3D XZHermiteSpline::interpolate(const Field3D& f, const std::string& region ASSERT1(f.getMesh() == localmesh); Field3D f_interp{emptyFrom(f)}; - const auto region2 = fmt::format("RGN_YPAR_{:+d}", y_offset); + const auto region2 = y_offset == 0 ? "RGN_NOY" : fmt::format("RGN_YPAR_{:+d}", y_offset); #if USE_NEW_WEIGHTS #ifdef HS_USE_PETSC From 81fd46189abdd05adfa99631985c84b800824cc4 Mon Sep 17 00:00:00 2001 From: David Bold Date: Mon, 24 Nov 2025 10:36:14 +0100 Subject: [PATCH 4/6] Clarify message --- src/mesh/interpolation/bilinear_xz.cxx | 2 +- src/mesh/interpolation/lagrange_4pt_xz.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mesh/interpolation/bilinear_xz.cxx b/src/mesh/interpolation/bilinear_xz.cxx index 4facdac34c..1ed18a7303 100644 --- a/src/mesh/interpolation/bilinear_xz.cxx +++ b/src/mesh/interpolation/bilinear_xz.cxx @@ -32,7 +32,7 @@ XZBilinear::XZBilinear(int y_offset, Mesh* mesh) w3(localmesh) { if (localmesh->getNXPE() > 1) { - throw BoutException("Do not support MPI splitting in X"); + throw BoutException("XZBilinear interpolation does not support MPI splitting in X"); } // Index arrays contain guard cells in order to get subscripts right diff --git a/src/mesh/interpolation/lagrange_4pt_xz.cxx b/src/mesh/interpolation/lagrange_4pt_xz.cxx index 8fa201ba72..1f6543b019 100644 --- a/src/mesh/interpolation/lagrange_4pt_xz.cxx +++ b/src/mesh/interpolation/lagrange_4pt_xz.cxx @@ -30,7 +30,7 @@ XZLagrange4pt::XZLagrange4pt(int y_offset, Mesh* mesh) : XZInterpolation(y_offset, mesh), t_x(localmesh), t_z(localmesh) { if (localmesh->getNXPE() > 1) { - throw BoutException("Do not support MPI splitting in X"); + throw BoutException("XZLagrange4pt interpolation does not support MPI splitting in X"); } // Index arrays contain guard cells in order to get subscripts right From 34b4f3b82d0957126f90a5365660a7d32317f483 Mon Sep 17 00:00:00 2001 From: dschwoerer <5637662+dschwoerer@users.noreply.github.com> Date: Mon, 24 Nov 2025 09:39:00 +0000 Subject: [PATCH 5/6] Apply clang-format changes --- src/mesh/interpolation/hermite_spline_xz.cxx | 3 ++- src/mesh/interpolation/lagrange_4pt_xz.cxx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mesh/interpolation/hermite_spline_xz.cxx b/src/mesh/interpolation/hermite_spline_xz.cxx index a5ef9f871d..06d5b393a2 100644 --- a/src/mesh/interpolation/hermite_spline_xz.cxx +++ b/src/mesh/interpolation/hermite_spline_xz.cxx @@ -346,7 +346,8 @@ Field3D XZHermiteSpline::interpolate(const Field3D& f, const std::string& region ASSERT1(f.getMesh() == localmesh); Field3D f_interp{emptyFrom(f)}; - const auto region2 = y_offset == 0 ? "RGN_NOY" : fmt::format("RGN_YPAR_{:+d}", y_offset); + const auto region2 = + y_offset == 0 ? "RGN_NOY" : fmt::format("RGN_YPAR_{:+d}", y_offset); #if USE_NEW_WEIGHTS #ifdef HS_USE_PETSC diff --git a/src/mesh/interpolation/lagrange_4pt_xz.cxx b/src/mesh/interpolation/lagrange_4pt_xz.cxx index 1f6543b019..e16b2699d1 100644 --- a/src/mesh/interpolation/lagrange_4pt_xz.cxx +++ b/src/mesh/interpolation/lagrange_4pt_xz.cxx @@ -30,7 +30,8 @@ XZLagrange4pt::XZLagrange4pt(int y_offset, Mesh* mesh) : XZInterpolation(y_offset, mesh), t_x(localmesh), t_z(localmesh) { if (localmesh->getNXPE() > 1) { - throw BoutException("XZLagrange4pt interpolation does not support MPI splitting in X"); + throw BoutException( + "XZLagrange4pt interpolation does not support MPI splitting in X"); } // Index arrays contain guard cells in order to get subscripts right From 49028fe22d59f7b13c215631e82f1b6b183eaf1c Mon Sep 17 00:00:00 2001 From: David Bold Date: Mon, 24 Nov 2025 12:08:04 +0100 Subject: [PATCH 6/6] Add doc strings --- include/bout/interpolation_xz.hxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/bout/interpolation_xz.hxx b/include/bout/interpolation_xz.hxx index def8a60a3e..6c7419f7e4 100644 --- a/include/bout/interpolation_xz.hxx +++ b/include/bout/interpolation_xz.hxx @@ -238,6 +238,9 @@ public: const std::string& region = "RGN_NOBNDRY") const override; }; +/// XZLagrange4pt interpolation class +/// +/// Does not support MPI splitting in X class XZLagrange4pt : public XZInterpolation { Tensor i_corner; // x-index of bottom-left grid point Tensor k_corner; // z-index of bottom-left grid point @@ -271,6 +274,9 @@ public: BoutReal lagrange_4pt(const BoutReal v[], BoutReal offset) const; }; +/// XZBilinear interpolation calss +/// +/// Does not support MPI splitting in X. class XZBilinear : public XZInterpolation { Tensor i_corner; // x-index of bottom-left grid point Tensor k_corner; // z-index of bottom-left grid point