MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
complexweakform.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_COMPLEX_DPGWEAKFORM
13#define MFEM_COMPLEX_DPGWEAKFORM
14
15#include "mfem.hpp"
16#include "complexstaticcond.hpp"
17
18namespace mfem
19{
20
21/** @brief Class representing the DPG weak formulation for complex valued systems
22 (see the class DPGWeakForm). */
24{
25
26protected:
27
29
30 bool initialized = false;
31
32 Mesh * mesh = nullptr;
37
38 /// Block matrix $ M $ to be associated with the real/imag Block bilinear form. Owned.
39 BlockMatrix *mat_r = nullptr;
40 BlockMatrix *mat_i = nullptr;
41 ComplexOperator * mat = nullptr;
42
43 /// BlockVectors to be associated with the real/imag Block linear form
44 BlockVector * y_r = nullptr;
45 BlockVector * y_i = nullptr;
46 Vector * y = nullptr;
47
48 /** @brief Block Matrix $ M_e $ used to store the eliminations
49 from the b.c. Owned.
50 $ M + M_e = M_{original} $ */
51 BlockMatrix *mat_e_r = nullptr;
52 BlockMatrix *mat_e_i = nullptr;
53
54 /// Trial FE spaces
56
57 /// Flags to determine if a FiniteElementSpace is Trace
59
60 /// Test FE Collections (Broken)
63
64 /// Set of Trial Integrators to be applied for matrix B
67
68 /// Set of Test Space (broken) Integrators to be applied for matrix G
71
72 /// Set of LinearForm Integrators to be applied.
75
76 /// Block Prolongation
77 BlockMatrix * P = nullptr;
78 /// Block Restriction
79 BlockMatrix * R = nullptr;
80
82
83 void Init();
84 void ReleaseInitMemory();
85
86 // Allocate appropriate SparseMatrix and assign it to mat
87 void AllocMat();
88
89 void ConformingAssemble();
90
91 void ComputeOffsets();
92
93 virtual void BuildProlongation();
94
95 bool store_matrices = false;
96
97 /** Store the matrix L^-1 B and Vector L^-1 l
98 where G = L L^t */
102
103private:
104
105public:
106
108 {
109 height = 0;
110 width = 0;
111 }
112
113 /// Creates bilinear form associated with FE spaces @a fes_.
119
120 void SetTestFECollVdim(int test_fec, int vdim)
121 {
122 test_fecols_vdims[test_fec] = vdim;
123 }
124
127 {
128 trial_fes = fes_;
129 test_fecols = fecol_;
133 mesh = trial_fes[0]->GetMesh();
134
136 // Initialize with False
137 IsTraceFes = false;
138 for (int i = 0; i < nblocks; i++)
139 {
140 IsTraceFes[i] =
141 (dynamic_cast<const H1_Trace_FECollection*>(trial_fes[i]->FEColl()) ||
142 dynamic_cast<const ND_Trace_FECollection*>(trial_fes[i]->FEColl()) ||
143 dynamic_cast<const RT_Trace_FECollection*>(trial_fes[i]->FEColl()));
144 }
145 Init();
146 }
147
148 // Get the size of the bilinear form of the ComplexDPGWeakForm
149 int Size() const { return height; }
150
151 // Pre-allocate the internal real and imag BlockMatrix before assembly.
152 void AllocateMatrix() { if (mat_r == nullptr) { AllocMat(); } }
153
154 /// Finalizes the matrix initialization.
155 void Finalize(int skip_zeros = 1);
156
157 /// Returns a reference to the BlockMatrix: $ M_r $
159 {
160 MFEM_VERIFY(mat_r, "mat_r is NULL and can't be dereferenced");
161 return *mat_r;
162 }
163 /// Returns a reference to the BlockMatrix: $ M_i $
165 {
166 MFEM_VERIFY(mat_i, "mat_i is NULL and can't be dereferenced");
167 return *mat_i;
168 }
169
170 /// Returns a reference to the BlockMatrix of eliminated b.c.: $ M_e_r $
172 {
173 MFEM_VERIFY(mat_e_r, "mat_e is NULL and can't be dereferenced");
174 return *mat_e_r;
175 }
176
177 /// Returns a reference to the BlockMatrix of eliminated b.c.: $ M_e_i $
179 {
180 MFEM_VERIFY(mat_e_i, "mat_e is NULL and can't be dereferenced");
181 return *mat_e_i;
182 }
183
184 /** Adds new Trial Integrator. Assumes ownership of @a bfi_r and @a bfi_i.
185 @a n and @a m correspond to the trial FESpace and test FEColl
186 respectively */
189 int n, int m);
190
191 /// Adds new Test Integrator. Assumes ownership of @a bfi_r and @a bfi_i.
194 int n, int m);
195
196 /// Adds new Domain LF Integrator. Assumes ownership of @a lfi_r and lfi_i.
199 int n);
200
201 /// Assembles the form i.e. sums over all integrators.
202 void Assemble(int skip_zeros = 1);
203
204 virtual void FormLinearSystem(const Array<int> &ess_tdof_list,
205 Vector &x, OperatorHandle & A,
206 Vector &X, Vector &B,
207 int copy_interior = 0);
208
209 template <typename OpType>
211 Vector &x, OpType &A,
212 Vector &X, Vector &B,
213 int copy_interior = 0)
214 {
216 FormLinearSystem(ess_tdof_list, x, Ah, X, B, copy_interior);
217 OpType *A_ptr = Ah.Is<OpType>();
218 MFEM_VERIFY(A_ptr, "invalid OpType used");
219 A.MakeRef(*A_ptr);
220 }
221
222 virtual void FormSystemMatrix(const Array<int> &ess_tdof_list,
223 OperatorHandle &A);
224
225 template <typename OpType>
227 {
230 OpType *A_ptr = Ah.Is<OpType>();
231 MFEM_VERIFY(A_ptr, "invalid OpType used");
232 A.MakeRef(*A_ptr);
233 }
234
235 void EliminateVDofs(const Array<int> &vdofs,
237
238 void EliminateVDofsInRHS(const Array<int> &vdofs,
239 const Vector &x_r, const Vector & x_i,
240 Vector &b_r, Vector & b_i);
241
242 virtual void RecoverFEMSolution(const Vector &X,Vector &x);
243
244 /// Sets diagonal policy used upon construction of the linear system.
245 /** Policies include:
246 - DIAG_ZERO (Set the diagonal values to zero)
247 - DIAG_ONE (Set the diagonal values to one)
248 - DIAG_KEEP (Keep the diagonal values)
249 */
251 {
252 diag_policy = policy;
253 }
254
255 virtual void Update();
256
257 void StoreMatrices(bool store_matrices_ = true)
258 {
259 store_matrices = store_matrices_;
260 if (Bmat.Size() == 0)
261 {
262 Bmat.SetSize(mesh->GetNE());
263 fvec.SetSize(mesh->GetNE());
264 for (int i =0; i<mesh->GetNE(); i++)
265 {
266 Bmat[i] = nullptr;
267 fvec[i] = nullptr;
268 }
269 }
270 }
271
273
274 Vector & ComputeResidual(const Vector & x);
275
277 {
278 trace_fes.SetSize(0);
279 Array<FiniteElementSpace *> trace_fes_all;
280 if (static_cond)
281 {
282 static_cond->GetTraceFESpaces(trace_fes_all);
283 for (int i = 0; i < trace_fes_all.Size(); i++)
284 {
285 if (trace_fes_all[i])
286 {
287 trace_fes.Append(trace_fes_all[i]);
288 }
289 }
290 }
291 }
292
293 /// Destroys bilinear form.
294 virtual ~ComplexDPGWeakForm();
295
296};
297
298} // namespace mfem
299
300#endif
Dynamic 2D array using row-major layout.
Definition array.hpp:459
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition array.hpp:869
int Size() const
Return the logical size of the array.
Definition array.hpp:192
int Append(const T &el)
Append element 'el' to array, resize if necessary.
Definition array.hpp:941
Abstract base class BilinearFormIntegrator.
A class to handle Vectors in a block fashion.
Class that performs static condensation of interior dofs for multiple FE spaces for complex systems (...
void GetTraceFESpaces(Array< FiniteElementSpace * > &trace_fes) const
Class representing the DPG weak formulation for complex valued systems (see the class DPGWeakForm).
void AddTestIntegrator(BilinearFormIntegrator *bfi_r, BilinearFormIntegrator *bfi_i, int n, int m)
Adds new Test Integrator. Assumes ownership of bfi_r and bfi_i.
void SetTestFECollVdim(int test_fec, int vdim)
BlockMatrix * mat_e_r
Block Matrix used to store the eliminations from the b.c. Owned. .
Array2D< Array< BilinearFormIntegrator * > * > test_integs_r
Set of Test Space (broken) Integrators to be applied for matrix G.
Array< FiniteElementSpace * > trial_fes
Trial FE spaces.
Array< int > IsTraceFes
Flags to determine if a FiniteElementSpace is Trace.
Array< ComplexDenseMatrix * > Bmat
void SetSpaces(Array< FiniteElementSpace * > &fes_, Array< FiniteElementCollection * > &fecol_)
virtual void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)
void SetDiagonalPolicy(Operator::DiagonalPolicy policy)
Sets diagonal policy used upon construction of the linear system.
ComplexDPGWeakForm(Array< FiniteElementSpace * > &fes_, Array< FiniteElementCollection * > &fecol_)
Creates bilinear form associated with FE spaces fes_.
BlockMatrix & BlockMatElim_r()
Returns a reference to the BlockMatrix of eliminated b.c.: .
Array2D< Array< BilinearFormIntegrator * > * > test_integs_i
mfem::Operator::DiagonalPolicy diag_policy
BlockMatrix & BlockMat_r()
Returns a reference to the BlockMatrix: .
void GetTraceFESpaces(Array< FiniteElementSpace * > &trace_fes) const
void AddTrialIntegrator(BilinearFormIntegrator *bfi_r, BilinearFormIntegrator *bfi_i, int n, int m)
Adds new Domain BF Integrator. Assumes ownership of bfi.
void EliminateVDofsInRHS(const Array< int > &vdofs, const Vector &x_r, const Vector &x_i, Vector &b_r, Vector &b_i)
BlockMatrix & BlockMat_i()
Returns a reference to the BlockMatrix: .
BlockMatrix * P
Block Prolongation.
void FormSystemMatrix(const Array< int > &ess_tdof_list, OpType &A)
BlockMatrix & BlockMatElim_i()
Returns a reference to the BlockMatrix of eliminated b.c.: .
BlockMatrix * R
Block Restriction.
virtual void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, OpType &A, Vector &X, Vector &B, int copy_interior=0)
void StoreMatrices(bool store_matrices_=true)
Array2D< Array< BilinearFormIntegrator * > * > trial_integs_r
Set of Trial Integrators to be applied for matrix B.
void AddDomainLFIntegrator(LinearFormIntegrator *lfi_r, LinearFormIntegrator *lfi_i, int n)
Adds new Domain LF Integrator. Assumes ownership of lfi_r and lfi_i.
BlockMatrix * mat_r
Block matrix to be associated with the real/imag Block bilinear form. Owned.
Array2D< Array< BilinearFormIntegrator * > * > trial_integs_i
void Finalize(int skip_zeros=1)
Finalizes the matrix initialization.
Array< Array< LinearFormIntegrator * > * > lfis_i
Vector & ComputeResidual(const Vector &x)
void EliminateVDofs(const Array< int > &vdofs, Operator::DiagonalPolicy dpolicy=Operator::DIAG_ONE)
void Assemble(int skip_zeros=1)
Assembles the form i.e. sums over all integrators.
virtual ~ComplexDPGWeakForm()
Destroys bilinear form.
Array< FiniteElementCollection * > test_fecols
Test FE Collections (Broken)
BlockVector * y_r
BlockVectors to be associated with the real/imag Block linear form.
Array< Array< LinearFormIntegrator * > * > lfis_r
Set of LinearForm Integrators to be applied.
virtual void RecoverFEMSolution(const Vector &X, Vector &x)
ComplexBlockStaticCondensation * static_cond
Owned.
Mimic the action of a complex operator using two real operators.
Arbitrary order "H^{1/2}-conforming" trace finite elements defined on the interface between mesh elem...
Definition fe_coll.hpp:357
Abstract base class LinearFormIntegrator.
Definition lininteg.hpp:28
Mesh data type.
Definition mesh.hpp:67
int GetNE() const
Returns number of elements.
Definition mesh.hpp:1390
Arbitrary order H(curl)-trace finite elements defined on the interface between mesh elements (faces,...
Definition fe_coll.hpp:575
Pointer to an Operator of a specified type.
Definition handle.hpp:34
OpType * Is() const
Return the Operator pointer dynamically cast to a specified OpType.
Definition handle.hpp:108
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
Definition operator.hpp:50
@ DIAG_ONE
Set the diagonal value to one.
Definition operator.hpp:52
Arbitrary order "H^{-1/2}-conforming" face finite elements defined on the interface between mesh elem...
Definition fe_coll.hpp:492
Vector data type.
Definition vector.hpp:82
const int * ess_tdof_list