https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Functions
Moose::PetscSupport Namespace Reference

Classes

class  PetscOptions
 A struct for storing the various types of petsc options and values. More...
 
class  PetscOptionsScope
 Activates a problem's PETSc options database for the lifetime of this scope. More...
 

Functions

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.
 
void petscSetOptions (const PetscOptions &po, const std::vector< SolverParams > &solver_params, FEProblemBase *problem)
 A function for setting the PETSc options in PETSc from the options supplied to MOOSE.
 
void petscSetKSPDefaults (FEProblemBase &problem, KSP ksp)
 Set the default options for a KSP.
 
template<typename T >
void setLinearSolverDefaults (FEProblemBase &problem, libMesh::LinearSolver< T > &linear_solver)
 Set the defaults for a libMesh LinearSolver.
 
void petscSetDefaults (FEProblemBase &problem)
 Sets the default options for PETSc.
 
PetscErrorCode petscSetupOutput (CommandLine *cmd_line)
 
void outputNorm (libMesh::Real old_norm, libMesh::Real norm, bool use_color=false)
 Helper function for outputting the norm values with/without color.
 
PetscErrorCode petscLinearMonitor (KSP, PetscInt its, PetscReal rnorm, void *void_ptr)
 Helper function for displaying the linear residual during PETSC solve.
 
void processSingletonMooseWrappedOptions (FEProblemBase &fe_problem, const InputParameters &params)
 Process some MOOSE-wrapped PETSc options.
 
void storePetscOptions (FEProblemBase &fe_problem, const std::string &prefix, const ParallelParamObject &param_object)
 Stores the PETSc options supplied from the parameter object on the problem.
 
void setConvergedReasonFlags (FEProblemBase &fe_problem, std::string prefix)
 Set flags that will instruct the user on the reason their simulation diverged from PETSc's perspective.
 
void setSolveTypeFromParams (FEProblemBase &fe_problem, const InputParameters &params)
 Sets the FE problem's solve type from the input params.
 
void setLineSearchFromParams (FEProblemBase &fe_problem, const InputParameters &params)
 Sets the FE problem's line search from the input params.
 
void setMFFDTypeFromParams (FEProblemBase &fe_problem, const InputParameters &params)
 Sets the FE problem's matrix-free finite difference type from the input params.
 
void storePetscOptionsFromParams (FEProblemBase &fe_problem, const InputParameters &params)
 Stores the Petsc flags and pair options fron the input params in the given PetscOptions object.
 
void addPetscFlagsToPetscOptions (const MultiMooseEnum &petsc_flags, std::string prefix, const ParallelParamObject &param_object, PetscOptions &petsc_options)
 Populate flags in a given PetscOptions object using a vector of input arguments.
 
void addPetscPairsToPetscOptions (const std::vector< std::pair< MooseEnumItem, std::string > > &petsc_pair_options, const unsigned int mesh_dimension, std::string prefix, const ParallelParamObject &param_object, PetscOptions &petsc_options)
 Populate name and value pairs in a given PetscOptions object using vectors of input arguments.
 
std::set< std::string > getPetscValidLineSearches ()
 Returns the valid petsc line search options as a set of strings.
 
InputParameters getPetscValidParams ()
 Returns the PETSc options that are common between Executioners and Preconditioners.
 
MultiMooseEnum getCommonPetscFlags ()
 A helper function to produce a MultiMooseEnum with commonly used PETSc single options (flags)
 
MultiMooseEnum getCommonSNESFlags ()
 A helper function to produce a MultiMooseEnum with commonly used PETSc snes single options (flags)
 
MultiMooseEnum getCommonKSPFlags ()
 A helper function to produce a MultiMooseEnum with commonly used PETSc ksp single options (flags)
 
MultiMooseEnum getCommonPetscKeys ()
 A helper function to produce a MultiMooseEnum with commonly used PETSc iname options (keys in key-value pairs)
 
MultiMooseEnum getCommonSNESKeys ()
 A helper function to produce a MultiMooseEnum with commonly used PETSc snes option names (keys)
 
MultiMooseEnum getCommonKSPKeys ()
 A helper function to produce a MultiMooseEnum with commonly used PETSc ksp option names (keys)
 
bool isSNESVI (FEProblemBase &fe_problem)
 check if SNES type is variational inequalities (VI) solver
 
void setSinglePetscOption (const std::string &name, const std::string &value="", FEProblemBase *const problem=nullptr)
 A wrapper function for dealing with different versions of PetscOptionsSetValue.
 
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 simulation type, e.g.
 
void registerPetscCitation (const std::string &bibtex)
 Register a BibTeX entry with PETSc's citation list so that it is printed (alongside the run-specific citations from any PETSc solvers/preconditioners used) when the PETSc -citations option is enabled.
 
void addPetscOptionsFromCommandline (FEProblemBase *const problem=nullptr)
 Insert command-line PETSc options into the active PETSc options database.
 
void petscSetDefaultPCSide (FEProblemBase &problem, KSP ksp)
 Setup which side we want to apply preconditioner.
 
void petscSetDefaultKSPNormType (FEProblemBase &problem, KSP ksp)
 Set norm type.
 
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 algorithm to produce a coloring.
 
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 be later set unless explicitly specified in input or on the command line.
 
void dontAddNonlinearConvergedReason (FEProblemBase &fe_problem)
 Function to ensure that -snes_converged_reason is not added to the PetscOptions storage object to be later set unless explicitly specified in input or on the command line.
 
void dontAddLinearConvergedReason (FEProblemBase &fe_problem)
 Function to ensure that -ksp_converged_reason is not added to the PetscOptions storage object to be later set unless explicitly specified in input or on the command line.
 
void dontAddCommonKSPOptions (FEProblemBase &fe_problem)
 Function to ensure that common KSP options are not added to the PetscOptions storage object to be later set unless explicitly specified in input or on the command line.
 
void dontAddCommonSNESOptions (FEProblemBase &fe_problem)
 Function to ensure that common SNES options are not added to the PetscOptions storage object to be later set unless explicitly specified in input or on the command line.
 
