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"
22
23namespace Moose::MFEM
24{
30{
31public:
34
35 // Build forms
36 virtual void Init(GridFunctions & gridfunctions,
37 ComplexGridFunctions & cmplx_gridfunctions,
38 mfem::AssemblyLevel assembly_level) override;
39
41 virtual void Mult(const mfem::Vector & x, mfem::Vector & y) const override;
42
44 virtual void BuildLinearForms() override;
45
47 virtual void BuildBilinearForms() override;
48
50 virtual void BuildMixedBilinearForms() override;
51
53 virtual void ApplyEssentialBCs() override;
54
56 virtual void ApplyComplexEssentialBC(const std::string & var_name,
57 mfem::ParComplexGridFunction & trial_gf,
58 mfem::Array<int> & global_ess_markers);
59
61 void AddComplexKernel(std::shared_ptr<MFEMComplexKernel> kernel);
62
64 void AddComplexIntegratedBC(std::shared_ptr<MFEMComplexIntegratedBC> bc);
65
67 void AddComplexEssentialBCs(std::shared_ptr<MFEMComplexEssentialBC> bc);
68
70 void EliminateCoupledVariables() override;
71
74 virtual void FormSystemOperator(mfem::OperatorHandle & op,
75 mfem::BlockVector & trueX,
76 mfem::BlockVector & trueRHS) override;
77
80 virtual void FormSystemMatrix(mfem::OperatorHandle & op,
81 mfem::BlockVector & trueX,
82 mfem::BlockVector & trueRHS) override;
83
85 virtual void SetTrialVariablesFromTrueVectors(const mfem::BlockVector & trueX) const override;
86
88 template <class FormType>
90 const std::string & trial_var_name,
91 const std::string & test_var_name,
92 std::shared_ptr<FormType> form,
93 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> &
94 kernels_map);
95
97 inline void ApplyDomainLFIntegrators(
98 const std::string & test_var_name,
99 std::shared_ptr<mfem::ParComplexLinearForm> form,
100 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> &
101 kernels_map);
102
104 template <class FormType>
106 const std::string & trial_var_name,
107 const std::string & test_var_name,
108 std::shared_ptr<FormType> form,
109 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
110 integrated_bc_map);
111
113 inline void ApplyBoundaryLFIntegrators(
114 const std::string & test_var_name,
115 std::shared_ptr<mfem::ParComplexLinearForm> form,
116 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
117 integrated_bc_map);
118
119 bool IsComplex() const override { return true; }
120
121protected:
122 // Complex Linear and Bilinear Forms
126
127 // Complex kernels and integrated BCs
132
133 // Complex essential BCs
135
138
140 std::vector<std::unique_ptr<mfem::ParComplexGridFunction>> _cmplx_var_ess_constraints;
141
142 // Pointer to complex GridFunctions to enable updates during nonlinear iterations
144};
145
146template <class FormType>
147void
149 const std::string & trial_var_name,
150 const std::string & test_var_name,
151 std::shared_ptr<FormType> form,
152 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> & kernels_map)
153{
154 if (kernels_map.Has(test_var_name) && kernels_map.Get(test_var_name)->Has(trial_var_name))
155 {
156 auto kernels = kernels_map.GetRef(test_var_name).GetRef(trial_var_name);
157 for (auto & kernel : kernels)
158 {
159 mfem::BilinearFormIntegrator * integ_real = kernel->getRealBFIntegrator();
160 mfem::BilinearFormIntegrator * integ_imag = kernel->getImagBFIntegrator();
161
162 if (integ_real || integ_imag)
163 {
164 kernel->isSubdomainRestricted()
165 ? form->AddDomainIntegrator(
166 std::move(integ_real), std::move(integ_imag), kernel->getSubdomainMarkers())
167 : form->AddDomainIntegrator(std::move(integ_real), std::move(integ_imag));
168 }
169 }
170 }
171}
172
173inline void
175 const std::string & test_var_name,
176 std::shared_ptr<mfem::ParComplexLinearForm> form,
177 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexKernel>>>> & kernels_map)
178{
179 if (kernels_map.Has(test_var_name))
180 {
181 auto kernels = kernels_map.GetRef(test_var_name).GetRef(test_var_name);
182 for (auto & kernel : kernels)
183 {
184 mfem::LinearFormIntegrator * integ_real = kernel->getRealLFIntegrator();
185 mfem::LinearFormIntegrator * integ_imag = kernel->getImagLFIntegrator();
186
187 if (integ_real || integ_imag)
188 {
189 kernel->isSubdomainRestricted()
190 ? form->AddDomainIntegrator(
191 std::move(integ_real), std::move(integ_imag), kernel->getSubdomainMarkers())
192 : form->AddDomainIntegrator(std::move(integ_real), std::move(integ_imag));
193 }
194 }
195 }
196}
197
198template <class FormType>
199void
201 const std::string & trial_var_name,
202 const std::string & test_var_name,
203 std::shared_ptr<FormType> form,
204 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
205 integrated_bc_map)
206{
207 if (integrated_bc_map.Has(test_var_name) &&
208 integrated_bc_map.Get(test_var_name)->Has(trial_var_name))
209 {
210 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(trial_var_name);
211 for (auto & bc : bcs)
212 {
213 mfem::BilinearFormIntegrator * integ_real = bc->getRealBFIntegrator();
214 mfem::BilinearFormIntegrator * integ_imag = bc->getImagBFIntegrator();
215
216 if (integ_real || integ_imag)
217 {
218 bc->isBoundaryRestricted()
219 ? form->AddBoundaryIntegrator(
220 std::move(integ_real), std::move(integ_imag), bc->getBoundaryMarkers())
221 : form->AddBoundaryIntegrator(std::move(integ_real), std::move(integ_imag));
222 }
223 }
224 }
225}
226
227inline void
229 const std::string & test_var_name,
230 std::shared_ptr<mfem::ParComplexLinearForm> form,
231 NamedFieldsMap<NamedFieldsMap<std::vector<std::shared_ptr<MFEMComplexIntegratedBC>>>> &
232 integrated_bc_map)
233{
234 if (integrated_bc_map.Has(test_var_name))
235 {
236 auto bcs = integrated_bc_map.GetRef(test_var_name).GetRef(test_var_name);
237 for (auto & bc : bcs)
238 {
239 mfem::LinearFormIntegrator * integ_real = bc->getRealLFIntegrator();
240 mfem::LinearFormIntegrator * integ_imag = bc->getImagLFIntegrator();
241
242 if (integ_real || integ_imag)
243 {
244 bc->isBoundaryRestricted()
245 ? form->AddBoundaryIntegrator(
246 std::move(integ_real), std::move(integ_imag), bc->getBoundaryMarkers())
247 : form->AddBoundaryIntegrator(std::move(integ_real), std::move(integ_imag));
248 }
249 }
250 }
251}
252
253}
254
255#endif
Class to store weak form components (bilinear and linear forms, and optionally mixed and nonlinear fo...
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).