MFEM  v4.2.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-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_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 /** An enum type to specify if only e1 value is requested (SingleValued) or both
25  e1 and e2 (DoubleValued). */
26 enum class L2FaceValues : bool {SingleValued, DoubleValued};
27 
28 /// Operator that converts FiniteElementSpace L-vectors to E-vectors.
29 /** Objects of this type are typically created and owned by FiniteElementSpace
30  objects, see FiniteElementSpace::GetElementRestriction(). */
32 {
33 private:
34  /** This number defines the maximum number of elements any dof can belong to
35  for the FillSparseMatrix method. */
36  static const int MaxNbNbr = 16;
37 
38 protected:
40  const int ne;
41  const int vdim;
42  const bool byvdim;
43  const int ndofs;
44  const int dof;
45  const int nedofs;
49 
50 public:
52  void Mult(const Vector &x, Vector &y) const;
53  void MultTranspose(const Vector &x, Vector &y) const;
54 
55  /// Compute Mult without applying signs based on DOF orientations.
56  void MultUnsigned(const Vector &x, Vector &y) const;
57  /// Compute MultTranspose without applying signs based on DOF orientations.
58  void MultTransposeUnsigned(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 /// Operator that extracts Face degrees of freedom.
104 /** Objects of this type are typically created and owned by FiniteElementSpace
105  objects, see FiniteElementSpace::GetFaceRestriction(). */
107 {
108 protected:
110  const int nf;
111  const int vdim;
112  const bool byvdim;
113  const int ndofs;
114  const int dof;
115  const int nfdofs;
119 
120 public:
122  const FaceType);
123  void Mult(const Vector &x, Vector &y) const;
124  void MultTranspose(const Vector &x, Vector &y) const;
125 };
126 
127 /// Operator that extracts Face degrees of freedom.
128 /** Objects of this type are typically created and owned by FiniteElementSpace
129  objects, see FiniteElementSpace::GetFaceRestriction(). */
131 {
132 protected:
134  const int nf;
135  const int ne;
136  const int vdim;
137  const bool byvdim;
138  const int ndofs;
139  const int dof;
140  const int elemDofs;
142  const int nfdofs;
147 
149  const FaceType,
151 
152 public:
154  const FaceType,
156  virtual void Mult(const Vector &x, Vector &y) const;
157  void MultTranspose(const Vector &x, Vector &y) const;
158  /** Fill the I array of SparseMatrix corresponding to the sparsity pattern
159  given by this L2FaceRestriction. */
160  virtual void FillI(SparseMatrix &mat, SparseMatrix &face_mat) const;
161  /** Fill the J and Data arrays of SparseMatrix corresponding to the sparsity
162  pattern given by this L2FaceRestriction, and the values of ea_data. */
163  virtual void FillJAndData(const Vector &ea_data,
164  SparseMatrix &mat,
165  SparseMatrix &face_mat) const;
166  /// This methods adds the DG face matrices to the element matrices.
168  Vector &ea_data) const;
169 };
170 
171 // Return the face degrees of freedom returned in Lexicographic order.
172 void GetFaceDofs(const int dim, const int face_id,
173  const int dof1d, Array<int> &faceMap);
174 
175 // Convert from Native ordering to lexicographic ordering
176 int ToLexOrdering(const int dim, const int face_id, const int size1d,
177  const int index);
178 
179 // Permute dofs or quads on a face for e2 to match with the ordering of e1
180 int PermuteFaceL2(const int dim, const int face_id1,
181  const int face_id2, const int orientation,
182  const int size1d, const int index);
183 
184 }
185 
186 #endif //MFEM_RESTRICTION
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
L2FaceValues
Definition: restriction.hpp:26
void MultTransposeUnsigned(const Vector &x, Vector &y) const
Compute MultTranspose without applying signs based on DOF orientations.
Operator that extracts Face degrees of freedom.
virtual void FillI(SparseMatrix &mat, SparseMatrix &face_mat) const
Array< int > gather_indices
void FillJAndData(const Vector &ea_data, SparseMatrix &mat) const
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
void AddFaceMatricesToElementMatrices(Vector &fea_data, Vector &ea_data) const
This methods adds the DG face matrices to the element matrices.
H1FaceRestriction(const FiniteElementSpace &, const ElementDofOrdering, const FaceType)
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 ...
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:46
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.
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
void MultUnsigned(const Vector &x, Vector &y) const
Compute Mult without applying signs based on DOF orientations.
ElementRestriction(const FiniteElementSpace &, ElementDofOrdering)
Definition: restriction.cpp:20
int ToLexOrdering(const int dim, const int face_id, const int size1d, const int index)
const FiniteElementSpace & fes
Definition: restriction.hpp:39
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:31
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 Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
void GetFaceDofs(const int dim, const int face_id, const int dof1d, Array< int > &faceMap)
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 ...
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:241
virtual void FillJAndData(const Vector &ea_data, SparseMatrix &mat, SparseMatrix &face_mat) const
Vector data type.
Definition: vector.hpp:51
int PermuteFaceL2(const int dim, const int face_id1, const int face_id2, const int orientation, const int size1d, const int index)
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
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 ...