10#ifdef MOOSE_MFEM_ENABLED
14#include "libmesh/int_range.h"
21 std::shared_ptr<MFEMEssentialConstraint> constraint)
25 "' cannot be used in an MFEM eigenproblem: essential constraints on interior "
26 "degrees of freedom are not supported by the eigenproblem equation system.");
48 mfem::Vector ess_values;
49 trial_gf.GetTrueDofs(ess_values);
51 mfem::real_t max_ess_value =
52 mfem::GlobalLpNorm(mfem::infinity(), ess_values.Normlinf(), trial_gf.ParFESpace()->GetComm());
54 if (max_ess_value > 10 * std::numeric_limits<mfem::real_t>::epsilon())
55 mooseError(
"Essential boundary conditions on variable '",
57 "' prescribe a nonzero value. "
58 "An eigenproblem is homogeneous so only zero-valued essential boundary conditions "
59 "are meaningful. Set the boundary coefficient to zero.");
77 std::unique_ptr<mfem::ParBilinearForm> m = std::make_unique<mfem::ParBilinearForm>(fespace);
79 if (fespace->GetTypicalFE()->GetRangeType() == mfem::FiniteElement::SCALAR)
82 if (std::holds_alternative<mfem::MatrixCoefficient *>(rhs_coefficient))
84 const auto & mat_coef = *std::get<mfem::MatrixCoefficient *>(rhs_coefficient);
85 if (mat_coef.GetHeight() != fespace->GetVDim() || mat_coef.GetWidth() != fespace->GetVDim())
86 mooseError(
"A matrix rhs_coefficient on an H1 or L2 finite element space must be ",
90 " to match the number of components of the space, but it is ",
96 auto *
const integ = std::visit(
97 [](
auto * coef) {
return new mfem::VectorMassIntegrator(*coef); }, rhs_coefficient);
99 integ->SetVDim(fespace->GetVDim());
100 m->AddDomainIntegrator(integ);
103 m->AddDomainIntegrator(std::visit(
104 [](
auto * coef) {
return new mfem::VectorFEMassIntegrator(*coef); }, rhs_coefficient));
110 m->EliminateEssentialBCDiag(
_ess_bdr_markers.at(0), std::numeric_limits<mfem::real_t>::epsilon());
121 "Eigensolve is only supported for single-variable, square systems");
123 height = trueX.Size();
124 width = trueX.Size();
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
void FormMassMatrix(EigenRHSCoefficient rhs_coefficient)
Form mass matrix for the eigensolver with Dirichlet BC elimination.
void AddEssentialConstraint(std::shared_ptr< MFEMEssentialConstraint > constraint) override
Eigenproblems mark external boundaries as essential and do not consult the constraint map,...
virtual void CheckProblemIsHomogeneous()
Verify that the problem is homogeneous (all Dirichlet BCs are zero)
mfem::OperatorHandle _mass_rhs
The mass operator (e.g. the RHS operator for a generalized eigenproblem)
void PrepareEigensolver(EigensolverBase &solver)
Prepare the provided eigensolver.
void BuildEigenproblemJacobian(mfem::BlockVector &trueX, EigenRHSCoefficient rhs_coefficient)
Build eigenproblem system, with essential boundary conditions accounted for.
void FormEigenproblemMatrix()
Form HypreParMatrix matrix operator for the eigensolver with Dirichlet BC elimination.
virtual void ApplyEssentialConstraints() override
Mark external boundaries as essential for eigenproblem BC elimination.
Base class for eigensolvers.
virtual void SetMassMatrix(mfem::Operator &mass)=0
Sets the mass matrix for the eigensolver in derived classes.
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
std::vector< mfem::Array< int > > _ess_bdr_markers
virtual void ApplyEssentialConstraint(const std::string &var_name, mfem::ParGridFunction &trial_gf, mfem::Array< int > &global_bdr_markers, mfem::Array< int > &global_ess_tdofs)
Apply essential constraints associated with var_name to set true DoFs of trial_gf,...
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
std::vector< mfem::Array< int > > _ess_tdof_lists
NamedFieldsMap< mfem::ParBilinearForm > _blfs
mfem::OperatorHandle _jacobian
std::vector< std::string > _trial_var_names
Subset of _coupled_var_names of all variables corresponding to gridfunctions with degrees of freedom ...
std::vector< std::unique_ptr< mfem::ParGridFunction > > _var_ess_constraints
Gridfunctions holding essential constraints from Dirichlet BCs.
Moose::MFEM::GridFunctions * _gfuncs
virtual void SetOperator(const mfem::Operator &op) override
Updates the solver and any associated weak form context at the operator level.
T * Get(const std::string &field_name) const
Returns a non-owning pointer to the field. This is guaranteed to return a non-null pointer.
T & GetRef(const std::string &field_name) const
Returns a reference to a field.
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).
std::variant< mfem::Coefficient *, mfem::MatrixCoefficient * > EigenRHSCoefficient
Scalar or matrix coefficient scaling the eigenproblem right-hand side.