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), "PETSc prefixes should be all lower-case") 588 const std::string & prefix,
591 const auto & params = param_object.
parameters();
595 const auto & petsc_options = params.get<
MultiMooseEnum>(
"petsc_options");
596 const auto & petsc_pair_options =
597 params.
get<
MooseEnumItem, std::string>(
"petsc_options_iname",
"petsc_options_value");
608 petsc_pair_options, fe_problem.
mesh().
dimension(), prefix, param_object, po);
618 const std::string & solve_type = params.
get<
MooseEnum>(
"solve_type");
620 fe_problem.
solverParams(i).
_type = Moose::stringToEnum<Moose::SolveType>(solve_type);
630 const auto & line_search = params.
get<
MooseEnum>(
"line_search");
635 Moose::stringToEnum<Moose::LineSearchType>(line_search);
642 mooseError(
"You've requested a line search but you must be solving an EigenProblem. " 643 "These two things are not consistent.");
646 if (!petsc_nonlinear_solver)
647 mooseError(
"Currently the MOOSE line searches all use Petsc, so you " 648 "must use Petsc as your non-linear solver.");
650 std::make_unique<ComputeLineSearchObjectWrapper>(fe_problem);
661 const auto & mffd_type = params.
get<
MooseEnum>(
"mffd_type");
667 template <
typename T>
671 const auto & string_option =
static_cast<const std::string &
>(option);
672 if (string_option[0] !=
'-')
673 param_object.
mooseError(
"PETSc option '", string_option,
"' does not begin with '-'");
678 const std::string & prefix,
685 for (
const auto & option : petsc_flags)
689 const std::string & string_option = option.name();
697 if (option ==
"-log_summary" || option ==
"-log_view")
698 mooseError(
"The PETSc option \"-log_summary\" or \"-log_view\" can only be used on the " 699 "command line. Please " 700 "remove it from the input file");
703 const std::string prefixed_option = prefix + string_option.substr(1);
718 #if !PETSC_VERSION_LESS_THAN(3, 14, 0) 721 std::array<std::string, 2> reason_flags = {{
"snes_converged_reason",
"ksp_converged_reason"}};
725 for (
const auto & reason_flag : reason_flags)
726 if (!po.flags.isValueSet(prefix + reason_flag) &&
727 (std::find_if(po.pairs.begin(),
729 [&reason_flag, &prefix](
auto & pair)
730 {
return pair.first == (prefix + reason_flag); }) == po.pairs.end()))
731 po.
pairs.emplace_back(prefix + reason_flag,
"::failed");
737 const std::vector<std::pair<MooseEnumItem, std::string>> & petsc_pair_options,
738 const unsigned int mesh_dimension,
739 const std::string & prefix,
746 bool boomeramg_found =
false;
747 bool strong_threshold_found =
false;
748 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 749 bool superlu_dist_found =
false;
750 bool fact_pattern_found =
false;
751 bool tiny_pivot_found =
false;
753 std::string pc_description =
"";
754 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 756 bool hmg_found =
false;
757 bool matptap_found =
false;
758 bool hmg_strong_threshold_found =
false;
760 std::vector<std::pair<std::string, std::string>> new_options;
762 for (
const auto & [option_name, option_value] : petsc_pair_options)
767 const std::string prefixed_option_name =
768 prefix +
static_cast<const std::string &
>(option_name).substr(1);
773 it == po.
pairs.end())
775 #if !PETSC_VERSION_LESS_THAN(3, 9, 0) 776 if (option_name ==
"-pc_factor_mat_solver_package")
777 new_options.emplace_back(prefix +
"pc_factor_mat_solver_type", option_value);
779 if (option_name ==
"-pc_factor_mat_solver_type")
780 new_options.push_back(prefix +
"pc_factor_mat_solver_package", option_value);
784 if (option_name ==
"-pc_type" || option_name ==
"-sub_pc_type" ||
785 option_name ==
"-pc_hypre_type")
786 pc_description += option_value +
' ';
788 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 789 if (option_name ==
"-pc_type" && option_value ==
"hmg")
798 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 799 if (hmg_found && (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via" ||
800 option_name ==
"-matproduct_ptap_via"))
801 new_options.emplace_back(prefix +
"mat_product_algorithm", option_value);
802 #elif !PETSC_VERSION_LESS_THAN(3, 13, 0) 803 if (hmg_found && (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via"))
804 new_options.emplace_back(prefix +
"matproduct_ptap_via", option_value);
806 if (hmg_found && (option_name ==
"-matproduct_ptap_via"))
808 new_options.emplace_back(prefix +
"matptap_via", option_value);
809 new_options.emplace_back(prefix +
"matmaijptap_via", option_value);
813 if (option_name ==
"-matptap_via" || option_name ==
"-matmaijptap_via" ||
814 option_name ==
"-matproduct_ptap_via" || option_name ==
"-mat_product_algorithm")
815 matptap_found =
true;
818 if (option_name ==
"-hmg_inner_pc_hypre_boomeramg_strong_threshold")
819 hmg_strong_threshold_found =
true;
822 if (option_name ==
"-pc_hypre_type" && option_value ==
"boomeramg")
823 boomeramg_found =
true;
824 if (option_name ==
"-pc_hypre_boomeramg_strong_threshold")
825 strong_threshold_found =
true;
826 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 827 if ((option_name ==
"-pc_factor_mat_solver_package" ||
828 option_name ==
"-pc_factor_mat_solver_type") &&
829 option_value ==
"superlu_dist")
830 superlu_dist_found =
true;
831 if (option_name ==
"-mat_superlu_dist_fact")
832 fact_pattern_found =
true;
833 if (option_name ==
"-mat_superlu_dist_replacetinypivot")
834 tiny_pivot_found =
true;
837 if (!new_options.empty())
839 std::copy(new_options.begin(), new_options.end(), std::back_inserter(po.
pairs));
840 for (
const auto & option : new_options)
845 po.
pairs.push_back(std::make_pair(prefixed_option_name, option_value));
853 it->second = option_value;
855 }
while (it != po.
pairs.end());
861 if (boomeramg_found && !strong_threshold_found && mesh_dimension == 3)
863 po.
pairs.emplace_back(prefix +
"pc_hypre_boomeramg_strong_threshold",
"0.7");
864 pc_description +=
"strong_threshold: 0.7 (auto)";
867 #if !PETSC_VERSION_LESS_THAN(3, 12, 0) 868 if (hmg_found && !hmg_strong_threshold_found && mesh_dimension == 3)
870 po.
pairs.emplace_back(prefix +
"hmg_inner_pc_hypre_boomeramg_strong_threshold",
"0.7");
871 pc_description +=
"strong_threshold: 0.7 (auto)";
876 if (hmg_found && !matptap_found)
878 #if !PETSC_VERSION_LESS_THAN(3, 17, 0) 879 po.
pairs.emplace_back(prefix +
"mat_product_algorithm",
"allatonce");
880 #elif !PETSC_VERSION_LESS_THAN(3, 13, 0) 881 po.
pairs.emplace_back(prefix +
"matproduct_ptap_via",
"allatonce");
883 po.
pairs.emplace_back(prefix +
"matptap_via",
"allatonce");
884 po.
pairs.emplace_back(prefix +
"matmaijptap_via",
"allatonce");
889 #if !PETSC_VERSION_LESS_THAN(3, 7, 0) 892 if (superlu_dist_found && !fact_pattern_found)
894 po.
pairs.emplace_back(prefix +
"mat_superlu_dist_fact",
895 #
if PETSC_VERSION_LESS_THAN(3, 7, 5)
896 "SamePattern_SameRowPerm");
897 pc_description +=
"mat_superlu_dist_fact: SamePattern_SameRowPerm ";
900 pc_description +=
"mat_superlu_dist_fact: SamePattern ";
905 if (superlu_dist_found && !tiny_pivot_found)
907 po.
pairs.emplace_back(prefix +
"mat_superlu_dist_replacetinypivot",
"1");
908 pc_description +=
" mat_superlu_dist_replacetinypivot: true ";
912 if (!pc_description.empty() && prefix.size() > 1)
913 po.
pc_description +=
"[" + prefix.substr(1, prefix.size() - 2) +
"]: ";
917 std::set<std::string>
920 return {
"default",
"shell",
"none",
"basic",
"l2",
"bt",
"cp"};
928 MooseEnum solve_type(
"PJFNK JFNK NEWTON FD LINEAR");
931 "PJFNK: Preconditioned Jacobian-Free Newton Krylov " 932 "JFNK: Jacobian-Free Newton Krylov " 933 "NEWTON: Full Newton Solve " 934 "FD: Use finite differences to compute Jacobian " 935 "LINEAR: Solving a linear problem");
940 "Specifies the finite differencing type for " 941 "Jacobian-free solve types. Note that the " 942 "default is wp (for Walker and Pernice).");
948 params.
addParam<std::vector<std::string>>(
949 "petsc_options_value",
950 "Values of PETSc name/value pairs (must correspond with \"petsc_options_iname\"");
962 "-ksp_monitor_snes_lg -snes_ksp_ew -ksp_snes_ew -snes_converged_reason " 963 "-snes_ksp -snes_linesearch_monitor -snes_mf -snes_mf_operator -snes_monitor " 964 "-snes_test_display -snes_view -snes_monitor_cancel",
973 "-ksp_converged_reason -ksp_gmres_modifiedgramschmidt -ksp_monitor",
"",
true);
979 auto options =
MultiMooseEnum(
"-dm_moose_print_embedding -dm_view",
"",
true);
988 return MultiMooseEnum(
"-snes_atol -snes_linesearch_type -snes_ls -snes_max_it -snes_rtol " 989 "-snes_divergence_tolerance -snes_type",
997 return MultiMooseEnum(
"-ksp_atol -ksp_gmres_restart -ksp_max_it -ksp_pc_side -ksp_rtol " 998 "-ksp_type -sub_ksp_type",
1005 auto options =
MultiMooseEnum(
"-mat_fd_coloring_err -mat_fd_type -mat_mffd_type " 1006 "-pc_asm_overlap -pc_factor_levels " 1007 "-pc_factor_mat_ordering_type -pc_hypre_boomeramg_grid_sweeps_all " 1008 "-pc_hypre_boomeramg_max_iter " 1009 "-pc_hypre_boomeramg_strong_threshold -pc_hypre_type -pc_type " 1025 LibmeshPetscCallA(fe_problem.
comm().
get(), PetscGetArgs(&argc, &args));
1027 std::vector<std::string> cml_arg;
1028 for (
int i = 0; i < argc; i++)
1029 cml_arg.push_back(args[i]);
1032 petsc.
pairs.end() &&
1034 petsc.
pairs.end() &&
1035 std::find(cml_arg.begin(), cml_arg.end(),
"vinewtonssls") == cml_arg.end() &&
1036 std::find(cml_arg.begin(), cml_arg.end(),
"vinewtonrsls") == cml_arg.end())
1044 const std::string & value ,
1049 LibmeshPetscCallA(comm.
get(),
1050 PetscOptionsSetValue(LIBMESH_PETSC_NULLPTR,
1052 value ==
"" ? LIBMESH_PETSC_NULLPTR :
value.c_str()));
1054 auto check_problem = [problem, &lower_case_name]()
1058 "Setting the option '",
1060 "' requires passing a 'problem' parameter. Contact a developer of your application " 1061 "to have them update their code. If in doubt, reach out to the MOOSE team on Github " 1066 if (lower_case_name.find(
"-vec_type") != std::string::npos)
1071 auto & lm_sys = solver_system->system();
1072 for (
auto & [vec_name, vec] :
as_range(lm_sys.vectors_begin(), lm_sys.vectors_end()))
1075 auto *
const petsc_vec = cast_ptr<PetscVector<Number> *>(vec.get());
1076 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1079 auto * petsc_vec = cast_ptr<PetscVector<Number> *>(lm_sys.solution.get());
1080 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1081 petsc_vec = cast_ptr<PetscVector<Number> *>(lm_sys.current_local_solution.get());
1082 LibmeshPetscCallA(comm.
get(), VecSetFromOptions(petsc_vec->vec()));
1086 else if (lower_case_name.find(
"mat_type") != std::string::npos)
1090 bool found_matching_prefix =
false;
1100 "Setting option '", lower_case_name,
"' is incompatible with a JFNK 'solve_type'");
1103 for (
auto & [mat_name, mat] :
as_range(lm_sys.matrices_begin(), lm_sys.matrices_end()))
1109 const char * mat_prefix;
1110 LibmeshPetscCallA(comm.
get(), MatGetOptionsPrefix(petsc_mat->mat(), &mat_prefix));
1111 mooseAssert(strcmp(mat_prefix, (solver_sys_name +
"_").c_str()) == 0,
1112 "We should have prefixed these matrices previously");
1114 LibmeshPetscCallA(comm.
get(), MatSetFromOptions(petsc_mat->mat()));
1117 found_matching_prefix =
true;
1121 if (!found_matching_prefix)
1122 mooseError(
"We did not find a matching solver system name for the petsc option '",
1130 const std::string & name,
1131 const std::string & value ,
1141 unsigned int colors,
1142 std::vector<unsigned int> & vertex_colors,
1143 const char * coloring_algorithm)
1147 LibmeshPetscCallA(PETSC_COMM_SELF, MatCreate(PETSC_COMM_SELF, &A));
1148 LibmeshPetscCallA(PETSC_COMM_SELF, MatSetSizes(A, size, size, size, size));
1149 LibmeshPetscCallA(PETSC_COMM_SELF, MatSetType(A, MATSEQDENSE));
1151 LibmeshPetscCallA(PETSC_COMM_SELF, MatSeqDenseSetPreallocation(A, adjacency_matrix));
1152 LibmeshPetscCallA(PETSC_COMM_SELF, MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
1153 LibmeshPetscCallA(PETSC_COMM_SELF, MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
1156 #if PETSC_VERSION_LESS_THAN(3, 7, 0) 1157 LibmeshPetscCallA(PETSC_COMM_SELF, MatConvert(A, MATAIJ, MAT_REUSE_MATRIX, &A));
1159 LibmeshPetscCallA(PETSC_COMM_SELF, MatConvert(A, MATAIJ, MAT_INPLACE_MATRIX, &A));
1162 ISColoring iscoloring;
1164 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringCreate(A, &mc));
1165 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetType(mc, coloring_algorithm));
1166 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetMaxColors(mc, static_cast<PetscInt>(colors)));
1169 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetDistance(mc, 1));
1170 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetFromOptions(mc));
1171 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringApply(mc, &iscoloring));
1175 #if PETSC_RELEASE_LESS_THAN(3, 12, 0) 1176 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringGetIS(iscoloring, &nn, &
is));
1178 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringGetIS(iscoloring, PETSC_USE_POINTER, &nn, &
is));
1181 if (nn > static_cast<PetscInt>(colors))
1182 throw std::runtime_error(
"Not able to color with designated number of colors");
1184 for (
int i = 0; i < nn; i++)
1187 const PetscInt * indices;
1188 LibmeshPetscCallA(PETSC_COMM_SELF, ISGetLocalSize(
is[i], &isize));
1189 LibmeshPetscCallA(PETSC_COMM_SELF, ISGetIndices(
is[i], &indices));
1190 for (
int j = 0; j < isize; j++)
1192 mooseAssert(indices[j] < static_cast<PetscInt>(vertex_colors.size()),
"Index out of bounds");
1193 vertex_colors[indices[j]] = i;
1195 LibmeshPetscCallA(PETSC_COMM_SELF, ISRestoreIndices(
is[i], &indices));
1198 LibmeshPetscCallA(PETSC_COMM_SELF, MatDestroy(&A));
1199 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringDestroy(&mc));
1200 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringDestroy(&iscoloring));
1237 if (!petsc_options.dont_add_these_options.contains(flag))
1240 if (!petsc_options.dont_add_these_options.contains(key))
1241 petsc_options.dont_add_these_options.setAdditionalValue(key);
1244 std::unique_ptr<PetscMatrix<Number>>
1247 const std::string & binary_mat_file,
1248 const unsigned int mat_number_to_load)
1250 LibmeshPetscCallA(comm.
get(), MatCreate(comm.
get(), &mat));
1251 PetscViewer matviewer;
1254 PetscViewerBinaryOpen(comm.
get(), binary_mat_file.c_str(), FILE_MODE_READ, &matviewer));
1255 for (
unsigned int i = 0; i < mat_number_to_load; ++i)
1256 LibmeshPetscCallA(comm.
get(), MatLoad(mat, matviewer));
1257 LibmeshPetscCallA(comm.
get(), PetscViewerDestroy(&matviewer));
1259 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.