https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Moose::MFEM::TimeDependentEquationSystem Class Reference

Class to store weak form components for time dependent PDEs. More...

#include <TimeDependentEquationSystem.h>

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

Public Member Functions

 TimeDependentEquationSystem (const Moose::MFEM::TimeDerivativeMap &time_derivative_map)
 
virtual void SetTimeStep (mfem::real_t &dt)
 
virtual void AddKernel (std::shared_ptr< MFEMKernel > kernel) override
 Add kernels. More...
 
virtual bool IsTimeDependent () const override
 
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. More...
 
virtual void Init (GridFunctions &gridfunctions, ComplexGridFunctions &cmplx_gridfunctions, mfem::AssemblyLevel assembly_level)
 Initialise. More...
 
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. More...
 
void Mult (const mfem::Vector &u, mfem::Vector &residual) const override
 Compute residual y = Mu. More...
 
virtual void ComputeNonlinearResidual (const mfem::Vector &u, mfem::Vector &residual) const
 Compute the contribution to the residual from nonlinear forms only. More...
 
mfem::Operator & GetGradient (const mfem::Vector &u) const override
 Get Jacobian at the provided vector of true DoFs of trial variables. More...
 
mfem::OperatorHandle & GetLinearOperator () const
 Get operator handle for linear component of system operator. More...
 
virtual void SetTrialVariablesFromTrueVectors (const mfem::BlockVector &trueX) const
 Update variable from solution vector after solve. More...
 
void SetGradientRequired (bool requires_gradient)
 Set whether an external object (such as a nonlinear solver) requires Jacobian information for this EquationSystem. More...
 
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. More...
 
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. More...
 
mfem::ParBilinearForm & GetBilinearForm (const std::string &test_var_name)
 
mfem::ParGridFunction & GetGridFunction (const std::string &trial_var_name)
 
bool Nonlinear () const
 
const mfem::Vector & GetLinearizationPoint () const
 The true-DoF vector used for the most recent Jacobian linearization. More...
 
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. More...
 
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. More...
 
mfem::Array< int > & GetEssentialBoundaryMarkers (const std::string &var_name)
 Return the essential boundary attribute marker array for a given trial variable. More...
 
virtual bool IsComplex () const
 
virtual bool IsEigen () const
 
bool IsMultivariate () const
 
bool IsNonlinear () const
 
virtual void BuildEquationSystem ()
 Build all forms comprising this EquationSystem. More...
 

Protected Member Functions

virtual void BuildBilinearForms () override
 Build bilinear forms (diagonal Jacobian contributions) More...
 
virtual void BuildMixedBilinearForms () override
 Build mixed bilinear forms (off-diagonal Jacobian contributions) More...
 
virtual void BuildNonlinearForms () override
 Build non-linear action forms. More...
 
virtual void EliminateCoupledVariables () override
 Perform trivial eliminations of coupled variables lacking corresponding test variables. More...
 
virtual void AddCoupledVariableNameIfMissing (const std::string &coupled_var_name)
 Add coupled variable to EquationSystem. More...
 
virtual void AddEliminatedVariableNameIfMissing (const std::string &eliminated_var_name)
 Add eliminated variable to EquationSystem. More...
 
virtual void AddTestVariableNameIfMissing (const std::string &test_var_name)
 Add test variable to EquationSystem. More...
 
virtual void SetTrialVariableNames ()
 Set trial variable names from subset of coupled variables that have an associated test variable. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual void ApplyEssentialBCs ()
 Update all essentially constrained true DoF markers and values on boundaries. More...
 
virtual void BuildLinearForms ()
 Build linear forms and eliminate constrained DoFs. More...
 
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. More...
 
