diff --git a/include/bout/interpolation_z.hxx b/include/bout/interpolation_z.hxx index 68cf5b0b06..c2ff03ff59 100644 --- a/include/bout/interpolation_z.hxx +++ b/include/bout/interpolation_z.hxx @@ -35,7 +35,7 @@ protected: public: explicit ZInterpolation(int y_offset = 0, Mesh* mesh = nullptr, - Region region_in = {}); + const Region& region_in = {}); virtual ~ZInterpolation() = default; virtual void calcWeights(const Field3D& delta_z) = 0; diff --git a/src/mesh/interpolation/interpolation_z.cxx b/src/mesh/interpolation/interpolation_z.cxx index 8d39e6baa8..e867eb858c 100644 --- a/src/mesh/interpolation/interpolation_z.cxx +++ b/src/mesh/interpolation/interpolation_z.cxx @@ -23,34 +23,7 @@ #include #include -ZInterpolation::ZInterpolation(int y_offset, Mesh* mesh, Region region_in) - : localmesh(mesh == nullptr ? bout::globals::mesh : mesh), region(region_in), - y_offset(y_offset) { - if (region.size() == 0) { - // Construct region that skips calculating interpolation in y-boundary regions that - // should be filled by boundary conditions - - region = localmesh->getRegion3D("RGN_NOBNDRY"); - - const int ny = localmesh->LocalNy; - const int nz = localmesh->LocalNz; - auto mask_region = Region(0, -1, 0, -1, 0, 0, ny, nz); - if (y_offset > 0) { - for (auto it = localmesh->iterateBndryUpperY(); not it.isDone(); it.next()) { - mask_region += - Region(it.ind, it.ind, localmesh->yend - y_offset + 1, localmesh->yend, - localmesh->zstart, localmesh->zend, ny, nz); - } - } else if (y_offset < 0) { - for (auto it = localmesh->iterateBndryLowerY(); not it.isDone(); it.next()) { - mask_region += Region(it.ind, it.ind, localmesh->ystart, - localmesh->ystart - y_offset - 1, localmesh->zstart, - localmesh->zend, ny, nz); - } - } - - mask_region.unique(); - - region.mask(mask_region); - } -} +ZInterpolation::ZInterpolation(int y_offset, Mesh* mesh, const Region& region_in) + : localmesh(mesh == nullptr ? bout::globals::mesh : mesh), + region(region_in.size() == 0 ? localmesh->getRegion3D("RGN_NOY") : region_in), + y_offset(y_offset) {} diff --git a/tests/unit/fake_mesh.hxx b/tests/unit/fake_mesh.hxx index 7d7326c149..4656ee0282 100644 --- a/tests/unit/fake_mesh.hxx +++ b/tests/unit/fake_mesh.hxx @@ -43,6 +43,9 @@ public: GlobalNx = nx; GlobalNy = ny; GlobalNz = nz; + GlobalNxNoBoundaries = nx - 2; + GlobalNyNoBoundaries = ny - 2; + GlobalNzNoBoundaries = nz; LocalNx = nx; LocalNy = ny; LocalNz = nz; diff --git a/tests/unit/mesh/parallel/test_shiftedmetric.cxx b/tests/unit/mesh/parallel/test_shiftedmetric.cxx index 579e6fdd7b..97775133e5 100644 --- a/tests/unit/mesh/parallel/test_shiftedmetric.cxx +++ b/tests/unit/mesh/parallel/test_shiftedmetric.cxx @@ -314,35 +314,19 @@ TYPED_TEST(ShiftedMetricTest, CalcParallelSlices) { // We don't shift in the guard cells, and the parallel slices are // stored offset in y, therefore we need to make new regions that we // can compare the expected and actual outputs over - - constexpr bool is_shifted_interp = std::is_same_v; - - // ShiftedMetricInterp doesn't seem to store interpolated values in _any_ of the - // guards, so we can only check the interior X point - const int xstart = is_shifted_interp ? mesh->xstart : 0; - const int xend = is_shifted_interp ? mesh->xend : mesh->LocalNx - 1; - - // It also means we can't check in the _y_ guards either. - // TODO(peter): Is this a bug? - const int yup_1_end = is_shifted_interp ? mesh->yend : mesh->yend + 1; - const int yup_2_end = is_shifted_interp ? mesh->yend : mesh->yend + 2; - - const int ydown_1_start = is_shifted_interp ? mesh->ystart : mesh->ystart - 1; - const int ydown_2_start = is_shifted_interp ? mesh->ystart : mesh->ystart - 2; - mesh->addRegion3D("RGN_YUP", - Region(xstart, xend, mesh->ystart + 1, yup_1_end, 0, - mesh->LocalNz - 1, mesh->LocalNy, mesh->LocalNz)); + Region(0, mesh->LocalNx - 1, mesh->ystart + 1, mesh->yend + 1, + 0, mesh->LocalNz - 1, mesh->LocalNy, mesh->LocalNz)); mesh->addRegion3D("RGN_YUP2", - Region(xstart, xend, mesh->ystart + 2, yup_2_end, 0, - mesh->LocalNz - 1, mesh->LocalNy, mesh->LocalNz)); + Region(0, mesh->LocalNx - 1, mesh->ystart + 2, mesh->yend + 2, + 0, mesh->LocalNz - 1, mesh->LocalNy, mesh->LocalNz)); mesh->addRegion3D("RGN_YDOWN", - Region(xstart, xend, ydown_1_start, mesh->yend - 1, 0, - mesh->LocalNz - 1, mesh->LocalNy, mesh->LocalNz)); + Region(0, mesh->LocalNx - 1, mesh->ystart - 1, mesh->yend - 1, + 0, mesh->LocalNz - 1, mesh->LocalNy, mesh->LocalNz)); mesh->addRegion3D("RGN_YDOWN2", - Region(xstart, xend, ydown_2_start, mesh->yend - 2, 0, - mesh->LocalNz - 1, mesh->LocalNy, mesh->LocalNz)); + Region(0, mesh->LocalNx - 1, mesh->ystart - 2, mesh->yend - 2, + 0, mesh->LocalNz - 1, mesh->LocalNy, mesh->LocalNz)); output_info.enable(); // Actual interesting bit here!