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

#include <ComplexEquationSystem.h>

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

Public Member Functions

 ComplexEquationSystem ()=default
 
 ~ComplexEquationSystem ()=default
 
virtual void Init (GridFunctions &gridfunctions, ComplexGridFunctions &cmplx_gridfunctions, mfem::AssemblyLevel assembly_level) override
 Initialise. More...
 
virtual void Mult (const mfem::Vector &x, mfem::Vector &y) const override
 Nonlinear Mult (Used by Newton-solver not necessarily nonlinear) More...
 
virtual void BuildEquationSystem () override
 Build all forms comprising this EquationSystem. More...
 
virtual void BuildLinearForms () override
 Build linear forms and eliminate constrained DoFs. More...
 
virtual void BuildBilinearForms () override
 Build bilinear forms (diagonal Jacobian contributions) More...
 
virtual void ApplyComplexEssentialBC (const std::string &var_name, mfem::ParComplexGridFunction &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 () override
 Update all essentially constrained true DoF markers and values on boundaries. More...
 
void AddComplexKernel (std::shared_ptr< MFEMComplexKernel > kernel)
 Add complex kernels. More...
 
void AddComplexIntegratedBC (std::shared_ptr< MFEMComplexIntegratedBC > bc)
 Add complex integrated BCs. More...
 
void AddComplexEssentialBCs (std::shared_ptr< MFEMComplexEssentialBC > bc)
 Add complex essential BCs. More...
 
virtual void FormSystemOperator (mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS) override
 Form matrix-free representation of system operator. More...
 
virtual void FormSystemMatrix (mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS) override
 Form matrix representation of system operator as a HypreParMatrix. More...
 
virtual void SetTrialVariablesFromTrueVectors (const mfem::BlockVector &trueX) const override
 Update variable from solution vector after solve. 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< MFEMComplexKernel >>>> &kernels_map)
 Template method for applying BilinearFormIntegrators on domains from kernels to a SesquilinearForm. More...
 
void ApplyDomainLFIntegrators (const std::string &test_var_name, std::shared_ptr< mfem::ParComplexLinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexKernel >>>> &kernels_map)
 Method for applying LinearFormIntegrators on domains from kernels to a ParComplexLinearForm. 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< MFEMComplexIntegratedBC >>>> &integrated_bc_map)
 Template method for applying BilinearFormIntegrators on boudaries from kernels to a SesquilinearForm. More...
 
void ApplyBoundaryLFIntegrators (const std::string &test_var_name, std::shared_ptr< mfem::ParComplexLinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC >>>> &integrated_bc_map)
 Method for applying LinearFormIntegrators on boundaries from kernels to a ParComplexLinearForm. More...
 
virtual bool Complex () const override
 Whether this a complex equation system. More...
 
virtual void AddKernel (std::shared_ptr< MFEMKernel > kernel)
 Add kernels. More...
 
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...
 
