Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
de449dd
+test_reflective_bcs: copy from psc_shock for now
JamesMcClung Mar 31, 2025
0af729d
test_reflective_bcs: bounce particle off wall
JamesMcClung Mar 31, 2025
a1a0f70
test_reflective_bcs: add slight z velocity
JamesMcClung Apr 3, 2025
62ef352
test_reflective_bcs: bring back full shocks setup that fails
JamesMcClung Apr 3, 2025
f89c88b
test_reflective_bcs: assert err<threshold with gtest
JamesMcClung Apr 3, 2025
d508832
test_reflective_bcs: cleanup
JamesMcClung Apr 3, 2025
b17f487
test_reflective_bcs: simplify while still failing
JamesMcClung Apr 4, 2025
4050d24
test_reflective_bcs: use just 1 particle
JamesMcClung Apr 11, 2025
0666140
fields_item, +add_ghosts: extract add_ghosts_reflecting_hi
JamesMcClung Apr 11, 2025
23ba92f
test_reflective_bcs: don't dump
JamesMcClung Apr 15, 2025
780a39f
checks_impl: -MP template from ChecksCommon
JamesMcClung Apr 15, 2025
9b5e589
test_reflective_bcs: rename test1
JamesMcClung Apr 17, 2025
4ee752f
test_reflective_bcs: add unit tests that fail
JamesMcClung Apr 17, 2025
c7a6874
fields_item, add_ghosts_reflecting: mv lo
JamesMcClung Apr 17, 2025
d2f8123
test_reflective_bcs: some magic numbers
JamesMcClung Apr 17, 2025
577cb56
test_reflective_bcs: inline setup_params
JamesMcClung Apr 17, 2025
ad0c34a
test_reflective_bcs: mv mpi init
JamesMcClung Apr 17, 2025
5bd37a0
test_reflective_bcs: impl AddGhostsReflectingHighY
JamesMcClung Apr 17, 2025
2d2c3ae
add_ghosts_reflecting: fix sign errors in y idx
JamesMcClung Apr 17, 2025
001e20c
add_ghosts_reflecting: scan entire ghost region
JamesMcClung Apr 17, 2025
1b108a5
test_reflective_bcs: impl AddGhostsReflectingHighZ
JamesMcClung Apr 17, 2025
4bfe629
add_ghosts_reflecting: also fix z
JamesMcClung Apr 17, 2025
05ac010
add_ghosts_reflecting: reorder iter
JamesMcClung Apr 17, 2025
e035122
add_ghosts_reflecting: generalize
JamesMcClung Apr 17, 2025
ad03f7d
test_reflective_bcs: +init_mres
JamesMcClung Apr 18, 2025
6fb5105
test_reflective_bcs: impl lo tests
JamesMcClung Apr 18, 2025
2532a67
add_ghosts_reflecting: rewrite lo
JamesMcClung Apr 18, 2025
3ea024c
test_reflective_bcs: ensure particle reflects
JamesMcClung Apr 18, 2025
ce9e67b
test_reflective_bcs: inline run()
JamesMcClung Apr 18, 2025
7fe83af
test_reflective_bcs: condense setup
JamesMcClung Apr 18, 2025
1c9228c
test_reflective_bcs: inj 2 prts
JamesMcClung Apr 29, 2025
deaa8dd
test_reflective_bcs: switch reverse/expects
JamesMcClung Apr 29, 2025
09c14d3
test_reflective_bcs: more asserts
JamesMcClung Apr 29, 2025
86bfabe
test_reflective_bcs: fix weight and kind
JamesMcClung Apr 29, 2025
73cbb1f
test_reflective_bcs: go faster
JamesMcClung Apr 29, 2025
36f7064
add_ghosts_reflecting; *: rename to _cc
JamesMcClung May 1, 2025
1e814c5
add_ghosts_reflecting: +nc stubs
JamesMcClung May 1, 2025
23af57f
test_reflective_bcs: +HighNcY test
JamesMcClung May 1, 2025
c5c0638
add_ghosts_reflecting: fix order
JamesMcClung May 2, 2025
f30cbc4
add_ghosts_reflecting: impl hi_nc
JamesMcClung May 2, 2025
cd039ed
test_reflective_bcs: +LowNcY test
JamesMcClung May 2, 2025
20f7874
add_ghosts_reflecting: impl lo_nc
JamesMcClung May 2, 2025
113c81d
test_reflective_bcs: +NcZ tests
JamesMcClung May 2, 2025
be28d6c
test_reflective_bcs: assert reflection happened
JamesMcClung May 2, 2025
644cc12
fields_item: de-nest ifs
JamesMcClung May 2, 2025
1837788
fields_item:+DomainBoundary
JamesMcClung May 2, 2025
43eb8d4
fields_item: template by Centering
JamesMcClung May 2, 2025
c8fc874
fields_item: impl NC specialization
JamesMcClung May 2, 2025
d877429
fields_item: template ItemMomentBnd by centering
JamesMcClung May 2, 2025
4a3f307
deposit: +DepositCentering to add centering info
JamesMcClung May 2, 2025
edabbdc
deposit: using DepositNorm
JamesMcClung May 2, 2025
9fbd31e
deposit: expose CENTERING in Deposit
JamesMcClung May 2, 2025
40b340b
moment: expose CENTERING
JamesMcClung May 2, 2025
dd1d74d
fields_item: get centering from moment_type
JamesMcClung May 2, 2025
b4fc341
+test_reflective_bcs_integration: try using psc_init
JamesMcClung May 2, 2025
ad22f61
test_reflective_bcs_integration: persist accessor
JamesMcClung May 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions src/include/add_ghosts_reflecting.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#pragma once

