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 // Precedence for options with the same prefixed name, highest first:
821 // - PETSc command line options (the last occurrence wins)
822 // - Preconditioner pair parameter
823 // - Preconditioner flag parameter
824 // - Executioner pair parameter
825 // - Executioner flag parameter
826 // - Programmatic default, e.g. "-ksp_converged_reason ::failed" from setConvergedReasonFlags
827 // A flag removes the pairs of the same name that were stored before it. PETSc option names are
828 // case-insensitive.
829 const auto upper_option = MooseUtils::toUpper(prefixed_option);
830 po.pairs.erase(std::remove_if(po.pairs.begin(),
831 po.pairs.end(),
832 [&upper_option](const auto & pair)
833 { return MooseUtils::toUpper(pair.first) == upper_option; }),
834 po.pairs.end());
835 }
836}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
std::string toUpper(std::string name)
Convert supplied string to upper case.
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 327 of file PetscSupport.C.

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

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 866 of file PetscSupport.C.

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

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 1245 of file PetscSupport.C.

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

◆ 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 1355 of file PetscSupport.C.

1359{
1360 LibmeshPetscCallA(comm.get(), MatCreate(comm.get(), &mat));
1361 PetscViewer matviewer;
1362 LibmeshPetscCallA(
1363 comm.get(),
1364 PetscViewerBinaryOpen(comm.get(), binary_mat_file.c_str(), FILE_MODE_READ, &matviewer));
1365 for (unsigned int i = 0; i < mat_number_to_load; ++i)
1366 LibmeshPetscCallA(comm.get(), MatLoad(mat, matviewer));
1367 LibmeshPetscCallA(comm.get(), PetscViewerDestroy(&matviewer));
1368
1369 return std::make_unique<PetscMatrix<Number>>(mat, comm);
1370}

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 1329 of file PetscSupport.C.

1330{
1331 auto & petsc_options = fe_problem.getPetscOptions();
1332 for (const auto & flag : getCommonKSPFlags().getNames())
1333 dontAddPetscFlag(flag, petsc_options);
1334 for (const auto & key : getCommonKSPKeys().getNames())
1335 dontAddPetscFlag(key, petsc_options);
1336}
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 1339 of file PetscSupport.C.

1340{
1341 dontAddCommonSNESOptions(fe_problem, "");
1342}
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 1345 of file PetscSupport.C.

1346{
1347 auto & petsc_options = fe_problem.getPetscOptions();
1348 for (const auto & flag : getCommonSNESFlags().getNames())
1349 dontAddPetscFlag("-" + prefix + flag.substr(1), petsc_options);
1350 for (const auto & key : getCommonSNESKeys().getNames())
1351 dontAddPetscFlag("-" + prefix + key.substr(1), petsc_options);
1352}
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 1323 of file PetscSupport.C.

1324{
1325 dontAddPetscFlag("-ksp_converged_reason", fe_problem.getPetscOptions());
1326}

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 1317 of file PetscSupport.C.

1318{
1319 dontAddPetscFlag("-snes_converged_reason", fe_problem.getPetscOptions());
1320}

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 1310 of file PetscSupport.C.

1311{
1312 if (!petsc_options.dont_add_these_options.contains(flag))
1313 petsc_options.dont_add_these_options.setAdditionalValue(flag);
1314}
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 1101 of file PetscSupport.C.

1102{
1103 return MultiMooseEnum(
1104 "-ksp_converged_reason -ksp_gmres_modifiedgramschmidt -ksp_monitor", "", true);
1105}
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 1126 of file PetscSupport.C.

1127{
1128 return MultiMooseEnum("-ksp_atol -ksp_gmres_restart -ksp_max_it -ksp_pc_side -ksp_rtol "
1129 "-ksp_type -sub_ksp_type",
1130 "",
1131 true);
1132}

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 1108 of file PetscSupport.C.

1109{
1110 auto options = MultiMooseEnum("-dm_moose_print_embedding -dm_view", "", true);
1111 options.addValidName(getCommonKSPFlags());
1112 options.addValidName(getCommonSNESFlags());
1113 return options;
1114}

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 1134 of file PetscSupport.C.

1135{
1136 auto options = MultiMooseEnum("-mat_fd_coloring_err -mat_fd_type -mat_mffd_type "
1137 "-pc_asm_overlap -pc_factor_levels "
1138 "-pc_factor_mat_ordering_type -pc_hypre_boomeramg_grid_sweeps_all "
1139 "-pc_hypre_boomeramg_max_iter "
1140 "-pc_hypre_boomeramg_strong_threshold -pc_hypre_type -pc_type "
1141 "-sub_pc_type",
1142 "",
1143 true);
1144 options.addValidName(getCommonKSPKeys());
1145 options.addValidName(getCommonSNESKeys());
1146 return options;
1147}

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 1090 of file PetscSupport.C.

1091{
1092 return MultiMooseEnum(
1093 "-ksp_monitor_snes_lg -snes_ksp_ew -snes_converged_reason "
1094 "-snes_ksp -snes_linesearch_monitor -snes_mf -snes_mf_operator -snes_monitor "
1095 "-snes_test_display -snes_view -snes_monitor_cancel",
1096 "",
1097 true);
1098}

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 1117 of file PetscSupport.C.

1118{
1119 return MultiMooseEnum("-snes_atol -snes_linesearch_type -snes_ls -snes_max_it -snes_rtol "
1120 "-snes_divergence_tolerance -snes_type",
1121 "",
1122 true);
1123}

Referenced by dontAddCommonSNESOptions(), and getCommonPetscKeys().

◆ getPetscKSPNormType()

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

Definition at line 548 of file PetscSupport.C.

549{
550 switch (kspnorm)
551 {
552 case Moose::KSPN_NONE:
553 return KSP_NORM_NONE;
555 return KSP_NORM_PRECONDITIONED;
557 return KSP_NORM_UNPRECONDITIONED;
559 return KSP_NORM_NATURAL;
561 return KSP_NORM_DEFAULT;
562 default:
563 mooseError("Unknown KSP norm type requested.");
564 break;
565 }
566}
@ KSPN_NONE
Definition MooseTypes.h:891
@ KSPN_PRECONDITIONED
Definition MooseTypes.h:892
@ KSPN_UNPRECONDITIONED
Definition MooseTypes.h:893
@ KSPN_DEFAULT
Use whatever we have in PETSc.
Definition MooseTypes.h:895
@ KSPN_NATURAL
Definition MooseTypes.h:894

Referenced by petscSetDefaultKSPNormType().

◆ getPetscPCSide()

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

Definition at line 531 of file PetscSupport.C.

532{
533 switch (pcs)
534 {
535 case Moose::PCS_LEFT:
536 return PC_LEFT;
537 case Moose::PCS_RIGHT:
538 return PC_RIGHT;
540 return PC_SYMMETRIC;
541 default:
542 mooseError("Unknown PC side requested.");
543 break;
544 }
545}
@ PCS_LEFT
Definition MooseTypes.h:880
@ PCS_SYMMETRIC
Definition MooseTypes.h:882
@ PCS_RIGHT
Definition MooseTypes.h:881

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 1049 of file PetscSupport.C.

1050{
1051 return {"default", "shell", "none", "basic", "l2", "bt", "cp"};
1052}

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 1055 of file PetscSupport.C.

1056{
1058
1059 MooseEnum solve_type("PJFNK JFNK NEWTON FD LINEAR");
1060 params.addParam<MooseEnum>("solve_type",
1061 solve_type,
1062 "PJFNK: Preconditioned Jacobian-Free Newton Krylov "
1063 "JFNK: Jacobian-Free Newton Krylov "
1064 "NEWTON: Full Newton Solve "
1065 "FD: Use finite differences to compute Jacobian "
1066 "LINEAR: Solving a linear problem");
1067
1068 MooseEnum mffd_type("wp ds", "wp");
1069 params.addParam<MooseEnum>("mffd_type",
1070 mffd_type,
1071 "Specifies the finite differencing type for "
1072 "Jacobian-free solve types. Note that the "
1073 "default is wp (for Walker and Pernice).");
1074
1075 params.addParam<MultiMooseEnum>(
1076 "petsc_options", getCommonPetscFlags(), "Singleton PETSc options");
1077 params.addParam<MultiMooseEnum>(
1078 "petsc_options_iname", getCommonPetscKeys(), "Names of PETSc name/value pairs");
1079 params.addParam<std::vector<std::string>>(
1080 "petsc_options_value",
1081 "Values of PETSc name/value pairs (must correspond with \"petsc_options_iname\"");
1082 params.addParamNamesToGroup("solve_type petsc_options petsc_options_iname petsc_options_value "
1083 "mffd_type",
1084 "PETSc");
1085
1086 return params;
1087}
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 1150 of file PetscSupport.C.