void FormSystem (mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
 Assemble the linear part of the operator, assemble the right-hand side, apply essential and eliminated-variable constraints, and populate the true-DoF vectors used by the solve. 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...
 
void SetSolverRequiresGradient (bool requires_gradient)
 Set whether the nonlinear solver driving this equation system requires Jacobian information. More...
 
const std::vector< std::string > & GetTrialVarNames () const
 
const std::vector< std::string > & GetTestVarNames () const
 
bool Nonlinear () const
 
void PrepareLinearSolver (LinearSolverBase &solver)
 Prepare the provided linear solver. More...
 

Protected Member Functions

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 EliminateCoupledVariables ()
 Perform trivial eliminations of coupled variables lacking corresponding test variables. More...
 
virtual void BuildNonlinearForms ()
 Build non-linear action forms. More...
 
virtual void BuildMixedBilinearForms ()
 Build mixed bilinear forms (off-diagonal Jacobian contributions) 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...
 
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

NamedFieldsMap< mfem::ParSesquilinearForm > _slfs
 
NamedFieldsMap< mfem::ParComplexLinearForm > _clfs
 
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexKernel > > > > _cmplx_kernels_map
 
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC > > > > _cmplx_integrated_bc_map
 
NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexEssentialBC > > > _cmplx_essential_bc_map
 
ComplexGridFunctions _cmplx_eliminated_variables
 Pointers to coupled variables not part of the reduced EquationSystem. More...
 
std::vector< std::unique_ptr< mfem::ParComplexGridFunction > > _cmplx_var_ess_constraints
 Complex Gridfunctions holding essential constraints from Dirichlet BCs. More...
 
Moose::MFEM::ComplexGridFunctions_complex_gfuncs
 
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
 
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
 
bool _non_linear = false
 
bool _solver_requires_gradient = false
 

Detailed Description

Definition at line 19 of file ComplexEquationSystem.h.

Constructor & Destructor Documentation

◆ ComplexEquationSystem()

Moose::MFEM::ComplexEquationSystem::ComplexEquationSystem ( )
default

◆ ~ComplexEquationSystem()

Moose::MFEM::ComplexEquationSystem::~ComplexEquationSystem ( )
default

Member Function Documentation

◆ AddComplexEssentialBCs()

void Moose::MFEM::ComplexEquationSystem::AddComplexEssentialBCs ( std::shared_ptr< MFEMComplexEssentialBC bc)

Add complex essential BCs.

Definition at line 197 of file ComplexEquationSystem.C.

Referenced by MFEMProblem::addBoundaryCondition().

198 {
199  const auto & test_var_name = bc->getTestVariableName();
200  AddTestVariableNameIfMissing(test_var_name);
201  // Register new complex essential bc map if not present for the test variable
202  if (!_cmplx_essential_bc_map.Has(test_var_name))
203  {
204  auto bcs = std::make_shared<std::vector<std::shared_ptr<MFEMComplexEssentialBC>>>();
205  _cmplx_essential_bc_map.Register(test_var_name, std::move(bcs));
206  }
207  _cmplx_essential_bc_map.GetRef(test_var_name).push_back(std::move(bc));
208 }
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< MFEMComplexEssentialBC > > > _cmplx_essential_bc_map
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.

◆ AddComplexIntegratedBC()

void Moose::MFEM::ComplexEquationSystem::AddComplexIntegratedBC ( std::shared_ptr< MFEMComplexIntegratedBC bc)

Add complex integrated BCs.

Definition at line 174 of file ComplexEquationSystem.C.

Referenced by MFEMProblem::addBoundaryCondition().

175 {
176  const auto & trial_var_name = bc->getTrialVariableName();
177  const auto & test_var_name = bc->getTestVariableName();
178  AddCoupledVariableNameIfMissing(trial_var_name);
179  AddTestVariableNameIfMissing(test_var_name);
180  // Register new complex integrated bc map if not present for the test variable
181  if (!_cmplx_integrated_bc_map.Has(test_var_name))
182  {
183  auto integrated_bc_field_map =
184  std::make_shared<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>>();
185  _cmplx_integrated_bc_map.Register(test_var_name, std::move(integrated_bc_field_map));
186  }
187  // Register new complex integrated bc map if not present for the test/trial variable pair
188  if (!_cmplx_integrated_bc_map.Get(test_var_name)->Has(trial_var_name))
189  {
190  auto bcs = std::make_shared<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>();
191  _cmplx_integrated_bc_map.Get(test_var_name)->Register(trial_var_name, std::move(bcs));
192  }
193  _cmplx_integrated_bc_map.GetRef(test_var_name).Get(trial_var_name)->push_back(std::move(bc));
194 }
virtual void AddTestVariableNameIfMissing(const std::string &test_var_name)
Add test variable to EquationSystem.
virtual void AddCoupledVariableNameIfMissing(const std::string &coupled_var_name)
Add coupled variable to EquationSystem.
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC > > > > _cmplx_integrated_bc_map

◆ AddComplexKernel()

void Moose::MFEM::ComplexEquationSystem::AddComplexKernel ( std::shared_ptr< MFEMComplexKernel kernel)

Add complex kernels.

Definition at line 151 of file ComplexEquationSystem.C.

Referenced by MFEMProblem::addKernel().

152 {
153  const auto & trial_var_name = kernel->getTrialVariableName();
154  const auto & test_var_name = kernel->getTestVariableName();
155  AddCoupledVariableNameIfMissing(trial_var_name);
156  AddTestVariableNameIfMissing(test_var_name);
157  // Register new complex kernels map if not present for the test variable
158  if (!_cmplx_kernels_map.Has(test_var_name))
159  {
160  auto kernel_field_map =
161  std::make_shared<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>>();
162  _cmplx_kernels_map.Register(test_var_name, std::move(kernel_field_map));
163  }
164  // Register new complex kernels map if not present for the test/trial variable pair
165  if (!_cmplx_kernels_map.Get(test_var_name)->Has(trial_var_name))
166  {
167  auto kernels = std::make_shared<std::vector<std::shared_ptr<MFEMComplexKernel>>>();
168  _cmplx_kernels_map.Get(test_var_name)->Register(trial_var_name, std::move(kernels));
169  }
170  _cmplx_kernels_map.GetRef(test_var_name).Get(trial_var_name)->push_back(std::move(kernel));
171 }
virtual void AddTestVariableNameIfMissing(const std::string &test_var_name)
Add test variable to EquationSystem.
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexKernel > > > > _cmplx_kernels_map
virtual void AddCoupledVariableNameIfMissing(const std::string &coupled_var_name)
Add coupled variable to EquationSystem.

◆ AddCoupledVariableNameIfMissing()

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

Add coupled variable to EquationSystem.

Definition at line 56 of file EquationSystem.C.

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

57 {
58  if (!VectorContainsName(_coupled_var_names, coupled_var_name))
59  _coupled_var_names.push_back(coupled_var_name);
60 }
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 63 of file EquationSystem.C.

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

64 {
65  if (!VectorContainsName(_eliminated_var_names, eliminated_var_name))
66  _eliminated_var_names.push_back(eliminated_var_name);
67 }
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 138 of file EquationSystem.C.

Referenced by MFEMProblem::addBoundaryCondition().

139 {
140  const auto & test_var_name = bc->getTestVariableName();
141  AddTestVariableNameIfMissing(test_var_name);
142  // Register new essential bc map if not present for the test variable
143  if (!_essential_bc_map.Has(test_var_name))
144  {
145  auto bcs = std::make_shared<std::vector<std::shared_ptr<MFEMEssentialBC>>>();
146  _essential_bc_map.Register(test_var_name, std::move(bcs));
147  }
148  _essential_bc_map.GetRef(test_var_name).push_back(std::move(bc));
149 }
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 115 of file EquationSystem.C.

Referenced by MFEMProblem::addBoundaryCondition().

116 {
117  const auto & trial_var_name = bc->getTrialVariableName();
118  const auto & test_var_name = bc->getTestVariableName();
119  AddCoupledVariableNameIfMissing(trial_var_name);
120  AddTestVariableNameIfMissing(test_var_name);
121  // Register new integrated bc map if not present for the test variable
122  if (!_integrated_bc_map.Has(test_var_name))
123  {
124  auto integrated_bc_field_map = std::make_shared<
126  _integrated_bc_map.Register(test_var_name, std::move(integrated_bc_field_map));
127  }
128  // Register new integrated bc map if not present for the test/trial variable pair
129  if (!_integrated_bc_map.Get(test_var_name)->Has(trial_var_name))
130  {
131  auto bcs = std::make_shared<std::vector<std::shared_ptr<MFEMIntegratedBC>>>();
132  _integrated_bc_map.Get(test_var_name)->Register(trial_var_name, std::move(bcs));
133  }
134  _integrated_bc_map.GetRef(test_var_name).Get(trial_var_name)->push_back(std::move(bc));
135 }
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::EquationSystem::AddKernel ( std::shared_ptr< MFEMKernel kernel)
virtualinherited

Add kernels.

Reimplemented in Moose::MFEM::TimeDependentEquationSystem.

Definition at line 92 of file EquationSystem.C.

Referenced by Moose::MFEM::TimeDependentEquationSystem::AddKernel(), and MFEMProblem::addKernel().

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

◆ AddTestVariableNameIfMissing()

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

Add test variable to EquationSystem.

Definition at line 70 of file EquationSystem.C.

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

71 {
72  if (!VectorContainsName(_test_var_names, test_var_name))
73  _test_var_names.push_back(test_var_name);
74 }
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() [1/2]

template<class FormType >
void Moose::MFEM::ComplexEquationSystem::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< MFEMComplexIntegratedBC >>>> &  integrated_bc_map 
)

