https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
13#include "MFEMProblem.h"
14#include "MFEMEigensolverBase.h"
15
16namespace Moose::MFEM
17{
20{
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
34template <typename T>
35void
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
62template void LinearSolverBase::SetPreconditioner(mfem::CGSolver &);
63template void LinearSolverBase::SetPreconditioner(mfem::GMRESSolver &);
64template void LinearSolverBase::SetPreconditioner(mfem::HypreFGMRES &);
65template void LinearSolverBase::SetPreconditioner(mfem::HypreGMRES &);
66template void LinearSolverBase::SetPreconditioner(mfem::HyprePCG &);
67template void LinearSolverBase::SetPreconditioner(mfem::HypreLOBPCG &);
68template void LinearSolverBase::SetPreconditioner(mfem::HypreAME &);
69
70void
72{
74 _preconditioner->UpdateEquationSystemContext();
75}
76
77} // namespace Moose::MFEM
78
79#endif
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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.
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
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
Base class for eigensolvers.
Base class for linear MFEM solvers and preconditioners.
virtual void UpdateEquationSystemContext() override
Update the solver following any changes to the EquationSystem it is responsible for solving.
LinearSolverBase * GetPreconditioner()
Returns this solver's preconditioner.
std::shared_ptr< LinearSolverBase > _preconditioner
Preconditioner to be used for the problem.
static InputParameters validParams()
void SetPreconditioner(T &solver)
Retrieves the preconditioner userobject if present, sets the member pointer to said object if still u...
LinearSolverBase(const InputParameters &parameters)
Base class for wrapping mfem::Solver-derived classes.
static InputParameters validParams()
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).