Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/include/checks_params.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct CheckParams
double err_threshold = 1e-13; // maximum acceptable error
bool print_max_err_always = true; // always print error, even if acceptable
bool dump_always = false; // always dump compared fields, even if acceptable
bool exit_on_failure = false; // exit the program if check fails

bool enabled() { return check_interval > 0; }

Expand Down
57 changes: 13 additions & 44 deletions src/include/fields_item.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,68 +34,38 @@ inline std::vector<std::string> addKindSuffix(
// ======================================================================
// ItemMomentBnd

template <centering::Centering C>
class DomainBoundary
template <typename FE>
void maybe_add_ghosts_boundary(const Grid_t& grid, FE& mres_gt, const Int3& ib,
int p, int mb, int me, centering::Centering c)
{
public:
template <typename FE>
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>
static void add_ghosts_boundary(const Grid_t& grid, FE& mres_gt,
const Int3& ib, int p, int mb, int me)
{
if (c == centering::CC) {
// 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)) {
if (grid.atBoundaryLo(p, d) && grid.bc.prt_lo[d] == BND_PRT_REFLECTING) {
add_ghosts_reflecting_lo_cc(grid.ldims, mres_gt, ib, p, d, mb, me);
}
}
// 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)) {
if (grid.atBoundaryHi(p, d) && grid.bc.prt_hi[d] == BND_PRT_REFLECTING) {
add_ghosts_reflecting_hi_cc(grid.ldims, mres_gt, ib, p, d, mb, me);
}
}
}
};

template <>
class DomainBoundary<centering::NC>
{
public:
template <typename FE>
static void add_ghosts_boundary(const Grid_t& grid, FE& mres_gt,
const Int3& ib, int p, int mb, int me)
{
} else if (c == centering::NC) {
// 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)) {
if (grid.atBoundaryLo(p, d) && grid.bc.prt_lo[d] == BND_PRT_REFLECTING) {
add_ghosts_reflecting_lo_nc(grid.ldims, mres_gt, ib, p, d, mb, me);
}
}
// 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)) {
if (grid.atBoundaryHi(p, d) && grid.bc.prt_hi[d] == BND_PRT_REFLECTING) {
add_ghosts_reflecting_hi_nc(grid.ldims, mres_gt, ib, p, d, mb, me);
}
}
}
};
}

// ======================================================================
// ItemMomentBnd
Expand All @@ -111,8 +81,7 @@ public:
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));
maybe_add_ghosts_boundary(grid, mres_gt, ib, p, 0, mres_gt.shape(3), C);
}