void dontAddCommonSNESOptions (FEProblemBase &fe_problem, const std::string &prefix)
 Prefixed variant: suppress common SNES options for the system identified by prefix (e.g.
 
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.
 
std::string stringify (const LineSearchType &t)
 
std::string stringify (const MffdType &t)
 
void setSolverOptions (const SolverParams &solver_params, const MultiMooseEnum &dont_add_these_options)
 
void petscSetOptionsHelper (const PetscOptions &po, FEProblemBase *const problem)
 
PetscErrorCode petscNonlinearConverged (SNES, PetscInt it, PetscReal, PetscReal, PetscReal, SNESConvergedReason *reason, void *ctx)
 
PetscErrorCode petscLinearConverged (KSP, PetscInt it, PetscReal, KSPConvergedReason *reason, void *ctx)
 
PCSide getPetscPCSide (Moose::PCSideType pcs)
 
KSPNormType getPetscKSPNormType (Moose::MooseKSPNormType kspnorm)
 
template<typename T >
void checkUserProvidedPetscOption (const T &option, const ParallelParamObject &param_object)
 

Function Documentation

◆ addPetscFlagsToPetscOptions()

void Moose::PetscSupport::addPetscFlagsToPetscOptions ( const MultiMooseEnum petsc_flags,
std::string  prefix,
const ParallelParamObject param_object,
PetscOptions petsc_options 
)

Populate flags in a given PetscOptions object using a vector of input arguments.

Parameters
petsc_flagsContainer holding the flags of the petsc options
prefixThe prefix to add to the user provided petsc_flags. This should not contain a leading dash per PETSc prefix convention. Note that this function will immediately \emph add said dash at the start of prefix so that later calls to PetscOptionsSetValue work. This is the reason we pass prefix by value
param_objectThe ParallelParamObject adding the PETSc options
petsc_optionsData structure which handles petsc options within moose

"-log_summary" cannot be used in the input file. This option needs to be set when PETSc is initialized which happens before the parser is even created. We'll throw an error if somebody attempts to add this option later.

"-log_summary" cannot be used in the input file. This option needs to be set when PETSc is initialized which happens before the parser is even created. We'll throw an error if somebody attempts to add this option later.

Definition at line 786 of file PetscSupport.C.

790{
791 prefix.insert(prefix.begin(), '-');
792 checkPrefix(prefix);
793
794 // Update the PETSc single flags
795 for (const auto & option : petsc_flags)
796 {
797 checkUserProvidedPetscOption(option, param_object);
798
799 const std::string & string_option = option.name();
800
807 if (option == "-log_summary" || option == "-log_view")
808 mooseError("The PETSc option \"-log_summary\" or \"-log_view\" can only be used on the "
809 "command line. Please "
810 "remove it from the input file");
811
812 // Update the stored items, but do not create duplicates
813 const std::string prefixed_option = prefix + string_option.substr(1);
814 if (!po.flags.isValueSet(prefixed_option))
815 {
816 po.flags.setAdditionalValue(prefixed_option);
817 po.user_set_options.setAdditionalValue(prefixed_option);
818 }
819 }
820}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
void checkUserProvidedPetscOption(const T &option, const ParallelParamObject &param_object)

Referenced by MFEMPetscNonlinearSolver::ConstructSolver(), and storePetscOptions().

◆ addPetscOptionsFromCommandline()

void Moose::PetscSupport::addPetscOptionsFromCommandline ( FEProblemBase *const  problem = nullptr)

Insert command-line PETSc options into the active PETSc options database.

When problem is provided, this also reapplies vector and matrix type options that may have been consumed before the options database was rebuilt, which preserves PETSc's used-option bookkeeping for command-line '-vec_type' and '*mat_type' options.

Definition at line 328 of file PetscSupport.C.

329{
330 // commandline options always win
331 // the options from a user commandline will overwrite the existing ones if any conflicts
332 int argc;
333 char ** args;
334
335 LibmeshPetscCallA(PETSC_COMM_WORLD, PetscGetArgs(&argc, &args));
336 std::vector<const char *> cl_args(args + 1, args + argc);
337 const auto cl_argc = libMesh::cast_int<int>(cl_args.size());
338
339 ::PetscOptions command_line_options;
340 LibmeshPetscCallA(PETSC_COMM_WORLD, PetscOptionsCreate(&command_line_options));
341 LibmeshPetscCallA(PETSC_COMM_WORLD,
342 PetscOptionsInsertArgs(command_line_options, cl_argc, cl_args.data()));
343 LibmeshPetscCallA(PETSC_COMM_WORLD,
344 PetscOptionsInsertArgs(LIBMESH_PETSC_NULLPTR, cl_argc, cl_args.data()));
345
346 if (!problem)
347 {
348 LibmeshPetscCallA(PETSC_COMM_WORLD, PetscOptionsDestroy(&command_line_options));
349 return;
350 }
351
352 errorOnUnprefixedMatTypeOption(command_line_options, *problem);
353
354 // Some vector/matrix-type options may have been consumed before the PETSc database rebuild.
355 // Replay only the command-line-controlled applications so input-file options handled through
356 // setSinglePetscOption() do not pay the cost twice.
357 const bool have_vec_type = petscOptionsHasName(command_line_options, "-vec_type");
358 bool have_mat_type = false;
359
360 for (const auto sys_index : make_range(problem->numSolverSystems()))
361 {
362 have_mat_type = petscOptionsHasName(
363 command_line_options, "-mat_type", problem->getSolverSystem(sys_index).name() + "_");
364 if (have_mat_type)
365 break;
366 }
367
368 if (have_vec_type)
369 applyVectorTypeOptions(*problem);
370 if (have_mat_type)
371 applyMatrixTypeOptions(*problem);
372
373 LibmeshPetscCallA(PETSC_COMM_WORLD, PetscOptionsDestroy(&command_line_options));
374}
SolverSystem & getSolverSystem(unsigned int sys_num)
Get non-constant reference to a solver system.
virtual const std::string & name() const
IntRange< T > make_range(T beg, T end)

Referenced by petscSetOptionsHelper(), and Moose::SlepcSupport::slepcSetOptions().

◆ addPetscPairsToPetscOptions()

void Moose::PetscSupport::addPetscPairsToPetscOptions ( const std::vector< std::pair< MooseEnumItem, std::string > > &  petsc_pair_options,
const unsigned int  mesh_dimension,
std::string  prefix,
const ParallelParamObject param_object,
PetscOptions petsc_options 
)

Populate name and value pairs in a given PetscOptions object using vectors of input arguments.

Parameters
petsc_pair_optionsOption-value pairs of petsc settings
mesh_dimensionThe mesh dimension, needed for multigrid settings
prefixThe prefix to add to the user provided petsc_pair_options. This should not contain a leading dash per PETSc prefix convention. Note that this function will immediately \emph add said dash at the start of prefix so that later calls to PetscOptionsSetValue work. This is the reason we pass prefix by value
param_objectThe ParallelParamObject adding the PETSc options
petsc_optionsData structure which handles petsc options within moose

Definition at line 850 of file PetscSupport.C.

856{
857 prefix.insert(prefix.begin(), '-');
858 checkPrefix(prefix);
859
860 // Setup the name value pairs
861 bool boomeramg_found = false;
862 bool strong_threshold_found = false;
863#if !PETSC_VERSION_LESS_THAN(3, 7, 0)
864 bool superlu_dist_found = false;
865 bool fact_pattern_found = false;
866 bool tiny_pivot_found = false;
867#endif
868 std::string pc_description = "";
869#if !PETSC_VERSION_LESS_THAN(3, 12, 0)
870 // If users use HMG, we would like to set
871 bool hmg_found = false;
872 bool matptap_found = false;
873 bool hmg_strong_threshold_found = false;
874#endif
875 std::vector<std::pair<std::string, std::string>> new_options;
876
877 for (const auto & [option_name, option_value] : petsc_pair_options)
878 {
879 checkUserProvidedPetscOption(option_name, param_object);
880
881 new_options.clear();
882 const std::string prefixed_option_name =
883 prefix + static_cast<const std::string &>(option_name).substr(1);
884
885 // Do not add duplicate settings
886 if (auto it =
887 MooseUtils::findPair(po.pairs, po.pairs.begin(), prefixed_option_name, MooseUtils::Any);
888 it == po.pairs.end())
889 {
890#if !PETSC_VERSION_LESS_THAN(3, 9, 0)
891 if (option_name == "-pc_factor_mat_solver_package")
892 new_options.emplace_back(prefix + "pc_factor_mat_solver_type", option_value);
893#else
894 if (option_name == "-pc_factor_mat_solver_type")
895 new_options.push_back(prefix + "pc_factor_mat_solver_package", option_value);
896#endif
897
898 // Look for a pc description
899 if (option_name == "-pc_type" || option_name == "-sub_pc_type" ||
900 option_name == "-pc_hypre_type")
901 pc_description += option_value + ' ';
902
903#if !PETSC_VERSION_LESS_THAN(3, 12, 0)
904 if (option_name == "-pc_type" && option_value == "hmg")
905 hmg_found = true;
906
907 // MPIAIJ for PETSc 3.12.0: -matptap_via
908 // MAIJ for PETSc 3.12.0: -matmaijptap_via
909 // MPIAIJ for PETSc 3.13 to 3.16: -matptap_via, -matproduct_ptap_via
910 // MAIJ for PETSc 3.13 to 3.16: -matproduct_ptap_via
911 // MPIAIJ for PETSc 3.17 and higher: -matptap_via, -mat_product_algorithm
912 // MAIJ for PETSc 3.17 and higher: -mat_product_algorithm
913#if !PETSC_VERSION_LESS_THAN(3, 17, 0)
914 if (hmg_found && (option_name == "-matptap_via" || option_name == "-matmaijptap_via" ||
915 option_name == "-matproduct_ptap_via"))
916 new_options.emplace_back(prefix + "mat_product_algorithm", option_value);
917#elif !PETSC_VERSION_LESS_THAN(3, 13, 0)
918 if (hmg_found && (option_name == "-matptap_via" || option_name == "-matmaijptap_via"))
919 new_options.emplace_back(prefix + "matproduct_ptap_via", option_value);
920#else
921 if (hmg_found && (option_name == "-matproduct_ptap_via"))
922 {
923 new_options.emplace_back(prefix + "matptap_via", option_value);
924 new_options.emplace_back(prefix + "matmaijptap_via", option_value);
925 }
926#endif
927
928 if (option_name == "-matptap_via" || option_name == "-matmaijptap_via" ||
929 option_name == "-matproduct_ptap_via" || option_name == "-mat_product_algorithm")
930 matptap_found = true;
931
932 // For 3D problems, we need to set this 0.7
933 if (option_name == "-hmg_inner_pc_hypre_boomeramg_strong_threshold")
934 hmg_strong_threshold_found = true;
935#endif
936 // This special case is common enough that we'd like to handle it for the user.
937 if (option_name == "-pc_hypre_type" && option_value == "boomeramg")
938 boomeramg_found = true;
939 if (option_name == "-pc_hypre_boomeramg_strong_threshold")
940 strong_threshold_found = true;
941#if !PETSC_VERSION_LESS_THAN(3, 7, 0)
942 if ((option_name == "-pc_factor_mat_solver_package" ||
943 option_name == "-pc_factor_mat_solver_type") &&
944 option_value == "superlu_dist")
945 superlu_dist_found = true;
946 if (option_name == "-mat_superlu_dist_fact")
947 fact_pattern_found = true;
948 if (option_name == "-mat_superlu_dist_replacetinypivot")
949 tiny_pivot_found = true;
950#endif
951
952 if (!new_options.empty())
953 {
954 std::copy(new_options.begin(), new_options.end(), std::back_inserter(po.pairs));
955 for (const auto & option : new_options)
956 po.user_set_options.setAdditionalValue(option.first);
957 }
958 else
959 {
960 po.pairs.push_back(std::make_pair(prefixed_option_name, option_value));
961 po.user_set_options.setAdditionalValue(prefixed_option_name);
962 }
963 }
964 else
965 {
966 do
967 {
968 it->second = option_value;
969 it = MooseUtils::findPair(po.pairs, std::next(it), prefixed_option_name, MooseUtils::Any);
970 } while (it != po.pairs.end());
971 }
972 }
973
974 // When running a 3D mesh with boomeramg, it is almost always best to supply a strong threshold
975 // value. We will provide that for the user here if they haven't supplied it themselves.
976 if (boomeramg_found && !strong_threshold_found && mesh_dimension == 3)
977 {
978 po.pairs.emplace_back(prefix + "pc_hypre_boomeramg_strong_threshold", "0.7");
979 pc_description += "strong_threshold: 0.7 (auto)";
980 }
981
982#if !PETSC_VERSION_LESS_THAN(3, 12, 0)
983 if (hmg_found && !hmg_strong_threshold_found && mesh_dimension == 3)
984 {
985 po.pairs.emplace_back(prefix + "hmg_inner_pc_hypre_boomeramg_strong_threshold", "0.7");
986 pc_description += "strong_threshold: 0.7 (auto)";
987 }
988
989 // Default PETSc PtAP takes too much memory, and it is not quite useful
990 // Let us switch to use new algorithm
991 if (hmg_found && !matptap_found)
992 {
993#if !PETSC_VERSION_LESS_THAN(3, 17, 0)
994 po.pairs.emplace_back(prefix + "mat_product_algorithm", "allatonce");
995#elif !PETSC_VERSION_LESS_THAN(3, 13, 0)
996 po.pairs.emplace_back(prefix + "matproduct_ptap_via", "allatonce");
997#else
998 po.pairs.emplace_back(prefix + "matptap_via", "allatonce");
999 po.pairs.emplace_back(prefix + "matmaijptap_via", "allatonce");
1000#endif
1001 }
1002#endif
1003
1004#if !PETSC_VERSION_LESS_THAN(3, 7, 0)
1005 // In PETSc-3.7.{0--4}, there is a bug when using superlu_dist, and we have to use
1006 // SamePattern_SameRowPerm, otherwise we use whatever we have in PETSc
1007 if (superlu_dist_found && !fact_pattern_found)
1008 {
1009 po.pairs.emplace_back(prefix + "mat_superlu_dist_fact",
1010#if PETSC_VERSION_LESS_THAN(3, 7, 5)
1011 "SamePattern_SameRowPerm");
1012 pc_description += "mat_superlu_dist_fact: SamePattern_SameRowPerm ";
1013#else
1014 "SamePattern");
1015 pc_description += "mat_superlu_dist_fact: SamePattern ";
1016#endif
1017 }
1018
1019 // restore this superlu option
1020 if (superlu_dist_found && !tiny_pivot_found)
1021 {
1022 po.pairs.emplace_back(prefix + "mat_superlu_dist_replacetinypivot", "1");
1023 pc_description += " mat_superlu_dist_replacetinypivot: true ";
1024 }
1025#endif
1026 // Set Preconditioner description
1027 if (!pc_description.empty() && prefix.size() > 1)
1028 po.pc_description += "[" + prefix.substr(1, prefix.size() - 2) + "]: ";
1029 po.pc_description += pc_description;
1030}

