Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop: Check for symmetry boundaries in outermost interior loops #300

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
10 changes: 7 additions & 3 deletions Loop/src/loop.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ public:
template <int CI, int CJ, int CK, int VS = 1, int N = 1, typename F>
inline CCTK_ATTRIBUTE_ALWAYS_INLINE void
loop_outermost_int(const vect<int, dim> &group_nghostzones,
const vect<vect<bool, dim>, 2> &is_sym_bnd,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd document what is_sym_bnd[f][d] stands for. Does this order (f then d) match what is used eg in cctk_bbox (see https://www.einsteintoolkit.org/usersguide/UsersGuide.html#x1-98000C1.6.2). Looking at the Cactus example it does seem to be different since the Cactus code uses:

An array of 2cctk_dim integers (in the order [dim_0^{min}, dim_0^{max}, dim_1^{min}, dim_1^{max}, ... ]), ...

Copy link
Contributor Author

@chcheng3 chcheng3 Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is_sym_bnd array follows the layout of the symmetry array from driver.hxx, which seems to be arranged in a different order from what Cactus does:

std::array<std::array<symmetry_t, dim>, 2> symmetries;

So the patch here is consistent with CarpetX, but not Cactus, which might be confusing.

const F &f) const {
// boundary_box sets bnd_min and bnd_max
vect<int, dim> bnd_min, bnd_max;
Expand Down Expand Up @@ -595,9 +596,12 @@ public:
// True when point is on left/right boundary,
// and vector is not parallel to a {face,corner,edge}
// In either of the 3 directions
if ((ni != 0 && bbox[ni < 0 ? 0 : 1][0]) ||
(nj != 0 && bbox[nj < 0 ? 0 : 1][1]) ||
(nk != 0 && bbox[nk < 0 ? 0 : 1][2])) {
if ((ni != 0 && bbox[ni < 0 ? 0 : 1][0] &&
!is_sym_bnd[ni < 0 ? 0 : 1][0]) ||
(nj != 0 && bbox[nj < 0 ? 0 : 1][1] &&
!is_sym_bnd[nj < 0 ? 0 : 1][1]) ||
(nk != 0 && bbox[nk < 0 ? 0 : 1][2] &&
!is_sym_bnd[nk < 0 ? 0 : 1][2])) {

const vect<int, dim> inormal{ni, nj, nk}; // normal vector

Expand Down
10 changes: 7 additions & 3 deletions Loop/src/loop_device.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public:
int NT = AMREX_GPU_MAX_THREADS, typename F>
inline CCTK_ATTRIBUTE_ALWAYS_INLINE void
loop_outermost_int_device(const vect<int, dim> &group_nghostzones,
const vect<vect<bool, dim>, 2> &is_sym_bnd,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above.

const F &f) const {
// boundary_box sets bnd_min and bnd_max
vect<int, dim> bnd_min, bnd_max;
Expand Down Expand Up @@ -329,9 +330,12 @@ public:
// True when point is on left/right boundary,
// and vector is not parallel to a {face,corner,edge}
// In either of the 3 directions
if ((ni != 0 && bbox[ni < 0 ? 0 : 1][0]) ||
(nj != 0 && bbox[nj < 0 ? 0 : 1][1]) ||
(nk != 0 && bbox[nk < 0 ? 0 : 1][2])) {
if ((ni != 0 && bbox[ni < 0 ? 0 : 1][0] &&
!is_sym_bnd[ni < 0 ? 0 : 1][0]) ||
(nj != 0 && bbox[nj < 0 ? 0 : 1][1] &&
!is_sym_bnd[nj < 0 ? 0 : 1][1]) ||
(nk != 0 && bbox[nk < 0 ? 0 : 1][2] &&
!is_sym_bnd[nk < 0 ? 0 : 1][2])) {

const vect<int, dim> inormal{ni, nj, nk}; // normal vector

Expand Down
18 changes: 16 additions & 2 deletions TestLoopX/src/testloop.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cctk.h>
#include "CarpetX/CarpetX/src/driver.hxx"
lucass-carneiro marked this conversation as resolved.
Show resolved Hide resolved
#include <cctk_Arguments.h>
#include <cctk_Parameters.h>
#include <loop.hxx>
Expand Down Expand Up @@ -27,15 +28,28 @@ extern "C" void TestLoopX_OutermostInterior(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTSX_TestLoopX_OutermostInterior;
DECLARE_CCTK_PARAMETERS;

const auto symmetries = CarpetX::ghext->patchdata.at(cctk_patch).symmetries;
const vect<vect<bool, Loop::dim>, 2> is_sym_bnd {
{
symmetries[0][0] != CarpetX::symmetry_t::none,
symmetries[0][1] != CarpetX::symmetry_t::none,
symmetries[0][2] != CarpetX::symmetry_t::none
},
{
symmetries[1][0] != CarpetX::symmetry_t::none,
symmetries[1][1] != CarpetX::symmetry_t::none,
symmetries[1][2] != CarpetX::symmetry_t::none
}
};
grid.loop_outermost_int<0, 0, 0>(
grid.nghostzones,
grid.nghostzones, is_sym_bnd,
[=] CCTK_DEVICE CCTK_HOST(const PointDesc &p)
CCTK_ATTRIBUTE_ALWAYS_INLINE {
testloop_gf(p.I) += 10.0;
});

grid.loop_outermost_int_device<0, 0, 0>(
grid.nghostzones,
grid.nghostzones, is_sym_bnd,
[=] CCTK_DEVICE CCTK_HOST(const PointDesc &p)
CCTK_ATTRIBUTE_ALWAYS_INLINE {
testloop_gf(p.I) += 1.0;
Expand Down