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 params.addParam<MFEMWeakFormName>(
25 "weak_form",
26 "",
27 "Name of the weak form in the WeakForms block whose equation system provides context for "
28 "this solver. May be omitted only if the problem has a single weak form, whose equation "
29 "system is then used.");
30 return params;
31}
32
34 : SolverBase(parameters), _preconditioner{nullptr}
35{
36 const auto & weak_form_name = getParam<MFEMWeakFormName>("weak_form");
37 if (!weak_form_name.empty() && !getMFEMProblem().getProblemData().eqn_systems.Has(weak_form_name))
38 paramError("weak_form",
39 "No weak form named '",
40 weak_form_name,
41 "' has been added to the problem. Weak forms are added in the 'WeakForms' block.");
42
44}
45
46void
47LinearSolverBase::SetPreconditioner(const mfem::Operator & op)
48{
49 if (!isParamSetByUser("preconditioner"))
50 return;
51
53 "Moose::MFEM::SolverBase", getParam<MFEMSolverName>("preconditioner"));
54 if (dynamic_cast<const EigensolverBase *>(&pre))
55 paramError("preconditioner", "Eigensolvers cannot be used as preconditioners.");
56 // Take shared ownership so the preconditioner outlives the solver
57 _preconditioner = std::static_pointer_cast<LinearSolverBase>(pre.getSharedPtr());
58 // SetOperatorImpl() may build the preconditioner (e.g. MatrixFreeAMS) for SetPreconditionerImpl()
59 _preconditioner->SetOperator(op);
61}
62
63void
64LinearSolverBase::SetOperator(const mfem::Operator & op)
65{
66 // May replace the wrapped solver (e.g. LOR), so this must precede SetPreconditioner()
68
70
71 // SetOperatorImpl() calls SetOperator() on the wrapped mfem solver. In most cases, this will
72 // redundantly reset the operator on the preconditioner. For others it requires the preconditioner
73 // be already set (e.g. AME), thus why it follows SetPreconditioner().
75}
76} // namespace Moose::MFEM
77
78#endif
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.
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.
std::shared_ptr< Moose::MFEM::EquationSystem > getEquationSystem(const std::string &weak_form_name="") const
Return the EquationSystem built by the weak form named weak_form_name.
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
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
Base class for eigensolvers.
Base class for linear MFEM solvers and preconditioners.
std::shared_ptr< EquationSystem > _equation_system
Pointer to EquationSystem used for problem-specific solver setup.
virtual void SetPreconditionerImpl()
Override in solvers that accept a preconditioner.
std::shared_ptr< LinearSolverBase > _preconditioner
Preconditioner to be used for the problem.
static InputParameters validParams()
void SetPreconditioner(const mfem::Operator &op)
Retrieves the preconditioner, sets the operator on it, and sets it on the wrapped solver.
LinearSolverBase(const InputParameters &parameters)
virtual void SetOperator(const mfem::Operator &op) override
Updates the solver and any associated weak form context at the operator level.
Base class for wrapping mfem::Solver-derived classes.
virtual void UpdateEquationSystemContext()
Update the solver following any changes to the weak form it is responsible for solving.
static InputParameters validParams()
virtual void SetOperatorImpl(const mfem::Operator &op)
Updates the solver at the operator level.
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).