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)
68 std::make_unique<mfem::PetscNonlinearSolver>(
getMFEMProblem().getComm(), normalized_prefix);
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);
81 mooseError(
"MFEMPetscNonlinearSolver does not support an external MFEM linear solver. "
82 "Configure PETSc KSP/PC behavior through PETSc options instead.");
registerMooseObject("MooseApp", MFEMPetscNonlinearSolver)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Moose::PetscSupport::PetscOptions & getPetscOptions()
Retrieve a writable reference the PETSc options (used by PetscSupport)
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
MooseObject wrapper for mfem::PetscNonlinearSolver-backed nonlinear solves.
void SetLinearSolver(mfem::Solver &solver) override
Configure the linear solver used inside the nonlinear solve.
void ConstructSolver() override
Override in derived classes to construct and set the solver options.
MFEMPetscNonlinearSolver(const InputParameters ¶meters)
static InputParameters validParams()
static InputParameters validParams()
std::unique_ptr< mfem::Solver > _solver
Solver to be used for the problem.
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.
MultiMooseEnum flags
Single value PETSc options (flags)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
MultiMooseEnum getCommonPetscFlags()
A helper function to produce a MultiMooseEnum with commonly used PETSc single options (flags)
void setSinglePetscOption(const std::string &name, const std::string &value="", FEProblemBase *const problem=nullptr)
A wrapper function for dealing with different versions of PetscOptionsSetValue.
MultiMooseEnum getCommonPetscKeys()
A helper function to produce a MultiMooseEnum with commonly used PETSc iname options (keys in key-val...
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.
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.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...