Template method for applying BilinearFormIntegrators on boudaries from kernels to a SesquilinearForm.

Definition at line 187 of file ComplexEquationSystem.h.

193 {
194  if (integrated_bc_map.Has(test_var_name) &&
195  integrated_bc_map.Get(test_var_name)->Has(trial_var_name))
196  {
197  auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(trial_var_name);
198  for (auto & bc : bcs)
199  {
200  mfem::BilinearFormIntegrator * integ_real = bc->getRealBFIntegrator();
201  mfem::BilinearFormIntegrator * integ_imag = bc->getImagBFIntegrator();
202 
203  if (integ_real || integ_imag)
204  {
205  bc->isBoundaryRestricted()
206  ? form->AddBoundaryIntegrator(
207  std::move(integ_real), std::move(integ_imag), bc->getBoundaryMarkers())
208  : form->AddBoundaryIntegrator(std::move(integ_real), std::move(integ_imag));
209  }
210  }
211  }
212 }

◆ ApplyBoundaryBLFIntegrators() [2/2]

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 311 of file EquationSystem.h.

318 {
319  if (integrated_bc_map.Has(test_var_name) &&
320  integrated_bc_map.Get(test_var_name)->Has(trial_var_name))
321  {
322  auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(trial_var_name);
323  for (auto & bc : bcs)
324  {
325  mfem::BilinearFormIntegrator * integ = bc->createBFIntegrator();
326 
327  if (integ)
328  {
329  if (scale_factor.has_value())
330  integ = new ScaleIntegrator(integ, scale_factor.value(), true);
331  bc->isBoundaryRestricted()
332  ? form->AddBoundaryIntegrator(std::move(integ), bc->getBoundaryMarkers())
333  : form->AddBoundaryIntegrator(std::move(integ));
334  }
335  }
336  }
337 }

◆ ApplyBoundaryLFIntegrators() [1/2]

void Moose::MFEM::ComplexEquationSystem::ApplyBoundaryLFIntegrators ( const std::string &  test_var_name,
std::shared_ptr< mfem::ParComplexLinearForm >  form,
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC >>>> &  integrated_bc_map 
)
inline

Method for applying LinearFormIntegrators on boundaries from kernels to a ParComplexLinearForm.

Definition at line 215 of file ComplexEquationSystem.h.

Referenced by BuildLinearForms().

220 {
221  if (integrated_bc_map.Has(test_var_name))
222  {
223  auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(test_var_name);
224  for (auto & bc : bcs)
225  {
226  mfem::LinearFormIntegrator * integ_real = bc->getRealLFIntegrator();
227  mfem::LinearFormIntegrator * integ_imag = bc->getImagLFIntegrator();
228 
229  if (integ_real || integ_imag)
230  {
231  bc->isBoundaryRestricted()
232  ? form->AddBoundaryIntegrator(
233  std::move(integ_real), std::move(integ_imag), bc->getBoundaryMarkers())
234  : form->AddBoundaryIntegrator(std::move(integ_real), std::move(integ_imag));
235  }
236  }
237  }
238 }

◆ ApplyBoundaryLFIntegrators() [2/2]

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

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

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

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

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

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

◆ ApplyComplexEssentialBC()

void Moose::MFEM::ComplexEquationSystem::ApplyComplexEssentialBC ( const std::string &  var_name,
mfem::ParComplexGridFunction &  trial_gf,
mfem::Array< int > &  global_ess_markers 
)
virtual

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 106 of file ComplexEquationSystem.C.

Referenced by ApplyEssentialBCs().

109 {
110  if (_cmplx_essential_bc_map.Has(var_name))
111  {
112  auto & bcs = _cmplx_essential_bc_map.GetRef(var_name);
113  for (auto & bc : bcs)
114  {
115  // Set constrained DoFs values on essential boundaries
116  bc->ApplyBC(trial_gf);
117  // Fetch marker array labelling essential boundaries of current BC
118  mfem::Array<int> ess_bdrs(bc->getBoundaryMarkers());
119  // Add these boundary markers to the set of markers labelling all essential boundaries
120  for (const auto i : make_range(trial_gf.ParFESpace()->GetParMesh()->bdr_attributes.Max()))
121  global_ess_markers[i] = std::max(global_ess_markers[i], ess_bdrs[i]);
122  }
123  }
124 }
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
auto max(const L &left, const R &right)
NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexEssentialBC > > > _cmplx_essential_bc_map
IntRange< T > make_range(T beg, T end)
T & GetRef(const std::string &field_name) const
Returns a reference to a field.

◆ ApplyDomainBLFIntegrators() [1/2]

template<class FormType >
void Moose::MFEM::ComplexEquationSystem::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< MFEMComplexKernel >>>> &  kernels_map 
)

Template method for applying BilinearFormIntegrators on domains from kernels to a SesquilinearForm.

Definition at line 135 of file ComplexEquationSystem.h.

140 {
141  if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(trial_var_name))
142  {
143  auto kernels = kernels_map.GetRef(test_var_name).GetRef(trial_var_name);
144  for (auto & kernel : kernels)
145  {
146  mfem::BilinearFormIntegrator * integ_real = kernel->getRealBFIntegrator();
147  mfem::BilinearFormIntegrator * integ_imag = kernel->getImagBFIntegrator();
148 
149  if (integ_real || integ_imag)
150  {
151  kernel->isSubdomainRestricted()
152  ? form->AddDomainIntegrator(
153  std::move(integ_real), std::move(integ_imag), kernel->getSubdomainMarkers())
154  : form->AddDomainIntegrator(std::move(integ_real), std::move(integ_imag));
155  }
156  }
157  }
158 }

