33 #include "libmesh/equation_systems.h" 34 #include "libmesh/linear_implicit_system.h" 35 #include "libmesh/nonlinear_implicit_system.h" 36 #include "libmesh/petsc_linear_solver.h" 37 #include "libmesh/petsc_matrix.h" 38 #include "libmesh/petsc_nonlinear_solver.h" 39 #include "libmesh/petsc_preconditioner.h" 40 #include "libmesh/petsc_vector.h" 41 #include "libmesh/sparse_matrix.h" 42 #include "libmesh/petsc_solver_exception.h" 43 #include "libmesh/simple_range.h" 47 #include <petscsnes.h> 69 LibmeshPetscCallA(vector.
comm().
get(), VecView(petsc_vec.
vec(), 0));
76 LibmeshPetscCallA(mat.
comm().
get(), MatView(petsc_mat.
mat(), 0));
84 LibmeshPetscCallA(vector.
comm().
get(), VecView(petsc_vec.
vec(), 0));
92 LibmeshPetscCallA(mat.
comm().
get(), MatView(petsc_mat.
mat(), 0));
97 namespace PetscSupport
147 const auto prefix_with_dash =
'-' + solver_params.
_prefix;
149 switch (solver_params.
_type)
153 prefix_with_dash +
"snes_mf_operator");
155 prefix_with_dash +
"mat_mffd_type",
162 prefix_with_dash +
"mat_mffd_type",
175 dont_add_these_options, prefix_with_dash +
"snes_type",
"ksponly");
177 prefix_with_dash +
"snes_monitor_cancel");
187 dont_add_these_options, prefix_with_dash +
"snes_linesearch_type",
stringify(ls_type));
199 LibmeshPetscCallA(PETSC_COMM_WORLD, PetscGetArgs(&argc, &args));
200 #if PETSC_VERSION_LESS_THAN(3, 7, 0) 201 LibmeshPetscCallA(PETSC_COMM_WORLD, PetscOptionsInsert(&argc, &args, NULL));
203 LibmeshPetscCallA(PETSC_COMM_WORLD,
204 PetscOptionsInsert(LIBMESH_PETSC_NULLPTR, &argc, &args, NULL));
213 for (
const auto & flag : po.
flags)
221 for (
auto & option : po.
pairs)
234 PetscCallAbort(PETSC_COMM_WORLD, PetscOptionsClear(LIBMESH_PETSC_NULLPTR));
241 const std::vector<SolverParams> & solver_params_vec,
244 PetscCallAbort(PETSC_COMM_WORLD, PetscOptionsClear(LIBMESH_PETSC_NULLPTR));
245 for (
const auto & solver_params : solver_params_vec)
254 char code[10] = {45, 45, 109, 111, 111, 115, 101};
255 const std::vector<std::string> argv = cmd_line->
getArguments();
256 for (
const auto & arg : argv)
258 if (arg.compare(code) == 0)
273 SNESConvergedReason * reason,
300 *reason = SNES_CONVERGED_ITERATING;
304 *reason = SNES_CONVERGED_FNORM_ABS;
308 *reason = SNES_DIVERGED_DTOL;
317 KSP , PetscInt it, PetscReal , KSPConvergedReason * reason,
void *
ctx)
345 *reason = KSP_CONVERGED_ITERATING;
350 *reason = KSP_CONVERGED_RTOL_NORMAL;
354 *reason = KSP_DIVERGED_DTOL;
384 return KSP_NORM_NONE;
386 return KSP_NORM_PRECONDITIONED;
388 return KSP_NORM_UNPRECONDITIONED;
390 return KSP_NORM_NATURAL;
392 return KSP_NORM_DEFAULT;
394 mooseError(
"Unknown KSP norm type requested.");
405 LibmeshPetscCallA(problem.
comm().
get(),
426 auto & es = problem.
es();
429 PetscReal atol = es.parameters.get<
Real>(
"linear solver absolute tolerance");
435 PetscReal maxits = es.parameters.get<
unsigned int>(
"linear solver maximum iterations");
438 LibmeshPetscCallA(problem.
comm().
get(), KSPSetTolerances(ksp, rtol, atol, 1e100, maxits));
458 auto & lm_sys = nl.
system();
463 for (
auto & [mat_name, mat] :
as_range(lm_sys.matrices_begin(), lm_sys.matrices_end()))
468 LibmeshPetscCallA(nl.
comm().
get(),
469 MatSetOptionsPrefix(petsc_mat->mat(), (nl.
name() +
"_").c_str()));
472 LibmeshPetscCallA(nl.
comm().
get(), MatSetFromOptions(petsc_mat->mat()));
481 auto *
const petsc_solver = cast_ptr<PetscNonlinearSolver<Number> *>(nl.
nonlinearSolver());
482 const char * snes_prefix =
nullptr;
483 std::string snes_prefix_str;
487 snes_prefix = snes_prefix_str.c_str();
489 SNES snes = petsc_solver->snes(snes_prefix);
491 LibmeshPetscCallA(nl.
comm().
get(), SNESGetKSP(snes, &ksp));
493 LibmeshPetscCallA(nl.
comm().
get(), SNESSetMaxLinearSolveFailures(snes, 1000000));
495 LibmeshPetscCallA(nl.
comm().
get(), SNESSetCheckJacobianDomainError(snes, PETSC_TRUE));
517 KSP ksp = petsc_solver->
ksp();
537 #define checkPrefix(prefix) \ 538 mooseAssert(prefix[0] == '-', \ 539 "Leading prefix character must be a '-'. Current prefix is '" << prefix << "'"); \ 540 mooseAssert((prefix.size() == 1) || (prefix.back() == '_'), \ 541 "Terminating prefix character must be a '_'. Current prefix is '" << prefix << "'"); \ 542 mooseAssert(MooseUtils::isAllLowercase(prefix), "PETSc prefixes should be all lower-case") 546 const std::string & prefix,
549 const auto & params = param_object.
parameters();
553 const auto & petsc_options = params.get<
MultiMooseEnum>(
"petsc_options");
554 const auto & petsc_pair_options =
555 params.
get<
MooseEnumItem, std::string>(
"petsc_options_iname",
"petsc_options_value");
566 petsc_pair_options, fe_problem.
mesh().
dimension(), prefix, param_object, po);
576 const std::string & solve_type = params.
get<
MooseEnum>(
"solve_type");
578 fe_problem.
solverParams(i).
_type = Moose::stringToEnum<Moose::SolveType>(solve_type);
588 const auto & line_search = params.
get<
MooseEnum>(
"line_search");
593 Moose::stringToEnum<Moose::LineSearchType>(line_search);
600 mooseError(
"You've requested a line search but you must be solving an EigenProblem. " 601 "These two things are not consistent.");
604 if (!petsc_nonlinear_solver)
605 mooseError(
"Currently the MOOSE line searches all use Petsc, so you " 606 "must use Petsc as your non-linear solver.");
608 std::make_unique<ComputeLineSearchObjectWrapper>(fe_problem);
619 const auto & mffd_type = params.
get<
MooseEnum>(
"mffd_type");
625 template <
typename T>
629 const auto & string_option =
static_cast<const std::string &
>(option);
630 if (string_option[0] !=
'-')
631 param_object.
mooseError(
"PETSc option '", string_option,
"' does not begin with '-'");
640 prefix.insert(prefix.begin(),
'-');
644 for (
const auto & option : petsc_flags)
648 const std::string & string_option = option.name();
656 if (option ==
"-log_summary" || option ==
"-log_view")
657 mooseError(
"The PETSc option \"-log_summary\" or \"-log_view\" can only be used on the " 658 "command line. Please " 659 "remove it from the input file");
662 const std::string prefixed_option = prefix + string_option.substr(1);
674 prefix.insert(prefix.begin(),
'-');
678 #if !PETSC_VERSION_LESS_THAN(3, 14, 0) 681 std::array<std::string, 2> reason_flags = {{
"snes_converged_reason",
"ksp_converged_reason"}};
685 for (
const auto & reason_flag : reason_flags)
686 if (!po.flags.isValueSet(prefix + reason_flag) &&
687 (std::find_if(po.pairs.begin(),
689 [&reason_flag, &prefix](
auto & pair)
690 {
return pair.first == (prefix + reason_flag); }) == po.pairs.end()))
691 po.
pairs.emplace_back(prefix + reason_flag,
"::failed");
697 const std::vector<std::pair<MooseEnumItem, std::string>> & petsc_pair_options,
698 const unsigned int mesh_dimension,
703 prefix.insert(prefix.begin(),
'-');
707 bool boomeramg_found =
false;
708 bool strong_threshold_found =
false;
709 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 710 bool superlu_dist_found =
false;
711 bool fact_pattern_found =
false;
712 bool tiny_pivot_found =
false;
714 std::string pc_description =
"";
715 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 717 bool hmg_found =
false;
718 bool matptap_found =
false;
719 bool hmg_strong_threshold_found =
false;
721 std::vector<std::pair<std::string, std::string>> new_options;
723 for (
const auto & [option_name, option_value] : petsc_pair_options)
728 const std::string prefixed_option_name =
729 prefix +
static_cast<const std::string &
>(option_name).substr(1);
734 it == po.
pairs.end())
736 #if !PETSC_VERSION_LESS_THAN(3, 9, 0) 737 if (option_name ==
"-pc_factor_mat_solver_package")
738 new_options.emplace_back(prefix +
"pc_factor_mat_solver_type", option_value);
740 if (option_name ==
"-pc_factor_mat_solver_type")
741 new_options.push_back(prefix +
"pc_factor_mat_solver_package", option_value);
745 if (option_name ==
"-pc_type" || option_name ==
"-sub_pc_type" ||
746 option_name ==
"-pc_hypre_type")
747 pc_description += option_value +
' ';
749 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 750 if (option_name ==
"-pc_type" && option_value ==
"hmg")
759 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 760 if (hmg_found && (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via" ||
761 option_name ==
"-matproduct_ptap_via"))
762 new_options.emplace_back(prefix +
"mat_product_algorithm", option_value);
763 #elif !PETSC_VERSION_LESS_THAN(3, 13, 0) 764 if (hmg_found && (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via"))
765 new_options.emplace_back(prefix +
"matproduct_ptap_via", option_value);
767 if (hmg_found && (option_name ==
"-matproduct_ptap_via"))
769 new_options.emplace_back(prefix +
"matptap_via", option_value);
770 new_options.emplace_back(prefix +
"matmaijptap_via", option_value);
774 if (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via" ||
775 option_name ==
"-matproduct_ptap_via" || option_name ==
"-mat_product_algorithm")
776 matptap_found =
true;
779 if (option_name ==
"-hmg_inner_pc_hypre_boomeramg_strong_threshold")
780 hmg_strong_threshold_found =
true;
783 if (option_name ==
"-pc_hypre_type" && option_value ==
"boomeramg")
784 boomeramg_found =
true;
785 if (option_name ==
"-pc_hypre_boomeramg_strong_threshold")
786 strong_threshold_found =
true;
787 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 788 if ((option_name ==
"-pc_factor_mat_solver_package" ||
789 option_name ==
"-pc_factor_mat_solver_type") &&
790 option_value ==
"superlu_dist")
791 superlu_dist_found =
true;
792 if (option_name ==
"-mat_superlu_dist_fact")
793 fact_pattern_found =
true;
794 if (option_name ==
"-mat_superlu_dist_replacetinypivot")
795 tiny_pivot_found =
true;
798 if (!new_options.empty())
800 std::copy(new_options.begin(), new_options.end(), std::back_inserter(po.
pairs));
801 for (
const auto & option : new_options)
806 po.
pairs.push_back(std::make_pair(prefixed_option_name, option_value));
814 it->second = option_value;
816 }
while (it != po.
pairs.end());
822 if (boomeramg_found && !strong_threshold_found && mesh_dimension == 3)
824 po.
pairs.emplace_back(prefix +
"pc_hypre_boomeramg_strong_threshold",
"0.7");
825 pc_description +=
"strong_threshold: 0.7 (auto)";
828 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 829 if (hmg_found && !hmg_strong_threshold_found && mesh_dimension == 3)
831 po.
pairs.emplace_back(prefix +
"hmg_inner_pc_hypre_boomeramg_strong_threshold",
"0.7");
832 pc_description +=
"strong_threshold: 0.7 (auto)";
837 if (hmg_found && !matptap_found)
839 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 840 po.
pairs.emplace_back(prefix +
"mat_product_algorithm",
"allatonce");
841 #elif !PETSC_VERSION_LESS_THAN(3, 13, 0) 842 po.
pairs.emplace_back(prefix +
"matproduct_ptap_via",
"allatonce");
844 po.
pairs.emplace_back(prefix +
"matptap_via",
"allatonce");
845 po.
pairs.emplace_back(prefix +
"matmaijptap_via",
"allatonce");
850 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 853 if (superlu_dist_found && !fact_pattern_found)
855 po.
pairs.emplace_back(prefix +
"mat_superlu_dist_fact",
856 #
if PETSC_VERSION_LESS_THAN(3, 7, 5)
857 "SamePattern_SameRowPerm");
858 pc_description +=
"mat_superlu_dist_fact: SamePattern_SameRowPerm ";
861 pc_description +=
"mat_superlu_dist_fact: SamePattern ";
866 if (superlu_dist_found && !tiny_pivot_found)
868 po.
pairs.emplace_back(prefix +
"mat_superlu_dist_replacetinypivot",
"1");
869 pc_description +=
" mat_superlu_dist_replacetinypivot: true ";
873 if (!pc_description.empty() && prefix.size() > 1)
874 po.
pc_description +=
"[" + prefix.substr(1, prefix.size() - 2) +
"]: ";
878 std::set<std::string>
881 return {
"default",
"shell",
"none",
"basic",
"l2",
"bt",
"cp"};
889 MooseEnum solve_type(
"PJFNK JFNK NEWTON FD LINEAR");
892 "PJFNK: Preconditioned Jacobian-Free Newton Krylov " 893 "JFNK: Jacobian-Free Newton Krylov " 894 "NEWTON: Full Newton Solve " 895 "FD: Use finite differences to compute Jacobian " 896 "LINEAR: Solving a linear problem");
901 "Specifies the finite differencing type for " 902 "Jacobian-free solve types. Note that the " 903 "default is wp (for Walker and Pernice).");
909 params.
addParam<std::vector<std::string>>(
910 "petsc_options_value",
911 "Values of PETSc name/value pairs (must correspond with \"petsc_options_iname\"");
923 "-ksp_monitor_snes_lg -snes_ksp_ew -ksp_snes_ew -snes_converged_reason " 924 "-snes_ksp -snes_linesearch_monitor -snes_mf -snes_mf_operator -snes_monitor " 925 "-snes_test_display -snes_view -snes_monitor_cancel",
934 "-ksp_converged_reason -ksp_gmres_modifiedgramschmidt -ksp_monitor",
"",
true);
940 auto options =
MultiMooseEnum(
"-dm_moose_print_embedding -dm_view",
"",
true);
949 return MultiMooseEnum(
"-snes_atol -snes_linesearch_type -snes_ls -snes_max_it -snes_rtol " 950 "-snes_divergence_tolerance -snes_type",
958 return MultiMooseEnum(
"-ksp_atol -ksp_gmres_restart -ksp_max_it -ksp_pc_side -ksp_rtol " 959 "-ksp_type -sub_ksp_type",
966 auto options =
MultiMooseEnum(
"-mat_fd_coloring_err -mat_fd_type -mat_mffd_type " 967 "-pc_asm_overlap -pc_factor_levels " 968 "-pc_factor_mat_ordering_type -pc_hypre_boomeramg_grid_sweeps_all " 969 "-pc_hypre_boomeramg_max_iter " 970 "-pc_hypre_boomeramg_strong_threshold -pc_hypre_type -pc_type " 986 LibmeshPetscCallA(fe_problem.
comm().
get(), PetscGetArgs(&argc, &args));
988 std::vector<std::string> cml_arg;
989 for (
int i = 0; i < argc; i++)
990 cml_arg.push_back(args[i]);
996 std::find(cml_arg.begin(), cml_arg.end(),
"vinewtonssls") == cml_arg.end() &&
997 std::find(cml_arg.begin(), cml_arg.end(),
"vinewtonrsls") == cml_arg.end())
1005 const std::string & value ,
1010 LibmeshPetscCallA(comm.
get(),
1011 PetscOptionsSetValue(LIBMESH_PETSC_NULLPTR,
1013 value ==
"" ? LIBMESH_PETSC_NULLPTR :
value.c_str()));
1015 auto check_problem = [problem, &lower_case_name]()
1019 "Setting the option '",
1021 "' requires passing a 'problem' parameter. Contact a developer of your application " 1022 "to have them update their code. If in doubt, reach out to the MOOSE team on Github " 1027 if (lower_case_name.find(
"-vec_type") != std::string::npos)
1032 auto & lm_sys = solver_system->system();
1033 for (
auto & [vec_name, vec] :
as_range(lm_sys.vectors_begin(), lm_sys.vectors_end()))
1036 auto *
const petsc_vec = cast_ptr<PetscVector<Number> *>(vec.get());
1037 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1040 auto * petsc_vec = cast_ptr<PetscVector<Number> *>(lm_sys.solution.get());
1041 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1042 petsc_vec = cast_ptr<PetscVector<Number> *>(lm_sys.current_local_solution.get());
1043 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1047 else if (lower_case_name.find(
"mat_type") != std::string::npos)
1051 bool found_matching_prefix =
false;
1061 "Setting option '", lower_case_name,
"' is incompatible with a JFNK 'solve_type'");
1064 for (
auto & [mat_name, mat] :
as_range(lm_sys.matrices_begin(), lm_sys.matrices_end()))
1070 const char * mat_prefix;
1071 LibmeshPetscCallA(comm.
get(), MatGetOptionsPrefix(petsc_mat->mat(), &mat_prefix));
1072 mooseAssert(strcmp(mat_prefix, (solver_sys_name +
"_").c_str()) == 0,
1073 "We should have prefixed these matrices previously");
1075 LibmeshPetscCallA(comm.
get(), MatSetFromOptions(petsc_mat->mat()));
1078 found_matching_prefix =
true;
1082 if (!found_matching_prefix)
1083 mooseError(
"We did not find a matching solver system name for the petsc option '",
1091 const std::string & name,
1092 const std::string & value ,
1102 unsigned int colors,
1103 std::vector<unsigned int> & vertex_colors,
1104 const char * coloring_algorithm)
1108 LibmeshPetscCallA(PETSC_COMM_SELF, MatCreate(PETSC_COMM_SELF, &A));
1109 LibmeshPetscCallA(PETSC_COMM_SELF, MatSetSizes(A, size, size, size, size));
1110 LibmeshPetscCallA(PETSC_COMM_SELF, MatSetType(A, MATSEQDENSE));
1112 LibmeshPetscCallA(PETSC_COMM_SELF, MatSeqDenseSetPreallocation(A, adjacency_matrix));
1113 LibmeshPetscCallA(PETSC_COMM_SELF, MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
1114 LibmeshPetscCallA(PETSC_COMM_SELF, MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
1117 #if PETSC_VERSION_LESS_THAN(3, 7, 0) 1118 LibmeshPetscCallA(PETSC_COMM_SELF, MatConvert(A, MATAIJ, MAT_REUSE_MATRIX, &A));
1120 LibmeshPetscCallA(PETSC_COMM_SELF, MatConvert(A, MATAIJ, MAT_INPLACE_MATRIX, &A));
1123 ISColoring iscoloring;
1125 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringCreate(A, &mc));
1126 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetType(mc, coloring_algorithm));
1127 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetMaxColors(mc, static_cast<PetscInt>(colors)));
1130 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetDistance(mc, 1));
1131 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetFromOptions(mc));
1132 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringApply(mc, &iscoloring));
1136 #if PETSC_RELEASE_LESS_THAN(3, 12, 0) 1137 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringGetIS(iscoloring, &nn, &
is));
1139 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringGetIS(iscoloring, PETSC_USE_POINTER, &nn, &
is));
1142 if (nn > static_cast<PetscInt>(colors))
1143 throw std::runtime_error(
"Not able to color with designated number of colors");
1145 for (
int i = 0; i < nn; i++)
1148 const PetscInt * indices;
1149 LibmeshPetscCallA(PETSC_COMM_SELF, ISGetLocalSize(
is[i], &isize));
1150 LibmeshPetscCallA(PETSC_COMM_SELF, ISGetIndices(
is[i], &indices));
1151 for (
int j = 0; j < isize; j++)
1153 mooseAssert(indices[j] < static_cast<PetscInt>(vertex_colors.size()),
"Index out of bounds");
1154 vertex_colors[indices[j]] = i;
1156 LibmeshPetscCallA(PETSC_COMM_SELF, ISRestoreIndices(
is[i], &indices));
1159 LibmeshPetscCallA(PETSC_COMM_SELF, MatDestroy(&A));
1160 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringDestroy(&mc));
1161 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringDestroy(&iscoloring));
1198 if (!petsc_options.dont_add_these_options.contains(flag))
1201 if (!petsc_options.dont_add_these_options.contains(key))
1202 petsc_options.dont_add_these_options.setAdditionalValue(key);
1205 std::unique_ptr<PetscMatrix<Number>>
1208 const std::string & binary_mat_file,
1209 const unsigned int mat_number_to_load)
1211 LibmeshPetscCallA(comm.
get(), MatCreate(comm.
get(), &mat));
1212 PetscViewer matviewer;
1215 PetscViewerBinaryOpen(comm.
get(), binary_mat_file.c_str(), FILE_MODE_READ, &matviewer));
1216 for (
unsigned int i = 0; i < mat_number_to_load; ++i)
1217 LibmeshPetscCallA(comm.
get(), MatLoad(mat, matviewer));
1218 LibmeshPetscCallA(comm.
get(), PetscViewerDestroy(&matviewer));
1220 return std::make_unique<PetscMatrix<Number>>(mat, comm);
std::string name(const ElemQuality q)
MultiMooseEnum getCommonKSPKeys()
A helper function to produce a MultiMooseEnum with commonly used PETSc ksp option names (keys) ...
MultiMooseEnum getCommonPetscKeys()
A helper function to produce a MultiMooseEnum with commonly used PETSc iname options (keys in key-val...
void resetFailNextNonlinearConvergenceCheck()
Tell the problem that the nonlinear convergence check(s) may proceed as normal.
bool isSNESVI(FEProblemBase &fe_problem)
check if SNES type is variational inequalities (VI) solver
const std::vector< ConvergenceName > & getNonlinearConvergenceNames() const
Gets the nonlinear system convergence object name(s).
Moose::PetscSupport::PetscOptions & getPetscOptions()
Retrieve a writable reference the PETSc options (used by PetscSupport)
void addPetscFlagsToPetscOptions(const MultiMooseEnum &petsc_flags, std::string prefix, const ParallelParamObject ¶m_object, PetscOptions &petsc_options)
Populate flags in a given PetscOptions object using a vector of input arguments.
KSPNormType getPetscKSPNormType(Moose::MooseKSPNormType kspnorm)
void addPetscOptionsFromCommandline()
void setMFFDTypeFromParams(FEProblemBase &fe_problem, const InputParameters ¶ms)
Sets the FE problem's matrix-free finite difference type from the input params.
std::unique_ptr< NonlinearSolver< Number > > nonlinear_solver
std::string toLower(const std::string &name)
Convert supplied string to lower case.
const ExecFlagType EXEC_NONLINEAR_CONVERGENCE
static void petscSetupOutput()
Output string for setting up PETSC output.
virtual std::size_t numNonlinearSystems() const override
std::set< std::string > getPetscValidLineSearches()
Returns the valid petsc line search options as a set of strings.
Moose::LineSearchType _line_search
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
void setAdditionalValue(const std::string &names)
Insert operators Operator to insert (push_back) values into the enum.
const ExecFlagType EXEC_LINEAR_CONVERGENCE
void addPetscPairsToPetscOptions(const std::vector< std::pair< MooseEnumItem, std::string >> &petsc_pair_options, const unsigned int mesh_dimension, std::string prefix, const ParallelParamObject ¶m_object, PetscOptions &petsc_options)
Populate name and value pairs in a given PetscOptions object using vectors of input arguments...
void petscSetDefaults(FEProblemBase &problem)
Sets the default options for PETSc.
libMesh::LinearImplicitSystem & linearImplicitSystem()
Return a reference to the stored linear implicit system.
virtual MooseConvergenceStatus checkConvergence(unsigned int iter)=0
Returns convergence status.
MultiMooseEnum getCommonSNESFlags()
A helper function to produce a MultiMooseEnum with commonly used PETSc snes single options (flags) ...
const InputParameters & parameters() const
Get the parameters of the object.
A struct for storing the various types of petsc options and values.
MultiMooseEnum flags
Single value PETSc options (flags)
void setSolveTypeFromParams(FEProblemBase &fe_problem, const InputParameters ¶ms)
Sets the FE problem's solve type from the input params.
const Parallel::Communicator & comm() const
void petscSetDefaultKSPNormType(FEProblemBase &problem, KSP ksp)
Set norm type.
std::unique_ptr< PetscMatrix< Number > > createMatrixFromFile(const libMesh::Parallel::Communicator &comm, Mat &petsc_mat, const std::string &binary_mat_file, unsigned int mat_number_to_load=1)
Create a matrix from a binary file.
Solving a linear problem.
void petscSetKSPDefaults(FEProblemBase &problem, KSP ksp)
Set the default options for a KSP.
std::vector< std::shared_ptr< SolverSystem > > _solver_systems
Combined container to base pointer of every solver system.
std::vector< std::pair< std::string, std::string > > pairs
PETSc key-value pairs.
virtual libMesh::NonlinearSolver< Number > * nonlinearSolver()=0
virtual LinearSolver< Number > * get_linear_solver() const override
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
MffdType
Type of the matrix-free finite-differencing parameter.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool hasLinearConvergenceObjects() const
Whether we have linear convergence objects.
This class wraps provides and tracks access to command line parameters.
MooseKSPNormType
Norm type for converge test.
Nonlinear system to be solved.
virtual const std::string & name() const
PCSide getPetscPCSide(Moose::PCSideType pcs)
void processSingletonMooseWrappedOptions(FEProblemBase &fe_problem, const InputParameters ¶ms)
Process some MOOSE-wrapped PETSc options.
void checkUserProvidedPetscOption(const T &option, const ParallelParamObject ¶m_object)
void setConvergedReasonFlags(FEProblemBase &fe_problem, std::string prefix)
Set flags that will instruct the user on the reason their simulation diverged from PETSc's perspectiv...
bool contains(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
std::vector< SolverSystemName > _solver_sys_names
The union of nonlinear and linear system names.
virtual void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
void dontAddCommonKSPOptions(FEProblemBase &fe_problem)
Function to ensure that common KSP options are not added to the PetscOptions storage object to be lat...
PetscErrorCode petscLinearConverged(KSP, PetscInt it, PetscReal, KSPConvergedReason *reason, void *ctx)
void libmesh_ignore(const Args &...)
Use whatever we have in PETSc.
PetscErrorCode petscNonlinearConverged(SNES, PetscInt it, PetscReal, PetscReal, PetscReal, SNESConvergedReason *reason, void *ctx)
const T & get(std::string_view) const
MultiMooseEnum getCommonPetscFlags()
A helper function to produce a MultiMooseEnum with commonly used PETSc single options (flags) ...
Moose::MffdType _mffd_type
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
LineSearchType
Type of the line search.
virtual Convergence & getConvergence(const std::string &name, const THREAD_ID tid=0) const
Gets a Convergence object.
void MooseMatView(SparseMatrix< Number > &mat)
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
std::string prefix() const
Use whatever we have in PETSc.
void dontAddPetscFlag(const std::string &flag, PetscOptions &petsc_options)
Function to ensure that a particular petsc option is not added to the PetscOptions storage object to ...
std::string stringify(const MffdType &t)
NonlinearSystemBase & currentNonlinearSystem()
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Jacobian-Free Newton Krylov.
virtual libMesh::EquationSystems & es() override
void setSolverOptions(const SolverParams &solver_params, const MultiMooseEnum &dont_add_these_options)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
PetscErrorCode PetscInt const PetscInt IS * is
Use finite differences to compute Jacobian.
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
bool isValueSet(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
unsigned int number() const
Gets the number of this system.
void petscSetOptions(const PetscOptions &po, const SolverParams &solver_params, FEProblemBase *const problem=nullptr)
A function for setting the PETSc options in PETSc from the options supplied to MOOSE.
bool getFailNextSystemConvergenceCheck() const
Whether it will fail the next system convergence check(s), triggering failed step behavior...
LinearSystem & getLinearSystem(unsigned int sys_num)
Get non-constant reference to a linear system.
MooseConvergenceStatus
Status returned by calls to checkConvergence.
auto findPair(C &container, It start_iterator, const M1 &first, const M2 &second)
Find a specific pair in a container matching on first, second or both pair components.
void setLineSearchFromParams(FEProblemBase &fe_problem, const InputParameters ¶ms)
Sets the FE problem's line search from the input params.
void dontAddCommonSNESOptions(FEProblemBase &fe_problem)
Function to ensure that common SNES options are not added to the PetscOptions storage object to be la...
unsigned int get(unsigned int i) const
Indexing operator Operator to retrieve the id of an item from the MultiMooseEnum. ...
void setSinglePetscOption(const std::string &name, const std::string &value="", FEProblemBase *const problem=nullptr)
A wrapper function for dealing with different versions of PetscOptionsSetValue.
MultiMooseEnum getCommonKSPFlags()
A helper function to produce a MultiMooseEnum with commonly used PETSc ksp single options (flags) ...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
InputParameters getPetscValidParams()
Returns the PETSc options that are common between Executioners and Preconditioners.
PetscErrorCode petscSetupOutput(CommandLine *cmd_line)
std::unique_ptr< ComputeLineSearchObject > linesearch_object
Class for containing MooseEnum item information.
void petscSetOptionsHelper(const PetscOptions &po, FEProblemBase *const problem)
void dontAddNonlinearConvergedReason(FEProblemBase &fe_problem)
Function to ensure that -snes_converged_reason is not added to the PetscOptions storage object to be ...
void colorAdjacencyMatrix(PetscScalar *adjacency_matrix, unsigned int size, unsigned int colors, std::vector< unsigned int > &vertex_colors, const char *coloring_algorithm)
This method takes an adjacency matrix, and a desired number of colors and applies a graph coloring al...
bool getFailNextNonlinearConvergenceCheck() const
Whether it will skip further residual evaluations and fail the next nonlinear convergence check(s) ...
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
LinearSystem & currentLinearSystem()
Get a non-constant reference to the current linear system.
void resetFailNextSystemConvergenceCheck()
Tell the problem that the system convergence check(s) may proceed as normal.
PCSideType
Preconditioning side.
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
SolverSystem & getSolverSystem(unsigned int sys_num)
Get non-constant reference to a solver system.
MultiMooseEnum getCommonSNESKeys()
A helper function to produce a MultiMooseEnum with commonly used PETSc snes option names (keys) ...
Linear system to be solved.
void setSinglePetscOptionIfAppropriate(const MultiMooseEnum &dont_add_these_options, const std::string &name, const std::string &value="", FEProblemBase *const problem=nullptr)
Same as setSinglePetscOption, but does not set the option if it doesn't make sense for the current si...
void dontAddLinearConvergedReason(FEProblemBase &fe_problem)
Function to ensure that -ksp_converged_reason is not added to the PetscOptions storage object to be l...
Preconditioned Jacobian-Free Newton Krylov.
virtual std::size_t numLinearSystems() const override
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type...
void storePetscOptions(FEProblemBase &fe_problem, const std::string &prefix, const ParallelParamObject ¶m_object)
Stores the PETSc options supplied from the parameter object on the problem.
std::string pc_description
Preconditioner description.
static const struct MooseUtils::AnyType Any
MultiMooseEnum dont_add_these_options
Flags to explicitly not set, even if they are specified programmatically.
Moose::MooseKSPNormType getMooseKSPNormType()
Get the norm in which the linear convergence is measured.
void prefix_with_name(bool value)
Base class shared by both Action and MooseObject.
PetscFunctionReturn(LIBMESH_PETSC_SUCCESS)
void MooseVecView(NumericVector< Number > &vector)
virtual std::size_t numSolverSystems() const override
MultiMooseEnum user_set_options
Options that are set by the user at the input level.
auto index_range(const T &sizable)
const std::vector< std::string > & getArguments()
Moose::PCSideType getPCSide()
Get the current preconditioner side.
void petscSetDefaultPCSide(FEProblemBase &problem, KSP ksp)
Setup which side we want to apply preconditioner.
const std::vector< ConvergenceName > & getLinearConvergenceNames() const
Gets the linear convergence object name(s).
virtual libMesh::System & system() override
Get the reference to the libMesh system.