https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComplexEquationSystem.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#ifdef MOOSE_MFEM_ENABLED
11
12#pragma once
13
14#include "libmesh/ignore_warnings.h"
15#include "mfem/miniapps/common/pfem_extras.hpp"
16#include "libmesh/restore_warnings.h"
17#include "EquationSystem.h"
18#include "MFEMComplexKernel.h"
23
24namespace Moose::MFEM
25{
31{
32public:
35
36 // Build forms
37 virtual void Init(GridFunctions & gridfunctions,
38 ComplexGridFunctions & cmplx_gridfunctions,
39 mfem::AssemblyLevel assembly_level) override;
40
42 virtual void Mult(const mfem::Vector & x, mfem::Vector & y) const override;
43
45 virtual void BuildLinearForms() override;
46
48 virtual void BuildBilinearForms() override;
49
51 virtual void BuildMixedBilinearForms() override;
52
54 virtual void ApplyEssentialConstraints() override;
55
58 virtual void ApplyComplexEssentialConstraint(const std::string & var_name,
59 mfem::ParComplexGridFunction & trial_gf,
60 mfem::Array<int> & global_bdr_markers,
61 mfem::Array<int> & global_ess_tdofs);
62
64 void AddComplexKernel(std::shared_ptr<MFEMComplexKernel> kernel);
65
67 void AddComplexIntegratedBC(std::shared_ptr<MFEMComplexIntegratedBC> bc);
68
70 void AddComplexEssentialBCs(std::shared_ptr<MFEMComplexEssentialBC> bc);
71
73 void AddComplexEssentialConstraint(std::shared_ptr<MFEMComplexEssentialConstraint> constraint);
74
75 bool HasEssentialConstraints(const std::string & var_name) const override;
76
78 void EliminateCoupledVariables() override;
79
82 virtual void FormSystemOperator(mfem::OperatorHandle & op,
83 mfem::BlockVector & trueX,
84 mfem::BlockVector & trueRHS) override;
85
88 virtual void FormSystemMatrix(mfem::OperatorHandle & op,
89 mfem::BlockVector & trueX,
90 mfem::BlockVector & trueRHS) override;
91
93 virtual void SetTrialVariablesFromTrueVectors(const mfem::BlockVector & trueX) const override;
94
96 template <class FormType>
98 const std::string & trial_var_name,
99 const std::string & test_var_name,
100 std::shared_ptr<FormType> form,
101 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> &
102 kernels_map);
103
105 inline void ApplyDomainLFIntegrators(
106 const std::string & test_var_name,
107 std::shared_ptr<mfem::ParComplexLinearForm> form,
108 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> &
109 kernels_map);
110
112 template <class FormType>
114 const std::string & trial_var_name,
115 const std::string & test_var_name,
116 std::shared_ptr<FormType> form,
117 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
118 integrated_bc_map);
119
121 inline void ApplyBoundaryLFIntegrators(
122 const std::string & test_var_name,
123 std::shared_ptr<mfem::ParComplexLinearForm> form,
124 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
125 integrated_bc_map);
126
127 bool IsComplex() const override { return true; }
128
129protected:
130 // Complex Linear and Bilinear Forms
134
135 // Complex kernels and integrated BCs
140
141 // Complex essential BCs
143
144 // Complex essential (volumetric) constraints
147
150
152 std::vector<std::unique_ptr<mfem::ParComplexGridFunction>> _cmplx_var_ess_constraints;
153
154 // Pointer to complex GridFunctions to enable updates during nonlinear iterations
156};
157
158template <class FormType>
159void
161 const std::string & trial_var_name,
162 const std::string & test_var_name,
163 std::shared_ptr<FormType> form,
164 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> & kernels_map)
165{
166 if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(trial_var_name))
167 {
168 auto kernels = kernels_map.GetRef(test_var_name).GetRef(trial_var_name);
169 for (auto & kernel : kernels)
170 {
171 mfem::BilinearFormIntegrator * integ_real = kernel->getRealBFIntegrator();
172 mfem::BilinearFormIntegrator * integ_imag = kernel->getImagBFIntegrator();
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}
184
185inline void
187 const std::string & test_var_name,
188 std::shared_ptr<mfem::ParComplexLinearForm> form,
189 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> & kernels_map)
190{
191 if (kernels_map.Has(test_var_name))
192 {
193 auto kernels = kernels_map.GetRef(test_var_name).GetRef(test_var_name);
194 for (auto & kernel : kernels)
195 {
196 mfem::LinearFormIntegrator * integ_real = kernel->getRealLFIntegrator();
197 mfem::LinearFormIntegrator * integ_imag = kernel->getImagLFIntegrator();
198
199 if (integ_real || integ_imag)
200 {
201 kernel->isSubdomainRestricted()
202 ? form->AddDomainIntegrator(
203 std::move(integ_real), std::move(integ_imag), kernel->getSubdomainMarkers())
204 : form->AddDomainIntegrator(std::move(integ_real), std::move(integ_imag));
205 }
206 }
207 }
208}
209
210template <class FormType>
211void
213 const std::string & trial_var_name,
214 const std::string & test_var_name,
215 std::shared_ptr<FormType> form,
216 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
217 integrated_bc_map)
218{
219 if (integrated_bc_map.Has(test_var_name) &&
220 integrated_bc_map.Get(test_var_name)->Has(trial_var_name))
221 {
222 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(trial_var_name);
223 for (auto & bc : bcs)
224 {
225 mfem::BilinearFormIntegrator * integ_real = bc->getRealBFIntegrator();
226 mfem::BilinearFormIntegrator * integ_imag = bc->getImagBFIntegrator();
227
228 if (integ_real || integ_imag)
229 {
230 bc->isBoundaryRestricted()
231 ? form->AddBoundaryIntegrator(
232 std::move(integ_real), std::move(integ_imag), bc->getBoundaryMarkers())
233 : form->AddBoundaryIntegrator(std::move(integ_real), std::move(integ_imag));
234 }
235 }
236 }
237}
238
239inline void
241 const std::string & test_var_name,
242 std::shared_ptr<mfem::ParComplexLinearForm> form,
243 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
244 integrated_bc_map)
245{
246 if (integrated_bc_map.Has(test_var_name))
247 {
248 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(test_var_name);
249 for (auto & bc : bcs)
250 {
251 mfem::LinearFormIntegrator * integ_real = bc->getRealLFIntegrator();
252 mfem::LinearFormIntegrator * integ_imag = bc->getImagLFIntegrator();
253
254 if (integ_real || integ_imag)
255 {
256 bc->isBoundaryRestricted()
257 ? form->AddBoundaryIntegrator(
258 std::move(integ_real), std::move(integ_imag), bc->getBoundaryMarkers())
259 : form->AddBoundaryIntegrator(std::move(integ_real), std::move(integ_imag));
260 }
261 }
262 }
263}
264
265}
266
267#endif
Class to store weak form components (bilinear and linear forms, and optionally mixed and nonlinear fo...
NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexEssentialConstraint > > > _cmplx_essential_constraint_map
virtual void ApplyComplexEssentialConstraint(const std::string &var_name, mfem::ParComplexGridFunction &trial_gf, mfem::Array< int > &global_bdr_markers, mfem::Array< int > &global_ess_tdofs)
Apply essential constraints associated with var_name to set true DoFs of trial_gf,...
bool HasEssentialConstraints(const std::string &var_name) const override
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.
void AddComplexEssentialConstraint(std::shared_ptr< MFEMComplexEssentialConstraint > constraint)
Add complex essential (volumetric) constraints.
NamedFieldsMap< NamedFieldsMap< std::vector< std::shared_ptr< MFEMComplexIntegratedBC > > > > _cmplx_integrated_bc_map
virtual void ApplyEssentialConstraints() override
Update essential boundary markers and all constrained true DoF lists and values.
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).