10 #ifdef MOOSE_MFEM_ENABLED 14 #include "libmesh/ignore_warnings.h" 15 #include "mfem/miniapps/common/pfem_extras.hpp" 16 #include "libmesh/restore_warnings.h" 40 virtual void AddKernel(std::shared_ptr<MFEMKernel> kernel);
48 mfem::AssemblyLevel assembly_level);
53 void FormSystem(mfem::BlockVector & trueX, mfem::BlockVector & trueRHS);
55 void Mult(
const mfem::Vector & u, mfem::Vector & residual)
const override;
57 mfem::Operator &
GetGradient(
const mfem::Vector & u)
const override;
88 const std::string & name)
const;
93 mfem::ParGridFunction & trial_gf,
94 mfem::Array<int> & global_ess_markers);
113 mfem::BlockVector & trueX,
114 mfem::BlockVector & trueRHS);
118 mfem::BlockVector & trueX,
119 mfem::BlockVector & trueRHS);
123 mfem::BlockVector & trueX,
124 mfem::BlockVector & trueRHS);
132 template <
class FormType>
134 const std::string & trial_var_name,
135 const std::string & test_var_name,
136 std::shared_ptr<FormType> form,
138 std::optional<mfem::real_t> scale_factor = std::nullopt);
141 const std::string & test_var_name,
142 std::shared_ptr<mfem::ParLinearForm> form,
146 const std::string & test_var_name,
147 std::shared_ptr<mfem::ParNonlinearForm> form,
149 std::optional<mfem::real_t> scale_factor = std::nullopt);
151 template <
class FormType>
153 const std::string & trial_var_name,
154 const std::string & test_var_name,
155 std::shared_ptr<FormType> form,
158 std::optional<mfem::real_t> scale_factor = std::nullopt);
161 const std::string & test_var_name,
162 std::shared_ptr<mfem::ParLinearForm> form,
167 const std::string & test_var_name,
168 std::shared_ptr<mfem::ParNonlinearForm> form,
171 std::optional<mfem::real_t> scale_factor = std::nullopt);
227 friend class ::MFEMProblemSolve;
229 using mfem::Operator::RecoverFEMSolution;
232 template <
class FormType>
235 const std::string & trial_var_name,
236 const std::string & test_var_name,
237 std::shared_ptr<FormType> form,
239 std::optional<mfem::real_t> scale_factor)
241 if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(trial_var_name))
243 auto kernels = kernels_map.GetRef(test_var_name).GetRef(trial_var_name);
244 for (
auto & kernel : kernels)
246 mfem::BilinearFormIntegrator * integ = kernel->createBFIntegrator();
250 if (scale_factor.has_value())
252 kernel->isSubdomainRestricted()
253 ? form->AddDomainIntegrator(std::move(integ), kernel->getSubdomainMarkers())
254 : form->AddDomainIntegrator(std::move(integ));
262 const std::string & test_var_name,
263 std::shared_ptr<mfem::ParLinearForm> form,
266 if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(test_var_name))
268 auto kernels = kernels_map.GetRef(test_var_name).GetRef(test_var_name);
269 for (
auto & kernel : kernels)
271 mfem::LinearFormIntegrator * integ = kernel->createLFIntegrator();
275 kernel->isSubdomainRestricted()
276 ? form->AddDomainIntegrator(std::move(integ), kernel->getSubdomainMarkers())
277 : form->AddDomainIntegrator(std::move(integ));
285 const std::string & test_var_name,
286 std::shared_ptr<mfem::ParNonlinearForm> form,
288 std::optional<mfem::real_t> scale_factor)
290 if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(test_var_name))
292 auto kernels = kernels_map.GetRef(test_var_name).GetRef(test_var_name);
293 for (
auto & kernel : kernels)
295 mfem::NonlinearFormIntegrator * integ = kernel->createNLIntegrator();
299 if (scale_factor.has_value())
301 kernel->isSubdomainRestricted()
302 ? form->AddDomainIntegrator(std::move(integ), kernel->getSubdomainMarkers())
303 : form->AddDomainIntegrator(std::move(integ));
309 template <
class FormType>
312 const std::string & trial_var_name,
313 const std::string & test_var_name,
314 std::shared_ptr<FormType> form,
317 std::optional<mfem::real_t> scale_factor)
319 if (integrated_bc_map.Has(test_var_name) &&
320 integrated_bc_map.Get(test_var_name)->Has(trial_var_name))
322 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(trial_var_name);
323 for (
auto & bc : bcs)
325 mfem::BilinearFormIntegrator * integ = bc->createBFIntegrator();
329 if (scale_factor.has_value())
331 bc->isBoundaryRestricted()
332 ? form->AddBoundaryIntegrator(std::move(integ), bc->getBoundaryMarkers())
333 : form->AddBoundaryIntegrator(std::move(integ));
341 const std::string & test_var_name,
342 std::shared_ptr<mfem::ParLinearForm> form,
346 if (integrated_bc_map.Has(test_var_name) &&
347 integrated_bc_map.Get(test_var_name)->Has(test_var_name))
349 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(test_var_name);
350 for (
auto & bc : bcs)
352 mfem::LinearFormIntegrator * integ = bc->createLFIntegrator();
356 bc->isBoundaryRestricted()
357 ? form->AddBoundaryIntegrator(std::move(integ), bc->getBoundaryMarkers())
358 : form->AddBoundaryIntegrator(std::move(integ));
366 const std::string & test_var_name,
367 std::shared_ptr<mfem::ParNonlinearForm> form,
370 std::optional<mfem::real_t> scale_factor)
372 if (integrated_bc_map.Has(test_var_name) &&
373 integrated_bc_map.Get(test_var_name)->Has(test_var_name))
375 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(test_var_name);
376 for (
auto & bc : bcs)
378 mfem::NonlinearFormIntegrator * integ = bc->createNLIntegrator();
382 if (scale_factor.has_value())
384 bc->isBoundaryRestricted()
385 ? form->AddBoundaryIntegrator(std::move(integ), bc->getBoundaryMarkers())
386 : form->AddBoundaryIntegrator(std::move(integ));
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)
NamedFieldsMap< mfem::ParBilinearForm > _blfs
virtual void EliminateCoupledVariables()
Perform trivial eliminations of coupled variables lacking corresponding test variables.
NamedFieldsMap< NamedFieldsMap< mfem::ParMixedBilinearForm > > _mblfs
virtual void AddTestVariableNameIfMissing(const std::string &test_var_name)
Add test variable to EquationSystem.
virtual void AddKernel(std::shared_ptr< MFEMKernel > kernel)
Add kernels.
virtual void BuildBilinearForms()
Build bilinear forms (diagonal Jacobian contributions)
std::vector< mfem::ParFiniteElementSpace * > _coupled_pfespaces
Pointers to finite element spaces associated with coupled variables.
virtual void SetTrialVariablesFromTrueVectors(const mfem::BlockVector &trueX) const
Update variable from solution vector after solve.
void DeleteJacobianBlocks()
Deletes the HypreParMatrix associated with any pointer stored in _jacobian_blocks, and then proceeds to delete all dynamically allocated memory for _jacobian_blocks itself, resetting all dimensions to zero.
bool VectorContainsName(const std::vector< std::string > &the_vector, const std::string &name) const
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< std::string > _eliminated_var_names
Names of all coupled variables without a corresponding test variable.
void FormJacobianMatrix(const mfem::Vector &u)
Compute Jacobian matrix at the provided vector of true DoFs of trial variables.
~EquationSystem() override
NamedFieldsMap< mfem::ParNonlinearForm > _nlfs
Class to store weak form components (bilinear and linear forms, and optionally mixed and nonlinear fo...
Moose::MFEM::GridFunctions _eliminated_variables
Pointers to coupled variables not part of the reduced EquationSystem.
virtual void AddEssentialBC(std::shared_ptr< MFEMEssentialBC > bc)
Add BC associated with essentially constrained DoFs on boundaries.
NonlinearFormIntegrator which scales its results by a constant value.
std::vector< mfem::Array< int > > _ess_tdof_lists
mfem::AssemblyLevel _assembly_level
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)
std::vector< mfem::ParFiniteElementSpace * > _test_pfespaces
Pointers to finite element spaces associated with test variables.
void FormSystem(mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
Assemble the linear part of the operator, assemble the right-hand side, apply essential and eliminate...
void Mult(const mfem::Vector &u, mfem::Vector &residual) const override
Compute residual y = Mu.
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 ...
NamedFieldsMap< std::vector< std::shared_ptr< MFEMEssentialBC > > > _essential_bc_map
Arrays to store essential BCs to act on each component of weak form.
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...
mfem::OperatorHandle _jacobian
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.
Steady-state problem operator with an equation system.
virtual void BuildEquationSystem()
Build all forms comprising this EquationSystem.
std::vector< std::unique_ptr< mfem::ParGridFunction > > _var_ess_constraints
Gridfunctions holding essential constraints from Dirichlet BCs.
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)
virtual void BuildMixedBilinearForms()
Build mixed bilinear forms (off-diagonal Jacobian contributions)
virtual void FormSystemOperator(mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
Form matrix-free representation of linear components of system operator.
Integrator which scales its results by a constant value.
mfem::Array2D< const mfem::HypreParMatrix * > _h_blocks
virtual void SetTrialVariableNames()
Set trial variable names from subset of coupled variables that have an associated test variable...
virtual void FormSystemMatrix(mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS)
Form matrix representation of linear components of system operator as a HypreParMatrix.
virtual void AddCoupledVariableNameIfMissing(const std::string &coupled_var_name)
Add coupled variable to 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.
void DeleteHBlocks()
Deletes the HypreParMatrix associated with any pointer stored in _h_blocks, and then proceeds to dele...
std::vector< std::string > _coupled_var_names
Names of all trial variables of kernels and boundary conditions added to this EquationSystem.
virtual void BuildNonlinearForms()
Build non-linear action forms.
NamedFieldsMap< mfem::ParLinearForm > _lfs
virtual void BuildLinearForms()
Build linear forms and eliminate constrained DoFs.
const std::vector< std::string > & GetTrialVarNames() const
const std::vector< std::string > & GetTestVarNames() const
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)
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)
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).
mfem::OperatorHandle _linear_operator
virtual void AddEliminatedVariableNameIfMissing(const std::string &eliminated_var_name)
Add eliminated variable to EquationSystem.
virtual void Init(GridFunctions &gridfunctions, ComplexGridFunctions &cmplx_gridfunctions, mfem::AssemblyLevel assembly_level)
Initialise.
mfem::Operator & GetGradient(const mfem::Vector &u) const override
Get Jacobian at the provided vector of true DoFs of trial variables.
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...
virtual void AddIntegratedBC(std::shared_ptr< MFEMIntegratedBC > kernel)
mfem::Array2D< const mfem::HypreParMatrix * > _jacobian_blocks
Moose::MFEM::GridFunctions * _gfuncs