Skip to content

Commit

Permalink
Fix a new bug introduced in AMReX-Codes#2858 (AMReX-Codes#2901)
Browse files Browse the repository at this point in the history
We need to take into account that `amrex::Any` stores `MultiFab&` or `MultiFab const&`.
  • Loading branch information
WeiqunZhang authored Aug 3, 2022
1 parent 6eaab8c commit 9ed4f59
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions Src/Base/AMReX_Any.H
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,25 @@ public:

//! Returns a reference to the contained object.
template <typename MF>
MF& get () { return dynamic_cast<innards<MF>&>(*m_ptr).m_mf; }
MF& get () {
if (auto p0 = dynamic_cast<innards<MF>*>(m_ptr.get())) {
return p0->m_mf;
} else {
return dynamic_cast<innards<MF&>&>(*m_ptr).m_mf;
}
}

//! Returns a const reference to the contained object.
template <typename MF>
MF const& get () const { return dynamic_cast<innards<MF> const&>(*m_ptr).m_mf; }
MF const& get () const {
if (auto p0 = dynamic_cast<innards<MF>*>(m_ptr.get())) {
return p0->m_mf;
} else if (auto p1 = dynamic_cast<innards<MF&>*>(m_ptr.get())) {
return p1->m_mf;
} else {
return dynamic_cast<innards<MF const&> const&>(*m_ptr).m_mf;
}
}

template <typename MF>
bool is () const { return m_ptr->Type() == typeid(MF); }
Expand Down
2 changes: 1 addition & 1 deletion Src/LinearSolvers/MLMG/AMReX_MLMG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ MLMG::compResidual (const Vector<MultiFab*>& a_res, const Vector<MultiFab*>& a_s
{
if (cf_strategy == CFStrategy::ghostnodes || a_sol[alev]->nGrowVect() == ng_sol)
{
sol[alev] = linop.AnyMakeAlias(a_sol[alev]);
sol[alev] = linop.AnyMakeAlias(*a_sol[alev]);
sol_is_alias[alev] = true;
}
else
Expand Down

0 comments on commit 9ed4f59

Please sign in to comment.