◆ ApplyDomainBLFIntegrators() [2/2]

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 283 of file EquationSystem.h.

289 {
290  if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(trial_var_name))
291  {
292  auto kernels = kernels_map.GetRef(test_var_name).GetRef(trial_var_name);
293  for (auto & kernel : kernels)
294  {
295  mfem::BilinearFormIntegrator * integ = kernel->createBFIntegrator();
296 
297  if (integ)
298  {
299  if (scale_factor.has_value())
300  integ = new ScaleIntegrator(integ, scale_factor.value(), true);
301  kernel->isSubdomainRestricted()
302  ? form->AddDomainIntegrator(std::move(integ), kernel->getSubdomainMarkers())
303  : form->AddDomainIntegrator(std::move(integ));
304  }
305  }
306  }
307 }

◆ ApplyDomainLFIntegrators() [1/2]

void Moose::MFEM::ComplexEquationSystem::ApplyDomainLFIntegrators ( const std::string &  test_var_name,
std::shared_ptr< mfem::ParComplexLinearForm >  form,
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexKernel >>>> &  kernels_map 
)
inline

Method for applying LinearFormIntegrators on domains from kernels to a ParComplexLinearForm.

Definition at line 161 of file ComplexEquationSystem.h.

Referenced by BuildLinearForms().

165 {
166  if (kernels_map.Has(test_var_name))
167  {
168  auto kernels = kernels_map.GetRef(test_var_name).GetRef(test_var_name);
169  for (auto & kernel : kernels)
170  {
171  mfem::LinearFormIntegrator * integ_real = kernel->getRealLFIntegrator();
172  mfem::LinearFormIntegrator * integ_imag = kernel->getImagLFIntegrator();
173 
174  if (integ_real || integ_imag)
175  {
176  kernel->isSubdomainRestricted()
177  ? form->AddDomainIntegrator(
178  std::move(integ_real), std::move(integ_imag), kernel->getSubdomainMarkers())
179  : form->AddDomainIntegrator(std::move(integ_real), std::move(integ_imag));
180  }
181  }
182  }
183 }

◆ ApplyDomainLFIntegrators() [2/2]

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

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

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

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

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

623 {
624  if (kernels_map.Has(test_var_name))
625  for (const auto & [trial_var_name, kernels] : kernels_map.GetRef(test_var_name))
626  for (auto & kernel : *kernels)
627  if (auto * integ = kernel->createNLIntegrator())
628  {
629  if (_solver_requires_gradient && (trial_var_name != test_var_name))
630  mooseError("Support for off-diagonal MFEM nonlinear domain integrators in conjunction "
631  "with a nonlinear solver that requires a gradient is not currently "
632  "implemented. Kernel '",
633  kernel->name(),
634  "' contributes to test variable '",
635  test_var_name,
636  "' from trial variable '",
637  trial_var_name,
638  "'.");
639 
640  _non_linear = true;
641  if (scale_factor.has_value())
642  integ = new NLScaleIntegrator(integ, scale_factor.value(), true);
643  kernel->isSubdomainRestricted()
644  ? form->AddDomainIntegrator(std::move(integ), kernel->getSubdomainMarkers())
645  : form->AddDomainIntegrator(std::move(integ));
646  }
647 }
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 207 of file EquationSystem.C.

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

210 {
211  if (_essential_bc_map.Has(var_name))
212  {
213  auto & bcs = _essential_bc_map.GetRef(var_name);
214  for (auto & bc : bcs)
215  {
216  // Set constrained DoFs values on essential boundaries
217  bc->ApplyBC(trial_gf);
218  // Fetch marker array labelling essential boundaries of current BC
219  mfem::Array<int> ess_bdrs(bc->getBoundaryMarkers());
220  // Add these boundary markers to the set of markers labelling all essential boundaries
221  for (const auto i : make_range(trial_gf.ParFESpace()->GetParMesh()->bdr_attributes.Max()))
222  global_ess_markers[i] = std::max(global_ess_markers[i], ess_bdrs[i]);
223  }
224  }
225 }
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.
auto max(const L &left, const R &right)
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::ComplexEquationSystem::ApplyEssentialBCs ( )
overridevirtual

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

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 127 of file ComplexEquationSystem.C.

Referenced by BuildLinearForms().