Referenced by PhysicsBase::addPetscPairsToPetscOptions(), MFEMPetscNonlinearSolver::ConstructSolver(), and storePetscOptions().

◆ checkUserProvidedPetscOption()

template<typename T >
void Moose::PetscSupport::checkUserProvidedPetscOption ( const T &  option,
const ParallelParamObject param_object 
)

Definition at line 778 of file PetscSupport.C.

779{
780 const auto & string_option = static_cast<const std::string &>(option);
781 if (string_option[0] != '-')
782 param_object.mooseError("PETSc option '", string_option, "' does not begin with '-'");
783}
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...
Definition MooseBase.h:271

Referenced by addPetscFlagsToPetscOptions(), and addPetscPairsToPetscOptions().

◆ colorAdjacencyMatrix()

void Moose::PetscSupport::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 algorithm to produce a coloring.

The coloring is returned as a vector of unsigned integers indicating which color or group each vextex in the adjacency matrix belongs to.

Definition at line 1229 of file PetscSupport.C.

1234{
1235 // Mat A will be a dense matrix from the incoming data structure
1236 Mat A;
1237 LibmeshPetscCallA(PETSC_COMM_SELF, MatCreate(PETSC_COMM_SELF, &A));
1238 LibmeshPetscCallA(PETSC_COMM_SELF, MatSetSizes(A, size, size, size, size));
1239 LibmeshPetscCallA(PETSC_COMM_SELF, MatSetType(A, MATSEQDENSE));
1240 // PETSc requires a non-const data array to populate the matrix
1241 LibmeshPetscCallA(PETSC_COMM_SELF, MatSeqDenseSetPreallocation(A, adjacency_matrix));
1242 LibmeshPetscCallA(PETSC_COMM_SELF, MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
1243 LibmeshPetscCallA(PETSC_COMM_SELF, MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
1244
1245 // Convert A to a sparse matrix
1246#if PETSC_VERSION_LESS_THAN(3, 7, 0)
1247 LibmeshPetscCallA(PETSC_COMM_SELF, MatConvert(A, MATAIJ, MAT_REUSE_MATRIX, &A));
1248#else
1249 LibmeshPetscCallA(PETSC_COMM_SELF, MatConvert(A, MATAIJ, MAT_INPLACE_MATRIX, &A));
1250#endif
1251
1252 ISColoring iscoloring;
1253 MatColoring mc;
1254 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringCreate(A, &mc));
1255 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetType(mc, coloring_algorithm));
1256 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetMaxColors(mc, static_cast<PetscInt>(colors)));
1257
1258 // Petsc normally colors by distance two (neighbors of neighbors), we just want one
1259 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetDistance(mc, 1));
1260 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringSetFromOptions(mc));
1261 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringApply(mc, &iscoloring));
1262
1263 PetscInt nn;
1264 IS * is;
1265#if PETSC_RELEASE_LESS_THAN(3, 12, 0)
1266 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringGetIS(iscoloring, &nn, &is));
1267#else
1268 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringGetIS(iscoloring, PETSC_USE_POINTER, &nn, &is));
1269#endif
1270
1271 if (nn > static_cast<PetscInt>(colors))
1272 throw std::runtime_error("Not able to color with designated number of colors");
1273
1274 for (int i = 0; i < nn; i++)
1275 {
1276 PetscInt isize;
1277 const PetscInt * indices;
1278 LibmeshPetscCallA(PETSC_COMM_SELF, ISGetLocalSize(is[i], &isize));
1279 LibmeshPetscCallA(PETSC_COMM_SELF, ISGetIndices(is[i], &indices));
1280 for (int j = 0; j < isize; j++)
1281 {
1282 mooseAssert(indices[j] < static_cast<PetscInt>(vertex_colors.size()), "Index out of bounds");
1283 vertex_colors[indices[j]] = i;
1284 }
1285 LibmeshPetscCallA(PETSC_COMM_SELF, ISRestoreIndices(is[i], &indices));
1286 }
1287
1288 LibmeshPetscCallA(PETSC_COMM_SELF, MatDestroy(&A));
1289 LibmeshPetscCallA(PETSC_COMM_SELF, MatColoringDestroy(&mc));
1290 LibmeshPetscCallA(PETSC_COMM_SELF, ISColoringDestroy(&iscoloring));
1291}
PetscErrorCode PetscInt const PetscInt IS * is

◆ createMatrixFromFile()

std::unique_ptr< PetscMatrix< Number > > Moose::PetscSupport::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.

Note that the returned libMesh matrix wrapper will not destroy the created matrix on destruction. petsc_mat must be destroyed manually via MatDestroy

Parameters
mat_number_to_loadA binary file may contain multiple writes of a matrix. This parameter can be used to load a particular matrix from the binary file. By default we load the first written matrix

Definition at line 1339 of file PetscSupport.C.

1343{
1344 LibmeshPetscCallA(comm.get(), MatCreate(comm.get(), &mat));
1345 PetscViewer matviewer;
1346 LibmeshPetscCallA(
1347 comm.get(),
1348 PetscViewerBinaryOpen(comm.get(), binary_mat_file.c_str(), FILE_MODE_READ, &matviewer));
1349 for (unsigned int i = 0; i < mat_number_to_load; ++i)
1350 LibmeshPetscCallA(comm.get(), MatLoad(mat, matviewer));
1351 LibmeshPetscCallA(comm.get(), PetscViewerDestroy(&matviewer));
1352
1353 return std::make_unique<PetscMatrix<Number>>(mat, comm);
1354}

Referenced by MatrixSymmetryCheck::execute().

◆ dontAddCommonKSPOptions()

void Moose::PetscSupport::dontAddCommonKSPOptions ( FEProblemBase fe_problem)

Function to ensure that common KSP options are not added to the PetscOptions storage object to be later set unless explicitly specified in input or on the command line.

Definition at line 1313 of file PetscSupport.C.

1314{
1315 auto & petsc_options = fe_problem.getPetscOptions();
1316 for (const auto & flag : getCommonKSPFlags().getNames())
1317 dontAddPetscFlag(flag, petsc_options);
1318 for (const auto & key : getCommonKSPKeys().getNames())
1319 dontAddPetscFlag(key, petsc_options);
1320}
Moose::PetscSupport::PetscOptions & getPetscOptions()
Retrieve a writable reference the PETSc options (used by PetscSupport)
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 ...
MultiMooseEnum getCommonKSPKeys()
A helper function to produce a MultiMooseEnum with commonly used PETSc ksp option names (keys)
MultiMooseEnum getCommonKSPFlags()
A helper function to produce a MultiMooseEnum with commonly used PETSc ksp single options (flags)

Referenced by ExplicitTimeIntegrator::ExplicitTimeIntegrator().

◆ dontAddCommonSNESOptions() [1/2]

void Moose::PetscSupport::dontAddCommonSNESOptions ( FEProblemBase fe_problem)

Function to ensure that common SNES options are not added to the PetscOptions storage object to be later set unless explicitly specified in input or on the command line.

Definition at line 1323 of file PetscSupport.C.

1324{
1325 dontAddCommonSNESOptions(fe_problem, "");
1326}
void dontAddCommonSNESOptions(FEProblemBase &fe_problem)
Function to ensure that common SNES options are not added to the PetscOptions storage object to be la...

Referenced by dontAddCommonSNESOptions(), ExplicitTimeIntegrator::ExplicitTimeIntegrator(), and FEProblemSolve::FEProblemSolve().

◆ dontAddCommonSNESOptions() [2/2]

