From 128b8a4a13bea5369be2891d6cc4190e32bf5104 Mon Sep 17 00:00:00 2001 From: James McClung Date: Fri, 11 Apr 2025 11:58:59 -0400 Subject: [PATCH 1/3] test_bnd: rename n_nei --- src/libpsc/tests/test_bnd.cxx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libpsc/tests/test_bnd.cxx b/src/libpsc/tests/test_bnd.cxx index 18eb790ea..d846ea451 100644 --- a/src/libpsc/tests/test_bnd.cxx +++ b/src/libpsc/tests/test_bnd.cxx @@ -264,30 +264,34 @@ TYPED_TEST(BndTest, AddGhosts) { auto&& h_mflds = gt::host_mirror(mflds.storage()); gt::copy(mflds.storage(), h_mflds); + for (int p = 0; p < mflds.n_patches(); p++) { auto flds = make_Fields3d( h_mflds.view(_all, _all, _all, _all, p), -grid.ibn); int j0 = grid.patches[p].off[1]; int k0 = grid.patches[p].off[2]; auto& ldims = grid.ldims; + grid.Foreach_3d(B, B, [&](int i, int j, int k) { - int n_nei = 0; + int n_neighbors = 0; if (i >= 0 && i < ldims[0] && j >= 0 && j < ldims[1] && k >= 0 && k < ldims[2]) { if (!dim::InvarX::value) { if (i < B || i >= ldims[0] - B) - n_nei++; + n_neighbors++; } if (j < B || j >= ldims[1] - B) - n_nei++; + n_neighbors++; if (k < B || k >= ldims[2] - B) - n_nei++; - if (n_nei == 2) - n_nei = 3; // edge -> diagonal contribution, too - else if (n_nei == 3) - n_nei = 11; // corner -> why? FIXME why not 7? + n_neighbors++; + + if (n_neighbors == 2) + n_neighbors = 3; // edge -> diagonal contribution, too + else if (n_neighbors == 3) + n_neighbors = 11; // corner -> why? FIXME why not 7? } - EXPECT_EQ(flds(0, i, j, k), 1 + n_nei) + + EXPECT_EQ(flds(0, i, j, k), 1 + n_neighbors) << "ijk " << i << " " << j << " " << k; }); } From 493c6b99e6215df1603fad5ede9f79c60abcbece Mon Sep 17 00:00:00 2001 From: James McClung Date: Fri, 11 Apr 2025 13:35:56 -0400 Subject: [PATCH 2/3] test_bnd: rm unused vars --- src/libpsc/tests/test_bnd.cxx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libpsc/tests/test_bnd.cxx b/src/libpsc/tests/test_bnd.cxx index d846ea451..7dbc44abd 100644 --- a/src/libpsc/tests/test_bnd.cxx +++ b/src/libpsc/tests/test_bnd.cxx @@ -247,9 +247,7 @@ TYPED_TEST(BndTest, AddGhosts) for (int p = 0; p < mflds.n_patches(); p++) { auto flds = make_Fields3d( h_mflds.view(_all, _all, _all, _all, p), -grid.ibn); - int i0 = grid.patches[p].off[0]; - int j0 = grid.patches[p].off[1]; - int k0 = grid.patches[p].off[2]; + grid.Foreach_3d(B, B, [&](int i, int j, int k) { flds(0, i, j, k) = 1; }); } gt::copy(h_mflds, mflds.storage()); From c927006c7c9adb7639fc308929c8aedcf86ac7bb Mon Sep 17 00:00:00 2001 From: James McClung Date: Fri, 11 Apr 2025 14:00:12 -0400 Subject: [PATCH 3/3] test_bnd: fix/explain why n_neighbors=11 n_neighbors_x was 2, since each cell was getting ghosts from both the lower and upper boundaries --- src/libpsc/tests/test_bnd.cxx | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/libpsc/tests/test_bnd.cxx b/src/libpsc/tests/test_bnd.cxx index 7dbc44abd..a76ac3767 100644 --- a/src/libpsc/tests/test_bnd.cxx +++ b/src/libpsc/tests/test_bnd.cxx @@ -271,24 +271,27 @@ TYPED_TEST(BndTest, AddGhosts) auto& ldims = grid.ldims; grid.Foreach_3d(B, B, [&](int i, int j, int k) { - int n_neighbors = 0; + int n_neighbors_x = 0; + int n_neighbors_y = 0; + int n_neighbors_z = 0; + if (i >= 0 && i < ldims[0] && j >= 0 && j < ldims[1] && k >= 0 && k < ldims[2]) { if (!dim::InvarX::value) { - if (i < B || i >= ldims[0] - B) - n_neighbors++; + n_neighbors_x += i < B; + n_neighbors_x += i >= ldims[0] - B; } - if (j < B || j >= ldims[1] - B) - n_neighbors++; - if (k < B || k >= ldims[2] - B) - n_neighbors++; - - if (n_neighbors == 2) - n_neighbors = 3; // edge -> diagonal contribution, too - else if (n_neighbors == 3) - n_neighbors = 11; // corner -> why? FIXME why not 7? + + n_neighbors_y += j < B; + n_neighbors_y += j >= ldims[1] - B; + + n_neighbors_z += k < B; + n_neighbors_z += k >= ldims[2] - B; } + int n_neighbors = + (n_neighbors_x + 1) * (n_neighbors_y + 1) * (n_neighbors_z + 1) - 1; + EXPECT_EQ(flds(0, i, j, k), 1 + n_neighbors) << "ijk " << i << " " << j << " " << k; });