3#include <AMReX_Config.H>
20 :
public std::runtime_error
23 using std::runtime_error::runtime_error;
48 template <
typename AMF>
50 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file =
nullptr);
52 template <
typename AMF>
53 RT solve (std::initializer_list<AMF*> a_sol,
54 std::initializer_list<AMF const*> a_rhs,
55 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file =
nullptr);
58 RT a_tol_rel,
RT a_tol_abs);
60 template <
typename AMF>
62 Location a_loc = Location::FaceCenter);
64 template <
typename AMF>
66 Location a_loc = Location::FaceCenter);
71 template <
typename AMF>
73 Location a_loc = Location::FaceCenter);
75 template <
typename AMF>
77 Location a_loc = Location::FaceCenter);
79 template <
typename AMF>
82 Location a_loc = Location::FaceCenter);
84 template <
typename AMF>
86 std::initializer_list<AMF*> a_sol,
87 Location a_loc = Location::FaceCenter);
89 template <
typename AMF>
91 Location a_loc = Location::CellCenter);
93 template <
typename AMF>
94 void getFluxes (std::initializer_list<AMF*> a_flux,
95 Location a_loc = Location::CellCenter);
97 template <
typename AMF>
100 Location a_loc = Location::CellCenter);
102 template <
typename AMF>
103 void getFluxes (std::initializer_list<AMF*> a_flux,
104 std::initializer_list<AMF*> a_sol,
105 Location a_loc = Location::CellCenter);
153 [[deprecated(
"Use MLMG::setConvergenceNormType() instead.")]]
167#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
178 void setHypreOptionsNamespace(
const std::string& prefix)
noexcept
180 hypre_options_namespace = prefix;
183 void setHypreOldDefault (
bool l)
noexcept {hypre_old_default = l;}
184 void setHypreRelaxType (
int n)
noexcept {hypre_relax_type = n;}
185 void setHypreRelaxOrder (
int n)
noexcept {hypre_relax_order = n;}
186 void setHypreNumSweeps (
int n)
noexcept {hypre_num_sweeps = n;}
187 void setHypreStrongThreshold (Real t)
noexcept {hypre_strong_threshold = t;}
192 template <
typename AMF>
193 void prepareForSolve (Vector<AMF*>
const& a_sol, Vector<AMF const*>
const& a_rhs);
205 void mgVcycle (
int amrlev,
int mglev);
209 void NSolve (MLMGT<MF>& a_solver, MF& a_sol, MF& a_rhs);
229#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
230 template <
class TMF=MF,std::enable_if_t<std::is_same_v<TMF,MultiFab>,
int> = 0>
231 void bottomSolveWithHypre (MF&
x,
const MF&
b);
234#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
235 template <
class TMF=MF,std::enable_if_t<std::is_same_v<TMF,MultiFab>,
int> = 0>
236 void bottomSolveWithPETSc (MF&
x,
const MF&
b);
302#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
307 std::unique_ptr<Hypre> hypre_solver;
308 std::unique_ptr<MLMGBndryT<MF>> hypre_bndry;
309 std::unique_ptr<HypreNodeLap> hypre_node_solver;
311 std::string hypre_options_namespace =
"hypre";
312 bool hypre_old_default =
true;
313 int hypre_relax_type = 6;
314 int hypre_relax_order = 1;
315 int hypre_num_sweeps = 2;
316 Real hypre_strong_threshold = 0.25;
320#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
321 std::unique_ptr<PETScABecLap> petsc_solver;
322 std::unique_ptr<MLMGBndryT<MF>> petsc_bndry;
356 RT a_tol_rel,
RT a_tol_abs,
const char* a_file_name)
const;
360template <
typename MF>
362 : linop(a_lp), ncomp(a_lp.getNComp()), namrlevs(a_lp.NAMRLevels()),
363 finest_amr_lev(a_lp.NAMRLevels()-1)
368template <
typename MF>
379template <
typename MF>
380template <
typename AMF>
383 std::initializer_list<AMF const*> a_rhs,
384 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file) ->
RT
388 a_tol_rel, a_tol_abs, checkpoint_file);
391template <
typename MF>
392template <
typename AMF>
395 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file) ->
RT
399 bool prev_in_single_stream_region =
false;
400 bool prev_in_nosync_region =
false;
402 if (do_no_sync_gpu) {
407 if constexpr (std::is_same<AMF,MultiFab>()) {
408 if (checkpoint_file !=
nullptr) {
409 checkPoint(a_sol, a_rhs, a_tol_rel, a_tol_abs, checkpoint_file);
414 bottom_solver = linop.getDefaultBottomSolver();
417#if (defined(AMREX_USE_HYPRE) || defined(AMREX_USE_PETSC)) && (AMREX_SPACEDIM > 1)
418 if constexpr (IsFabArray_v<AMF>) {
420 int mo = linop.getMaxOrder();
421 if (a_sol[0]->hasEBFabFactory()) {
422 linop.setMaxOrder(2);
424 linop.setMaxOrder(std::min(3,mo));
430 bool is_nsolve = linop.m_parent;
434 RT& composite_norminf = m_final_resnorm0;
437 m_iter_fine_resnorm0.clear();
439 prepareForSolve(a_sol, a_rhs);
441 computeMLResidual(finest_amr_lev);
444 RT resnorm0 = MLResNormInf(finest_amr_lev, local);
445 RT rhsnorm0 = MLRhsNormInf(local);
451 amrex::Print() << print_ident <<
"MLMG: Initial rhs = " << rhsnorm0 <<
"\n"
452 << print_ident <<
"MLMG: Initial residual (resid0) = " << resnorm0 <<
"\n";
456 m_init_resnorm0 = resnorm0;
457 m_rhsnorm0 = rhsnorm0;
459 RT max_norm = resnorm0;
460 std::string norm_name =
"resid0";
463 if (rhsnorm0 >= resnorm0) {
467 norm_name =
"resid0";
476 norm_name =
"resid0";
481 const RT res_target = std::max(a_tol_abs, std::max(a_tol_rel,
RT(1.e-16))*max_norm);
483 if (!is_nsolve && resnorm0 <= res_target) {
484 composite_norminf = resnorm0;
486 amrex::Print() << print_ident <<
"MLMG: No iterations needed\n";
490 bool converged =
false;
492 const int niters = do_fixed_number_of_iters ? do_fixed_number_of_iters : max_iters;
493 for (
int iter = 0; iter < niters; ++iter)
500 computeResidual(finest_amr_lev);
502 if (is_nsolve) {
continue; }
504 RT fine_norminf = ResNormInf(finest_amr_lev);
505 m_iter_fine_resnorm0.push_back(fine_norminf);
506 composite_norminf = fine_norminf;
508 amrex::Print() << print_ident <<
"MLMG: Iteration " << std::setw(3) << iter+1 <<
" Fine resid/"
509 << norm_name <<
" = " << fine_norminf/max_norm <<
"\n";
511 bool fine_converged = (fine_norminf <= res_target);
513 if (namrlevs == 1 && fine_converged) {
515 }
else if (fine_converged) {
517 computeMLResidual(finest_amr_lev-1);
518 RT crse_norminf = MLResNormInf(finest_amr_lev-1);
520 amrex::Print() << print_ident <<
"MLMG: Iteration " << std::setw(3) << iter+1
521 <<
" Crse resid/" << norm_name <<
" = "
522 << crse_norminf/max_norm <<
"\n";
524 converged = (crse_norminf <= res_target);
525 composite_norminf = std::max(fine_norminf, crse_norminf);
532 amrex::Print() << print_ident <<
"MLMG: Final Iter. " << iter+1
533 <<
" resid, resid/" << norm_name <<
" = "
534 << composite_norminf <<
", "
535 << composite_norminf/max_norm <<
"\n";
539 if (composite_norminf >
RT(1.e20)*max_norm)
542 amrex::Print() << print_ident <<
"MLMG: Failing to converge after " << iter+1 <<
" iterations."
543 <<
" resid, resid/" << norm_name <<
" = "
544 << composite_norminf <<
", "
545 << composite_norminf/max_norm <<
"\n";
548 if ( throw_exception ) {
549 throw error(
"MLMG blew up.");
557 if (!converged && do_fixed_number_of_iters == 0) {
559 amrex::Print() << print_ident <<
"MLMG: Failed to converge after " << max_iters <<
" iterations."
560 <<
" resid, resid/" << norm_name <<
" = "
561 << composite_norminf <<
", "
562 << composite_norminf/max_norm <<
"\n";
565 if ( throw_exception ) {
566 throw error(
"MLMG failed to converge.");
577 if (linop.hasHiddenDimension()) {
578 ng_back[linop.hiddenDirection()] = 0;
580 for (
int alev = 0; alev < namrlevs; ++alev)
582 if (!sol_is_alias[alev]) {
583 LocalCopy(*a_sol[alev], sol[alev], 0, 0, ncomp, ng_back);
589 ParallelReduce::Max<double>(timer.data(), timer.size(), 0,
593 amrex::AllPrint() << print_ident <<
"MLMG: Timers: Solve = " << timer[solve_time]
594 <<
" Iter = " << timer[iter_time]
595 <<
" Bottom = " << timer[bottom_time] <<
"\n";
601 if (do_no_sync_gpu) {
606 return composite_norminf;
609template <
typename MF>
612 RT a_tol_rel,
RT a_tol_abs) ->
RT
615 std::swap(max_precond_iters, do_fixed_number_of_iters);
616 linop.beginPrecondBC();
618 auto r = solve(a_sol, a_rhs, a_tol_rel, a_tol_abs);
620 linop.endPrecondBC();
621 std::swap(max_precond_iters, do_fixed_number_of_iters);
622 precond_mode =
false;
627template <
typename MF>
631 for (
int alev = finest_amr_lev; alev >= 0; --alev) {
632 const MF* crse_bcdata = (alev > 0) ? a_sol[alev-1] :
nullptr;
633 linop.prepareForFluxes(alev, crse_bcdata);
637template <
typename MF>
638template <
typename AMF>
643 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
644 if constexpr (std::is_same<AMF,MF>()) {
645 linop.compGrad(alev, a_grad_sol[alev], sol[alev], a_loc);
648 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
649 auto const& amf = *(a_grad_sol[alev][idim]);
652 linop.compGrad(alev,
GetArrOfPtrs(grad_sol), sol[alev], a_loc);
653 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
654 LocalCopy(*a_grad_sol[alev][idim], grad_sol[idim], 0, 0, ncomp,
IntVect(0));
660template <
typename MF>
661template <
typename AMF>
668template <
typename MF>
669template <
typename AMF>
674 if (!linop.isCellCentered()) {
675 amrex::Abort(
"Calling wrong getFluxes for nodal solver");
680 if constexpr (std::is_same<AMF,MF>()) {
684 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
685 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
686 auto const& amf = *(a_flux[ilev][idim]);
691 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
692 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
693 LocalCopy(*a_flux[ilev][idim], fluxes[ilev][idim], 0, 0, ncomp,
IntVect(0));
699template <
typename MF>
700template <
typename AMF>
708template <
typename MF>
709template <
typename AMF>
716 if (!linop.isCellCentered()) {
717 amrex::Abort(
"Calling wrong getFluxes for nodal solver");
720 if constexpr (std::is_same<AMF,MF>()) {
721 linop.getFluxes(a_flux, a_sol, a_loc);
724 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
725 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
726 auto const& amf = *(a_flux[ilev][idim]);
732 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
733 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
734 LocalCopy(*a_flux[ilev][idim], fluxes[ilev][idim], 0, 0, ncomp,
IntVect(0));
740template <
typename MF>
741template <
typename AMF>
744 std::initializer_list<AMF*> a_sol,
Location a_loc)
750template <
typename MF>
751template <
typename AMF>
756 if constexpr (std::is_same<AMF,MF>()) {
760 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
761 auto const& amf = *a_flux[ilev];
765 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
771template <
typename MF>
772template <
typename AMF>
779template <
typename MF>
780template <
typename AMF>
787 if constexpr (! std::is_same<AMF,MF>()) {
788 for (
int alev = 0; alev < namrlevs; ++alev) {
793 if (linop.isCellCentered())
796 for (
int alev = 0; alev < namrlevs; ++alev) {
797 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
800 if (cf_strategy == CFStrategy::ghostnodes) { nghost = linop.getNGrow(alev); }
801 ffluxes[alev][idim].define(
amrex::convert(linop.m_grids[alev][mglev],
803 linop.m_dmap[alev][mglev], ncomp, nghost,
MFInfo(),
804 *linop.m_factory[alev][mglev]);
807 if constexpr (std::is_same<AMF,MF>()) {
812 for (
int alev = 0; alev < namrlevs; ++alev) {
821 if constexpr (std::is_same<AMF,MF>()) {
822 linop.getFluxes(a_flux, a_sol);
825 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
826 auto const& amf = *a_flux[ilev];
830 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
837template <
typename MF>
838template <
typename AMF>
841 std::initializer_list<AMF*> a_sol,
Location a_loc)
848template <
typename MF>
852 if (!linop.isCellCentered()) {
860template <
typename MF>
866 if (!linop.isCellCentered()) {
870 linop.getEBFluxes(a_eb_flux, a_sol);
874template <
typename MF>
882 if (linop.hasHiddenDimension()) { ng_sol[linop.hiddenDirection()] = 0; }
885 sol_is_alias.resize(namrlevs,
true);
886 for (
int alev = 0; alev < namrlevs; ++alev)
888 if (cf_strategy == CFStrategy::ghostnodes ||
nGrowVect(*a_sol[alev]) == ng_sol)
890 sol[alev] = linop.makeAlias(*a_sol[alev]);
891 sol_is_alias[alev] =
true;
895 if (sol_is_alias[alev])
897 sol[alev] = linop.make(alev, 0, ng_sol);
905 const auto& amrrr = linop.AMRRefRatio();
907 for (
int alev = finest_amr_lev; alev >= 0; --alev) {
908 const MF* crse_bcdata = (alev > 0) ? &(sol[alev-1]) :
nullptr;
909 const MF* prhs = a_rhs[alev];
910#if (AMREX_SPACEDIM != 3)
911 int nghost = (cf_strategy == CFStrategy::ghostnodes) ? linop.getNGrow(alev) : 0;
913 MFInfo(), *linop.Factory(alev));
915 linop.applyMetricTerm(alev, 0, rhstmp);
916 linop.unimposeNeumannBC(alev, rhstmp);
917 linop.applyInhomogNeumannTerm(alev, rhstmp);
920 linop.solutionResidual(alev, *a_res[alev], sol[alev], *prhs, crse_bcdata);
921 if (alev < finest_amr_lev) {
922 linop.reflux(alev, *a_res[alev], sol[alev], *prhs,
923 *a_res[alev+1], sol[alev+1], *a_rhs[alev+1]);
924 if (linop.isCellCentered()) {
928 average_down(*a_res[alev+1], *a_res[alev], 0, ncomp, amrrr[alev]);
935#if (AMREX_SPACEDIM != 3)
936 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
937 linop.unapplyMetricTerm(alev, 0, *a_res[alev]);
942template <
typename MF>
953 if (linop.hasHiddenDimension()) { ng_sol[linop.hiddenDirection()] = 0; }
955 for (
int alev = 0; alev < namrlevs; ++alev)
957 if (cf_strategy == CFStrategy::ghostnodes)
959 nghost = linop.getNGrow(alev);
960 in[alev] = a_in[alev];
962 else if (
nGrowVect(*a_in[alev]) == ng_sol)
964 in[alev] = a_in[alev];
969 if (cf_strategy == CFStrategy::ghostnodes) { ng =
IntVect(nghost); }
970 in_raii[alev] = linop.make(alev, 0, ng);
972 in[alev] = &(in_raii[alev]);
974 rh[alev] = linop.make(alev, 0,
IntVect(nghost));
980 for (
int alev = 0; alev < namrlevs; ++alev) {
981 linop.applyInhomogNeumannTerm(alev, rh[alev]);
984 const auto& amrrr = linop.AMRRefRatio();
986 for (
int alev = finest_amr_lev; alev >= 0; --alev) {
987 const MF* crse_bcdata = (alev > 0) ? in[alev-1] :
nullptr;
988 linop.solutionResidual(alev, *out[alev], *in[alev], rh[alev], crse_bcdata);
989 if (alev < finest_amr_lev) {
990 linop.reflux(alev, *out[alev], *in[alev], rh[alev],
991 *out[alev+1], *in[alev+1], rh[alev+1]);
992 if (linop.isCellCentered()) {
993 if constexpr (IsMultiFabLike_v<MF>) {
1000 amrex::Abort(
"MLMG: TODO average_down for non-MultiFab");
1006#if (AMREX_SPACEDIM != 3)
1007 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
1008 linop.unapplyMetricTerm(alev, 0, *out[alev]);
1012 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
1013 if (cf_strategy == CFStrategy::ghostnodes) { nghost = linop.getNGrow(alev); }
1014 Scale(*out[alev],
RT(-1), 0,
nComp(*out[alev]), nghost);
1018template <
typename MF>
1022 precond_mode =
true;
1023 linop.beginPrecondBC();
1025 linop.endPrecondBC();
1026 precond_mode =
false;
1029template <
typename MF>
1030template <
typename AMF>
1039 timer.assign(ntimers, 0.0);
1043 if (linop.hasHiddenDimension()) { ng_sol[linop.hiddenDirection()] = 0; }
1045 if (!linop_prepared) {
1046 linop.prepareForSolve();
1047 linop_prepared =
true;
1048 }
else if (linop.needsUpdate()) {
1051#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
1052 hypre_solver.reset();
1053 hypre_bndry.reset();
1054 hypre_node_solver.reset();
1057#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
1058 petsc_solver.reset();
1059 petsc_bndry.reset();
1064 sol_is_alias.resize(namrlevs,
false);
1065 for (
int alev = 0; alev < namrlevs; ++alev)
1067 if (cf_strategy == CFStrategy::ghostnodes)
1069 if constexpr (std::is_same<AMF,MF>()) {
1070 sol[alev] = linop.makeAlias(*a_sol[alev]);
1071 sol_is_alias[alev] =
true;
1073 amrex::Abort(
"Type conversion not supported for CFStrategy::ghostnodes");
1078 if (
nGrowVect(*a_sol[alev]) == ng_sol) {
1079 if constexpr (std::is_same<AMF,MF>()) {
1080 sol[alev] = linop.makeAlias(*a_sol[alev]);
1081 sol_is_alias[alev] =
true;
1084 if (!sol_is_alias[alev]) {
1085 if (!solve_called) {
1086 sol[alev] = linop.make(alev, 0, ng_sol);
1094 rhs.resize(namrlevs);
1095 for (
int alev = 0; alev < namrlevs; ++alev)
1097 if (cf_strategy == CFStrategy::ghostnodes) { ng_rhs =
IntVect(linop.getNGrow(alev)); }
1098 if (!solve_called) {
1099 rhs[alev] = linop.make(alev, 0, ng_rhs);
1101 LocalCopy(rhs[alev], *a_rhs[alev], 0, 0, ncomp, ng_rhs);
1102 linop.applyMetricTerm(alev, 0, rhs[alev]);
1103 linop.unimposeNeumannBC(alev, rhs[alev]);
1104 linop.applyInhomogNeumannTerm(alev, rhs[alev]);
1105 linop.applyOverset(alev, rhs[alev]);
1106 if ( ! precond_mode) {
1107 bool r = linop.scaleRHS(alev, &(rhs[alev]));
1113 if (factory && !factory->isAllRegular()) {
1114 if constexpr (std::is_same<MF,MultiFab>()) {
1118 amrex::Abort(
"TODO: MLMG with EB only works with MultiFab");
1124 for (
int falev = finest_amr_lev; falev > 0; --falev)
1126 linop.averageDownSolutionRHS(falev-1, sol[falev-1], rhs[falev-1], sol[falev], rhs[falev]);
1130 if (linop.isSingular(0) && linop.getEnforceSingularSolvable())
1135 IntVect ng = linop.getNGrowVectRestriction();
1136 if (cf_strategy == CFStrategy::ghostnodes) { ng = ng_rhs; }
1137 if (!solve_called) {
1138 linop.make(res, ng);
1139 linop.make(rescor, ng);
1141 for (
int alev = 0; alev <= finest_amr_lev; ++alev)
1143 const int nmglevs = linop.NMGLevels(alev);
1144 for (
int mglev = 0; mglev < nmglevs; ++mglev)
1146 setVal(res [alev][mglev],
RT(0.0));
1147 setVal(rescor[alev][mglev],
RT(0.0));
1151 if (cf_strategy != CFStrategy::ghostnodes) { ng = ng_sol; }
1153 for (
int alev = 0; alev <= finest_amr_lev; ++alev)
1155 const int nmglevs = linop.NMGLevels(alev);
1156 cor[alev].resize(nmglevs);
1157 for (
int mglev = 0; mglev < nmglevs; ++mglev)
1159 if (!solve_called) {
1161 if (cf_strategy == CFStrategy::ghostnodes) { _ng=
IntVect(linop.getNGrow(alev,mglev)); }
1162 cor[alev][mglev] = linop.make(alev, mglev, _ng);
1168 cor_hold.resize(std::max(namrlevs-1,1));
1171 const int nmglevs = linop.NMGLevels(alev);
1172 cor_hold[alev].resize(nmglevs);
1173 for (
int mglev = 0; mglev < nmglevs-1; ++mglev)
1175 if (!solve_called) {
1177 if (cf_strategy == CFStrategy::ghostnodes) { _ng=
IntVect(linop.getNGrow(alev,mglev)); }
1178 cor_hold[alev][mglev] = linop.make(alev, mglev, _ng);
1180 setVal(cor_hold[alev][mglev],
RT(0.0));
1183 for (
int alev = 1; alev < finest_amr_lev; ++alev)
1185 cor_hold[alev].resize(1);
1186 if (!solve_called) {
1188 if (cf_strategy == CFStrategy::ghostnodes) { _ng=
IntVect(linop.getNGrow(alev)); }
1189 cor_hold[alev][0] = linop.make(alev, 0, _ng);
1191 setVal(cor_hold[alev][0],
RT(0.0));
1195 || !linop.supportNSolve())
1200 if (do_nsolve && ns_linop ==
nullptr)
1206 amrex::Print() << print_ident <<
"MLMG: # of AMR levels: " << namrlevs <<
"\n"
1207 << print_ident <<
" # of MG levels on the coarsest AMR level: " << linop.NMGLevels(0)
1210 amrex::Print() << print_ident <<
" # of MG levels in N-Solve: " << ns_linop->NMGLevels(0) <<
"\n"
1211 << print_ident <<
" # of grids in N-Solve: " << ns_linop->m_grids[0][0].size() <<
"\n";
1216template <
typename MF>
1220 if (!linop_prepared) {
1221 linop.prepareForSolve();
1222 linop_prepared =
true;
1223 }
else if (linop.needsUpdate()) {
1228template <
typename MF>
1233 linop.preparePrecond();
1236template <
typename MF>
1240 if constexpr (IsMultiFabLike_v<MF>) {
1241 ns_linop = linop.makeNLinOp(nsolve_grid_size);
1244 if (cf_strategy == CFStrategy::ghostnodes) { nghost = linop.getNGrow(); }
1246 const BoxArray& ba = (*ns_linop).m_grids[0][0];
1250 if (cf_strategy == CFStrategy::ghostnodes) { ng = nghost; }
1251 ns_sol = std::make_unique<MF>(ba, dm, ncomp, ng,
MFInfo(), *(ns_linop->Factory(0,0)));
1253 if (cf_strategy == CFStrategy::ghostnodes) { ng = nghost; }
1254 ns_rhs = std::make_unique<MF>(ba, dm, ncomp, ng,
MFInfo(), *(ns_linop->Factory(0,0)));
1258 ns_linop->setLevelBC(0, ns_sol.get());
1260 ns_mlmg = std::make_unique<MLMGT<MF>>(*ns_linop);
1261 ns_mlmg->setVerbose(0);
1262 ns_mlmg->setFixedIter(1);
1263 ns_mlmg->setMaxFmgIter(20);
1270template <
typename MF>
1275 for (
int alev = finest_amr_lev; alev > 0; --alev)
1280 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(alev)); }
1281 LocalAdd(sol[alev], cor[alev][0], 0, 0, ncomp, nghost);
1284 computeResWithCrseSolFineCor(alev-1,alev);
1286 if (alev != finest_amr_lev) {
1287 std::swap(cor_hold[alev][0], cor[alev][0]);
1294 if (linop.isSingular(0) && linop.getEnforceSingularSolvable())
1296 makeSolvable(0,0,res[0][0]);
1299 if (iter < max_fmg_iters) {
1306 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(0)); }
1307 LocalAdd(sol[0], cor[0][0], 0, 0, ncomp, nghost);
1310 for (
int alev = 1; alev <= finest_amr_lev; ++alev)
1313 interpCorrection(alev);
1316 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(alev)); }
1317 LocalAdd(sol[alev], cor[alev][0], 0, 0, ncomp, nghost);
1319 if (alev != finest_amr_lev) {
1320 LocalAdd(cor_hold[alev][0], cor[alev][0], 0, 0, ncomp, nghost);
1324 computeResWithCrseCorFineCor(alev);
1328 LocalAdd(sol[alev], cor[alev][0], 0, 0, ncomp, nghost);
1330 if (alev != finest_amr_lev) {
1331 LocalAdd(cor[alev][0], cor_hold[alev][0], 0, 0, ncomp, nghost);
1335 linop.averageDownAndSync(sol);
1338template <
typename MF>
1343 const int mglev = 0;
1344 mgVcycle(amrlev, mglev);
1349template <
typename MF>
1355 const int mglev_bottom = linop.NMGLevels(amrlev) - 1;
1357 for (
int mglev = mglev_top; mglev < mglev_bottom; ++mglev)
1359 BL_PROFILE_VAR(
"MLMG::mgVcycle_down::"+std::to_string(mglev), blp_mgv_down_lev);
1364 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
1365 <<
" DN: Norm before smooth " <<
norm <<
"\n";
1368 setVal(cor[amrlev][mglev],
RT(0.0));
1369 bool skip_fillboundary =
true;
1370 linop.smooth(amrlev, mglev, cor[amrlev][mglev], res[amrlev][mglev], skip_fillboundary, nu1);
1373 computeResOfCorrection(amrlev, mglev);
1378 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
1379 <<
" DN: Norm after smooth " <<
norm <<
"\n";
1383 linop.restriction(amrlev, mglev+1, res[amrlev][mglev+1], rescor[amrlev][mglev]);
1392 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
1393 <<
" DN: Norm before bottom " <<
norm <<
"\n";
1398 computeResOfCorrection(amrlev, mglev_bottom);
1400 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
1401 <<
" UP: Norm after bottom " <<
norm <<
"\n";
1409 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
1410 <<
" Norm before smooth " <<
norm <<
"\n";
1412 setVal(cor[amrlev][mglev_bottom],
RT(0.0));
1413 bool skip_fillboundary =
true;
1414 linop.smooth(amrlev, mglev_bottom, cor[amrlev][mglev_bottom],
1415 res[amrlev][mglev_bottom], skip_fillboundary, nu1);
1418 computeResOfCorrection(amrlev, mglev_bottom);
1420 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
1421 <<
" Norm after smooth " <<
norm <<
"\n";
1426 for (
int mglev = mglev_bottom-1; mglev >= mglev_top; --mglev)
1428 BL_PROFILE_VAR(
"MLMG::mgVcycle_up::"+std::to_string(mglev), blp_mgv_up_lev);
1430 addInterpCorrection(amrlev, mglev);
1433 computeResOfCorrection(amrlev, mglev);
1435 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
1436 <<
" UP: Norm before smooth " <<
norm <<
"\n";
1438 linop.smooth(amrlev, mglev, cor[amrlev][mglev], res[amrlev][mglev],
false, nu2);
1440 if (cf_strategy == CFStrategy::ghostnodes) { computeResOfCorrection(amrlev, mglev); }
1444 computeResOfCorrection(amrlev, mglev);
1446 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
1447 <<
" UP: Norm after smooth " <<
norm <<
"\n";
1455template <
typename MF>
1462 auto* pf = linop.Factory(0);
1463 auto is_all_regular = [pf] () {
1472 AMREX_ASSERT(linop.isCellCentered() || is_all_regular());
1475 const int amrlev = 0;
1476 const int mg_bottom_lev = linop.NMGLevels(amrlev) - 1;
1478 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(amrlev)); }
1480 for (
int mglev = 1; mglev <= mg_bottom_lev; ++mglev)
1482 linop.avgDownResMG(mglev, res[amrlev][mglev], res[amrlev][mglev-1]);
1487 for (
int mglev = mg_bottom_lev-1; mglev >= 0; --mglev)
1490 interpCorrection(amrlev, mglev);
1493 computeResOfCorrection(amrlev, mglev);
1495 LocalCopy(res[amrlev][mglev], rescor[amrlev][mglev], 0, 0, ncomp, nghost);
1498 std::swap(cor[amrlev][mglev], cor_hold[amrlev][mglev]);
1499 mgVcycle(amrlev, mglev);
1500 LocalAdd(cor[amrlev][mglev], cor_hold[amrlev][mglev], 0, 0, ncomp, nghost);
1507template <
typename MF>
1513 NSolve(*ns_mlmg, *ns_sol, *ns_rhs);
1517 actualBottomSolve();
1521template <
typename MF>
1529 MF
const& res_bottom = res[0].back();
1540 RT(-1.0),
RT(-1.0));
1542 linop.copyNSolveSolution(cor[0].back(), a_sol);
1545template <
typename MF>
1551 if (!linop.isBottomActive()) {
return; }
1557 const int amrlev = 0;
1558 const int mglev = linop.NMGLevels(amrlev) - 1;
1559 auto&
x = cor[amrlev][mglev];
1560 auto&
b = res[amrlev][mglev];
1566 bool skip_fillboundary =
true;
1567 linop.smooth(amrlev, mglev,
x,
b, skip_fillboundary, nuf);
1573 if (linop.isBottomSingular() && linop.getEnforceSingularSolvable())
1576 raii_b = linop.make(amrlev, mglev, ng);
1580 makeSolvable(amrlev,mglev,*bottom_b);
1585#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
1586 if constexpr (std::is_same<MF,MultiFab>()) {
1587 bottomSolveWithHypre(
x, *bottom_b);
1591 amrex::Abort(
"Using Hypre as bottom solver not supported in this case");
1596#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
1597 if constexpr (std::is_same<MF,MultiFab>()) {
1598 bottomSolveWithPETSc(
x, *bottom_b);
1602 amrex::Abort(
"Using PETSc as bottom solver not supported in this case");
1615 int ret = bottomSolveWithCG(
x, *bottom_b, cg_type);
1625 setVal(cor[amrlev][mglev],
RT(0.0));
1626 ret = bottomSolveWithCG(
x, *bottom_b, cg_type);
1637 if (ret != 0 && ret != 9) {
1638 setVal(cor[amrlev][mglev],
RT(0.0));
1640 const int n = (ret==0) ? nub : nuf;
1641 linop.smooth(amrlev, mglev,
x,
b,
false, n);
1647 if (! timer.empty()) {
1652template <
typename MF>
1662 if (cf_strategy == CFStrategy::ghostnodes) { cg_solver.
setNGhost(linop.getNGrow()); }
1664 int ret = cg_solver.
solve(
x,
b, bottom_reltol, bottom_abstol);
1665 if (ret != 0 &&
verbose > 1) {
1666 amrex::Print() << print_ident <<
"MLMG: Bottom solve failed.\n";
1673template <
typename MF>
1679 const int mglev = 0;
1680 for (
int alev = amrlevmax; alev >= 0; --alev) {
1681 const MF* crse_bcdata = (alev > 0) ? &(sol[alev-1]) :
nullptr;
1682 linop.solutionResidual(alev, res[alev][mglev], sol[alev], rhs[alev], crse_bcdata);
1683 if (alev < finest_amr_lev) {
1684 linop.reflux(alev, res[alev][mglev], sol[alev], rhs[alev],
1685 res[alev+1][mglev], sol[alev+1], rhs[alev+1]);
1691template <
typename MF>
1696 const MF* crse_bcdata = (alev > 0) ? &(sol[alev-1]) :
nullptr;
1697 linop.solutionResidual(alev, res[alev][0], sol[alev], rhs[alev], crse_bcdata);
1701template <
typename MF>
1705 BL_PROFILE(
"MLMG::computeResWithCrseSolFineCor()");
1708 if (cf_strategy == CFStrategy::ghostnodes) {
1709 nghost =
IntVect(std::min(linop.getNGrow(falev),linop.getNGrow(calev)));
1712 MF& crse_sol = sol[calev];
1713 const MF& crse_rhs = rhs[calev];
1714 MF& crse_res = res[calev][0];
1716 MF& fine_sol = sol[falev];
1717 const MF& fine_rhs = rhs[falev];
1718 MF& fine_cor = cor[falev][0];
1719 MF& fine_res = res[falev][0];
1720 MF& fine_rescor = rescor[falev][0];
1722 const MF* crse_bcdata = (calev > 0) ? &(sol[calev-1]) :
nullptr;
1723 linop.solutionResidual(calev, crse_res, crse_sol, crse_rhs, crse_bcdata);
1725 linop.correctionResidual(falev, 0, fine_rescor, fine_cor, fine_res, BCMode::Homogeneous);
1726 LocalCopy(fine_res, fine_rescor, 0, 0, ncomp, nghost);
1728 linop.reflux(calev, crse_res, crse_sol, crse_rhs, fine_res, fine_sol, fine_rhs);
1730 linop.avgDownResAmr(calev, crse_res, fine_res);
1734template <
typename MF>
1738 BL_PROFILE(
"MLMG::computeResWithCrseCorFineCor()");
1741 if (cf_strategy == CFStrategy::ghostnodes) {
1742 nghost =
IntVect(linop.getNGrow(falev));
1745 const MF& crse_cor = cor[falev-1][0];
1747 MF& fine_cor = cor [falev][0];
1748 MF& fine_res = res [falev][0];
1749 MF& fine_rescor = rescor[falev][0];
1752 linop.correctionResidual(falev, 0, fine_rescor, fine_cor, fine_res,
1753 BCMode::Inhomogeneous, &crse_cor);
1754 LocalCopy(fine_res, fine_rescor, 0, 0, ncomp, nghost);
1758template <
typename MF>
1765 if (cf_strategy == CFStrategy::ghostnodes) {
1766 nghost =
IntVect(linop.getNGrow(alev));
1769 MF
const& crse_cor = cor[alev-1][0];
1770 MF & fine_cor = cor[alev ][0];
1772 const Geometry& crse_geom = linop.Geom(alev-1,0);
1775 int ng_dst = linop.isCellCentered() ? 1 : 0;
1776 if (cf_strategy == CFStrategy::ghostnodes)
1778 ng_src = linop.getNGrow(alev-1);
1779 ng_dst = linop.getNGrow(alev-1);
1782 MF cfine = linop.makeCoarseAmr(alev,
IntVect(ng_dst));
1787 linop.interpolationAmr(alev, fine_cor, cfine, nghost);
1793template <
typename MF>
1799 MF& crse_cor = cor[alev][mglev+1];
1800 MF& fine_cor = cor[alev][mglev ];
1801 linop.interpAssign(alev, mglev, fine_cor, crse_cor);
1805template <
typename MF>
1811 const MF& crse_cor = cor[alev][mglev+1];
1812 MF& fine_cor = cor[alev][mglev ];
1817 if (linop.isMFIterSafe(alev, mglev, mglev+1))
1823 cfine = linop.makeCoarseMG(alev, mglev,
IntVect(0));
1828 linop.interpolation(alev, mglev, fine_cor, *cmf);
1835template <
typename MF>
1840 MF &
x = cor[amrlev][mglev];
1841 const MF&
b = res[amrlev][mglev];
1842 MF &
r = rescor[amrlev][mglev];
1843 linop.correctionResidual(amrlev, mglev,
r,
x,
b, BCMode::Homogeneous);
1847template <
typename MF>
1852 return linop.normInf(alev, res[alev][0], local);
1856template <
typename MF>
1862 for (
int alev = 0; alev <= alevmax; ++alev)
1864 r = std::max(
r, ResNormInf(alev,
true));
1871template <
typename MF>
1877 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
1878 auto t = linop.normInf(alev, rhs[alev],
true);
1885template <
typename MF>
1889 auto const&
offset = linop.getSolvabilityOffset(0, 0, rhs[0]);
1891 for (
int c = 0; c < ncomp; ++c) {
1892 amrex::Print() << print_ident <<
"MLMG: Subtracting " <<
offset[c] <<
" from rhs component "
1896 for (
int alev = 0; alev < namrlevs; ++alev) {
1897 linop.fixSolvabilityByOffset(alev, 0, rhs[alev],
offset);
1901template <
typename MF>
1905 auto const&
offset = linop.getSolvabilityOffset(amrlev, mglev, mf);
1907 for (
int c = 0; c < ncomp; ++c) {
1909 <<
" from mf component c = " << c
1910 <<
" on level (" << amrlev <<
", " << mglev <<
")\n";
1913 linop.fixSolvabilityByOffset(amrlev, mglev, mf,
offset);
1916#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
1917template <
typename MF>
1918template <
class TMF,std::enable_if_t<std::is_same_v<TMF,MultiFab>,
int>>
1922 const int amrlev = 0;
1923 const int mglev = linop.NMGLevels(amrlev) - 1;
1927 if (linop.isCellCentered())
1929 if (hypre_solver ==
nullptr)
1931 hypre_solver = linop.makeHypre(hypre_interface);
1933 hypre_solver->setVerbose(bottom_verbose);
1935 hypre_solver->setHypreOptionsNamespace(hypre_options_namespace);
1937 hypre_solver->setHypreOldDefault(hypre_old_default);
1938 hypre_solver->setHypreRelaxType(hypre_relax_type);
1939 hypre_solver->setHypreRelaxOrder(hypre_relax_order);
1940 hypre_solver->setHypreNumSweeps(hypre_num_sweeps);
1941 hypre_solver->setHypreStrongThreshold(hypre_strong_threshold);
1944 const BoxArray& ba = linop.m_grids[amrlev].back();
1945 const DistributionMapping& dm = linop.m_dmap[amrlev].back();
1946 const Geometry& geom = linop.m_geom[amrlev].back();
1948 hypre_bndry = std::make_unique<MLMGBndryT<MF>>(ba, dm, ncomp, geom);
1949 hypre_bndry->setHomogValues();
1950 const Real* dx = linop.m_geom[0][0].CellSize();
1951 IntVect crse_ratio = linop.m_coarse_data_crse_ratio.
allGT(0) ? linop.m_coarse_data_crse_ratio :
IntVect(1);
1953 0.5*dx[1]*crse_ratio[1],
1954 0.5*dx[2]*crse_ratio[2]));
1955 hypre_bndry->setLOBndryConds(linop.m_lobc, linop.m_hibc,
IntVect(-1), bclocation,
1956 linop.m_coarse_fine_bc_type);
1960 amrex::Real hypre_abstol =
1962 ? bottom_abstol : Real(-1.0);
1963 hypre_solver->solve(
1964 x,
b, bottom_reltol, hypre_abstol, bottom_maxiter, *hypre_bndry,
1965 linop.getMaxOrder());
1969 if (hypre_node_solver ==
nullptr)
1972 linop.makeHypreNodeLap(bottom_verbose, hypre_options_namespace);
1974 hypre_node_solver->solve(
x,
b, bottom_reltol, bottom_abstol, bottom_maxiter);
1979 if (linop.isSingular(amrlev) && linop.getEnforceSingularSolvable())
1981 makeSolvable(amrlev, mglev,
x);
1986#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
1987template <
typename MF>
1988template <
class TMF,std::enable_if_t<std::is_same_v<TMF,MultiFab>,
int>>
1990MLMGT<MF>::bottomSolveWithPETSc (MF&
x,
const MF&
b)
1994 if(petsc_solver ==
nullptr)
1996 petsc_solver = linop.makePETSc();
1997 petsc_solver->setVerbose(bottom_verbose);
1999 const BoxArray& ba = linop.m_grids[0].back();
2000 const DistributionMapping& dm = linop.m_dmap[0].back();
2001 const Geometry& geom = linop.m_geom[0].back();
2003 petsc_bndry = std::make_unique<MLMGBndryT<MF>>(ba, dm, ncomp, geom);
2004 petsc_bndry->setHomogValues();
2005 const Real* dx = linop.m_geom[0][0].CellSize();
2006 auto crse_ratio = linop.m_coarse_data_crse_ratio.allGT(0) ? linop.m_coarse_data_crse_ratio :
IntVect(1);
2008 0.5*dx[1]*crse_ratio[1],
2009 0.5*dx[2]*crse_ratio[2]));
2010 petsc_bndry->setLOBndryConds(linop.m_lobc, linop.m_hibc,
IntVect(-1), bclocation,
2011 linop.m_coarse_fine_bc_type);
2013 petsc_solver->solve(
x,
b, bottom_reltol, Real(-1.), bottom_maxiter, *petsc_bndry,
2014 linop.getMaxOrder());
2018template <
typename MF>
2022 RT a_tol_rel,
RT a_tol_abs,
const char* a_file_name)
const
2024 std::string file_name(a_file_name);
2029 std::string HeaderFileName(std::string(a_file_name)+
"/Header");
2030 std::ofstream HeaderFile;
2031 HeaderFile.open(HeaderFileName.c_str(), std::ofstream::out |
2032 std::ofstream::trunc |
2033 std::ofstream::binary);
2034 if( ! HeaderFile.good()) {
2038 HeaderFile.precision(17);
2042 HeaderFile << linop.name() <<
"\n"
2043 <<
"a_tol_rel = " << a_tol_rel <<
"\n"
2044 <<
"a_tol_abs = " << a_tol_abs <<
"\n"
2045 <<
"verbose = " <<
verbose <<
"\n"
2046 <<
"max_iters = " << max_iters <<
"\n"
2047 <<
"nu1 = " << nu1 <<
"\n"
2048 <<
"nu2 = " << nu2 <<
"\n"
2049 <<
"nuf = " << nuf <<
"\n"
2050 <<
"nub = " << nub <<
"\n"
2051 <<
"max_fmg_iters = " << max_fmg_iters <<
"\n"
2052 <<
"bottom_solver = " <<
static_cast<int>(bottom_solver) <<
"\n"
2053 <<
"bottom_verbose = " << bottom_verbose <<
"\n"
2054 <<
"bottom_maxiter = " << bottom_maxiter <<
"\n"
2055 <<
"bottom_reltol = " << bottom_reltol <<
"\n"
2056 <<
"convergence_norm = " << norm_name <<
"\n"
2057 <<
"namrlevs = " << namrlevs <<
"\n"
2058 <<
"finest_amr_lev = " << finest_amr_lev <<
"\n"
2059 <<
"linop_prepared = " << linop_prepared <<
"\n"
2060 <<
"solve_called = " << solve_called <<
"\n";
2062 for (
int ilev = 0; ilev <= finest_amr_lev; ++ilev) {
2069 for (
int ilev = 0; ilev <= finest_amr_lev; ++ilev) {
2070 VisMF::Write(*a_sol[ilev], file_name+
"/Level_"+std::to_string(ilev)+
"/sol");
2071 VisMF::Write(*a_rhs[ilev], file_name+
"/Level_"+std::to_string(ilev)+
"/rhs");
2074 linop.checkPoint(file_name+
"/linop");
2077template <
typename MF>
2081 print_ident.resize(print_ident.size()+4,
' ');
2084template <
typename MF>
2088 if (print_ident.size() > 4) {
2089 print_ident.resize(print_ident.size()-4,
' ');
2091 print_ident.clear();
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:551
#define BL_PROFILE_VAR_STOP(vname)
Definition AMReX_BLProfiler.H:563
#define BL_PROFILE_VAR(fname, vname)
Definition AMReX_BLProfiler.H:560
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_ENUM(CLASS,...)
Definition AMReX_Enum.H:206
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1089
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Print on all processors of the default communicator.
Definition AMReX_Print.H:117
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:551
static bool SameRefs(const BoxArray &lhs, const BoxArray &rhs)
whether two BoxArrays share the same data
Definition AMReX_BoxArray.H:824
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:41
static bool SameRefs(const DistributionMapping &lhs, const DistributionMapping &rhs)
Definition AMReX_DistributionMapping.H:187
Definition AMReX_EBFabFactory.H:24
bool isAllRegular() const noexcept
Definition AMReX_EBFabFactory.cpp:148
Solve using GMRES with multigrid as preconditioner.
Definition AMReX_GMRES_MLMG.H:21
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:73
Periodicity periodicity() const noexcept
Definition AMReX_Geometry.H:355
Interface
Definition AMReX_Hypre.H:21
__host__ __device__ 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:423
__host__ __device__ 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:773
__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:696
Definition AMReX_MLCGSolver.H:12
void setSolver(Type _typ) noexcept
Definition AMReX_MLCGSolver.H:28
void setVerbose(int _verbose)
Definition AMReX_MLCGSolver.H:39
int getNumIters() const noexcept
Definition AMReX_MLCGSolver.H:64
void setInitSolnZeroed(bool _sol_zeroed)
Definition AMReX_MLCGSolver.H:53
void setPrintIdentation(std::string s)
Definition AMReX_MLCGSolver.H:45
int solve(MF &solnL, const MF &rhsL, RT eps_rel, RT eps_abs)
Definition AMReX_MLCGSolver.H:89
Type
Definition AMReX_MLCGSolver.H:18
void setNGhost(int _nghost)
Definition AMReX_MLCGSolver.H:56
void setMaxIter(int _maxiter)
Definition AMReX_MLCGSolver.H:42
Definition AMReX_MLLinOp.H:98
typename FabDataType< MF >::fab_type FAB
Definition AMReX_MLLinOp.H:108
typename FabDataType< MF >::value_type RT
Definition AMReX_MLLinOp.H:109
Definition AMReX_MLMG.H:21
Definition AMReX_MLMG.H:16
void prepareForFluxes(Vector< MF const * > const &a_sol)
Definition AMReX_MLMG.H:629
void setBottomVerbose(int v) noexcept
Definition AMReX_MLMG.H:147
void setMaxFmgIter(int n) noexcept
Definition AMReX_MLMG.H:135
RT MLResNormInf(int alevmax, bool local=false)
Definition AMReX_MLMG.H:1858
RT MLRhsNormInf(bool local=false)
Definition AMReX_MLMG.H:1873
void setNoGpuSync(bool do_not_sync) noexcept
Definition AMReX_MLMG.H:165
MLMGT(MLMGT< MF > &&)=delete
void actualBottomSolve()
Definition AMReX_MLMG.H:1547
Vector< Vector< MF > > rescor
Definition AMReX_MLMG.H:342
MF MFType
Definition AMReX_MLMG.H:29
BottomSolver getBottomSolver() const noexcept
Definition AMReX_MLMG.H:145
bool linop_prepared
Definition AMReX_MLMG.H:286
int bottom_verbose
Definition AMReX_MLMG.H:272
void checkPoint(const Vector< MultiFab * > &a_sol, const Vector< MultiFab const * > &a_rhs, RT a_tol_rel, RT a_tol_abs, const char *a_file_name) const
Definition AMReX_MLMG.H:2020
void setPreSmooth(int n) noexcept
Definition AMReX_MLMG.H:139
void setBottomToleranceAbs(RT t) noexcept
Definition AMReX_MLMG.H:150
Vector< Vector< MF > > cor
= rhs - L(sol)
Definition AMReX_MLMG.H:340
RT getFinalResidual() const noexcept
Definition AMReX_MLMG.H:245
int do_nsolve
N Solve.
Definition AMReX_MLMG.H:290
void interpCorrection(int alev)
Definition AMReX_MLMG.H:1760
void getEBFluxes(const Vector< MF * > &a_eb_flux)
Definition AMReX_MLMG.H:850
Long solve_called
Definition AMReX_MLMG.H:287
void getGradSolution(const Vector< Array< AMF *, 3 > > &a_grad_sol, Location a_loc=Location::FaceCenter)
Definition AMReX_MLMG.H:640
void setBottomSmooth(int n) noexcept
Definition AMReX_MLMG.H:142
int final_fill_bc
Definition AMReX_MLMG.H:279
MLMGNormType norm_type
Definition AMReX_MLMG.H:277
bool precond_mode
Definition AMReX_MLMG.H:255
void setNSolve(int flag) noexcept
Definition AMReX_MLMG.H:162
int getBottomVerbose() const
Definition AMReX_MLMG.H:127
std::unique_ptr< MF > ns_sol
Definition AMReX_MLMG.H:294
std::string print_ident
Definition AMReX_MLMG.H:297
Vector< Vector< MF > > cor_hold
Definition AMReX_MLMG.H:341
void computeResOfCorrection(int amrlev, int mglev)
Definition AMReX_MLMG.H:1837
void applyPrecond(const Vector< MF * > &out, const Vector< MF * > &in)
out = L(in) as a preconditioner
Definition AMReX_MLMG.H:1020
void setCFStrategy(CFStrategy a_cf_strategy) noexcept
Definition AMReX_MLMG.H:146
void computeResWithCrseCorFineCor(int falev)
Definition AMReX_MLMG.H:1736
void NSolve(MLMGT< MF > &a_solver, MF &a_sol, MF &a_rhs)
Definition AMReX_MLMG.H:1523
typename MLLinOpT< MF >::Location Location
Definition AMReX_MLMG.H:34
RT m_final_resnorm0
Definition AMReX_MLMG.H:350
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:944
Vector< MF > rhs
Definition AMReX_MLMG.H:330
void getFluxes(const Vector< Array< AMF *, 3 > > &a_flux, Location a_loc=Location::FaceCenter)
For (alpha * a - beta * (del dot b grad)) phi = rhs, flux means -b grad phi
Definition AMReX_MLMG.H:671
void setNSolveGridSize(int s) noexcept
Definition AMReX_MLMG.H:163
int nuf
when smoother is used as bottom solver
Definition AMReX_MLMG.H:265
bool do_no_sync_gpu
Definition AMReX_MLMG.H:299
void setVerbose(int v) noexcept
Definition AMReX_MLMG.H:133
int nu1
pre
Definition AMReX_MLMG.H:263
void computeMLResidual(int amrlevmax)
Definition AMReX_MLMG.H:1675
Vector< RT > m_iter_fine_resnorm0
Definition AMReX_MLMG.H:352
RT getInitResidual() const noexcept
Definition AMReX_MLMG.H:243
int getNumIters() const noexcept
Definition AMReX_MLMG.H:248
void setPostSmooth(int n) noexcept
Definition AMReX_MLMG.H:140
BottomSolver bottom_solver
Definition AMReX_MLMG.H:270
void mgVcycle(int amrlev, int mglev)
Definition AMReX_MLMG.H:1351
MLLinOpT< MF > & linop
Definition AMReX_MLMG.H:281
int ncomp
Definition AMReX_MLMG.H:282
void prepareForNSolve()
Definition AMReX_MLMG.H:1238
RT precond(Vector< MF * > const &a_sol, Vector< MF const * > const &a_rhs, RT a_tol_rel, RT a_tol_abs)
Definition AMReX_MLMG.H:611
int max_fmg_iters
Definition AMReX_MLMG.H:268
void makeSolvable()
Definition AMReX_MLMG.H:1887
void setBottomSolver(BottomSolver s) noexcept
Definition AMReX_MLMG.H:144
int namrlevs
Definition AMReX_MLMG.H:283
void preparePrecond()
Definition AMReX_MLMG.H:1230
int nub
additional smoothing after bottom cg solver
Definition AMReX_MLMG.H:266
void incPrintIdentation()
Definition AMReX_MLMG.H:2079
typename MLLinOpT< MF >::RT RT
Definition AMReX_MLMG.H:31
int max_iters
Definition AMReX_MLMG.H:259
int do_fixed_number_of_iters
Definition AMReX_MLMG.H:260
void setThrowException(bool t) noexcept
Definition AMReX_MLMG.H:132
void decPrintIdentation()
Definition AMReX_MLMG.H:2086
void setFixedIter(int nit) noexcept
Definition AMReX_MLMG.H:136
int finest_amr_lev
Definition AMReX_MLMG.H:284
Vector< RT > const & getResidualHistory() const noexcept
Definition AMReX_MLMG.H:247
void prepareLinOp()
Definition AMReX_MLMG.H:1218
RT m_rhsnorm0
Definition AMReX_MLMG.H:348
void setPrecondIter(int nit) noexcept
Definition AMReX_MLMG.H:137
CFStrategy
Definition AMReX_MLMG.H:37
void prepareForSolve(Vector< AMF * > const &a_sol, Vector< AMF const * > const &a_rhs)
Definition AMReX_MLMG.H:1032
int bottomSolveWithCG(MF &x, const MF &b, typename MLCGSolverT< MF >::Type type)
Definition AMReX_MLMG.H:1654
std::unique_ptr< MLMGT< MF > > ns_mlmg
Definition AMReX_MLMG.H:293
void setAlwaysUseBNorm(int flag) noexcept
Definition AMReX_MLMG.H:370
void compResidual(const Vector< MF * > &a_res, const Vector< MF * > &a_sol, const Vector< MF const * > &a_rhs)
Definition AMReX_MLMG.H:876
void miniCycle(int amrlev)
Definition AMReX_MLMG.H:1340
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)
int bottom_maxiter
Definition AMReX_MLMG.H:273
bool throw_exception
Definition AMReX_MLMG.H:256
RT bottom_reltol
Definition AMReX_MLMG.H:274
Vector< Vector< MF > > res
First Vector: Amr levels. 0 is the coarest level Second Vector: MG levels. 0 is the finest level.
Definition AMReX_MLMG.H:339
void setFinalFillBC(int flag) noexcept
Definition AMReX_MLMG.H:158
typename MLLinOpT< MF >::BCMode BCMode
Definition AMReX_MLMG.H:33
void setConvergenceNormType(MLMGNormType norm) noexcept
Definition AMReX_MLMG.H:156
void computeResWithCrseSolFineCor(int calev, int falev)
Definition AMReX_MLMG.H:1703
MLMGT< MF > & operator=(MLMGT< MF > const &)=delete
Vector< MF > sol
Hypre.
Definition AMReX_MLMG.H:329
int nsolve_grid_size
Definition AMReX_MLMG.H:291
MLMGT(MLLinOpT< MF > &a_lp)
Definition AMReX_MLMG.H:361
int verbose
Definition AMReX_MLMG.H:257
void computeResidual(int alev)
Definition AMReX_MLMG.H:1693
MLLinOpT< MF > & getLinOp()
Definition AMReX_MLMG.H:251
std::unique_ptr< MF > ns_rhs
Definition AMReX_MLMG.H:295
timer_types
Definition AMReX_MLMG.H:345
@ ntimers
Definition AMReX_MLMG.H:345
@ bottom_time
Definition AMReX_MLMG.H:345
@ iter_time
Definition AMReX_MLMG.H:345
@ solve_time
Definition AMReX_MLMG.H:345
CFStrategy cf_strategy
Definition AMReX_MLMG.H:271
typename MLLinOpT< MF >::FAB FAB
Definition AMReX_MLMG.H:30
Vector< int > sol_is_alias
Definition AMReX_MLMG.H:333
RT getBottomToleranceAbs() const noexcept
Definition AMReX_MLMG.H:151
int numAMRLevels() const noexcept
Definition AMReX_MLMG.H:160
RT bottom_abstol
Definition AMReX_MLMG.H:275
Vector< int > m_niters_cg
Definition AMReX_MLMG.H:351
MLMGT(MLMGT< MF > const &)=delete
void mgFcycle()
Definition AMReX_MLMG.H:1457
Vector< double > timer
Definition AMReX_MLMG.H:346
RT getInitRHS() const noexcept
Definition AMReX_MLMG.H:241
RT ResNormInf(int alev, bool local=false)
Definition AMReX_MLMG.H:1849
Vector< int > const & getNumCGIters() const noexcept
Definition AMReX_MLMG.H:249
int nu2
post
Definition AMReX_MLMG.H:264
int max_precond_iters
Definition AMReX_MLMG.H:261
void bottomSolve()
Definition AMReX_MLMG.H:1509
void setBottomTolerance(RT t) noexcept
Definition AMReX_MLMG.H:149
void setFinalSmooth(int n) noexcept
Definition AMReX_MLMG.H:141
std::unique_ptr< MLLinOpT< MF > > ns_linop
Definition AMReX_MLMG.H:292
void addInterpCorrection(int alev, int mglev)
Definition AMReX_MLMG.H:1807
RT m_init_resnorm0
Definition AMReX_MLMG.H:349
int getVerbose() const
Definition AMReX_MLMG.H:126
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)
void setBottomMaxIter(int n) noexcept
Definition AMReX_MLMG.H:148
void oneIter(int iter)
Definition AMReX_MLMG.H:1271
void setMaxIter(int n) noexcept
Definition AMReX_MLMG.H:134
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:28
Long size() const noexcept
Definition AMReX_Vector.H:53
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:979
bool setNoSyncRegion(bool b) noexcept
Definition AMReX_GpuControl.H:158
bool setSingleStreamRegion(bool b) noexcept
Definition AMReX_GpuControl.H:154
void Max(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:126
void push(MPI_Comm c)
Definition AMReX_ParallelContext.H:102
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
void pop()
Note that it's the user's responsibility to free the MPI_Comm.
Definition AMReX_ParallelContext.H:108
bool IOProcessorSub() noexcept
Am IO processor for current frame?
Definition AMReX_ParallelContext.H:80
Definition AMReX_Amr.cpp:49
MF::value_type norminf(MF const &mf, int scomp, int ncomp, IntVect const &nghost, bool local=false)
Definition AMReX_FabArrayUtility.H:1977
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:138
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Returns a BoxND with different type.
Definition AMReX_Box.H:1453
int nComp(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2852
void FileOpenFailed(const std::string &file)
Output a message and abort when couldn't open the file.
Definition AMReX_Utility.cpp:137
void EB_average_face_to_cellcenter(MultiFab &ccmf, int dcomp, const Array< MultiFab const *, 3 > &fmf)
Definition AMReX_EBMultiFabUtil.cpp:806
std::array< T const *, 3 > GetArrOfConstPtrs(const std::array< T, 3 > &a) noexcept
Definition AMReX_Array.H:1010
__host__ __device__ T norm(const GpuComplex< T > &a_z) noexcept
Return the norm (magnitude squared) of a complex number.
Definition AMReX_GpuComplex.H:348
DistributionMapping const & DistributionMap(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2867
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:336
std::string getEnumNameString(T const &v)
Definition AMReX_Enum.H:154
IntVect nGrowVect(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2857
void average_face_to_cellcenter(MultiFab &cc, int dcomp, const Vector< const MultiFab * > &fc, IntVect const &ng_vect)
Definition AMReX_MultiFabUtil.cpp:155
void LocalCopy(DMF &dst, SMF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst = src
Definition AMReX_FabArrayUtility.H:1898
void EB_set_covered(MultiFab &mf, Real val)
Definition AMReX_EBMultiFabUtil.cpp:21
void LocalAdd(MF &dst, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst += src
Definition AMReX_FabArrayUtility.H:1906
double second() noexcept
Definition AMReX_Utility.cpp:940
std::array< T *, 3 > GetArrOfPtrs(std::array< T, 3 > &a) noexcept
Definition AMReX_Array.H:998
void UtilCreateCleanDirectory(const std::string &path, bool callbarrier=true)
Create a new directory, renaming the old one if it exists.
Definition AMReX_Utility.cpp:167
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)
Definition AMReX_EBMultiFabUtil.cpp:336
BottomSolver
Definition AMReX_MLLinOp.H:30
IntVectND< 3 > IntVect
Definition AMReX_BaseFwd.H:30
RealVectND< 3 > RealVect
Definition AMReX_ParmParse.H:35
void setBndry(MF &dst, typename MF::value_type val, int scomp, int ncomp)
dst = val in ghost cells.
Definition AMReX_FabArrayUtility.H:1882
Vector< T * > GetVecOfPtrs(Vector< T > &a)
Definition AMReX_Vector.H:64
void Scale(MF &dst, typename MF::value_type val, int scomp, int ncomp, int nghost)
dst *= val
Definition AMReX_FabArrayUtility.H:1889
Vector< std::array< T *, 3 > > GetVecOfArrOfPtrs(const Vector< std::array< std::unique_ptr< T >, 3 > > &a)
Definition AMReX_Vector.H:141
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
MLMGNormType
Definition AMReX_MLMG.H:12
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:1967
int verbose
Definition AMReX_DistributionMapping.cpp:36
void setVal(MF &dst, typename MF::value_type val)
dst = val
Definition AMReX_FabArrayUtility.H:1875
BoxArray const & boxArray(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2862
std::array< T, N > Array
Definition AMReX_Array.H:24
BCMode
Definition AMReX_MLLinOp.H:85
Location
Definition AMReX_MLLinOp.H:87
FabArray memory allocation information.
Definition AMReX_FabArray.H:66