void Moose::PetscSupport::dontAddCommonSNESOptions ( FEProblemBase fe_problem,
const std::string &  prefix 
)

Prefixed variant: suppress common SNES options for the system identified by prefix (e.g.

"v_sys_"). Adds the prefixed flag/key names to the blocklist so that setSolverOptions and setConvergedReasonFlags skip them for that system.

Definition at line 1329 of file PetscSupport.C.

1330{
1331 auto & petsc_options = fe_problem.getPetscOptions();
1332 for (const auto & flag : getCommonSNESFlags().getNames())
1333 dontAddPetscFlag("-" + prefix + flag.substr(1), petsc_options);
1334 for (const auto & key : getCommonSNESKeys().getNames())
1335 dontAddPetscFlag("-" + prefix + key.substr(1), petsc_options);
1336}
MultiMooseEnum getCommonSNESKeys()
A helper function to produce a MultiMooseEnum with commonly used PETSc snes option names (keys)
MultiMooseEnum getCommonSNESFlags()
A helper function to produce a MultiMooseEnum with commonly used PETSc snes single options (flags)

◆ dontAddLinearConvergedReason()

void Moose::PetscSupport::dontAddLinearConvergedReason ( FEProblemBase fe_problem)

Function to ensure that -ksp_converged_reason is not added to the PetscOptions storage object to be later set unless explicitly specified in input or on the command line.

Definition at line 1307 of file PetscSupport.C.

1308{
1309 dontAddPetscFlag("-ksp_converged_reason", fe_problem.getPetscOptions());
1310}

Referenced by CommonOutputAction::act(), and EigenProblemSolve::EigenProblemSolve().

◆ dontAddNonlinearConvergedReason()

void Moose::PetscSupport::dontAddNonlinearConvergedReason ( FEProblemBase fe_problem)

Function to ensure that -snes_converged_reason is not added to the PetscOptions storage object to be later set unless explicitly specified in input or on the command line.

Definition at line 1301 of file PetscSupport.C.

1302{
1303 dontAddPetscFlag("-snes_converged_reason", fe_problem.getPetscOptions());
1304}

Referenced by CommonOutputAction::act(), and EigenProblemSolve::EigenProblemSolve().

◆ dontAddPetscFlag()

void Moose::PetscSupport::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 be later set unless explicitly specified in input or on the command line.

Definition at line 1294 of file PetscSupport.C.