128 {
129  _ess_tdof_lists.resize(_trial_var_names.size());
130  for (const auto i : index_range(_trial_var_names))
131  {
132  const auto & trial_var_name = _trial_var_names.at(i);
133  mfem::ParComplexGridFunction & trial_gf = *_cmplx_var_ess_constraints.at(i);
134 
135  // Make sure we update the size, if this mesh has changed recently for instance
136  trial_gf.Update();
137 
138  // Initial guess for iterative solvers (initial condition or the previous time step solution)
139  static_cast<mfem::Vector &>(trial_gf) = _complex_gfuncs->GetRef(trial_var_name);
140 
141  mfem::Array<int> global_ess_markers(trial_gf.ParFESpace()->GetParMesh()->bdr_attributes.Max());
142  global_ess_markers = 0;
143  // Set strongly constrained DoFs of trial_gf on essential boundaries and add markers for all
144  // essential boundaries to the global_ess_markers array
145  ApplyComplexEssentialBC(trial_var_name, trial_gf, global_ess_markers);
146  trial_gf.FESpace()->GetEssentialTrueDofs(global_ess_markers, _ess_tdof_lists.at(i));
147  }
148 }
std::vector< std::unique_ptr< mfem::ParComplexGridFunction > > _cmplx_var_ess_constraints
Complex Gridfunctions holding essential constraints from Dirichlet BCs.
virtual void ApplyComplexEssentialBC(const std::string &var_name, mfem::ParComplexGridFunction &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 ...
Moose::MFEM::ComplexGridFunctions * _complex_gfuncs
T & GetRef(const std::string &field_name) const
Returns a reference to a field.
auto index_range(const T &sizable)

◆ BuildBilinearForms()

void Moose::MFEM::ComplexEquationSystem::BuildBilinearForms ( )
overridevirtual

Build bilinear forms (diagonal Jacobian contributions)

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 84 of file ComplexEquationSystem.C.

Referenced by BuildEquationSystem().

85 {
86  // Register bilinear forms
87  for (const auto i : index_range(_test_var_names))
88  {
89  auto test_var_name = _test_var_names.at(i);
90  _slfs.Register(test_var_name,
91  std::make_shared<mfem::ParSesquilinearForm>(_test_pfespaces.at(i)));
92 
93  // Apply kernels
94  auto slf = _slfs.GetShared(test_var_name);
95  slf->SetAssemblyLevel(_assembly_level);
96  ApplyBoundaryBLFIntegrators<mfem::ParSesquilinearForm>(
97  test_var_name, test_var_name, slf, _cmplx_integrated_bc_map);
98  ApplyDomainBLFIntegrators<mfem::ParSesquilinearForm>(
99  test_var_name, test_var_name, slf, _cmplx_kernels_map);
100  // Assemble
101  slf->Assemble();
102  }
103 }
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< MFEMComplexKernel > > > > _cmplx_kernels_map
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.
NamedFieldsMap< mfem::ParSesquilinearForm > _slfs
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC > > > > _cmplx_integrated_bc_map
auto index_range(const T &sizable)

◆ BuildEquationSystem()

void Moose::MFEM::ComplexEquationSystem::BuildEquationSystem ( )
overridevirtual

Build all forms comprising this EquationSystem.

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 53 of file ComplexEquationSystem.C.

54 {
57 }
virtual void BuildLinearForms() override
Build linear forms and eliminate constrained DoFs.
virtual void BuildBilinearForms() override
Build bilinear forms (diagonal Jacobian contributions)

◆ BuildLinearForms()

void Moose::MFEM::ComplexEquationSystem::BuildLinearForms ( )
overridevirtual

Build linear forms and eliminate constrained DoFs.

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 60 of file ComplexEquationSystem.C.

Referenced by BuildEquationSystem().

61 {
62  // Register linear forms
63  for (const auto i : index_range(_test_var_names))
64  {
65  auto test_var_name = _test_var_names.at(i);
66  _clfs.Register(test_var_name,
67  std::make_shared<mfem::ParComplexLinearForm>(_test_pfespaces.at(i)));
68  _clfs.GetRef(test_var_name) = 0.0;
69  }
70  // Apply boundary conditions
72 
73  for (auto & test_var_name : _test_var_names)
74  {
75  // Apply kernels
76  auto clf = _clfs.GetShared(test_var_name);
77  ApplyDomainLFIntegrators(test_var_name, clf, _cmplx_kernels_map);
79  clf->Assemble();
80  }
81 }
NamedFieldsMap< mfem::ParComplexLinearForm > _clfs
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
virtual void ApplyEssentialBCs() override
Update all essentially constrained true DoF markers and values on boundaries.
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< MFEMComplexKernel > > > > _cmplx_kernels_map
void ApplyDomainLFIntegrators(const std::string &test_var_name, std::shared_ptr< mfem::ParComplexLinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexKernel >>>> &kernels_map)
Method for applying LinearFormIntegrators on domains from kernels to a ParComplexLinearForm.
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 ApplyBoundaryLFIntegrators(const std::string &test_var_name, std::shared_ptr< mfem::ParComplexLinearForm > form, NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC >>>> &integrated_bc_map)
Method for applying LinearFormIntegrators on boundaries from kernels to a ParComplexLinearForm.
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC > > > > _cmplx_integrated_bc_map
T & GetRef(const std::string &field_name) const
Returns a reference to a field.
auto index_range(const T &sizable)

◆ BuildMixedBilinearForms()

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

Build mixed bilinear forms (off-diagonal Jacobian contributions)

Reimplemented in Moose::MFEM::TimeDependentEquationSystem.

Definition at line 547 of file EquationSystem.C.

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

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

◆ BuildNonlinearForms()

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

Build non-linear action forms.

Reimplemented in Moose::MFEM::TimeDependentEquationSystem.

Definition at line 510 of file EquationSystem.C.

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

511 {
512  // Register non-linear Action forms
513  for (const auto i : index_range(_test_var_names))
514  {
515  auto test_var_name = _test_var_names.at(i);
516  _nlfs.Register(test_var_name, std::make_shared<mfem::ParNonlinearForm>(_test_pfespaces.at(i)));
517  // Apply kernels
518  auto nlf = _nlfs.GetShared(test_var_name);
519  nlf->SetEssentialTrueDofs(_ess_tdof_lists.at(i));
520  ApplyDomainNLFIntegrators(test_var_name, nlf, _kernels_map, std::nullopt);
521  ApplyBoundaryNLFIntegrators(test_var_name, nlf, _integrated_bc_map, std::nullopt);
522  }
523 }
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)

◆ Complex()

virtual bool Moose::MFEM::ComplexEquationSystem::Complex ( ) const
inlineoverridevirtual

Whether this a complex equation system.

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 107 of file ComplexEquationSystem.h.

107 { return true; }

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

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

407 {
408  mooseAssert(_non_linear, "Should not be calling this method if our forms are not nonlinear");
409  residual = 0.0;
410 
411  const mfem::BlockVector block_solution(const_cast<mfem::Vector &>(sol), _block_true_offsets);
412  SetTrialVariablesFromTrueVectors(block_solution);
413 
414  mfem::BlockVector block_residual(residual, _block_true_offsets);
415  for (unsigned int i = 0; i < _test_var_names.size(); i++)
416  {
417  auto & test_var_name = _test_var_names.at(i);
418  auto nlf = _nlfs.GetShared(test_var_name);
419  nlf->Mult(block_solution.GetBlock(i), block_residual.GetBlock(i));
420  block_residual.GetBlock(i).SyncAliasMemory(block_residual);
421  }
422 }
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 26 of file EquationSystem.C.

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

