https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComplexEquationSystem.h
Go to the documentation of this file.
1#ifdef MOOSE_MFEM_ENABLED
2
3#pragma once
4
5#include "libmesh/ignore_warnings.h"
6#include "mfem/miniapps/common/pfem_extras.hpp"
7#include "libmesh/restore_warnings.h"
8#include "EquationSystem.h"
9#include "MFEMComplexKernel.h"
13
14namespace Moose::MFEM
15{
16/*
17Class to store weak form components (bilinear and linear forms, and optionally
18mixed and nonlinear forms) and build methods
19*/
21{
22public:
25
26 // Build forms
27 virtual void Init(GridFunctions & gridfunctions,
28 ComplexGridFunctions & cmplx_gridfunctions,
29 mfem::AssemblyLevel assembly_level) override;
30
32 virtual void Mult(const mfem::Vector & x, mfem::Vector & y) const override;
33
35 virtual void BuildLinearForms() override;
36
38 virtual void BuildBilinearForms() override;
39
41 virtual void BuildMixedBilinearForms() override;
42
44 virtual void ApplyEssentialBCs() override;
45
47 virtual void ApplyComplexEssentialBC(const std::string & var_name,
48 mfem::ParComplexGridFunction & trial_gf,
49 mfem::Array<int> & global_ess_markers);
50
52 void AddComplexKernel(std::shared_ptr<MFEMComplexKernel> kernel);
53
55 void AddComplexIntegratedBC(std::shared_ptr<MFEMComplexIntegratedBC> bc);
56
58 void AddComplexEssentialBCs(std::shared_ptr<MFEMComplexEssentialBC> bc);
59
61 void EliminateCoupledVariables() override;
62
65 virtual void FormSystemOperator(mfem::OperatorHandle & op,
66 mfem::BlockVector & trueX,
67 mfem::BlockVector & trueRHS) override;
68
71 virtual void FormSystemMatrix(mfem::OperatorHandle & op,
72 mfem::BlockVector & trueX,
73 mfem::BlockVector & trueRHS) override;
74
76 virtual void SetTrialVariablesFromTrueVectors(const mfem::BlockVector & trueX) const override;
77
79 template <class FormType>
81 const std::string & trial_var_name,
82 const std::string & test_var_name,
83 std::shared_ptr<FormType> form,
84 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> &
85 kernels_map);
86
88 inline void ApplyDomainLFIntegrators(
89 const std::string & test_var_name,
90 std::shared_ptr<mfem::ParComplexLinearForm> form,
91 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> &
92 kernels_map);
93
95 template <class FormType>
97 const std::string & trial_var_name,
98 const std::string & test_var_name,
99 std::shared_ptr<FormType> form,
100 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
101 integrated_bc_map);
102
104 inline void ApplyBoundaryLFIntegrators(
105 const std::string & test_var_name,
106 std::shared_ptr<mfem::ParComplexLinearForm> form,
107 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
108 integrated_bc_map);
109
110 bool IsComplex() const override { return true; }
111
112protected:
113 // Complex Linear and Bilinear Forms
117
118 // Complex kernels and integrated BCs
123
124 // Complex essential BCs
126
129
131 std::vector<std::unique_ptr<mfem::ParComplexGridFunction>> _cmplx_var_ess_constraints;
132
133 // Pointer to complex GridFunctions to enable updates during nonlinear iterations
135};
136
137template <class FormType>
138void
140 const std::string & trial_var_name,
141 const std::string & test_var_name,
142 std::shared_ptr<FormType> form,
143 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> & kernels_map)
144{
145 if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(trial_var_name))
146 {
147 auto kernels = kernels_map.GetRef(test_var_name).GetRef(trial_var_name);
148 for (auto & kernel : kernels)
149 {
150 mfem::BilinearFormIntegrator * integ_real = kernel->getRealBFIntegrator();
151 mfem::BilinearFormIntegrator * integ_imag = kernel->getImagBFIntegrator();
152
153 if (integ_real || integ_imag)
154 {
155 kernel->isSubdomainRestricted()
156 ? form->AddDomainIntegrator(
157 std::move(integ_real), std::move(integ_imag), kernel->getSubdomainMarkers())
158 : form->AddDomainIntegrator(std::move(integ_real), std::move(integ_imag));
159 }
160 }
161 }
162}
163
164inline void
166 const std::string & test_var_name,
167 std::shared_ptr<mfem::ParComplexLinearForm> form,
168 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> & kernels_map)
169{
170 if (kernels_map.Has(test_var_name))
171 {
172 auto kernels = kernels_map.GetRef(test_var_name).GetRef(test_var_name);
173 for (auto & kernel : kernels)
174 {
175 mfem::LinearFormIntegrator * integ_real = kernel->getRealLFIntegrator();
176 mfem::LinearFormIntegrator * integ_imag = kernel->getImagLFIntegrator();
177
178 if (integ_real || integ_imag)
179 {
180 kernel->isSubdomainRestricted()
181 ? form->AddDomainIntegrator(
182 std::move(integ_real), std::move(integ_imag), kernel->getSubdomainMarkers())
183 : form->AddDomainIntegrator(std::move(integ_real), std::move(integ_imag));
184 }
185 }
186 }
187}
188
189template <class FormType>
190void
192 const std::string & trial_var_name,
193 const std::string & test_var_name,
194 std::shared_ptr<FormType> form,
195 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
196 integrated_bc_map)
197{
198 if (integrated_bc_map.Has(test_var_name) &&
199 integrated_bc_map.Get(test_var_name)->Has(trial_var_name))
200 {
201 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(trial_var_name);
202 for (auto & bc : bcs)
203 {
204 mfem::BilinearFormIntegrator * integ_real = bc->getRealBFIntegrator();
205 mfem::BilinearFormIntegrator * integ_imag = bc->getImagBFIntegrator();
206
207 if (integ_real || integ_imag)
208 {
209 bc->isBoundaryRestricted()
210 ? form->AddBoundaryIntegrator(
211 std::move(integ_real), std::move(integ_imag), bc->getBoundaryMarkers())
212 : form->AddBoundaryIntegrator(std::move(integ_real), std::move(integ_imag));
213 }
214 }
215 }
216}
217
218inline void
220 const std::string & test_var_name,
221 std::shared_ptr<mfem::ParComplexLinearForm> form,
222 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
223 integrated_bc_map)
224{
225 if (integrated_bc_map.Has(test_var_name))
226 {
227 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(test_var_name);
228 for (auto & bc : bcs)
229 {
230 mfem::LinearFormIntegrator * integ_real = bc->getRealLFIntegrator();
231 mfem::LinearFormIntegrator * integ_imag = bc->getImagLFIntegrator();
232
233 if (integ_real || integ_imag)
234 {
235 bc->isBoundaryRestricted()
236 ? form->AddBoundaryIntegrator(
237 std::move(integ_real), std::move(integ_imag), bc->getBoundaryMarkers())
238 : form->AddBoundaryIntegrator(std::move(integ_real), std::move(integ_imag));
239 }
240 }
241 }
242}
243
244}
245
246#endif
void EliminateCoupledVariables() override
Perform trivial eliminations of coupled variables lacking corresponding test variables.
virtual void BuildLinearForms() override
Build linear forms and eliminate constrained DoFs.
std::vector< std::unique_ptr< mfem::ParComplexGridFunction > > _cmplx_var_ess_constraints
Complex Gridfunctions holding essential constraints from Dirichlet BCs.
Moose::MFEM::ComplexGridFunctions * _complex_gfuncs
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexKernel > > > > _cmplx_kernels_map
virtual void Mult(const mfem::Vector &x, mfem::Vector &y) const override
Nonlinear Mult (Used by Newton-solver not necessarily nonlinear)
virtual void FormSystemOperator(mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS) override
Form matrix-free representation of system operator.
virtual void BuildMixedBilinearForms() override
Build mixed bilinear forms (off-diagonal Jacobian contributions)
virtual void SetTrialVariablesFromTrueVectors(const mfem::BlockVector &trueX) const override
Update variable from solution vector after solve.
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.
NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexEssentialBC > > > _cmplx_essential_bc_map
NamedFieldsMap< mfem::ParSesquilinearForm > _slfs
virtual void BuildBilinearForms() override
Build bilinear forms (diagonal Jacobian contributions)
virtual void Init(GridFunctions &gridfunctions, ComplexGridFunctions &cmplx_gridfunctions, mfem::AssemblyLevel assembly_level) override
Initialise.
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.
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.
void AddComplexKernel(std::shared_ptr< MFEMComplexKernel > kernel)
Add complex kernels.
virtual void ApplyComplexEssentialBC(const std::string &var_name, mfem::ParComplexGridFunction &trial_gf, mfem::Array< int > &global_ess_markers)
Applies complex BCs to a single trial variable.
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC > > > > _cmplx_integrated_bc_map
virtual void ApplyEssentialBCs() override
Update all essentially constrained true DoF markers and values on boundaries.
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.
NamedFieldsMap< mfem::ParComplexLinearForm > _clfs
NamedFieldsMap< NamedFieldsMap< mfem::ParMixedSesquilinearForm > > _mslfs
virtual void FormSystemMatrix(mfem::OperatorHandle &op, mfem::BlockVector &trueX, mfem::BlockVector &trueRHS) override
Form matrix representation of system operator as a HypreParMatrix.
void AddComplexIntegratedBC(std::shared_ptr< MFEMComplexIntegratedBC > bc)
Add complex integrated BCs.
ComplexGridFunctions _cmplx_eliminated_variables
Pointers to coupled variables not part of the reduced ComplexEquationSystem.
void AddComplexEssentialBCs(std::shared_ptr< MFEMComplexEssentialBC > bc)
Add complex essential BCs.
Owns the weak-form mathematics of a MOOSE MFEM problem.
T & GetRef(const std::string &field_name) const
Returns a reference to a field.
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).