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
148 switch (solver_params.
_type)
152 solver_params.
_prefix +
"snes_mf_operator");
154 solver_params.
_prefix +
"mat_mffd_type",
161 solver_params.
_prefix +
"mat_mffd_type",
174 dont_add_these_options, solver_params.
_prefix +
"snes_type",
"ksponly");
176 solver_params.
_prefix +
"snes_monitor_cancel");
186 dont_add_these_options, solver_params.
_prefix +
"snes_linesearch_type",
stringify(ls_type));
193 DM
dm = LIBMESH_PETSC_NULLPTR;
201 const char * snes_prefix =
nullptr;
202 std::string snes_prefix_str;
206 snes_prefix = snes_prefix_str.c_str();
208 SNES snes = petsc_solver->
snes(snes_prefix);
210 LibmeshPetscCallA(nl.
comm().
get(), SNESGetDM(snes, &
dm));
213 LibmeshPetscCallA(nl.
comm().
get(), PetscObjectTypeCompare((PetscObject)
dm, DMMOOSE, &ismoose));
218 LibmeshPetscCallA(nl.
comm().
get(), DMSetFromOptions(
dm));
219 LibmeshPetscCallA(nl.
comm().
get(), DMSetUp(
dm));
220 LibmeshPetscCallA(nl.
comm().
get(), SNESSetDM(snes,
dm));
221 LibmeshPetscCallA(nl.
comm().
get(), DMDestroy(&
dm));
241 LibmeshPetscCallA(PETSC_COMM_WORLD, PetscGetArgs(&argc, &args));
242 #if PETSC_VERSION_LESS_THAN(3, 7, 0) 243 LibmeshPetscCallA(PETSC_COMM_WORLD, PetscOptionsInsert(&argc, &args, NULL));
245 LibmeshPetscCallA(PETSC_COMM_WORLD,
246 PetscOptionsInsert(LIBMESH_PETSC_NULLPTR, &argc, &args, NULL));
255 for (
const auto & flag : po.
flags)
263 for (
auto & option : po.
pairs)
276 PetscCallAbort(PETSC_COMM_WORLD, PetscOptionsClear(LIBMESH_PETSC_NULLPTR));
283 const std::vector<SolverParams> & solver_params_vec,
286 PetscCallAbort(PETSC_COMM_WORLD, PetscOptionsClear(LIBMESH_PETSC_NULLPTR));
287 for (
const auto & solver_params : solver_params_vec)
296 char code[10] = {45, 45, 109, 111, 111, 115, 101};
297 const std::vector<std::string> argv = cmd_line->
getArguments();
298 for (
const auto & arg : argv)
300 if (arg.compare(code) == 0)
315 SNESConvergedReason * reason,
342 *reason = SNES_CONVERGED_ITERATING;
346 *reason = SNES_CONVERGED_FNORM_ABS;
350 *reason = SNES_DIVERGED_DTOL;
359 KSP , PetscInt it, PetscReal , KSPConvergedReason * reason,
void *
ctx)
387 *reason = KSP_CONVERGED_ITERATING;
392 *reason = KSP_CONVERGED_RTOL_NORMAL;
396 *reason = KSP_DIVERGED_DTOL;
426 return KSP_NORM_NONE;
428 return KSP_NORM_PRECONDITIONED;
430 return KSP_NORM_UNPRECONDITIONED;
432 return KSP_NORM_NATURAL;
434 return KSP_NORM_DEFAULT;
436 mooseError(
"Unknown KSP norm type requested.");
447 LibmeshPetscCallA(problem.
comm().
get(),
468 auto & es = problem.
es();
471 PetscReal atol = es.parameters.get<
Real>(
"linear solver absolute tolerance");
477 PetscReal maxits = es.parameters.get<
unsigned int>(
"linear solver maximum iterations");
480 LibmeshPetscCallA(problem.
comm().
get(), KSPSetTolerances(ksp, rtol, atol, 1e100, maxits));
500 auto & lm_sys = nl.
system();
505 for (
auto & [mat_name, mat] :
as_range(lm_sys.matrices_begin(), lm_sys.matrices_end()))
510 LibmeshPetscCallA(nl.
comm().
get(),
511 MatSetOptionsPrefix(petsc_mat->mat(), (nl.
name() +
"_").c_str()));
514 LibmeshPetscCallA(nl.
comm().
get(), MatSetFromOptions(petsc_mat->mat()));
523 auto *
const petsc_solver = cast_ptr<PetscNonlinearSolver<Number> *>(nl.
nonlinearSolver());
524 const char * snes_prefix =
nullptr;
525 std::string snes_prefix_str;
529 snes_prefix = snes_prefix_str.c_str();
531 SNES snes = petsc_solver->snes(snes_prefix);
533 LibmeshPetscCallA(nl.
comm().
get(), SNESGetKSP(snes, &ksp));
535 LibmeshPetscCallA(nl.
comm().
get(), SNESSetMaxLinearSolveFailures(snes, 1000000));
537 LibmeshPetscCallA(nl.
comm().
get(), SNESSetCheckJacobianDomainError(snes, PETSC_TRUE));
559 KSP ksp = petsc_solver->
ksp();
579 #define checkPrefix(prefix) \ 580 mooseAssert(prefix[0] == '-', \ 581 "Leading prefix character must be a '-'. Current prefix is '" << prefix << "'"); \ 582 mooseAssert((prefix.size() == 1) || (prefix.back() == '_'), \ 583 "Terminating prefix character must be a '_'. Current prefix is '" << prefix << "'"); \ 584 mooseAssert(MooseUtils::isAllLowercase(prefix), \ 585 "PETSc prefixes should be all lower-case. What are you, a crazy person?") 589 const std::string & prefix,
592 const auto & params = param_object.
parameters();
596 const auto & petsc_options = params.get<
MultiMooseEnum>(
"petsc_options");
597 const auto & petsc_pair_options =
598 params.
get<
MooseEnumItem, std::string>(
"petsc_options_iname",
"petsc_options_value");
609 petsc_pair_options, fe_problem.
mesh().
dimension(), prefix, param_object, po);
619 const std::string & solve_type = params.
get<
MooseEnum>(
"solve_type");
621 fe_problem.
solverParams(i).
_type = Moose::stringToEnum<Moose::SolveType>(solve_type);
631 const auto & line_search = params.
get<
MooseEnum>(
"line_search");
636 Moose::stringToEnum<Moose::LineSearchType>(line_search);
643 mooseError(
"You've requested a line search but you must be solving an EigenProblem. " 644 "These two things are not consistent.");
647 if (!petsc_nonlinear_solver)
648 mooseError(
"Currently the MOOSE line searches all use Petsc, so you " 649 "must use Petsc as your non-linear solver.");
651 std::make_unique<ComputeLineSearchObjectWrapper>(fe_problem);
662 const auto & mffd_type = params.
get<
MooseEnum>(
"mffd_type");
668 template <
typename T>
672 const auto & string_option =
static_cast<const std::string &
>(option);
673 if (string_option[0] !=
'-')
674 param_object.
mooseError(
"PETSc option '", string_option,
"' does not begin with '-'");
679 const std::string & prefix,
686 for (
const auto & option : petsc_flags)
690 const std::string & string_option = option.name();
698 if (option ==
"-log_summary" || option ==
"-log_view")
699 mooseError(
"The PETSc option \"-log_summary\" or \"-log_view\" can only be used on the " 700 "command line. Please " 701 "remove it from the input file");
704 const std::string prefixed_option = prefix + string_option.substr(1);
719 #if !PETSC_VERSION_LESS_THAN(3, 14, 0) 722 std::array<std::string, 2> reason_flags = {{
"snes_converged_reason",
"ksp_converged_reason"}};
726 for (
const auto & reason_flag : reason_flags)
727 if (!po.flags.isValueSet(prefix + reason_flag) &&
728 (std::find_if(po.pairs.begin(),
730 [&reason_flag, &prefix](
auto & pair)
731 {
return pair.first == (prefix + reason_flag); }) == po.pairs.end()))
732 po.
pairs.emplace_back(prefix + reason_flag,
"::failed");
738 const std::vector<std::pair<MooseEnumItem, std::string>> & petsc_pair_options,
739 const unsigned int mesh_dimension,
740 const std::string & prefix,
747 bool boomeramg_found =
false;
748 bool strong_threshold_found =
false;
749 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 750 bool superlu_dist_found =
false;
751 bool fact_pattern_found =
false;
752 bool tiny_pivot_found =
false;
754 std::string pc_description =
"";
755 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 757 bool hmg_found =
false;
758 bool matptap_found =
false;
759 bool hmg_strong_threshold_found =
false;
761 std::vector<std::pair<std::string, std::string>> new_options;
763 for (
const auto & [option_name, option_value] : petsc_pair_options)
768 const std::string prefixed_option_name =
769 prefix +
static_cast<const std::string &
>(option_name).substr(1);
774 it == po.
pairs.end())
776 #if !PETSC_VERSION_LESS_THAN(3, 9, 0) 777 if (option_name ==
"-pc_factor_mat_solver_package")
778 new_options.emplace_back(prefix +
"pc_factor_mat_solver_type", option_value);
780 if (option_name ==
"-pc_factor_mat_solver_type")
781 new_options.push_back(prefix +
"pc_factor_mat_solver_package", option_value);
785 if (option_name ==
"-pc_type" || option_name ==
"-sub_pc_type" ||
786 option_name ==
"-pc_hypre_type")
787 pc_description += option_value +
' ';
789 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 790 if (option_name ==
"-pc_type" && option_value ==
"hmg")
799 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 800 if (hmg_found && (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via" ||
801 option_name ==
"-matproduct_ptap_via"))
802 new_options.emplace_back(prefix +
"mat_product_algorithm", option_value);
803 #elif !PETSC_VERSION_LESS_THAN(3, 13, 0) 804 if (hmg_found && (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via"))
805 new_options.emplace_back(prefix +
"matproduct_ptap_via", option_value);
807 if (hmg_found && (option_name ==
"-matproduct_ptap_via"))
809 new_options.emplace_back(prefix +
"matptap_via", option_value);
810 new_options.emplace_back(prefix +
"matmaijptap_via", option_value);
814 if (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via" ||
815 option_name ==
"-matproduct_ptap_via" || option_name ==
"-mat_product_algorithm")
816 matptap_found =
true;
819 if (option_name ==
"-hmg_inner_pc_hypre_boomeramg_strong_threshold")
820 hmg_strong_threshold_found =
true;
823 if (option_name ==
"-pc_hypre_type" && option_value ==
"boomeramg")
824 boomeramg_found =
true;
825 if (option_name ==
"-pc_hypre_boomeramg_strong_threshold")
826 strong_threshold_found =
true;
827 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 828 if ((option_name ==
"-pc_factor_mat_solver_package" ||
829 option_name ==
"-pc_factor_mat_solver_type") &&
830 option_value ==
"superlu_dist")
831 superlu_dist_found =
true;
832 if (option_name ==
"-mat_superlu_dist_fact")
833 fact_pattern_found =
true;
834 if (option_name ==
"-mat_superlu_dist_replacetinypivot")
835 tiny_pivot_found =
true;
838 if (!new_options.empty())
840 std::copy(new_options.begin(), new_options.end(), std::back_inserter(po.
pairs));
841 for (
const auto & option : new_options)
846 po.
pairs.push_back(std::make_pair(prefixed_option_name, option_value));
854 it->second = option_value;
856 }
while (it != po.
pairs.end());
862 if (boomeramg_found && !strong_threshold_found && mesh_dimension == 3)
864 po.
pairs.emplace_back(prefix +
"pc_hypre_boomeramg_strong_threshold",
"0.7");
865 pc_description +=
"strong_threshold: 0.7 (auto)";
868 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 869 if (hmg_found && !hmg_strong_threshold_found && mesh_dimension == 3)
871 po.
pairs.emplace_back(prefix +
"hmg_inner_pc_hypre_boomeramg_strong_threshold",
"0.7");
872 pc_description +=
"strong_threshold: 0.7 (auto)";
877 if (hmg_found && !matptap_found)
879 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 880 po.
pairs.emplace_back(prefix +
"mat_product_algorithm",
"allatonce");
881 #elif !PETSC_VERSION_LESS_THAN(3, 13, 0) 882 po.
pairs.emplace_back(prefix +
"matproduct_ptap_via",
"allatonce");
884 po.
pairs.emplace_back(prefix +
"matptap_via",
"allatonce");
885 po.
pairs.emplace_back(prefix +
"matmaijptap_via",
"allatonce");
890 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 893 if (superlu_dist_found && !fact_pattern_found)
895 po.
pairs.emplace_back(prefix +
"mat_superlu_dist_fact",
896 #
if PETSC_VERSION_LESS_THAN(3, 7, 5)
897 "SamePattern_SameRowPerm");
898 pc_description +=
"mat_superlu_dist_fact: SamePattern_SameRowPerm ";
901 pc_description +=
"mat_superlu_dist_fact: SamePattern ";
906 if (superlu_dist_found && !tiny_pivot_found)
908 po.
pairs.emplace_back(prefix +
"mat_superlu_dist_replacetinypivot",
"1");
909 pc_description +=
" mat_superlu_dist_replacetinypivot: true ";
913 if (!pc_description.empty() && prefix.size() > 1)
914 po.
pc_description +=
"[" + prefix.substr(1, prefix.size() - 2) +
"]: ";
918 std::set<std::string>
921 return {
"default",
"shell",
"none",
"basic",
"l2",
"bt",
"cp"};
929 MooseEnum solve_type(
"PJFNK JFNK NEWTON FD LINEAR");
932 "PJFNK: Preconditioned Jacobian-Free Newton Krylov " 933 "JFNK: Jacobian-Free Newton Krylov " 934 "NEWTON: Full Newton Solve " 935 "FD: Use finite differences to compute Jacobian " 936 "LINEAR: Solving a linear problem");
941 "Specifies the finite differencing type for " 942 "Jacobian-free solve types. Note that the " 943 "default is wp (for Walker and Pernice).");
949 params.
addParam<std::vector<std::string>>(
950 "petsc_options_value",
951 "Values of PETSc name/value pairs (must correspond with \"petsc_options_iname\"");
963 "-ksp_monitor_snes_lg -snes_ksp_ew -ksp_snes_ew -snes_converged_reason " 964 "-snes_ksp -snes_linesearch_monitor -snes_mf -snes_mf_operator -snes_monitor " 965 "-snes_test_display -snes_view -snes_monitor_cancel",
974 "-ksp_converged_reason -ksp_gmres_modifiedgramschmidt -ksp_monitor",
"",
true);
980 auto options =
MultiMooseEnum(
"-dm_moose_print_embedding -dm_view",
"",
true);
989 return MultiMooseEnum(
"-snes_atol -snes_linesearch_type -snes_ls -snes_max_it -snes_rtol " 990 "-snes_divergence_tolerance -snes_type",
998 return MultiMooseEnum(
"-ksp_atol -ksp_gmres_restart -ksp_max_it -ksp_pc_side -ksp_rtol " 999 "-ksp_type -sub_ksp_type",
1006 auto options =
MultiMooseEnum(
"-mat_fd_coloring_err -mat_fd_type -mat_mffd_type " 1007 "-pc_asm_overlap -pc_factor_levels " 1008 "-pc_factor_mat_ordering_type -pc_hypre_boomeramg_grid_sweeps_all " 1009 "-pc_hypre_boomeramg_max_iter " 1010 "-pc_hypre_boomeramg_strong_threshold -pc_hypre_type -pc_type " 1026 LibmeshPetscCallA(fe_problem.
comm().
get(), PetscGetArgs(&argc, &args));
1028 std::vector<std::string> cml_arg;
1029 for (
int i = 0; i < argc; i++)
1030 cml_arg.push_back(args[i]);
1033 petsc.
pairs.end() &&
1035 petsc.
pairs.end() &&
1036 std::find(cml_arg.begin(), cml_arg.end(),
"vinewtonssls") == cml_arg.end() &&
1037 std::find(cml_arg.begin(), cml_arg.end(),
"vinewtonrsls") == cml_arg.end())
1045 const std::string & value ,
1050 LibmeshPetscCallA(comm.
get(),
1051 PetscOptionsSetValue(LIBMESH_PETSC_NULLPTR,
1053 value ==
"" ? LIBMESH_PETSC_NULLPTR :
value.c_str()));
1055 auto check_problem = [problem, &lower_case_name]()
1059 "Setting the option '",
1061 "' requires passing a 'problem' parameter. Contact a developer of your application " 1062 "to have them update their code. If in doubt, reach out to the MOOSE team on Github " 1067 if (lower_case_name.find(
"-vec_type") != std::string::npos)
1072 auto & lm_sys = solver_system->system();
1073 for (
auto & [vec_name, vec] :
as_range(lm_sys.vectors_begin(), lm_sys.vectors_end()))
1076 auto *
const petsc_vec = cast_ptr<PetscVector<Number> *>(vec.get());
1077 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1080 auto * petsc_vec = cast_ptr<PetscVector<Number> *>(lm_sys.solution.get());
1081 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1082 petsc_vec = cast_ptr<PetscVector<Number> *>(lm_sys.current_local_solution.get());
1083 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1087 else if (lower_case_name.find(
"mat_type") != std::string::npos)
1091 bool found_matching_prefix =
false;
1101 "Setting option '", lower_case_name,
"' is incompatible with a JFNK 'solve_type'");
1104 for (
auto & [mat_name, mat] :
as_range(lm_sys.matrices_begin(), lm_sys.matrices_end()))
1110 const char * mat_prefix;
1111 LibmeshPetscCallA(comm.
get(), MatGetOptionsPrefix(petsc_mat->mat(), &mat_prefix));
1112 mooseAssert(strcmp(mat_prefix, (solver_sys_name +
"_").c_str()) == 0,
1113 "We should have prefixed these matrices previously");
1115 LibmeshPetscCallA(comm.
get(), MatSetFromOptions(petsc_mat->mat()));
1118 found_matching_prefix =
true;
1122 if (!found_matching_prefix)
1123 mooseError(
"We did not find a matching solver system name for the petsc option '",
1131 const std::string & name,
1132 const std::string & value ,
1142 unsigned int colors,
1143 std::vector<unsigned int> & vertex_colors,
1144 const char * coloring_algorithm)
1148 LibmeshPetscCallA(PETSC_COMM_SELF, MatCreate(PETSC_COMM_SELF, &A));
1149 LibmeshPetscCallA(PETSC_COMM_SELF, MatSetSizes(A, size, size, size, size));
1150 LibmeshPetscCallA(PETSC_COMM_SELF, MatSetType(A, MATSEQDENSE));
1152 LibmeshPetscCallA(PETSC_COMM_SELF, MatSeqDenseSetPreallocation(A, adjacency_matrix));
1153 LibmeshPetscCallA(PETSC_COMM_SELF, MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
1154 LibmeshPetscCallA(PETSC_COMM_SELF, MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
1157 #if PETSC_VERSION_LESS_THAN(3, 7, 0) 1158 LibmeshPetscCallA(PETSC_COMM_SELF, MatConvert(A, MATAIJ, MAT_REUSE_MATRIX, &A));
1160 LibmeshPetscCallA(PETSC_COMM_SELF, MatConvert(A, MATAIJ, MAT_INPLACE_MATRIX, &A));
1163 ISColoring iscoloring;
1165 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringCreate(A, &mc));
1166 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetType(mc, coloring_algorithm));
1167 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetMaxColors(mc, static_cast<PetscInt>(colors)));
1170 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetDistance(mc, 1));
1171 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetFromOptions(mc));
1172 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringApply(mc, &iscoloring));
1176 #if PETSC_RELEASE_LESS_THAN(3, 12, 0) 1177 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringGetIS(iscoloring, &nn, &
is));
1179 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringGetIS(iscoloring, PETSC_USE_POINTER, &nn, &
is));
1182 if (nn > static_cast<PetscInt>(colors))
1183 throw std::runtime_error(
"Not able to color with designated number of colors");
1185 for (
int i = 0; i < nn; i++)
1188 const PetscInt * indices;
1189 LibmeshPetscCallA(PETSC_COMM_SELF, ISGetLocalSize(
is[i], &isize));
1190 LibmeshPetscCallA(PETSC_COMM_SELF, ISGetIndices(
is[i], &indices));
1191 for (
int j = 0; j < isize; j++)
1193 mooseAssert(indices[j] < static_cast<PetscInt>(vertex_colors.size()),
"Index out of bounds");
1194 vertex_colors[indices[j]] = i;
1196 LibmeshPetscCallA(PETSC_COMM_SELF, ISRestoreIndices(
is[i], &indices));
1199 LibmeshPetscCallA(PETSC_COMM_SELF, MatDestroy(&A));
1200 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringDestroy(&mc));
1201 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringDestroy(&iscoloring));
1238 if (!petsc_options.dont_add_these_options.contains(flag))
1241 if (!petsc_options.dont_add_these_options.contains(key))
1242 petsc_options.dont_add_these_options.setAdditionalValue(key);
1245 std::unique_ptr<PetscMatrix<Number>>
1248 const std::string & binary_mat_file,
1249 const unsigned int mat_number_to_load)
1251 LibmeshPetscCallA(comm.
get(), MatCreate(comm.
get(), &mat));
1252 PetscViewer matviewer;
1255 PetscViewerBinaryOpen(comm.
get(), binary_mat_file.c_str(), FILE_MODE_READ, &matviewer));
1256 for (
unsigned int i = 0; i < mat_number_to_load; ++i)
1257 LibmeshPetscCallA(comm.
get(), MatLoad(mat, matviewer));
1258 LibmeshPetscCallA(comm.
get(), PetscViewerDestroy(&matviewer));
1260 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
SNES snes(const char *name=nullptr)
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)
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.
void petscSetupDM(NonlinearSystemBase &nl, const std::string &dm_name)
Setup the PETSc DM object.
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 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) ...
A struct for storing the various types of petsc options and values.
MultiMooseEnum flags
Single value PETSc options (flags)
PetscErrorCode PetscOptionItems *PetscErrorCode DM dm
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)
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)
PetscErrorCode DMCreateMoose(MPI_Comm comm, NonlinearSystemBase &nl, const std::string &dm_name, DM *dm)
Create a MOOSE DM.
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 setConvergedReasonFlags(FEProblemBase &fe_problem, const std::string &prefix)
Set flags that will instruct the user on the reason their simulation diverged from PETSc's perspectiv...
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 addPetscPairsToPetscOptions(const std::vector< std::pair< MooseEnumItem, std::string >> &petsc_pair_options, const unsigned int mesh_dimension, const 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 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
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.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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) ...
const InputParameters & parameters() const
Get the parameters of the object.
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 addPetscFlagsToPetscOptions(const MultiMooseEnum &petsc_flags, const std::string &prefix, const ParallelParamObject ¶m_object, PetscOptions &petsc_options)
Populate flags in a given PetscOptions object using a vector of input arguments.
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)
PetscErrorCode DMMooseRegisterAll()
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.