27 {
28  for (const auto i : make_range(_h_blocks.NumRows()))
29  for (const auto j : make_range(_h_blocks.NumCols()))
30  {
31  if (_jacobian_blocks.NumRows() && _jacobian_blocks(i, j) == _h_blocks(i, j))
32  _jacobian_blocks(i, j) = nullptr;
33  delete _h_blocks(i, j);
34  }
35  _h_blocks.DeleteAll();
36 }
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 39 of file EquationSystem.C.

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

40 {
41  for (const auto i : make_range(_jacobian_blocks.NumRows()))
42  for (const auto j : make_range(_jacobian_blocks.NumCols()))
43  if (!_h_blocks.NumRows() || _jacobian_blocks(i, j) != _h_blocks(i, j))
44  delete _jacobian_blocks(i, j);
45  _jacobian_blocks.DeleteAll();
46 }
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::EquationSystem::EliminateCoupledVariables ( )
protectedvirtualinherited

Perform trivial eliminations of coupled variables lacking corresponding test variables.

Reimplemented in Moose::MFEM::TimeDependentEquationSystem.

Definition at line 252 of file EquationSystem.C.

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

253 {
254  for (const auto & test_var_name : _test_var_names)
255  for (const auto & eliminated_var_name : _eliminated_var_names)
256  if (_mblfs.Has(test_var_name) && _mblfs.Get(test_var_name)->Has(eliminated_var_name) &&
257  !VectorContainsName(_test_var_names, eliminated_var_name))
258  {
259  auto & mblf = *_mblfs.Get(test_var_name)->Get(eliminated_var_name);
260  mblf.AddMult(*_eliminated_variables.Get(eliminated_var_name), *_lfs.Get(test_var_name), -1);
261  }
262 }
NamedFieldsMap< NamedFieldsMap< mfem::ParMixedBilinearForm > > _mblfs
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.
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...
std::vector< std::string > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
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 425 of file EquationSystem.C.

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

426 {
428  _jacobian_blocks.SetSize(_test_var_names.size(), _trial_var_names.size());
429  _jacobian_blocks = nullptr;
430 
431  const mfem::BlockVector update_vector(const_cast<mfem::Vector &>(u), _block_true_offsets);
432  for (const auto i : index_range(_test_var_names))
433  {
434  auto test_var_name = _test_var_names.at(i);
435  if (_nlfs.Has(test_var_name))
436  {
437  auto nlf = _nlfs.Get(test_var_name);
438  mfem::HypreParMatrix * nlf_jac =
439  dynamic_cast<mfem::HypreParMatrix *>(&nlf->GetGradient(update_vector.GetBlock(i)));
440  mooseAssert(nlf_jac,
441  "Jacobian contribution of nonlinear form associated with " + test_var_name +
442  " is not castable into a HypreParMatrix");
443  _jacobian_blocks(i, i) = mfem::ParAdd(_h_blocks(i, i), nlf_jac);
444  }
445  else
446  _jacobian_blocks(i, i) = _h_blocks(i, i);
447  for (const auto j : index_range(_trial_var_names))
448  if (i != j) // nlf->GetGradient only contributes to on-diagonal blocks
449  _jacobian_blocks(i, j) = _h_blocks(i, j);
450  }
451  // Create monolithic matrix
452  _jacobian.Reset(mfem::HypreParMatrixFromBlocks(_jacobian_blocks));
453 }
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 265 of file EquationSystem.C.

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

268 {
269  mooseAssert(_test_var_names.size() == _trial_var_names.size(),
270  "Number of test and trial variables must be the same for block matrix assembly.");
271 
272  if (_assembly_level == mfem::AssemblyLevel::LEGACY)
273  FormSystemMatrix(op, trueX, trueRHS);
274  else
275  {
276  mooseAssert(_test_var_names.size() == 1 && _test_var_names.size() == _trial_var_names.size(),
277  "Non-legacy assembly is only supported for single test and trial variable systems");
278  FormSystemOperator(op, trueX, trueRHS);
279  }
280 }
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

Assemble the linear part of the operator, assemble the right-hand side, apply essential and eliminated-variable constraints, and populate the true-DoF vectors used by the solve.

Definition at line 374 of file EquationSystem.C.

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

375 {
376  height = trueX.Size();
377  width = trueRHS.Size();
378  // Store block offsets
379  _block_true_offsets.SetSize(trueX.NumBlocks() + 1);
380  _block_true_offsets[0] = 0;
381  for (unsigned i = 0; i < _trial_var_names.size(); i++)
382  _block_true_offsets[i + 1] = trueX.BlockSize(i);
383  _block_true_offsets.PartialSum();
384  FormLinearSystem(_linear_operator, trueX, trueRHS);
385 }
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 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::ComplexEquationSystem::FormSystemMatrix ( mfem::OperatorHandle &  op,
mfem::BlockVector &  trueX,
mfem::BlockVector &  trueRHS 
)
overridevirtual

Form matrix representation of system operator as a HypreParMatrix.

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

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 238 of file ComplexEquationSystem.C.

