Skip to content

Commit

Permalink
add some checks on dynamic_casts in gravity (#2737)
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale authored Feb 11, 2024
1 parent 8d4459f commit 9bbf9dc
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Source/gravity/Gravity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1844,8 +1844,13 @@ Gravity::fill_multipole_BCs(int crse_level, int fine_level, const Vector<MultiFa
MultiFab::Copy(source, *Rhs[lev - crse_level], 0, 0, 1, 0);

if (lev < fine_level) {
const MultiFab& mask = dynamic_cast<Castro*>(&(parent->getLevel(lev+1)))->build_fine_mask();
MultiFab::Multiply(source, mask, 0, 0, 1, 0);
auto *castro_level = dynamic_cast<Castro*>(&(parent->getLevel(lev+1)));
if (castro_level != nullptr) {
const MultiFab& mask = castro_level->build_fine_mask();
MultiFab::Multiply(source, mask, 0, 0, 1, 0);
} else {
amrex::Abort("unable to access mask");
}
}

// Loop through the grids and compute the individual contributions
Expand Down Expand Up @@ -2968,7 +2973,11 @@ Gravity::set_mass_offset (Real time, bool multi_level)
{
for (int lev = 0; lev <= parent->finestLevel(); lev++) {
auto* cs = dynamic_cast<Castro*>(&parent->getLevel(lev));
mass_offset += cs->volWgtSum("density", time);
if (cs != nullptr) {
mass_offset += cs->volWgtSum("density", time);
} else {
amrex::Abort("unable to access volWgtSum");
}
}
}
else
Expand Down Expand Up @@ -3132,9 +3141,13 @@ Gravity::make_radial_gravity(int level, Real time, RealVector& radial_grav)
if (lev < level)
{
auto* fine_level = dynamic_cast<Castro*>(&(parent->getLevel(lev+1)));
const MultiFab& mask = fine_level->build_fine_mask();
for (int n = 0; n < NUM_STATE; ++n) {
MultiFab::Multiply(S, mask, 0, n, 1, 0);
if (fine_level != nullptr) {
const MultiFab& mask = fine_level->build_fine_mask();
for (int n = 0; n < NUM_STATE; ++n) {
MultiFab::Multiply(S, mask, 0, n, 1, 0);
}
} else {
amrex::Abort("unable to create mask");
}
}

Expand Down

0 comments on commit 9bbf9dc

Please sign in to comment.