Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some checks on dynamic_casts in gravity #2737

Merged
merged 3 commits into from
Feb 11, 2024
Merged
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
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
Loading