54 amrex::Vector<std::unique_ptr<amrex::MultiFab> >& a_rhs,
55 Real a_tol_rel, Real a_tol_abs,
bool copyrhs =
false,
56 const char* checkpoint_file =
nullptr)
59 amrex::Vector<amrex::MultiFab*> rhs_tmp(a_rhs.size());
60 amrex::Vector<amrex::MultiFab*> zero_tmp(a_rhs.size());
61 for (
int i = 0; i < rhs_tmp.size(); i++)
63 rhs_tmp[i] =
new amrex::MultiFab(a_rhs[i]->boxArray(), a_rhs[i]->DistributionMap(), a_rhs[i]->nComp(), a_rhs[i]->nGrow());
64 zero_tmp[i] =
new amrex::MultiFab(a_rhs[i]->boxArray(), a_rhs[i]->DistributionMap(), a_rhs[i]->nComp(), a_rhs[i]->nGrow());
65 rhs_tmp[i]->setVal(0.0);
66 zero_tmp[i]->setVal(0.0);
71 mlmg->apply(rhs_tmp, zero_tmp);
73 for (
int lev = 0; lev < rhs_tmp.size(); lev++)
75 amrex::Box domain =
linop->
Geom(lev).Domain();
76 domain.convert(amrex::IntVect::TheNodeVector());
77 const Dim3 lo = amrex::lbound(domain), hi = amrex::ubound(domain);
78 for (MFIter mfi(*rhs_tmp[lev], amrex::TilingIfNotGPU());mfi.isValid();++mfi)
80 amrex::Box bx = mfi.growntilebox(rhs_tmp[lev]->nGrow());
82 amrex::Array4<amrex::Real>
const& rhstmp = rhs_tmp[lev]->array(mfi);
83 for (
int n = 0; n < rhs_tmp[lev]->nComp(); n++)
85 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
87 bool AMREX_D_DECL(xmin = (i == lo.x), ymin = (j == lo.y), zmin = (k == lo.z)),
88 AMREX_D_DECL(xmax = (i == hi.x), ymax = (j == hi.y), zmax = (k == hi.z));
89 if (AMREX_D_TERM(xmax || xmin, || ymax || ymin, || zmax || zmin))
90 rhstmp(i, j, k, n) = 0.0;
92 rhstmp(i, j, k, n) *= -1.0;
102 for (
int lev = 0; lev < rhs_tmp.size(); lev++)
105 amrex::Add(*rhs_tmp[lev], *a_rhs[lev], 0, 0, rhs_tmp[lev]->nComp(), rhs_tmp[lev]->nGrow());
107 amrex::Copy(*a_rhs[lev], *rhs_tmp[lev], 0, 0, rhs_tmp[lev]->nComp(), rhs_tmp[lev]->nGrow());
116 retval =
mlmg->solve(GetVecOfPtrs(a_sol), GetVecOfConstPtrs(rhs_tmp), a_tol_rel, a_tol_abs, checkpoint_file);
118 catch (
const std::exception& e)
123 if (a_sol[0]->contains_nan())
133 amrex::Vector<std::unique_ptr<amrex::MultiFab> >& a_rhs,
134 Real a_tol_rel, Real a_tol_abs,
const char* checkpoint_file =
nullptr)
140 retval =
mlmg->solve(GetVecOfPtrs(a_sol), GetVecOfConstPtrs(a_rhs), a_tol_rel, a_tol_abs, checkpoint_file);
142 catch (
const std::exception& e)
188 const amrex::Vector<amrex::MultiFab const*>& a_rhs_mf)
190 int nlevs = a_sol_mf.size();
191 int ncomps = a_sol_mf[0]->nComp();
193 amrex::Vector<amrex::Geometry> geom;
194 amrex::Vector<int> iter;
195 amrex::Vector<amrex::IntVect> refratio;
196 amrex::Vector<std::string> names;
197 for (
int i = 0; i < nlevs; i++)
201 if (i > 0) refratio.push_back(amrex::IntVect(2));
203 for (
int n = 0; n < ncomps; n++)
205 names.push_back(
"var" + std::to_string(n));
209 WriteMultiLevelPlotfile(outputdir +
"/mlmg_sol", nlevs,
210 amrex::GetVecOfConstPtrs(a_sol_mf),
211 names, geom, 0, iter, refratio);
212 WriteMultiLevelPlotfile(outputdir +
"/mlmg_rhs", nlevs,
213 amrex::GetVecOfConstPtrs(a_rhs_mf),
214 names, geom, 0, iter, refratio);
217 for (
int lev = 0; lev < nlevs; lev++)
219 res_mf.
Define(lev, a_sol_mf[lev]->boxArray(), a_sol_mf[lev]->DistributionMap(),
220 ncomps, a_sol_mf[lev]->nGrow());
223 mlmg->compResidual(amrex::GetVecOfPtrs(res_mf), a_sol_mf, a_rhs_mf);
225 WriteMultiLevelPlotfile(outputdir +
"/mlmg_res", nlevs,
226 amrex::GetVecOfConstPtrs(res_mf),
227 names, geom, 0, iter, refratio);