Skip to content

Commit d171635

Browse files
authored
Fix typo in MLMGT<MF>::getGradSolution when MF is different from 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
1 parent a9da2a5 commit d171635

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Src/LinearSolvers/MLMG/AMReX_MLMG.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ MLMGT<MF>::getGradSolution (const Vector<Array<AMF*,AMREX_SPACEDIM> >& a_grad_so
545545
}
546546
linop.compGrad(alev, GetArrOfPtrs(grad_sol), sol[alev], a_loc);
547547
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
548-
a_grad_sol[alev][idim]->LocalCopy(grad_sol, 0, 0, ncomp, IntVect(0));
548+
a_grad_sol[alev][idim]->LocalCopy(grad_sol[idim], 0, 0, ncomp, IntVect(0));
549549
}
550550
}
551551
}

Tests/LinearSolvers/EBflux_grad/MyTest.H

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ private:
4545
amrex::Vector<amrex::MultiFab> phi;
4646
amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> flux;
4747
amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> grad;
48+
amrex::Vector<amrex::Array<amrex::fMultiFab, AMREX_SPACEDIM>> fgrad; // Used to test getGradSolution when MF is different from AMF
4849
amrex::Vector<amrex::MultiFab> rhs;
4950
amrex::Vector<amrex::MultiFab> acoef;
5051
amrex::Vector<amrex::Array<amrex::MultiFab,AMREX_SPACEDIM> > bcoef;

Tests/LinearSolvers/EBflux_grad/MyTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ MyTest::solve ()
7373
mlmg.solve(amrex::GetVecOfPtrs(phi), amrex::GetVecOfConstPtrs(rhs), tol_rel, tol_abs);
7474
mlmg.getFluxes(amrex::GetVecOfArrOfPtrs(flux));
7575
mlmg.getGradSolution(amrex::GetVecOfArrOfPtrs(grad));
76+
mlmg.getGradSolution(amrex::GetVecOfArrOfPtrs(fgrad)); // Test when MF is different from AMF
7677
for (int ilev = 0; ilev <= max_level; ++ilev) {
7778
amrex::VisMF::Write(phi[0], "phi-"+std::to_string(ilev));
7879
}
@@ -146,6 +147,7 @@ MyTest::initData ()
146147
bcoef.resize(nlevels);
147148
flux.resize(1);
148149
grad.resize(1);
150+
fgrad.resize(1);
149151
for (int ilev = 0; ilev < nlevels; ++ilev)
150152
{
151153
dmap[ilev].define(grids[ilev]);
@@ -193,5 +195,7 @@ MyTest::initData ()
193195
dmap[0], 1, 0, MFInfo(), *factory[0]);
194196
grad[0][idim].define(amrex::convert(grids[0],IntVect::TheDimensionVector(idim)),
195197
dmap[0], 1, 0, MFInfo(), *factory[0]);
198+
fgrad[0][idim].define(amrex::convert(grids[0],IntVect::TheDimensionVector(idim)),
199+
dmap[0], 1, 0, MFInfo(), DefaultFabFactory<BaseFab<float>>());
196200
}
197201
}

0 commit comments

Comments
 (0)