virtual void FormSystemOperator (mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
 Form matrix-free representation of linear components of system operator. More...
 
virtual void FormSystemMatrix (mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
 Form matrix representation of linear components of system operator as a HypreParMatrix. More...
 
void FormJacobianMatrix (const mfem::Vector &u)
 Compute Jacobian matrix at the provided vector of true DoFs of trial variables. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Protected Attributes

mfem::real_t _dt
 Timestep size. More...
 
Moose::MFEM::NamedFieldsMap< Moose::MFEM::NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _td_kernels_map
 
Moose::MFEM::NamedFieldsMap< mfem::ParBilinearForm > _td_blfs
 Containers to store contributions to weak form of the form (F du/dt, v) More...
 
Moose::MFEM::NamedFieldsMap< Moose::MFEM::NamedFieldsMap< mfem::ParMixedBilinearForm > > _td_mblfs
 
const Moose::MFEM::TimeDerivativeMap_time_derivative_map
 Map between variable names and their time derivatives. More...
 
std::vector< std::string > _coupled_var_names
 Names of all trial variables of kernels and boundary conditions added to this EquationSystem. More...
 
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. More...
 
std::vector< std::string > _eliminated_var_names
 Names of all coupled variables without a corresponding test variable. More...
 
Moose::MFEM::GridFunctions _eliminated_variables
 Pointers to coupled variables not part of the reduced EquationSystem. More...
 
std::vector< std::string > _test_var_names
 Names of all test variables corresponding to linear forms in this equation system. More...
 
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
 Pointers to finite element spaces associated with test variables. More...
 
std::vector< mfem::ParFiniteElementSpace * > _coupled_pfespaces
 Pointers to finite element spaces associated with coupled variables. More...
 
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. More...
 
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. More...
 
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > _integrated_bc_map
 Arrays to store integrated BCs to act on each component of weak form. More...
 
NamedFieldsMap< std::vector< std::shared_ptr< MFEMEssentialBC > > > _essential_bc_map
 Arrays to store essential BCs to act on each component of weak form. More...
 
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
 

Friends

class TimeDependentEquationSystemProblemOperator
 

Detailed Description

Class to store weak form components for time dependent PDEs.

Definition at line 21 of file TimeDependentEquationSystem.h.

Constructor & Destructor Documentation

◆ TimeDependentEquationSystem()

Moose::MFEM::TimeDependentEquationSystem::TimeDependentEquationSystem ( const Moose::MFEM::TimeDerivativeMap time_derivative_map)

Definition at line 16 of file TimeDependentEquationSystem.C.

18  : _dt(1.0), _time_derivative_map(time_derivative_map)
19 {
20 }
const Moose::MFEM::TimeDerivativeMap & _time_derivative_map
Map between variable names and their time derivatives.

Member Function Documentation

◆ AddCoupledVariableNameIfMissing()

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

Add coupled variable to EquationSystem.

Definition at line 57 of file EquationSystem.C.

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

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

◆ AddEliminatedVariableNameIfMissing()

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

Add eliminated variable to EquationSystem.

Definition at line 64 of file EquationSystem.C.

Referenced by AddKernel().

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

◆ AddEssentialBC()

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

Add BC associated with essentially constrained DoFs on boundaries.

Definition at line 139 of file EquationSystem.C.

Referenced by MFEMProblem::addBoundaryCondition().

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.
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
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.
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)
virtualinherited

Definition at line 116 of file EquationSystem.C.

Referenced by MFEMProblem::addBoundaryCondition().

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 AddTestVariableNameIfMissing(const std::string &test_var_name)
Add test 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.
virtual void AddCoupledVariableNameIfMissing(const std::string &coupled_var_name)
Add coupled variable to EquationSystem.

◆ AddKernel()

void Moose::MFEM::TimeDependentEquationSystem::AddKernel ( std::shared_ptr< MFEMKernel kernel)
overridevirtual

Add kernels.

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 23 of file TimeDependentEquationSystem.C.

24 {
25  if (!_time_derivative_map.isTimeDerivative(kernel->getTrialVariableName()))
26  {
28  return;
29  }
30 
31  const auto & trial_var_name =
32  _time_derivative_map.getTimeIntegralName(kernel->getTrialVariableName());
33  const auto & test_var_name = kernel->getTestVariableName();
34  AddEliminatedVariableNameIfMissing(trial_var_name);
35  AddTestVariableNameIfMissing(test_var_name);
36  // Register new td kernels map if not present for the test variable
37  if (!_td_kernels_map.Has(test_var_name))
38  {
39  auto kernel_field_map =
40  std::make_shared<Moose::MFEM::NamedFieldsMap<std::vector<std::shared_ptr<MFEMKernel>>>>();
41  _td_kernels_map.Register(test_var_name, std::move(kernel_field_map));
42  }
43  // Register new td kernels map if not present for the test/trial variable pair
44  if (!_td_kernels_map.Get(test_var_name)->Has(trial_var_name))
45  {
46  auto kernels = std::make_shared<std::vector<std::shared_ptr<MFEMKernel>>>();
47  _td_kernels_map.Get(test_var_name)->Register(trial_var_name, std::move(kernels));
48  }
49  _td_kernels_map.GetRef(test_var_name).Get(trial_var_name)->push_back(std::move(kernel));
50 }
virtual void AddTestVariableNameIfMissing(const std::string &test_var_name)
Add test variable to EquationSystem.
virtual void AddKernel(std::shared_ptr< MFEMKernel > kernel)
Add kernels.
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
Moose::MFEM::NamedFieldsMap< Moose::MFEM::NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _td_kernels_map
bool isTimeDerivative(const std::string &time_derivative_var_name) const
const std::string & getTimeIntegralName(const std::string &time_derivative_var_name) const
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...
void Register(const std::string &field_name, FieldArgs &&... args)
Construct new field with name field_name and register.
const Moose::MFEM::TimeDerivativeMap & _time_derivative_map
Map between variable names and their time derivatives.
virtual void AddEliminatedVariableNameIfMissing(const std::string &eliminated_var_name)
Add eliminated variable to EquationSystem.
T & GetRef(const std::string &field_name) const
Returns a reference to a field.

◆ AddTestVariableNameIfMissing()

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

Add test variable to EquationSystem.

Definition at line 71 of file EquationSystem.C.

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

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

◆ 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 
)
protectedinherited

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

Definition at line 385 of file EquationSystem.h.

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

◆ 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 
)
protectedinherited

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

Definition at line 649 of file EquationSystem.C.

Referenced by Moose::MFEM::EquationSystem::BuildLinearForms().

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

◆ 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 
)
protectedinherited

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

Definition at line 674 of file EquationSystem.C.

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

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

◆ 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 
)
protectedinherited

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

Definition at line 357 of file EquationSystem.h.

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

◆ 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 
)
protectedinherited

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

Definition at line 594 of file EquationSystem.C.

Referenced by Moose::MFEM::EquationSystem::BuildLinearForms().

598 {
599  if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(test_var_name))
600  {
601  auto kernels = kernels_map.GetRef(test_var_name).GetRef(test_var_name);
602  for (auto & kernel : kernels)
603  {
604  mfem::LinearFormIntegrator * integ = kernel->createLFIntegrator();
605 
606  if (integ)
607  {
608  kernel->isSubdomainRestricted()
609  ? form->AddDomainIntegrator(std::move(integ), kernel->getSubdomainMarkers())
610  : form->AddDomainIntegrator(std::move(integ));
611  }
612  }
613  }
614 }

◆ 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 
)
protectedinherited

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

Definition at line 617 of file EquationSystem.C.

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