#include "../kg/include/kg/Vec3.h"
#include "grid.hxx"

template <typename FE>
void add_ghosts_reflecting_lo_cc(const Int3& ldims, FE& mres_gt, const Int3& ib,
int p, int d, int mb, int me)
{
// FIXME only need to scan 1 cell into the ghost region for 1st-order moments

Int3 idx_begin = ib;
Int3 idx_end = ldims - ib;

idx_begin[d] = 0;
idx_end[d] = -ib[d];

Int3 idx;

for (int m = mb; m < me; m++) {
for (idx[2] = idx_begin[2]; idx[2] < idx_end[2]; idx[2]++) {
for (idx[1] = idx_begin[1]; idx[1] < idx_end[1]; idx[1]++) {
for (idx[0] = idx_begin[0]; idx[0] < idx_end[0]; idx[0]++) {
Int3 idx_reflected = idx;
idx_reflected[d] = -idx[d] - 1;

auto val_reflected =
mres_gt(idx_reflected[0] - ib[0], idx_reflected[1] - ib[1],
idx_reflected[2] - ib[2], m, p);

mres_gt(idx[0] - ib[0], idx[1] - ib[1], idx[2] - ib[2], m, p) +=
val_reflected;
}
}
}
}
}

template <typename FE>
void add_ghosts_reflecting_hi_cc(const Int3& ldims, FE& mres_gt, const Int3& ib,
int p, int d, int mb, int me)
{
// FIXME only need to scan 1 cell into the ghost region for 1st-order moments

Int3 idx_begin = ib;
Int3 idx_end = ldims - ib;

idx_begin[d] = ldims[d] + ib[d];
idx_end[d] = ldims[d];

Int3 idx;

for (int m = mb; m < me; m++) {
for (idx[2] = idx_begin[2]; idx[2] < idx_end[2]; idx[2]++) {
for (idx[1] = idx_begin[1]; idx[1] < idx_end[1]; idx[1]++) {
for (idx[0] = idx_begin[0]; idx[0] < idx_end[0]; idx[0]++) {
Int3 idx_reflected = idx;
idx_reflected[d] = 2 * ldims[d] - idx[d] - 1;

auto val_reflected =
mres_gt(idx_reflected[0] - ib[0], idx_reflected[1] - ib[1],
idx_reflected[2] - ib[2], m, p);

mres_gt(idx[0] - ib[0], idx[1] - ib[1], idx[2] - ib[2], m, p) +=
val_reflected;
}
}
}
}
}

template <typename FE>
void add_ghosts_reflecting_lo_nc(const Int3& ldims, FE& mres_gt, const Int3& ib,
int p, int d, int mb, int me)
{
// When lower boundary has 2 ghosts, upper boundary of nc grid only has 1
// because nc has +1 point compared to cc, and takes it from upper ghost
// region. Thus, ignore a ghost from lower ghost region to balance it out.

Int3 unused_ghost = {!!ib[0], !!ib[1], !!ib[2]};

Int3 idx_begin = ib + unused_ghost;
Int3 idx_end = ldims - ib;

// Also note that the boundary nc point is the point about which reflections
// occur, and isn't itself reflected.

idx_begin[d] = 1;
idx_end[d] = 1 - ib[d] - unused_ghost[d];

Int3 idx;

for (int m = mb; m < me; m++) {
for (idx[2] = idx_begin[2]; idx[2] < idx_end[2]; idx[2]++) {
for (idx[1] = idx_begin[1]; idx[1] < idx_end[1]; idx[1]++) {
for (idx[0] = idx_begin[0]; idx[0] < idx_end[0]; idx[0]++) {
Int3 idx_reflected = idx;
idx_reflected[d] = -idx[d];

auto val_reflected =
mres_gt(idx_reflected[0] - ib[0], idx_reflected[1] - ib[1],
idx_reflected[2] - ib[2], m, p);

mres_gt(idx[0] - ib[0], idx[1] - ib[1], idx[2] - ib[2], m, p) +=
val_reflected;
}
}
}
}
}

