MFEM  v4.6.0
Finite element discretization library
complexweakform.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, 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 
18 namespace mfem
19 {
20 
21 /** @brief Class representing the DPG weak formulation for complex valued systems
22  (see the class DPGWeakForm). */
24 {
25 
26 protected:
27 
29 
30  bool initialized = false;
31 
32  Mesh * mesh = nullptr;
33  int height, width;
34  int nblocks;
37 
38  /// Block matrix \f$ M \f$ 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 \f$ M_e \f$ used to store the eliminations
49  from the b.c. Owned.
50  \f$ M + M_e = M_{original} \f$ */
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 
103 private:
104 
105 public:
106 
108  {
109  height = 0;
110  width = 0;
111  }
112 
113  /// Creates bilinear form associated with FE spaces @a fes_.
116  {
117  SetSpaces(fes_,fecol_);
118  }
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_;
131  test_fecols_vdims = 1;
132  nblocks = trial_fes.Size();
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: \f$ M_r \f$
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: \f$ M_i \f$
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.: \f$ M_e_r \f$
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.: \f$ M_e_i \f$
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 */
188  BilinearFormIntegrator *bfi_i,
189  int n, int m);
190 
191  /// Adds new Test Integrator. Assumes ownership of @a bfi_r and @a bfi_i.
193  BilinearFormIntegrator *bfi_i,
194  int n, int m);
195 
196  /// Adds new Domain LF Integrator. Assumes ownership of @a lfi_r and lfi_i.
198  LinearFormIntegrator *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>
210  void FormLinearSystem(const Array<int> &ess_tdof_list,
211  Vector &x, OpType &A,
212  Vector &X, Vector &B,
213  int copy_interior = 0)
214  {
215  OperatorHandle Ah;
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>
226  void FormSystemMatrix(const Array<int> &ess_tdof_list, OpType &A)
227  {
228  OperatorHandle Ah;
229  FormSystemMatrix(ess_tdof_list, Ah);
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 
276  /// Destroys bilinear form.
277  virtual ~ComplexDPGWeakForm();
278 
279 };
280 
281 } // namespace mfem
282 
283 #endif
void Finalize(int skip_zeros=1)
Finalizes the matrix initialization.
virtual void BuildProlongation()
Array< int > IsTraceFes
Flags to determine if a FiniteElementSpace is Trace.
Class that performs static condensation of interior dofs for multiple FE spaces for complex systems (...
void SetDiagonalPolicy(Operator::DiagonalPolicy policy)
Sets diagonal policy used upon construction of the linear system.
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, OpType &A, Vector &X, Vector &B, int copy_interior=0)
A class to handle Vectors in a block fashion.
Definition: blockvector.hpp:30
void Assemble(int skip_zeros=1)
Assembles the form i.e. sums over all integrators.
void FormSystemMatrix(const Array< int > &ess_tdof_list, OpType &A)
Mimic the action of a complex operator using two real operators.
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.
Pointer to an Operator of a specified type.
Definition: handle.hpp:33
OpType * Is() const
Return the Operator pointer dynamically cast to a specified OpType.
Definition: handle.hpp:108
BlockMatrix * mat_r
Block matrix to be associated with the real/imag Block bilinear form. Owned.
Array2D< Array< BilinearFormIntegrator *> *> trial_integs_r
Set of Trial Integrators to be applied for matrix B.
Array2D< Array< BilinearFormIntegrator *> *> test_integs_i
Abstract base class LinearFormIntegrator.
Definition: lininteg.hpp:24
BlockMatrix & BlockMatElim_i()
Returns a reference to the BlockMatrix of eliminated b.c.: .
Array< Array< LinearFormIntegrator *> *> lfis_r
Set of LinearForm Integrators to be applied.
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.
BlockMatrix * R
Block Restriction.
Array2D< Array< BilinearFormIntegrator *> *> trial_integs_i
BlockMatrix * P
Block Prolongation.
void AddDomainLFIntegrator(LinearFormIntegrator *lfi_r, LinearFormIntegrator *lfi_i, int n)
Adds new Domain LF Integrator. Assumes ownership of lfi_r and lfi_i.
void StoreMatrices(bool store_matrices_=true)
Arbitrary order "H^{1/2}-conforming" trace finite elements defined on the interface between mesh elem...
Definition: fe_coll.hpp:319
void SetSpaces(Array< FiniteElementSpace * > &fes_, Array< FiniteElementCollection *> &fecol_)
virtual void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
Array< Array< LinearFormIntegrator *> *> lfis_i
Set the diagonal value to one.
Definition: operator.hpp:50
void EliminateVDofsInRHS(const Array< int > &vdofs, const Vector &x_r, const Vector &x_i, Vector &b_r, Vector &b_i)
mfem::Operator::DiagonalPolicy diag_policy
Dynamic 2D array using row-major layout.
Definition: array.hpp:354
BlockMatrix & BlockMat_r()
Returns a reference to the BlockMatrix: .
Array< ComplexDenseMatrix *> Bmat
Abstract base class BilinearFormIntegrator.
Definition: bilininteg.hpp:24
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.: .
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition: array.hpp:687
virtual void RecoverFEMSolution(const Vector &X, Vector &x)
int GetNE() const
Returns number of elements.
Definition: mesh.hpp:1086
BlockMatrix * mat_e_r
Block Matrix used to store the eliminations from the b.c. Owned. .
void SetTestFECollVdim(int test_fec, int vdim)
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
Definition: operator.hpp:47
void AddTrialIntegrator(BilinearFormIntegrator *bfi_r, BilinearFormIntegrator *bfi_i, int n, int m)
Adds new Domain BF Integrator. Assumes ownership of bfi.
int Size() const
Return the logical size of the array.
Definition: array.hpp:141
virtual void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)
BlockMatrix & BlockMat_i()
Returns a reference to the BlockMatrix: .
Vector & ComputeResidual(const Vector &x)
Vector data type.
Definition: vector.hpp:58
ComplexBlockStaticCondensation * static_cond
Owned.
virtual ~ComplexDPGWeakForm()
Destroys bilinear form.
void EliminateVDofs(const Array< int > &vdofs, Operator::DiagonalPolicy dpolicy=Operator::DIAG_ONE)
BlockVector * y_r
BlockVectors to be associated with the real/imag Block linear form.
Array< FiniteElementCollection * > test_fecols
Test FE Collections (Broken)