Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/AMReX-Codes/amrex in…
Browse files Browse the repository at this point in the history
…to comments-fab
  • Loading branch information
eebasso committed Nov 17, 2023
2 parents 7de490d + 175b99d commit 0858ecb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
11 changes: 5 additions & 6 deletions Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
MF sorig = Lp.make(amrlev, mglev, nghost);
MF p = Lp.make(amrlev, mglev, nghost);
MF r = Lp.make(amrlev, mglev, nghost);
MF s = Lp.make(amrlev, mglev, nghost);
MF rh = Lp.make(amrlev, mglev, nghost);
MF v = Lp.make(amrlev, mglev, nghost);
MF t = Lp.make(amrlev, mglev, nghost);
Expand Down Expand Up @@ -166,9 +165,9 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
ret = 2; break;
}
MF::Saxpy(sol, alpha, ph, 0, 0, ncomp, nghost); // sol += alpha * ph
MF::LinComb(s, RT(1.0), r, 0, -alpha, v, 0, 0, ncomp, nghost); // s = r - alpha * v
MF::Saxpy(r, -alpha, v, 0, 0, ncomp, nghost); // r += -alpha * v

rnorm = norm_inf(s);
rnorm = norm_inf(r);

if ( verbose > 2 && ParallelDescriptor::IOProcessor() )
{
Expand All @@ -180,15 +179,15 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)

if ( rnorm < eps_rel*rnorm0 || rnorm < eps_abs ) { break; }

sh.LocalCopy(s,0,0,ncomp,nghost);
sh.LocalCopy(r,0,0,ncomp,nghost);
Lp.apply(amrlev, mglev, t, sh, MLLinOpT<MF>::BCMode::Homogeneous, MLLinOpT<MF>::StateMode::Correction);
Lp.normalize(amrlev, mglev, t);
//
// This is a little funky. I want to elide one of the reductions
// in the following two dotxy()s. We do that by calculating the "local"
// values and then reducing the two local values at the same time.
//
RT tvals[2] = { dotxy(t,t,true), dotxy(t,s,true) };
RT tvals[2] = { dotxy(t,t,true), dotxy(t,r,true) };

BL_PROFILE_VAR("MLCGSolver::ParallelAllReduce", blp_par);
ParallelAllReduce::Sum(tvals,2,Lp.BottomCommunicator());
Expand All @@ -203,7 +202,7 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
ret = 3; break;
}
MF::Saxpy(sol, omega, sh, 0, 0, ncomp, nghost); // sol += omega * sh
MF::LinComb(r, RT(1.0), s, 0, -omega, t, 0, 0, ncomp, nghost); // r = s - omega * t
MF::Saxpy(r, -omega, t, 0, 0, ncomp, nghost); // r += -omega * t

rnorm = norm_inf(r);

Expand Down
2 changes: 1 addition & 1 deletion Src/LinearSolvers/MLMG/AMReX_MLMG.H
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ MLMGT<MF>::getGradSolution (const Vector<Array<AMF*,AMREX_SPACEDIM> >& a_grad_so
}
linop.compGrad(alev, GetArrOfPtrs(grad_sol), sol[alev], a_loc);
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
a_grad_sol[alev][idim]->LocalCopy(grad_sol, 0, 0, ncomp, IntVect(0));
a_grad_sol[alev][idim]->LocalCopy(grad_sol[idim], 0, 0, ncomp, IntVect(0));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Tests/LinearSolvers/EBflux_grad/MyTest.H
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private:
amrex::Vector<amrex::MultiFab> phi;
amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> flux;
amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> grad;
amrex::Vector<amrex::Array<amrex::fMultiFab, AMREX_SPACEDIM>> fgrad; // Used to test getGradSolution when MF is different from AMF
amrex::Vector<amrex::MultiFab> rhs;
amrex::Vector<amrex::MultiFab> acoef;
amrex::Vector<amrex::Array<amrex::MultiFab,AMREX_SPACEDIM> > bcoef;
Expand Down
4 changes: 4 additions & 0 deletions Tests/LinearSolvers/EBflux_grad/MyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ MyTest::solve ()
mlmg.solve(amrex::GetVecOfPtrs(phi), amrex::GetVecOfConstPtrs(rhs), tol_rel, tol_abs);
mlmg.getFluxes(amrex::GetVecOfArrOfPtrs(flux));
mlmg.getGradSolution(amrex::GetVecOfArrOfPtrs(grad));
mlmg.getGradSolution(amrex::GetVecOfArrOfPtrs(fgrad)); // Test when MF is different from AMF
for (int ilev = 0; ilev <= max_level; ++ilev) {
amrex::VisMF::Write(phi[0], "phi-"+std::to_string(ilev));
}
Expand Down Expand Up @@ -146,6 +147,7 @@ MyTest::initData ()
bcoef.resize(nlevels);
flux.resize(1);
grad.resize(1);
fgrad.resize(1);
for (int ilev = 0; ilev < nlevels; ++ilev)
{
dmap[ilev].define(grids[ilev]);
Expand Down Expand Up @@ -193,5 +195,7 @@ MyTest::initData ()
dmap[0], 1, 0, MFInfo(), *factory[0]);
grad[0][idim].define(amrex::convert(grids[0],IntVect::TheDimensionVector(idim)),
dmap[0], 1, 0, MFInfo(), *factory[0]);
fgrad[0][idim].define(amrex::convert(grids[0],IntVect::TheDimensionVector(idim)),
dmap[0], 1, 0, MFInfo(), DefaultFabFactory<BaseFab<float>>());
}
}

0 comments on commit 0858ecb

Please sign in to comment.