template <typename FE>
void add_ghosts_reflecting_hi_nc(const Int3& ldims, FE& mres_gt, const Int3& ib,
int p, int d, int mb, int me)
{
// When lower boundary has 2 ghosts, upper boundary of nc grid only has 1
// because nc has +1 point compared to cc, and takes it from upper ghost
// region. Thus, ignore a ghost from lower ghost region to balance it out.

Int3 unused_ghost = {!!ib[0], !!ib[1], !!ib[2]};

Int3 idx_begin = ib + unused_ghost;
Int3 idx_end = ldims - ib;

// Also note that the extra nc point is the point about which reflections
// occur, and isn't itself reflected.

idx_begin[d] = ldims[d] + ib[d] + unused_ghost[d];
idx_end[d] = ldims[d];

Int3 idx;

for (int m = mb; m < me; m++) {
for (idx[2] = idx_begin[2]; idx[2] < idx_end[2]; idx[2]++) {
for (idx[1] = idx_begin[1]; idx[1] < idx_end[1]; idx[1]++) {
for (idx[0] = idx_begin[0]; idx[0] < idx_end[0]; idx[0]++) {
Int3 idx_reflected = idx;
idx_reflected[d] = 2 * ldims[d] - idx[d];

auto val_reflected =
mres_gt(idx_reflected[0] - ib[0], idx_reflected[1] - ib[1],
idx_reflected[2] - ib[2], m, p);

mres_gt(idx[0] - ib[0], idx[1] - ib[1], idx[2] - ib[2], m, p) +=
val_reflected;
}
}
}
}
}
155 changes: 64 additions & 91 deletions src/include/fields_item.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

#include "../libpsc/psc_bnd/psc_bnd_impl.hxx"
#include "bnd.hxx"
#include "centering.hxx"
#include "fields.hxx"
#include "fields3d.hxx"
#include "particles.hxx"
#include "psc_fields_c.h"
#include "add_ghosts_reflecting.hxx"

#include <mrc_profile.h>

