Skip to content

Commit

Permalink
fix a bug in norm2 where there are overlaps (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Jun 6, 2020
1 parent f52f7be commit 70afa5a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Src/Base/AMReX_MultiFab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,15 +1045,23 @@ MultiFab::norm2 (int comp) const
Real
MultiFab::norm2 (int comp, const Periodicity& period) const
{
MultiFab tmpmf(boxArray(), DistributionMap(), 1, 0, MFInfo(), Factory());
MultiFab::Copy(tmpmf, *this, comp, 0, 1, 0);

auto mask = OverlapMask(period);
MultiFab::Divide(tmpmf, *mask, 0, 0, 1, 0);

Real nm2 = MultiFab::Dot(*this, comp, tmpmf, 0, 1, 0);
nm2 = std::sqrt(nm2);
return nm2;
Real nm2 = amrex::ReduceSum(*this, *mask, 0,
[=] AMREX_GPU_HOST_DEVICE (Box const& bx, Array4<Real const> const& xfab,
Array4<Real const> const& mfab) -> Real
{
Real r = 0.0;
AMREX_LOOP_3D(bx, i, j, k,
{
Real tmp = xfab(i,j,k,comp);
r += tmp*tmp/mfab(i,j,k);
});
return r;
});

ParallelAllReduce::Sum(nm2, ParallelContext::CommunicatorSub());
return std::sqrt(nm2);
}

Vector<Real>
Expand Down

0 comments on commit 70afa5a

Please sign in to comment.