Skip to content

Commit

Permalink
Carpet: Improve output when grid functions contain nans
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnett committed Jul 27, 2023
1 parent f238a8f commit 127bf92
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions CarpetX/src/valid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ void check_valid(const GHExt::PatchData::LevelData &leveldata,

struct info_t {
where_t where;
int patch, level, block;
vect<int, dim> I;
vect<CCTK_REAL, dim> X;
CCTK_REAL val;
Expand All @@ -337,38 +338,55 @@ void check_valid(const GHExt::PatchData::LevelData &leveldata,
const Loop::GridDescBaseDevice grid(cctkGH);
const Loop::GF3D2layout layout(cctkGH, groupdata.indextype);
const Loop::GF3D2<const CCTK_REAL> gf(
layout, static_cast<CCTK_REAL *>(CCTK_VarDataPtrI(
layout, static_cast<const CCTK_REAL *>(CCTK_VarDataPtrI(
cctkGH, tl, groupdata.firstvarindex + vi)));
#pragma omp critical(CarpetX_check_valid)
std::cerr << "valid grid=" << grid << "\n";

if (valid.valid_int)
grid.loop_idx(
where_t::interior, groupdata.indextype, groupdata.nghostzones,
[&](const Loop::PointDesc &p) {
if (nan_check(grid, gf, p))
grid.loop_idx(where_t::interior, groupdata.indextype,
groupdata.nghostzones, [&](const Loop::PointDesc &p) {
if (nan_check(grid, gf, p))
#pragma omp critical(CarpetX_check_valid)
infos.push_back(info_t{where_t::interior, p.I, p.X, gf(p.I)});
});
infos.push_back(info_t{where_t::interior, p.patch,
p.level, p.block, p.I, p.X,
gf(p.I)});
});
if (valid.valid_outer)
grid.loop_idx(
where_t::boundary, groupdata.indextype, groupdata.nghostzones,
[&](const Loop::PointDesc &p) {
if (nan_check(grid, gf, p))
grid.loop_idx(where_t::boundary, groupdata.indextype,
groupdata.nghostzones, [&](const Loop::PointDesc &p) {
if (nan_check(grid, gf, p))
#pragma omp critical(CarpetX_check_valid)
infos.push_back(info_t{where_t::interior, p.I, p.X, gf(p.I)});
});
infos.push_back(info_t{where_t::boundary, p.patch,
p.level, p.block, p.I, p.X,
gf(p.I)});
});
if (valid.valid_ghosts)
grid.loop_idx(
where_t::ghosts, groupdata.indextype, groupdata.nghostzones,
[&](const Loop::PointDesc &p) {
if (nan_check(grid, gf, p))
grid.loop_idx(where_t::ghosts, groupdata.indextype,
groupdata.nghostzones, [&](const Loop::PointDesc &p) {
if (nan_check(grid, gf, p))
#pragma omp critical(CarpetX_check_valid)
infos.push_back(info_t{where_t::interior, p.I, p.X, gf(p.I)});
});
infos.push_back(info_t{where_t::ghosts, p.patch,
p.level, p.block, p.I, p.X,
gf(p.I)});
});
});
synchronize();

std::sort(infos.begin(), infos.end(),
[](const info_t &a, const info_t &b) {
if (a.level < b.level)
return true;
if (a.level > b.level)
return false;
if (a.patch < b.patch)
return true;
if (a.patch > b.patch)
return false;
if (a.block < b.block)
return true;
if (a.block > b.block)
return false;
const std::less<vect<int, dim> > lt;
return lt(reversed(a.I), reversed(b.I));
});
Expand All @@ -377,7 +395,9 @@ void check_valid(const GHExt::PatchData::LevelData &leveldata,
buf << setprecision(std::numeric_limits<CCTK_REAL>::digits10 + 1);
for (const auto &info : infos)
buf << "\n"
<< info.where << " " << info.I << " " << info.X << " " << info.val;
<< info.where << " level " << info.level << " patch " << info.patch
<< " block " << info.block << " " << info.I << " " << info.X << " "
<< info.val;
CCTK_WARN(CCTK_WARN_ALERT, buf.str().c_str());

CCTK_VERROR("%s: Grid function \"%s\" contains nans, infinities, or "
Expand Down

0 comments on commit 127bf92

Please sign in to comment.