Expand All @@ -32,118 +34,89 @@ inline std::vector<std::string> addKindSuffix(
// ======================================================================
// ItemMomentBnd

template <typename S, typename Bnd>
class ItemMomentBnd
template <centering::Centering C>
class DomainBoundary
{
public:
using storage_type = S;

ItemMomentBnd(const Grid_t& grid) {}

void add_ghosts(const Grid_t& grid, storage_type& mres_gt, const Int3& ib)
{
for (int p = 0; p < mres_gt.shape(4); p++) {
add_ghosts_boundary(grid, mres_gt, ib, p, 0, mres_gt.shape(3));
}

bnd_.add_ghosts(grid, mres_gt, ib, 0, mres_gt.shape(3));
}

private:
// ----------------------------------------------------------------------
// boundary stuff FIXME, should go elsewhere...

template <typename FE>
void add_ghosts_reflecting_lo(const Int3& ldims, FE& mres_gt, const Int3& ib,
int p, int d, int mb, int me)
{
int bx = ldims[0] == 1 ? 0 : 1;
if (d == 1) {
for (int iz = -1; iz < ldims[2] + 1; iz++) {
for (int ix = -bx; ix < ldims[0] + bx; ix++) {
int iy = 0;
{
for (int m = mb; m < me; m++) {
mres_gt(ix - ib[0], iy - ib[1], iz - ib[2], m, p) +=
mres_gt(ix - ib[0], iy - 1 - ib[1], iz - ib[2], m, p);
}
}
}
}
} else if (d == 2) {
for (int iy = 0 * -1; iy < ldims[1] + 0 * 1; iy++) {
for (int ix = -bx; ix < ldims[0] + bx; ix++) {
int iz = 0;
{
for (int m = mb; m < me; m++) {
mres_gt(ix - ib[0], iy - ib[1], iz - ib[2], m, p) +=
mres_gt(ix - ib[0], iy - ib[1], iz - 1 - ib[2], m, p);
}
}
}
}
} else {
assert(0);
}
}
static void add_ghosts_boundary(const Grid_t& grid, FE& mres_gt,
const Int3& ib, int p, int mb, int me);
};

template <>
class DomainBoundary<centering::CC>
{
public:
template <typename FE>
void add_ghosts_reflecting_hi(const Int3& ldims, FE& mres_gt, const Int3& ib,
int p, int d, int mb, int me)
static void add_ghosts_boundary(const Grid_t& grid, FE& mres_gt,
const Int3& ib, int p, int mb, int me)
{
int bx = ldims[0] == 1 ? 0 : 1;
if (d == 1) {
for (int iz = -1; iz < ldims[2] + 1; iz++) {
for (int ix = -bx; ix < ldims[0] + bx; ix++) {
int iy = ldims[1] - 1;
{
for (int m = mb; m < me; m++) {
mres_gt(ix - ib[0], iy - ib[1], iz - ib[2], m, p) +=
mres_gt(ix - ib[0], iy - 1 + ib[1], iz - ib[2], m, p);
}
}
}
// lo
for (int d = 0; d < 3; d++) {
// FIXME why reflect for open BCs?
if (grid.atBoundaryLo(p, d) && (grid.bc.prt_lo[d] == BND_PRT_REFLECTING ||
grid.bc.prt_lo[d] == BND_PRT_OPEN)) {
add_ghosts_reflecting_lo_cc(grid.ldims, mres_gt, ib, p, d, mb, me);
}
} else if (d == 2) {
for (int iy = 0 * -1; iy < ldims[1] + 0 * 1; iy++) {
for (int ix = -bx; ix < ldims[0] + bx; ix++) {
int iz = ldims[2] - 1;
{
for (int m = mb; m < me; m++) {
mres_gt(ix - ib[0], iy - ib[1], iz - ib[2], m, p) +=
mres_gt(ix - ib[0], iy - ib[1], iz + 1 - ib[2], m, p);
}
}
}
}
// hi
for (int d = 0; d < 3; d++) {
// FIXME why reflect for open BCs?
if (grid.atBoundaryHi(p, d) && (grid.bc.prt_hi[d] == BND_PRT_REFLECTING ||
grid.bc.prt_hi[d] == BND_PRT_OPEN)) {
add_ghosts_reflecting_hi_cc(grid.ldims, mres_gt, ib, p, d, mb, me);
}
} else {
assert(0);
}
}
};

template <>
class DomainBoundary<centering::NC>
{
public:
template <typename FE>
void add_ghosts_boundary(const Grid_t& grid, FE& mres_gt, const Int3& ib,
int p, int mb, int me)
static void add_ghosts_boundary(const Grid_t& grid, FE& mres_gt,
const Int3& ib, int p, int mb, int me)
{
// lo
for (int d = 0; d < 3; d++) {
if (grid.atBoundaryLo(p, d)) {
if (grid.bc.prt_lo[d] == BND_PRT_REFLECTING ||
grid.bc.prt_lo[d] == BND_PRT_OPEN) {
add_ghosts_reflecting_lo(grid.ldims, mres_gt, ib, p, d, mb, me);
}
// FIXME why reflect for open BCs?
if (grid.atBoundaryLo(p, d) && (grid.bc.prt_lo[d] == BND_PRT_REFLECTING ||
grid.bc.prt_lo[d] == BND_PRT_OPEN)) {
add_ghosts_reflecting_lo_nc(grid.ldims, mres_gt, ib, p, d, mb, me);
}
}
// hi
for (int d = 0; d < 3; d++) {
if (grid.atBoundaryHi(p, d)) {
if (grid.bc.prt_hi[d] == BND_PRT_REFLECTING ||
grid.bc.prt_hi[d] == BND_PRT_OPEN) {
add_ghosts_reflecting_hi(grid.ldims, mres_gt, ib, p, d, mb, me);
}
// FIXME why reflect for open BCs?
if (grid.atBoundaryHi(p, d) && (grid.bc.prt_hi[d] == BND_PRT_REFLECTING ||
grid.bc.prt_hi[d] == BND_PRT_OPEN)) {
add_ghosts_reflecting_hi_nc(grid.ldims, mres_gt, ib, p, d, mb, me);
}
}
}
};

// ======================================================================
// ItemMomentBnd

template <typename S, typename Bnd, centering::Centering C>
class ItemMomentBnd
{
public:
using storage_type = S;

ItemMomentBnd(const Grid_t& grid) {}

void add_ghosts(const Grid_t& grid, storage_type& mres_gt, const Int3& ib)
{
for (int p = 0; p < mres_gt.shape(4); p++) {
DomainBoundary<C>::add_ghosts_boundary(grid, mres_gt, ib, p, 0,
mres_gt.shape(3));
}

bnd_.add_ghosts(grid, mres_gt, ib, 0, mres_gt.shape(3));
}

private:
Bnd bnd_;
Expand Down Expand Up @@ -189,6 +162,6 @@ public:
}

private:
ItemMomentBnd<storage_type, Bnd> bnd_;
ItemMomentBnd<storage_type, Bnd, moment_type::CENTERING> bnd_;
std::vector<std::string> comp_names_;
};
Loading