241 {
242 
243  // Allocate block operator
244  DeleteHBlocks();
245  _h_blocks.SetSize(_test_var_names.size(), _trial_var_names.size());
246  _h_blocks = nullptr;
247  // Zero out RHS and sync memory
248  trueRHS = 0.0;
249  trueRHS.SyncToBlocks();
250 
251  // Form diagonal blocks.
252  for (const auto i : index_range(_test_var_names))
253  {
254  auto & test_var_name = _test_var_names.at(i);
255 
256  mfem::Vector aux_x, aux_rhs;
257  mfem::OperatorHandle aux_a;
258 
259  auto slf = _slfs.Get(test_var_name);
260  slf->FormLinearSystem(_ess_tdof_lists.at(i),
262  *_clfs.Get(test_var_name),
263  aux_a,
264  aux_x,
265  aux_rhs,
266  /*copy_interior=*/true);
267  trueX.GetBlock(i) = aux_x;
268  trueRHS.GetBlock(i) = aux_rhs;
269  _h_blocks(i, i) = aux_a.As<mfem::ComplexHypreParMatrix>()->GetSystemMatrix();
270  }
271  // Sync memory
272  trueX.SyncFromBlocks();
273  trueRHS.SyncFromBlocks();
274 
275  // Create monolithic matrix
276  op.Reset(mfem::HypreParMatrixFromBlocks(_h_blocks));
277 }
std::vector< std::unique_ptr< mfem::ParComplexGridFunction > > _cmplx_var_ess_constraints
Complex Gridfunctions holding essential constraints from Dirichlet BCs.
NamedFieldsMap< mfem::ParComplexLinearForm > _clfs
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.
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::ParSesquilinearForm > _slfs
auto index_range(const T &sizable)

◆ FormSystemOperator()

void Moose::MFEM::ComplexEquationSystem::FormSystemOperator ( mfem::OperatorHandle &  op,
mfem::BlockVector &  trueX,
mfem::BlockVector &  trueRHS 
)
overridevirtual

Form matrix-free representation of system operator.

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

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 211 of file ComplexEquationSystem.C.

214 {
215  auto & test_var_name = _test_var_names.at(0);
216  mfem::Vector aux_x, aux_rhs;
217  mfem::OperatorPtr aux_a;
218 
219  auto slf = _slfs.Get(test_var_name);
220  slf->FormLinearSystem(_ess_tdof_lists.at(0),
222  *_clfs.Get(test_var_name),
223  aux_a,
224  aux_x,
225  aux_rhs,
226  /*copy_interior=*/true);
227 
228  trueX.GetBlock(0) = aux_x;
229  trueRHS.GetBlock(0) = aux_rhs;
230  trueX.SyncFromBlocks();
231  trueRHS.SyncFromBlocks();
232 
233  op.Reset(aux_a.Ptr());
234  aux_a.SetOperatorOwner(false);
235 }
std::vector< std::unique_ptr< mfem::ParComplexGridFunction > > _cmplx_var_ess_constraints
Complex Gridfunctions holding essential constraints from Dirichlet BCs.
NamedFieldsMap< mfem::ParComplexLinearForm > _clfs
std::vector< mfem::Array< int > > _ess_tdof_lists
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.
NamedFieldsMap< mfem::ParSesquilinearForm > _slfs

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

457 {
458  if (_non_linear)
459  {
460  if (_assembly_level != mfem::AssemblyLevel::LEGACY)
461  mooseError("MFEM nonlinear solvers that require GetGradient() currently require legacy "
462  "assembly in EquationSystem.");
463  const_cast<EquationSystem *>(this)->FormJacobianMatrix(u);
464  }
465  else
467 
468  return *_jacobian;
469 }
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

◆ GetTestVarNames()

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

Definition at line 74 of file EquationSystem.h.

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