622 {
623  if (kernels_map.Has(test_var_name))
624  for (const auto & [trial_var_name, kernels] : kernels_map.GetRef(test_var_name))
625  for (auto & kernel : *kernels)
626  if (auto * integ = kernel->createNLIntegrator())
627  {
628  if (_gradient_required && (trial_var_name != test_var_name))
629  mooseError("Support for off-diagonal MFEM nonlinear domain integrators in conjunction "
630  "with a nonlinear solver that requires a gradient is not currently "
631  "implemented. Kernel '",
632  kernel->name(),
633  "' contributes to test variable '",
634  test_var_name,
635  "' from trial variable '",
636  trial_var_name,
637  "'.");
638 
639  _non_linear = true;
640  if (scale_factor.has_value())
641  integ = new NLScaleIntegrator(integ, scale_factor.value(), true);
642  kernel->isSubdomainRestricted()
643  ? form->AddDomainIntegrator(std::move(integ), kernel->getSubdomainMarkers())
644  : form->AddDomainIntegrator(std::move(integ));
645  }
646 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311

◆ ApplyEssentialBC()

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

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.

Referenced by Moose::MFEM::EquationSystem::ApplyEssentialBCs().

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 }
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
NamedFieldsMap< std::vector< std::shared_ptr< MFEMEssentialBC > > > _essential_bc_map
Arrays to store essential BCs to act on each component of weak form.
IntRange< T > make_range(T beg, T end)
T & GetRef(const std::string &field_name) const
Returns a reference to a field.

◆ ApplyEssentialBCs()

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

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.

Referenced by Moose::MFEM::EquationSystem::BuildLinearForms().

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  _ess_markers.at(i).SetSize(trial_gf.ParFESpace()->GetParMesh()->bdr_attributes.Max(), 0);
238  // Set strongly constrained DoFs of trial_gf on essential boundaries and add markers for all
239  // essential boundaries to the _ess_markers array
240  ApplyEssentialBC(trial_var_name, trial_gf, _ess_markers.at(i));
241  trial_gf.ParFESpace()->GetEssentialTrueDofs(_ess_markers.at(i), _ess_tdof_lists.at(i));
242  }
243 }
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
T & GetRef(const std::string &field_name) const
Returns a reference to a field.
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...
auto index_range(const T &sizable)
Moose::MFEM::GridFunctions * _gfuncs

◆ BuildBilinearFormForFESpace()

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

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 716 of file EquationSystem.C.

719 {
720  auto blf = std::make_shared<mfem::ParBilinearForm>(&fespace);
721  blf->SetAssemblyLevel(assembly_level);
722  ApplyBoundaryBLFIntegrators<mfem::ParBilinearForm>(var_name, var_name, blf, _integrated_bc_map);
723  ApplyDomainBLFIntegrators<mfem::ParBilinearForm>(var_name, var_name, blf, _kernels_map);
724  blf->Assemble();
725  return blf;
726 }
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< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _kernels_map
Arrays to store kernels to act on each component of weak form.

◆ BuildBilinearForms()

void Moose::MFEM::TimeDependentEquationSystem::BuildBilinearForms ( )
overrideprotectedvirtual

Build bilinear forms (diagonal Jacobian contributions)

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 53 of file TimeDependentEquationSystem.C.

54 {
55  // Register bilinear forms
56  for (const auto i : index_range(_test_var_names))
57  {
58  const auto & test_var_name = _test_var_names.at(i);
59 
60  // Apply kernels to blf
61  _blfs.Register(test_var_name, std::make_shared<mfem::ParBilinearForm>(_test_pfespaces.at(i)));
62  auto blf = _blfs.GetShared(test_var_name);
63  blf->SetAssemblyLevel(_assembly_level);
64  ApplyBoundaryBLFIntegrators<mfem::ParBilinearForm>(
65  test_var_name, test_var_name, blf, _integrated_bc_map, _dt);
66  ApplyDomainBLFIntegrators<mfem::ParBilinearForm>(
67  test_var_name, test_var_name, blf, _kernels_map, _dt);
68  // Apply dt*du/dt contributions from the operator on the trial variable
69  ApplyDomainBLFIntegrators<mfem::ParBilinearForm>(
70  test_var_name, test_var_name, blf, _td_kernels_map);
71  // Assemble
72  blf->Assemble();
73 
74  // Apply kernels to td_blf
75  _td_blfs.Register(test_var_name,
76  std::make_shared<mfem::ParBilinearForm>(_test_pfespaces.at(i)));
77  auto td_blf = _td_blfs.GetShared(test_var_name);
78  td_blf->SetAssemblyLevel(_assembly_level);
79  ApplyDomainBLFIntegrators<mfem::ParBilinearForm>(
80  test_var_name, test_var_name, td_blf, _td_kernels_map);
81  // Assemble
82  td_blf->Assemble();
83  }
84 }
NamedFieldsMap< mfem::ParBilinearForm > _blfs
Moose::MFEM::NamedFieldsMap< Moose::MFEM::NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _td_kernels_map
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > _integrated_bc_map
Arrays to store integrated BCs to act on each component of weak form.
mfem::AssemblyLevel _assembly_level
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
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...
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _kernels_map
Arrays to store kernels to act on each component of weak form.
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
void Register(const std::string &field_name, FieldArgs &&... args)
Construct new field with name field_name and register.
Moose::MFEM::NamedFieldsMap< mfem::ParBilinearForm > _td_blfs
Containers to store contributions to weak form of the form (F du/dt, v)
auto index_range(const T &sizable)

◆ BuildEquationSystem()

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

Build all forms comprising this EquationSystem.

Reimplemented in Moose::MFEM::ComplexEquationSystem.

Definition at line 585 of file EquationSystem.C.

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

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

◆ BuildLinearForms()

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

Build linear forms and eliminate constrained DoFs.

Reimplemented in Moose::MFEM::ComplexEquationSystem.

Definition at line 482 of file EquationSystem.C.

Referenced by Moose::MFEM::EquationSystem::BuildEquationSystem().

