From 0baa3f6abb85264c81c98704a2c8b2a07b0f3ec5 Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 11 Aug 2023 17:01:51 +0200 Subject: [PATCH 1/2] Add .zpm for sign-independent coding --- include/bout/region.hxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/bout/region.hxx b/include/bout/region.hxx index 5e2eb9c1a2..0775e6b368 100644 --- a/include/bout/region.hxx +++ b/include/bout/region.hxx @@ -308,6 +308,10 @@ struct SpecificInd { ASSERT3(dz >= 0); return {(ind) % nz < dz ? ind + nz - dz : ind - dz, ny, nz}; } + /// Automatically select zm or zp depending on sign + inline SpecificInd zpm(int dz) const { + return dz > 0? zp(dz) : zm(-dz); + } // and for 2 cells inline SpecificInd xpp() const { return xp(2); } @@ -319,8 +323,7 @@ struct SpecificInd { /// Generic offset of \p index in multiple directions simultaneously inline SpecificInd offset(int dx, int dy, int dz) const { - auto temp = (dz > 0) ? zp(dz) : zm(-dz); - return temp.yp(dy).xp(dx); + return zpm(dz).yp(dy).xp(dx); } }; From ad06d97d23c9baadb506d870ffe6fa6a54c248fb Mon Sep 17 00:00:00 2001 From: dschwoerer Date: Tue, 19 Mar 2024 15:39:50 +0000 Subject: [PATCH 2/2] Apply clang-format changes --- include/bout/region.hxx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/bout/region.hxx b/include/bout/region.hxx index 0775e6b368..68810324e3 100644 --- a/include/bout/region.hxx +++ b/include/bout/region.hxx @@ -309,9 +309,7 @@ struct SpecificInd { return {(ind) % nz < dz ? ind + nz - dz : ind - dz, ny, nz}; } /// Automatically select zm or zp depending on sign - inline SpecificInd zpm(int dz) const { - return dz > 0? zp(dz) : zm(-dz); - } + inline SpecificInd zpm(int dz) const { return dz > 0 ? zp(dz) : zm(-dz); } // and for 2 cells inline SpecificInd xpp() const { return xp(2); }