74 { 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 73 of file EquationSystem.h.

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

73 { 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::ComplexEquationSystem::Init ( GridFunctions gridfunctions,
ComplexGridFunctions cmplx_gridfunctions,
mfem::AssemblyLevel  assembly_level 
)
overridevirtual

Initialise.

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 10 of file ComplexEquationSystem.C.

13 {
14  _assembly_level = assembly_level;
15 
16  if (gridfunctions.size())
17  mooseError("Mixing real and complex variables is currently not supported.");
18 
19  for (auto & test_var_name : _test_var_names)
20  {
21  if (!cmplx_gridfunctions.Has(test_var_name))
22  {
23  mooseError("MFEM complex variable ",
24  test_var_name,
25  " requested by equation system during initialization was "
26  "not found in gridfunctions");
27  }
28  // Store pointers to test FESpaces
29  _test_pfespaces.push_back(cmplx_gridfunctions.Get(test_var_name)->ParFESpace());
30  // Create auxiliary gridfunctions for storing essential constraints from Dirichlet conditions
31  _cmplx_var_ess_constraints.emplace_back(std::make_unique<mfem::ParComplexGridFunction>(
32  cmplx_gridfunctions.Get(test_var_name)->ParFESpace()));
33  }
34 
35  // Store pointers to FESpaces of all coupled variables
36  for (auto & coupled_var_name : _coupled_var_names)
37  _coupled_pfespaces.push_back(cmplx_gridfunctions.Get(coupled_var_name)->ParFESpace());
38 
39  // Extract which coupled variables are to be trivially eliminated and which are trial variables
41 
42  // Store pointers to coupled variable ComplexGridFunctions that are to be eliminated prior to
43  // forming the jacobian
44  for (auto & eliminated_var_name : _eliminated_var_names)
45  _cmplx_eliminated_variables.Register(eliminated_var_name,
46  cmplx_gridfunctions.GetShared(eliminated_var_name));
47 
48  // Get a reference to the complex GridFunctions
49  _complex_gfuncs = &cmplx_gridfunctions;
50 }
std::vector< std::unique_ptr< mfem::ParComplexGridFunction > > _cmplx_var_ess_constraints
Complex Gridfunctions holding essential constraints from Dirichlet BCs.
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.
ComplexGridFunctions _cmplx_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 > _test_var_names
Names of all test variables corresponding to linear forms in this equation system.
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::ComplexGridFunctions * _complex_gfuncs

◆ Mult()

void Moose::MFEM::ComplexEquationSystem::Mult ( const mfem::Vector &  x,
mfem::Vector &  y 
) const
overridevirtual

Nonlinear Mult (Used by Newton-solver not necessarily nonlinear)

Definition at line 281 of file ComplexEquationSystem.C.

282 {
283  _linear_operator->Mult(x, residual);
284  x.HostRead();
285  residual.HostRead();
286 }
mfem::OperatorHandle _linear_operator

◆ Nonlinear()

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

Definition at line 79 of file EquationSystem.h.

Referenced by Moose::MFEM::ProblemOperatorBase::SolveWithOperator().

◆ PrepareLinearSolver()

void Moose::MFEM::EquationSystem::PrepareLinearSolver ( LinearSolverBase solver)
inherited

Prepare the provided linear solver.

First calls SetupLOR on the solver if it's using a Low Order Refined methodology and then calls SetOperator on the solver with the assembled linear operator

Definition at line 709 of file EquationSystem.C.

Referenced by Moose::MFEM::ProblemOperatorBase::SolveWithOperator().

710 {
711  if (solver.IsLOR())
712  {
713  if (Complex())
714  mooseError("LOR solve is not supported for complex equation systems.");
715  if (_test_var_names.size() > 1)
716  mooseError("LOR solve is only supported for single-variable systems");
717  solver.SetupLOR(*_blfs.Get(_test_var_names.at(0)), _ess_tdof_lists.at(0));
718  }
719 
720  mooseAssert(_linear_operator.Ptr(),
721  "If we are preparing a linear solver, we better have a linear operator");
722  solver.SetOperator(_linear_operator);
723 }
NamedFieldsMap< mfem::ParBilinearForm > _blfs
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::vector< mfem::Array< int > > _ess_tdof_lists
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.
mfem::OperatorHandle _linear_operator
virtual bool Complex() const
Whether this a complex equation system.

◆ SetSolverRequiresGradient()

void Moose::MFEM::EquationSystem::SetSolverRequiresGradient ( bool  requires_gradient)
inlineinherited

Set whether the nonlinear solver driving this equation system requires Jacobian information.

Definition at line 66 of file EquationSystem.h.

67  {
68  _solver_requires_gradient = requires_gradient;
69  }

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

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

78 {
79  // If a coupled variable has an equation associated with it,
80  // add it to the set of trial variables.
81  for (const auto & test_var_name : _test_var_names)
82  if (VectorContainsName(_coupled_var_names, test_var_name))
83  _trial_var_names.push_back(test_var_name);
84 
85  // Otherwise, add it to the set of eliminated variables.
86  for (const auto & coupled_var_name : _coupled_var_names)
87  if (!VectorContainsName(_test_var_names, coupled_var_name))
88  _eliminated_var_names.push_back(coupled_var_name);
89 }
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::ComplexEquationSystem::SetTrialVariablesFromTrueVectors ( const mfem::BlockVector &  trueX) const
overridevirtual

Update variable from solution vector after solve.

Reimplemented from Moose::MFEM::EquationSystem.

Definition at line 289 of file ComplexEquationSystem.C.

290 {
291  for (const auto i : index_range(_trial_var_names))
292  {
293  auto & trial_var_name = _trial_var_names.at(i);
294  trueX.GetBlock(i).SyncMemory(trueX);
295  _complex_gfuncs->Get(trial_var_name)->Distribute(&(trueX.GetBlock(i)));
296  }
297 }
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...
Moose::MFEM::ComplexGridFunctions * _complex_gfuncs
auto index_range(const T &sizable)

◆ VectorContainsName()

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

Definition at line 49 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().

51 {
52  return std::find(the_vector.begin(), the_vector.end(), name) != the_vector.end();
53 }
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

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

◆ _clfs

NamedFieldsMap<mfem::ParComplexLinearForm> Moose::MFEM::ComplexEquationSystem::_clfs
protected

Definition at line 112 of file ComplexEquationSystem.h.

Referenced by BuildLinearForms(), FormSystemMatrix(), and FormSystemOperator().

◆ _cmplx_eliminated_variables

ComplexGridFunctions Moose::MFEM::ComplexEquationSystem::_cmplx_eliminated_variables
protected

Pointers to coupled variables not part of the reduced EquationSystem.

Definition at line 124 of file ComplexEquationSystem.h.

Referenced by Init().

◆ _cmplx_essential_bc_map

NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexEssentialBC> > > Moose::MFEM::ComplexEquationSystem::_cmplx_essential_bc_map
protected

Definition at line 121 of file ComplexEquationSystem.h.

Referenced by AddComplexEssentialBCs(), and ApplyComplexEssentialBC().

◆ _cmplx_integrated_bc_map

NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC> > > > Moose::MFEM::ComplexEquationSystem::_cmplx_integrated_bc_map
protected

◆ _cmplx_kernels_map

NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel> > > > Moose::MFEM::ComplexEquationSystem::_cmplx_kernels_map
protected

Definition at line 116 of file ComplexEquationSystem.h.

Referenced by AddComplexKernel(), BuildBilinearForms(), and BuildLinearForms().

◆ _cmplx_var_ess_constraints

std::vector<std::unique_ptr<mfem::ParComplexGridFunction> > Moose::MFEM::ComplexEquationSystem::_cmplx_var_ess_constraints
protected

Complex Gridfunctions holding essential constraints from Dirichlet BCs.

Definition at line 127 of file ComplexEquationSystem.h.

Referenced by ApplyEssentialBCs(), FormSystemMatrix(), FormSystemOperator(), and Init().

◆ _complex_gfuncs

Moose::MFEM::ComplexGridFunctions* Moose::MFEM::ComplexEquationSystem::_complex_gfuncs
protected

◆ _coupled_pfespaces

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

Pointers to finite element spaces associated with coupled variables.

Definition at line 236 of file EquationSystem.h.

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

◆ _coupled_var_names

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

◆ _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

◆ _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 257 of file EquationSystem.h.

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

◆ _gfuncs

Moose::MFEM::GridFunctions* Moose::MFEM::EquationSystem::_gfuncs
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

◆ _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

◆ _slfs

NamedFieldsMap<mfem::ParSesquilinearForm> Moose::MFEM::ComplexEquationSystem::_slfs
protected

◆ _solver_requires_gradient

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

◆ _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

◆ _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: