3#include <AMReX_Config.H>
43 :
public std::runtime_error
46 using std::runtime_error::runtime_error;
81 template <
typename AMF>
83 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file =
nullptr);
95 template <
typename AMF>
96 RT solve (std::initializer_list<AMF*> a_sol,
97 std::initializer_list<AMF const*> a_rhs,
98 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file =
nullptr);
110 RT a_tol_rel,
RT a_tol_abs);
118 template <
typename AMF>
120 Location a_loc = Location::FaceCenter);
128 template <
typename AMF>
130 Location a_loc = Location::FaceCenter);
138 template <
typename AMF>
140 Location a_loc = Location::FaceCenter);
148 template <
typename AMF>
150 Location a_loc = Location::FaceCenter);
159 template <
typename AMF>
162 Location a_loc = Location::FaceCenter);
171 template <
typename AMF>
173 std::initializer_list<AMF*> a_sol,
174 Location a_loc = Location::FaceCenter);
182 template <
typename AMF>
184 Location a_loc = Location::CellCenter);
192 template <
typename AMF>
193 void getFluxes (std::initializer_list<AMF*> a_flux,
194 Location a_loc = Location::CellCenter);
203 template <
typename AMF>
206 Location a_loc = Location::CellCenter);
215 template <
typename AMF>
216 void getFluxes (std::initializer_list<AMF*> a_flux,
217 std::initializer_list<AMF*> a_sol,
218 Location a_loc = Location::CellCenter);
301 void setFixedIter (
int nit)
noexcept { do_fixed_number_of_iters = nit; }
348 [[nodiscard]]
bool usedAlgMG () const noexcept {
return m_algmg_active; }
361 m_algmg_options = std::move(f);
362 m_algmg_bottom.reset();
363 m_algmg_level0.reset();
372 hybrid_stall_window = window; hybrid_stall_rate = rate;
409 [[deprecated(
"Use MLMG::setConvergenceNormType() instead.")]]
438 void setNSolve (
int flag)
noexcept { do_nsolve = flag; }
461 void setNoGpuSync (
bool do_not_sync)
noexcept { do_no_sync_gpu = do_not_sync; }
463#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
483 void setHypreOptionsNamespace(
const std::string& prefix)
noexcept
485 hypre_options_namespace = prefix;
489 void setHypreOldDefault (
bool l)
noexcept {hypre_old_default = l;}
491 void setHypreRelaxType (
int n)
noexcept {hypre_relax_type = n;}
493 void setHypreRelaxOrder (
int n)
noexcept {hypre_relax_order = n;}
495 void setHypreNumSweeps (
int n)
noexcept {hypre_num_sweeps = n;}
497 void setHypreStrongThreshold (
Real t)
noexcept {hypre_strong_threshold = t;}
513 template <
typename AMF>
514 void prepareForSolve (Vector<AMF*>
const& a_sol, Vector<AMF const*>
const& a_rhs);
545 void mgVcycle (
int amrlev,
int mglev);
558 void NSolve (MLMGT<MF>& a_solver, MF& a_sol, MF& a_rhs);
570 void postCG (
int ret,
int niters = -1);
658#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
666 template <
class TMF=MF>
667 requires (std::same_as<TMF,MultiFab>)
668 void bottomSolveWithHypre (MF&
x,
const MF& b);
671#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
679 template <
class TMF=MF>
680 requires (std::same_as<TMF,MultiFab>)
681 void bottomSolveWithPETSc (MF&
x,
const MF& b);
695 template <
class TMF=MF>
696 requires (std::same_as<TMF,MultiFab>)
701 template <
class TMF=MF>
702 requires (std::same_as<TMF,MultiFab>)
705 template <
class TMF=MF>
706 requires (std::same_as<TMF,MultiFab>)
710 template <
class TMF=MF>
711 requires (std::same_as<TMF,MultiFab>)
718 RT best_norm, std::string& reason)
const;
727 [[nodiscard]]
int getNumIters () const noexcept {
return m_iter_fine_resnorm0.
size(); }
734 bool precond_mode =
false;
735 bool throw_exception =
false;
739 int do_fixed_number_of_iters = 0;
740 int max_precond_iters = 1;
747 int max_fmg_iters = 0;
751 int bottom_verbose = 0;
752 int bottom_maxiter = 200;
753 RT bottom_reltol = std::is_same<RT,double>() ?
RT(1.e-4) :
RT(1.e-3);
754 RT bottom_abstol =
RT(-1.0);
759 bool m_algmg_active =
false;
760 int hybrid_stall_window = 4;
761 RT hybrid_stall_rate =
RT(0.8);
762 RT hybrid_divergence_factor =
RT(10.0);
763 std::function<void(
AlgMG<RT>&)> m_algmg_options;
764 std::unique_ptr<MLAlgMG> m_algmg_bottom;
765 std::unique_ptr<MLAlgMG> m_algmg_level0;
767 int final_fill_bc = 0;
774 bool linop_prepared =
false;
775 Long solve_called = 0;
778 int do_nsolve =
false;
779 int nsolve_grid_size = 16;
780 std::unique_ptr<MLLinOpT<MF>> ns_linop;
781 std::unique_ptr<MLMGT<MF>> ns_mlmg;
782 std::unique_ptr<MF> ns_sol;
783 std::unique_ptr<MF> ns_rhs;
785 std::string print_ident;
787 bool do_no_sync_gpu =
false;
790#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
795 std::unique_ptr<Hypre> hypre_solver;
796 std::unique_ptr<MLMGBndryT<MF>> hypre_bndry;
797 std::unique_ptr<HypreNodeLap> hypre_node_solver;
799 std::string hypre_options_namespace =
"hypre";
803 int hypre_num_sweeps = 2;
804 Real hypre_strong_threshold = 0.25;
808#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
809 std::unique_ptr<PETScABecLap> petsc_solver;
810 std::unique_ptr<MLMGBndryT<MF>> petsc_bndry;
833 enum timer_types { solve_time=0, iter_time, bottom_time, ntimers };
834 Vector<double> timer;
836 RT m_rhsnorm0 =
RT(-1.0);
837 RT m_init_resnorm0 =
RT(-1.0);
838 RT m_final_resnorm0 =
RT(-1.0);
839 Vector<int> m_niters_cg;
840 Vector<RT> m_iter_fine_resnorm0;
851 void checkPoint (
const Vector<MultiFab*>& a_sol,
852 const Vector<MultiFab const*>& a_rhs,
853 RT a_tol_rel,
RT a_tol_abs,
const char* a_file_name)
const;
857template <
typename MF>
859 : linop(a_lp), ncomp(a_lp.getNComp()), namrlevs(a_lp.NAMRLevels()),
860 finest_amr_lev(a_lp.NAMRLevels()-1)
865template <
typename MF>
876template <
typename MF>
877template <
typename AMF>
880 std::initializer_list<AMF const*> a_rhs,
881 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file) ->
RT
885 a_tol_rel, a_tol_abs, checkpoint_file);
888template <
typename MF>
889template <
typename AMF>
892 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file) ->
RT
903 std::optional<Gpu::SyncAtExitOnly> no_sync_region;
904 std::optional<Gpu::SingleStreamRegion> single_stream_region;
905 if (do_no_sync_gpu) {
906 no_sync_region.emplace();
907 single_stream_region.emplace();
910 if constexpr (std::is_same<AMF,MultiFab>()) {
911 if (checkpoint_file !=
nullptr) {
912 checkPoint(a_sol, a_rhs, a_tol_rel, a_tol_abs, checkpoint_file);
921 bottom_solver = linop.getDefaultBottomSolver();
925 bool eb_linop =
false;
927 if constexpr (IsFabArray_v<AMF>) {
933#if (defined(AMREX_USE_HYPRE) || defined(AMREX_USE_PETSC)) && (AMREX_SPACEDIM > 1)
934 if constexpr (IsFabArray_v<AMF>) {
937 linop.setMaxOrder(std::min(3, linop.getMaxOrder()));
939#ifdef AMREX_USE_HYPRE
941 linop.setMaxOrder(std::min(3, linop.getMaxOrder()));
949 "MLMG: AlgMG is not available for this operator (single-component cell and nodal operators only)");
952 "MLMG: AlgMG does not support the ghostnodes strategy with ghost cells");
955 linop.setMaxOrder(std::min(3, linop.getMaxOrder()));
959 bool is_nsolve = linop.m_parent;
964 "MLMG: NSolve requires the geometric multigrid type");
966 "MLMG: the hybrid multigrid type needs a convergence test; as a preconditioner or with a fixed number of iterations use geometric or algebraic");
970 RT& composite_norminf = m_final_resnorm0;
973 m_iter_fine_resnorm0.clear();
975 prepareForSolve(a_sol, a_rhs);
977 computeMLResidual(finest_amr_lev);
980 RT resnorm0 = MLResNormInf(finest_amr_lev, local);
981 RT rhsnorm0 = MLRhsNormInf(local);
987 amrex::Print() << print_ident <<
"MLMG: Initial rhs = " << rhsnorm0 <<
"\n"
988 << print_ident <<
"MLMG: Initial residual (resid0) = " << resnorm0 <<
"\n";
992 m_init_resnorm0 = resnorm0;
993 m_rhsnorm0 = rhsnorm0;
995 if (!is_nsolve && !amrex::isfinite(std::max(resnorm0, rhsnorm0))) {
996 if ( throw_exception ) {
997 throw error(
"MLMG: rhs or initial residual is not finite.");
999 amrex::Abort(
"MLMG: rhs or initial residual is not finite");
1003 RT max_norm = resnorm0;
1004 std::string norm_name =
"resid0";
1005 switch (norm_type) {
1007 if (rhsnorm0 >= resnorm0) {
1008 norm_name =
"bnorm";
1009 max_norm = rhsnorm0;
1011 norm_name =
"resid0";
1012 max_norm = resnorm0;
1016 norm_name =
"bnorm";
1017 max_norm = rhsnorm0;
1020 norm_name =
"resid0";
1021 max_norm = resnorm0;
1025 const RT res_target = std::max(a_tol_abs, std::max(a_tol_rel,std::numeric_limits<RT>::epsilon())*max_norm);
1027 if (!is_nsolve && resnorm0 <= res_target) {
1028 composite_norminf = resnorm0;
1030 amrex::Print() << print_ident <<
"MLMG: No iterations needed\n";
1034 bool converged =
false;
1041 bool hybrid_composite =
false;
1042 RT best_norm = resnorm0;
1044 if (namrlevs > 1) { best_norm = ResNormInf(finest_amr_lev); }
1045 best_sol.resize(namrlevs);
1046 for (
int alev = 0; alev < namrlevs; ++alev) {
1048 best_sol[alev] = linop.make(alev, 0, ng);
1049 LocalCopy(best_sol[alev], sol[alev], 0, 0, ncomp, ng);
1053 int niters = do_fixed_number_of_iters ? do_fixed_number_of_iters : max_iters;
1054 for (
int iter = 0; iter < niters; ++iter)
1063 if (is_nsolve) {
continue; }
1065 RT fine_norminf = ResNormInf(finest_amr_lev);
1066 m_iter_fine_resnorm0.push_back(fine_norminf);
1067 composite_norminf = fine_norminf;
1069 amrex::Print() << print_ident <<
"MLMG: Iteration " << std::setw(3) << iter+1 <<
" Fine resid/"
1070 << norm_name <<
" = " << fine_norminf/max_norm <<
"\n";
1072 bool fine_converged = (fine_norminf <= res_target);
1074 if (namrlevs == 1 && fine_converged) {
1076 }
else if (fine_converged) {
1078 computeMLResidual(finest_amr_lev-1);
1079 RT crse_norminf = MLResNormInf(finest_amr_lev-1);
1081 amrex::Print() << print_ident <<
"MLMG: Iteration " << std::setw(3) << iter+1
1082 <<
" Crse resid/" << norm_name <<
" = "
1083 << crse_norminf/max_norm <<
"\n";
1085 converged = (crse_norminf <= res_target);
1086 composite_norminf = std::max(fine_norminf, crse_norminf);
1093 amrex::Print() << print_ident <<
"MLMG: Final Iter. " << iter+1
1094 <<
" resid, resid/" << norm_name <<
" = "
1095 << composite_norminf <<
", "
1096 << composite_norminf/max_norm <<
"\n";
1100 if (
hybrid && !m_algmg_active) {
1101 if (fine_converged && !hybrid_composite) {
1104 hybrid_composite =
true;
1105 hybrid_norms.clear();
1106 best_norm = composite_norminf;
1107 for (
int alev = 0; alev < namrlevs; ++alev) {
1111 hybrid_norms.push_back(composite_norminf);
1113 bool do_switch = hybridShouldSwitch(hybrid_norms, max_norm,
1115 if (!do_switch && iter+1 == niters) {
1117 reason =
"not converged";
1121 amrex::Print() << print_ident <<
"MLMG: " << reason <<
" after "
1122 << iter+1 <<
" iterations, switching to AlgMG on AMR level 0\n";
1124 if (!amrex::isfinite(composite_norminf) || composite_norminf > best_norm) {
1125 for (
int alev = 0; alev < namrlevs; ++alev) {
1129 composite_norminf = best_norm;
1131 amrex::Print() << print_ident <<
"MLMG: restarting from the best iterate, resid/"
1132 << norm_name <<
" = " << best_norm/max_norm <<
"\n";
1135 m_algmg_active =
true;
1136 niters = iter + 1 + max_iters;
1139 if (composite_norminf < best_norm) {
1140 best_norm = composite_norminf;
1141 for (
int alev = 0; alev < namrlevs; ++alev) {
1146 if (composite_norminf >
RT(1.e20)*max_norm || !amrex::isfinite(composite_norminf))
1149 amrex::Print() << print_ident <<
"MLMG: Failing to converge after " << iter+1 <<
" iterations."
1150 <<
" resid, resid/" << norm_name <<
" = "
1151 << composite_norminf <<
", "
1152 << composite_norminf/max_norm <<
"\n";
1155 if ( throw_exception ) {
1156 throw error(
"MLMG blew up.");
1164 if (!converged && do_fixed_number_of_iters == 0) {
1166 amrex::Print() << print_ident <<
"MLMG: Failed to converge after " << niters <<
" iterations."
1167 <<
" resid, resid/" << norm_name <<
" = "
1168 << composite_norminf <<
", "
1169 << composite_norminf/max_norm <<
"\n";
1172 if ( throw_exception ) {
1173 throw error(
"MLMG failed to converge.");
1184 if (linop.hasHiddenDimension()) {
1185 ng_back[linop.hiddenDirection()] = 0;
1187 for (
int alev = 0; alev < namrlevs; ++alev)
1189 if (!sol_is_alias[alev]) {
1190 LocalCopy(*a_sol[alev], sol[alev], 0, 0, ncomp, ng_back);
1196 ParallelReduce::Max<double>(timer.data(), timer.size(), 0,
1200 amrex::AllPrint() << print_ident <<
"MLMG: Timers: Solve = " << timer[solve_time]
1201 <<
" Iter = " << timer[iter_time]
1202 <<
" Bottom = " << timer[bottom_time] <<
"\n";
1208 return composite_norminf;
1211template <
typename MF>
1214 RT a_tol_rel,
RT a_tol_abs) ->
RT
1216 precond_mode =
true;
1217 std::swap(max_precond_iters, do_fixed_number_of_iters);
1218 linop.beginPrecondBC();
1220 auto r = solve(a_sol, a_rhs, a_tol_rel, a_tol_abs);
1222 linop.endPrecondBC();
1223 std::swap(max_precond_iters, do_fixed_number_of_iters);
1224 precond_mode =
false;
1229template <
typename MF>
1233 for (
int alev = finest_amr_lev; alev >= 0; --alev) {
1234 const MF* crse_bcdata = (alev > 0) ? a_sol[alev-1] :
nullptr;
1235 linop.prepareForFluxes(alev, crse_bcdata);
1239template <
typename MF>
1240template <
typename AMF>
1245 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
1246 if constexpr (std::is_same<AMF,MF>()) {
1247 linop.compGrad(alev, a_grad_sol[alev], sol[alev], a_loc);
1250 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1251 auto const& amf = *(a_grad_sol[alev][idim]);
1254 linop.compGrad(alev,
GetArrOfPtrs(grad_sol), sol[alev], a_loc);
1255 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1256 LocalCopy(*a_grad_sol[alev][idim], grad_sol[idim], 0, 0, ncomp,
IntVect(0));
1262template <
typename MF>
1263template <
typename AMF>
1270template <
typename MF>
1271template <
typename AMF>
1276 if (!linop.isCellCentered()) {
1277 amrex::Abort(
"Calling wrong getFluxes for nodal solver");
1282 if constexpr (std::is_same<AMF,MF>()) {
1286 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
1287 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1288 auto const& amf = *(a_flux[ilev][idim]);
1293 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
1294 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1295 LocalCopy(*a_flux[ilev][idim], fluxes[ilev][idim], 0, 0, ncomp,
IntVect(0));
1301template <
typename MF>
1302template <
typename AMF>
1310template <
typename MF>
1311template <
typename AMF>
1318 if (!linop.isCellCentered()) {
1319 amrex::Abort(
"Calling wrong getFluxes for nodal solver");
1322 if constexpr (std::is_same<AMF,MF>()) {
1323 linop.getFluxes(a_flux, a_sol, a_loc);
1326 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
1327 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1328 auto const& amf = *(a_flux[ilev][idim]);
1334 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
1335 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1336 LocalCopy(*a_flux[ilev][idim], fluxes[ilev][idim], 0, 0, ncomp,
IntVect(0));
1342template <
typename MF>
1343template <
typename AMF>
1346 std::initializer_list<AMF*> a_sol,
Location a_loc)
1352template <
typename MF>
1353template <
typename AMF>
1358 if constexpr (std::is_same<AMF,MF>()) {
1362 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
1363 auto const& amf = *a_flux[ilev];
1367 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
1373template <
typename MF>
1374template <
typename AMF>
1381template <
typename MF>
1382template <
typename AMF>
1389 if constexpr (! std::is_same<AMF,MF>()) {
1390 for (
int alev = 0; alev < namrlevs; ++alev) {
1395 if (linop.isCellCentered())
1398 for (
int alev = 0; alev < namrlevs; ++alev) {
1399 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1400 const int mglev = 0;
1402 if (cf_strategy == CFStrategy::ghostnodes) { nghost = linop.getNGrow(alev); }
1403 ffluxes[alev][idim].define(
amrex::convert(linop.m_grids[alev][mglev],
1405 linop.m_dmap[alev][mglev], ncomp, nghost,
MFInfo(),
1406 *linop.m_factory[alev][mglev]);
1409 if constexpr (std::is_same<AMF,MF>()) {
1414 for (
int alev = 0; alev < namrlevs; ++alev) {
1423 if constexpr (std::is_same<AMF,MF>()) {
1424 linop.getFluxes(a_flux, a_sol);
1427 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
1428 auto const& amf = *a_flux[ilev];
1432 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
1439template <
typename MF>
1440template <
typename AMF>
1443 std::initializer_list<AMF*> a_sol,
Location a_loc)
1450template <
typename MF>
1454 if (!linop.isCellCentered()) {
1462template <
typename MF>
1468 if (!linop.isCellCentered()) {
1472 linop.getEBFluxes(a_eb_flux, a_sol);
1476template <
typename MF>
1484 if (linop.hasHiddenDimension()) { ng_sol[linop.hiddenDirection()] = 0; }
1487 sol_is_alias.resize(namrlevs,
true);
1488 for (
int alev = 0; alev < namrlevs; ++alev)
1490 if (cf_strategy == CFStrategy::ghostnodes ||
nGrowVect(*a_sol[alev]) == ng_sol)
1492 sol[alev] = linop.makeAlias(*a_sol[alev]);
1493 sol_is_alias[alev] =
true;
1497 if (sol_is_alias[alev])
1499 sol[alev] = linop.make(alev, 0, ng_sol);
1500 sol_is_alias[alev] =
false;
1509 for (
int alev = finest_amr_lev; alev >= 0; --alev) {
1510 const MF* crse_bcdata = (alev > 0) ? &(sol[alev-1]) :
nullptr;
1511 const MF* prhs = a_rhs[alev];
1512#if (AMREX_SPACEDIM != 3)
1513 int nghost = (cf_strategy == CFStrategy::ghostnodes) ? linop.getNGrow(alev) : 0;
1515 MFInfo(), *linop.Factory(alev));
1517 linop.applyMetricTerm(alev, 0, rhstmp);
1518 linop.unimposeNeumannBC(alev, rhstmp);
1519 linop.applyInhomogNeumannTerm(alev, rhstmp);
1522 linop.solutionResidual(alev, *a_res[alev], sol[alev], *prhs, crse_bcdata);
1523 if (alev < finest_amr_lev) {
1524 linop.reflux(alev, *a_res[alev], sol[alev], *prhs,
1525 *a_res[alev+1], sol[alev+1], *a_rhs[alev+1]);
1526 if (linop.isCellCentered()) {
1528 EB_average_down(*a_res[alev+1], *a_res[alev], 0, ncomp, linop.AMRRefRatioVect(alev));
1530 average_down(*a_res[alev+1], *a_res[alev], 0, ncomp, linop.AMRRefRatioVect(alev));
1537#if (AMREX_SPACEDIM != 3)
1538 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
1539 linop.unapplyMetricTerm(alev, 0, *a_res[alev]);
1544template <
typename MF>
1555 if (linop.hasHiddenDimension()) { ng_sol[linop.hiddenDirection()] = 0; }
1557 for (
int alev = 0; alev < namrlevs; ++alev)
1559 if (cf_strategy == CFStrategy::ghostnodes)
1561 nghost = linop.getNGrow(alev);
1562 in[alev] = a_in[alev];
1564 else if (
nGrowVect(*a_in[alev]) == ng_sol)
1566 in[alev] = a_in[alev];
1571 if (cf_strategy == CFStrategy::ghostnodes) { ng =
IntVect(nghost); }
1572 in_raii[alev] = linop.make(alev, 0, ng,
1575 in[alev] = &(in_raii[alev]);
1577 rh[alev] = linop.make(alev, 0,
IntVect(nghost),
1584 for (
int alev = 0; alev < namrlevs; ++alev) {
1585 linop.applyInhomogNeumannTerm(alev, rh[alev]);
1589 for (
int alev = finest_amr_lev; alev >= 0; --alev) {
1590 const MF* crse_bcdata = (alev > 0) ? in[alev-1] :
nullptr;
1591 linop.solutionResidual(alev, *out[alev], *in[alev], rh[alev], crse_bcdata);
1592 if (alev < finest_amr_lev) {
1593 linop.reflux(alev, *out[alev], *in[alev], rh[alev],
1594 *out[alev+1], *in[alev+1], rh[alev+1]);
1595 if (linop.isCellCentered()) {
1596 if constexpr (IsMultiFabLike_v<MF>) {
1600 average_down(*out[alev+1], *out[alev], 0,
nComp(*out[alev]), linop.AMRRefRatioVect(alev));
1603 amrex::Abort(
"MLMG: TODO average_down for non-MultiFab");
1609#if (AMREX_SPACEDIM != 3)
1610 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
1611 linop.unapplyMetricTerm(alev, 0, *out[alev]);
1615 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
1616 if (cf_strategy == CFStrategy::ghostnodes) { nghost = linop.getNGrow(alev); }
1617 Scale(*out[alev],
RT(-1), 0,
nComp(*out[alev]), nghost);
1621template <
typename MF>
1625 precond_mode =
true;
1626 linop.beginPrecondBC();
1628 linop.endPrecondBC();
1629 precond_mode =
false;
1632template <
typename MF>
1633template <
typename AMF>
1642 timer.assign(ntimers, 0.0);
1646 if (linop.hasHiddenDimension()) { ng_sol[linop.hiddenDirection()] = 0; }
1648 linop.setPrintIndentation(print_ident);
1649 if (!linop_prepared) {
1650 linop.prepareForSolve();
1651 AMREX_ASSERT(!linop.m_mg_deferred || linop.m_mg_built);
1652 linop_prepared =
true;
1653 }
else if (linop.needsUpdate()) {
1656 m_algmg_bottom.reset();
1657 m_algmg_level0.reset();
1659#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
1660 hypre_solver.reset();
1661 hypre_bndry.reset();
1662 hypre_node_solver.reset();
1665#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
1666 petsc_solver.reset();
1667 petsc_bndry.reset();
1671 sol.resize(namrlevs);
1672 sol_is_alias.resize(namrlevs,
false);
1673 for (
int alev = 0; alev < namrlevs; ++alev)
1675 if (cf_strategy == CFStrategy::ghostnodes)
1677 if constexpr (std::is_same<AMF,MF>()) {
1678 sol[alev] = linop.makeAlias(*a_sol[alev]);
1679 sol_is_alias[alev] =
true;
1681 amrex::Abort(
"Type conversion not supported for CFStrategy::ghostnodes");
1686 bool alias_made =
false;
1687 if (
nGrowVect(*a_sol[alev]) == ng_sol) {
1688 if constexpr (std::is_same<AMF,MF>()) {
1689 sol[alev] = linop.makeAlias(*a_sol[alev]);
1690 sol_is_alias[alev] =
true;
1695 if (sol_is_alias[alev] || !solve_called) {
1696 sol[alev] = linop.make(alev, 0, ng_sol);
1697 sol_is_alias[alev] =
false;
1705 rhs.resize(namrlevs);
1706 for (
int alev = 0; alev < namrlevs; ++alev)
1708 if (cf_strategy == CFStrategy::ghostnodes) { ng_rhs =
IntVect(linop.getNGrow(alev)); }
1709 if (!solve_called) {
1710 rhs[alev] = linop.make(alev, 0, ng_rhs);
1712 LocalCopy(rhs[alev], *a_rhs[alev], 0, 0, ncomp, ng_rhs);
1713 linop.applyMetricTerm(alev, 0, rhs[alev]);
1714 linop.unimposeNeumannBC(alev, rhs[alev]);
1715 linop.applyInhomogNeumannTerm(alev, rhs[alev]);
1716 linop.applyOverset(alev, rhs[alev]);
1717 if ( ! precond_mode) {
1718 bool r = linop.scaleRHS(alev, &(rhs[alev]));
1724 if (factory && !factory->isAllRegular()) {
1725 if constexpr (std::is_same<MF,MultiFab>()) {
1729 amrex::Abort(
"TODO: MLMG with EB only works with MultiFab");
1735 for (
int falev = finest_amr_lev; falev > 0; --falev)
1737 linop.averageDownSolutionRHS(falev-1, sol[falev-1], rhs[falev-1], sol[falev], rhs[falev]);
1741 if (linop.isSingular(0) && linop.getEnforceSingularSolvable())
1746 IntVect ng = linop.getNGrowVectRestriction();
1747 if (cf_strategy == CFStrategy::ghostnodes) { ng = ng_rhs; }
1748 if (!solve_called) {
1749 linop.make(res, ng);
1750 linop.make(rescor, ng);
1752 for (
int alev = 0; alev <= finest_amr_lev; ++alev)
1754 const int nmglevs = linop.NMGLevels(alev);
1755 for (
int mglev = 0; mglev < nmglevs; ++mglev)
1757 setVal(res [alev][mglev],
RT(0.0));
1758 setVal(rescor[alev][mglev],
RT(0.0));
1762 if (cf_strategy != CFStrategy::ghostnodes) { ng = ng_sol; }
1764 for (
int alev = 0; alev <= finest_amr_lev; ++alev)
1766 const int nmglevs = linop.NMGLevels(alev);
1767 cor[alev].resize(nmglevs);
1768 for (
int mglev = 0; mglev < nmglevs; ++mglev)
1770 if (!solve_called) {
1772 if (cf_strategy == CFStrategy::ghostnodes) { _ng=
IntVect(linop.getNGrow(alev,mglev)); }
1773 cor[alev][mglev] = linop.make(alev, mglev, _ng);
1779 cor_hold.resize(std::max(namrlevs-1,1));
1782 const int nmglevs = linop.NMGLevels(alev);
1783 cor_hold[alev].resize(nmglevs);
1784 for (
int mglev = 0; mglev < nmglevs-1; ++mglev)
1786 if (!solve_called) {
1788 if (cf_strategy == CFStrategy::ghostnodes) { _ng=
IntVect(linop.getNGrow(alev,mglev)); }
1789 cor_hold[alev][mglev] = linop.make(alev, mglev, _ng);
1791 setVal(cor_hold[alev][mglev],
RT(0.0));
1794 for (
int alev = 1; alev < finest_amr_lev; ++alev)
1796 cor_hold[alev].resize(1);
1797 if (!solve_called) {
1799 if (cf_strategy == CFStrategy::ghostnodes) { _ng=
IntVect(linop.getNGrow(alev)); }
1800 cor_hold[alev][0] = linop.make(alev, 0, _ng);
1802 setVal(cor_hold[alev][0],
RT(0.0));
1806 || !linop.supportNSolve())
1811 if (do_nsolve && ns_linop ==
nullptr)
1817 amrex::Print() << print_ident <<
"MLMG: # of AMR levels: " << namrlevs <<
"\n"
1818 << print_ident <<
" # of MG levels on the coarsest AMR level: " << linop.NMGLevels(0)
1821 amrex::Print() << print_ident <<
" # of MG levels in N-Solve: " << ns_linop->NMGLevels(0) <<
"\n"
1822 << print_ident <<
" # of grids in N-Solve: " << ns_linop->m_grids[0][0].size() <<
"\n";
1827template <
typename MF>
1831 linop.setPrintIndentation(print_ident);
1832 if (!linop_prepared) {
1833 linop.prepareForSolve();
1834 AMREX_ASSERT(!linop.m_mg_deferred || linop.m_mg_built);
1835 linop_prepared =
true;
1836 }
else if (linop.needsUpdate()) {
1839 m_algmg_bottom.reset();
1840 m_algmg_level0.reset();
1842#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
1843 hypre_solver.reset();
1844 hypre_bndry.reset();
1845 hypre_node_solver.reset();
1848#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
1849 petsc_solver.reset();
1850 petsc_bndry.reset();
1855template <
typename MF>
1860 linop.preparePrecond();
1863template <
typename MF>
1867 if constexpr (IsMultiFabLike_v<MF>) {
1868 ns_linop = linop.makeNLinOp(nsolve_grid_size);
1871 if (cf_strategy == CFStrategy::ghostnodes) { nghost = linop.getNGrow(); }
1873 const BoxArray& ba = (*ns_linop).m_grids[0][0];
1877 if (cf_strategy == CFStrategy::ghostnodes) { ng = nghost; }
1878 ns_sol = std::make_unique<MF>(ba, dm, ncomp, ng,
MFInfo(), *(ns_linop->Factory(0,0)));
1880 if (cf_strategy == CFStrategy::ghostnodes) { ng = nghost; }
1881 ns_rhs = std::make_unique<MF>(ba, dm, ncomp, ng,
MFInfo(), *(ns_linop->Factory(0,0)));
1885 ns_linop->setLevelBC(0, ns_sol.get());
1887 ns_mlmg = std::make_unique<MLMGT<MF>>(*ns_linop);
1888 ns_mlmg->setVerbose(0);
1889 ns_mlmg->setFixedIter(1);
1890 ns_mlmg->setMaxFmgIter(20);
1897template <
typename MF>
1902 for (
int alev = finest_amr_lev; alev > 0; --alev)
1907 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(alev)); }
1908 LocalAdd(sol[alev], cor[alev][0], 0, 0, ncomp, nghost);
1911 computeResWithCrseSolFineCor(alev-1,alev);
1913 if (alev != finest_amr_lev) {
1914 std::swap(cor_hold[alev][0], cor[alev][0]);
1921 if (linop.isSingular(0) && linop.getEnforceSingularSolvable())
1923 makeSolvable(0,0,res[0][0]);
1926 if (m_algmg_active) {
1927 if constexpr (std::is_same<MF,MultiFab>()) {
1930 amrex::Abort(
"MLMG: AlgMG is only supported for MultiFab");
1932 }
else if (iter < max_fmg_iters) {
1939 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(0)); }
1940 LocalAdd(sol[0], cor[0][0], 0, 0, ncomp, nghost);
1943 for (
int alev = 1; alev <= finest_amr_lev; ++alev)
1946 interpCorrection(alev);
1948 linop.applyOverset(alev, cor[alev][0]);
1951 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(alev)); }
1952 LocalAdd(sol[alev], cor[alev][0], 0, 0, ncomp, nghost);
1954 if (alev != finest_amr_lev) {
1955 LocalAdd(cor_hold[alev][0], cor[alev][0], 0, 0, ncomp, nghost);
1959 computeResWithCrseCorFineCor(alev);
1963 LocalAdd(sol[alev], cor[alev][0], 0, 0, ncomp, nghost);
1965 if (alev != finest_amr_lev) {
1966 LocalAdd(cor[alev][0], cor_hold[alev][0], 0, 0, ncomp, nghost);
1970 linop.averageDownAndSync(sol);
1973template <
typename MF>
1978 const int mglev = 0;
1979 mgVcycle(amrlev, mglev);
1984template <
typename MF>
1990 const int mglev_bottom = linop.NMGLevels(amrlev) - 1;
1992 for (
int mglev = mglev_top; mglev < mglev_bottom; ++mglev)
1994 BL_PROFILE_VAR(
"MLMG::mgVcycle_down::"+std::to_string(mglev), blp_mgv_down_lev);
1999 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
2000 <<
" DN: Norm before smooth " <<
norm <<
"\n";
2003 setVal(cor[amrlev][mglev],
RT(0.0));
2004 bool skip_fillboundary =
true;
2005 linop.smooth(amrlev, mglev, cor[amrlev][mglev], res[amrlev][mglev], skip_fillboundary, nu1);
2008 computeResOfCorrection(amrlev, mglev);
2013 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
2014 <<
" DN: Norm after smooth " <<
norm <<
"\n";
2018 linop.restriction(amrlev, mglev+1, res[amrlev][mglev+1], rescor[amrlev][mglev]);
2027 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
2028 <<
" DN: Norm before bottom " <<
norm <<
"\n";
2033 computeResOfCorrection(amrlev, mglev_bottom);
2035 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
2036 <<
" UP: Norm after bottom " <<
norm <<
"\n";
2044 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
2045 <<
" Norm before smooth " <<
norm <<
"\n";
2047 setVal(cor[amrlev][mglev_bottom],
RT(0.0));
2048 bool skip_fillboundary =
true;
2049 linop.smooth(amrlev, mglev_bottom, cor[amrlev][mglev_bottom],
2050 res[amrlev][mglev_bottom], skip_fillboundary, nu1);
2053 computeResOfCorrection(amrlev, mglev_bottom);
2055 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
2056 <<
" Norm after smooth " <<
norm <<
"\n";
2061 for (
int mglev = mglev_bottom-1; mglev >= mglev_top; --mglev)
2063 BL_PROFILE_VAR(
"MLMG::mgVcycle_up::"+std::to_string(mglev), blp_mgv_up_lev);
2065 addInterpCorrection(amrlev, mglev);
2068 computeResOfCorrection(amrlev, mglev);
2070 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
2071 <<
" UP: Norm before smooth " <<
norm <<
"\n";
2073 linop.smooth(amrlev, mglev, cor[amrlev][mglev], res[amrlev][mglev],
false, nu2);
2075 if (cf_strategy == CFStrategy::ghostnodes) { computeResOfCorrection(amrlev, mglev); }
2079 computeResOfCorrection(amrlev, mglev);
2081 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
2082 <<
" UP: Norm after smooth " <<
norm <<
"\n";
2090template <
typename MF>
2097 auto* pf = linop.Factory(0);
2098 auto is_all_regular = [pf] () {
2107 AMREX_ASSERT(linop.isCellCentered() || is_all_regular());
2110 const int amrlev = 0;
2111 const int mg_bottom_lev = linop.NMGLevels(amrlev) - 1;
2113 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(amrlev)); }
2115 for (
int mglev = 1; mglev <= mg_bottom_lev; ++mglev)
2117 linop.avgDownResMG(mglev, res[amrlev][mglev], res[amrlev][mglev-1]);
2122 for (
int mglev = mg_bottom_lev-1; mglev >= 0; --mglev)
2125 interpCorrection(amrlev, mglev);
2128 computeResOfCorrection(amrlev, mglev);
2130 LocalCopy(res[amrlev][mglev], rescor[amrlev][mglev], 0, 0, ncomp, nghost);
2133 std::swap(cor[amrlev][mglev], cor_hold[amrlev][mglev]);
2134 mgVcycle(amrlev, mglev);
2135 LocalAdd(cor[amrlev][mglev], cor_hold[amrlev][mglev], 0, 0, ncomp, nghost);
2142template <
typename MF>
2148 NSolve(*ns_mlmg, *ns_sol, *ns_rhs);
2152 actualBottomSolve();
2156template <
typename MF>
2164 MF
const& res_bottom = res[0].back();
2175 RT(-1.0),
RT(-1.0));
2177 linop.copyNSolveSolution(cor[0].back(), a_sol);
2180template <
typename MF>
2185 m_niters_cg.push_back(niters);
2188 const int amrlev = 0;
2189 const int mglev = linop.NMGLevels(amrlev) - 1;
2190 auto&
x = cor[amrlev][mglev];
2191 auto& b = res[amrlev][mglev];
2192 const int n = (ret==0) ? nub : nuf;
2193 linop.smooth(amrlev, mglev,
x, b,
false, n);
2196template <
typename MF>
2202 if (!linop.isBottomActive()) {
return; }
2207 struct PopGuard { ~PopGuard () { ParallelContext::pop(); } } pop_guard;
2209 const int amrlev = 0;
2210 const int mglev = linop.NMGLevels(amrlev) - 1;
2211 auto&
x = cor[amrlev][mglev];
2212 auto& b = res[amrlev][mglev];
2218 bool skip_fillboundary =
true;
2219 linop.smooth(amrlev, mglev,
x, b, skip_fillboundary, nuf);
2225 if (linop.isBottomSingular() && linop.getEnforceSingularSolvable())
2228 raii_b = linop.make(amrlev, mglev, ng,
2233 makeSolvable(amrlev,mglev,*bottom_b);
2238#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
2239 if constexpr (std::is_same<MF,MultiFab>()) {
2240 bottomSolveWithHypre(
x, *bottom_b);
2244 amrex::Abort(
"Using Hypre as bottom solver not supported in this case");
2249#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
2250 if constexpr (std::is_same<MF,MultiFab>()) {
2251 bottomSolveWithPETSc(
x, *bottom_b);
2255 amrex::Abort(
"Using PETSc as bottom solver not supported in this case");
2260 if constexpr (std::is_same<MF,MultiFab>()) {
2261 bottomSolveWithAlgMG(
x, *bottom_b);
2263 amrex::Abort(
"MLMG: AlgMG is only supported for MultiFab");
2268 linop.customBottomSolve(
this,
x, *bottom_b, bottom_reltol, bottom_abstol,
2281 int ret = bottomSolveWithCG(
x, *bottom_b, cg_type);
2295 ret = bottomSolveWithCG(
x, *bottom_b, cg_type);
2309 if (! timer.empty()) {
2314template <
typename MF>
2324 if (cf_strategy == CFStrategy::ghostnodes) { cg_solver.
setNGhost(linop.getNGrow()); }
2326 int ret = cg_solver.
solve(
x, b, bottom_reltol, bottom_abstol);
2327 if (ret != 0 && verbose > 1) {
2328 amrex::Print() << print_ident <<
"MLMG: Bottom solve failed.\n";
2332 if (ret != 0 && ret != 9) {
2340template <
typename MF>
2346 const int mglev = 0;
2347 for (
int alev = amrlevmax; alev >= 0; --alev) {
2348 const MF* crse_bcdata = (alev > 0) ? &(sol[alev-1]) :
nullptr;
2349 linop.solutionResidual(alev, res[alev][mglev], sol[alev], rhs[alev], crse_bcdata);
2350 if (alev < finest_amr_lev) {
2351 linop.reflux(alev, res[alev][mglev], sol[alev], rhs[alev],
2352 res[alev+1][mglev], sol[alev+1], rhs[alev+1]);
2358template <
typename MF>
2363 const MF* crse_bcdata = (alev > 0) ? &(sol[alev-1]) :
nullptr;
2364 linop.solutionResidual(alev, res[alev][0], sol[alev], rhs[alev], crse_bcdata);
2368template <
typename MF>
2372 BL_PROFILE(
"MLMG::computeResWithCrseSolFineCor()");
2375 if (cf_strategy == CFStrategy::ghostnodes) {
2376 nghost =
IntVect(std::min(linop.getNGrow(falev),linop.getNGrow(calev)));
2379 MF& crse_sol = sol[calev];
2380 const MF& crse_rhs = rhs[calev];
2381 MF& crse_res = res[calev][0];
2383 MF& fine_sol = sol[falev];
2384 const MF& fine_rhs = rhs[falev];
2385 MF& fine_cor = cor[falev][0];
2386 MF& fine_res = res[falev][0];
2387 MF& fine_rescor = rescor[falev][0];
2389 const MF* crse_bcdata = (calev > 0) ? &(sol[calev-1]) :
nullptr;
2390 linop.solutionResidual(calev, crse_res, crse_sol, crse_rhs, crse_bcdata);
2392 linop.correctionResidual(falev, 0, fine_rescor, fine_cor, fine_res, BCMode::Homogeneous);
2393 LocalCopy(fine_res, fine_rescor, 0, 0, ncomp, nghost);
2395 linop.reflux(calev, crse_res, crse_sol, crse_rhs, fine_res, fine_sol, fine_rhs);
2397 linop.avgDownResAmr(calev, crse_res, fine_res);
2401template <
typename MF>
2405 BL_PROFILE(
"MLMG::computeResWithCrseCorFineCor()");
2408 if (cf_strategy == CFStrategy::ghostnodes) {
2409 nghost =
IntVect(linop.getNGrow(falev));
2412 const MF& crse_cor = cor[falev-1][0];
2414 MF& fine_cor = cor [falev][0];
2415 MF& fine_res = res [falev][0];
2416 MF& fine_rescor = rescor[falev][0];
2419 linop.correctionResidual(falev, 0, fine_rescor, fine_cor, fine_res,
2420 BCMode::Inhomogeneous, &crse_cor);
2421 LocalCopy(fine_res, fine_rescor, 0, 0, ncomp, nghost);
2425template <
typename MF>
2432 if (cf_strategy == CFStrategy::ghostnodes) {
2433 nghost =
IntVect(linop.getNGrow(alev));
2436 MF & crse_cor = cor[alev-1][0];
2437 MF & fine_cor = cor[alev ][0];
2439 const Geometry& crse_geom = linop.Geom(alev-1,0);
2442 int ng_dst = linop.isCellCentered() ? 1 : 0;
2443 if (cf_strategy == CFStrategy::ghostnodes)
2445 ng_src = linop.getNGrow(alev-1);
2446 ng_dst = linop.getNGrow(alev-1);
2447 if constexpr (IsMultiFabLike_v<MF>) {
2450 amrex::Abort(
"MLMG: CFStrategy::ghostnodes not supported for non-MultiFab like types");
2454 MF cfine = linop.makeCoarseAmr(alev,
IntVect(ng_dst),
2460 linop.interpolationAmr(alev, fine_cor, cfine, nghost);
2466template <
typename MF>
2472 MF& crse_cor = cor[alev][mglev+1];
2473 MF& fine_cor = cor[alev][mglev ];
2474 linop.interpAssign(alev, mglev, fine_cor, crse_cor);
2478template <
typename MF>
2484 const MF& crse_cor = cor[alev][mglev+1];
2485 MF& fine_cor = cor[alev][mglev ];
2490 if (linop.isMFIterSafe(alev, mglev, mglev+1))
2496 cfine = linop.makeCoarseMG(alev, mglev,
IntVect(0),
2502 linop.interpolation(alev, mglev, fine_cor, *cmf);
2509template <
typename MF>
2514 MF &
x = cor[amrlev][mglev];
2515 const MF& b = res[amrlev][mglev];
2516 MF & r = rescor[amrlev][mglev];
2517 linop.correctionResidual(amrlev, mglev, r,
x, b, BCMode::Homogeneous);
2521template <
typename MF>
2526 return linop.normInf(alev, res[alev][0], local);
2530template <
typename MF>
2536 for (
int alev = 0; alev <= alevmax; ++alev)
2538 r = std::max(r, ResNormInf(alev,
true));
2545template <
typename MF>
2551 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
2552 auto t = linop.normInf(alev, rhs[alev],
true);
2559template <
typename MF>
2563 auto const&
offset = linop.getSolvabilityOffset(0, 0, rhs[0]);
2565 for (
int c = 0; c < ncomp; ++c) {
2566 amrex::Print() << print_ident <<
"MLMG: Subtracting " <<
offset[c] <<
" from rhs component "
2570 for (
int alev = 0; alev < namrlevs; ++alev) {
2571 linop.fixSolvabilityByOffset(alev, 0, rhs[alev],
offset);
2575template <
typename MF>
2579 auto const&
offset = linop.getSolvabilityOffset(amrlev, mglev, mf);
2581 for (
int c = 0; c < ncomp; ++c) {
2583 <<
" from mf component c = " << c
2584 <<
" on level (" << amrlev <<
", " << mglev <<
")\n";
2587 linop.fixSolvabilityByOffset(amrlev, mglev, mf,
offset);
2590template <
typename MF>
2592requires (std::same_as<TMF,MultiFab>)
2608 if (m_algmg_options) { m_algmg_options(a); }
2612template <
typename MF>
2614requires (std::same_as<TMF,MultiFab>)
2620 s.applyVcycle(
x, b);
2623 s.
solve(
x, b, bottom_reltol, std::max(bottom_abstol,
RT(0)), bottom_maxiter);
2624 }
catch (std::runtime_error
const& e) {
2625 throw error(e.what());
2630template <
typename MF>
2632requires (std::same_as<TMF,MultiFab>)
2636 const int amrlev = 0;
2637 const int mglev = linop.NMGLevels(amrlev) - 1;
2641 bool const fresh = (m_algmg_bottom ==
nullptr);
2642 if (fresh) { m_algmg_bottom = linop.makeAlgMG(mglev); }
2643 configureAlgMG(*m_algmg_bottom, linop.isBottomSingular(), fresh);
2644 algmgSolve(*m_algmg_bottom,
x, b);
2646 if (linop.isSingular(amrlev) && linop.getEnforceSingularSolvable()) {
2647 makeSolvable(amrlev, mglev,
x);
2651template <
typename MF>
2653requires (std::same_as<TMF,MultiFab>)
2663 bool const fresh = (m_algmg_level0 ==
nullptr);
2664 if (fresh) { m_algmg_level0 = linop.makeAlgMG(0); }
2665 configureAlgMG(*m_algmg_level0, linop.isSingular(0), fresh);
2666 algmgSolve(*m_algmg_level0, cor[0][0], res[0][0]);
2670 linop.applyOverset(0, cor[0][0]);
2672 if (linop.isSingular(0) && linop.getEnforceSingularSolvable()) {
2673 makeSolvable(0, 0, cor[0][0]);
2676 if (! timer.empty()) {
2681template <
typename MF>
2684 RT best_norm, std::string& reason)
const
2686 RT const rnorm = norms.back();
2687 if (!amrex::isfinite(rnorm)) {
2688 reason =
"non-finite residual";
2691 if (rnorm >
RT(1.e20)*max_norm ||
2692 rnorm > hybrid_divergence_factor*best_norm) {
2693 reason =
"diverging";
2696 const int w = hybrid_stall_window;
2697 if (w > 0 &&
int(norms.
size()) > w) {
2698 const RT r_old = norms[norms.
size()-1-w];
2699 if (rnorm > std::pow(hybrid_stall_rate,
RT(w)) * r_old) {
2700 reason =
"stalling";
2707#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
2708template <
typename MF>
2710requires (std::same_as<TMF,MultiFab>)
2714 const int amrlev = 0;
2715 const int mglev = linop.NMGLevels(amrlev) - 1;
2719 if (linop.isCellCentered())
2721 if (hypre_solver ==
nullptr)
2723 hypre_solver = linop.makeHypre(hypre_interface);
2725 hypre_solver->setVerbose(bottom_verbose);
2727 hypre_solver->setHypreOptionsNamespace(hypre_options_namespace);
2729 hypre_solver->setHypreOldDefault(hypre_old_default);
2730 hypre_solver->setHypreRelaxType(hypre_relax_type);
2731 hypre_solver->setHypreRelaxOrder(hypre_relax_order);
2732 hypre_solver->setHypreNumSweeps(hypre_num_sweeps);
2733 hypre_solver->setHypreStrongThreshold(hypre_strong_threshold);
2736 const BoxArray& ba = linop.m_grids[amrlev].back();
2737 const DistributionMapping& dm = linop.m_dmap[amrlev].back();
2738 const Geometry& geom = linop.m_geom[amrlev].back();
2740 hypre_bndry = std::make_unique<MLMGBndryT<MF>>(ba, dm, ncomp, geom);
2741 hypre_bndry->setHomogValues();
2742 const Real* dx = linop.m_geom[0][0].CellSize();
2743 IntVect crse_ratio = linop.m_coarse_data_crse_ratio.
allGT(0) ? linop.m_coarse_data_crse_ratio :
IntVect(1);
2745 0.5*dx[1]*crse_ratio[1],
2746 0.5*dx[2]*crse_ratio[2]));
2747 hypre_bndry->setLOBndryConds(linop.m_lobc, linop.m_hibc,
IntVect(-1), bclocation,
2748 linop.m_coarse_fine_bc_type);
2754 ? bottom_abstol :
Real(-1.0);
2755 hypre_solver->solve(
2756 x, b, bottom_reltol, hypre_abstol, bottom_maxiter, *hypre_bndry,
2757 linop.getMaxOrder());
2761 if (hypre_node_solver ==
nullptr)
2764 linop.makeHypreNodeLap(bottom_verbose, hypre_options_namespace);
2766 hypre_node_solver->solve(
x, b, bottom_reltol, bottom_abstol, bottom_maxiter);
2771 if (linop.isSingular(amrlev) && linop.getEnforceSingularSolvable())
2773 makeSolvable(amrlev, mglev,
x);
2778#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
2779template <
typename MF>
2781requires (std::same_as<TMF,MultiFab>)
2783MLMGT<MF>::bottomSolveWithPETSc (MF&
x,
const MF& b)
2787 if(petsc_solver ==
nullptr)
2789 petsc_solver = linop.makePETSc();
2790 petsc_solver->setVerbose(bottom_verbose);
2792 const BoxArray& ba = linop.m_grids[0].back();
2793 const DistributionMapping& dm = linop.m_dmap[0].back();
2794 const Geometry& geom = linop.m_geom[0].back();
2796 petsc_bndry = std::make_unique<MLMGBndryT<MF>>(ba, dm, ncomp, geom);
2797 petsc_bndry->setHomogValues();
2798 const Real* dx = linop.m_geom[0][0].CellSize();
2799 auto crse_ratio = linop.m_coarse_data_crse_ratio.allGT(0) ? linop.m_coarse_data_crse_ratio :
IntVect(1);
2801 0.5*dx[1]*crse_ratio[1],
2802 0.5*dx[2]*crse_ratio[2]));
2803 petsc_bndry->setLOBndryConds(linop.m_lobc, linop.m_hibc,
IntVect(-1), bclocation,
2804 linop.m_coarse_fine_bc_type);
2806 petsc_solver->solve(
x, b, bottom_reltol,
Real(-1.), bottom_maxiter, *petsc_bndry,
2807 linop.getMaxOrder());
2811template <
typename MF>
2813MLMGT<MF>::checkPoint (
const Vector<MultiFab*>& a_sol,
2814 const Vector<MultiFab const*>& a_rhs,
2815 RT a_tol_rel, RT a_tol_abs,
const char* a_file_name)
const
2817 std::string file_name(a_file_name);
2822 std::string HeaderFileName(std::string(a_file_name)+
"/Header");
2823 std::ofstream HeaderFile;
2824 HeaderFile.open(HeaderFileName.c_str(), std::ofstream::out |
2825 std::ofstream::trunc |
2826 std::ofstream::binary);
2827 if( ! HeaderFile.good()) {
2831 HeaderFile.precision(17);
2835 HeaderFile << linop.name() <<
"\n"
2836 <<
"a_tol_rel = " << a_tol_rel <<
"\n"
2837 <<
"a_tol_abs = " << a_tol_abs <<
"\n"
2838 <<
"verbose = " <<
verbose <<
"\n"
2839 <<
"max_iters = " << max_iters <<
"\n"
2840 <<
"nu1 = " << nu1 <<
"\n"
2841 <<
"nu2 = " << nu2 <<
"\n"
2842 <<
"nuf = " << nuf <<
"\n"
2843 <<
"nub = " << nub <<
"\n"
2844 <<
"max_fmg_iters = " << max_fmg_iters <<
"\n"
2845 <<
"bottom_solver = " <<
static_cast<int>(bottom_solver) <<
"\n"
2846 <<
"bottom_verbose = " << bottom_verbose <<
"\n"
2847 <<
"bottom_maxiter = " << bottom_maxiter <<
"\n"
2848 <<
"bottom_reltol = " << bottom_reltol <<
"\n"
2849 <<
"convergence_norm = " << norm_name <<
"\n"
2850 <<
"namrlevs = " << namrlevs <<
"\n"
2851 <<
"finest_amr_lev = " << finest_amr_lev <<
"\n"
2852 <<
"linop_prepared = " << linop_prepared <<
"\n"
2853 <<
"solve_called = " << solve_called <<
"\n";
2855 for (
int ilev = 0; ilev <= finest_amr_lev; ++ilev) {
2862 for (
int ilev = 0; ilev <= finest_amr_lev; ++ilev) {
2863 VisMF::Write(*a_sol[ilev], file_name+
"/Level_"+std::to_string(ilev)+
"/sol");
2864 VisMF::Write(*a_rhs[ilev], file_name+
"/Level_"+std::to_string(ilev)+
"/rhs");
2867 linop.checkPoint(file_name+
"/linop");
2870template <
typename MF>
2874 print_ident.resize(print_ident.size()+4,
' ');
2877template <
typename MF>
2881 if (print_ident.size() > 4) {
2882 print_ident.resize(print_ident.size()-4,
' ');
2884 print_ident.clear();
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:562
#define BL_PROFILE_VAR_STOP(vname)
Definition AMReX_BLProfiler.H:574
#define BL_PROFILE_VAR(fname, vname)
Definition AMReX_BLProfiler.H:571
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
Enum reflection utilities and the AMREX_ENUM macro.
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1139
GpuArray< MultiArray4< Real const >, 3 > s
Definition AMReX_MLEBNodeFDLaplacian.cpp:214
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Algebraic multigrid solver for SpMatrix / AlgVector systems.
Definition AMReX_AlgMG.H:264
void setSingular(bool b)
Definition AMReX_AlgMG.H:330
void setPrintIndentation(std::string s)
Prefix of the lines the solver prints, e.g. to nest them in MLMG output.
Definition AMReX_AlgMG.H:286
void setThrowException(bool b)
Definition AMReX_AlgMG.H:370
void setVerbose(int v)
Definition AMReX_AlgMG.H:284
void setKrylovSolver(KrylovSolver a)
Krylov solver with the V-cycle as preconditioner (see KrylovSolver). Default None.
Definition AMReX_AlgMG.H:347
Print on all processors of the default communicator.
Definition AMReX_Print.H:113
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:681
static bool SameRefs(const BoxArray &lhs, const BoxArray &rhs)
whether two BoxArrays share the same data
Definition AMReX_BoxArray.H:1251
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:51
static bool SameRefs(const DistributionMapping &lhs, const DistributionMapping &rhs)
Return true if lhs and rhs share the same underlying Ref.
Definition AMReX_DistributionMapping.H:295
Definition AMReX_EBFabFactory.H:32
bool isAllRegular() const noexcept
Definition AMReX_EBFabFactory.cpp:232
Solve using GMRES with multigrid as preconditioner.
Definition AMReX_GMRES_MLMG.H:28
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:85
Periodicity periodicity() const noexcept
Return the Periodicity based on the length of the domain.
Definition AMReX_Geometry.H:424
Interface
HYPRE interface modes supported.
Definition AMReX_Hypre.H:70
__host__ __device__ constexpr bool allGT(const IntVectND< dim > &rhs) const noexcept
Returns true if this is greater than argument for all components. NOTE: This is NOT a strict weak ord...
Definition AMReX_IntVect.H:517
__host__ __device__ constexpr IntVectND< new_dim > resize(int fill_extra=0) const noexcept
Returns a new IntVectND of size new_dim by either shrinking or expanding this IntVectND.
Definition AMReX_IntVect.H:889
__host__ static __device__ constexpr IntVectND< dim > TheDimensionVector(int d) noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:790
Algebraic system of one MG level of AMR level 0 of an MLLinOp, solved with AlgMG.
Definition AMReX_MLAlgMG.H:25
CG-family solvers (BiCGStab or CG) for use as the bottom solver in MLMG.
Definition AMReX_MLCGSolver.H:21
void setSolver(Type _typ) noexcept
Switch between BiCGStab and CG after construction.
Definition AMReX_MLCGSolver.H:48
void setVerbose(int _verbose)
Control how much logging is emitted (0 = silent).
Definition AMReX_MLCGSolver.H:72
int getNumIters() const noexcept
Iteration count from the last solve* call (or -1 if unused).
Definition AMReX_MLCGSolver.H:151
void setInitSolnZeroed(bool _sol_zeroed)
Definition AMReX_MLCGSolver.H:99
int solve(MF &solnL, const MF &rhsL, RT eps_rel, RT eps_abs)
Solve Lp(solnL)=rhsL to the requested tolerance.
Definition AMReX_MLCGSolver.H:176
Type
Definition AMReX_MLCGSolver.H:27
void setNGhost(int _nghost)
Set the number of grow cells used when allocating temporaries.
Definition AMReX_MLCGSolver.H:108
void setMaxIter(int _maxiter)
Cap the number of Krylov iterations performed.
Definition AMReX_MLCGSolver.H:81
void setPrintIndentation(std::string s)
Prefix printed messages (e.g., to indent per level).
Definition AMReX_MLCGSolver.H:90
Abstract base class for multilevel linear operators used by MLMG and the bottom solvers.
Definition AMReX_MLLinOp.H:139
typename FabDataType< MF >::fab_type FAB
Definition AMReX_MLLinOp.H:149
typename FabDataType< MF >::value_type RT
Definition AMReX_MLLinOp.H:150
Definition AMReX_MLMG.H:44
Definition AMReX_MLMG.H:39
void prepareForFluxes(Vector< MF const * > const &a_sol)
Build boundary caches needed by getFluxes()/compFluxes.
Definition AMReX_MLMG.H:1231
void setBottomVerbose(int v) noexcept
Verbosity for the bottom solver (0 silent).
Definition AMReX_MLMG.H:388
void setMaxFmgIter(int n) noexcept
Cap the number of FMG cycles executed.
Definition AMReX_MLMG.H:294
RT MLResNormInf(int alevmax, bool local=false)
Composite infinity norm of the residual up to level alevmax.
Definition AMReX_MLMG.H:2532
void postCG(int ret, int niters=-1)
Post CG smoothing.
Definition AMReX_MLMG.H:2182
RT MLRhsNormInf(bool local=false)
Composite infinity norm of the RHS.
Definition AMReX_MLMG.H:2547
void setNoGpuSync(bool do_not_sync) noexcept
Control implicit GPU synchronization inside solve().
Definition AMReX_MLMG.H:461
MLMGT(MLMGT< MF > &&)=delete
bool hybridShouldSwitch(Vector< RT > const &norms, RT max_norm, RT best_norm, std::string &reason) const
Definition AMReX_MLMG.H:2683
void actualBottomSolve()
Execute the actual bottom solve after pre-smoothing and restriction.
Definition AMReX_MLMG.H:2198
MF MFType
Definition AMReX_MLMG.H:52
BottomSolver getBottomSolver() const noexcept
Definition AMReX_MLMG.H:341
void setPreSmooth(int n) noexcept
Number of pre-smoothing passes per V-cycle.
Definition AMReX_MLMG.H:315
void setBottomToleranceAbs(RT t) noexcept
Absolute tolerance for the bottom solver.
Definition AMReX_MLMG.H:406
RT getFinalResidual() const noexcept
Definition AMReX_MLMG.H:724
void interpCorrection(int alev)
Interpolate corrections onto AMR level alev.
Definition AMReX_MLMG.H:2427
void getEBFluxes(const Vector< MF * > &a_eb_flux)
Flux into the EB wall using the internally stored solution.
Definition AMReX_MLMG.H:1452
void getGradSolution(const Vector< Array< AMF *, 3 > > &a_grad_sol, Location a_loc=Location::FaceCenter)
Populate gradient components of the converged solution.
Definition AMReX_MLMG.H:1242
void setBottomSmooth(int n) noexcept
Additional smoothing passes executed after the bottom solver.
Definition AMReX_MLMG.H:333
void setNSolve(int flag) noexcept
Enable (flag!=0) or disable the N-solve path.
Definition AMReX_MLMG.H:438
int getBottomVerbose() const
Definition AMReX_MLMG.H:262
void computeResOfCorrection(int amrlev, int mglev)
Compute the residual of the correction equation on (amrlev,mglev).
Definition AMReX_MLMG.H:2511
void applyPrecond(const Vector< MF * > &out, const Vector< MF * > &in)
Apply the linear operator as a preconditioner (out = L(in)).
Definition AMReX_MLMG.H:1623
void setCFStrategy(CFStrategy a_cf_strategy) noexcept
Select the coarse-fine synchronization strategy.
Definition AMReX_MLMG.H:382
void computeResWithCrseCorFineCor(int falev)
Residual update using coarse correction / fine correction.
Definition AMReX_MLMG.H:2403
void NSolve(MLMGT< MF > &a_solver, MF &a_sol, MF &a_rhs)
Perform an NSolve using an MLMGT wrapper.
Definition AMReX_MLMG.H:2158
typename MLLinOpT< MF >::Location Location
Definition AMReX_MLMG.H:57
void apply(const Vector< MF * > &out, const Vector< MF * > &in)
out = L(in). Note that, if no actual solve is needed, one could turn off multigrid coarsening by cons...
Definition AMReX_MLMG.H:1546
void getFluxes(const Vector< Array< AMF *, 3 > > &a_flux, Location a_loc=Location::FaceCenter)
Face-centered flux helper (-b grad(phi) for alpha a - beta div(b grad)).
Definition AMReX_MLMG.H:1273
void setNSolveGridSize(int s) noexcept
Set the tile size used for N-solve builds.
Definition AMReX_MLMG.H:444
void setVerbose(int v) noexcept
Set the main solver verbosity (0 silent).
Definition AMReX_MLMG.H:282
MultigridType getMultigridType() const noexcept
Definition AMReX_MLMG.H:345
void computeMLResidual(int amrlevmax)
Compute the composite residual norm up to AMR level amrlevmax.
Definition AMReX_MLMG.H:2342
RT getInitResidual() const noexcept
Definition AMReX_MLMG.H:722
int getNumIters() const noexcept
Definition AMReX_MLMG.H:727
void setPostSmooth(int n) noexcept
Number of post-smoothing passes per V-cycle.
Definition AMReX_MLMG.H:321
void mgVcycle(int amrlev, int mglev)
Run a multigrid V-cycle on (amrlev,mglev).
Definition AMReX_MLMG.H:1986
void prepareForNSolve()
Prepare the NSolve path.
Definition AMReX_MLMG.H:1865
RT precond(Vector< MF * > const &a_sol, Vector< MF const * > const &a_rhs, RT a_tol_rel, RT a_tol_abs)
Apply MLMG as a right-preconditioner with relaxed tolerances.
Definition AMReX_MLMG.H:1213
void setHybridStallCriterion(int window, RT rate) noexcept
Hybrid mode: switch to AlgMG when the residual has not dropped by rate per iteration on average over ...
Definition AMReX_MLMG.H:371
void makeSolvable()
Adjust RHS/solution to satisfy null-space constraints.
Definition AMReX_MLMG.H:2561
void setBottomSolver(BottomSolver s) noexcept
Select the bottom solver type (e.g., CG, BiCGStab, Hypre, PETSc).
Definition AMReX_MLMG.H:340
void preparePrecond()
Prepare preconditioner-specific caches (e.g., boundary data).
Definition AMReX_MLMG.H:1857
void incPrintIdentation()
Increase the indentation used when printing solver logs.
Definition AMReX_MLMG.H:2872
typename MLLinOpT< MF >::RT RT
Definition AMReX_MLMG.H:54
void setThrowException(bool t) noexcept
Control behavior when the solve fails to converge or blows up.
Definition AMReX_MLMG.H:276
void decPrintIdentation()
Decrease the indentation used when printing solver logs.
Definition AMReX_MLMG.H:2879
void setFixedIter(int nit) noexcept
Set the number of fixed MLMG iterations (convergence may still exit early if the residual is already ...
Definition AMReX_MLMG.H:301
void setMultigridType(MultigridType t) noexcept
Select how AMR level 0 is solved. See MultigridType.
Definition AMReX_MLMG.H:344
Vector< RT > const & getResidualHistory() const noexcept
Definition AMReX_MLMG.H:726
void prepareLinOp()
Finalize operator-dependent metadata before iterating.
Definition AMReX_MLMG.H:1829
void setPrecondIter(int nit) noexcept
Set how many MLMG iterations the preconditioner executes per Krylov call (still subject to early-conv...
Definition AMReX_MLMG.H:308
CFStrategy
Definition AMReX_MLMG.H:61
void prepareForSolve(Vector< AMF * > const &a_sol, Vector< AMF const * > const &a_rhs)
Prepare linear operators, coefficients, and RHS data prior to solving.
Definition AMReX_MLMG.H:1635
int bottomSolveWithCG(MF &x, const MF &b, typename MLCGSolverT< MF >::Type type)
Bottom solve using CG/BiCGStab implemented in MLCGSolverT.
Definition AMReX_MLMG.H:2316
void setAlwaysUseBNorm(int flag) noexcept
Deprecated flag for forcing B-norm convergence checks.
Definition AMReX_MLMG.H:867
bool usedAlgMG() const noexcept
Definition AMReX_MLMG.H:348
void compResidual(const Vector< MF * > &a_res, const Vector< MF * > &a_sol, const Vector< MF const * > &a_rhs)
Compute multilevel residuals a_rhs - L(a_sol) on each AMR level.
Definition AMReX_MLMG.H:1478
void miniCycle(int amrlev)
Execute a per-level mini cycle.
Definition AMReX_MLMG.H:1975
RT solve(std::initializer_list< AMF * > a_sol, std::initializer_list< AMF const * > a_rhs, RT a_tol_rel, RT a_tol_abs, const char *checkpoint_file=nullptr)
Convenience initializer-list overload that forwards to the Vector-based solve.
void setFinalFillBC(int flag) noexcept
Force a FillBoundary at the end of the solve (nonzero enables).
Definition AMReX_MLMG.H:429
typename MLLinOpT< MF >::BCMode BCMode
Definition AMReX_MLMG.H:56
void setConvergenceNormType(MLMGNormType norm) noexcept
Choose the norm used for convergence tests.
Definition AMReX_MLMG.H:422
void setHybridDivergenceFactor(RT f) noexcept
Definition AMReX_MLMG.H:376
void computeResWithCrseSolFineCor(int calev, int falev)
Residual update using coarse solution / fine correction.
Definition AMReX_MLMG.H:2370
MLMGT< MF > & operator=(MLMGT< MF > const &)=delete
MLMGT(MLLinOpT< MF > &a_lp)
Definition AMReX_MLMG.H:858
void computeResidual(int alev)
Compute the residual on AMR level alev.
Definition AMReX_MLMG.H:2360
MLLinOpT< MF > & getLinOp()
Definition AMReX_MLMG.H:730
typename MLLinOpT< MF >::FAB FAB
Definition AMReX_MLMG.H:53
RT getBottomToleranceAbs() const noexcept
Definition AMReX_MLMG.H:407
int numAMRLevels() const noexcept
Definition AMReX_MLMG.H:431
MLMGT(MLMGT< MF > const &)=delete
void mgFcycle()
Run an FMG cycle starting from the coarsest grid.
Definition AMReX_MLMG.H:2092
RT getInitRHS() const noexcept
Definition AMReX_MLMG.H:720
void algmgSolve(MLAlgMG &s, MF &x, MF const &b)
Definition AMReX_MLMG.H:2616
RT ResNormInf(int alev, bool local=false)
Infinity norm of the residual on level alev.
Definition AMReX_MLMG.H:2523
Vector< int > const & getNumCGIters() const noexcept
Definition AMReX_MLMG.H:728
void bottomSolveWithAlgMG(MF &x, const MF &b)
AlgMG on the bottom MG level (MultiFab, single component only).
Definition AMReX_MLMG.H:2634
void bottomSolve()
Execute the configured bottom solver (Hypre, PETSc, CG, etc.).
Definition AMReX_MLMG.H:2144
void setAlgMGOptions(std::function< void(AlgMG< RT > &)> f)
Adjust the AlgMG solvers MLMG builds (level 0 and bottom).
Definition AMReX_MLMG.H:360
void setBottomTolerance(RT t) noexcept
Relative tolerance for the bottom solver.
Definition AMReX_MLMG.H:400
void setFinalSmooth(int n) noexcept
Number of smoothing passes when MLMG is used standalone (final smooth).
Definition AMReX_MLMG.H:327
void addInterpCorrection(int alev, int mglev)
Add interpolated corrections to (alev,mglev) data.
Definition AMReX_MLMG.H:2480
int getVerbose() const
Definition AMReX_MLMG.H:261
void algmgLevel0Solve()
Definition AMReX_MLMG.H:2655
RT solve(const Vector< AMF * > &a_sol, const Vector< AMF const * > &a_rhs, RT a_tol_rel, RT a_tol_abs, const char *checkpoint_file=nullptr)
Solve the multilevel system; optional checkpoint_file is for debugging only.
void setBottomMaxIter(int n) noexcept
Cap the number of iterations inside the bottom solver.
Definition AMReX_MLMG.H:394
void configureAlgMG(MLAlgMG &s, bool singular, bool with_options)
Definition AMReX_MLMG.H:2594
void oneIter(int iter)
Execute a single multigrid iteration (FMG or V-cycle).
Definition AMReX_MLMG.H:1898
void setMaxIter(int n) noexcept
Cap the number of MLMG iterations executed.
Definition AMReX_MLMG.H:288
This class provides the user with a few print options.
Definition AMReX_Print.H:35
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
Long size() const noexcept
Definition AMReX_Vector.H:54
static Long Write(const FabArray< FArrayBox > &mf, const std::string &name, VisMF::How how=NFiles, bool set_ghost=false)
Write a FabArray<FArrayBox> to disk in a "smart" way. Returns the total number of bytes written on th...
Definition AMReX_VisMF.cpp:980
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a copy of b converted to the nodal flags typ.
Definition AMReX_Box.H:1630
std::array< T, N > Array
Definition AMReX_Array.H:31
Arena * The_Async_Arena()
Definition AMReX_Arena.cpp:839
void Max(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:133
#define AMREX_ENUM(CLASS,...)
Declare a scoped enum with reflection support.
Definition AMReX_Enum.H:270
std::string getEnumNameString(T const &v)
Get the name string of an enum value.
Definition AMReX_Enum.H:190
constexpr int relax_order
Definition AMReX_Hypre.H:45
constexpr int relax_type
Definition AMReX_Hypre.H:44
constexpr bool old_default
Falgout coarsening with modified classical interpolation.
Definition AMReX_Hypre.H:39
void push(MPI_Comm c)
Definition AMReX_ParallelContext.H:105
void BarrierSub() noexcept
Definition AMReX_ParallelContext.H:88
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
int MyProcSub() noexcept
my sub-rank in current frame
Definition AMReX_ParallelContext.H:76
bool IOProcessorSub() noexcept
Am IO processor for current frame?
Definition AMReX_ParallelContext.H:80
int verbose
Definition AMReX.cpp:113
Definition AMReX_Amr.cpp:50
MultigridType
How MLMG solves the coarsest AMR level.
Definition AMReX_MLMG.H:34
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:273
void FileOpenFailed(const std::string &file)
Output a message and abort when couldn't open the file.
Definition AMReX_Utility.cpp:116
std::array< T const *, 3 > GetArrOfConstPtrs(const std::array< T, 3 > &a) noexcept
Create an array of const-qualified pointers from an array of objects.
Definition AMReX_Array.H:1079
void EB_average_face_to_cellcenter(MultiFab &ccmf, int dcomp, const Array< MultiFab const *, 3 > &fmf)
Average face-centered values to cell centers.
Definition AMReX_EBMultiFabUtil.cpp:809
__host__ __device__ T norm(const GpuComplex< T > &a_z) noexcept
Return the norm (magnitude squared) of a complex number.
Definition AMReX_GpuComplex.H:349
void average_down(const MultiFab &S_fine, MultiFab &S_crse, const Geometry &fgeom, const Geometry &cgeom, int scomp, int ncomp, int rr)
Definition AMReX_MultiFabUtil.cpp:359
void Scale(MF &dst, typename MF::value_type val, int scomp, int ncomp, int nghost)
dst *= val
Definition AMReX_FabArrayUtility.H:2175
BoxArray const & boxArray(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.boxArray().
Definition AMReX_FabArrayBase.cpp:2949
DistributionMapping const & DistributionMap(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.DistributionMap().
Definition AMReX_FabArrayBase.cpp:2954
void average_face_to_cellcenter(MultiFab &cc, int dcomp, const Vector< const MultiFab * > &fc, IntVect const &ng_vect)
Definition AMReX_MultiFabUtil.cpp:156
void EB_set_covered(MultiFab &mf, Real val)
Fill all covered cells with a single value val.
Definition AMReX_EBMultiFabUtil.cpp:21
double second() noexcept
Definition AMReX_Utility.cpp:919
std::array< T *, 3 > GetArrOfPtrs(std::array< T, 3 > &a) noexcept
Create an array of pointers from an array of objects.
Definition AMReX_Array.H:1033
int nComp(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.nComp().
Definition AMReX_FabArrayBase.cpp:2939
void ParallelCopy(MF &dst, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &ng_src=IntVect(0), IntVect const &ng_dst=IntVect(0), Periodicity const &period=Periodicity::NonPeriodic())
dst = src w/ MPI communication
Definition AMReX_FabArrayUtility.H:2251
void UtilCreateCleanDirectory(const std::string &path, bool callbarrier=true)
Create a new directory, renaming the old one if it exists.
Definition AMReX_Utility.cpp:146
void EB_average_down(const MultiFab &S_fine, MultiFab &S_crse, const MultiFab &vol_fine, const MultiFab &vfrac_fine, int scomp, int ncomp, const IntVect &ratio)
Volume-weighted average-down from fine to coarse using EB volume fractions.
Definition AMReX_EBMultiFabUtil.cpp:336
void computeResidual(AlgVector< T, AllocV > &res, SpMatrix< T, AllocM > const &A, AlgVector< T, AllocV > const &x, AlgVector< T, AllocV > const &b)
Compute the residual res = b - A * x.
Definition AMReX_SpMV.H:345
BottomSolver
Definition AMReX_MLLinOp.H:42
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
RealVectND< 3 > RealVect
Definition AMReX_ParmParse.H:39
Vector< T * > GetVecOfPtrs(Vector< T > &a)
Definition AMReX_Vector.H:65
IntVect nGrowVect(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.nGrowVect().
Definition AMReX_FabArrayBase.cpp:2944
void LocalCopy(DMF &dst, SMF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst = src
Definition AMReX_FabArrayUtility.H:2182
void setBndry(MF &dst, typename MF::value_type val, int scomp, int ncomp)
dst = val in ghost cells.
Definition AMReX_FabArrayUtility.H:2168
MF::value_type norminf(MF const &mf, int scomp, int ncomp, IntVect const &nghost, bool local=false)
Return the infinity norm, with an MPI maximum unless local is true.
Definition AMReX_FabArrayUtility.H:2262
Vector< std::array< T *, 3 > > GetVecOfArrOfPtrs(const Vector< std::array< std::unique_ptr< T >, 3 > > &a)
Definition AMReX_Vector.H:142
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:244
MLMGNormType
Definition AMReX_MLMG.H:23
void LocalAdd(MF &dst, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst += src
Definition AMReX_FabArrayUtility.H:2190
void setVal(MF &dst, typename MF::value_type val)
dst = val
Definition AMReX_FabArrayUtility.H:2161
BCMode
Definition AMReX_MLLinOp.H:119
Location
Definition AMReX_MLLinOp.H:121
FabArray memory allocation information.
Definition AMReX_FabArray.H:73
MFInfo & SetArena(Arena *ar) noexcept
Select the Arena used for FAB storage.
Definition AMReX_FabArray.H:87