From d171635b3a54fb9e8896c9562bbedaa5f3a894cd Mon Sep 17 00:00:00 2001 From: Edward Basso Date: Thu, 16 Nov 2023 08:49:21 -0800 Subject: [PATCH 1/2] Fix typo in `MLMGT::getGradSolution` when `MF` is different from `AMF` (#3631) ## Summary This PR fixes a small typo in `MLMGT::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 --- Src/LinearSolvers/MLMG/AMReX_MLMG.H | 2 +- Tests/LinearSolvers/EBflux_grad/MyTest.H | 1 + Tests/LinearSolvers/EBflux_grad/MyTest.cpp | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Src/LinearSolvers/MLMG/AMReX_MLMG.H b/Src/LinearSolvers/MLMG/AMReX_MLMG.H index 7fc822afa23..f1fed2d3db3 100644 --- a/Src/LinearSolvers/MLMG/AMReX_MLMG.H +++ b/Src/LinearSolvers/MLMG/AMReX_MLMG.H @@ -545,7 +545,7 @@ MLMGT::getGradSolution (const Vector >& 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)); } } } diff --git a/Tests/LinearSolvers/EBflux_grad/MyTest.H b/Tests/LinearSolvers/EBflux_grad/MyTest.H index 17ccdec1604..f26ee4e1c0b 100644 --- a/Tests/LinearSolvers/EBflux_grad/MyTest.H +++ b/Tests/LinearSolvers/EBflux_grad/MyTest.H @@ -45,6 +45,7 @@ private: amrex::Vector phi; amrex::Vector> flux; amrex::Vector> grad; + amrex::Vector> fgrad; // Used to test getGradSolution when MF is different from AMF amrex::Vector rhs; amrex::Vector acoef; amrex::Vector > bcoef; diff --git a/Tests/LinearSolvers/EBflux_grad/MyTest.cpp b/Tests/LinearSolvers/EBflux_grad/MyTest.cpp index 782f3eece39..c814536203d 100644 --- a/Tests/LinearSolvers/EBflux_grad/MyTest.cpp +++ b/Tests/LinearSolvers/EBflux_grad/MyTest.cpp @@ -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)); } @@ -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]); @@ -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>()); } } From d93f34416da3dfb5b50e5a8b0cbb3b6f78bd0569 Mon Sep 17 00:00:00 2001 From: Ankith Anil Das <46082093+ankithadas@users.noreply.github.com> Date: Fri, 17 Nov 2023 04:57:41 +1100 Subject: [PATCH 2/2] Bug fix for amrex::Subtract when called with interger nghost (#3634) ## Summary `amrex::Subtract` leads to an infinite recursion when invoked with an integer value for nghost. To address this issue, explicit casting of the integer to `IntVect` has been incorporated. ## Checklist The proposed changes: - [x] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate --- Src/Base/AMReX_FabArrayUtility.H | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Base/AMReX_FabArrayUtility.H b/Src/Base/AMReX_FabArrayUtility.H index 78f3355d34a..ca80a070f45 100644 --- a/Src/Base/AMReX_FabArrayUtility.H +++ b/Src/Base/AMReX_FabArrayUtility.H @@ -1103,7 +1103,7 @@ template & dst, FabArray const& src, int srccomp, int dstcomp, int numcomp, int nghost) { - Subtract(dst,src,srccomp,dstcomp,numcomp,nghost); + Subtract(dst,src,srccomp,dstcomp,numcomp,IntVect(nghost)); } template