483 {
484  // Register linear forms
485  for (const auto i : index_range(_test_var_names))
486  {
487  auto test_var_name = _test_var_names.at(i);
488  _lfs.Register(test_var_name, std::make_shared<mfem::ParLinearForm>(_test_pfespaces.at(i)));
489  _lfs.GetRef(test_var_name) = 0.0;
490  }
491 
492  for (auto & test_var_name : _test_var_names)
493  {
494  // Apply kernels
495  auto lf = _lfs.GetShared(test_var_name);
496  ApplyDomainLFIntegrators(test_var_name, lf, _kernels_map);
498  lf->Assemble();
499  }
500 
501  // Apply essential boundary conditions
503 
504  // Eliminate trivially eliminated variables by subtracting contributions from linear forms
506 }
virtual void EliminateCoupledVariables()
Perform trivial eliminations of coupled variables lacking corresponding test variables.
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > _integrated_bc_map
Arrays to store integrated BCs to act on each component of weak form.
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
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...
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _kernels_map
Arrays to store kernels to act on each component of weak form.
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
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...
void Register(const std::string &field_name, FieldArgs &&... args)
Construct new field with name field_name and register.
NamedFieldsMap< mfem::ParLinearForm > _lfs
virtual void ApplyEssentialBCs()
Update all essentially constrained true DoF markers and values on boundaries.
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 ...
T & GetRef(const std::string &field_name) const
Returns a reference to a field.
auto index_range(const T &sizable)

◆ BuildMixedBilinearForms()

void Moose::MFEM::TimeDependentEquationSystem::BuildMixedBilinearForms ( )
overrideprotectedvirtual

Build mixed bilinear forms (off-diagonal Jacobian contributions)

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 87 of file TimeDependentEquationSystem.C.

88 {
89  // Register mixed bilinear forms. Note that not all combinations may
90  // have a kernel.
91 
92  // Create mblf for each test/coupled variable pair with an added kernel.
93  // Mixed bilinear forms with coupled variables that are not trial variables are
94  // associated with contributions from eliminated variables.
95  for (const auto i : index_range(_test_var_names))
96  {
97  const auto & test_var_name = _test_var_names.at(i);
98  auto test_mblfs = std::make_shared<Moose::MFEM::NamedFieldsMap<mfem::ParMixedBilinearForm>>();
99  for (const auto j : index_range(_coupled_var_names))
100  {
101  const auto & coupled_var_name = _coupled_var_names.at(j);
102  auto mblf = std::make_shared<mfem::ParMixedBilinearForm>(_coupled_pfespaces.at(j),
103  _test_pfespaces.at(i));
104  // Register MixedBilinearForm if kernels exist for it, and assemble kernels
105  if (test_var_name != coupled_var_name)
106  {
107  // Apply all mixed kernels with this test/trial pair
108  ApplyBoundaryBLFIntegrators<mfem::ParMixedBilinearForm>(
109  coupled_var_name, test_var_name, mblf, _integrated_bc_map, _dt);
110  ApplyDomainBLFIntegrators<mfem::ParMixedBilinearForm>(
111  coupled_var_name, test_var_name, mblf, _kernels_map, _dt);
112  // Apply dt*du/dt contributions from the operator on the trial variable
113  ApplyDomainBLFIntegrators<mfem::ParMixedBilinearForm>(
114  coupled_var_name, test_var_name, mblf, _td_kernels_map);
115  if (mblf->GetDBFI()->Size() || mblf->GetBBFI()->Size())
116  {
117  // Assemble mixed bilinear forms
118  mblf->SetAssemblyLevel(_assembly_level);
119  mblf->Assemble();
120  // Register mixed bilinear forms associated with a single trial variable
121  // for the current test variable
122  test_mblfs->Register(coupled_var_name, mblf);
123  }
124  }
125  }
126  // Register all mixed bilinear form sets associated with a single test variable
127  _mblfs.Register(test_var_name, test_mblfs);
128  }
129 
130  // Register mixed bilinear forms. Note that not all combinations may
131  // have a kernel.
132 
133  // Create mblf for each test/trial variable pair with an added kernel
134  for (const auto i : index_range(_test_var_names))
135  {
136  const auto & test_var_name = _test_var_names.at(i);
137  auto test_td_mblfs =
138  std::make_shared<Moose::MFEM::NamedFieldsMap<mfem::ParMixedBilinearForm>>();
139  for (const auto j : index_range(_trial_var_names))
140  {
141  const auto & trial_var_name = _trial_var_names.at(j);
142  auto td_mblf = std::make_shared<mfem::ParMixedBilinearForm>(_test_pfespaces.at(j),
143  _test_pfespaces.at(i));
144  // Register MixedBilinearForm if kernels exist for it, and assemble kernels
145  if (test_var_name != trial_var_name)
146  {
147  // Apply all mixed kernels with this test/trial pair
148  ApplyDomainBLFIntegrators<mfem::ParMixedBilinearForm>(
149  trial_var_name, test_var_name, td_mblf, _td_kernels_map);
150  // Assemble mixed bilinear form
151  if (td_mblf->GetDBFI()->Size() || td_mblf->GetBBFI()->Size())
152  {
153  td_mblf->SetAssemblyLevel(_assembly_level);
154  td_mblf->Assemble();
155  // Register mixed bilinear forms associated with a single trial variable
156  // for the current test variable
157  test_td_mblfs->Register(trial_var_name, td_mblf);
158  }
159  }
160  }
161  // Register all mixed bilinear forms associated with a single test variable
162  _td_mblfs.Register(test_var_name, test_td_mblfs);
163  }
164 }
NamedFieldsMap< NamedFieldsMap< mfem::ParMixedBilinearForm > > _mblfs
std::vector< mfem::ParFiniteElementSpace * > _coupled_pfespaces
Pointers to finite element spaces associated with coupled variables.
Moose::MFEM::NamedFieldsMap< Moose::MFEM::NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _td_kernels_map
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMIntegratedBC > > > > _integrated_bc_map
Arrays to store integrated BCs to act on each component of weak form.
Moose::MFEM::NamedFieldsMap< Moose::MFEM::NamedFieldsMap< mfem::ParMixedBilinearForm > > _td_mblfs
mfem::AssemblyLevel _assembly_level
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
std::vector< std::string > _trial_var_names
Subset of _coupled_var_names of all variables corresponding to gridfunctions with degrees of freedom ...
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _kernels_map
Arrays to store kernels to act on each component of weak form.
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
std::vector< std::string > _coupled_var_names
Names of all trial variables of kernels and boundary conditions added to this EquationSystem.
void Register(const std::string &field_name, FieldArgs &&... args)
Construct new field with name field_name and register.
auto index_range(const T &sizable)

