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 #if PETSC_VERSION_LESS_THAN(3, 24, 0) 351 *reason = KSP_CONVERGED_RTOL_NORMAL;
353 *reason = KSP_CONVERGED_RTOL_NORMAL_EQUATIONS;
358 *reason = KSP_DIVERGED_DTOL;
388 return KSP_NORM_NONE;
390 return KSP_NORM_PRECONDITIONED;
392 return KSP_NORM_UNPRECONDITIONED;
394 return KSP_NORM_NATURAL;
396 return KSP_NORM_DEFAULT;
398 mooseError(
"Unknown KSP norm type requested.");
409 LibmeshPetscCallA(problem.
comm().
get(),
430 auto & es = problem.
es();
433 PetscReal atol = es.parameters.get<
Real>(
"linear solver absolute tolerance");
439 PetscReal maxits = es.parameters.get<
unsigned int>(
"linear solver maximum iterations");
442 LibmeshPetscCallA(problem.
comm().
get(), KSPSetTolerances(ksp, rtol, atol, 1e100, maxits));
462 auto & lm_sys = nl.
system();
467 for (
auto & [mat_name, mat] :
as_range(lm_sys.matrices_begin(), lm_sys.matrices_end()))
472 LibmeshPetscCallA(nl.
comm().
get(),
473 MatSetOptionsPrefix(petsc_mat->mat(), (nl.
name() +
"_").c_str()));
476 LibmeshPetscCallA(nl.
comm().
get(), MatSetFromOptions(petsc_mat->mat()));
485 auto *
const petsc_solver = cast_ptr<PetscNonlinearSolver<Number> *>(nl.
nonlinearSolver());
486 const char * snes_prefix =
nullptr;
487 std::string snes_prefix_str;
491 snes_prefix = snes_prefix_str.c_str();
493 SNES snes = petsc_solver->snes(snes_prefix);
495 LibmeshPetscCallA(nl.
comm().
get(), SNESGetKSP(snes, &ksp));
497 LibmeshPetscCallA(nl.
comm().
get(), SNESSetMaxLinearSolveFailures(snes, 1000000));
499 LibmeshPetscCallA(nl.
comm().
get(), SNESSetCheckJacobianDomainError(snes, PETSC_TRUE));
521 KSP ksp = petsc_solver->
ksp();
541 #define checkPrefix(prefix) \ 542 mooseAssert(prefix[0] == '-', \ 543 "Leading prefix character must be a '-'. Current prefix is '" << prefix << "'"); \ 544 mooseAssert((prefix.size() == 1) || (prefix.back() == '_'), \ 545 "Terminating prefix character must be a '_'. Current prefix is '" << prefix << "'"); \ 546 mooseAssert(MooseUtils::isAllLowercase(prefix), "PETSc prefixes should be all lower-case") 550 const std::string & prefix,
553 const auto & params = param_object.
parameters();
557 const auto & petsc_options = params.get<
MultiMooseEnum>(
"petsc_options");
558 const auto & petsc_pair_options =
559 params.
get<
MooseEnumItem, std::string>(
"petsc_options_iname",
"petsc_options_value");
570 petsc_pair_options, fe_problem.
mesh().
dimension(), prefix, param_object, po);
580 const std::string & solve_type = params.
get<
MooseEnum>(
"solve_type");
582 fe_problem.
solverParams(i).
_type = Moose::stringToEnum<Moose::SolveType>(solve_type);
592 const auto & line_search = params.
get<
MooseEnum>(
"line_search");
597 Moose::stringToEnum<Moose::LineSearchType>(line_search);
604 mooseError(
"You've requested a line search but you must be solving an EigenProblem. " 605 "These two things are not consistent.");
608 if (!petsc_nonlinear_solver)
609 mooseError(
"Currently the MOOSE line searches all use Petsc, so you " 610 "must use Petsc as your non-linear solver.");
612 std::make_unique<ComputeLineSearchObjectWrapper>(fe_problem);
623 const auto & mffd_type = params.
get<
MooseEnum>(
"mffd_type");
629 template <
typename T>
633 const auto & string_option =
static_cast<const std::string &
>(option);
634 if (string_option[0] !=
'-')
635 param_object.
mooseError(
"PETSc option '", string_option,
"' does not begin with '-'");
644 prefix.insert(prefix.begin(),
'-');
648 for (
const auto & option : petsc_flags)
652 const std::string & string_option = option.name();
660 if (option ==
"-log_summary" || option ==
"-log_view")
661 mooseError(
"The PETSc option \"-log_summary\" or \"-log_view\" can only be used on the " 662 "command line. Please " 663 "remove it from the input file");
666 const std::string prefixed_option = prefix + string_option.substr(1);
678 prefix.insert(prefix.begin(),
'-');
682 #if !PETSC_VERSION_LESS_THAN(3, 14, 0) 685 std::array<std::string, 2> reason_flags = {{
"snes_converged_reason",
"ksp_converged_reason"}};
689 for (
const auto & reason_flag : reason_flags)
690 if (!po.flags.isValueSet(prefix + reason_flag) &&
691 (std::find_if(po.pairs.begin(),
693 [&reason_flag, &prefix](
auto & pair)
694 {
return pair.first == (prefix + reason_flag); }) == po.pairs.end()))
695 po.
pairs.emplace_back(prefix + reason_flag,
"::failed");
701 const std::vector<std::pair<MooseEnumItem, std::string>> & petsc_pair_options,
702 const unsigned int mesh_dimension,
707 prefix.insert(prefix.begin(),
'-');
711 bool boomeramg_found =
false;
712 bool strong_threshold_found =
false;
713 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 714 bool superlu_dist_found =
false;
715 bool fact_pattern_found =
false;
716 bool tiny_pivot_found =
false;
718 std::string pc_description =
"";
719 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 721 bool hmg_found =
false;
722 bool matptap_found =
false;
723 bool hmg_strong_threshold_found =
false;
725 std::vector<std::pair<std::string, std::string>> new_options;
727 for (
const auto & [option_name, option_value] : petsc_pair_options)
732 const std::string prefixed_option_name =
733 prefix +
static_cast<const std::string &
>(option_name).substr(1);
738 it == po.
pairs.end())
740 #if !PETSC_VERSION_LESS_THAN(3, 9, 0) 741 if (option_name ==
"-pc_factor_mat_solver_package")
742 new_options.emplace_back(prefix +
"pc_factor_mat_solver_type", option_value);
744 if (option_name ==
"-pc_factor_mat_solver_type")
745 new_options.push_back(prefix +
"pc_factor_mat_solver_package", option_value);
749 if (option_name ==
"-pc_type" || option_name ==
"-sub_pc_type" ||
750 option_name ==
"-pc_hypre_type")
751 pc_description += option_value +
' ';
753 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 754 if (option_name ==
"-pc_type" && option_value ==
"hmg")
763 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 764 if (hmg_found && (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via" ||
765 option_name ==
"-matproduct_ptap_via"))
766 new_options.emplace_back(prefix +
"mat_product_algorithm", option_value);
767 #elif !PETSC_VERSION_LESS_THAN(3, 13, 0) 768 if (hmg_found && (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via"))
769 new_options.emplace_back(prefix +
"matproduct_ptap_via", option_value);
771 if (hmg_found && (option_name ==
"-matproduct_ptap_via"))
773 new_options.emplace_back(prefix +
"matptap_via", option_value);
774 new_options.emplace_back(prefix +
"matmaijptap_via", option_value);
778 if (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via" ||
779 option_name ==
"-matproduct_ptap_via" || option_name ==
"-mat_product_algorithm")
780 matptap_found =
true;
783 if (option_name ==
"-hmg_inner_pc_hypre_boomeramg_strong_threshold")
784 hmg_strong_threshold_found =
true;
787 if (option_name ==
"-pc_hypre_type" && option_value ==
"boomeramg")
788 boomeramg_found =
true;
789 if (option_name ==
"-pc_hypre_boomeramg_strong_threshold")
790 strong_threshold_found =
true;
791 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 792 if ((option_name ==
"-pc_factor_mat_solver_package" ||
793 option_name ==
"-pc_factor_mat_solver_type") &&
794 option_value ==
"superlu_dist")
795 superlu_dist_found =
true;
796 if (option_name ==
"-mat_superlu_dist_fact")
797 fact_pattern_found =
true;
798 if (option_name ==
"-mat_superlu_dist_replacetinypivot")
799 tiny_pivot_found =
true;
802 if (!new_options.empty())
804 std::copy(new_options.begin(), new_options.end(), std::back_inserter(po.
pairs));
805 for (
const auto & option : new_options)
810 po.
pairs.push_back(std::make_pair(prefixed_option_name, option_value));
818 it->second = option_value;
820 }
while (it != po.
pairs.end());
826 if (boomeramg_found && !strong_threshold_found && mesh_dimension == 3)
828 po.
pairs.emplace_back(prefix +
"pc_hypre_boomeramg_strong_threshold",
"0.7");
829 pc_description +=
"strong_threshold: 0.7 (auto)";
832 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 833 if (hmg_found && !hmg_strong_threshold_found && mesh_dimension == 3)
835 po.
pairs.emplace_back(prefix +
"hmg_inner_pc_hypre_boomeramg_strong_threshold",
"0.7");
836 pc_description +=
"strong_threshold: 0.7 (auto)";
841 if (hmg_found && !matptap_found)
843 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 844 po.
pairs.emplace_back(prefix +
"mat_product_algorithm",
"allatonce");
845 #elif !PETSC_VERSION_LESS_THAN(3, 13, 0) 846 po.
pairs.emplace_back(prefix +
"matproduct_ptap_via",
"allatonce");
848 po.
pairs.emplace_back(prefix +
"matptap_via",
"allatonce");
849 po.
pairs.emplace_back(prefix +
"matmaijptap_via",
"allatonce");
854 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 857 if (superlu_dist_found && !fact_pattern_found)
859 po.
pairs.emplace_back(prefix +
"mat_superlu_dist_fact",
860 #
if PETSC_VERSION_LESS_THAN(3, 7, 5)
861 "SamePattern_SameRowPerm");
862 pc_description +=
"mat_superlu_dist_fact: SamePattern_SameRowPerm ";
865 pc_description +=
"mat_superlu_dist_fact: SamePattern ";
870 if (superlu_dist_found && !tiny_pivot_found)
872 po.
pairs.emplace_back(prefix +
"mat_superlu_dist_replacetinypivot",
"1");
873 pc_description +=
" mat_superlu_dist_replacetinypivot: true ";
877 if (!pc_description.empty() && prefix.size() > 1)
878 po.
pc_description +=
"[" + prefix.substr(1, prefix.size() - 2) +
"]: ";
882 std::set<std::string>
885 return {
"default",
"shell",
"none",
"basic",
"l2",
"bt",
"cp"};
893 MooseEnum solve_type(
"PJFNK JFNK NEWTON FD LINEAR");
896 "PJFNK: Preconditioned Jacobian-Free Newton Krylov " 897 "JFNK: Jacobian-Free Newton Krylov " 898 "NEWTON: Full Newton Solve " 899 "FD: Use finite differences to compute Jacobian " 900 "LINEAR: Solving a linear problem");
905 "Specifies the finite differencing type for " 906 "Jacobian-free solve types. Note that the " 907 "default is wp (for Walker and Pernice).");
913 params.
addParam<std::vector<std::string>>(
914 "petsc_options_value",
915 "Values of PETSc name/value pairs (must correspond with \"petsc_options_iname\"");
927 "-ksp_monitor_snes_lg -snes_ksp_ew -ksp_snes_ew -snes_converged_reason " 928 "-snes_ksp -snes_linesearch_monitor -snes_mf -snes_mf_operator -snes_monitor " 929 "-snes_test_display -snes_view -snes_monitor_cancel",
938 "-ksp_converged_reason -ksp_gmres_modifiedgramschmidt -ksp_monitor",
"",
true);
944 auto options =
MultiMooseEnum(
"-dm_moose_print_embedding -dm_view",
"",
true);
953 return MultiMooseEnum(
"-snes_atol -snes_linesearch_type -snes_ls -snes_max_it -snes_rtol " 954 "-snes_divergence_tolerance -snes_type",
962 return MultiMooseEnum(
"-ksp_atol -ksp_gmres_restart -ksp_max_it -ksp_pc_side -ksp_rtol " 963 "-ksp_type -sub_ksp_type",
970 auto options =
MultiMooseEnum(
"-mat_fd_coloring_err -mat_fd_type -mat_mffd_type " 971 "-pc_asm_overlap -pc_factor_levels " 972 "-pc_factor_mat_ordering_type -pc_hypre_boomeramg_grid_sweeps_all " 973 "-pc_hypre_boomeramg_max_iter " 974 "-pc_hypre_boomeramg_strong_threshold -pc_hypre_type -pc_type " 990 LibmeshPetscCallA(fe_problem.
comm().
get(), PetscGetArgs(&argc, &args));
992 std::vector<std::string> cml_arg;
993 for (
int i = 0; i < argc; i++)
994 cml_arg.push_back(args[i]);
1000 std::find(cml_arg.begin(), cml_arg.end(),
"vinewtonssls") == cml_arg.end() &&
1001 std::find(cml_arg.begin(), cml_arg.end(),
"vinewtonrsls") == cml_arg.end())
1009 const std::string & value ,
1014 LibmeshPetscCallA(comm.
get(),
1015 PetscOptionsSetValue(LIBMESH_PETSC_NULLPTR,
1017 value ==
"" ? LIBMESH_PETSC_NULLPTR :
value.c_str()));
1019 auto check_problem = [problem, &lower_case_name]()
1023 "Setting the option '",
1025 "' requires passing a 'problem' parameter. Contact a developer of your application " 1026 "to have them update their code. If in doubt, reach out to the MOOSE team on Github " 1031 if (lower_case_name.find(
"-vec_type") != std::string::npos)
1036 auto & lm_sys = solver_system->system();
1037 for (
auto & [vec_name, vec] :
as_range(lm_sys.vectors_begin(), lm_sys.vectors_end()))
1040 auto *
const petsc_vec = cast_ptr<PetscVector<Number> *>(vec.get());
1041 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1044 auto * petsc_vec = cast_ptr<PetscVector<Number> *>(lm_sys.solution.get());
1045 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1046 petsc_vec = cast_ptr<PetscVector<Number> *>(lm_sys.current_local_solution.get());
1047 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1051 else if (lower_case_name.find(
"mat_type") != std::string::npos)
1055 bool found_matching_prefix =
false;
1065 "Setting option '", lower_case_name,
"' is incompatible with a JFNK 'solve_type'");
1068 for (
auto & [mat_name, mat] :
as_range(lm_sys.matrices_begin(), lm_sys.matrices_end()))
1074 const char * mat_prefix;
1075 LibmeshPetscCallA(comm.
get(), MatGetOptionsPrefix(petsc_mat->mat(), &mat_prefix));
1076 mooseAssert(strcmp(mat_prefix, (solver_sys_name +
"_").c_str()) == 0,
1077 "We should have prefixed these matrices previously");
1079 LibmeshPetscCallA(comm.
get(), MatSetFromOptions(petsc_mat->mat()));
1082 found_matching_prefix =
true;
1086 if (!found_matching_prefix)
1087 mooseError(
"We did not find a matching solver system name for the petsc option '",
1095 const std::string & name,
1096 const std::string & value ,
1106 unsigned int colors,
1107 std::vector<unsigned int> & vertex_colors,
1108 const char * coloring_algorithm)
1112 LibmeshPetscCallA(PETSC_COMM_SELF, MatCreate(PETSC_COMM_SELF, &A));
1113 LibmeshPetscCallA(PETSC_COMM_SELF, MatSetSizes(A, size, size, size, size));
1114 LibmeshPetscCallA(PETSC_COMM_SELF, MatSetType(A, MATSEQDENSE));
1116 LibmeshPetscCallA(PETSC_COMM_SELF, MatSeqDenseSetPreallocation(A, adjacency_matrix));
1117 LibmeshPetscCallA(PETSC_COMM_SELF, MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
1118 LibmeshPetscCallA(PETSC_COMM_SELF, MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
1121 #if PETSC_VERSION_LESS_THAN(3, 7, 0) 1122 LibmeshPetscCallA(PETSC_COMM_SELF, MatConvert(A, MATAIJ, MAT_REUSE_MATRIX, &A));
1124 LibmeshPetscCallA(PETSC_COMM_SELF, MatConvert(A, MATAIJ, MAT_INPLACE_MATRIX, &A));
1127 ISColoring iscoloring;
1129 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringCreate(A, &mc));
1130 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetType(mc, coloring_algorithm));
1131 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetMaxColors(mc, static_cast<PetscInt>(colors)));
1134 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetDistance(mc, 1));
1135 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetFromOptions(mc));
1136 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringApply(mc, &iscoloring));
1140 #if PETSC_RELEASE_LESS_THAN(3, 12, 0) 1141 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringGetIS(iscoloring, &nn, &
is));
1143 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringGetIS(iscoloring, PETSC_USE_POINTER, &nn, &
is));
1146 if (nn > static_cast<PetscInt>(colors))
1147 throw std::runtime_error(
"Not able to color with designated number of colors");
1149 for (
int i = 0; i < nn; i++)
1152 const PetscInt * indices;
1153 LibmeshPetscCallA(PETSC_COMM_SELF, ISGetLocalSize(
is[i], &isize));
1154 LibmeshPetscCallA(PETSC_COMM_SELF, ISGetIndices(
is[i], &indices));
1155 for (
int j = 0; j < isize; j++)
1157 mooseAssert(indices[j] < static_cast<PetscInt>(vertex_colors.size()),
"Index out of bounds");
1158 vertex_colors[indices[j]] = i;
1160 LibmeshPetscCallA(PETSC_COMM_SELF, ISRestoreIndices(
is[i], &indices));
1163 LibmeshPetscCallA(PETSC_COMM_SELF, MatDestroy(&A));
1164 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringDestroy(&mc));
1165 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringDestroy(&iscoloring));
1202 if (!petsc_options.dont_add_these_options.contains(flag))
1205 if (!petsc_options.dont_add_these_options.contains(key))
1206 petsc_options.dont_add_these_options.setAdditionalValue(key);
1209 std::unique_ptr<PetscMatrix<Number>>
1212 const std::string & binary_mat_file,
1213 const unsigned int mat_number_to_load)
1215 LibmeshPetscCallA(comm.
get(), MatCreate(comm.
get(), &mat));
1216 PetscViewer matviewer;
1219 PetscViewerBinaryOpen(comm.
get(), binary_mat_file.c_str(), FILE_MODE_READ, &matviewer));
1220 for (
unsigned int i = 0; i < mat_number_to_load; ++i)
1221 LibmeshPetscCallA(comm.
get(), MatLoad(mat, matviewer));
1222 LibmeshPetscCallA(comm.
get(), PetscViewerDestroy(&matviewer));
1224 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()
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
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
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.
std::string toLower(std::string name)
Convert supplied string to lower case.
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.