bnd_.add_ghosts(grid, mres_gt, ib, 0, mres_gt.shape(3));
Expand Down Expand Up @@ -152,8 +121,8 @@ public:
{
Int3 ib = -mprts.grid().ibn;
// FIXME, gt::gtensor and psc::gtensor are slightly different, and ideally
// zeros() shouldn't actually allocate, but probably it does, so this wastes
// memory and a copy
// zeros() shouldn't actually allocate, but probably it does, so this
// wastes memory and a copy
storage_type mres =
psc::mflds::zeros<value_type, space_type>(mprts.grid(), n_comps(), ib);
moment_type{}(mres, ib, mprts);
Expand Down
92 changes: 46 additions & 46 deletions src/libpsc/psc_bnd_fields/psc_bnd_fields_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ struct BndFields_ : BndFieldsBase
if (d == 1) {
#ifdef DEBUG
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
fields_t_set_nan(&F(EX, ix, -1, iz));
fields_t_set_nan(&F(EX, ix, -2, iz));
fields_t_set_nan(&F(EY, ix, -1, iz));
Expand All @@ -158,8 +158,8 @@ struct BndFields_ : BndFieldsBase
#endif
for (int iz = -2; iz < ldims[2] + 2; iz++) {
// FIXME, needs to be for other dir, too, and it's ugly
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(EX, ix, 0, iz) = 0.;
F(EX, ix, -1, iz) = F(EX, ix, 1, iz);

Expand All @@ -183,8 +183,8 @@ struct BndFields_ : BndFieldsBase
}
#endif
for (int iy = -2; iy < ldims[1] + 2; iy++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(EX, ix, iy, 0) = 0.;
F(EX, ix, iy, -1) = F(EX, ix, iy, 1);

Expand All @@ -209,8 +209,8 @@ struct BndFields_ : BndFieldsBase
int my _mrc_unused = ldims[1];
#ifdef DEBUG
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
fields_t_set_nan(&F(EX, ix, my, iz));
fields_t_set_nan(&F(EX, ix, my + 1, iz));
fields_t_set_nan(&F(EY, ix, my, iz));
Expand All @@ -221,8 +221,8 @@ struct BndFields_ : BndFieldsBase
}
#endif
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(EX, ix, my, iz) = 0.;
F(EX, ix, my + 1, iz) = F(EX, ix, my - 1, iz);

Expand All @@ -247,8 +247,8 @@ struct BndFields_ : BndFieldsBase
}
#endif
for (int iy = -2; iy < ldims[1] + 2; iy++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(EX, ix, iy, mz) = 0.;
F(EX, ix, iy, mz + 1) = F(EX, ix, iy, mz - 1);

Expand All @@ -272,8 +272,8 @@ struct BndFields_ : BndFieldsBase
if (d == 1) {
#ifdef DEBUG
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
fields_t_set_nan(&F(HX, ix, -1, iz));
fields_t_set_nan(&F(HX, ix, -2, iz));
fields_t_set_nan(&F(HY, ix, -1, iz));
Expand All @@ -284,8 +284,8 @@ struct BndFields_ : BndFieldsBase
}
#endif
for (int iz = -1; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(HX, ix, -1, iz) = -F(HX, ix, 0, iz);

F(HY, ix, -1, iz) = F(HY, ix, 1, iz);
Expand All @@ -307,8 +307,8 @@ struct BndFields_ : BndFieldsBase
}
#endif
for (int iy = -2; iy < ldims[1] + 2; iy++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(HX, ix, iy, -1) = -F(HX, ix, iy, 0);

F(HY, ix, iy, -1) = -F(HY, ix, iy, 0);
Expand All @@ -332,8 +332,8 @@ struct BndFields_ : BndFieldsBase
int my _mrc_unused = ldims[1];
#ifdef DEBUG
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
fields_t_set_nan(&F(HX, ix, my, iz));
fields_t_set_nan(&F(HX, ix, my + 1, iz));
fields_t_set_nan(&F(HY, ix, my + 1, iz));
Expand All @@ -343,8 +343,8 @@ struct BndFields_ : BndFieldsBase
}
#endif
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(HX, ix, my, iz) = -F(HX, ix, my - 1, iz);

F(HY, ix, my + 1, iz) = F(HY, ix, my - 1, iz);
Expand All @@ -366,8 +366,8 @@ struct BndFields_ : BndFieldsBase
}
#endif
for (int iy = -2; iy < ldims[1] + 2; iy++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(HX, ix, iy, mz) = -F(HX, ix, iy, mz - 1);

F(HY, ix, iy, mz) = -F(HY, ix, iy, mz - 1);
Expand All @@ -388,8 +388,8 @@ struct BndFields_ : BndFieldsBase

if (d == 1) {
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(JXI, ix, 1, iz) += F(JXI, ix, -1, iz);
F(JXI, ix, -1, iz) = 0.;

Expand All @@ -402,8 +402,8 @@ struct BndFields_ : BndFieldsBase
}
} else if (d == 2) {
for (int iy = -2; iy < ldims[1] + 2; iy++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(JXI, ix, iy, 1) += F(JXI, ix, iy, -1);
F(JXI, ix, iy, -1) = 0.;

Expand All @@ -428,8 +428,8 @@ struct BndFields_ : BndFieldsBase
if (d == 1) {
int my _mrc_unused = ldims[1];
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(JXI, ix, my - 1, iz) += F(JXI, ix, my + 1, iz);
F(JXI, ix, my + 1, iz) = 0.;

Expand All @@ -443,8 +443,8 @@ struct BndFields_ : BndFieldsBase
} else if (d == 2) {
int mz = ldims[2];
for (int iy = -2; iy < ldims[1] + 2; iy++) {
for (int ix = MAX(-2, ib[0]); ix < MIN(ldims[0] + 2, ib[0] + im[0]);
ix++) {
for (int ix = std::max(-2, ib[0]);
ix < std::min(ldims[0] + 2, ib[0] + im[0]); ix++) {
F(JXI, ix, iy, mz - 1) += F(JXI, ix, iy, mz + 1);
F(JXI, ix, iy, mz + 1) = 0.;

Expand Down Expand Up @@ -479,8 +479,8 @@ struct BndFields_ : BndFieldsBase
if (d == 1) {
#ifdef DEBUG
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
fields_t_set_nan(&F(HX, ix, -1, iz));
fields_t_set_nan(&F(HX, ix, -2, iz));
fields_t_set_nan(&F(HY, ix, -1, iz));
Expand All @@ -493,8 +493,8 @@ struct BndFields_ : BndFieldsBase
real_t dt = F.grid().dt, dy = F.grid().domain.dx[1],
dz = F.grid().domain.dx[2];
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
F(HX, ix, -1, iz) =
(/* + 4.f * C_s_pulse_y1(x,y,z+0.5*dz,t) */
-2.f * F(EZ, ix, 0, iz)
Expand All @@ -512,8 +512,8 @@ struct BndFields_ : BndFieldsBase
} else if (d == 2) {
#ifdef DEBUG
for (int iy = -2; iy < ldims[1] + 2; iy++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
fields_t_set_nan(&F(HX, ix, iy, -1));
fields_t_set_nan(&F(HX, ix, iy, -2));
fields_t_set_nan(&F(HY, ix, iy, -1));
Expand All @@ -526,8 +526,8 @@ struct BndFields_ : BndFieldsBase
real_t dt = F.grid().dt, dy = F.grid().domain.dx[1],
dz = F.grid().domain.dx[2];
for (int iy = -2; iy < ldims[1] + 2; iy++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
F(HY, ix, iy, -1) =
(/* + 4.f * C_s_pulse_z1(x+0.5*dx,y,z,t) */
-2.f * F(EX, ix, iy, 0) -
Expand Down Expand Up @@ -562,8 +562,8 @@ struct BndFields_ : BndFieldsBase
int my _mrc_unused = ldims[1];
#ifdef DEBUG
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
fields_t_set_nan(&F(HX, ix, my, iz));
fields_t_set_nan(&F(HX, ix, my + 1, iz));
fields_t_set_nan(&F(HY, ix, my, iz));
Expand All @@ -575,8 +575,8 @@ struct BndFields_ : BndFieldsBase
real_t dt = F.grid().dt, dy = F.grid().domain.dx[1],
dz = F.grid().domain.dx[2];
for (int iz = -2; iz < ldims[2] + 2; iz++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
F(HX, ix, my, iz) =
(/* + 4.f * C_s_pulse_y2(x,y,z+0.5*dz,t) */
+2.f * F(EZ, ix, my, iz)
Expand Down Expand Up @@ -609,8 +609,8 @@ struct BndFields_ : BndFieldsBase
real_t dt = F.grid().dt, dy = F.grid().domain.dx[1],
dz = F.grid().domain.dx[2];
for (int iy = -2; iy < ldims[1] + 2; iy++) {
for (int ix = MAX(-2, F.ib_[0]);
ix < MIN(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
for (int ix = std::max(-2, F.ib_[0]);
ix < std::min(ldims[0] + 2, F.ib_[0] + F.im_[0]); ix++) {
F(HY, ix, iy, mz) =
(/* - 4.f * C_s_pulse_z2(x+0.5*dx,y,z,t) */
+2.f * F(EX, ix, iy, mz) +
Expand Down
Loading