◆ BuildNonlinearFormForFESpace()

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

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 729 of file EquationSystem.C.

732 {
733  auto nlf = std::make_shared<mfem::ParNonlinearForm>(&fespace);
734  ApplyDomainNLFIntegrators(var_name, nlf, _kernels_map, std::nullopt);
735  ApplyBoundaryNLFIntegrators(var_name, nlf, _integrated_bc_map, std::nullopt);
736  return nlf;
737 }
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...
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< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _kernels_map
Arrays to store kernels to act on each component of weak form.
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::TimeDependentEquationSystem::BuildNonlinearForms ( )
overrideprotectedvirtual

Build non-linear action forms.

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 167 of file TimeDependentEquationSystem.C.

168 {
169  // Register non-linear Action forms
170  for (const auto i : index_range(_test_var_names))
171  {
172  auto test_var_name = _test_var_names.at(i);
173  _nlfs.Register(test_var_name, std::make_shared<mfem::ParNonlinearForm>(_test_pfespaces.at(i)));
174  // Apply kernels
175  auto nlf = _nlfs.GetShared(test_var_name);
176  nlf->SetEssentialTrueDofs(_ess_tdof_lists.at(i));
177  ApplyDomainNLFIntegrators(test_var_name, nlf, _kernels_map, _dt);
178  ApplyBoundaryNLFIntegrators(test_var_name, nlf, _integrated_bc_map, _dt);
179  }
180 }
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...
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< mfem::ParNonlinearForm > _nlfs
std::vector< mfem::Array< int > > _ess_tdof_lists
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
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...
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMKernel > > > > _kernels_map
Arrays to store kernels to act on each component of weak form.
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
void Register(const std::string &field_name, FieldArgs &&... args)
Construct new field with name field_name and register.
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...
auto index_range(const T &sizable)

◆ ComputeNonlinearResidual()

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

Compute the contribution to the residual from nonlinear forms only.

Definition at line 400 of file EquationSystem.C.

Referenced by Moose::MFEM::EquationSystem::Mult().

401 {
402  mooseAssert(_non_linear, "Should not be calling this method if our forms are not nonlinear");
403  residual = 0.0;
404 
405  const mfem::BlockVector block_solution(const_cast<mfem::Vector &>(sol), _block_true_offsets);
406  SetTrialVariablesFromTrueVectors(block_solution);
407 
408  mfem::BlockVector block_residual(residual, _block_true_offsets);
409  for (unsigned int i = 0; i < _test_var_names.size(); i++)
410  {
411  auto & test_var_name = _test_var_names.at(i);
412  auto nlf = _nlfs.GetShared(test_var_name);
413  nlf->Mult(block_solution.GetBlock(i), block_residual.GetBlock(i));
414  block_residual.GetBlock(i).SyncAliasMemory(block_residual);
415  }
416 }
virtual void SetTrialVariablesFromTrueVectors(const mfem::BlockVector &trueX) const
Update variable from solution vector after solve.
NamedFieldsMap< mfem::ParNonlinearForm > _nlfs
mfem::Array< int > _block_true_offsets
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...
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.

◆ DeleteHBlocks()

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

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.

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

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
IntRange< T > make_range(T beg, T end)
mfem::Array2D< const mfem::HypreParMatrix * > _jacobian_blocks

◆ DeleteJacobianBlocks()

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

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.

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

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 }
mfem::Array2D< const mfem::HypreParMatrix * > _h_blocks
IntRange< T > make_range(T beg, T end)
mfem::Array2D< const mfem::HypreParMatrix * > _jacobian_blocks

◆ EliminateCoupledVariables()

void Moose::MFEM::TimeDependentEquationSystem::EliminateCoupledVariables ( )
overrideprotectedvirtual

Perform trivial eliminations of coupled variables lacking corresponding test variables.

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 183 of file TimeDependentEquationSystem.C.

184 {
185  for (const auto & test_var_name : _test_var_names)
186  {
187  auto & lf = *_lfs.Get(test_var_name) *= _dt;
188  for (const auto & eliminated_var_name : _eliminated_var_names)
189  if (eliminated_var_name == test_var_name)
190  {
191  // if implicit, add contribution to linear form from terms involving state
192  // The AddMult method in mfem::BilinearForm is not defined for non-legacy assembly
193  mfem::Vector lf_prev(lf.Size());
194  auto & td_blf = *_td_blfs.Get(test_var_name);
195  td_blf.Mult(*_eliminated_variables.Get(test_var_name), lf_prev);
196  lf += lf_prev;
197  }
198  else if (_td_mblfs.Has(test_var_name) &&
199  _td_mblfs.Get(test_var_name)->Has(eliminated_var_name))
200  {
201  auto & td_mblf = *_td_mblfs.Get(test_var_name)->Get(eliminated_var_name);
202  td_mblf.AddMult(*_eliminated_variables.Get(eliminated_var_name), lf);
203  }
204  }
205  // Eliminate contributions from other coupled variables.
207 }
virtual void EliminateCoupledVariables()
Perform trivial eliminations of coupled variables lacking corresponding test variables.
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
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.
Moose::MFEM::NamedFieldsMap< Moose::MFEM::NamedFieldsMap< mfem::ParMixedBilinearForm > > _td_mblfs
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...
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
Moose::MFEM::NamedFieldsMap< mfem::ParBilinearForm > _td_blfs
Containers to store contributions to weak form of the form (F du/dt, v)
NamedFieldsMap< mfem::ParLinearForm > _lfs

