https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMHypreGMRES.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#ifdef MOOSE_MFEM_ENABLED
11
12#include "MFEMHypreGMRES.h"
13#include "MFEMProblem.h"
14
16
19{
21 params.addClassDescription("Hypre solver for the iterative solution of MFEM equation systems "
22 "using the generalized minimal residual method.");
23
24 params.addParam<mfem::real_t>("l_tol", 1e-5, "Set the relative tolerance.");
25 params.addParam<mfem::real_t>("l_abs_tol", 1e-50, "Set the absolute tolerance.");
26 params.addParam<int>("l_max_its", 10000, "Set the maximum number of iterations.");
27 params.addParam<int>("kdim", 10, "Set the k-dimension.");
28 params.addParam<int>("print_level", 2, "Set the solver verbosity.");
29 params.addParam<MFEMSolverName>("preconditioner", "Optional choice of preconditioner to use.");
30
31 return params;
32}
33
35 : Moose::MFEM::LORLinearSolverBase<mfem::HypreGMRES>(parameters)
36{
38}
39
40void
42{
43 auto solver = std::make_unique<mfem::HypreGMRES>(getMFEMProblem().getComm());
44 SetSolverParameters(*solver);
45 _solver = std::move(solver);
46}
47
48void
49MFEMHypreGMRES::SetSolverParameters(mfem::HypreGMRES & solver)
50{
51 solver.iterative_mode = getParam<bool>("use_initial_guess");
52 solver.SetTol(getParam<mfem::real_t>("l_tol"));
53 solver.SetAbsTol(getParam<mfem::real_t>("l_abs_tol"));
54 solver.SetMaxIter(getParam<int>("l_max_its"));
55 solver.SetKDim(getParam<int>("kdim"));
56 solver.SetPrintLevel(getParam<int>("print_level"));
57}
58
59void
61{
62 if (auto * prec = dynamic_cast<mfem::HypreSolver *>(&_preconditioner->GetSolver()))
63 cast_ref<mfem::HypreGMRES &>(GetSolver()).SetPreconditioner(*prec);
64 else
65 paramError("preconditioner", "MFEMHypreGMRES requires a hypre solver as its preconditioner");
66}
67
68#endif
registerMooseObject("MooseApp", MFEMHypreGMRES)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Wrapper for mfem::HypreGMRES solver.
void ConstructSolver() override
Override in derived classes to construct and set the solver options.
MFEMHypreGMRES(const InputParameters &)
virtual void SetSolverParameters(mfem::HypreGMRES &solver) override
Update the wrapped MFEM solver parameters.
static InputParameters validParams()
virtual void SetPreconditionerImpl() override
Override in solvers that accept a preconditioner.
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition MFEMObject.h:45
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
std::shared_ptr< LinearSolverBase > _preconditioner
Preconditioner to be used for the problem.
mfem::Solver & GetSolver()
Returns the wrapped MFEM solver.
std::unique_ptr< mfem::Solver > _solver
Solver to be used for the problem.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...