From 9ed4f5955b1d5d0e400fd2f233e5e7b83db4e41b Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Wed, 3 Aug 2022 16:53:20 -0700 Subject: [PATCH] Fix a new bug introduced in #2858 (#2901) We need to take into account that `amrex::Any` stores `MultiFab&` or `MultiFab const&`. --- Src/Base/AMReX_Any.H | 18 ++++++++++++++++-- Src/LinearSolvers/MLMG/AMReX_MLMG.cpp | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Src/Base/AMReX_Any.H b/Src/Base/AMReX_Any.H index 31c824825a4..2c7d9688d36 100644 --- a/Src/Base/AMReX_Any.H +++ b/Src/Base/AMReX_Any.H @@ -48,11 +48,25 @@ public: //! Returns a reference to the contained object. template - MF& get () { return dynamic_cast&>(*m_ptr).m_mf; } + MF& get () { + if (auto p0 = dynamic_cast*>(m_ptr.get())) { + return p0->m_mf; + } else { + return dynamic_cast&>(*m_ptr).m_mf; + } + } //! Returns a const reference to the contained object. template - MF const& get () const { return dynamic_cast const&>(*m_ptr).m_mf; } + MF const& get () const { + if (auto p0 = dynamic_cast*>(m_ptr.get())) { + return p0->m_mf; + } else if (auto p1 = dynamic_cast*>(m_ptr.get())) { + return p1->m_mf; + } else { + return dynamic_cast const&>(*m_ptr).m_mf; + } + } template bool is () const { return m_ptr->Type() == typeid(MF); } diff --git a/Src/LinearSolvers/MLMG/AMReX_MLMG.cpp b/Src/LinearSolvers/MLMG/AMReX_MLMG.cpp index a1e897e85ba..0e1762ae3fb 100644 --- a/Src/LinearSolvers/MLMG/AMReX_MLMG.cpp +++ b/Src/LinearSolvers/MLMG/AMReX_MLMG.cpp @@ -1152,7 +1152,7 @@ MLMG::compResidual (const Vector& a_res, const Vector& 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