◆ FormJacobianMatrix()

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

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

Definition at line 419 of file EquationSystem.C.

Referenced by Moose::MFEM::EquationSystem::GetGradient().

420 {
422  _jacobian_blocks.SetSize(_test_var_names.size(), _trial_var_names.size());
423  _jacobian_blocks = nullptr;
424 
425  const mfem::BlockVector update_vector(const_cast<mfem::Vector &>(u), _block_true_offsets);
426  for (const auto i : index_range(_test_var_names))
427  {
428  auto test_var_name = _test_var_names.at(i);
429  if (_nlfs.Has(test_var_name))
430  {
431  auto nlf = _nlfs.Get(test_var_name);
432  mfem::HypreParMatrix * nlf_jac =
433  dynamic_cast<mfem::HypreParMatrix *>(&nlf->GetGradient(update_vector.GetBlock(i)));
434  mooseAssert(nlf_jac,
435  "Jacobian contribution of nonlinear form associated with " + test_var_name +
436  " is not castable into a HypreParMatrix");
437  _jacobian_blocks(i, i) = mfem::ParAdd(_h_blocks(i, i), nlf_jac);
438  }
439  else
440  _jacobian_blocks(i, i) = _h_blocks(i, i);
441  for (const auto j : index_range(_trial_var_names))
442  if (i != j) // nlf->GetGradient only contributes to on-diagonal blocks
443  _jacobian_blocks(i, j) = _h_blocks(i, j);
444  }
445  // Create monolithic matrix
446  _jacobian.Reset(mfem::HypreParMatrixFromBlocks(_jacobian_blocks));
447 }
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
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.
NamedFieldsMap< mfem::ParNonlinearForm > _nlfs
mfem::Array< int > _block_true_offsets
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...
mfem::OperatorHandle _jacobian
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
mfem::Array2D< const mfem::HypreParMatrix * > _h_blocks
auto index_range(const T &sizable)
mfem::Array2D< const mfem::HypreParMatrix * > _jacobian_blocks

◆ FormLinearSystem()

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

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 259 of file EquationSystem.C.

Referenced by Moose::MFEM::EquationSystem::FormSystem().

262 {
263  mooseAssert(_test_var_names.size() == _trial_var_names.size(),
264  "Number of test and trial variables must be the same for block matrix assembly.");
265 
266  if (_assembly_level == mfem::AssemblyLevel::LEGACY)
267  FormSystemMatrix(op, trueX, trueRHS);
268  else
269  FormSystemOperator(op, trueX, trueRHS);
270 }
mfem::AssemblyLevel _assembly_level
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::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
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.

◆ FormSystem()

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

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 367 of file EquationSystem.C.

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

368 {
370  height = trueX.Size();
371  width = trueRHS.Size();
372  // Store block offsets
373  _block_true_offsets.SetSize(trueX.NumBlocks() + 1);
374  _block_true_offsets[0] = 0;
375  for (unsigned i = 0; i < _trial_var_names.size(); i++)
376  _block_true_offsets[i + 1] = trueX.BlockSize(i);
377  _block_true_offsets.PartialSum();
378  FormLinearSystem(_linear_operator, trueX, trueRHS);
379 }
mfem::Array< int > _block_true_offsets
std::vector< std::string > _trial_var_names
Subset of _coupled_var_names of all variables corresponding to gridfunctions with degrees of freedom ...
virtual void BuildEquationSystem()
Build all forms comprising this EquationSystem.
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.
mfem::OperatorHandle _linear_operator

◆ FormSystemMatrix()

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

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 303 of file EquationSystem.C.

Referenced by Moose::MFEM::EquationSystem::FormLinearSystem().

306 {
307  // Allocate block operator
308  DeleteHBlocks();
309  _h_blocks.SetSize(_test_var_names.size(), _trial_var_names.size());
310  _h_blocks = nullptr;
311  // Zero out RHS and sync memory
312  trueRHS = 0.0;
313  trueRHS.SyncToBlocks();
314 
315  for (const auto i : index_range(_test_var_names))
316  {
317  auto test_var_name = _test_var_names.at(i);
318 
319  for (const auto j : index_range(_trial_var_names))
320  {
321  auto trial_var_name = _trial_var_names.at(j);
322 
323  mfem::Vector aux_x, aux_rhs;
324  mfem::ParLinearForm aux_lf(_test_pfespaces.at(i));
325  mfem::HypreParMatrix * aux_a = new mfem::HypreParMatrix;
326 
327  if (test_var_name == trial_var_name)
328  {
329  mooseAssert(i == j, "Trial and test variables must have the same ordering.");
330  auto blf = _blfs.Get(test_var_name);
331  blf->FormLinearSystem(_ess_tdof_lists.at(j),
332  *_var_ess_constraints.at(j),
333  *_lfs.Get(test_var_name),
334  *aux_a,
335  aux_x,
336  aux_rhs,
337  /*copy_interior=*/true);
338  trueX.GetBlock(j) = aux_x;
339  }
340  else if (_mblfs.Has(test_var_name) && _mblfs.Get(test_var_name)->Has(trial_var_name))
341  {
342  auto mblf = _mblfs.Get(test_var_name)->Get(trial_var_name);
343  mblf->FormRectangularLinearSystem(_ess_tdof_lists.at(j),
344  _ess_tdof_lists.at(i),
345  *_var_ess_constraints.at(j),
346  aux_lf = 0,
347  *aux_a,
348  aux_x,
349  aux_rhs);
350  }
351  else
352  continue;
353 
354  trueRHS.GetBlock(i) += aux_rhs;
355  _h_blocks(i, j) = aux_a;
356  }
357  }
358  // Sync memory
359  trueX.SyncFromBlocks();
360  trueRHS.SyncFromBlocks();
361 
362  // Create monolithic matrix
363  op.Reset(mfem::HypreParMatrixFromBlocks(_h_blocks));
364 }
NamedFieldsMap< mfem::ParBilinearForm > _blfs
NamedFieldsMap< NamedFieldsMap< mfem::ParMixedBilinearForm > > _mblfs
std::vector< mfem::Array< int > > _ess_tdof_lists
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
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...
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.
mfem::Array2D< const mfem::HypreParMatrix * > _h_blocks
void DeleteHBlocks()
Deletes the HypreParMatrix associated with any pointer stored in _h_blocks, and then proceeds to dele...
NamedFieldsMap< mfem::ParLinearForm > _lfs
auto index_range(const T &sizable)

◆ FormSystemOperator()

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

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 273 of file EquationSystem.C.

Referenced by Moose::MFEM::EquationSystem::FormLinearSystem().

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

◆ GetBilinearForm()

mfem::ParBilinearForm& Moose::MFEM::EquationSystem::GetBilinearForm ( const std::string &  test_var_name)
inlineinherited
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  }
NamedFieldsMap< mfem::ParBilinearForm > _blfs
T & GetRef(const std::string &field_name) const
Returns a reference to a field.

◆ GetBlockOffsets()

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

Getter for block true offsets associated with the EquationSystem operator.

Definition at line 101 of file EquationSystem.h.

101 { return _block_true_offsets; }
mfem::Array< int > _block_true_offsets

◆ GetEssentialBoundaryMarkers()

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

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 740 of file EquationSystem.C.

741 {
742  for (const auto i : index_range(_trial_var_names))
743  if (_trial_var_names.at(i) == var_name)
744  return _ess_markers.at(i);
745 
746  mooseError("No essential boundary markers found for variable '", var_name, "'.");
747 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::vector< std::string > _trial_var_names
Subset of _coupled_var_names of all variables corresponding to gridfunctions with degrees of freedom ...
std::vector< mfem::Array< int > > _ess_markers
auto index_range(const T &sizable)

◆ GetGradient()

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

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

Definition at line 450 of file EquationSystem.C.

451 {
453 
454  if (_non_linear)
455  {
456  if (_assembly_level != mfem::AssemblyLevel::LEGACY)
457  mooseError("MFEM nonlinear solvers that require GetGradient() currently require legacy "
458  "assembly in EquationSystem.");
459  const_cast<EquationSystem *>(this)->FormJacobianMatrix(u);
460  }
461  else
463 
464  return *_jacobian;
465 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
void FormJacobianMatrix(const mfem::Vector &u)
Compute Jacobian matrix at the provided vector of true DoFs of trial variables.
mfem::AssemblyLevel _assembly_level
mfem::OperatorHandle _jacobian
mfem::OperatorHandle _linear_operator
const mfem::Vector * _linearization_point

◆ GetGridFunction()

mfem::ParGridFunction& Moose::MFEM::EquationSystem::GetGridFunction ( const std::string &  trial_var_name)
inlineinherited
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  }
T & GetRef(const std::string &field_name) const
Returns a reference to a field.
Moose::MFEM::GridFunctions * _gfuncs

◆ GetLinearizationPoint()

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

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

Definition at line 708 of file EquationSystem.C.

709 {
711  mooseError("EquationSystem::GetLinearizationPoint() called before GetGradient().");
712  return *_linearization_point;
713 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
const mfem::Vector * _linearization_point

◆ GetLinearOperator()

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

Get operator handle for linear component of system operator.

Definition at line 80 of file EquationSystem.h.

80 { return _linear_operator; };
mfem::OperatorHandle _linear_operator

◆ GetTestVarNames()

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

Definition at line 98 of file EquationSystem.h.

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

98 { return _test_var_names; }
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.

◆ GetTrialVarNames()

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

Definition at line 97 of file EquationSystem.h.

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

97 { return _trial_var_names; }
std::vector< std::string > _trial_var_names
Subset of _coupled_var_names of all variables corresponding to gridfunctions with degrees of freedom ...

◆ Init()

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

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 }
std::vector< mfem::ParFiniteElementSpace * > _coupled_pfespaces
Pointers to finite element spaces associated with coupled variables.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
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.
mfem::AssemblyLevel _assembly_level
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
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::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.
virtual void SetTrialVariableNames()
Set trial variable names from subset of coupled variables that have an associated test variable...
std::vector< std::string > _coupled_var_names
Names of all trial variables of kernels and boundary conditions added to this EquationSystem.
void Register(const std::string &field_name, FieldArgs &&... args)
Construct new field with name field_name and register.
Moose::MFEM::GridFunctions * _gfuncs

◆ IsComplex()

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

Reimplemented in Moose::MFEM::ComplexEquationSystem.

Definition at line 152 of file EquationSystem.h.

152 { return false; }

◆ IsEigen()

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

Reimplemented in Moose::MFEM::EigenproblemEquationSystem.

Definition at line 154 of file EquationSystem.h.

154 { return false; }

◆ IsMultivariate()

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

Definition at line 158 of file EquationSystem.h.

158 { return _test_var_names.size() > 1; }
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.

◆ IsNonlinear()

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

Definition at line 160 of file EquationSystem.h.

◆ IsTimeDependent()

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

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 29 of file TimeDependentEquationSystem.h.

29 { return true; }

◆ Mult()

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

Compute residual y = Mu.

Definition at line 382 of file EquationSystem.C.

383 {
384  if (_non_linear)
385  {
386  ComputeNonlinearResidual(sol, residual);
387  _linear_operator->AddMult(sol, residual);
388  }
389  else
390  {
391  residual = 0.0;
392  _linear_operator->Mult(sol, residual);
393  }
394 
395  sol.HostRead();
396  residual.HostRead();
397 }
mfem::OperatorHandle _linear_operator
virtual void ComputeNonlinearResidual(const mfem::Vector &u, mfem::Vector &residual) const
Compute the contribution to the residual from nonlinear forms only.

◆ Nonlinear()

bool Moose::MFEM::EquationSystem::Nonlinear ( ) const
inlineinherited
Returns
Whether nonlinear integrators are present

Definition at line 122 of file EquationSystem.h.

◆ SetCoefficientManager()

void Moose::MFEM::EquationSystem::SetCoefficientManager ( CoefficientManager coefficients)
inlineinherited

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)
inlineinherited

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; }

◆ SetTimeStep()

virtual void Moose::MFEM::TimeDependentEquationSystem::SetTimeStep ( mfem::real_t &  dt)
inlinevirtual

◆ SetTrialVariableNames()

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

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

Definition at line 78 of file EquationSystem.C.

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

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)
83  if (VectorContainsName(_coupled_var_names, test_var_name))
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 }
bool VectorContainsName(const std::vector< std::string > &the_vector, const std::string &name) const
std::vector< std::string > _eliminated_var_names
Names of all coupled variables without a corresponding test variable.
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::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
std::vector< std::string > _coupled_var_names
Names of all trial variables of kernels and boundary conditions added to this EquationSystem.

◆ SetTrialVariablesFromTrueVectors()

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

Update variable from solution vector after solve.

Reimplemented in Moose::MFEM::ComplexEquationSystem.

Definition at line 468 of file EquationSystem.C.

Referenced by Moose::MFEM::EquationSystem::ComputeNonlinearResidual().

469 {
470  for (const auto i : index_range(_trial_var_names))
471  {
472  auto & trial_var_name = _trial_var_names.at(i);
473  trueX.GetBlock(i).SyncMemory(trueX);
474  _gfuncs->Get(trial_var_name)->Distribute(&(trueX.GetBlock(i)));
475  }
476  // Solution variables changed: stored projections of solution-dependent coefficients are stale.
479 }
CoefficientManager * _coefficient_manager
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...
void markSolutionChanged()
Notify quadrature function coefficients that solution variables have changed, marking the stored valu...
auto index_range(const T &sizable)
Moose::MFEM::GridFunctions * _gfuncs

◆ VectorContainsName()

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

Definition at line 50 of file EquationSystem.C.

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

52 {
53  return std::find(the_vector.begin(), the_vector.end(), name) != the_vector.end();
54 }
std::string name(const ElemQuality q)
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:40

Friends And Related Function Documentation

◆ TimeDependentEquationSystemProblemOperator

Definition at line 51 of file TimeDependentEquationSystem.h.

Member Data Documentation

◆ _assembly_level

mfem::AssemblyLevel Moose::MFEM::EquationSystem::_assembly_level
protectedinherited

◆ _blfs

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

◆ _block_true_offsets

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

◆ _coefficient_manager

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

◆ _coupled_pfespaces

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

Pointers to finite element spaces associated with coupled variables.

Definition at line 306 of file EquationSystem.h.

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

◆ _coupled_var_names

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

◆ _dt

mfem::real_t Moose::MFEM::TimeDependentEquationSystem::_dt
protected

◆ _eliminated_var_names

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

◆ _eliminated_variables

Moose::MFEM::GridFunctions Moose::MFEM::EquationSystem::_eliminated_variables
protectedinherited

Pointers to coupled variables not part of the reduced EquationSystem.

Definition at line 300 of file EquationSystem.h.

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

◆ _ess_markers

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

◆ _ess_tdof_lists

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

◆ _essential_bc_map

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

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

Named according to test variable.

Definition at line 328 of file EquationSystem.h.

Referenced by Moose::MFEM::EquationSystem::AddEssentialBC(), and Moose::MFEM::EquationSystem::ApplyEssentialBC().

◆ _gfuncs

Moose::MFEM::GridFunctions* Moose::MFEM::EquationSystem::_gfuncs
protectedinherited

◆ _gradient_required

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

◆ _h_blocks

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

◆ _integrated_bc_map

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

◆ _jacobian

mfem::OperatorHandle Moose::MFEM::EquationSystem::_jacobian
mutableprotectedinherited

◆ _jacobian_blocks

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

◆ _kernels_map

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

◆ _lfs

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

◆ _linear_operator

mfem::OperatorHandle Moose::MFEM::EquationSystem::_linear_operator
mutableprotectedinherited

◆ _linearization_point

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

◆ _mblfs

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

◆ _nlfs

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

◆ _non_linear

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

◆ _td_blfs

Moose::MFEM::NamedFieldsMap<mfem::ParBilinearForm> Moose::MFEM::TimeDependentEquationSystem::_td_blfs
protected

Containers to store contributions to weak form of the form (F du/dt, v)

Definition at line 43 of file TimeDependentEquationSystem.h.

Referenced by BuildBilinearForms(), and EliminateCoupledVariables().

◆ _td_kernels_map

Moose::MFEM::NamedFieldsMap<Moose::MFEM::NamedFieldsMap<std::vector<std::shared_ptr<MFEMKernel> > > > Moose::MFEM::TimeDependentEquationSystem::_td_kernels_map
protected

◆ _td_mblfs

Moose::MFEM::NamedFieldsMap<Moose::MFEM::NamedFieldsMap<mfem::ParMixedBilinearForm> > Moose::MFEM::TimeDependentEquationSystem::_td_mblfs
protected

◆ _test_pfespaces

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

◆ _test_var_names

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

◆ _time_derivative_map

const Moose::MFEM::TimeDerivativeMap& Moose::MFEM::TimeDependentEquationSystem::_time_derivative_map
protected

Map between variable names and their time derivatives.

Definition at line 48 of file TimeDependentEquationSystem.h.

Referenced by AddKernel().

◆ _trial_var_names

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

◆ _var_ess_constraints

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

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