10 #ifdef MOOSE_MFEM_ENABLED 26 params.
set<
bool>(
"use_initial_guess",
true) =
true;
31 "Names of PETSc name/value pairs");
32 params.
addParam<std::vector<std::string>>(
33 "petsc_options_value",
34 "Values of PETSc name/value pairs (must correspond with \"petsc_options_iname\")");
36 "petsc_options_prefix",
"",
"PETSc options prefix used for this nonlinear solver.");
41 :
Moose::MFEM::NonlinearSolverBase(parameters)
49 const auto & prefix = getParam<std::string>(
"petsc_options_prefix");
50 const auto normalized_prefix = !prefix.empty() && prefix.back() !=
'_' ? prefix +
"_" : prefix;
54 getParam<MultiMooseEnum>(
"petsc_options"), normalized_prefix, *
this, petsc_options);
56 getParam<MooseEnumItem, std::string>(
"petsc_options_iname",
"petsc_options_value"),
62 for (
const auto & flag : petsc_options.
flags)
64 for (
const auto & option : petsc_options.
pairs)
69 solver->iterative_mode = getParam<bool>(
"use_initial_guess");
70 solver->SetRelTol(getParam<mfem::real_t>(
"rel_tol"));
71 solver->SetAbsTol(getParam<mfem::real_t>(
"abs_tol"));
72 solver->SetMaxIter(getParam<unsigned int>(
"max_its"));
73 solver->SetPrintLevel(getParam<unsigned int>(
"print_level"));
74 solver->SetJacobianType(mfem::Operator::PETSC_MATAIJ);
87 mooseError(
"MFEMPetscNonlinearSolver does not support an external MFEM linear solver. " 88 "Configure PETSc KSP/PC behavior through PETSc options instead.");
MultiMooseEnum getCommonPetscKeys()
A helper function to produce a MultiMooseEnum with commonly used PETSc iname options (keys in key-val...
Moose::PetscSupport::PetscOptions & getPetscOptions()
Retrieve a writable reference the PETSc options (used by PetscSupport)
void addPetscFlagsToPetscOptions(const MultiMooseEnum &petsc_flags, std::string prefix, const ParallelParamObject ¶m_object, PetscOptions &petsc_options)
Populate flags in a given PetscOptions object using a vector of input arguments.
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
mfem::Solver & GetSolver()
Returns the wrapped MFEM solver.
static InputParameters validParams()
void addPetscPairsToPetscOptions(const std::vector< std::pair< MooseEnumItem, std::string >> &petsc_pair_options, const unsigned int mesh_dimension, std::string prefix, const ParallelParamObject ¶m_object, PetscOptions &petsc_options)
Populate name and value pairs in a given PetscOptions object using vectors of input arguments...
A struct for storing the various types of petsc options and values.
MultiMooseEnum flags
Single value PETSc options (flags)
std::unique_ptr< mfem::Solver > _solver
Solver to be used for the problem.
registerMooseObject("MooseApp", MFEMPetscNonlinearSolver)
std::vector< std::pair< std::string, std::string > > pairs
PETSc key-value pairs.
MFEMPetscNonlinearSolver(const InputParameters ¶meters)
MooseObject wrapper for mfem::PetscNonlinearSolver-backed nonlinear solves.
void Mult(const mfem::Vector &rhs, mfem::Vector &x) override
Solve the nonlinear system for the provided right-hand side and solution vector.
MultiMooseEnum getCommonPetscFlags()
A helper function to produce a MultiMooseEnum with commonly used PETSc single options (flags) ...
void SetOperator(const mfem::Operator &op) override
Configure the nonlinear solver with the residual/Jacobian operator.
void ConstructSolver() override
Override in derived classes to construct and set the solver options.
void SetLinearSolver(mfem::Solver &solver) override
Configure the linear solver used inside the nonlinear solve.
MPI_Comm getComm()
Return the MPI communicator associated with this FE problem's mesh.
static InputParameters validParams()
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 mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type...