1151{
1152 const PetscOptions & petsc = fe_problem.getPetscOptions();
1153
1154 int argc;
1155 char ** args;
1156 LibmeshPetscCallA(fe_problem.comm().get(), PetscGetArgs(&argc, &args));
1157
1158 std::vector<std::string> cml_arg;
1159 for (int i = 0; i < argc; i++)
1160 cml_arg.push_back(args[i]);
1161
1162 if (MooseUtils::findPair(petsc.pairs, petsc.pairs.begin(), MooseUtils::Any, "vinewtonssls") ==
1163 petsc.pairs.end() &&
1164 MooseUtils::findPair(petsc.pairs, petsc.pairs.begin(), MooseUtils::Any, "vinewtonrsls") ==
1165 petsc.pairs.end() &&
1166 std::find(cml_arg.begin(), cml_arg.end(), "vinewtonssls") == cml_arg.end() &&
1167 std::find(cml_arg.begin(), cml_arg.end(), "vinewtonrsls") == cml_arg.end())
1168 return false;
1169
1170 return true;
1171}
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 481 of file PetscSupport.C.

483{
485 FEProblemBase & problem = *static_cast<FEProblemBase *>(ctx);
486
487 // execute objects that may be used in convergence check
488 // Right now, setting objects to execute on this flag would be ignored except in the
489 // linear-system-only use case.
491
492 // perform the convergence check
495 {
498 }
499 else
500 {
501 auto & convergence = problem.getConvergence(
503 status = convergence.checkConvergence(it);
504 }
505
506 // convert convergence status to PETSc converged reason
507 switch (status)
508 {
510 *reason = KSP_CONVERGED_ITERATING;
511 break;
512
513 // TODO: find a KSP code that works better for this case
515#if PETSC_VERSION_LESS_THAN(3, 24, 0)
516 *reason = KSP_CONVERGED_RTOL_NORMAL;
517#else
518 *reason = KSP_CONVERGED_RTOL_NORMAL_EQUATIONS;
519#endif
520 break;
521
523 *reason = KSP_DIVERGED_DTOL;
524 break;
525 }
526
527 PetscFunctionReturn(PETSC_SUCCESS);
528}
const ExecFlagType EXEC_LINEAR_CONVERGENCE
Definition Moose.C:33
PetscFunctionReturn(PETSC_SUCCESS)
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.

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 434 of file PetscSupport.C.

441{
443 FEProblemBase & problem = *static_cast<FEProblemBase *>(ctx);
444
445 // execute objects that may be used in convergence check
447
448 // perform the convergence check
451 {
454 }
455 else
456 {
457 auto & convergence = problem.currentNonlinearSystem().convergence();
458 status = convergence.checkConvergence(it);
459 }
460
461 // convert convergence status to PETSc converged reason
462 switch (status)
463 {
465 *reason = SNES_CONVERGED_ITERATING;
466 break;
467
469 *reason = SNES_CONVERGED_USER;
470 break;
471
473 *reason = SNES_DIVERGED_USER;
474 break;
475 }
476
477 PetscFunctionReturn(PETSC_SUCCESS);
478}
const ExecFlagType EXEC_NONLINEAR_CONVERGENCE
Definition Moose.C:35
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()
Convergence & convergence()
Retrieves the associated Convergence object.

Referenced by petscSetDefaults().

◆ petscSetDefaultKSPNormType()

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

Set norm type.

Definition at line 569 of file PetscSupport.C.

570{
571 for (const auto i : make_range(problem.numSolverSystems()))
572 {
573 SolverSystem & sys = problem.getSolverSystem(i);
574 LibmeshPetscCallA(problem.comm().get(),
575 KSPSetNormType(ksp, getPetscKSPNormType(sys.getMooseKSPNormType())));
576 }
577}
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 580 of file PetscSupport.C.

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

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

◆ petscSetDefaults()

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

Sets the default options for PETSc.

Definition at line 615 of file PetscSupport.C.

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

594{
595 auto & es = problem.es();
596
597 PetscReal rtol = es.parameters.get<Real>("linear solver tolerance");
598 PetscReal atol = es.parameters.get<Real>("linear solver absolute tolerance");
599
600 // MOOSE defaults this to -1 for some dumb reason
601 if (atol < 0)
602 atol = 1e-50;
603
604 PetscReal maxits = es.parameters.get<unsigned int>("linear solver maximum iterations");
605
606 // 1e100 is because we don't use divtol currently
607 LibmeshPetscCallA(problem.comm().get(), KSPSetTolerances(ksp, rtol, atol, 1e100, maxits));
608
609 petscSetDefaultPCSide(problem, ksp);
610
611 petscSetDefaultKSPNormType(problem, ksp);
612}
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.

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 396 of file PetscSupport.C.

399{
400 PetscCallAbort(PETSC_COMM_WORLD, PetscOptionsClear(LIBMESH_PETSC_NULLPTR));
401 setSolverOptions(solver_params, po.dont_add_these_options);
402 petscSetOptionsHelper(po, problem);
403}
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 406 of file PetscSupport.C.

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

◆ petscSetOptionsHelper()

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

Definition at line 376 of file PetscSupport.C.

377{
378 // Add any additional options specified in the input file
379 for (const auto & flag : po.flags)
380 // Need to use name method here to pass a str instead of an EnumItem because
381 // we don't care if the id attributes match
382 if (!po.dont_add_these_options.contains(flag.name()) ||
383 po.user_set_options.contains(flag.name()))
384 setSinglePetscOption(flag.rawName().c_str());
385
386 // Add option pairs
387 for (auto & option : po.pairs)
388 if (!po.dont_add_these_options.contains(option.first) ||
389 po.user_set_options.contains(option.first))
390 setSinglePetscOption(option.first, option.second, problem);
391
393}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
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.

Referenced by petscSetOptions(), and petscSetOptions().

◆ petscSetupOutput()

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

Definition at line 417 of file PetscSupport.C.

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

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 680 of file PetscSupport.C.

681{
682 setSolveTypeFromParams(fe_problem, params);
683 setLineSearchFromParams(fe_problem, params);
684 setMFFDTypeFromParams(fe_problem, params);
685}
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 1373 of file PetscSupport.C.

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

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 839 of file PetscSupport.C.

840{
841 prefix.insert(prefix.begin(), '-');
842 checkPrefix(prefix);
843 libmesh_ignore(fe_problem); // avoid unused warnings for old PETSc
844
845#if !PETSC_VERSION_LESS_THAN(3, 14, 0)
846 // the boolean in these pairs denote whether the user has specified any of the reason flags in the
847 // input file
848 std::array<std::string, 2> reason_flags = {{"snes_converged_reason", "ksp_converged_reason"}};
849
850 auto & po = fe_problem.getPetscOptions();
851
852 for (const auto & reason_flag : reason_flags)
853 {
854 const auto full_flag = prefix + reason_flag;
855 if (!po.flags.isValueSet(full_flag) && !po.dont_add_these_options.contains(full_flag) &&
856 (std::find_if(po.pairs.begin(),
857 po.pairs.end(),
858 [&full_flag](auto & pair)
859 { return pair.first == (full_flag); }) == po.pairs.end()))
860 po.pairs.emplace_back(full_flag, "::failed");
861 }
862#endif
863}

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, cast_ref<libMesh::PetscLinearSolver<T> &>(linear_solver).ksp());
121}
void petscSetKSPDefaults(FEProblemBase &problem, KSP ksp)
Set the default options for a KSP.

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 733 of file PetscSupport.C.

734{
735 // Note: Options set in the Preconditioner block will override those set in the Executioner block
736 if (params.isParamValid("line_search"))
737 {
738 const auto & line_search = params.get<MooseEnum>("line_search");
739 for (const auto i : make_range(fe_problem.numNonlinearSystems()))
740 if (fe_problem.solverParams(i)._line_search == Moose::LS_INVALID || line_search != "default")
741 {
742 Moose::LineSearchType enum_line_search =
743 Moose::stringToEnum<Moose::LineSearchType>(line_search);
744 fe_problem.solverParams(i)._line_search = enum_line_search;
745 if (enum_line_search == LS_CONTACT || enum_line_search == LS_PROJECT)
746 {
747 NonlinearImplicitSystem * nl_system = dynamic_cast<NonlinearImplicitSystem *>(
748 &fe_problem.getNonlinearSystemBase(i).system());
749 if (!nl_system)
750 mooseError("You've requested a line search but you must be solving an EigenProblem. "
751 "These two things are not consistent.");
752 libMesh::PetscNonlinearSolver<Real> * petsc_nonlinear_solver =
754 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< 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:985
@ LS_INVALID
means not set
Definition MooseTypes.h:986

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.

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 1174 of file PetscSupport.C.

1177{
1178 static const TIMPI::Communicator comm_world(PETSC_COMM_WORLD);
1179 const TIMPI::Communicator & comm = problem ? problem->comm() : comm_world;
1180 LibmeshPetscCallA(comm.get(),
1181 PetscOptionsSetValue(LIBMESH_PETSC_NULLPTR,
1182 name.c_str(),
1183 value == "" ? LIBMESH_PETSC_NULLPTR : value.c_str()));
1184 // Create a single option data base so that we can use PETSC's internal option checking which
1185 // is case insensitive. This is better than re-implementing case-insensitive checks here in this
1186 // TU
1187 ::PetscOptions single_option;
1188 LibmeshPetscCallA(comm.get(), PetscOptionsCreate(&single_option));
1189 LibmeshPetscCallA(comm.get(),
1190 PetscOptionsSetValue(single_option,
1191 name.c_str(),
1192 value == "" ? LIBMESH_PETSC_NULLPTR : value.c_str()));
1193 auto check_problem = [problem, &name]()
1194 {
1195 if (!problem)
1196 mooseError(
1197 "Setting the option '",
1198 name,
1199 "' requires passing a 'problem' parameter. Contact a developer of your application "
1200 "to have them update their code. If in doubt, reach out to the MOOSE team on Github "
1201 "discussions");
1202 };
1203
1204 // Select vector type from user-passed PETSc options
1205 if (petscOptionsHasName(single_option, "-vec_type"))
1206 {
1207 check_problem();
1208 applyVectorTypeOptions(*problem);
1209 }
1210 // First do a cheap suffix check so unrelated PETSc options do not pay for looping over every
1211 // solver system. Once we know the name looks like a matrix-type option, rely on PETSc's
1212 // option lookup for the actual case-insensitive and prefix-aware matching.
1213 else if (problem && mightBeMatTypeOption(name))
1214 {
1215 errorOnUnprefixedMatTypeOption(single_option, *problem);
1216
1217 for (const auto i : index_range(problem->_solver_systems))
1218 {
1219 const auto & solver_sys_name = problem->_solver_sys_names[i];
1220 if (!petscOptionsHasName(single_option, "-mat_type", solver_sys_name + "_"))
1221 continue;
1222
1223 if (problem->solverParams(i)._type == Moose::ST_JFNK)
1224 mooseError("Setting option '", name, "' is incompatible with a JFNK 'solve_type'");
1225
1226 applyMatrixTypeOptions(*problem, i);
1227 break;
1228 }
1229 }
1230
1231 LibmeshPetscCallA(comm.get(), PetscOptionsDestroy(&single_option));
1232}
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:904

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 1235 of file PetscSupport.C.

1239{
1240 if (!dont_add_these_options.contains(name))
1241 setSinglePetscOption(name, value, problem);
1242}

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 281 of file PetscSupport.C.

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

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 720 of file PetscSupport.C.

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

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 695 of file PetscSupport.C.

698{
699 const auto & params = param_object.parameters();
700 processSingletonMooseWrappedOptions(fe_problem, params);
701
702 // The parameters contained in the Action
703 const auto & petsc_options = params.get<MultiMooseEnum>("petsc_options");
704 const auto & petsc_pair_options =
705 params.get<MooseEnumItem, std::string>("petsc_options_iname", "petsc_options_value");
706
707 // A reference to the PetscOptions object that contains the settings that will be used in the
708 // solve
709 auto & po = fe_problem.getPetscOptions();
710
711 // First process the single petsc options/flags
712 addPetscFlagsToPetscOptions(petsc_options, prefix, param_object, po);
713
714 // Then process the option-value pairs
716 petsc_pair_options, fe_problem.mesh().dimension(), prefix, param_object, po);
717}
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:2993
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 237 of file PetscSupport.C.

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

Referenced by setSolverOptions().

◆ stringify() [2/2]

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

Definition at line 266 of file PetscSupport.C.

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