MFEM  v4.3.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
restriction.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2021, 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_RESTRICTION
13 #define MFEM_RESTRICTION
14 
15 #include "../linalg/operator.hpp"
16 #include "../mesh/mesh.hpp"
17 
18 namespace mfem
19 {
20 
21 class FiniteElementSpace;
22 enum class ElementDofOrdering;
23 
24 /// Operator that converts FiniteElementSpace L-vectors to E-vectors.
25 /** Objects of this type are typically created and owned by FiniteElementSpace
26  objects, see FiniteElementSpace::GetElementRestriction(). */
28 {
29 private:
30  /** This number defines the maximum number of elements any dof can belong to
31  for the FillSparseMatrix method. */
32  static const int MaxNbNbr = 16;
33 
34 protected:
36  const int ne;
37  const int vdim;
38  const bool byvdim;
39  const int ndofs;
40  const int dof;
41  const int nedofs;
45 
46 public:
48  void Mult(const Vector &x, Vector &y) const;
49  void MultTranspose(const Vector &x, Vector &y) const;
50 
51  /// Compute Mult without applying signs based on DOF orientations.
52  void MultUnsigned(const Vector &x, Vector &y) const;
53  /// Compute MultTranspose without applying signs based on DOF orientations.
54  void MultTransposeUnsigned(const Vector &x, Vector &y) const;
55 
56  /// Compute MultTranspose by setting (rather than adding) element
57  /// contributions; this is a left inverse of the Mult() operation
58  void MultLeftInverse(const Vector &x, Vector &y) const;
59 
60  /// @brief Fills the E-vector y with `boolean` values 0.0 and 1.0 such that each
61  /// each entry of the L-vector is uniquely represented in `y`.
62  /** This means, the sum of the E-vector `y` is equal to the sum of the
63  corresponding L-vector filled with ones. The boolean mask is required to
64  emulate SetSubVector and its transpose on GPUs. This method is running on
65  the host, since the `processed` array requires a large shared memory. */
66  void BooleanMask(Vector& y) const;
67 
68  /// Fill a Sparse Matrix with Element Matrices.
69  void FillSparseMatrix(const Vector &mat_ea, SparseMatrix &mat) const;
70 
71  /** Fill the I array of SparseMatrix corresponding to the sparsity pattern
72  given by this ElementRestriction. */
73  int FillI(SparseMatrix &mat) const;
74  /** Fill the J and Data arrays of SparseMatrix corresponding to the sparsity
75  pattern given by this ElementRestriction, and the values of ea_data. */
76  void FillJAndData(const Vector &ea_data, SparseMatrix &mat) const;
77 };
78 
79 /// Operator that converts L2 FiniteElementSpace L-vectors to E-vectors.
80 /** Objects of this type are typically created and owned by FiniteElementSpace
81  objects, see FiniteElementSpace::GetElementRestriction(). L-vectors
82  corresponding to grid functions in L2 finite element spaces differ from
83  E-vectors only in the ordering of the degrees of freedom. */
85 {
86  const int ne;
87  const int vdim;
88  const bool byvdim;
89  const int ndof;
90  const int ndofs;
91 public:
93  void Mult(const Vector &x, Vector &y) const;
94  void MultTranspose(const Vector &x, Vector &y) const;
95  /** Fill the I array of SparseMatrix corresponding to the sparsity pattern
96  given by this ElementRestriction. */
97  void FillI(SparseMatrix &mat) const;
98  /** Fill the J and Data arrays of SparseMatrix corresponding to the sparsity
99  pattern given by this L2FaceRestriction, and the values of ea_data. */
100  void FillJAndData(const Vector &ea_data, SparseMatrix &mat) const;
101 };
102 
103 /** An enum type to specify if only e1 value is requested (SingleValued) or both
104  e1 and e2 (DoubleValued). */
106 
107 /** @brief Base class for operators that extracts Face degrees of freedom.
108 
109  In order to compute quantities on the faces of a mesh, it is often useful to
110  extract the degrees of freedom on the faces of the elements. This class
111  provides an interface for such operations.
112 
113  If the FiniteElementSpace is ordered by Ordering::byVDIM, then the expected
114  format for the L-vector is (vdim x ndofs), otherwise if Ordering::byNODES
115  the expected format is (ndofs x vdim), where ndofs is the total number of
116  degrees of freedom.
117  Since FiniteElementSpace can either be continuous or discontinuous, the
118  degrees of freedom on a face can either be single valued or double valued,
119  this is what we refer to as the multiplicity and is represented by the
120  L2FaceValues enum type.
121  The format of the output face E-vector of degrees of freedom is
122  (face_dofs x vdim x multiplicity x nfaces), where face_dofs is the number of
123  degrees of freedom on each face, and nfaces the number of faces of the
124  requested FaceType (see FiniteElementSpace::GetNFbyType).
125 
126  @note Objects of this type are typically created and owned by
127  FiniteElementSpace objects, see FiniteElementSpace::GetFaceRestriction(). */
128 class FaceRestriction : public Operator
129 {
130 public:
132 
133  FaceRestriction(int h, int w): Operator(h, w) { }
134 
135  virtual ~FaceRestriction() { }
136 
137  /** @brief Extract the face degrees of freedom from @a x into @a y.
138 
139  @param[in] x The L-vector of degrees of freedom.
140  @param[out] y The degrees of freedom on the face, corresponding to a face
141  E-vector.
142  */
143  void Mult(const Vector &x, Vector &y) const override = 0;
144 
145  /** @brief Add the face degrees of freedom @a x to the element degrees of
146  freedom @a y.
147 
148  @param[in] x The face degrees of freedom on the face.
149  @param[in,out] y The L-vector of degrees of freedom to which we add the
150  face degrees of freedom.
151  */
152  virtual void AddMultTranspose(const Vector &x, Vector &y) const = 0;
153 
154  /** @brief Set the face degrees of freedom in the element degrees of freedom
155  @a y to the values given in @a x.
156 
157  @param[in] x The face degrees of freedom on the face.
158  @param[in,out] y The L-vector of degrees of freedom to which we add the
159  face degrees of freedom.
160  */
161  void MultTranspose(const Vector &x, Vector &y) const override
162  {
163  y = 0.0;
164  AddMultTranspose(x, y);
165  }
166 };
167 
168 /// Operator that extracts Face degrees of freedom for H1 FiniteElementSpaces.
169 /** Objects of this type are typically created and owned by FiniteElementSpace
170  objects, see FiniteElementSpace::GetFaceRestriction(). */
172 {
173 protected:
175  const int nf;
176  const int vdim;
177  const bool byvdim;
178  const int ndofs;
179  const int dof;
180  const int nfdofs;
184 
185 public:
186  /** @brief Constructor for a H1FaceRestriction.
187 
188  @param[in] fes The FiniteElementSpace on which this H1FaceRestriction
189  operates.
190  @param[in] ordering The requested output ordering of the
191  H1FaceRestriction, either Native or Lexicographic.
192  @param[in] type The requested type of faces on which this operator
193  extracts the degrees of freedom, either Interior or
194  Boundary.
195  */
197  const ElementDofOrdering ordering,
198  const FaceType type);
199 
200  /** @brief Extract the face degrees of freedom from @a x into @a y.
201 
202  @param[in] x The L-vector of degrees of freedom.
203  @param[out] y The degrees of freedom on the face, corresponding to a face
204  E-vector.
205  */
206  void Mult(const Vector &x, Vector &y) const override;
207 
208  /** @brief Add the face degrees of freedom @a x to the element degrees of
209  freedom @a y.
210 
211  @param[in] x The face degrees of freedom on the face.
212  @param[in,out] y The L-vector of degrees of freedom to which we add the
213  face degrees of freedom.
214  */
215  void AddMultTranspose(const Vector &x, Vector &y) const override;
216 };
217 
218 /// Operator that extracts Face degrees of freedom on L2 FiniteElementSpaces.
219 /** Objects of this type are typically created and owned by FiniteElementSpace
220  objects, see FiniteElementSpace::GetFaceRestriction(). */
222 {
223 protected:
225  const int nf;
226  const int ne;
227  const int vdim;
228  const bool byvdim;
229  const int ndofs;
230  const int dof;
231  const int elemDofs;
233  const int nfdofs;
238 
240  const FaceType,
242 
243 public:
245  const ElementDofOrdering,
246  const FaceType,
248 
249  /** @brief Extract the face degrees of freedom from @a x into @a y.
250 
251  @param[in] x The L-vector of degrees of freedom.
252  @param[out] y The degrees of freedom on the face, corresponding to a face
253  E-vector.
254  */
255  void Mult(const Vector &x, Vector &y) const override;
256 
257  /** @brief Add the face degrees of freedom @a x to the element degrees of
258  freedom @a y.
259 
260  @param[in] x The face degrees of freedom on the face.
261  @param[in,out] y The L-vector of degrees of freedom to which we add the
262  face degrees of freedom.
263  */
264  void AddMultTranspose(const Vector &x, Vector &y) const override;
265 
266  /** Fill the I array of SparseMatrix corresponding to the sparsity pattern
267  given by this L2FaceRestriction. */
268  virtual void FillI(SparseMatrix &mat, const bool keep_nbr_block = false) const;
269 
270  /** Fill the J and Data arrays of SparseMatrix corresponding to the sparsity
271  pattern given by this L2FaceRestriction, and the values of ea_data. */
272  virtual void FillJAndData(const Vector &ea_data,
273  SparseMatrix &mat,
274  const bool keep_nbr_block = false) const;
275 
276  /// This methods adds the DG face matrices to the element matrices.
278  Vector &ea_data) const;
279 };
280 
281 // Return the face degrees of freedom returned in Lexicographic order.
282 void GetFaceDofs(const int dim, const int face_id,
283  const int dof1d, Array<int> &faceMap);
284 
285 // Convert from Native ordering to lexicographic ordering
286 int ToLexOrdering(const int dim, const int face_id, const int size1d,
287  const int index);
288 
289 // Permute dofs or quads on a face for e2 to match with the ordering of e1
290 int PermuteFaceL2(const int dim, const int face_id1,
291  const int face_id2, const int orientation,
292  const int size1d, const int index);
293 
294 }
295 
296 #endif //MFEM_RESTRICTION
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
void Mult(const Vector &x, Vector &y) const override
Extract the face degrees of freedom from x into y.
void MultTranspose(const Vector &x, Vector &y) const override
Set the face degrees of freedom in the element degrees of freedom y to the values given in x...
void MultTransposeUnsigned(const Vector &x, Vector &y) const
Compute MultTranspose without applying signs based on DOF orientations.
void Mult(const Vector &x, Vector &y) const override=0
Extract the face degrees of freedom from x into y.
Operator that extracts Face degrees of freedom for H1 FiniteElementSpaces.
virtual void FillJAndData(const Vector &ea_data, SparseMatrix &mat, const bool keep_nbr_block=false) const
Array< int > gather_indices
void AddMultTranspose(const Vector &x, Vector &y) const override
Add the face degrees of freedom x to the element degrees of freedom y.
void FillJAndData(const Vector &ea_data, SparseMatrix &mat) const
void AddFaceMatricesToElementMatrices(Vector &fea_data, Vector &ea_data) const
This methods adds the DG face matrices to the element matrices.
void MultLeftInverse(const Vector &x, Vector &y) const
FaceRestriction(int h, int w)
const L2FaceValues m
Array< int > gather_indices
L2ElementRestriction(const FiniteElementSpace &)
FaceType
Definition: mesh.hpp:45
const FiniteElementSpace & fes
L2FaceRestriction(const FiniteElementSpace &, const FaceType, const L2FaceValues m=L2FaceValues::DoubleValued)
Data type sparse matrix.
Definition: sparsemat.hpp:41
int FillI(SparseMatrix &mat) const
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 FillI(SparseMatrix &mat) const
Operator that extracts Face degrees of freedom on L2 FiniteElementSpaces.
void Mult(const Vector &x, Vector &y) const override
Extract the face degrees of freedom from x into y.
void BooleanMask(Vector &y) const
Fills the E-vector y with boolean values 0.0 and 1.0 such that each each entry of the L-vector is uni...
const FiniteElementSpace & fes
H1FaceRestriction(const FiniteElementSpace &fes, const ElementDofOrdering ordering, const FaceType type)
Constructor for a H1FaceRestriction.
void AddMultTranspose(const Vector &x, Vector &y) const override
Add the face degrees of freedom x to the element degrees of freedom y.
void MultUnsigned(const Vector &x, Vector &y) const
Compute Mult without applying signs based on DOF orientations.
ElementRestriction(const FiniteElementSpace &, ElementDofOrdering)
Definition: restriction.cpp:21
int ToLexOrdering(const int dim, const int face_id, const int size1d, const int index)
const FiniteElementSpace & fes
Definition: restriction.hpp:35
virtual void AddMultTranspose(const Vector &x, Vector &y) const =0
Add the face degrees of freedom x to the element degrees of freedom y.
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Operator that converts FiniteElementSpace L-vectors to E-vectors.
Definition: restriction.hpp:27
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:87
void FillJAndData(const Vector &ea_data, SparseMatrix &mat) const
void GetFaceDofs(const int dim, const int face_id, const int dof1d, Array< int > &faceMap)
Array< int > scatter_indices1
ElementDofOrdering
Constants describing the possible orderings of the DOFs in one element.
Definition: fespace.hpp:65
int dim
Definition: ex24.cpp:53
int index(int i, int j, int nx, int ny)
Definition: life.cpp:237
Vector data type.
Definition: vector.hpp:60
int PermuteFaceL2(const int dim, const int face_id1, const int face_id2, const int orientation, const int size1d, const int index)
Base class for operators that extracts Face degrees of freedom.
Abstract operator.
Definition: operator.hpp:24
Operator that converts L2 FiniteElementSpace L-vectors to E-vectors.
Definition: restriction.hpp:84
Array< int > scatter_indices
Array< int > scatter_indices2
virtual void FillI(SparseMatrix &mat, const bool keep_nbr_block=false) const
void FillSparseMatrix(const Vector &mat_ea, SparseMatrix &mat) const
Fill a Sparse Matrix with Element Matrices.
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 ...