1295{
1296 if (!petsc_options.dont_add_these_options.contains(flag))
1297 petsc_options.dont_add_these_options.setAdditionalValue(flag);
1298}
MultiMooseEnum dont_add_these_options
Flags to explicitly not set, even if they are specified programmatically.
void setAdditionalValue(const std::string &names)
Insert operators Operator to insert (push_back) values into the enum.
bool contains(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.

Referenced by dontAddCommonKSPOptions(), dontAddCommonSNESOptions(), dontAddLinearConvergedReason(), dontAddNonlinearConvergedReason(), and EigenProblemSolve::EigenProblemSolve().

◆ getCommonKSPFlags()

MultiMooseEnum Moose::PetscSupport::getCommonKSPFlags ( )

A helper function to produce a MultiMooseEnum with commonly used PETSc ksp single options (flags)

Definition at line 1085 of file PetscSupport.C.

1086{
1087 return MultiMooseEnum(
1088 "-ksp_converged_reason -ksp_gmres_modifiedgramschmidt -ksp_monitor", "", true);
1089}
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.

Referenced by dontAddCommonKSPOptions(), and getCommonPetscFlags().

◆ getCommonKSPKeys()

MultiMooseEnum Moose::PetscSupport::getCommonKSPKeys ( )

A helper function to produce a MultiMooseEnum with commonly used PETSc ksp option names (keys)

Definition at line 1110 of file PetscSupport.C.

1111{
1112 return MultiMooseEnum("-ksp_atol -ksp_gmres_restart -ksp_max_it -ksp_pc_side -ksp_rtol "
1113 "-ksp_type -sub_ksp_type",
1114 "",
1115 true);
1116}

Referenced by dontAddCommonKSPOptions(), and getCommonPetscKeys().

◆ getCommonPetscFlags()

MultiMooseEnum Moose::PetscSupport::getCommonPetscFlags ( )

A helper function to produce a MultiMooseEnum with commonly used PETSc single options (flags)

Definition at line 1092 of file PetscSupport.C.

1093{
1094 auto options = MultiMooseEnum("-dm_moose_print_embedding -dm_view", "", true);
1095 options.addValidName(getCommonKSPFlags());
1096 options.addValidName(getCommonSNESFlags());
1097 return options;
1098}

Referenced by getPetscValidParams(), AddFieldSplitAction::validParams(), MFEMPetscNonlinearSolver::validParams(), and Split::validParams().

◆ getCommonPetscKeys()

MultiMooseEnum Moose::PetscSupport::getCommonPetscKeys ( )

A helper function to produce a MultiMooseEnum with commonly used PETSc iname options (keys in key-value pairs)

Definition at line 1118 of file PetscSupport.C.

1119{
1120 auto options = MultiMooseEnum("-mat_fd_coloring_err -mat_fd_type -mat_mffd_type "
1121 "-pc_asm_overlap -pc_factor_levels "
1122 "-pc_factor_mat_ordering_type -pc_hypre_boomeramg_grid_sweeps_all "
1123 "-pc_hypre_boomeramg_max_iter "
1124 "-pc_hypre_boomeramg_strong_threshold -pc_hypre_type -pc_type "
1125 "-sub_pc_type",
1126 "",
1127 true);
1128 options.addValidName(getCommonKSPKeys());
1129 options.addValidName(getCommonSNESKeys());
1130 return options;
1131}

Referenced by getPetscValidParams(), AddFieldSplitAction::validParams(), MFEMPetscNonlinearSolver::validParams(), and Split::validParams().

◆ getCommonSNESFlags()

MultiMooseEnum Moose::PetscSupport::getCommonSNESFlags ( )

A helper function to produce a MultiMooseEnum with commonly used PETSc snes single options (flags)

Definition at line 1074 of file PetscSupport.C.

1075{
1076 return MultiMooseEnum(
1077 "-ksp_monitor_snes_lg -snes_ksp_ew -snes_converged_reason "
1078 "-snes_ksp -snes_linesearch_monitor -snes_mf -snes_mf_operator -snes_monitor "
1079 "-snes_test_display -snes_view -snes_monitor_cancel",
1080 "",
1081 true);
1082}

Referenced by dontAddCommonSNESOptions(), and getCommonPetscFlags().

◆ getCommonSNESKeys()

MultiMooseEnum Moose::PetscSupport::getCommonSNESKeys ( )

A helper function to produce a MultiMooseEnum with commonly used PETSc snes option names (keys)

Definition at line 1101 of file PetscSupport.C.

1102{
1103 return MultiMooseEnum("-snes_atol -snes_linesearch_type -snes_ls -snes_max_it -snes_rtol "
1104 "-snes_divergence_tolerance -snes_type",
1105 "",
1106 true);
1107}

Referenced by dontAddCommonSNESOptions(), and getCommonPetscKeys().

◆ getPetscKSPNormType()

KSPNormType Moose::PetscSupport::getPetscKSPNormType ( Moose::MooseKSPNormType  kspnorm)

Definition at line 550 of file PetscSupport.C.

551{
552 switch (kspnorm)
553 {
554 case Moose::KSPN_NONE:
555 return KSP_NORM_NONE;
557 return KSP_NORM_PRECONDITIONED;
559 return KSP_NORM_UNPRECONDITIONED;
561 return KSP_NORM_NATURAL;
563 return KSP_NORM_DEFAULT;
564 default:
565 mooseError("Unknown KSP norm type requested.");
566 break;
567 }
568}
@ KSPN_NONE
Definition MooseTypes.h:886
@ KSPN_PRECONDITIONED
Definition MooseTypes.h:887
@ KSPN_UNPRECONDITIONED
Definition MooseTypes.h:888
@ KSPN_DEFAULT
Use whatever we have in PETSc.
Definition MooseTypes.h:890
@ KSPN_NATURAL
Definition MooseTypes.h:889

Referenced by petscSetDefaultKSPNormType().

◆ getPetscPCSide()

PCSide Moose::PetscSupport::getPetscPCSide ( Moose::PCSideType  pcs)

Definition at line 533 of file PetscSupport.C.

534{
535 switch (pcs)
536 {
537 case Moose::PCS_LEFT:
538 return PC_LEFT;
539 case Moose::PCS_RIGHT:
540 return PC_RIGHT;
542 return PC_SYMMETRIC;
543 default:
544 mooseError("Unknown PC side requested.");
545 break;
546 }
547}
@ PCS_LEFT
Definition MooseTypes.h:875
@ PCS_SYMMETRIC
Definition MooseTypes.h:877
@ PCS_RIGHT
Definition MooseTypes.h:876

Referenced by petscSetDefaultPCSide().

◆ getPetscValidLineSearches()

std::set< std::string > Moose::PetscSupport::getPetscValidLineSearches ( )

Returns the valid petsc line search options as a set of strings.

Definition at line 1033 of file PetscSupport.C.

1034{
1035 return {"default", "shell", "none", "basic", "l2", "bt", "cp"};
1036}

Referenced by FEProblemSolve::validParams().

◆ getPetscValidParams()

InputParameters Moose::PetscSupport::getPetscValidParams ( )

Returns the PETSc options that are common between Executioners and Preconditioners.

Returns
InputParameters object containing the PETSc related parameters

The output of this function should be added to the the parameters object of the overarching class

See also
CreateExecutionerAction

Definition at line 1039 of file PetscSupport.C.

1040{
1042
1043 MooseEnum solve_type("PJFNK JFNK NEWTON FD LINEAR");
1044 params.addParam<MooseEnum>("solve_type",
1045 solve_type,
1046 "PJFNK: Preconditioned Jacobian-Free Newton Krylov "
1047 "JFNK: Jacobian-Free Newton Krylov "
1048 "NEWTON: Full Newton Solve "
1049 "FD: Use finite differences to compute Jacobian "
1050 "LINEAR: Solving a linear problem");
1051
1052 MooseEnum mffd_type("wp ds", "wp");
1053 params.addParam<MooseEnum>("mffd_type",
1054 mffd_type,
1055 "Specifies the finite differencing type for "
1056 "Jacobian-free solve types. Note that the "
1057 "default is wp (for Walker and Pernice).");
1058
1059 params.addParam<MultiMooseEnum>(
1060 "petsc_options", getCommonPetscFlags(), "Singleton PETSc options");
1061 params.addParam<MultiMooseEnum>(
1062 "petsc_options_iname", getCommonPetscKeys(), "Names of PETSc name/value pairs");
1063 params.addParam<std::vector<std::string>>(
1064 "petsc_options_value",
1065 "Values of PETSc name/value pairs (must correspond with \"petsc_options_iname\"");
1066 params.addParamNamesToGroup("solve_type petsc_options petsc_options_iname petsc_options_value "
1067 "mffd_type",
1068 "PETSc");
1069
1070 return params;
1071}
InputParameters emptyInputParameters()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
MultiMooseEnum getCommonPetscFlags()
A helper function to produce a MultiMooseEnum with commonly used PETSc single options (flags)
MultiMooseEnum getCommonPetscKeys()
A helper function to produce a MultiMooseEnum with commonly used PETSc iname options (keys in key-val...

Referenced by FEProblemSolve::validParams(), and MoosePreconditioner::validParams().

◆ isSNESVI()

bool Moose::PetscSupport::isSNESVI ( FEProblemBase fe_problem)

check if SNES type is variational inequalities (VI) solver

Definition at line 1134 of file PetscSupport.C.

1135{
1136 const PetscOptions & petsc = fe_problem.getPetscOptions();
1137
1138 int argc;
1139 char ** args;
1140 LibmeshPetscCallA(fe_problem.comm().get(), PetscGetArgs(&argc, &args));
1141
1142 std::vector<std::string> cml_arg;
1143 for (int i = 0; i < argc; i++)
1144 cml_arg.push_back(args[i]);
1145
1146 if (MooseUtils::findPair(petsc.pairs, petsc.pairs.begin(), MooseUtils::Any, "vinewtonssls") ==
1147 petsc.pairs.end() &&
1148 MooseUtils::findPair(petsc.pairs, petsc.pairs.begin(), MooseUtils::Any, "vinewtonrsls") ==
1149 petsc.pairs.end() &&
1150 std::find(cml_arg.begin(), cml_arg.end(), "vinewtonssls") == cml_arg.end() &&
1151 std::find(cml_arg.begin(), cml_arg.end(), "vinewtonrsls") == cml_arg.end())
1152 return false;
1153
1154 return true;
1155}
A struct for storing the various types of petsc options and values.
std::vector< std::pair< std::string, std::string > > pairs
PETSc key-value pairs.
const Parallel::Communicator & comm() const

Referenced by BoundsBase::initialSetup().

◆ outputNorm()

void Moose::PetscSupport::outputNorm ( libMesh::Real  old_norm,
libMesh::Real  norm,
bool  use_color = false 
)

Helper function for outputting the norm values with/without color.

◆ petscLinearConverged()

PetscErrorCode Moose::PetscSupport::petscLinearConverged ( KSP  ,
PetscInt  it,
PetscReal  ,
KSPConvergedReason *  reason,
void *  ctx 
)

Definition at line 483 of file PetscSupport.C.

485{
487 FEProblemBase & problem = *static_cast<FEProblemBase *>(ctx);
488
489 // execute objects that may be used in convergence check
490 // Right now, setting objects to execute on this flag would be ignored except in the
491 // linear-system-only use case.
493
494 // perform the convergence check
497 {
500 }
501 else
502 {
503 auto & convergence = problem.getConvergence(
505 status = convergence.checkConvergence(it);
506 }
507
508 // convert convergence status to PETSc converged reason
509 switch (status)
510 {
512 *reason = KSP_CONVERGED_ITERATING;
513 break;
514
515 // TODO: find a KSP code that works better for this case
517#if PETSC_VERSION_LESS_THAN(3, 24, 0)
518 *reason = KSP_CONVERGED_RTOL_NORMAL;
519#else
520 *reason = KSP_CONVERGED_RTOL_NORMAL_EQUATIONS;
521#endif
522 break;
523
525 *reason = KSP_DIVERGED_DTOL;
526 break;
527 }
528
529 PetscFunctionReturn(PETSC_SUCCESS);
530}
const ExecFlagType EXEC_LINEAR_CONVERGENCE
Definition Moose.C:32
PetscFunctionBegin
MooseConvergenceStatus
Status returned by calls to checkConvergence.
Definition Convergence.h:34
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
LinearSystem & currentLinearSystem()
Get a non-constant reference to the current linear system.
virtual Convergence & getConvergence(const std::string &name, const THREAD_ID tid=0) const
Gets a Convergence object.
bool getFailNextSystemConvergenceCheck() const
Whether it will fail the next system convergence check(s), triggering failed step behavior.
const std::vector< ConvergenceName > & getLinearConvergenceNames() const
Gets the linear convergence object name(s).
virtual void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
void resetFailNextSystemConvergenceCheck()
Tell the problem that the system convergence check(s) may proceed as normal.
unsigned int number() const
Gets the number of this system.
PetscFunctionReturn(LIBMESH_PETSC_SUCCESS)
void * ctx

Referenced by petscSetDefaults().

◆ petscLinearMonitor()

PetscErrorCode Moose::PetscSupport::petscLinearMonitor ( KSP  ,
PetscInt  its,
PetscReal  rnorm,
void *  void_ptr 
)

Helper function for displaying the linear residual during PETSC solve.

◆ petscNonlinearConverged()

PetscErrorCode Moose::PetscSupport::petscNonlinearConverged ( SNES  ,
PetscInt  it,
PetscReal  ,
PetscReal  ,
PetscReal  ,
SNESConvergedReason *  reason,
void *  ctx 
)

Definition at line 435 of file PetscSupport.C.

442{
444 FEProblemBase & problem = *static_cast<FEProblemBase *>(ctx);
445
446 // execute objects that may be used in convergence check
448
449 // perform the convergence check
452 {
455 }
456 else
457 {
458 auto & convergence = problem.getConvergence(
460 status = convergence.checkConvergence(it);
461 }
462
463 // convert convergence status to PETSc converged reason
464 switch (status)
465 {
467 *reason = SNES_CONVERGED_ITERATING;
468 break;
469
471 *reason = SNES_CONVERGED_FNORM_ABS;
472 break;
473
475 *reason = SNES_DIVERGED_DTOL;
476 break;
477 }
478
479 PetscFunctionReturn(PETSC_SUCCESS);
480}
const ExecFlagType EXEC_NONLINEAR_CONVERGENCE
Definition Moose.C:34
const std::vector< ConvergenceName > & getNonlinearConvergenceNames() const
Gets the nonlinear system convergence object name(s).
bool getFailNextNonlinearConvergenceCheck() const
Whether it will skip further residual evaluations and fail the next nonlinear convergence check(s)
void resetFailNextNonlinearConvergenceCheck()
Tell the problem that the nonlinear convergence check(s) may proceed as normal.
NonlinearSystemBase & currentNonlinearSystem()

Referenced by petscSetDefaults().

◆ petscSetDefaultKSPNormType()

void Moose::PetscSupport::petscSetDefaultKSPNormType ( FEProblemBase problem,
KSP  ksp 
)

Set norm type.

Definition at line 571 of file PetscSupport.C.

572{
573 for (const auto i : make_range(problem.numSolverSystems()))
574 {
575 SolverSystem & sys = problem.getSolverSystem(i);
576 LibmeshPetscCallA(problem.comm().get(),
577 KSPSetNormType(ksp, getPetscKSPNormType(sys.getMooseKSPNormType())));
578 }
579}
Moose::MooseKSPNormType getMooseKSPNormType()
Get the norm in which the linear convergence is measured.
KSPNormType getPetscKSPNormType(Moose::MooseKSPNormType kspnorm)

Referenced by Moose::SlepcSupport::mooseSlepcEPSSNESKSPSetPCSide(), and petscSetKSPDefaults().

◆ petscSetDefaultPCSide()

void Moose::PetscSupport::petscSetDefaultPCSide ( FEProblemBase problem,
KSP  ksp 
)

Setup which side we want to apply preconditioner.

Definition at line 582 of file PetscSupport.C.

583{
584 for (const auto i : make_range(problem.numSolverSystems()))
585 {
586 SolverSystem & sys = problem.getSolverSystem(i);
587
588 // PETSc 3.2.x+
589 if (sys.getPCSide() != Moose::PCS_DEFAULT)
590 LibmeshPetscCallA(problem.comm().get(), KSPSetPCSide(ksp, getPetscPCSide(sys.getPCSide())));
591 }
592}
Moose::PCSideType getPCSide()
Get the current preconditioner side.
PCSide getPetscPCSide(Moose::PCSideType pcs)
@ PCS_DEFAULT
Use whatever we have in PETSc.
Definition MooseTypes.h:878

Referenced by Moose::SlepcSupport::mooseSlepcEPSSNESKSPSetPCSide(), and petscSetKSPDefaults().

◆ petscSetDefaults()

void Moose::PetscSupport::petscSetDefaults ( FEProblemBase problem)

Sets the default options for PETSc.

Definition at line 617 of file PetscSupport.C.

618{
619 // Apply matrix-type options once the per-system matrix prefixes are known. This is different
620 // from vectors: libMesh/PETSc vector construction already sees a global '-vec_type' option,
621 // but prefixed matrix options such as '-nl0_mat_type' cannot match anything until we set the
622 // matrix prefix here. Without this, a matrix may be constructed with the default type and keep
623 // that type for the rest of the solve, unless we not only set the options prefix but also apply
624 // the options to the matrix in this function call.
625 applyMatrixTypeOptions(problem);
626
627 for (const auto nl_index : make_range(problem.numNonlinearSystems()))
628 {
629 NonlinearSystemBase & nl = problem.getNonlinearSystemBase(nl_index);
630
631 // dig out PETSc solver
632 auto * const petsc_solver = cast_ptr<PetscNonlinearSolver<Number> *>(nl.nonlinearSolver());
633
634 // Ensure we properly prefix SNES which in turn prefixes its KSP
635 const char * snes_prefix = nullptr;
636 std::string snes_prefix_str;
637 if (nl.system().prefix_with_name())
638 {
639 snes_prefix_str = nl.system().prefix();
640 snes_prefix = snes_prefix_str.c_str();
641 }
642 SNES snes = petsc_solver->snes(snes_prefix);
643 KSP ksp;
644 LibmeshPetscCallA(nl.comm().get(), SNESGetKSP(snes, &ksp));
645 LibmeshPetscCallA(nl.comm().get(), SNESSetMaxLinearSolveFailures(snes, 1000000));
646 LibmeshPetscCallA(nl.comm().get(), SNESSetCheckJacobianDomainError(snes, PETSC_TRUE));
647 LibmeshPetscCallA(
648 nl.comm().get(),
649 SNESSetConvergenceTest(snes, petscNonlinearConverged, &problem, LIBMESH_PETSC_NULLPTR));
650
651 petscSetKSPDefaults(problem, ksp);
652 }
653
654 for (auto sys_index : make_range(problem.numLinearSystems()))
655 {
656 // dig out PETSc solver
657 LinearSystem & lin_sys = problem.getLinearSystem(sys_index);
658 auto & lm_lin_sys = lin_sys.linearImplicitSystem();
659 auto * const petsc_solver =
660 dynamic_cast<PetscLinearSolver<Number> *>(lm_lin_sys.get_linear_solver());
661 // Ensure we properly prefix KSP
662 if (lm_lin_sys.prefix_with_name())
663 petsc_solver->init(lm_lin_sys.prefix().c_str());
664 else
665 petsc_solver->init();
666 // The KSP call here would initialize without a prefix if we hadn't "manually" performed
667 // initialization above
668 KSP ksp = petsc_solver->ksp();
669
670 if (problem.hasLinearConvergenceObjects())
671 LibmeshPetscCallA(
672 lin_sys.comm().get(),
673 KSPSetConvergenceTest(ksp, petscLinearConverged, &problem, LIBMESH_PETSC_NULLPTR));
674
675 // We dont set the KSP defaults here because they seem to clash with the linear solve parameters
676 // set in FEProblemBase::solveLinearSystem
677 }
678}
bool hasLinearConvergenceObjects() const
Whether we have linear convergence objects.
LinearSystem & getLinearSystem(unsigned int sys_num)
Get non-constant reference to a linear system.
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
Linear system to be solved.
libMesh::LinearImplicitSystem & linearImplicitSystem()
Return a reference to the stored linear implicit system.
Nonlinear system to be solved.
virtual libMesh::NonlinearSolver< Number > * nonlinearSolver()=0
virtual libMesh::System & system() override
Get the reference to the libMesh system.
virtual void init(const char *name=nullptr) override
void prefix_with_name(bool value)
std::string prefix() const

Referenced by FEProblemBase::initPetscOutputAndSomeSolverSettings(), Moose::ScopedThrowOnError::ScopedThrowOnError(), and FEProblemBase::solveLinearSystem().

◆ petscSetKSPDefaults()

void Moose::PetscSupport::petscSetKSPDefaults ( FEProblemBase problem,
KSP  ksp 
)

Set the default options for a KSP.

Definition at line 595 of file PetscSupport.C.

596{
597 auto & es = problem.es();
598
599 PetscReal rtol = es.parameters.get<Real>("linear solver tolerance");
600 PetscReal atol = es.parameters.get<Real>("linear solver absolute tolerance");
601
602 // MOOSE defaults this to -1 for some dumb reason
603 if (atol < 0)
604 atol = 1e-50;
605
606 PetscReal maxits = es.parameters.get<unsigned int>("linear solver maximum iterations");
607
608 // 1e100 is because we don't use divtol currently
609 LibmeshPetscCallA(problem.comm().get(), KSPSetTolerances(ksp, rtol, atol, 1e100, maxits));
610
611 petscSetDefaultPCSide(problem, ksp);
612
613 petscSetDefaultKSPNormType(problem, ksp);
614}
virtual libMesh::EquationSystems & es() override
const T & get(std::string_view) const
void petscSetDefaultKSPNormType(FEProblemBase &problem, KSP ksp)
Set norm type.
void petscSetDefaultPCSide(FEProblemBase &problem, KSP ksp)
Setup which side we want to apply preconditioner.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

Referenced by petscSetDefaults(), and setLinearSolverDefaults().

◆ petscSetOptions() [1/2]

void Moose::PetscSupport::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.

This interface function should be used when setting options on a per-system basis

Definition at line 397 of file PetscSupport.C.

400{
401 PetscCallAbort(PETSC_COMM_WORLD, PetscOptionsClear(LIBMESH_PETSC_NULLPTR));
402 setSolverOptions(solver_params, po.dont_add_these_options);
403 petscSetOptionsHelper(po, problem);
404}
void petscSetOptionsHelper(const PetscOptions &po, FEProblemBase *const problem)
void setSolverOptions(const SolverParams &solver_params, const MultiMooseEnum &dont_add_these_options)

Referenced by Moose::SlepcSupport::slepcSetOptions(), FEProblemBase::solve(), and FEProblemBase::solveLinearSystem().

◆ petscSetOptions() [2/2]

void Moose::PetscSupport::petscSetOptions ( const PetscOptions po,
const std::vector< SolverParams > &  solver_params,
FEProblemBase problem 
)

A function for setting the PETSc options in PETSc from the options supplied to MOOSE.

This interface function should be used for setting options all at once for all systems in a multi-system context. Note that PetscOptions is not a vector because the options database has prefixes for the different systems

Definition at line 407 of file PetscSupport.C.

410{
411 PetscCallAbort(PETSC_COMM_WORLD, PetscOptionsClear(LIBMESH_PETSC_NULLPTR));
412 for (const auto & solver_params : solver_params_vec)
413 setSolverOptions(solver_params, po.dont_add_these_options);
414 petscSetOptionsHelper(po, problem);
415}

◆ petscSetOptionsHelper()

void Moose::PetscSupport::petscSetOptionsHelper ( const PetscOptions po,
FEProblemBase *const  problem 
)

Definition at line 377 of file PetscSupport.C.

378{
379 // Add any additional options specified in the input file
380 for (const auto & flag : po.flags)
381 // Need to use name method here to pass a str instead of an EnumItem because
382 // we don't care if the id attributes match
383 if (!po.dont_add_these_options.contains(flag.name()) ||
384 po.user_set_options.contains(flag.name()))
385 setSinglePetscOption(flag.rawName().c_str());
386
387 // Add option pairs
388 for (auto & option : po.pairs)
389 if (!po.dont_add_these_options.contains(option.first) ||
390 po.user_set_options.contains(option.first))
391 setSinglePetscOption(option.first, option.second, problem);
392
394}
void addPetscOptionsFromCommandline(FEProblemBase *const problem=nullptr)
Insert command-line PETSc options into the active PETSc options database.
void setSinglePetscOption(const std::string &name, const std::string &value="", FEProblemBase *const problem=nullptr)
A wrapper function for dealing with different versions of PetscOptionsSetValue.
if(subdm)

Referenced by petscSetOptions(), and petscSetOptions().

◆ petscSetupOutput()

PetscErrorCode Moose::PetscSupport::petscSetupOutput ( CommandLine cmd_line)

Definition at line 418 of file PetscSupport.C.

419{
421 char code[10] = {45, 45, 109, 111, 111, 115, 101};
422 const std::vector<std::string> argv = cmd_line->getArguments();
423 for (const auto & arg : argv)
424 {
425 if (arg.compare(code) == 0)
426 {
428 break;
429 }
430 }
431 PetscFunctionReturn(PETSC_SUCCESS);
432}
const std::vector< std::string > & getArguments()
static void petscSetupOutput()
Output string for setting up PETSC output.
Definition Console.C:855

Referenced by MooseApp::executeExecutioner().

◆ processSingletonMooseWrappedOptions()

void Moose::PetscSupport::processSingletonMooseWrappedOptions ( FEProblemBase fe_problem,
const InputParameters params 
)

Process some MOOSE-wrapped PETSc options.

These options have no support for multi-system as indicated by the fact that this function takes no prefix nor solver system argument

Definition at line 681 of file PetscSupport.C.

682{
683 setSolveTypeFromParams(fe_problem, params);
684 setLineSearchFromParams(fe_problem, params);
685 setMFFDTypeFromParams(fe_problem, params);
686}
void setMFFDTypeFromParams(FEProblemBase &fe_problem, const InputParameters &params)
Sets the FE problem's matrix-free finite difference type from the input params.
void setSolveTypeFromParams(FEProblemBase &fe_problem, const InputParameters &params)
Sets the FE problem's solve type from the input params.
void setLineSearchFromParams(FEProblemBase &fe_problem, const InputParameters &params)
Sets the FE problem's line search from the input params.

Referenced by storePetscOptions().

◆ registerPetscCitation()

void Moose::PetscSupport::registerPetscCitation ( const std::string &  bibtex)

Register a BibTeX entry with PETSc's citation list so that it is printed (alongside the run-specific citations from any PETSc solvers/preconditioners used) when the PETSc -citations option is enabled.

The list is printed at PetscFinalize.

Definition at line 1357 of file PetscSupport.C.

1358{
1359 // PETSc concatenates registered entries verbatim, so ensure a trailing newline to keep entries
1360 // separated. A null "set" flag registers unconditionally; callers deduplicate by citation key.
1361 const std::string entry = (!bibtex.empty() && bibtex.back() == '\n') ? bibtex : bibtex + "\n";
1362 LibmeshPetscCallA(PETSC_COMM_WORLD, PetscCitationsRegister(entry.c_str(), nullptr));
1363}

Referenced by MooseApp::requestCitations().

◆ setConvergedReasonFlags()

void Moose::PetscSupport::setConvergedReasonFlags ( FEProblemBase fe_problem,
std::string  prefix 
)

Set flags that will instruct the user on the reason their simulation diverged from PETSc's perspective.

Parameters
fe_problemThe problem from which to retrieve the PETSc options
prefixThe prefix to add to the convergence flags. This should not contain a leading dash per PETSc prefix convention. Note that this function will immediately \emph add said dash at the start of prefix so that calls to PetscOptionsSetValue work. This is the reason we pass prefix by value

Definition at line 823 of file PetscSupport.C.

824{
825 prefix.insert(prefix.begin(), '-');
826 checkPrefix(prefix);
827 libmesh_ignore(fe_problem); // avoid unused warnings for old PETSc
828
829#if !PETSC_VERSION_LESS_THAN(3, 14, 0)
830 // the boolean in these pairs denote whether the user has specified any of the reason flags in the
831 // input file
832 std::array<std::string, 2> reason_flags = {{"snes_converged_reason", "ksp_converged_reason"}};
833
834 auto & po = fe_problem.getPetscOptions();
835
836 for (const auto & reason_flag : reason_flags)
837 {
838 const auto full_flag = prefix + reason_flag;
839 if (!po.flags.isValueSet(full_flag) && !po.dont_add_these_options.contains(full_flag) &&
840 (std::find_if(po.pairs.begin(),
841 po.pairs.end(),
842 [&full_flag](auto & pair)
843 { return pair.first == (full_flag); }) == po.pairs.end()))
844 po.pairs.emplace_back(full_flag, "::failed");
845 }
846#endif
847}
void libmesh_ignore(const Args &...)

Referenced by FEProblemSolve::FEProblemSolve().

◆ setLinearSolverDefaults()

template<typename T >
void Moose::PetscSupport::setLinearSolverDefaults ( FEProblemBase problem,
libMesh::LinearSolver< T > &  linear_solver 
)

Set the defaults for a libMesh LinearSolver.

Used in explicit solves

Definition at line 118 of file PetscSupport.h.

119{
120 petscSetKSPDefaults(problem,
121 libMesh::cast_ref<libMesh::PetscLinearSolver<T> &>(linear_solver).ksp());
122}
void petscSetKSPDefaults(FEProblemBase &problem, KSP ksp)
Set the default options for a KSP.
Tnew cast_ref(Told &oldvar)

Referenced by ExplicitTimeIntegrator::setupSolver().

◆ setLineSearchFromParams()

void Moose::PetscSupport::setLineSearchFromParams ( FEProblemBase fe_problem,
const InputParameters params 
)

Sets the FE problem's line search from the input params.

Definition at line 734 of file PetscSupport.C.

735{
736 // Note: Options set in the Preconditioner block will override those set in the Executioner block
737 if (params.isParamValid("line_search"))
738 {
739 const auto & line_search = params.get<MooseEnum>("line_search");
740 for (const auto i : make_range(fe_problem.numNonlinearSystems()))
741 if (fe_problem.solverParams(i)._line_search == Moose::LS_INVALID || line_search != "default")
742 {
743 Moose::LineSearchType enum_line_search =
744 Moose::stringToEnum<Moose::LineSearchType>(line_search);
745 fe_problem.solverParams(i)._line_search = enum_line_search;
746 if (enum_line_search == LS_CONTACT || enum_line_search == LS_PROJECT)
747 {
748 NonlinearImplicitSystem * nl_system = dynamic_cast<NonlinearImplicitSystem *>(
749 &fe_problem.getNonlinearSystemBase(i).system());
750 if (!nl_system)
751 mooseError("You've requested a line search but you must be solving an EigenProblem. "
752 "These two things are not consistent.");
753 PetscNonlinearSolver<Real> * petsc_nonlinear_solver =
754 dynamic_cast<PetscNonlinearSolver<Real> *>(nl_system->nonlinear_solver.get());
755 if (!petsc_nonlinear_solver)
756 mooseError("Currently the MOOSE line searches all use Petsc, so you "
757 "must use Petsc as your non-linear solver.");
758 petsc_nonlinear_solver->linesearch_object =
759 std::make_unique<ComputeLineSearchObjectWrapper>(fe_problem);
760 }
761 }
762 }
763}
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
Moose::LineSearchType _line_search
std::unique_ptr< NonlinearSolver< Number > > nonlinear_solver
std::unique_ptr< ComputeLineSearchObject > linesearch_object
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
LineSearchType
Type of the line search.
Definition MooseTypes.h:980
@ LS_INVALID
means not set
Definition MooseTypes.h:981

Referenced by processSingletonMooseWrappedOptions().

◆ setMFFDTypeFromParams()

void Moose::PetscSupport::setMFFDTypeFromParams ( FEProblemBase fe_problem,
const InputParameters params 
)

Sets the FE problem's matrix-free finite difference type from the input params.

Definition at line 766 of file PetscSupport.C.

767{
768 if (params.isParamValid("mffd_type"))
769 {
770 const auto & mffd_type = params.get<MooseEnum>("mffd_type");
771 for (const auto i : make_range(fe_problem.numNonlinearSystems()))
772 fe_problem.solverParams(i)._mffd_type = Moose::stringToEnum<Moose::MffdType>(mffd_type);
773 }
774}
T stringToEnum(const std::string &s)
MffdType
Type of the matrix-free finite-differencing parameter.
Definition MooseTypes.h:997

Referenced by processSingletonMooseWrappedOptions().

◆ setSinglePetscOption()

void Moose::PetscSupport::setSinglePetscOption ( const std::string &  name,
const std::string &  value = "",
FEProblemBase *const  problem = nullptr 
)

A wrapper function for dealing with different versions of PetscOptionsSetValue.

This is not generally called from MOOSE code, it is instead intended to be called by stuff in MOOSE::PetscSupport.

Definition at line 1158 of file PetscSupport.C.

1161{
1162 static const TIMPI::Communicator comm_world(PETSC_COMM_WORLD);
1163 const TIMPI::Communicator & comm = problem ? problem->comm() : comm_world;
1164 LibmeshPetscCallA(comm.get(),
1165 PetscOptionsSetValue(LIBMESH_PETSC_NULLPTR,
1166 name.c_str(),
1167 value == "" ? LIBMESH_PETSC_NULLPTR : value.c_str()));
1168 // Create a single option data base so that we can use PETSC's internal option checking which
1169 // is case insensitive. This is better than re-implementing case-insensitive checks here in this
1170 // TU
1171 ::PetscOptions single_option;
1172 LibmeshPetscCallA(comm.get(), PetscOptionsCreate(&single_option));
1173 LibmeshPetscCallA(comm.get(),
1174 PetscOptionsSetValue(single_option,
1175 name.c_str(),
1176 value == "" ? LIBMESH_PETSC_NULLPTR : value.c_str()));
1177 auto check_problem = [problem, &name]()
1178 {
1179 if (!problem)
1180 mooseError(
1181 "Setting the option '",
1182 name,
1183 "' requires passing a 'problem' parameter. Contact a developer of your application "
1184 "to have them update their code. If in doubt, reach out to the MOOSE team on Github "
1185 "discussions");
1186 };
1187
1188 // Select vector type from user-passed PETSc options
1189 if (petscOptionsHasName(single_option, "-vec_type"))
1190 {
1191 check_problem();
1192 applyVectorTypeOptions(*problem);
1193 }
1194 // First do a cheap suffix check so unrelated PETSc options do not pay for looping over every
1195 // solver system. Once we know the name looks like a matrix-type option, rely on PETSc's
1196 // option lookup for the actual case-insensitive and prefix-aware matching.
1197 else if (problem && mightBeMatTypeOption(name))
1198 {
1199 errorOnUnprefixedMatTypeOption(single_option, *problem);
1200
1201 for (const auto i : index_range(problem->_solver_systems))
1202 {
1203 const auto & solver_sys_name = problem->_solver_sys_names[i];
1204 if (!petscOptionsHasName(single_option, "-mat_type", solver_sys_name + "_"))
1205 continue;
1206
1207 if (problem->solverParams(i)._type == Moose::ST_JFNK)
1208 mooseError("Setting option '", name, "' is incompatible with a JFNK 'solve_type'");
1209
1210 applyMatrixTypeOptions(*problem, i);
1211 break;
1212 }
1213 }
1214
1215 LibmeshPetscCallA(comm.get(), PetscOptionsDestroy(&single_option));
1216}
std::vector< SolverSystemName > _solver_sys_names
The union of nonlinear and linear system names.
Moose::SolveType _type
@ ST_JFNK
Jacobian-Free Newton Krylov.
Definition MooseTypes.h:899
auto index_range(const T &sizable)

Referenced by Moose::SlepcSupport::clearFreeNonlinearPowerIterations(), MFEMPetscNonlinearSolver::ConstructSolver(), FEProblemBase::FEProblemBase(), petscSetOptionsHelper(), CommandLine::printUsage(), MooseApp::requestCitations(), Moose::SlepcSupport::setEigenSolverOptions(), Moose::SlepcSupport::setFreeNonlinearPowerIterations(), Moose::SlepcSupport::setNewtonPetscOptions(), Moose::SlepcSupport::setNonlinearPowerOptions(), and setSinglePetscOptionIfAppropriate().

◆ setSinglePetscOptionIfAppropriate()

void Moose::PetscSupport::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 simulation type, e.g.

if name is contained within dont_add_these_options

Definition at line 1219 of file PetscSupport.C.

1223{
1224 if (!dont_add_these_options.contains(name))
1225 setSinglePetscOption(name, value, problem);
1226}

Referenced by Moose::SlepcSupport::setEigenProblemOptions(), Moose::SlepcSupport::setSlepcEigenSolverTolerances(), setSolverOptions(), Moose::SlepcSupport::setWhichEigenPairsOptions(), and Moose::SlepcSupport::slepcSetOptions().

◆ setSolverOptions()

void Moose::PetscSupport::setSolverOptions ( const SolverParams solver_params,
const MultiMooseEnum dont_add_these_options 
)

Definition at line 282 of file PetscSupport.C.

283{
284 const auto prefix_with_dash = '-' + solver_params._prefix;
285 // set PETSc options implied by a solve type
286 switch (solver_params._type)
287 {
288 case Moose::ST_PJFNK:
289 setSinglePetscOptionIfAppropriate(dont_add_these_options,
290 prefix_with_dash + "snes_mf_operator");
291 setSinglePetscOptionIfAppropriate(dont_add_these_options,
292 prefix_with_dash + "mat_mffd_type",
293 stringify(solver_params._mffd_type));
294 break;
295
296 case Moose::ST_JFNK:
297 setSinglePetscOptionIfAppropriate(dont_add_these_options, prefix_with_dash + "snes_mf");
298 setSinglePetscOptionIfAppropriate(dont_add_these_options,
299 prefix_with_dash + "mat_mffd_type",
300 stringify(solver_params._mffd_type));
301 break;
302
303 case Moose::ST_NEWTON:
304 break;
305
306 case Moose::ST_FD:
307 setSinglePetscOptionIfAppropriate(dont_add_these_options, prefix_with_dash + "snes_fd");
308 break;
309
310 case Moose::ST_LINEAR:
312 dont_add_these_options, prefix_with_dash + "snes_type", "ksponly");
313 setSinglePetscOptionIfAppropriate(dont_add_these_options,
314 prefix_with_dash + "snes_monitor_cancel");
315 break;
316 }
317
318 Moose::LineSearchType ls_type = solver_params._line_search;
319 if (ls_type == Moose::LS_NONE)
320 ls_type = Moose::LS_BASIC;
321
322 if (ls_type != Moose::LS_DEFAULT && ls_type != Moose::LS_CONTACT && ls_type != Moose::LS_PROJECT)
323 setSinglePetscOptionIfAppropriate(
324 dont_add_these_options, prefix_with_dash + "snes_linesearch_type", stringify(ls_type));
325}
Moose::MffdType _mffd_type
std::string _prefix
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...
@ ST_FD
Use finite differences to compute Jacobian.
Definition MooseTypes.h:901
@ ST_LINEAR
Solving a linear problem.
Definition MooseTypes.h:902
@ ST_NEWTON
Full Newton Solve.
Definition MooseTypes.h:900
@ ST_PJFNK
Preconditioned Jacobian-Free Newton Krylov.
Definition MooseTypes.h:898
@ LS_DEFAULT
Definition MooseTypes.h:982
@ LS_NONE
Definition MooseTypes.h:983
@ LS_PROJECT
Definition MooseTypes.h:987
@ LS_CONTACT
Definition MooseTypes.h:986
@ LS_BASIC
Definition MooseTypes.h:984

Referenced by petscSetOptions(), and petscSetOptions().

◆ setSolveTypeFromParams()

void Moose::PetscSupport::setSolveTypeFromParams ( FEProblemBase fe_problem,
const InputParameters params 
)

Sets the FE problem's solve type from the input params.

Definition at line 721 of file PetscSupport.C.

722{
723 // Note: Options set in the Preconditioner block will override those set in the Executioner block
724 if (params.isParamValid("solve_type") && !params.isParamValid("_use_eigen_value"))
725 {
726 // Extract the solve type
727 const std::string & solve_type = params.get<MooseEnum>("solve_type");
728 for (const auto i : make_range(fe_problem.numNonlinearSystems()))
729 fe_problem.solverParams(i)._type = Moose::stringToEnum<Moose::SolveType>(solve_type);
730 }
731}
SolveType
Type of the solve.
Definition MooseTypes.h:897

Referenced by MoosePreconditioner::MoosePreconditioner(), and processSingletonMooseWrappedOptions().

◆ storePetscOptions()

void Moose::PetscSupport::storePetscOptions ( FEProblemBase fe_problem,
const std::string &  prefix,
const ParallelParamObject param_object 
)

Stores the PETSc options supplied from the parameter object on the problem.

Parameters
fe_problemThe problem on which we will store the parameters
prefixA prefix to apply to all the parameter object's PETSc options. This should either be a single character '-' or a string like "-foo_" where the trailing '_' is required
param_objectThe parameter object potentially holding PETSc options String prefixes may be used to select the system the parameters is applied to

Definition at line 696 of file PetscSupport.C.

699{
700 const auto & params = param_object.parameters();
701 processSingletonMooseWrappedOptions(fe_problem, params);
702
703 // The parameters contained in the Action
704 const auto & petsc_options = params.get<MultiMooseEnum>("petsc_options");
705 const auto & petsc_pair_options =
706 params.get<MooseEnumItem, std::string>("petsc_options_iname", "petsc_options_value");
707
708 // A reference to the PetscOptions object that contains the settings that will be used in the
709 // solve
710 auto & po = fe_problem.getPetscOptions();
711
712 // First process the single petsc options/flags
713 addPetscFlagsToPetscOptions(petsc_options, prefix, param_object, po);
714
715 // Then process the option-value pairs
717 petsc_pair_options, fe_problem.mesh().dimension(), prefix, param_object, po);
718}
virtual MooseMesh & mesh() override
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
Class for containing MooseEnum item information.
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition MooseMesh.C:2986
unsigned int get(unsigned int i) const
Indexing operator Operator to retrieve the id of an item from the MultiMooseEnum.
void processSingletonMooseWrappedOptions(FEProblemBase &fe_problem, const InputParameters &params)
Process some MOOSE-wrapped PETSc options.
void addPetscFlagsToPetscOptions(const MultiMooseEnum &petsc_flags, std::string prefix, const ParallelParamObject &param_object, PetscOptions &petsc_options)
Populate flags in a given PetscOptions object using a vector of input arguments.
void addPetscPairsToPetscOptions(const std::vector< std::pair< MooseEnumItem, std::string > > &petsc_pair_options, const unsigned int mesh_dimension, std::string prefix, const ParallelParamObject &param_object, PetscOptions &petsc_options)
Populate name and value pairs in a given PetscOptions object using vectors of input arguments.

Referenced by FEProblemSolve::FEProblemSolve(), MoosePreconditioner::initialSetup(), MooseStaticCondensationPreconditioner::initialSetup(), and Split::setup().

◆ storePetscOptionsFromParams()

void Moose::PetscSupport::storePetscOptionsFromParams ( FEProblemBase fe_problem,
const InputParameters params 
)

Stores the Petsc flags and pair options fron the input params in the given PetscOptions object.

◆ stringify() [1/2]

std::string Moose::PetscSupport::stringify ( const LineSearchType t)

Definition at line 238 of file PetscSupport.C.

239{
240 switch (t)
241 {
242 case LS_BASIC:
243 return "basic";
244 case LS_DEFAULT:
245 return "default";
246 case LS_NONE:
247 return "none";
248 case LS_SHELL:
249 return "shell";
250 case LS_L2:
251 return "l2";
252 case LS_BT:
253 return "bt";
254 case LS_CP:
255 return "cp";
256 case LS_CONTACT:
257 return "contact";
258 case LS_PROJECT:
259 return "project";
260 case LS_INVALID:
261 mooseError("Invalid LineSearchType");
262 }
263 return "";
264}
@ LS_SHELL
Definition MooseTypes.h:985

Referenced by setSolverOptions().

◆ stringify() [2/2]

std::string Moose::PetscSupport::stringify ( const MffdType t)

Definition at line 267 of file PetscSupport.C.

268{
269 switch (t)
270 {
271 case MFFD_WP:
272 return "wp";
273 case MFFD_DS:
274 return "ds";
275 case MFFD_INVALID:
276 mooseError("Invalid MffdType");
277 }
278 return "";
279}
@ MFFD_WP
Definition MooseTypes.h:999
@ MFFD_INVALID
means not set
Definition MooseTypes.h:998