https://mooseframework.inl.gov
MFEMLinearSolverBase.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 "MFEMLinearSolverBase.h"
13 #include "MFEMProblem.h"
14 #include "MFEMEigensolverBase.h"
15 
16 namespace Moose::MFEM
17 {
20 {
22  params.addClassDescription(
23  "Base class for defining linear mfem::Solver derived classes for Moose.");
24  return params;
25 }
26 
28  : SolverBase(parameters),
29  _preconditioner{nullptr},
30  _equation_system(getMFEMProblem().getProblemData().eqn_system)
31 {
32 }
33 
34 template <typename T>
35 void
37 {
38  if (isParamSetByUser("preconditioner"))
39  {
40  if (!_preconditioner)
41  {
43  "Moose::MFEM::SolverBase", getParam<MFEMSolverName>("preconditioner"));
44  // Take shared ownership so the preconditioner outlives the solver
45  _preconditioner = std::static_pointer_cast<LinearSolverBase>(pre.shared_from_this());
46  }
47 
48  if (dynamic_cast<const EigensolverBase *>(GetPreconditioner()))
49  mooseError("Eigensolvers cannot be used as preconditioners.");
50 
51  auto & mfem_pre = _preconditioner->GetSolver();
52  if constexpr (std::is_base_of_v<mfem::HypreSolver, T> || std::is_same_v<mfem::HypreAME, T>)
53  if (auto * const hypre_pre = dynamic_cast<mfem::HypreSolver *>(&mfem_pre))
54  solver.SetPreconditioner(*hypre_pre);
55  else
56  mooseError("hypre solver preconditioners must themselves be hypre solvers");
57  else
58  solver.SetPreconditioner(mfem_pre);
59  }
60 }
61 
62 template void LinearSolverBase::SetPreconditioner(mfem::CGSolver &);
63 template void LinearSolverBase::SetPreconditioner(mfem::GMRESSolver &);
64 template void LinearSolverBase::SetPreconditioner(mfem::HypreFGMRES &);
65 template void LinearSolverBase::SetPreconditioner(mfem::HypreGMRES &);
66 template void LinearSolverBase::SetPreconditioner(mfem::HyprePCG &);
67 template void LinearSolverBase::SetPreconditioner(mfem::HypreLOBPCG &);
68 template void LinearSolverBase::SetPreconditioner(mfem::HypreAME &);
69 
70 void
72 {
73  if (_preconditioner)
74  _preconditioner->UpdateEquationSystemContext();
75 }
76 
77 } // namespace Moose::MFEM
78 
79 #endif
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition: MFEMObject.h:45
T & getMFEMObject(const std::string &system, const std::string &name, const THREAD_ID tid=0) const
Retrieve an MFEM object from the warehouse by system and name.
Definition: MFEMProblem.h:418
LinearSolverBase(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
LinearSolverBase * GetPreconditioner()
Returns this solver&#39;s preconditioner.
static InputParameters validParams()
std::shared_ptr< LinearSolverBase > _preconditioner
Preconditioner to be used for the problem.
Base class for linear MFEM solvers and preconditioners.
static InputParameters validParams()
Base class for wrapping mfem::Solver-derived classes.
void SetPreconditioner(T &solver)
Retrieves the preconditioner userobject if present, sets the member pointer to said object if still u...
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
virtual void UpdateEquationSystemContext() override
Update the solver following any changes to the EquationSystem it is responsible for solving...
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...
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
Definition: MooseBase.h:205