3#include <AMReX_Config.H>
16 :
public std::runtime_error
19 using std::runtime_error::runtime_error;
44 template <
typename AMF>
46 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file =
nullptr);
48 template <
typename AMF>
49 RT solve (std::initializer_list<AMF*> a_sol,
50 std::initializer_list<AMF const*> a_rhs,
51 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file =
nullptr);
54 RT a_tol_rel,
RT a_tol_abs);
56 template <
typename AMF>
58 Location a_loc = Location::FaceCenter);
60 template <
typename AMF>
62 Location a_loc = Location::FaceCenter);
67 template <
typename AMF>
69 Location a_loc = Location::FaceCenter);
71 template <
typename AMF>
73 Location a_loc = Location::FaceCenter);
75 template <
typename AMF>
78 Location a_loc = Location::FaceCenter);
80 template <
typename AMF>
82 std::initializer_list<AMF*> a_sol,
83 Location a_loc = Location::FaceCenter);
85 template <
typename AMF>
87 Location a_loc = Location::CellCenter);
89 template <
typename AMF>
90 void getFluxes (std::initializer_list<AMF*> a_flux,
91 Location a_loc = Location::CellCenter);
93 template <
typename AMF>
96 Location a_loc = Location::CellCenter);
98 template <
typename AMF>
99 void getFluxes (std::initializer_list<AMF*> a_flux,
100 std::initializer_list<AMF*> a_sol,
101 Location a_loc = Location::CellCenter);
160#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
171 void setHypreOptionsNamespace(
const std::string& prefix)
noexcept
173 hypre_options_namespace = prefix;
176 void setHypreOldDefault (
bool l)
noexcept {hypre_old_default = l;}
177 void setHypreRelaxType (
int n)
noexcept {hypre_relax_type = n;}
178 void setHypreRelaxOrder (
int n)
noexcept {hypre_relax_order = n;}
179 void setHypreNumSweeps (
int n)
noexcept {hypre_num_sweeps = n;}
180 void setHypreStrongThreshold (Real t)
noexcept {hypre_strong_threshold = t;}
185 template <
typename AMF>
186 void prepareForSolve (Vector<AMF*>
const& a_sol, Vector<AMF const*>
const& a_rhs);
198 void mgVcycle (
int amrlev,
int mglev);
202 void NSolve (MLMGT<MF>& a_solver, MF& a_sol, MF& a_rhs);
222#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
223 template <
class TMF=MF,std::enable_if_t<std::is_same_v<TMF,MultiFab>,
int> = 0>
224 void bottomSolveWithHypre (MF&
x,
const MF&
b);
227#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
228 template <
class TMF=MF,std::enable_if_t<std::is_same_v<TMF,MultiFab>,
int> = 0>
229 void bottomSolveWithPETSc (MF&
x,
const MF&
b);
295#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
300 std::unique_ptr<Hypre> hypre_solver;
301 std::unique_ptr<MLMGBndryT<MF>> hypre_bndry;
302 std::unique_ptr<HypreNodeLap> hypre_node_solver;
304 std::string hypre_options_namespace =
"hypre";
305 bool hypre_old_default =
true;
306 int hypre_relax_type = 6;
307 int hypre_relax_order = 1;
308 int hypre_num_sweeps = 2;
309 Real hypre_strong_threshold = 0.25;
313#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
314 std::unique_ptr<PETScABecLap> petsc_solver;
315 std::unique_ptr<MLMGBndryT<MF>> petsc_bndry;
349 RT a_tol_rel,
RT a_tol_abs,
const char* a_file_name)
const;
353template <
typename MF>
355 : linop(a_lp), ncomp(a_lp.getNComp()), namrlevs(a_lp.NAMRLevels()),
356 finest_amr_lev(a_lp.NAMRLevels()-1)
361template <
typename MF>
362template <
typename AMF>
365 std::initializer_list<AMF const*> a_rhs,
366 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file) ->
RT
370 a_tol_rel, a_tol_abs, checkpoint_file);
373template <
typename MF>
374template <
typename AMF>
377 RT a_tol_rel,
RT a_tol_abs,
const char* checkpoint_file) ->
RT
381 bool prev_in_single_stream_region =
false;
382 bool prev_in_nosync_region =
false;
384 if (do_no_sync_gpu) {
389 if constexpr (std::is_same<AMF,MultiFab>()) {
390 if (checkpoint_file !=
nullptr) {
391 checkPoint(a_sol, a_rhs, a_tol_rel, a_tol_abs, checkpoint_file);
396 bottom_solver = linop.getDefaultBottomSolver();
399#if (defined(AMREX_USE_HYPRE) || defined(AMREX_USE_PETSC)) && (AMREX_SPACEDIM > 1)
400 if constexpr (IsFabArray_v<AMF>) {
402 int mo = linop.getMaxOrder();
403 if (a_sol[0]->hasEBFabFactory()) {
404 linop.setMaxOrder(2);
406 linop.setMaxOrder(std::min(3,mo));
412 bool is_nsolve = linop.m_parent;
416 RT& composite_norminf = m_final_resnorm0;
419 m_iter_fine_resnorm0.clear();
421 prepareForSolve(a_sol, a_rhs);
423 computeMLResidual(finest_amr_lev);
426 RT resnorm0 = MLResNormInf(finest_amr_lev, local);
427 RT rhsnorm0 = MLRhsNormInf(local);
433 amrex::Print() << print_ident <<
"MLMG: Initial rhs = " << rhsnorm0 <<
"\n"
434 << print_ident <<
"MLMG: Initial residual (resid0) = " << resnorm0 <<
"\n";
438 m_init_resnorm0 = resnorm0;
439 m_rhsnorm0 = rhsnorm0;
442 std::string norm_name;
443 if (always_use_bnorm || rhsnorm0 >= resnorm0) {
447 norm_name =
"resid0";
450 const RT res_target = std::max(a_tol_abs, std::max(a_tol_rel,
RT(1.e-16))*max_norm);
452 if (!is_nsolve && resnorm0 <= res_target) {
453 composite_norminf = resnorm0;
455 amrex::Print() << print_ident <<
"MLMG: No iterations needed\n";
459 bool converged =
false;
461 const int niters = do_fixed_number_of_iters ? do_fixed_number_of_iters : max_iters;
462 for (
int iter = 0; iter < niters; ++iter)
469 computeResidual(finest_amr_lev);
471 if (is_nsolve) {
continue; }
473 RT fine_norminf = ResNormInf(finest_amr_lev);
474 m_iter_fine_resnorm0.push_back(fine_norminf);
475 composite_norminf = fine_norminf;
477 amrex::Print() << print_ident <<
"MLMG: Iteration " << std::setw(3) << iter+1 <<
" Fine resid/"
478 << norm_name <<
" = " << fine_norminf/max_norm <<
"\n";
480 bool fine_converged = (fine_norminf <= res_target);
482 if (namrlevs == 1 && fine_converged) {
484 }
else if (fine_converged) {
486 computeMLResidual(finest_amr_lev-1);
487 RT crse_norminf = MLResNormInf(finest_amr_lev-1);
489 amrex::Print() << print_ident <<
"MLMG: Iteration " << std::setw(3) << iter+1
490 <<
" Crse resid/" << norm_name <<
" = "
491 << crse_norminf/max_norm <<
"\n";
493 converged = (crse_norminf <= res_target);
494 composite_norminf = std::max(fine_norminf, crse_norminf);
501 amrex::Print() << print_ident <<
"MLMG: Final Iter. " << iter+1
502 <<
" resid, resid/" << norm_name <<
" = "
503 << composite_norminf <<
", "
504 << composite_norminf/max_norm <<
"\n";
508 if (composite_norminf >
RT(1.e20)*max_norm)
511 amrex::Print() << print_ident <<
"MLMG: Failing to converge after " << iter+1 <<
" iterations."
512 <<
" resid, resid/" << norm_name <<
" = "
513 << composite_norminf <<
", "
514 << composite_norminf/max_norm <<
"\n";
517 if ( throw_exception ) {
518 throw error(
"MLMG blew up.");
526 if (!converged && do_fixed_number_of_iters == 0) {
528 amrex::Print() << print_ident <<
"MLMG: Failed to converge after " << max_iters <<
" iterations."
529 <<
" resid, resid/" << norm_name <<
" = "
530 << composite_norminf <<
", "
531 << composite_norminf/max_norm <<
"\n";
534 if ( throw_exception ) {
535 throw error(
"MLMG failed to converge.");
546 if (linop.hasHiddenDimension()) {
547 ng_back[linop.hiddenDirection()] = 0;
549 for (
int alev = 0; alev < namrlevs; ++alev)
551 if (!sol_is_alias[alev]) {
552 LocalCopy(*a_sol[alev], sol[alev], 0, 0, ncomp, ng_back);
558 ParallelReduce::Max<double>(timer.data(), timer.size(), 0,
562 amrex::AllPrint() << print_ident <<
"MLMG: Timers: Solve = " << timer[solve_time]
563 <<
" Iter = " << timer[iter_time]
564 <<
" Bottom = " << timer[bottom_time] <<
"\n";
570 if (do_no_sync_gpu) {
575 return composite_norminf;
578template <
typename MF>
581 RT a_tol_rel,
RT a_tol_abs) ->
RT
584 std::swap(max_precond_iters, do_fixed_number_of_iters);
585 linop.beginPrecondBC();
587 auto r = solve(a_sol, a_rhs, a_tol_rel, a_tol_abs);
589 linop.endPrecondBC();
590 std::swap(max_precond_iters, do_fixed_number_of_iters);
591 precond_mode =
false;
596template <
typename MF>
600 for (
int alev = finest_amr_lev; alev >= 0; --alev) {
601 const MF* crse_bcdata = (alev > 0) ? a_sol[alev-1] :
nullptr;
602 linop.prepareForFluxes(alev, crse_bcdata);
606template <
typename MF>
607template <
typename AMF>
612 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
613 if constexpr (std::is_same<AMF,MF>()) {
614 linop.compGrad(alev, a_grad_sol[alev], sol[alev], a_loc);
617 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
618 auto const& amf = *(a_grad_sol[alev][idim]);
621 linop.compGrad(alev,
GetArrOfPtrs(grad_sol), sol[alev], a_loc);
622 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
623 LocalCopy(*a_grad_sol[alev][idim], grad_sol[idim], 0, 0, ncomp,
IntVect(0));
629template <
typename MF>
630template <
typename AMF>
637template <
typename MF>
638template <
typename AMF>
643 if (!linop.isCellCentered()) {
644 amrex::Abort(
"Calling wrong getFluxes for nodal solver");
649 if constexpr (std::is_same<AMF,MF>()) {
653 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
654 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
655 auto const& amf = *(a_flux[ilev][idim]);
660 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
661 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
662 LocalCopy(*a_flux[ilev][idim], fluxes[ilev][idim], 0, 0, ncomp,
IntVect(0));
668template <
typename MF>
669template <
typename AMF>
677template <
typename MF>
678template <
typename AMF>
685 if (!linop.isCellCentered()) {
686 amrex::Abort(
"Calling wrong getFluxes for nodal solver");
689 if constexpr (std::is_same<AMF,MF>()) {
690 linop.getFluxes(a_flux, a_sol, a_loc);
693 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
694 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
695 auto const& amf = *(a_flux[ilev][idim]);
701 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
702 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
703 LocalCopy(*a_flux[ilev][idim], fluxes[ilev][idim], 0, 0, ncomp,
IntVect(0));
709template <
typename MF>
710template <
typename AMF>
713 std::initializer_list<AMF*> a_sol,
Location a_loc)
719template <
typename MF>
720template <
typename AMF>
725 if constexpr (std::is_same<AMF,MF>()) {
729 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
730 auto const& amf = *a_flux[ilev];
734 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
740template <
typename MF>
741template <
typename AMF>
748template <
typename MF>
749template <
typename AMF>
756 if constexpr (! std::is_same<AMF,MF>()) {
757 for (
int alev = 0; alev < namrlevs; ++alev) {
762 if (linop.isCellCentered())
765 for (
int alev = 0; alev < namrlevs; ++alev) {
766 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
769 if (cf_strategy == CFStrategy::ghostnodes) { nghost = linop.getNGrow(alev); }
770 ffluxes[alev][idim].define(
amrex::convert(linop.m_grids[alev][mglev],
772 linop.m_dmap[alev][mglev], ncomp, nghost,
MFInfo(),
773 *linop.m_factory[alev][mglev]);
776 if constexpr (std::is_same<AMF,MF>()) {
781 for (
int alev = 0; alev < namrlevs; ++alev) {
790 if constexpr (std::is_same<AMF,MF>()) {
791 linop.getFluxes(a_flux, a_sol);
794 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
795 auto const& amf = *a_flux[ilev];
799 for (
int ilev = 0; ilev < namrlevs; ++ilev) {
806template <
typename MF>
807template <
typename AMF>
810 std::initializer_list<AMF*> a_sol,
Location a_loc)
817template <
typename MF>
821 if (!linop.isCellCentered()) {
829template <
typename MF>
831MLMGT<MF>::getEBFluxes (
const Vector<MF*>& a_eb_flux,
const Vector<MF*>& a_sol)
835 if (!linop.isCellCentered()) {
839 linop.getEBFluxes(a_eb_flux, a_sol);
843template <
typename MF>
851 if (linop.hasHiddenDimension()) { ng_sol[linop.hiddenDirection()] = 0; }
854 sol_is_alias.resize(namrlevs,
true);
855 for (
int alev = 0; alev < namrlevs; ++alev)
857 if (cf_strategy == CFStrategy::ghostnodes ||
nGrowVect(*a_sol[alev]) == ng_sol)
859 sol[alev] = linop.makeAlias(*a_sol[alev]);
860 sol_is_alias[alev] =
true;
864 if (sol_is_alias[alev])
866 sol[alev] = linop.make(alev, 0, ng_sol);
874 const auto& amrrr = linop.AMRRefRatio();
876 for (
int alev = finest_amr_lev; alev >= 0; --alev) {
877 const MF* crse_bcdata = (alev > 0) ? &(sol[alev-1]) :
nullptr;
878 const MF* prhs = a_rhs[alev];
879#if (AMREX_SPACEDIM != 3)
880 int nghost = (cf_strategy == CFStrategy::ghostnodes) ? linop.getNGrow(alev) : 0;
882 MFInfo(), *linop.Factory(alev));
884 linop.applyMetricTerm(alev, 0, rhstmp);
885 linop.unimposeNeumannBC(alev, rhstmp);
886 linop.applyInhomogNeumannTerm(alev, rhstmp);
889 linop.solutionResidual(alev, *a_res[alev], sol[alev], *prhs, crse_bcdata);
890 if (alev < finest_amr_lev) {
891 linop.reflux(alev, *a_res[alev], sol[alev], *prhs,
892 *a_res[alev+1], sol[alev+1], *a_rhs[alev+1]);
893 if (linop.isCellCentered()) {
897 average_down(*a_res[alev+1], *a_res[alev], 0, ncomp, amrrr[alev]);
904#if (AMREX_SPACEDIM != 3)
905 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
906 linop.unapplyMetricTerm(alev, 0, *a_res[alev]);
911template <
typename MF>
922 if (linop.hasHiddenDimension()) { ng_sol[linop.hiddenDirection()] = 0; }
924 for (
int alev = 0; alev < namrlevs; ++alev)
926 if (cf_strategy == CFStrategy::ghostnodes)
928 nghost = linop.getNGrow(alev);
929 in[alev] = a_in[alev];
931 else if (
nGrowVect(*a_in[alev]) == ng_sol)
933 in[alev] = a_in[alev];
938 if (cf_strategy == CFStrategy::ghostnodes) { ng =
IntVect(nghost); }
939 in_raii[alev] = linop.make(alev, 0, ng);
941 in[alev] = &(in_raii[alev]);
943 rh[alev] = linop.make(alev, 0,
IntVect(nghost));
949 for (
int alev = 0; alev < namrlevs; ++alev) {
950 linop.applyInhomogNeumannTerm(alev, rh[alev]);
953 const auto& amrrr = linop.AMRRefRatio();
955 for (
int alev = finest_amr_lev; alev >= 0; --alev) {
956 const MF* crse_bcdata = (alev > 0) ? in[alev-1] :
nullptr;
957 linop.solutionResidual(alev, *out[alev], *in[alev], rh[alev], crse_bcdata);
958 if (alev < finest_amr_lev) {
959 linop.reflux(alev, *out[alev], *in[alev], rh[alev],
960 *out[alev+1], *in[alev+1], rh[alev+1]);
961 if (linop.isCellCentered()) {
962 if constexpr (IsMultiFabLike_v<MF>) {
969 amrex::Abort(
"MLMG: TODO average_down for non-MultiFab");
975#if (AMREX_SPACEDIM != 3)
976 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
977 linop.unapplyMetricTerm(alev, 0, *out[alev]);
981 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
982 if (cf_strategy == CFStrategy::ghostnodes) { nghost = linop.getNGrow(alev); }
983 Scale(*out[alev],
RT(-1), 0,
nComp(*out[alev]), nghost);
987template <
typename MF>
992 linop.beginPrecondBC();
994 linop.endPrecondBC();
995 precond_mode =
false;
998template <
typename MF>
999template <
typename AMF>
1008 timer.assign(ntimers, 0.0);
1012 if (linop.hasHiddenDimension()) { ng_sol[linop.hiddenDirection()] = 0; }
1014 if (!linop_prepared) {
1015 linop.prepareForSolve();
1016 linop_prepared =
true;
1017 }
else if (linop.needsUpdate()) {
1020#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
1021 hypre_solver.reset();
1022 hypre_bndry.reset();
1023 hypre_node_solver.reset();
1026#ifdef AMREX_USE_PETSC
1027 petsc_solver.reset();
1028 petsc_bndry.reset();
1033 sol_is_alias.resize(namrlevs,
false);
1034 for (
int alev = 0; alev < namrlevs; ++alev)
1036 if (cf_strategy == CFStrategy::ghostnodes)
1038 if constexpr (std::is_same<AMF,MF>()) {
1039 sol[alev] = linop.makeAlias(*a_sol[alev]);
1040 sol_is_alias[alev] =
true;
1042 amrex::Abort(
"Type conversion not supported for CFStrategy::ghostnodes");
1047 if (
nGrowVect(*a_sol[alev]) == ng_sol) {
1048 if constexpr (std::is_same<AMF,MF>()) {
1049 sol[alev] = linop.makeAlias(*a_sol[alev]);
1050 sol_is_alias[alev] =
true;
1053 if (!sol_is_alias[alev]) {
1054 if (!solve_called) {
1055 sol[alev] = linop.make(alev, 0, ng_sol);
1063 rhs.resize(namrlevs);
1064 for (
int alev = 0; alev < namrlevs; ++alev)
1066 if (cf_strategy == CFStrategy::ghostnodes) { ng_rhs =
IntVect(linop.getNGrow(alev)); }
1067 if (!solve_called) {
1068 rhs[alev] = linop.make(alev, 0, ng_rhs);
1070 LocalCopy(rhs[alev], *a_rhs[alev], 0, 0, ncomp, ng_rhs);
1071 linop.applyMetricTerm(alev, 0, rhs[alev]);
1072 linop.unimposeNeumannBC(alev, rhs[alev]);
1073 linop.applyInhomogNeumannTerm(alev, rhs[alev]);
1074 linop.applyOverset(alev, rhs[alev]);
1075 if ( ! precond_mode) {
1076 bool r = linop.scaleRHS(alev, &(rhs[alev]));
1082 if (factory && !factory->isAllRegular()) {
1083 if constexpr (std::is_same<MF,MultiFab>()) {
1087 amrex::Abort(
"TODO: MLMG with EB only works with MultiFab");
1093 for (
int falev = finest_amr_lev; falev > 0; --falev)
1095 linop.averageDownSolutionRHS(falev-1, sol[falev-1], rhs[falev-1], sol[falev], rhs[falev]);
1099 if (linop.isSingular(0) && linop.getEnforceSingularSolvable())
1104 IntVect ng = linop.getNGrowVectRestriction();
1105 if (cf_strategy == CFStrategy::ghostnodes) { ng = ng_rhs; }
1106 if (!solve_called) {
1107 linop.make(res, ng);
1108 linop.make(rescor, ng);
1110 for (
int alev = 0; alev <= finest_amr_lev; ++alev)
1112 const int nmglevs = linop.NMGLevels(alev);
1113 for (
int mglev = 0; mglev < nmglevs; ++mglev)
1115 setVal(res [alev][mglev],
RT(0.0));
1116 setVal(rescor[alev][mglev],
RT(0.0));
1120 if (cf_strategy != CFStrategy::ghostnodes) { ng = ng_sol; }
1122 for (
int alev = 0; alev <= finest_amr_lev; ++alev)
1124 const int nmglevs = linop.NMGLevels(alev);
1125 cor[alev].resize(nmglevs);
1126 for (
int mglev = 0; mglev < nmglevs; ++mglev)
1128 if (!solve_called) {
1130 if (cf_strategy == CFStrategy::ghostnodes) { _ng=
IntVect(linop.getNGrow(alev,mglev)); }
1131 cor[alev][mglev] = linop.make(alev, mglev, _ng);
1137 cor_hold.resize(std::max(namrlevs-1,1));
1140 const int nmglevs = linop.NMGLevels(alev);
1141 cor_hold[alev].resize(nmglevs);
1142 for (
int mglev = 0; mglev < nmglevs-1; ++mglev)
1144 if (!solve_called) {
1146 if (cf_strategy == CFStrategy::ghostnodes) { _ng=
IntVect(linop.getNGrow(alev,mglev)); }
1147 cor_hold[alev][mglev] = linop.make(alev, mglev, _ng);
1149 setVal(cor_hold[alev][mglev],
RT(0.0));
1152 for (
int alev = 1; alev < finest_amr_lev; ++alev)
1154 cor_hold[alev].resize(1);
1155 if (!solve_called) {
1157 if (cf_strategy == CFStrategy::ghostnodes) { _ng=
IntVect(linop.getNGrow(alev)); }
1158 cor_hold[alev][0] = linop.make(alev, 0, _ng);
1160 setVal(cor_hold[alev][0],
RT(0.0));
1164 || !linop.supportNSolve())
1169 if (do_nsolve && ns_linop ==
nullptr)
1175 amrex::Print() << print_ident <<
"MLMG: # of AMR levels: " << namrlevs <<
"\n"
1176 << print_ident <<
" # of MG levels on the coarsest AMR level: " << linop.NMGLevels(0)
1179 amrex::Print() << print_ident <<
" # of MG levels in N-Solve: " << ns_linop->NMGLevels(0) <<
"\n"
1180 << print_ident <<
" # of grids in N-Solve: " << ns_linop->m_grids[0][0].size() <<
"\n";
1185template <
typename MF>
1189 if (!linop_prepared) {
1190 linop.prepareForSolve();
1191 linop_prepared =
true;
1192 }
else if (linop.needsUpdate()) {
1197template <
typename MF>
1202 linop.preparePrecond();
1205template <
typename MF>
1209 if constexpr (IsMultiFabLike_v<MF>) {
1210 ns_linop = linop.makeNLinOp(nsolve_grid_size);
1213 if (cf_strategy == CFStrategy::ghostnodes) { nghost = linop.getNGrow(); }
1215 const BoxArray& ba = (*ns_linop).m_grids[0][0];
1219 if (cf_strategy == CFStrategy::ghostnodes) { ng = nghost; }
1220 ns_sol = std::make_unique<MF>(ba, dm, ncomp, ng,
MFInfo(), *(ns_linop->Factory(0,0)));
1222 if (cf_strategy == CFStrategy::ghostnodes) { ng = nghost; }
1223 ns_rhs = std::make_unique<MF>(ba, dm, ncomp, ng,
MFInfo(), *(ns_linop->Factory(0,0)));
1227 ns_linop->setLevelBC(0, ns_sol.get());
1229 ns_mlmg = std::make_unique<MLMGT<MF>>(*ns_linop);
1230 ns_mlmg->setVerbose(0);
1231 ns_mlmg->setFixedIter(1);
1232 ns_mlmg->setMaxFmgIter(20);
1239template <
typename MF>
1244 for (
int alev = finest_amr_lev; alev > 0; --alev)
1249 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(alev)); }
1250 LocalAdd(sol[alev], cor[alev][0], 0, 0, ncomp, nghost);
1253 computeResWithCrseSolFineCor(alev-1,alev);
1255 if (alev != finest_amr_lev) {
1256 std::swap(cor_hold[alev][0], cor[alev][0]);
1263 if (linop.isSingular(0) && linop.getEnforceSingularSolvable())
1265 makeSolvable(0,0,res[0][0]);
1268 if (iter < max_fmg_iters) {
1275 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(0)); }
1276 LocalAdd(sol[0], cor[0][0], 0, 0, ncomp, nghost);
1279 for (
int alev = 1; alev <= finest_amr_lev; ++alev)
1282 interpCorrection(alev);
1285 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(alev)); }
1286 LocalAdd(sol[alev], cor[alev][0], 0, 0, ncomp, nghost);
1288 if (alev != finest_amr_lev) {
1289 LocalAdd(cor_hold[alev][0], cor[alev][0], 0, 0, ncomp, nghost);
1293 computeResWithCrseCorFineCor(alev);
1297 LocalAdd(sol[alev], cor[alev][0], 0, 0, ncomp, nghost);
1299 if (alev != finest_amr_lev) {
1300 LocalAdd(cor[alev][0], cor_hold[alev][0], 0, 0, ncomp, nghost);
1304 linop.averageDownAndSync(sol);
1307template <
typename MF>
1312 const int mglev = 0;
1313 mgVcycle(amrlev, mglev);
1318template <
typename MF>
1324 const int mglev_bottom = linop.NMGLevels(amrlev) - 1;
1326 for (
int mglev = mglev_top; mglev < mglev_bottom; ++mglev)
1328 BL_PROFILE_VAR(
"MLMG::mgVcycle_down::"+std::to_string(mglev), blp_mgv_down_lev);
1333 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
1334 <<
" DN: Norm before smooth " <<
norm <<
"\n";
1337 setVal(cor[amrlev][mglev],
RT(0.0));
1338 bool skip_fillboundary =
true;
1339 linop.smooth(amrlev, mglev, cor[amrlev][mglev], res[amrlev][mglev], skip_fillboundary, nu1);
1342 computeResOfCorrection(amrlev, mglev);
1347 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
1348 <<
" DN: Norm after smooth " <<
norm <<
"\n";
1352 linop.restriction(amrlev, mglev+1, res[amrlev][mglev+1], rescor[amrlev][mglev]);
1361 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
1362 <<
" DN: Norm before bottom " <<
norm <<
"\n";
1367 computeResOfCorrection(amrlev, mglev_bottom);
1369 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
1370 <<
" UP: Norm after bottom " <<
norm <<
"\n";
1378 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
1379 <<
" Norm before smooth " <<
norm <<
"\n";
1381 setVal(cor[amrlev][mglev_bottom],
RT(0.0));
1382 bool skip_fillboundary =
true;
1383 linop.smooth(amrlev, mglev_bottom, cor[amrlev][mglev_bottom],
1384 res[amrlev][mglev_bottom], skip_fillboundary, nu1);
1387 computeResOfCorrection(amrlev, mglev_bottom);
1389 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev_bottom
1390 <<
" Norm after smooth " <<
norm <<
"\n";
1395 for (
int mglev = mglev_bottom-1; mglev >= mglev_top; --mglev)
1397 BL_PROFILE_VAR(
"MLMG::mgVcycle_up::"+std::to_string(mglev), blp_mgv_up_lev);
1399 addInterpCorrection(amrlev, mglev);
1402 computeResOfCorrection(amrlev, mglev);
1404 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
1405 <<
" UP: Norm before smooth " <<
norm <<
"\n";
1407 linop.smooth(amrlev, mglev, cor[amrlev][mglev], res[amrlev][mglev],
false, nu2);
1409 if (cf_strategy == CFStrategy::ghostnodes) { computeResOfCorrection(amrlev, mglev); }
1413 computeResOfCorrection(amrlev, mglev);
1415 amrex::Print() << print_ident <<
"AT LEVEL " << amrlev <<
" " << mglev
1416 <<
" UP: Norm after smooth " <<
norm <<
"\n";
1424template <
typename MF>
1434 const int amrlev = 0;
1435 const int mg_bottom_lev = linop.NMGLevels(amrlev) - 1;
1437 if (cf_strategy == CFStrategy::ghostnodes) { nghost =
IntVect(linop.getNGrow(amrlev)); }
1439 for (
int mglev = 1; mglev <= mg_bottom_lev; ++mglev)
1441 linop.avgDownResMG(mglev, res[amrlev][mglev], res[amrlev][mglev-1]);
1446 for (
int mglev = mg_bottom_lev-1; mglev >= 0; --mglev)
1449 interpCorrection(amrlev, mglev);
1452 computeResOfCorrection(amrlev, mglev);
1454 LocalCopy(res[amrlev][mglev], rescor[amrlev][mglev], 0, 0, ncomp, nghost);
1457 std::swap(cor[amrlev][mglev], cor_hold[amrlev][mglev]);
1458 mgVcycle(amrlev, mglev);
1459 LocalAdd(cor[amrlev][mglev], cor_hold[amrlev][mglev], 0, 0, ncomp, nghost);
1466template <
typename MF>
1472 NSolve(*ns_mlmg, *ns_sol, *ns_rhs);
1476 actualBottomSolve();
1480template <
typename MF>
1488 MF
const& res_bottom = res[0].back();
1499 RT(-1.0),
RT(-1.0));
1501 linop.copyNSolveSolution(cor[0].back(), a_sol);
1504template <
typename MF>
1510 if (!linop.isBottomActive()) {
return; }
1516 const int amrlev = 0;
1517 const int mglev = linop.NMGLevels(amrlev) - 1;
1518 auto&
x = cor[amrlev][mglev];
1519 auto&
b = res[amrlev][mglev];
1525 bool skip_fillboundary =
true;
1526 linop.smooth(amrlev, mglev,
x,
b, skip_fillboundary, nuf);
1532 if (linop.isBottomSingular() && linop.getEnforceSingularSolvable())
1535 raii_b = linop.make(amrlev, mglev, ng);
1539 makeSolvable(amrlev,mglev,*bottom_b);
1544#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
1545 if constexpr (std::is_same<MF,MultiFab>()) {
1546 bottomSolveWithHypre(
x, *bottom_b);
1550 amrex::Abort(
"Using Hypre as bottom solver not supported in this case");
1555#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
1556 if constexpr (std::is_same<MF,MultiFab>()) {
1557 bottomSolveWithPETSc(
x, *bottom_b);
1561 amrex::Abort(
"Using PETSc as bottom solver not supported in this case");
1574 int ret = bottomSolveWithCG(
x, *bottom_b, cg_type);
1584 setVal(cor[amrlev][mglev],
RT(0.0));
1585 ret = bottomSolveWithCG(
x, *bottom_b, cg_type);
1596 if (ret != 0 && ret != 9) {
1597 setVal(cor[amrlev][mglev],
RT(0.0));
1599 const int n = (ret==0) ? nub : nuf;
1600 linop.smooth(amrlev, mglev,
x,
b,
false, n);
1606 if (! timer.empty()) {
1611template <
typename MF>
1621 if (cf_strategy == CFStrategy::ghostnodes) { cg_solver.
setNGhost(linop.getNGrow()); }
1623 int ret = cg_solver.
solve(
x,
b, bottom_reltol, bottom_abstol);
1624 if (ret != 0 &&
verbose > 1) {
1625 amrex::Print() << print_ident <<
"MLMG: Bottom solve failed.\n";
1632template <
typename MF>
1638 const int mglev = 0;
1639 for (
int alev = amrlevmax; alev >= 0; --alev) {
1640 const MF* crse_bcdata = (alev > 0) ? &(sol[alev-1]) :
nullptr;
1641 linop.solutionResidual(alev, res[alev][mglev], sol[alev], rhs[alev], crse_bcdata);
1642 if (alev < finest_amr_lev) {
1643 linop.reflux(alev, res[alev][mglev], sol[alev], rhs[alev],
1644 res[alev+1][mglev], sol[alev+1], rhs[alev+1]);
1650template <
typename MF>
1655 const MF* crse_bcdata = (alev > 0) ? &(sol[alev-1]) :
nullptr;
1656 linop.solutionResidual(alev, res[alev][0], sol[alev], rhs[alev], crse_bcdata);
1660template <
typename MF>
1664 BL_PROFILE(
"MLMG::computeResWithCrseSolFineCor()");
1667 if (cf_strategy == CFStrategy::ghostnodes) {
1668 nghost =
IntVect(std::min(linop.getNGrow(falev),linop.getNGrow(calev)));
1671 MF& crse_sol = sol[calev];
1672 const MF& crse_rhs = rhs[calev];
1673 MF& crse_res = res[calev][0];
1675 MF& fine_sol = sol[falev];
1676 const MF& fine_rhs = rhs[falev];
1677 MF& fine_cor = cor[falev][0];
1678 MF& fine_res = res[falev][0];
1679 MF& fine_rescor = rescor[falev][0];
1681 const MF* crse_bcdata = (calev > 0) ? &(sol[calev-1]) :
nullptr;
1682 linop.solutionResidual(calev, crse_res, crse_sol, crse_rhs, crse_bcdata);
1684 linop.correctionResidual(falev, 0, fine_rescor, fine_cor, fine_res, BCMode::Homogeneous);
1685 LocalCopy(fine_res, fine_rescor, 0, 0, ncomp, nghost);
1687 linop.reflux(calev, crse_res, crse_sol, crse_rhs, fine_res, fine_sol, fine_rhs);
1689 linop.avgDownResAmr(calev, crse_res, fine_res);
1693template <
typename MF>
1697 BL_PROFILE(
"MLMG::computeResWithCrseCorFineCor()");
1700 if (cf_strategy == CFStrategy::ghostnodes) {
1701 nghost =
IntVect(linop.getNGrow(falev));
1704 const MF& crse_cor = cor[falev-1][0];
1706 MF& fine_cor = cor [falev][0];
1707 MF& fine_res = res [falev][0];
1708 MF& fine_rescor = rescor[falev][0];
1711 linop.correctionResidual(falev, 0, fine_rescor, fine_cor, fine_res,
1712 BCMode::Inhomogeneous, &crse_cor);
1713 LocalCopy(fine_res, fine_rescor, 0, 0, ncomp, nghost);
1717template <
typename MF>
1724 if (cf_strategy == CFStrategy::ghostnodes) {
1725 nghost =
IntVect(linop.getNGrow(alev));
1728 MF
const& crse_cor = cor[alev-1][0];
1729 MF & fine_cor = cor[alev ][0];
1731 const Geometry& crse_geom = linop.Geom(alev-1,0);
1734 int ng_dst = linop.isCellCentered() ? 1 : 0;
1735 if (cf_strategy == CFStrategy::ghostnodes)
1737 ng_src = linop.getNGrow(alev-1);
1738 ng_dst = linop.getNGrow(alev-1);
1741 MF cfine = linop.makeCoarseAmr(alev,
IntVect(ng_dst));
1746 linop.interpolationAmr(alev, fine_cor, cfine, nghost);
1752template <
typename MF>
1758 MF& crse_cor = cor[alev][mglev+1];
1759 MF& fine_cor = cor[alev][mglev ];
1760 linop.interpAssign(alev, mglev, fine_cor, crse_cor);
1764template <
typename MF>
1770 const MF& crse_cor = cor[alev][mglev+1];
1771 MF& fine_cor = cor[alev][mglev ];
1776 if (linop.isMFIterSafe(alev, mglev, mglev+1))
1782 cfine = linop.makeCoarseMG(alev, mglev,
IntVect(0));
1787 linop.interpolation(alev, mglev, fine_cor, *cmf);
1794template <
typename MF>
1799 MF &
x = cor[amrlev][mglev];
1800 const MF&
b = res[amrlev][mglev];
1801 MF &
r = rescor[amrlev][mglev];
1802 linop.correctionResidual(amrlev, mglev,
r,
x,
b, BCMode::Homogeneous);
1806template <
typename MF>
1811 return linop.normInf(alev, res[alev][0], local);
1815template <
typename MF>
1821 for (
int alev = 0; alev <= alevmax; ++alev)
1823 r = std::max(
r, ResNormInf(alev,
true));
1830template <
typename MF>
1836 for (
int alev = 0; alev <= finest_amr_lev; ++alev) {
1837 auto t = linop.normInf(alev, rhs[alev],
true);
1844template <
typename MF>
1848 auto const&
offset = linop.getSolvabilityOffset(0, 0, rhs[0]);
1850 for (
int c = 0; c < ncomp; ++c) {
1851 amrex::Print() << print_ident <<
"MLMG: Subtracting " <<
offset[c] <<
" from rhs component "
1855 for (
int alev = 0; alev < namrlevs; ++alev) {
1856 linop.fixSolvabilityByOffset(alev, 0, rhs[alev],
offset);
1860template <
typename MF>
1864 auto const&
offset = linop.getSolvabilityOffset(amrlev, mglev, mf);
1866 for (
int c = 0; c < ncomp; ++c) {
1868 <<
" from mf component c = " << c
1869 <<
" on level (" << amrlev <<
", " << mglev <<
")\n";
1872 linop.fixSolvabilityByOffset(amrlev, mglev, mf,
offset);
1875#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
1876template <
typename MF>
1877template <
class TMF,std::enable_if_t<std::is_same_v<TMF,MultiFab>,
int>>
1881 const int amrlev = 0;
1882 const int mglev = linop.NMGLevels(amrlev) - 1;
1886 if (linop.isCellCentered())
1888 if (hypre_solver ==
nullptr)
1890 hypre_solver = linop.makeHypre(hypre_interface);
1892 hypre_solver->setVerbose(bottom_verbose);
1894 hypre_solver->setHypreOptionsNamespace(hypre_options_namespace);
1896 hypre_solver->setHypreOldDefault(hypre_old_default);
1897 hypre_solver->setHypreRelaxType(hypre_relax_type);
1898 hypre_solver->setHypreRelaxOrder(hypre_relax_order);
1899 hypre_solver->setHypreNumSweeps(hypre_num_sweeps);
1900 hypre_solver->setHypreStrongThreshold(hypre_strong_threshold);
1903 const BoxArray& ba = linop.m_grids[amrlev].back();
1904 const DistributionMapping& dm = linop.m_dmap[amrlev].back();
1905 const Geometry& geom = linop.m_geom[amrlev].back();
1907 hypre_bndry = std::make_unique<MLMGBndryT<MF>>(ba, dm, ncomp, geom);
1908 hypre_bndry->setHomogValues();
1909 const Real* dx = linop.m_geom[0][0].CellSize();
1910 IntVect crse_ratio = linop.m_coarse_data_crse_ratio.
allGT(0) ? linop.m_coarse_data_crse_ratio :
IntVect(1);
1911 RealVect bclocation(
AMREX_D_DECL(0.5*dx[0]*crse_ratio[0],
1912 0.5*dx[1]*crse_ratio[1],
1913 0.5*dx[2]*crse_ratio[2]));
1914 hypre_bndry->setLOBndryConds(linop.m_lobc, linop.m_hibc,
IntVect(-1), bclocation,
1915 linop.m_coarse_fine_bc_type);
1919 amrex::Real hypre_abstol =
1921 ? bottom_abstol : Real(-1.0);
1922 hypre_solver->solve(
1923 x,
b, bottom_reltol, hypre_abstol, bottom_maxiter, *hypre_bndry,
1924 linop.getMaxOrder());
1928 if (hypre_node_solver ==
nullptr)
1931 linop.makeHypreNodeLap(bottom_verbose, hypre_options_namespace);
1933 hypre_node_solver->solve(
x,
b, bottom_reltol, bottom_abstol, bottom_maxiter);
1938 if (linop.isSingular(amrlev) && linop.getEnforceSingularSolvable())
1940 makeSolvable(amrlev, mglev,
x);
1945#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
1946template <
typename MF>
1947template <
class TMF,std::enable_if_t<std::is_same_v<TMF,MultiFab>,
int>>
1949MLMGT<MF>::bottomSolveWithPETSc (MF&
x,
const MF&
b)
1953 if(petsc_solver ==
nullptr)
1955 petsc_solver = linop.makePETSc();
1956 petsc_solver->setVerbose(bottom_verbose);
1958 const BoxArray& ba = linop.m_grids[0].back();
1959 const DistributionMapping& dm = linop.m_dmap[0].back();
1960 const Geometry& geom = linop.m_geom[0].back();
1962 petsc_bndry = std::make_unique<MLMGBndryT<MF>>(ba, dm, ncomp, geom);
1963 petsc_bndry->setHomogValues();
1964 const Real* dx = linop.m_geom[0][0].CellSize();
1965 auto crse_ratio = linop.m_coarse_data_crse_ratio.allGT(0) ? linop.m_coarse_data_crse_ratio :
IntVect(1);
1966 RealVect bclocation(
AMREX_D_DECL(0.5*dx[0]*crse_ratio[0],
1967 0.5*dx[1]*crse_ratio[1],
1968 0.5*dx[2]*crse_ratio[2]));
1969 petsc_bndry->setLOBndryConds(linop.m_lobc, linop.m_hibc,
IntVect(-1), bclocation,
1970 linop.m_coarse_fine_bc_type);
1972 petsc_solver->solve(
x,
b, bottom_reltol, Real(-1.), bottom_maxiter, *petsc_bndry,
1973 linop.getMaxOrder());
1977template <
typename MF>
1981 RT a_tol_rel,
RT a_tol_abs,
const char* a_file_name)
const
1983 std::string file_name(a_file_name);
1988 std::string HeaderFileName(std::string(a_file_name)+
"/Header");
1989 std::ofstream HeaderFile;
1990 HeaderFile.open(HeaderFileName.c_str(), std::ofstream::out |
1991 std::ofstream::trunc |
1992 std::ofstream::binary);
1993 if( ! HeaderFile.good()) {
1997 HeaderFile.precision(17);
1999 HeaderFile << linop.name() <<
"\n"
2000 <<
"a_tol_rel = " << a_tol_rel <<
"\n"
2001 <<
"a_tol_abs = " << a_tol_abs <<
"\n"
2002 <<
"verbose = " <<
verbose <<
"\n"
2003 <<
"max_iters = " << max_iters <<
"\n"
2004 <<
"nu1 = " << nu1 <<
"\n"
2005 <<
"nu2 = " << nu2 <<
"\n"
2006 <<
"nuf = " << nuf <<
"\n"
2007 <<
"nub = " << nub <<
"\n"
2008 <<
"max_fmg_iters = " << max_fmg_iters <<
"\n"
2009 <<
"bottom_solver = " <<
static_cast<int>(bottom_solver) <<
"\n"
2010 <<
"bottom_verbose = " << bottom_verbose <<
"\n"
2011 <<
"bottom_maxiter = " << bottom_maxiter <<
"\n"
2012 <<
"bottom_reltol = " << bottom_reltol <<
"\n"
2013 <<
"always_use_bnorm = " << always_use_bnorm <<
"\n"
2014 <<
"namrlevs = " << namrlevs <<
"\n"
2015 <<
"finest_amr_lev = " << finest_amr_lev <<
"\n"
2016 <<
"linop_prepared = " << linop_prepared <<
"\n"
2017 <<
"solve_called = " << solve_called <<
"\n";
2019 for (
int ilev = 0; ilev <= finest_amr_lev; ++ilev) {
2026 for (
int ilev = 0; ilev <= finest_amr_lev; ++ilev) {
2027 VisMF::Write(*a_sol[ilev], file_name+
"/Level_"+std::to_string(ilev)+
"/sol");
2028 VisMF::Write(*a_rhs[ilev], file_name+
"/Level_"+std::to_string(ilev)+
"/rhs");
2031 linop.checkPoint(file_name+
"/linop");
2034template <
typename MF>
2038 print_ident.resize(print_ident.size()+4,
' ');
2041template <
typename MF>
2045 if (print_ident.size() > 4) {
2046 print_ident.resize(print_ident.size()-4,
' ');
2048 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
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1089
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:550
static bool SameRefs(const BoxArray &lhs, const BoxArray &rhs)
whether two BoxArrays share the same data
Definition AMReX_BoxArray.H:823
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
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE 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:416
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE 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:689
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE 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:766
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:17
Definition AMReX_MLMG.H:12
void prepareForFluxes(Vector< MF const * > const &a_sol)
Definition AMReX_MLMG.H:598
void setBottomVerbose(int v) noexcept
Definition AMReX_MLMG.H:143
void setMaxFmgIter(int n) noexcept
Definition AMReX_MLMG.H:131
RT MLResNormInf(int alevmax, bool local=false)
Definition AMReX_MLMG.H:1817
RT MLRhsNormInf(bool local=false)
Definition AMReX_MLMG.H:1832
void setNoGpuSync(bool do_not_sync) noexcept
Definition AMReX_MLMG.H:158
MLMGT(MLMGT< MF > &&)=delete
void actualBottomSolve()
Definition AMReX_MLMG.H:1506
Vector< Vector< MF > > rescor
Definition AMReX_MLMG.H:335
MF MFType
Definition AMReX_MLMG.H:25
BottomSolver getBottomSolver() const noexcept
Definition AMReX_MLMG.H:141
bool linop_prepared
Definition AMReX_MLMG.H:279
int bottom_verbose
Definition AMReX_MLMG.H:265
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:1979
void setPreSmooth(int n) noexcept
Definition AMReX_MLMG.H:135
void setBottomToleranceAbs(RT t) noexcept
Definition AMReX_MLMG.H:146
Vector< Vector< MF > > cor
= rhs - L(sol)
Definition AMReX_MLMG.H:333
RT getFinalResidual() const noexcept
Definition AMReX_MLMG.H:238
int do_nsolve
N Solve.
Definition AMReX_MLMG.H:283
void interpCorrection(int alev)
Definition AMReX_MLMG.H:1719
Long solve_called
Definition AMReX_MLMG.H:280
void setBottomSmooth(int n) noexcept
Definition AMReX_MLMG.H:138
int final_fill_bc
Definition AMReX_MLMG.H:272
bool precond_mode
Definition AMReX_MLMG.H:248
void setNSolve(int flag) noexcept
Definition AMReX_MLMG.H:155
int getBottomVerbose() const
Definition AMReX_MLMG.H:123
std::unique_ptr< MF > ns_sol
Definition AMReX_MLMG.H:287
std::string print_ident
Definition AMReX_MLMG.H:290
Vector< Vector< MF > > cor_hold
Definition AMReX_MLMG.H:334
void computeResOfCorrection(int amrlev, int mglev)
Definition AMReX_MLMG.H:1796
void applyPrecond(const Vector< MF * > &out, const Vector< MF * > &in)
out = L(in) as a preconditioner
Definition AMReX_MLMG.H:989
void setCFStrategy(CFStrategy a_cf_strategy) noexcept
Definition AMReX_MLMG.H:142
void computeResWithCrseCorFineCor(int falev)
Definition AMReX_MLMG.H:1695
void NSolve(MLMGT< MF > &a_solver, MF &a_sol, MF &a_rhs)
Definition AMReX_MLMG.H:1482
typename MLLinOpT< MF >::Location Location
Definition AMReX_MLMG.H:30
RT m_final_resnorm0
Definition AMReX_MLMG.H:343
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:913
Vector< MF > rhs
Definition AMReX_MLMG.H:323
void setNSolveGridSize(int s) noexcept
Definition AMReX_MLMG.H:156
int nuf
when smoother is used as bottom solver
Definition AMReX_MLMG.H:258
bool do_no_sync_gpu
Definition AMReX_MLMG.H:292
void setVerbose(int v) noexcept
Definition AMReX_MLMG.H:129
int nu1
pre
Definition AMReX_MLMG.H:256
void computeMLResidual(int amrlevmax)
Definition AMReX_MLMG.H:1634
Vector< RT > m_iter_fine_resnorm0
Definition AMReX_MLMG.H:345
RT getInitResidual() const noexcept
Definition AMReX_MLMG.H:236
int getNumIters() const noexcept
Definition AMReX_MLMG.H:241
void setPostSmooth(int n) noexcept
Definition AMReX_MLMG.H:136
BottomSolver bottom_solver
Definition AMReX_MLMG.H:263
void mgVcycle(int amrlev, int mglev)
Definition AMReX_MLMG.H:1320
MLLinOpT< MF > & linop
Definition AMReX_MLMG.H:274
int ncomp
Definition AMReX_MLMG.H:275
void prepareForNSolve()
Definition AMReX_MLMG.H:1207
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:580
int always_use_bnorm
Definition AMReX_MLMG.H:270
int max_fmg_iters
Definition AMReX_MLMG.H:261
void makeSolvable()
Definition AMReX_MLMG.H:1846
void setBottomSolver(BottomSolver s) noexcept
Definition AMReX_MLMG.H:140
int namrlevs
Definition AMReX_MLMG.H:276
void preparePrecond()
Definition AMReX_MLMG.H:1199
int nub
additional smoothing after bottom cg solver
Definition AMReX_MLMG.H:259
void incPrintIdentation()
Definition AMReX_MLMG.H:2036
typename MLLinOpT< MF >::RT RT
Definition AMReX_MLMG.H:27
int max_iters
Definition AMReX_MLMG.H:252
int do_fixed_number_of_iters
Definition AMReX_MLMG.H:253
void setThrowException(bool t) noexcept
Definition AMReX_MLMG.H:128
void decPrintIdentation()
Definition AMReX_MLMG.H:2043
void setFixedIter(int nit) noexcept
Definition AMReX_MLMG.H:132
int finest_amr_lev
Definition AMReX_MLMG.H:277
void getGradSolution(const Vector< Array< AMF *, AMREX_SPACEDIM > > &a_grad_sol, Location a_loc=Location::FaceCenter)
Definition AMReX_MLMG.H:609
Vector< RT > const & getResidualHistory() const noexcept
Definition AMReX_MLMG.H:240
void prepareLinOp()
Definition AMReX_MLMG.H:1187
RT m_rhsnorm0
Definition AMReX_MLMG.H:341
void setPrecondIter(int nit) noexcept
Definition AMReX_MLMG.H:133
CFStrategy
Definition AMReX_MLMG.H:33
void prepareForSolve(Vector< AMF * > const &a_sol, Vector< AMF const * > const &a_rhs)
Definition AMReX_MLMG.H:1001
int bottomSolveWithCG(MF &x, const MF &b, typename MLCGSolverT< MF >::Type type)
Definition AMReX_MLMG.H:1613
std::unique_ptr< MLMGT< MF > > ns_mlmg
Definition AMReX_MLMG.H:286
void setAlwaysUseBNorm(int flag) noexcept
Definition AMReX_MLMG.H:149
void compResidual(const Vector< MF * > &a_res, const Vector< MF * > &a_sol, const Vector< MF const * > &a_rhs)
Definition AMReX_MLMG.H:845
void miniCycle(int amrlev)
Definition AMReX_MLMG.H:1309
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:266
bool throw_exception
Definition AMReX_MLMG.H:249
RT bottom_reltol
Definition AMReX_MLMG.H:267
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:332
void setFinalFillBC(int flag) noexcept
Definition AMReX_MLMG.H:151
typename MLLinOpT< MF >::BCMode BCMode
Definition AMReX_MLMG.H:29
void computeResWithCrseSolFineCor(int calev, int falev)
Definition AMReX_MLMG.H:1662
MLMGT< MF > & operator=(MLMGT< MF > const &)=delete
Vector< MF > sol
Hypre.
Definition AMReX_MLMG.H:322
int nsolve_grid_size
Definition AMReX_MLMG.H:284
MLMGT(MLLinOpT< MF > &a_lp)
Definition AMReX_MLMG.H:354
int verbose
Definition AMReX_MLMG.H:250
void computeResidual(int alev)
Definition AMReX_MLMG.H:1652
MLLinOpT< MF > & getLinOp()
Definition AMReX_MLMG.H:244
std::unique_ptr< MF > ns_rhs
Definition AMReX_MLMG.H:288
timer_types
Definition AMReX_MLMG.H:338
@ ntimers
Definition AMReX_MLMG.H:338
@ bottom_time
Definition AMReX_MLMG.H:338
@ iter_time
Definition AMReX_MLMG.H:338
@ solve_time
Definition AMReX_MLMG.H:338
CFStrategy cf_strategy
Definition AMReX_MLMG.H:264
typename MLLinOpT< MF >::FAB FAB
Definition AMReX_MLMG.H:26
Vector< int > sol_is_alias
Definition AMReX_MLMG.H:326
RT getBottomToleranceAbs() const noexcept
Definition AMReX_MLMG.H:147
int numAMRLevels() const noexcept
Definition AMReX_MLMG.H:153
RT bottom_abstol
Definition AMReX_MLMG.H:268
Vector< int > m_niters_cg
Definition AMReX_MLMG.H:344
MLMGT(MLMGT< MF > const &)=delete
void mgFcycle()
Definition AMReX_MLMG.H:1426
Vector< double > timer
Definition AMReX_MLMG.H:339
RT getInitRHS() const noexcept
Definition AMReX_MLMG.H:234
RT ResNormInf(int alev, bool local=false)
Definition AMReX_MLMG.H:1808
Vector< int > const & getNumCGIters() const noexcept
Definition AMReX_MLMG.H:242
int nu2
post
Definition AMReX_MLMG.H:257
int max_precond_iters
Definition AMReX_MLMG.H:254
void bottomSolve()
Definition AMReX_MLMG.H:1468
void getFluxes(const Vector< Array< AMF *, AMREX_SPACEDIM > > &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:640
void setBottomTolerance(RT t) noexcept
Definition AMReX_MLMG.H:145
void setFinalSmooth(int n) noexcept
Definition AMReX_MLMG.H:137
std::unique_ptr< MLLinOpT< MF > > ns_linop
Definition AMReX_MLMG.H:285
void addInterpCorrection(int alev, int mglev)
Definition AMReX_MLMG.H:1766
RT m_init_resnorm0
Definition AMReX_MLMG.H:342
int getVerbose() const
Definition AMReX_MLMG.H:122
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:144
void oneIter(int iter)
Definition AMReX_MLMG.H:1240
void setMaxIter(int n) noexcept
Definition AMReX_MLMG.H:130
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:27
Long size() const noexcept
Definition AMReX_Vector.H:50
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:975
bool setNoSyncRegion(bool b) noexcept
Definition AMReX_GpuControl.H:152
bool setSingleStreamRegion(bool b) noexcept
Definition AMReX_GpuControl.H:148
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
int nComp(FabArrayBase const &fa)
void FileOpenFailed(const std::string &file)
Output a message and abort when couldn't open the file.
Definition AMReX_Utility.cpp:131
DistributionMapping const & DistributionMap(FabArrayBase const &fa)
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:314
IntVect nGrowVect(FabArrayBase const &fa)
void EB_average_face_to_cellcenter(MultiFab &ccmf, int dcomp, const Array< MultiFab const *, AMREX_SPACEDIM > &fmf)
Definition AMReX_EBMultiFabUtil.cpp:806
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Returns a BoxND with different type.
Definition AMReX_Box.H:1435
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:922
void UtilCreateCleanDirectory(const std::string &path, bool callbarrier=true)
Create a new directory, renaming the old one if it exists.
Definition AMReX_Utility.cpp:161
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
Vector< std::array< T *, AMREX_SPACEDIM > > GetVecOfArrOfPtrs(const Vector< std::array< std::unique_ptr< T >, AMREX_SPACEDIM > > &a)
Definition AMReX_Vector.H:138
IntVectND< AMREX_SPACEDIM > IntVect
Definition AMReX_BaseFwd.H:30
BottomSolver
Definition AMReX_MLLinOp.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:127
void average_face_to_cellcenter(MultiFab &cc, int dcomp, const Vector< const MultiFab * > &fc, int ngrow)
Average face-based MultiFab onto cell-centered MultiFab.
Definition AMReX_MultiFabUtil.cpp:141
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T norm(const GpuComplex< T > &a_z) noexcept
Return the norm (magnitude squared) of a complex number.
Definition AMReX_GpuComplex.H:344
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:61
std::array< T *, AMREX_SPACEDIM > GetArrOfPtrs(std::array< T, AMREX_SPACEDIM > &a) noexcept
Definition AMReX_Array.H:982
void Scale(MF &dst, typename MF::value_type val, int scomp, int ncomp, int nghost)
dst *= val
Definition AMReX_FabArrayUtility.H:1889
std::array< T const *, AMREX_SPACEDIM > GetArrOfConstPtrs(const std::array< T, AMREX_SPACEDIM > &a) noexcept
Definition AMReX_Array.H:994
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
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)
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