https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Moose::MFEM::EquationSystem Class Reference

Owns the weak-form mathematics of a MOOSE MFEM problem. More...

#include <EquationSystem.h>

Inheritance diagram for Moose::MFEM::EquationSystem:
[legend]

Public Member Functions

 EquationSystem ()=default
 
 ~EquationSystem () override
 
virtual void AddKernel (std::shared_ptr< MFEMKernel > kernel)
 Add kernels.
 
virtual void AddIntegratedBC (std::shared_ptr< MFEMIntegratedBC > kernel)
 
virtual void AddEssentialBC (std::shared_ptr< MFEMEssentialBC > bc)
 Add BC associated with essentially constrained DoFs on boundaries.
 
virtual void Init (GridFunctions &gridfunctions, ComplexGridFunctions &cmplx_gridfunctions, mfem::AssemblyLevel assembly_level)
 Initialise.
 
void FormSystem (mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
 Build all weak-form components via BuildEquationSystem(), form the constrained linear part of the system, and populate the true-DoF vectors used by the solve.
 
void Mult (const mfem::Vector &u, mfem::Vector &residual) const override
 Compute residual y = Mu.
 
virtual void ComputeNonlinearResidual (const mfem::Vector &u, mfem::Vector &residual) const
 Compute the contribution to the residual from nonlinear forms only.
 
mfem::Operator & GetGradient (const mfem::Vector &u) const override
 Get Jacobian at the provided vector of true DoFs of trial variables.
 
mfem::OperatorHandle & GetLinearOperator () const
 Get operator handle for linear component of system operator.
 
virtual void SetTrialVariablesFromTrueVectors (const mfem::BlockVector &trueX) const
 Update variable from solution vector after solve.
 
void SetGradientRequired (bool requires_gradient)
 Set whether an external object (such as a nonlinear solver) requires Jacobian information for this EquationSystem.
 
void SetCoefficientManager (CoefficientManager &coefficients)
 Set the coefficient manager to notify when trial variables are updated, so that stored projections of solution-dependent coefficients are invalidated.
 
const std::vector< std::string > & GetTrialVarNames () const
 
const std::vector< std::string > & GetTestVarNames () const
 
const mfem::Array< int > & GetBlockOffsets () const
 Getter for block true offsets associated with the EquationSystem operator.
 
mfem::ParBilinearForm & GetBilinearForm (const std::string &test_var_name)
 
mfem::ParGridFunction & GetGridFunction (const std::string &trial_var_name)
 
const mfem::Vector & GetLinearizationPoint () const
 The true-DoF vector used for the most recent Jacobian linearization.
 
std::shared_ptr< mfem::ParBilinearForm > BuildBilinearFormForFESpace (const std::string &var_name, mfem::ParFiniteElementSpace &fespace, mfem::AssemblyLevel assembly_level)
 Build a fresh ParBilinearForm on the given FESpace using the same kernels as the main system's bilinear form for var_name.
 
std::shared_ptr< mfem::ParNonlinearForm > BuildNonlinearFormForFESpace (const std::string &var_name, mfem::ParFiniteElementSpace &fespace, mfem::AssemblyLevel assembly_level)
 Build a fresh ParNonlinearForm on the given FESpace using the same kernels as the main system's nonlinear form for var_name.
 
mfem::Array< int > & GetEssentialBoundaryMarkers (const std::string &var_name)
 Return the essential boundary attribute marker array for a given trial variable.
 
virtual bool IsComplex () const
 
virtual bool IsEigen () const
 
virtual bool IsTimeDependent () const
 
bool IsMultivariate () const
 
bool IsNonlinear () const
 
virtual void BuildEquationSystem ()
 Build all forms comprising this EquationSystem.
 

Protected Member Functions

virtual void AddCoupledVariableNameIfMissing (const std::string &coupled_var_name)
 Add coupled variable to EquationSystem.
 
virtual void AddEliminatedVariableNameIfMissing (const std::string &eliminated_var_name)
 Add eliminated variable to EquationSystem.
 
virtual void AddTestVariableNameIfMissing (const std::string &test_var_name)
 Add test variable to EquationSystem.
 
virtual void SetTrialVariableNames ()
 Set trial variable names from subset of coupled variables that have an associated test variable.
 
void DeleteHBlocks ()
 Deletes the HypreParMatrix associated with any pointer stored in _h_blocks, and then proceeds to delete all dynamically allocated memory for _h_blocks itself, resetting all dimensions to zero.
 
void DeleteJacobianBlocks ()
 Deletes the HypreParMatrix associated with any pointer stored in _jacobian_blocks, and then proceeds to delete all dynamically allocated memory for _jacobian_blocks itself, resetting all dimensions to zero.
 
bool VectorContainsName (const std::vector< std::string > &the_vector, const std::string &name) const
 
virtual void ApplyEssentialBC (const std::string &var_name, mfem::ParGridFunction &trial_gf, mfem::Array< int > &global_ess_markers)
 Apply essential BC(s) associated with var_name to set true DoFs of trial_gf and update markers of all essential boundaries.
 
virtual void ApplyEssentialBCs ()
 Update all essentially constrained true DoF markers and values on boundaries.
 
virtual void EliminateCoupledVariables ()
 Perform trivial eliminations of coupled variables lacking corresponding test variables.
 
virtual void BuildLinearForms ()
 Build linear forms and eliminate constrained DoFs.
 
virtual void BuildNonlinearForms ()
 Build non-linear action forms.
 
virtual void BuildBilinearForms ()
 Build bilinear forms (diagonal Jacobian contributions)
 
virtual void BuildMixedBilinearForms ()
 Build mixed bilinear forms (off-diagonal Jacobian contributions)
 
virtual void FormLinearSystem (mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
 Form linear components of system based on on- and off-diagonal bilinear form contributions, populate solution and RHS vectors of true DoFs, and apply constraints.
 
virtual void FormSystemOperator (mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
 Form matrix-free representation of linear components of system operator.
 
virtual void FormSystemMatrix (mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
 Form matrix representation of linear components of system operator as a HypreParMatrix.
 
void FormJacobianMatrix (const mfem::Vector &u)
 Compute Jacobian matrix at the provided vector of true DoFs of trial variables.
 
template<class FormType >
void ApplyDomainBLFIntegrators (const std::string &trial_var_name, const std::string &test_var_name, std::shared_ptr< FormType > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > &kernels_map, std::optional< mfem::real_t > scale_factor=std::nullopt)
 Template method for applying BilinearFormIntegrators on domains from kernels to a BilinearForm, or MixedBilinearForm.
 
void ApplyDomainLFIntegrators (const std::string &test_var_name, std::shared_ptr< mfem::ParLinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > &kernels_map)
 Apply domain LinearFormIntegrators from kernels to the linear form associated with the supplied test variable.
 
void ApplyDomainNLFIntegrators (const std::string &test_var_name, std::shared_ptr< mfem::ParNonlinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > &kernels_map, std::optional< mfem::real_t > scale_factor=std::nullopt)
 Apply domain NonlinearFormIntegrators from kernels to the nonlinear form associated with the supplied test variable.
 
template<class FormType >
void ApplyBoundaryBLFIntegrators (const std::string &trial_var_name, const std::string &test_var_name, std::shared_ptr< FormType > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > &integrated_bc_map, std::optional< mfem::real_t > scale_factor=std::nullopt)
 Template method for applying BilinearFormIntegrators on boundaries from integrated boundary conditions to a BilinearForm, or MixedBilinearForm.
 
void ApplyBoundaryLFIntegrators (const std::string &test_var_name, std::shared_ptr< mfem::ParLinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > &integrated_bc_map)
 Apply boundary LinearFormIntegrators from integrated boundary conditions to the linear form associated with the supplied test variable.
 
void ApplyBoundaryNLFIntegrators (const std::string &test_var_name, std::shared_ptr< mfem::ParNonlinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > &integrated_bc_map, std::optional< mfem::real_t > scale_factor=std::nullopt)
 Apply boundary NonlinearFormIntegrators from integrated boundary conditions to the nonlinear form associated with the supplied test variable.
 

Protected Attributes

std::vector< std::string > _coupled_var_names
 Names of all trial variables of kernels and boundary conditions added to this EquationSystem.
 
std::vector< std::string > _trial_var_names
 Subset of _coupled_var_names of all variables corresponding to gridfunctions with degrees of freedom that comprise the state vector of this EquationSystem.
 
std::vector< std::string > _eliminated_var_names
 Names of all coupled variables without a corresponding test variable.
 
Moose::MFEM::GridFunctions _eliminated_variables
 Pointers to coupled variables not part of the reduced EquationSystem.
 
std::vector< std::string > _test_var_names
 Names of all test variables corresponding to linear forms in this equation system.
 
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
 Pointers to finite element spaces associated with test variables.
 
std::vector< mfem::ParFiniteElementSpace * > _coupled_pfespaces
 Pointers to finite element spaces associated with coupled variables.
 
NamedFieldsMap< mfem::ParBilinearForm > _blfs
 
NamedFieldsMap< mfem::ParLinearForm > _lfs
 
NamedFieldsMap< mfem::ParNonlinearForm > _nlfs
 
NamedFieldsMap< NamedFieldsMap< mfem::ParMixedBilinearForm > > _mblfs
 
std::vector< std::unique_ptr< mfem::ParGridFunction > > _var_ess_constraints
 Gridfunctions holding essential constraints from Dirichlet BCs.
 
std::vector< mfem::Array< int > > _ess_tdof_lists
 
std::vector< mfem::Array< int > > _ess_markers
 
mfem::Array2D< const mfem::HypreParMatrix * > _h_blocks
 
mfem::Array2D< const mfem::HypreParMatrix * > _jacobian_blocks
 
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _kernels_map
 Arrays to store kernels to act on each component of weak form.
 
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > _integrated_bc_map
 Arrays to store integrated BCs to act on each component of weak form.
 
NamedFieldsMap< std::vector< std::shared_ptr< MFEMEssentialBC > > > _essential_bc_map
 Arrays to store essential BCs to act on each component of weak form.
 
mfem::OperatorHandle _jacobian
 
mfem::OperatorHandle _linear_operator
 
mfem::AssemblyLevel _assembly_level
 
Moose::MFEM::GridFunctions * _gfuncs
 
mfem::Array< int > _block_true_offsets
 
const mfem::Vector * _linearization_point = nullptr
 
bool _non_linear = false
 
bool _gradient_required = false
 
CoefficientManager * _coefficient_manager = nullptr
 

Detailed Description

Owns the weak-form mathematics of a MOOSE MFEM problem.

An EquationSystem stores weak-form components (bilinear, linear, mixed-bilinear, and nonlinear forms) contributed by kernels and boundary conditions. It forms the constrained linear part, keeps nonlinear action forms for residual/Jacobian evaluation, and exposes the solve interface as an mfem::Operator. It is responsible for applying essential-DoF constraints and propagating either itself or the assembled linear operator (and bilinear form, for LOR) to the configured solver tree.

EquationSystem is not responsible for grid-function bookkeeping, time stepping, or solver selection - those belong to the ProblemOperator layer.

See also
ProblemOperatorBase for the conceptual split between the two layers.

Definition at line 44 of file EquationSystem.h.

Constructor & Destructor Documentation

◆ EquationSystem()

Moose::MFEM::EquationSystem::EquationSystem ( )
default

◆ ~EquationSystem()

Moose::MFEM::EquationSystem::~EquationSystem ( )
override

Definition at line 20 of file EquationSystem.C.

21{
24}
void DeleteHBlocks()
Deletes the HypreParMatrix associated with any pointer stored in _h_blocks, and then proceeds to dele...
void DeleteJacobianBlocks()
Deletes the HypreParMatrix associated with any pointer stored in _jacobian_blocks,...

Member Function Documentation

◆ AddCoupledVariableNameIfMissing()

void Moose::MFEM::EquationSystem::AddCoupledVariableNameIfMissing ( const std::string &  coupled_var_name)
protectedvirtual

Add coupled variable to EquationSystem.

Definition at line 57 of file EquationSystem.C.

58{
59 if (!VectorContainsName(_coupled_var_names, coupled_var_name))
60 _coupled_var_names.push_back(coupled_var_name);
61}
std::vector< std::string > _coupled_var_names
Names of all trial variables of kernels and boundary conditions added to this EquationSystem.
bool VectorContainsName(const std::vector< std::string > &the_vector, const std::string &name) const

Referenced by Moose::MFEM::ComplexEquationSystem::AddComplexIntegratedBC(), Moose::MFEM::ComplexEquationSystem::AddComplexKernel(), AddIntegratedBC(), and AddKernel().

◆ AddEliminatedVariableNameIfMissing()

void Moose::MFEM::EquationSystem::AddEliminatedVariableNameIfMissing ( const std::string &  eliminated_var_name)
protectedvirtual

Add eliminated variable to EquationSystem.

Definition at line 64 of file EquationSystem.C.

65{
66 if (!VectorContainsName(_eliminated_var_names, eliminated_var_name))
67 _eliminated_var_names.push_back(eliminated_var_name);
68}
std::vector< std::string > _eliminated_var_names
Names of all coupled variables without a corresponding test variable.

Referenced by Moose::MFEM::TimeDependentEquationSystem::AddKernel().

◆ AddEssentialBC()

void Moose::MFEM::EquationSystem::AddEssentialBC ( std::shared_ptr< MFEMEssentialBC >  bc)
virtual

Add BC associated with essentially constrained DoFs on boundaries.

Definition at line 139 of file EquationSystem.C.

140{
141 const auto & test_var_name = bc->getTestVariableName();
142 AddTestVariableNameIfMissing(test_var_name);
143 // Register new essential bc map if not present for the test variable
144 if (!_essential_bc_map.Has(test_var_name))
145 {
146 auto bcs = std::make_shared<std::vector<std::shared_ptr<MFEMEssentialBC>>>();
147 _essential_bc_map.Register(test_var_name, std::move(bcs));
148 }
149 _essential_bc_map.GetRef(test_var_name).push_back(std::move(bc));
150}
virtual void AddTestVariableNameIfMissing(const std::string &test_var_name)
Add test variable to EquationSystem.
NamedFieldsMap< std::vector< std::shared_ptr< MFEMEssentialBC > > > _essential_bc_map
Arrays to store essential BCs to act on each component of weak form.
void Register(const std::string &field_name, FieldArgs &&... args)
Construct new field with name field_name and register.
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
T & GetRef(const std::string &field_name) const
Returns a reference to a field.

◆ AddIntegratedBC()

void Moose::MFEM::EquationSystem::AddIntegratedBC ( std::shared_ptr< MFEMIntegratedBC >  kernel)
virtual

Definition at line 116 of file EquationSystem.C.

117{
118 const auto & trial_var_name = bc->getTrialVariableName();
119 const auto & test_var_name = bc->getTestVariableName();
120 AddCoupledVariableNameIfMissing(trial_var_name);
121 AddTestVariableNameIfMissing(test_var_name);
122 // Register new integrated bc map if not present for the test variable
123 if (!_integrated_bc_map.Has(test_var_name))
124 {
125 auto integrated_bc_field_map = std::make_shared<
127 _integrated_bc_map.Register(test_var_name, std::move(integrated_bc_field_map));
128 }
129 // Register new integrated bc map if not present for the test/trial variable pair
130 if (!_integrated_bc_map.Get(test_var_name)->Has(trial_var_name))
131 {
132 auto bcs = std::make_shared<std::vector<std::shared_ptr<MFEMIntegratedBC>>>();
133 _integrated_bc_map.Get(test_var_name)->Register(trial_var_name, std::move(bcs));
134 }
135 _integrated_bc_map.GetRef(test_var_name).Get(trial_var_name)->push_back(std::move(bc));
136}
virtual void AddCoupledVariableNameIfMissing(const std::string &coupled_var_name)
Add coupled variable to EquationSystem.
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > _integrated_bc_map
Arrays to store integrated BCs to act on each component of weak form.
Lightweight adaptor over an std::map from strings to pointer to T.

◆ AddKernel()

void Moose::MFEM::EquationSystem::AddKernel ( std::shared_ptr< MFEMKernel >  kernel)
virtual

Add kernels.

Reimplemented in Moose::MFEM::TimeDependentEquationSystem.

Definition at line 93 of file EquationSystem.C.

94{
95 const auto & trial_var_name = kernel->getTrialVariableName();
96 const auto & test_var_name = kernel->getTestVariableName();
97 AddCoupledVariableNameIfMissing(trial_var_name);
98 AddTestVariableNameIfMissing(test_var_name);
99 // Register new kernels map if not present for the test variable
100 if (!_kernels_map.Has(test_var_name))
101 {
102 auto kernel_field_map =
103 std::make_shared<Moose::MFEM::NamedFieldsMap<std::vector<std::shared_ptr<MFEMKernel>>>>();
104 _kernels_map.Register(test_var_name, std::move(kernel_field_map));
105 }
106 // Register new kernels map if not present for the test/trial variable pair
107 if (!_kernels_map.Get(test_var_name)->Has(trial_var_name))
108 {
109 auto kernels = std::make_shared<std::vector<std::shared_ptr<MFEMKernel>>>();
110 _kernels_map.Get(test_var_name)->Register(trial_var_name, std::move(kernels));
111 }
112 _kernels_map.GetRef(test_var_name).Get(trial_var_name)->push_back(std::move(kernel));
113}
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _kernels_map
Arrays to store kernels to act on each component of weak form.

Referenced by Moose::MFEM::TimeDependentEquationSystem::AddKernel().

◆ AddTestVariableNameIfMissing()

void Moose::MFEM::EquationSystem::AddTestVariableNameIfMissing ( const std::string &  test_var_name)
protectedvirtual

Add test variable to EquationSystem.

Definition at line 71 of file EquationSystem.C.

72{
73 if (!VectorContainsName(_test_var_names, test_var_name))
74 _test_var_names.push_back(test_var_name);
75}
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.

Referenced by Moose::MFEM::ComplexEquationSystem::AddComplexEssentialBCs(), Moose::MFEM::ComplexEquationSystem::AddComplexIntegratedBC(), Moose::MFEM::ComplexEquationSystem::AddComplexKernel(), AddEssentialBC(), AddIntegratedBC(), AddKernel(), and Moose::MFEM::TimeDependentEquationSystem::AddKernel().

◆ ApplyBoundaryBLFIntegrators()

template<class FormType >
void Moose::MFEM::EquationSystem::ApplyBoundaryBLFIntegrators ( const std::string &  trial_var_name,
const std::string &  test_var_name,
std::shared_ptr< FormType >  form,
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > &  integrated_bc_map,
std::optional< mfem::real_t >  scale_factor = std::nullopt 
)
protected

Template method for applying BilinearFormIntegrators on boundaries from integrated boundary conditions to a BilinearForm, or MixedBilinearForm.

Definition at line 381 of file EquationSystem.h.

388{
389 if (integrated_bc_map.Has(test_var_name) &&
390 integrated_bc_map.Get(test_var_name)->Has(trial_var_name))
391 {
392 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(trial_var_name);
393 for (auto & bc : bcs)
394 {
395 mfem::BilinearFormIntegrator * integ = bc->createBFIntegrator();
396
397 if (integ)
398 {
399 if (scale_factor.has_value())
400 integ = new ScaleIntegrator(integ, scale_factor.value(), true);
401 bc->isDGBC() ? bc->isBoundaryRestricted()
402 ? form->AddBdrFaceIntegrator(std::move(integ), bc->getBoundaryMarkers())
403 : form->AddBdrFaceIntegrator(std::move(integ))
404 : bc->isBoundaryRestricted()
405 ? form->AddBoundaryIntegrator(std::move(integ), bc->getBoundaryMarkers())
406 : form->AddBoundaryIntegrator(std::move(integ));
407 }
408 }
409 }
410}

◆ ApplyBoundaryLFIntegrators()

void Moose::MFEM::EquationSystem::ApplyBoundaryLFIntegrators ( const std::string &  test_var_name,
std::shared_ptr< mfem::ParLinearForm >  form,
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > &  integrated_bc_map 
)
protected

Apply boundary LinearFormIntegrators from integrated boundary conditions to the linear form associated with the supplied test variable.

Definition at line 643 of file EquationSystem.C.

648{
649 if (integrated_bc_map.Has(test_var_name) &&
650 integrated_bc_map.Get(test_var_name)->Has(test_var_name))
651 {
652 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(test_var_name);
653 for (auto & bc : bcs)
654 {
655 mfem::LinearFormIntegrator * integ = bc->createLFIntegrator();
656
657 if (integ)
658 {
659 bc->isDGBC() ? bc->isBoundaryRestricted()
660 ? form->AddBdrFaceIntegrator(std::move(integ), bc->getBoundaryMarkers())
661 : form->AddBdrFaceIntegrator(std::move(integ))
662 : bc->isBoundaryRestricted()
663 ? form->AddBoundaryIntegrator(std::move(integ), bc->getBoundaryMarkers())
664 : form->AddBoundaryIntegrator(std::move(integ));
665 }
666 }
667 }
668}

Referenced by BuildLinearForms().

◆ ApplyBoundaryNLFIntegrators()

void Moose::MFEM::EquationSystem::ApplyBoundaryNLFIntegrators ( const std::string &  test_var_name,
std::shared_ptr< mfem::ParNonlinearForm >  form,
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > &  integrated_bc_map,
std::optional< mfem::real_t >  scale_factor = std::nullopt 
)
protected

Apply boundary NonlinearFormIntegrators from integrated boundary conditions to the nonlinear form associated with the supplied test variable.

Definition at line 671 of file EquationSystem.C.

677{
678 if (integrated_bc_map.Has(test_var_name))
679 for (const auto & [trial_var_name, bcs] : integrated_bc_map.GetRef(test_var_name))
680 for (auto & bc : *bcs)
681 if (auto * integ = bc->createNLIntegrator())
682 {
683 if (_gradient_required && (test_var_name != trial_var_name))
685 "Support for Off-diagonal MFEM nonlinear boundary integrators in conjunction with "
686 "a nonlinear solver that requires a gradient is not currently "
687 "implemented. Boundary condition '",
688 bc->name(),
689 "' contributes to test variable '",
690 test_var_name,
691 "' from trial variable '",
692 trial_var_name,
693 "'.");
694
695 _non_linear = true;
696 if (scale_factor.has_value())
697 integ = new NLScaleIntegrator(integ, scale_factor.value(), true);
698 bc->isBoundaryRestricted()
699 ? form->AddBoundaryIntegrator(std::move(integ), bc->getBoundaryMarkers())
700 : form->AddBoundaryIntegrator(std::move(integ));
701 }
702}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
for(PetscInt i=0;i< nvars;++i)
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD

Referenced by BuildNonlinearFormForFESpace(), BuildNonlinearForms(), and Moose::MFEM::TimeDependentEquationSystem::BuildNonlinearForms().

◆ ApplyDomainBLFIntegrators()

template<class FormType >
void Moose::MFEM::EquationSystem::ApplyDomainBLFIntegrators ( const std::string &  trial_var_name,
const std::string &  test_var_name,
std::shared_ptr< FormType >  form,
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > &  kernels_map,
std::optional< mfem::real_t >  scale_factor = std::nullopt 
)
protected

Template method for applying BilinearFormIntegrators on domains from kernels to a BilinearForm, or MixedBilinearForm.

Definition at line 352 of file EquationSystem.h.

358{
359 if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(trial_var_name))
360 {
361 auto kernels = kernels_map.GetRef(test_var_name).GetRef(trial_var_name);
362 for (auto & kernel : kernels)
363 {
364 mfem::BilinearFormIntegrator * integ = kernel->createBFIntegrator();
365
366 if (integ)
367 {
368 if (scale_factor.has_value())
369 integ = new ScaleIntegrator(integ, scale_factor.value(), true);
370 kernel->isDGKernel() ? form->AddInteriorFaceIntegrator(std::move(integ))
371 : kernel->isSubdomainRestricted()
372 ? form->AddDomainIntegrator(std::move(integ), kernel->getSubdomainMarkers())
373 : form->AddDomainIntegrator(std::move(integ));
374 }
375 }
376 }
377}

◆ ApplyDomainLFIntegrators()

void Moose::MFEM::EquationSystem::ApplyDomainLFIntegrators ( const std::string &  test_var_name,
std::shared_ptr< mfem::ParLinearForm >  form,
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > &  kernels_map 
)
protected

Apply domain LinearFormIntegrators from kernels to the linear form associated with the supplied test variable.

Definition at line 588 of file EquationSystem.C.

592{
593 if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(test_var_name))
594 {
595 auto kernels = kernels_map.GetRef(test_var_name).GetRef(test_var_name);
596 for (auto & kernel : kernels)
597 {
598 mfem::LinearFormIntegrator * integ = kernel->createLFIntegrator();
599
600 if (integ)
601 {
602 kernel->isSubdomainRestricted()
603 ? form->AddDomainIntegrator(std::move(integ), kernel->getSubdomainMarkers())
604 : form->AddDomainIntegrator(std::move(integ));
605 }
606 }
607 }
608}

Referenced by BuildLinearForms().

◆ ApplyDomainNLFIntegrators()

void Moose::MFEM::EquationSystem::ApplyDomainNLFIntegrators ( const std::string &  test_var_name,
std::shared_ptr< mfem::ParNonlinearForm >  form,
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > &  kernels_map,
std::optional< mfem::real_t >  scale_factor = std::nullopt 
)
protected

Apply domain NonlinearFormIntegrators from kernels to the nonlinear form associated with the supplied test variable.

Definition at line 611 of file EquationSystem.C.

616{
617 if (kernels_map.Has(test_var_name))
618 for (const auto & [trial_var_name, kernels] : kernels_map.GetRef(test_var_name))
619 for (auto & kernel : *kernels)
620 if (auto * integ = kernel->createNLIntegrator())
621 {
622 if (_gradient_required && (trial_var_name != test_var_name))
623 mooseError("Support for off-diagonal MFEM nonlinear domain integrators in conjunction "
624 "with a nonlinear solver that requires a gradient is not currently "
625 "implemented. Kernel '",
626 kernel->name(),
627 "' contributes to test variable '",
628 test_var_name,
629 "' from trial variable '",
630 trial_var_name,
631 "'.");
632
633 _non_linear = true;
634 if (scale_factor.has_value())
635 integ = new NLScaleIntegrator(integ, scale_factor.value(), true);
636 kernel->isSubdomainRestricted()
637 ? form->AddDomainIntegrator(std::move(integ), kernel->getSubdomainMarkers())
638 : form->AddDomainIntegrator(std::move(integ));
639 }
640}

Referenced by BuildNonlinearFormForFESpace(), BuildNonlinearForms(), and Moose::MFEM::TimeDependentEquationSystem::BuildNonlinearForms().

◆ ApplyEssentialBC()

void Moose::MFEM::EquationSystem::ApplyEssentialBC ( const std::string &  var_name,
mfem::ParGridFunction &  trial_gf,
mfem::Array< int > &  global_ess_markers 
)
protectedvirtual

Apply essential BC(s) associated with var_name to set true DoFs of trial_gf and update markers of all essential boundaries.

Definition at line 204 of file EquationSystem.C.

207{
208 if (_essential_bc_map.Has(var_name))
209 for (auto & bc : _essential_bc_map.GetRef(var_name))
210 {
211 // Set constrained DoFs values on essential boundaries
212 bc->ApplyBC(trial_gf);
213 // Fetch marker array labelling essential boundaries of current BC
214 mfem::Array<int> ess_bdrs(bc->getBoundaryMarkers());
215 // Add these boundary markers to the set of markers labelling all essential boundaries
216 for (const auto i : make_range(ess_bdrs.Size()))
217 global_ess_markers[i] |= ess_bdrs[i];
218 }
219}
IntRange< T > make_range(T beg, T end)

Referenced by ApplyEssentialBCs(), and Moose::MFEM::EigenproblemEquationSystem::ApplyEssentialBCs().

◆ ApplyEssentialBCs()

void Moose::MFEM::EquationSystem::ApplyEssentialBCs ( )
protectedvirtual

Update all essentially constrained true DoF markers and values on boundaries.

Reimplemented in Moose::MFEM::ComplexEquationSystem, and Moose::MFEM::EigenproblemEquationSystem.

Definition at line 222 of file EquationSystem.C.

223{
224 _ess_tdof_lists.resize(_trial_var_names.size());
225 _ess_markers.resize(_trial_var_names.size());
226 for (const auto i : index_range(_trial_var_names))
227 {
228 const auto & trial_var_name = _trial_var_names.at(i);
229 mfem::ParGridFunction & trial_gf = *_var_ess_constraints.at(i);
230
231 // Make sure we update the size, if this mesh has changed recently for instance
232 trial_gf.Update();
233
234 // Initial guess for iterative solvers (initial condition or the previous time step solution)
235 trial_gf = _gfuncs->GetRef(trial_var_name);
236
237 // A mesh without boundary elements, such as a periodic one, has no boundary attributes
238 const auto & bdr_attributes = trial_gf.ParFESpace()->GetParMesh()->bdr_attributes;
239 _ess_markers.at(i).SetSize(bdr_attributes.Size() ? bdr_attributes.Max() : 0, 0);
240 // Set strongly constrained DoFs of trial_gf on essential boundaries and add markers for all
241 // essential boundaries to the _ess_markers array
242 ApplyEssentialBC(trial_var_name, trial_gf, _ess_markers.at(i));
243 trial_gf.ParFESpace()->GetEssentialTrueDofs(_ess_markers.at(i), _ess_tdof_lists.at(i));
244 }
245}
virtual void ApplyEssentialBC(const std::string &var_name, mfem::ParGridFunction &trial_gf, mfem::Array< int > &global_ess_markers)
Apply essential BC(s) associated with var_name to set true DoFs of trial_gf and update markers of all...
std::vector< mfem::Array< int > > _ess_tdof_lists
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.
std::vector< mfem::Array< int > > _ess_markers
Moose::MFEM::GridFunctions * _gfuncs
auto index_range(const T &sizable)

Referenced by BuildLinearForms().

◆ BuildBilinearFormForFESpace()

std::shared_ptr< mfem::ParBilinearForm > Moose::MFEM::EquationSystem::BuildBilinearFormForFESpace ( const std::string &  var_name,
mfem::ParFiniteElementSpace &  fespace,
mfem::AssemblyLevel  assembly_level 
)

Build a fresh ParBilinearForm on the given FESpace using the same kernels as the main system's bilinear form for var_name.

Caller owns the returned form.

Definition at line 713 of file EquationSystem.C.

716{
717 auto blf = std::make_shared<mfem::ParBilinearForm>(&fespace);
718 blf->SetAssemblyLevel(assembly_level);
719 ApplyBoundaryBLFIntegrators<mfem::ParBilinearForm>(var_name, var_name, blf, _integrated_bc_map);
720 ApplyDomainBLFIntegrators<mfem::ParBilinearForm>(var_name, var_name, blf, _kernels_map);
721 blf->Assemble();
722 blf->Finalize();
723 return blf;
724}

◆ BuildBilinearForms()

void Moose::MFEM::EquationSystem::BuildBilinearForms ( )
protectedvirtual

Build bilinear forms (diagonal Jacobian contributions)

Reimplemented in Moose::MFEM::ComplexEquationSystem, and Moose::MFEM::TimeDependentEquationSystem.

Definition at line 517 of file EquationSystem.C.

518{
519 // Register bilinear forms
520 for (const auto i : index_range(_test_var_names))
521 {
522 auto test_var_name = _test_var_names.at(i);
523 _blfs.Register(test_var_name, std::make_shared<mfem::ParBilinearForm>(_test_pfespaces.at(i)));
524
525 // Apply kernels
526 auto blf = _blfs.GetShared(test_var_name);
527 blf->SetAssemblyLevel(_assembly_level);
528 ApplyBoundaryBLFIntegrators<mfem::ParBilinearForm>(
529 test_var_name, test_var_name, blf, _integrated_bc_map);
530 ApplyDomainBLFIntegrators<mfem::ParBilinearForm>(
531 test_var_name, test_var_name, blf, _kernels_map);
532 // Assemble
533 blf->Assemble();
534 blf->Finalize();
535 }
536}
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
mfem::AssemblyLevel _assembly_level
NamedFieldsMap< mfem::ParBilinearForm > _blfs
std::shared_ptr< T > GetShared(const std::string &field_name) const
Returns a shared pointer to the field. This is guaranteed to return a non-null shared pointer.

Referenced by BuildEquationSystem().

◆ BuildEquationSystem()

void Moose::MFEM::EquationSystem::BuildEquationSystem ( )
virtual

Build all forms comprising this EquationSystem.

Definition at line 579 of file EquationSystem.C.

580{
585}
virtual void BuildBilinearForms()
Build bilinear forms (diagonal Jacobian contributions)
virtual void BuildNonlinearForms()
Build non-linear action forms.
virtual void BuildMixedBilinearForms()
Build mixed bilinear forms (off-diagonal Jacobian contributions)
virtual void BuildLinearForms()
Build linear forms and eliminate constrained DoFs.

Referenced by Moose::MFEM::EigenproblemESProblemOperator::FormEquationSystemOperator(), and FormSystem().

◆ BuildLinearForms()

void Moose::MFEM::EquationSystem::BuildLinearForms ( )
protectedvirtual

Build linear forms and eliminate constrained DoFs.

Reimplemented in Moose::MFEM::ComplexEquationSystem.

Definition at line 474 of file EquationSystem.C.

475{
476 // Register linear forms
477 for (const auto i : index_range(_test_var_names))
478 {
479 auto test_var_name = _test_var_names.at(i);
480 _lfs.Register(test_var_name, std::make_shared<mfem::ParLinearForm>(_test_pfespaces.at(i)));
481 _lfs.GetRef(test_var_name) = 0.0;
482 }
483
484 for (auto & test_var_name : _test_var_names)
485 {
486 // Apply kernels
487 auto lf = _lfs.GetShared(test_var_name);
488 ApplyDomainLFIntegrators(test_var_name, lf, _kernels_map);
490 lf->Assemble();
491 }
492
493 // Apply essential boundary conditions
495
496 // Eliminate trivially eliminated variables by subtracting contributions from linear forms
498}
virtual void ApplyEssentialBCs()
Update all essentially constrained true DoF markers and values on boundaries.
virtual void EliminateCoupledVariables()
Perform trivial eliminations of coupled variables lacking corresponding test variables.
void ApplyBoundaryLFIntegrators(const std::string &test_var_name, std::shared_ptr< mfem::ParLinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > &integrated_bc_map)
Apply boundary LinearFormIntegrators from integrated boundary conditions to the linear form associate...
NamedFieldsMap< mfem::ParLinearForm > _lfs
void ApplyDomainLFIntegrators(const std::string &test_var_name, std::shared_ptr< mfem::ParLinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > &kernels_map)
Apply domain LinearFormIntegrators from kernels to the linear form associated with the supplied test ...

Referenced by BuildEquationSystem().

◆ BuildMixedBilinearForms()

void Moose::MFEM::EquationSystem::BuildMixedBilinearForms ( )
protectedvirtual

Build mixed bilinear forms (off-diagonal Jacobian contributions)

Reimplemented in Moose::MFEM::ComplexEquationSystem, and Moose::MFEM::TimeDependentEquationSystem.

Definition at line 539 of file EquationSystem.C.

540{
541 // Register mixed bilinear forms. Note that not all combinations may
542 // have a kernel.
543
544 // Create mblf for each test/coupled variable pair with an added kernel.
545 // Mixed bilinear forms with coupled variables that are not trial variables are
546 // associated with contributions from eliminated variables.
547 for (const auto i : index_range(_test_var_names))
548 {
549 auto test_var_name = _test_var_names.at(i);
550 auto test_mblfs = std::make_shared<Moose::MFEM::NamedFieldsMap<mfem::ParMixedBilinearForm>>();
551 for (const auto j : index_range(_coupled_var_names))
552 {
553 const auto & coupled_var_name = _coupled_var_names.at(j);
554 auto mblf = std::make_shared<mfem::ParMixedBilinearForm>(_coupled_pfespaces.at(j),
555 _test_pfespaces.at(i));
556 // Register MixedBilinearForm if kernels exist for it, and assemble kernels
557 if (_kernels_map.Has(test_var_name) &&
558 _kernels_map.Get(test_var_name)->Has(coupled_var_name) &&
559 test_var_name != coupled_var_name)
560 {
561 mblf->SetAssemblyLevel(_assembly_level);
562 // Apply all mixed kernels with this test/trial pair
563 ApplyDomainBLFIntegrators<mfem::ParMixedBilinearForm>(
564 coupled_var_name, test_var_name, mblf, _kernels_map);
565 // Assemble mixed bilinear forms
566 mblf->Assemble();
567 mblf->Finalize();
568 // Register mixed bilinear forms associated with a single trial variable
569 // for the current test variable
570 test_mblfs->Register(coupled_var_name, mblf);
571 }
572 }
573 // Register all mixed bilinear form sets associated with a single test variable
574 _mblfs.Register(test_var_name, test_mblfs);
575 }
576}
std::vector< mfem::ParFiniteElementSpace * > _coupled_pfespaces
Pointers to finite element spaces associated with coupled variables.
NamedFieldsMap< NamedFieldsMap< mfem::ParMixedBilinearForm > > _mblfs

Referenced by BuildEquationSystem().

◆ BuildNonlinearFormForFESpace()

std::shared_ptr< mfem::ParNonlinearForm > Moose::MFEM::EquationSystem::BuildNonlinearFormForFESpace ( const std::string &  var_name,
mfem::ParFiniteElementSpace &  fespace,
mfem::AssemblyLevel  assembly_level 
)

Build a fresh ParNonlinearForm on the given FESpace using the same kernels as the main system's nonlinear form for var_name.

Caller owns the returned form.

Definition at line 727 of file EquationSystem.C.

730{
731 auto nlf = std::make_shared<mfem::ParNonlinearForm>(&fespace);
732 ApplyDomainNLFIntegrators(var_name, nlf, _kernels_map, std::nullopt);
733 ApplyBoundaryNLFIntegrators(var_name, nlf, _integrated_bc_map, std::nullopt);
734 return nlf;
735}
void ApplyDomainNLFIntegrators(const std::string &test_var_name, std::shared_ptr< mfem::ParNonlinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > &kernels_map, std::optional< mfem::real_t > scale_factor=std::nullopt)
Apply domain NonlinearFormIntegrators from kernels to the nonlinear form associated with the supplied...
void ApplyBoundaryNLFIntegrators(const std::string &test_var_name, std::shared_ptr< mfem::ParNonlinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > &integrated_bc_map, std::optional< mfem::real_t > scale_factor=std::nullopt)
Apply boundary NonlinearFormIntegrators from integrated boundary conditions to the nonlinear form ass...

◆ BuildNonlinearForms()

void Moose::MFEM::EquationSystem::BuildNonlinearForms ( )
protectedvirtual

Build non-linear action forms.

Reimplemented in Moose::MFEM::TimeDependentEquationSystem.

Definition at line 501 of file EquationSystem.C.

502{
503 // Register non-linear Action forms
504 for (const auto i : index_range(_test_var_names))
505 {
506 auto test_var_name = _test_var_names.at(i);
507 _nlfs.Register(test_var_name, std::make_shared<mfem::ParNonlinearForm>(_test_pfespaces.at(i)));
508 // Apply kernels
509 auto nlf = _nlfs.GetShared(test_var_name);
510 nlf->SetEssentialTrueDofs(_ess_tdof_lists.at(i));
511 ApplyDomainNLFIntegrators(test_var_name, nlf, _kernels_map, std::nullopt);
512 ApplyBoundaryNLFIntegrators(test_var_name, nlf, _integrated_bc_map, std::nullopt);
513 }
514}
NamedFieldsMap< mfem::ParNonlinearForm > _nlfs

Referenced by BuildEquationSystem().

◆ ComputeNonlinearResidual()

void Moose::MFEM::EquationSystem::ComputeNonlinearResidual ( const mfem::Vector &  u,
mfem::Vector &  residual 
) const
virtual

Compute the contribution to the residual from nonlinear forms only.

Definition at line 393 of file EquationSystem.C.

394{
395 mooseAssert(IsNonlinear(), "Should not be calling this method if our forms are not nonlinear");
396
397 const mfem::BlockVector block_solution(const_cast<mfem::Vector &>(sol), _block_true_offsets);
398 SetTrialVariablesFromTrueVectors(block_solution);
399
400 mfem::BlockVector block_residual(residual, _block_true_offsets);
401 for (unsigned int i = 0; i < _test_var_names.size(); i++)
402 {
403 auto & test_var_name = _test_var_names.at(i);
404 auto nlf = _nlfs.GetShared(test_var_name);
405 nlf->AddMult(block_solution.GetBlock(i), block_residual.GetBlock(i));
406 block_residual.GetBlock(i).SyncAliasMemory(block_residual);
407 }
408}
mfem::Array< int > _block_true_offsets
virtual void SetTrialVariablesFromTrueVectors(const mfem::BlockVector &trueX) const
Update variable from solution vector after solve.

Referenced by Mult().

◆ DeleteHBlocks()

void Moose::MFEM::EquationSystem::DeleteHBlocks ( )
protected

Deletes the HypreParMatrix associated with any pointer stored in _h_blocks, and then proceeds to delete all dynamically allocated memory for _h_blocks itself, resetting all dimensions to zero.

Definition at line 27 of file EquationSystem.C.

28{
29 for (const auto i : make_range(_h_blocks.NumRows()))
30 for (const auto j : make_range(_h_blocks.NumCols()))
31 {
32 if (_jacobian_blocks.NumRows() && _jacobian_blocks(i, j) == _h_blocks(i, j))
33 _jacobian_blocks(i, j) = nullptr;
34 delete _h_blocks(i, j);
35 }
36 _h_blocks.DeleteAll();
37}
mfem::Array2D< const mfem::HypreParMatrix * > _h_blocks
mfem::Array2D< const mfem::HypreParMatrix * > _jacobian_blocks

Referenced by FormSystemMatrix(), Moose::MFEM::ComplexEquationSystem::FormSystemMatrix(), and ~EquationSystem().

◆ DeleteJacobianBlocks()

void Moose::MFEM::EquationSystem::DeleteJacobianBlocks ( )
protected

Deletes the HypreParMatrix associated with any pointer stored in _jacobian_blocks, and then proceeds to delete all dynamically allocated memory for _jacobian_blocks itself, resetting all dimensions to zero.

Definition at line 40 of file EquationSystem.C.

41{
42 for (const auto i : make_range(_jacobian_blocks.NumRows()))
43 for (const auto j : make_range(_jacobian_blocks.NumCols()))
44 if (!_h_blocks.NumRows() || _jacobian_blocks(i, j) != _h_blocks(i, j))
45 delete _jacobian_blocks(i, j);
46 _jacobian_blocks.DeleteAll();
47}

Referenced by FormJacobianMatrix(), and ~EquationSystem().

◆ EliminateCoupledVariables()

void Moose::MFEM::EquationSystem::EliminateCoupledVariables ( )
protectedvirtual

Perform trivial eliminations of coupled variables lacking corresponding test variables.

Reimplemented in Moose::MFEM::ComplexEquationSystem, and Moose::MFEM::TimeDependentEquationSystem.

Definition at line 248 of file EquationSystem.C.

249{
250 for (const auto & test_var_name : _test_var_names)
251 for (const auto & eliminated_var_name : _eliminated_var_names)
252 if (_mblfs.Has(test_var_name) && _mblfs.Get(test_var_name)->Has(eliminated_var_name) &&
253 !VectorContainsName(_test_var_names, eliminated_var_name))
254 {
255 auto & mblf = *_mblfs.Get(test_var_name)->Get(eliminated_var_name);
256 mblf.AddMult(*_eliminated_variables.Get(eliminated_var_name), *_lfs.Get(test_var_name), -1);
257 }
258}
Moose::MFEM::GridFunctions _eliminated_variables
Pointers to coupled variables not part of the reduced EquationSystem.
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.

Referenced by BuildLinearForms(), and Moose::MFEM::TimeDependentEquationSystem::EliminateCoupledVariables().

◆ FormJacobianMatrix()

void Moose::MFEM::EquationSystem::FormJacobianMatrix ( const mfem::Vector &  u)
protected

Compute Jacobian matrix at the provided vector of true DoFs of trial variables.

Definition at line 411 of file EquationSystem.C.

412{
414 _jacobian_blocks.SetSize(_test_var_names.size(), _trial_var_names.size());
415 _jacobian_blocks = nullptr;
416
417 const mfem::BlockVector update_vector(const_cast<mfem::Vector &>(u), _block_true_offsets);
418 for (const auto i : index_range(_test_var_names))
419 {
420 auto test_var_name = _test_var_names.at(i);
421 if (_nlfs.Has(test_var_name))
422 {
423 auto nlf = _nlfs.Get(test_var_name);
424 mfem::HypreParMatrix * nlf_jac =
425 dynamic_cast<mfem::HypreParMatrix *>(&nlf->GetGradient(update_vector.GetBlock(i)));
426 mooseAssert(nlf_jac,
427 "Jacobian contribution of nonlinear form associated with " + test_var_name +
428 " is not castable into a HypreParMatrix");
429 _jacobian_blocks(i, i) = mfem::ParAdd(_h_blocks(i, i), nlf_jac);
430 }
431 else
432 _jacobian_blocks(i, i) = _h_blocks(i, i);
433 for (const auto j : index_range(_trial_var_names))
434 if (i != j) // nlf->GetGradient only contributes to on-diagonal blocks
435 _jacobian_blocks(i, j) = _h_blocks(i, j);
436 }
437 // Create monolithic matrix
438 _jacobian.Reset(mfem::HypreParMatrixFromBlocks(_jacobian_blocks));
439}
mfem::OperatorHandle _jacobian

Referenced by GetGradient().

◆ FormLinearSystem()

void Moose::MFEM::EquationSystem::FormLinearSystem ( mfem::OperatorHandle &  op,
mfem::BlockVector &  trueX,
mfem::BlockVector &  trueRHS 
)
protectedvirtual

Form linear components of system based on on- and off-diagonal bilinear form contributions, populate solution and RHS vectors of true DoFs, and apply constraints.

Definition at line 261 of file EquationSystem.C.

264{
265 mooseAssert(_test_var_names.size() == _trial_var_names.size(),
266 "Number of test and trial variables must be the same for block matrix assembly.");
267
268 if (_assembly_level == mfem::AssemblyLevel::LEGACY)
269 FormSystemMatrix(op, trueX, trueRHS);
270 else
271 FormSystemOperator(op, trueX, trueRHS);
272}
virtual void FormSystemOperator(mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
Form matrix-free representation of linear components of system operator.
virtual void FormSystemMatrix(mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
Form matrix representation of linear components of system operator as a HypreParMatrix.

Referenced by FormSystem().

◆ FormSystem()

void Moose::MFEM::EquationSystem::FormSystem ( mfem::BlockVector &  trueX,
mfem::BlockVector &  trueRHS 
)

Build all weak-form components via BuildEquationSystem(), form the constrained linear part of the system, and populate the true-DoF vectors used by the solve.

For nonlinear problems, nonlinear forms are registered here but are not folded into the assembled linear operator. Their residual action is evaluated by Mult(), and any Jacobian contribution is formed at the current nonlinear iterate by GetGradient().

This is the single public entry point for callers that want the equation system prepared for a solve. Subclasses customize the form-building step by overriding BuildEquationSystem().

Definition at line 369 of file EquationSystem.C.

370{
372 height = trueX.Size();
373 width = trueRHS.Size();
374 // Store block offsets
375 _block_true_offsets.SetSize(trueX.NumBlocks() + 1);
376 _block_true_offsets[0] = 0;
377 for (unsigned i = 0; i < _trial_var_names.size(); i++)
378 _block_true_offsets[i + 1] = trueX.BlockSize(i);
379 _block_true_offsets.PartialSum();
380 FormLinearSystem(_linear_operator, trueX, trueRHS);
381}
virtual void BuildEquationSystem()
Build all forms comprising this EquationSystem.
mfem::OperatorHandle _linear_operator
virtual void FormLinearSystem(mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
Form linear components of system based on on- and off-diagonal bilinear form contributions,...

Referenced by Moose::MFEM::EquationSystemProblemOperator::FormEquationSystemOperator(), and Moose::MFEM::TimeDependentEquationSystemProblemOperator::FormEquationSystemOperator().

◆ FormSystemMatrix()

void Moose::MFEM::EquationSystem::FormSystemMatrix ( mfem::OperatorHandle &  op,
mfem::BlockVector &  trueX,
mfem::BlockVector &  trueRHS 
)
protectedvirtual

Form matrix representation of linear components of system operator as a HypreParMatrix.

Used when EquationSystem assembly level is set to 'LEGACY'.

Reimplemented in Moose::MFEM::ComplexEquationSystem.

Definition at line 305 of file EquationSystem.C.

308{
309 // Allocate block operator
311 _h_blocks.SetSize(_test_var_names.size(), _trial_var_names.size());
312 _h_blocks = nullptr;
313 // Zero out RHS and sync memory
314 trueRHS = 0.0;
315 trueRHS.SyncToBlocks();
316
317 for (const auto i : index_range(_test_var_names))
318 {
319 auto test_var_name = _test_var_names.at(i);
320
321 for (const auto j : index_range(_trial_var_names))
322 {
323 auto trial_var_name = _trial_var_names.at(j);
324
325 mfem::Vector aux_x, aux_rhs;
326 mfem::ParLinearForm aux_lf(_test_pfespaces.at(i));
327 mfem::HypreParMatrix * aux_a = new mfem::HypreParMatrix;
328
329 if (test_var_name == trial_var_name)
330 {
331 mooseAssert(i == j, "Trial and test variables must have the same ordering.");
332 auto blf = _blfs.Get(test_var_name);
333 blf->FormLinearSystem(_ess_tdof_lists.at(j),
335 *_lfs.Get(test_var_name),
336 *aux_a,
337 aux_x,
338 aux_rhs,
339 /*copy_interior=*/true);
340 trueX.GetBlock(j) = aux_x;
341 }
342 else if (_mblfs.Has(test_var_name) && _mblfs.Get(test_var_name)->Has(trial_var_name))
343 {
344 auto mblf = _mblfs.Get(test_var_name)->Get(trial_var_name);
345 mblf->FormRectangularLinearSystem(_ess_tdof_lists.at(j),
346 _ess_tdof_lists.at(i),
348 aux_lf = 0.,
349 *aux_a,
350 aux_x,
351 aux_rhs);
352 }
353 else
354 continue;
355
356 trueRHS.GetBlock(i) += aux_rhs;
357 _h_blocks(i, j) = aux_a;
358 }
359 }
360 // Sync memory
361 trueX.SyncFromBlocks();
362 trueRHS.SyncFromBlocks();
363
364 // Create monolithic matrix
365 op.Reset(mfem::HypreParMatrixFromBlocks(_h_blocks));
366}

Referenced by FormLinearSystem().

◆ FormSystemOperator()

void Moose::MFEM::EquationSystem::FormSystemOperator ( mfem::OperatorHandle &  op,
mfem::BlockVector &  trueX,
mfem::BlockVector &  trueRHS 
)
protectedvirtual

Form matrix-free representation of linear components of system operator.

Used when EquationSystem assembly level is set to 'FULL', 'ELEMENT', 'PARTIAL', or 'NONE'.

Reimplemented in Moose::MFEM::ComplexEquationSystem.

Definition at line 275 of file EquationSystem.C.

278{
279 mooseAssert(_test_var_names.size() == 1 && _test_var_names.size() == _trial_var_names.size(),
280 "Non-legacy assembly is only supported for single test and trial variable systems");
281
282 auto & test_var_name = _test_var_names.at(0);
283 mfem::Vector aux_x, aux_rhs;
284 mfem::OperatorPtr aux_a;
285
286 auto blf = _blfs.Get(test_var_name);
287 blf->FormLinearSystem(_ess_tdof_lists.at(0),
289 *_lfs.Get(test_var_name),
290 aux_a,
291 aux_x,
292 aux_rhs,
293 /*copy_interior=*/true);
294
295 trueX.GetBlock(0) = aux_x;
296 trueRHS.GetBlock(0) = aux_rhs;
297 trueX.SyncFromBlocks();
298 trueRHS.SyncFromBlocks();
299
300 op.Reset(aux_a.Ptr());
301 aux_a.SetOperatorOwner(false);
302}

Referenced by FormLinearSystem().

◆ GetBilinearForm()

mfem::ParBilinearForm & Moose::MFEM::EquationSystem::GetBilinearForm ( const std::string &  test_var_name)
inline
Returns
a reference to the MFEM ParBilinearForm corresponding to test_var_name

Definition at line 106 of file EquationSystem.h.

107 {
108 return _blfs.GetRef(test_var_name);
109 }

◆ GetBlockOffsets()

const mfem::Array< int > & Moose::MFEM::EquationSystem::GetBlockOffsets ( ) const
inline

Getter for block true offsets associated with the EquationSystem operator.

Definition at line 101 of file EquationSystem.h.

101{ return _block_true_offsets; }

◆ GetEssentialBoundaryMarkers()

mfem::Array< int > & Moose::MFEM::EquationSystem::GetEssentialBoundaryMarkers ( const std::string &  var_name)

Return the essential boundary attribute marker array for a given trial variable.

The returned array has size == pmesh.bdr_attributes.Max() with 1 at essential boundaries.

Definition at line 738 of file EquationSystem.C.

739{
740 for (const auto i : index_range(_trial_var_names))
741 if (_trial_var_names.at(i) == var_name)
742 return _ess_markers.at(i);
743
744 mooseError("No essential boundary markers found for variable '", var_name, "'.");
745}

◆ GetGradient()

mfem::Operator & Moose::MFEM::EquationSystem::GetGradient ( const mfem::Vector &  u) const
override

Get Jacobian at the provided vector of true DoFs of trial variables.

Definition at line 442 of file EquationSystem.C.

443{
445
446 if (IsNonlinear())
447 {
448 if (_assembly_level != mfem::AssemblyLevel::LEGACY)
449 mooseError("MFEM nonlinear solvers that require GetGradient() currently require legacy "
450 "assembly in EquationSystem.");
451 const_cast<EquationSystem *>(this)->FormJacobianMatrix(u);
452 }
453 else
455
456 return *_jacobian;
457}
void FormJacobianMatrix(const mfem::Vector &u)
Compute Jacobian matrix at the provided vector of true DoFs of trial variables.
const mfem::Vector * _linearization_point

◆ GetGridFunction()

mfem::ParGridFunction & Moose::MFEM::EquationSystem::GetGridFunction ( const std::string &  trial_var_name)
inline
Returns
a reference to the MFEM ParGridFunction corresponding to trial_var_name

Definition at line 114 of file EquationSystem.h.

115 {
116 return _gfuncs->GetRef(trial_var_name);
117 }

◆ GetLinearizationPoint()

const mfem::Vector & Moose::MFEM::EquationSystem::GetLinearizationPoint ( ) const

The true-DoF vector used for the most recent Jacobian linearization.

Definition at line 705 of file EquationSystem.C.

706{
708 mooseError("EquationSystem::GetLinearizationPoint() called before GetGradient().");
709 return *_linearization_point;
710}

◆ GetLinearOperator()

mfem::OperatorHandle & Moose::MFEM::EquationSystem::GetLinearOperator ( ) const
inline

Get operator handle for linear component of system operator.

Definition at line 80 of file EquationSystem.h.

80{ return _linear_operator; };

◆ GetTestVarNames()

const std::vector< std::string > & Moose::MFEM::EquationSystem::GetTestVarNames ( ) const
inline

◆ GetTrialVarNames()

const std::vector< std::string > & Moose::MFEM::EquationSystem::GetTrialVarNames ( ) const
inline

◆ Init()

void Moose::MFEM::EquationSystem::Init ( GridFunctions &  gridfunctions,
ComplexGridFunctions &  cmplx_gridfunctions,
mfem::AssemblyLevel  assembly_level 
)
virtual

Initialise.

Reimplemented in Moose::MFEM::ComplexEquationSystem.

Definition at line 153 of file EquationSystem.C.

156{
157 _assembly_level = assembly_level;
158
159 // Extract which coupled variables are to be trivially eliminated and which are trial variables
161
162 for (auto & test_var_name : _test_var_names)
163 {
164 if (!gridfunctions.Has(test_var_name))
165 {
166 mooseError("MFEM variable ",
167 test_var_name,
168 " requested by equation system during initialization was "
169 "not found in gridfunctions");
170 }
171 // Store pointers to test FESpaces
172 _test_pfespaces.push_back(gridfunctions.Get(test_var_name)->ParFESpace());
173 }
174
175 for (auto & trial_var_name : _trial_var_names)
176 {
177 if (!gridfunctions.Has(trial_var_name))
178 {
179 mooseError("MFEM variable ",
180 trial_var_name,
181 " requested by equation system during initialization was "
182 "not found in gridfunctions");
183 }
184 // Create auxiliary gridfunctions for storing essential constraints from Dirichlet conditions
185 _var_ess_constraints.emplace_back(
186 std::make_unique<mfem::ParGridFunction>(gridfunctions.Get(trial_var_name)->ParFESpace()));
187 }
188
189 // Store pointers to FESpaces of all coupled variables
190 for (auto & coupled_var_name : _coupled_var_names)
191 _coupled_pfespaces.push_back(gridfunctions.Get(coupled_var_name)->ParFESpace());
192
193 // Store pointers to coupled variable GridFunctions that are to be eliminated prior to forming the
194 // jacobian
195 for (auto & eliminated_var_name : _eliminated_var_names)
196 _eliminated_variables.Register(eliminated_var_name,
197 gridfunctions.GetShared(eliminated_var_name));
198
199 // Get a reference to the GridFunctions
200 _gfuncs = &gridfunctions;
201}
virtual void SetTrialVariableNames()
Set trial variable names from subset of coupled variables that have an associated test variable.

◆ IsComplex()

virtual bool Moose::MFEM::EquationSystem::IsComplex ( ) const
inlinevirtual
Returns
Whether this EquationSystem includes complex components

Reimplemented in Moose::MFEM::ComplexEquationSystem.

Definition at line 147 of file EquationSystem.h.

147{ return false; }

◆ IsEigen()

virtual bool Moose::MFEM::EquationSystem::IsEigen ( ) const
inlinevirtual
Returns
Whether this EquationSystem represents an eigenproblem

Reimplemented in Moose::MFEM::EigenproblemEquationSystem.

Definition at line 149 of file EquationSystem.h.

149{ return false; }

◆ IsMultivariate()

bool Moose::MFEM::EquationSystem::IsMultivariate ( ) const
inline
Returns
Whether this is a multivariate (maybe mixed) equation system

Definition at line 153 of file EquationSystem.h.

153{ return _test_var_names.size() > 1; }

◆ IsNonlinear()

bool Moose::MFEM::EquationSystem::IsNonlinear ( ) const
inline
Returns
Whether nonlinear integrators are present in the equation system

Definition at line 155 of file EquationSystem.h.

155{ return _non_linear; }

Referenced by ComputeNonlinearResidual(), GetGradient(), and Mult().

◆ IsTimeDependent()

virtual bool Moose::MFEM::EquationSystem::IsTimeDependent ( ) const
inlinevirtual
Returns
Whether this EquationSystem has time-dependent components

Reimplemented in Moose::MFEM::TimeDependentEquationSystem.

Definition at line 151 of file EquationSystem.h.

151{ return false; }

◆ Mult()

void Moose::MFEM::EquationSystem::Mult ( const mfem::Vector &  u,
mfem::Vector &  residual 
) const
override

Compute residual y = Mu.

Definition at line 384 of file EquationSystem.C.

385{
386 _linear_operator->Mult(sol, residual);
387
388 if (IsNonlinear())
389 ComputeNonlinearResidual(sol, residual);
390}
virtual void ComputeNonlinearResidual(const mfem::Vector &u, mfem::Vector &residual) const
Compute the contribution to the residual from nonlinear forms only.

◆ SetCoefficientManager()

void Moose::MFEM::EquationSystem::SetCoefficientManager ( CoefficientManager &  coefficients)
inline

Set the coefficient manager to notify when trial variables are updated, so that stored projections of solution-dependent coefficients are invalidated.

Definition at line 90 of file EquationSystem.h.

91 {
92 _coefficient_manager = &coefficients;
93 }
CoefficientManager * _coefficient_manager

◆ SetGradientRequired()

void Moose::MFEM::EquationSystem::SetGradientRequired ( bool  requires_gradient)
inline

Set whether an external object (such as a nonlinear solver) requires Jacobian information for this EquationSystem.

Definition at line 86 of file EquationSystem.h.

86{ _gradient_required = requires_gradient; }

◆ SetTrialVariableNames()

void Moose::MFEM::EquationSystem::SetTrialVariableNames ( )
protectedvirtual

Set trial variable names from subset of coupled variables that have an associated test variable.

Definition at line 78 of file EquationSystem.C.

79{
80 // If a coupled variable has an equation associated with it,
81 // add it to the set of trial variables.
82 for (const auto & test_var_name : _test_var_names)
84 _trial_var_names.push_back(test_var_name);
85
86 // Otherwise, add it to the set of eliminated variables.
87 for (const auto & coupled_var_name : _coupled_var_names)
88 if (!VectorContainsName(_test_var_names, coupled_var_name))
89 _eliminated_var_names.push_back(coupled_var_name);
90}

Referenced by Init(), and Moose::MFEM::ComplexEquationSystem::Init().

◆ SetTrialVariablesFromTrueVectors()

void Moose::MFEM::EquationSystem::SetTrialVariablesFromTrueVectors ( const mfem::BlockVector &  trueX) const
virtual

Update variable from solution vector after solve.

Reimplemented in Moose::MFEM::ComplexEquationSystem.

Definition at line 460 of file EquationSystem.C.

461{
462 for (const auto i : index_range(_trial_var_names))
463 {
464 auto & trial_var_name = _trial_var_names.at(i);
465 trueX.GetBlock(i).SyncMemory(trueX);
466 _gfuncs->Get(trial_var_name)->Distribute(&(trueX.GetBlock(i)));
467 }
468 // Solution variables changed: stored projections of solution-dependent coefficients are stale.
471}
void markSolutionChanged()
Notify quadrature function coefficients that solution variables have changed, marking the stored valu...

Referenced by ComputeNonlinearResidual().

◆ VectorContainsName()

bool Moose::MFEM::EquationSystem::VectorContainsName ( const std::vector< std::string > &  the_vector,
const std::string &  name 
) const
protected

Definition at line 50 of file EquationSystem.C.

52{
53 return std::find(the_vector.begin(), the_vector.end(), name) != the_vector.end();
54}

Referenced by AddCoupledVariableNameIfMissing(), AddEliminatedVariableNameIfMissing(), AddTestVariableNameIfMissing(), EliminateCoupledVariables(), Moose::MFEM::ComplexEquationSystem::EliminateCoupledVariables(), and SetTrialVariableNames().

Member Data Documentation

◆ _assembly_level

mfem::AssemblyLevel Moose::MFEM::EquationSystem::_assembly_level
protected

◆ _blfs

NamedFieldsMap<mfem::ParBilinearForm> Moose::MFEM::EquationSystem::_blfs
protected

◆ _block_true_offsets

mfem::Array<int> Moose::MFEM::EquationSystem::_block_true_offsets
protected

◆ _coefficient_manager

CoefficientManager* Moose::MFEM::EquationSystem::_coefficient_manager = nullptr
protected

◆ _coupled_pfespaces

std::vector<mfem::ParFiniteElementSpace *> Moose::MFEM::EquationSystem::_coupled_pfespaces
protected

◆ _coupled_var_names

std::vector<std::string> Moose::MFEM::EquationSystem::_coupled_var_names
protected

◆ _eliminated_var_names

std::vector<std::string> Moose::MFEM::EquationSystem::_eliminated_var_names
protected

◆ _eliminated_variables

Moose::MFEM::GridFunctions Moose::MFEM::EquationSystem::_eliminated_variables
protected

Pointers to coupled variables not part of the reduced EquationSystem.

Definition at line 295 of file EquationSystem.h.

Referenced by EliminateCoupledVariables(), Moose::MFEM::TimeDependentEquationSystem::EliminateCoupledVariables(), and Init().

◆ _ess_markers

std::vector<mfem::Array<int> > Moose::MFEM::EquationSystem::_ess_markers
protected

◆ _ess_tdof_lists

std::vector<mfem::Array<int> > Moose::MFEM::EquationSystem::_ess_tdof_lists
protected

◆ _essential_bc_map

NamedFieldsMap<std::vector<std::shared_ptr<MFEMEssentialBC> > > Moose::MFEM::EquationSystem::_essential_bc_map
protected

Arrays to store essential BCs to act on each component of weak form.

Named according to test variable.

Definition at line 323 of file EquationSystem.h.

Referenced by AddEssentialBC(), and ApplyEssentialBC().

◆ _gfuncs

Moose::MFEM::GridFunctions* Moose::MFEM::EquationSystem::_gfuncs
protected

◆ _gradient_required

bool Moose::MFEM::EquationSystem::_gradient_required = false
protected

◆ _h_blocks

mfem::Array2D<const mfem::HypreParMatrix *> Moose::MFEM::EquationSystem::_h_blocks
protected

◆ _integrated_bc_map

NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMIntegratedBC> > > > Moose::MFEM::EquationSystem::_integrated_bc_map
protected

◆ _jacobian

mfem::OperatorHandle Moose::MFEM::EquationSystem::_jacobian
mutableprotected

◆ _jacobian_blocks

mfem::Array2D<const mfem::HypreParMatrix *> Moose::MFEM::EquationSystem::_jacobian_blocks
protected

Definition at line 314 of file EquationSystem.h.

Referenced by DeleteHBlocks(), DeleteJacobianBlocks(), and FormJacobianMatrix().

◆ _kernels_map

NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMKernel> > > > Moose::MFEM::EquationSystem::_kernels_map
protected

◆ _lfs

NamedFieldsMap<mfem::ParLinearForm> Moose::MFEM::EquationSystem::_lfs
protected

◆ _linear_operator

mfem::OperatorHandle Moose::MFEM::EquationSystem::_linear_operator
mutableprotected

◆ _linearization_point

const mfem::Vector* Moose::MFEM::EquationSystem::_linearization_point = nullptr
mutableprotected

Definition at line 336 of file EquationSystem.h.

Referenced by GetGradient(), and GetLinearizationPoint().

◆ _mblfs

NamedFieldsMap<NamedFieldsMap<mfem::ParMixedBilinearForm> > Moose::MFEM::EquationSystem::_mblfs
protected

◆ _nlfs

NamedFieldsMap<mfem::ParNonlinearForm> Moose::MFEM::EquationSystem::_nlfs
protected

◆ _non_linear

bool Moose::MFEM::EquationSystem::_non_linear = false
protected

◆ _test_pfespaces

std::vector<mfem::ParFiniteElementSpace *> Moose::MFEM::EquationSystem::_test_pfespaces
protected

◆ _test_var_names

std::vector<std::string> Moose::MFEM::EquationSystem::_test_var_names
protected

◆ _trial_var_names

std::vector<std::string> Moose::MFEM::EquationSystem::_trial_var_names
protected

◆ _var_ess_constraints

std::vector<std::unique_ptr<mfem::ParGridFunction> > Moose::MFEM::EquationSystem::_var_ess_constraints
protected

The documentation for this class was generated from the following files: