https://mooseframework.inl.gov
EigenproblemEquationSystem.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 "MFEMEigensolverBase.h"
14 #include "libmesh/int_range.h"
15 
16 namespace Moose::MFEM
17 {
18 
19 void
21 {
22  _ess_tdof_lists.resize(1);
23  mfem::ParGridFunction & trial_gf = *(_var_ess_constraints.at(0));
24  _global_ess_markers.SetSize(trial_gf.ParFESpace()->GetParMesh()->bdr_attributes.Max());
26  trial_gf.Update();
27  trial_gf = _gfuncs->GetRef(_trial_var_names.at(0));
28  trial_gf.ParFESpace()->GetParMesh()->MarkExternalBoundaries(_global_ess_markers);
29  trial_gf.ParFESpace()->GetEssentialTrueDofs(_global_ess_markers, _ess_tdof_lists.at(0));
30 }
31 
32 void
34 {
35  auto & test_var_name = _test_var_names.at(0);
36  auto blf = _blfs.Get(test_var_name);
37 
38  blf->EliminateEssentialBCDiag(_global_ess_markers, 1.0);
39  blf->Finalize();
40  _jacobian.Reset(blf->ParallelAssemble());
41 }
42 
43 void
45 {
46  mfem::ConstantCoefficient one(1.0);
47  mfem::ParFiniteElementSpace * fespace = _test_pfespaces.at(0);
48  std::unique_ptr<mfem::ParBilinearForm> m = std::make_unique<mfem::ParBilinearForm>(fespace);
49 
50  if (fespace->GetTypicalFE()->GetRangeType() == mfem::FiniteElement::SCALAR)
51  m->AddDomainIntegrator(new mfem::MassIntegrator(one));
52  else
53  m->AddDomainIntegrator(new mfem::VectorFEMassIntegrator(one));
54 
55  m->Assemble();
56  // Shift the eigenvalue corresponding to eliminated dofs to a large value. The BC DoFs on the
57  // stiffness matrix are set to 1 and the mass matrix BC DoFs are set to a small value eps, such
58  // that the eigenvaluesd associate with these DOFs are ~1/eps.
59  m->EliminateEssentialBCDiag(_global_ess_markers, std::numeric_limits<mfem::real_t>::min());
60  m->Finalize();
61  _mass_rhs.Reset(m->ParallelAssemble());
62 }
63 
64 void
66 {
67  mooseAssert(_test_var_names.size() == 1 && (_test_var_names.size() == _trial_var_names.size()) &&
68  (_test_var_names.at(0) == _trial_var_names.at(0)),
69  "Eigensolve is only supported for single-variable, square systems");
70 
71  height = trueX.Size();
72  width = trueX.Size();
76 }
77 
78 void
80 {
81  solver.SetMassMatrix(_mass_rhs);
82  solver.SetOperator(_jacobian);
83 }
84 
85 } // namespace Moose::MFEM
86 
87 #endif
NamedFieldsMap< mfem::ParBilinearForm > _blfs
mfem::OperatorHandle _mass_rhs
The mass operator (e.g. the RHS operator for a generalized eigenproblem)
std::vector< mfem::Array< int > > _ess_tdof_lists
void FormMassMatrix()
Form mass matrix for the eigensolver with Dirichlet BC elimination.
void PrepareEigensolver(EigensolverBase &solver)
Prepare the provided eigensolver.
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
virtual void SetOperator(mfem::OperatorHandle &op) override=0
Sets the operator for the eigensolver in derived classes.
std::vector< std::string > _trial_var_names
Subset of _coupled_var_names of all variables corresponding to gridfunctions with degrees of freedom ...
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...
virtual void SetMassMatrix(mfem::OperatorHandle &mass)=0
Sets the mass matrix for the eigensolver in derived classes.
void FormEigenproblemMatrix()
Form HypreParMatrix matrix operator for the eigensolver with Dirichlet BC elimination.
mfem::OperatorHandle _jacobian
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
std::vector< std::unique_ptr< mfem::ParGridFunction > > _var_ess_constraints
Gridfunctions holding essential constraints from Dirichlet BCs.
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).
T & GetRef(const std::string &field_name) const
Returns a reference to a field.
virtual void ApplyEssentialBCs() override
Mark external boundaries as essential for eigenproblem BC elimination.
Base class for eigensolvers.
auto min(const L &left, const R &right)
void BuildEigenproblemJacobian(mfem::BlockVector &trueX)
Build eigenproblem system, with essential boundary conditions accounted for.
Moose::MFEM::GridFunctions * _gfuncs