MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
bilinearform_ext.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, 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_BILINEARFORM_EXT
13 #define MFEM_BILINEARFORM_EXT
14 
15 #include "../config/config.hpp"
16 #include "fespace.hpp"
17 #include "../general/device.hpp"
18 
19 namespace mfem
20 {
21 
22 class BilinearForm;
23 class MixedBilinearForm;
24 
25 /// Class extending the BilinearForm class to support different AssemblyLevels.
26 /** FA - Full Assembly
27  PA - Partial Assembly
28  EA - Element Assembly
29  MF - Matrix Free
30 */
32 {
33 protected:
34  BilinearForm *a; ///< Not owned
35 
36 public:
38 
39  virtual MemoryClass GetMemoryClass() const
40  { return Device::GetDeviceMemoryClass(); }
41 
42  /// Get the finite element space prolongation matrix
43  virtual const Operator *GetProlongation() const;
44 
45  /// Get the finite element space restriction matrix
46  virtual const Operator *GetRestriction() const;
47 
48  /// Assemble at the level given for the BilinearFormExtension subclass
49  virtual void Assemble() = 0;
50 
51  virtual void AssembleDiagonal(Vector &diag) const
52  {
53  MFEM_ABORT("AssembleDiagonal not implemented for this assembly level!");
54  }
55 
56  virtual void FormSystemMatrix(const Array<int> &ess_tdof_list,
57  OperatorHandle &A) = 0;
58  virtual void FormLinearSystem(const Array<int> &ess_tdof_list,
59  Vector &x, Vector &b,
60  OperatorHandle &A, Vector &X, Vector &B,
61  int copy_interior = 0) = 0;
62  virtual void Update() = 0;
63 };
64 
65 /// Data and methods for partially-assembled bilinear forms
67 {
68 protected:
69  const FiniteElementSpace *trialFes, *testFes; // Not owned
70  mutable Vector localX, localY;
73  const Operator *elem_restrict; // Not owned
74  const Operator *int_face_restrict_lex; // Not owned
75  const Operator *bdr_face_restrict_lex; // Not owned
76 
77 public:
79 
80  void Assemble();
81  void AssembleDiagonal(Vector &diag) const;
82  void FormSystemMatrix(const Array<int> &ess_tdof_list, OperatorHandle &A);
83  void FormLinearSystem(const Array<int> &ess_tdof_list,
84  Vector &x, Vector &b,
85  OperatorHandle &A, Vector &X, Vector &B,
86  int copy_interior = 0);
87  void Mult(const Vector &x, Vector &y) const;
88  void MultTranspose(const Vector &x, Vector &y) const;
89  void Update();
90 
91 protected:
93 };
94 
95 /// Data and methods for element-assembled bilinear forms
97 {
98 protected:
99  int ne;
100  int elemDofs;
101  // The element matrices are stored row major
104  int faceDofs;
107 
108 public:
110 
111  void Assemble();
112  void Mult(const Vector &x, Vector &y) const;
113  void MultTranspose(const Vector &x, Vector &y) const;
114 };
115 
116 /// Data and methods for fully-assembled bilinear forms
118 {
119 private:
120  SparseMatrix mat;
121  /// face_mat handles parallelism for DG face terms.
122  SparseMatrix face_mat;
123  bool use_face_mat;
124 
125 public:
127 
128  void Assemble();
129  void Mult(const Vector &x, Vector &y) const;
130  void MultTranspose(const Vector &x, Vector &y) const;
131 };
132 
133 /// Data and methods for matrix-free bilinear forms
135 {
136 protected:
137  const FiniteElementSpace *trialFes, *testFes; // Not owned
138  mutable Vector localX, localY;
141  const Operator *elem_restrict; // Not owned
142  const Operator *int_face_restrict_lex; // Not owned
143  const Operator *bdr_face_restrict_lex; // Not owned
144 
145 public:
147 
148  void Assemble();
149  void AssembleDiagonal(Vector &diag) const;
150  void FormSystemMatrix(const Array<int> &ess_tdof_list, OperatorHandle &A);
151  void FormLinearSystem(const Array<int> &ess_tdof_list,
152  Vector &x, Vector &b,
153  OperatorHandle &A, Vector &X, Vector &B,
154  int copy_interior = 0);
155  void Mult(const Vector &x, Vector &y) const;
156  void MultTranspose(const Vector &x, Vector &y) const;
157  void Update();
158 };
159 
160 /// Class extending the MixedBilinearForm class to support different AssemblyLevels.
161 /** FA - Full Assembly
162  PA - Partial Assembly
163  EA - Element Assembly
164  MF - Matrix Free
165 */
167 {
168 protected:
169  MixedBilinearForm *a; ///< Not owned
170 
171 public:
173 
174  virtual MemoryClass GetMemoryClass() const
175  { return Device::GetMemoryClass(); }
176 
177  /// Get the finite element space prolongation matrix
178  virtual const Operator *GetProlongation() const;
179 
180  /// Get the finite element space restriction matrix
181  virtual const Operator *GetRestriction() const;
182 
183  /// Get the output finite element space restriction matrix
184  virtual const Operator *GetOutputProlongation() const;
185 
186  /// Get the output finite element space restriction matrix
187  virtual const Operator *GetOutputRestriction() const;
188 
189  virtual void Assemble() = 0;
190  virtual void FormRectangularSystemOperator(const Array<int> &trial_tdof_list,
191  const Array<int> &test_tdof_list,
192  OperatorHandle &A) = 0;
193  virtual void FormRectangularLinearSystem(const Array<int> &trial_tdof_list,
194  const Array<int> &test_tdof_list,
195  Vector &x, Vector &b,
196  OperatorHandle &A, Vector &X, Vector &B) = 0;
197 
198  virtual void AddMult(const Vector &x, Vector &y, const double c=1.0) const = 0;
199  virtual void AddMultTranspose(const Vector &x, Vector &y,
200  const double c=1.0) const = 0;
201 
202  virtual void AssembleDiagonal_ADAt(const Vector &D, Vector &diag) const = 0;
203 
204  virtual void Update() = 0;
205 };
206 
207 /// Data and methods for partially-assembled mixed bilinear forms
209 {
210 protected:
211  const FiniteElementSpace *trialFes, *testFes; // Not owned
213  const Operator *elem_restrict_trial; // Not owned
214  const Operator *elem_restrict_test; // Not owned
215 private:
216  /// Helper function to set up inputs/outputs for Mult or MultTranspose
217  void SetupMultInputs(const Operator *elem_restrict_x,
218  const Vector &x, Vector &localX,
219  const Operator *elem_restrict_y,
220  Vector &y, Vector &localY, const double c) const;
221 
222 public:
224 
225  /// Partial assembly of all internal integrators
226  void Assemble();
227  /**
228  @brief Setup OperatorHandle A to contain constrained linear operator
229 
230  OperatorHandle A contains matrix-free constrained operator formed for RAP
231  system where ess_tdof_list are in trial space and eliminated from
232  "columns" of A.
233  */
234  void FormRectangularSystemOperator(const Array<int> &trial_tdof_list,
235  const Array<int> &test_tdof_list,
236  OperatorHandle &A);
237  /**
238  Setup OperatorHandle A to contain constrained linear operator and
239  eliminate columns corresponding to essential dofs from system,
240  updating RHS B vector with the results.
241  */
242  void FormRectangularLinearSystem(const Array<int> &trial_tdof_list,
243  const Array<int> &test_tdof_list,
244  Vector &x, Vector &b,
245  OperatorHandle &A, Vector &X, Vector &B);
246  /// y = A*x
247  void Mult(const Vector &x, Vector &y) const;
248  /// y += c*A*x
249  void AddMult(const Vector &x, Vector &y, const double c=1.0) const;
250  /// y = A^T*x
251  void MultTranspose(const Vector &x, Vector &y) const;
252  /// y += c*A^T*x
253  void AddMultTranspose(const Vector &x, Vector &y, const double c=1.0) const;
254  /// Assemble the diagonal of ADA^T for a diagonal vector D.
255  void AssembleDiagonal_ADAt(const Vector &D, Vector &diag) const;
256 
257  /// Update internals for when a new MixedBilinearForm is given to this class
258  void Update();
259 };
260 
261 }
262 
263 #endif
static MemoryClass GetMemoryClass()
(DEPRECATED) Equivalent to GetDeviceMemoryClass().
Definition: device.hpp:273
const Operator * bdr_face_restrict_lex
void AssembleDiagonal_ADAt(const Vector &D, Vector &diag) const
Assemble the diagonal of ADA^T for a diagonal vector D.
L2FaceValues
Definition: restriction.hpp:26
void FormRectangularSystemOperator(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, OperatorHandle &A)
Setup OperatorHandle A to contain constrained linear operator.
Data and methods for matrix-free bilinear forms.
const FiniteElementSpace * testFes
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
MFBilinearFormExtension(BilinearForm *form)
void Assemble()
Assemble at the level given for the BilinearFormExtension subclass.
void Assemble()
Assemble at the level given for the BilinearFormExtension subclass.
void AddMultTranspose(const Vector &x, Vector &y, const double c=1.0) const
y += c*A^T*x
Pointer to an Operator of a specified type.
Definition: handle.hpp:33
PAMixedBilinearFormExtension(MixedBilinearForm *form)
void MultTranspose(const Vector &x, Vector &y) const
y = A^T*x
virtual void AddMult(const Vector &x, Vector &y, const double c=1.0) const =0
virtual const Operator * GetRestriction() const
Get the finite element space restriction matrix.
virtual const Operator * GetRestriction() const
Get the finite element space restriction matrix.
BilinearFormExtension(BilinearForm *form)
virtual void AddMultTranspose(const Vector &x, Vector &y, const double c=1.0) const =0
Data and methods for partially-assembled bilinear forms.
virtual void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)=0
Class extending the MixedBilinearForm class to support different AssemblyLevels.
virtual const Operator * GetOutputProlongation() const
Get the output finite element space restriction matrix.
void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
virtual const Operator * GetProlongation() const
Get the finite element space prolongation matrix.
void Assemble()
Partial assembly of all internal integrators.
virtual void FormRectangularSystemOperator(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, OperatorHandle &A)=0
Data type sparse matrix.
Definition: sparsemat.hpp:46
virtual void AssembleDiagonal(Vector &diag) const
static MemoryClass GetDeviceMemoryClass()
Get the current Device MemoryClass. This is the MemoryClass used by most MFEM device kernels to acces...
Definition: device.hpp:269
Data and methods for fully-assembled bilinear forms.
const FiniteElementSpace * trialFes
double b
Definition: lissajous.cpp:42
BilinearForm * a
Not owned.
void AssembleDiagonal(Vector &diag) const
virtual void Assemble()=0
Assemble at the level given for the BilinearFormExtension subclass.
void AddMult(const Vector &x, Vector &y, const double c=1.0) const
y += c*A*x
Class extending the BilinearForm class to support different AssemblyLevels.
virtual const Operator * GetProlongation() const
Get the finite element space prolongation matrix.
FABilinearFormExtension(BilinearForm *form)
const FiniteElementSpace * testFes
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)
void FormRectangularLinearSystem(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B)
void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
void Assemble()
Assemble at the level given for the BilinearFormExtension subclass.
void SetupRestrictionOperators(const L2FaceValues m)
void Mult(const Vector &x, Vector &y) const
y = A*x
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Data and methods for element-assembled bilinear forms.
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:87
const FiniteElementSpace * trialFes
void Assemble()
Assemble at the level given for the BilinearFormExtension subclass.
EABilinearFormExtension(BilinearForm *form)
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
MixedBilinearForm * a
Not owned.
A &quot;square matrix&quot; operator for the associated FE space and BLFIntegrators The sum of all the BLFInteg...
virtual const Operator * GetOutputRestriction() const
Get the output finite element space restriction matrix.
const Operator * int_face_restrict_lex
void Update()
Update internals for when a new MixedBilinearForm is given to this class.
virtual MemoryClass GetMemoryClass() const
Return the MemoryClass preferred by the Operator.
void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Data and methods for partially-assembled mixed bilinear forms.
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Vector data type.
Definition: vector.hpp:51
const FiniteElementSpace * trialFes
virtual void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)=0
const FiniteElementSpace * testFes
void AssembleDiagonal(Vector &diag) const
virtual MemoryClass GetMemoryClass() const
Return the MemoryClass preferred by the Operator.
Abstract operator.
Definition: operator.hpp:24
MixedBilinearFormExtension(MixedBilinearForm *form)
void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
MemoryClass
Memory classes identify sets of memory types.
Definition: mem_manager.hpp:58
virtual void FormRectangularLinearSystem(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B)=0
virtual void AssembleDiagonal_ADAt(const Vector &D, Vector &diag) const =0