Skip to content

Commit

Permalink
Fix typo in MLMGT<MF>::getGradSolution when MF is different from …
Browse files Browse the repository at this point in the history
…`AMF` (AMReX-Codes#3631)

## Summary

This PR fixes a small typo in `MLMGT<MF>::getGradSolution` that causes
an error when `AMR` is distinct from `MF`. A test demonstrating the fix
is added for the case where `MF`=`MultiFab` and `AMF`=`fMultiFab`.

## Additional background

This typo was noticed when working on generalizing the `MLMG` template
to the WIP class `FabArraySet`.

## Checklist

The proposed changes:
- [x] fix a bug or incorrect behavior in AMReX
  • Loading branch information
eebasso authored Nov 16, 2023
1 parent a9da2a5 commit d171635
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
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 d171635

Please sign in to comment.