MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
prestriction.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, 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_PRESTRICTION
13 #define MFEM_PRESTRICTION
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_MPI
18 
19 #include "restriction.hpp"
20 
21 namespace mfem
22 {
23 
24 class ParFiniteElementSpace;
25 
26 /// Operator that extracts Face degrees of freedom for NCMesh in parallel.
27 /** Objects of this type are typically created and owned by
28  ParFiniteElementSpace objects, see
29  ParFiniteElementSpace::GetFaceRestriction(). */
31 {
32 protected:
33  const FaceType type;
35  mutable Vector x_interp;
36 
37 public:
38  /** @brief Constructs an ParNCH1FaceRestriction.
39 
40  @param[in] fes The ParFiniteElementSpace on which this operates
41  @param[in] ordering Request a specific ordering
42  @param[in] type Request internal or boundary faces dofs */
44  ElementDofOrdering ordering,
45  FaceType type);
46 
47  /** @brief Scatter the degrees of freedom, i.e. goes from L-Vector to
48  face E-Vector.
49 
50  @param[in] x The L-vector degrees of freedom.
51  @param[out] y The face E-Vector degrees of freedom with the given format:
52  face_dofs x vdim x nf
53  where nf is the number of interior or boundary faces
54  requested by @a type in the constructor.
55  The face_dofs are ordered according to the given
56  ElementDofOrdering. */
57  void Mult(const Vector &x, Vector &y) const override;
58 
59  /** @brief Gather the degrees of freedom, i.e. goes from face E-Vector to
60  L-Vector.
61 
62  @param[in] x The face E-Vector degrees of freedom with the given format:
63  face_dofs x vdim x nf
64  where nf is the number of interior or boundary faces
65  requested by @a type in the constructor.
66  The face_dofs should be ordered according to the given
67  ElementDofOrdering.
68  @param[in,out] y The L-vector degrees of freedom. */
69  void AddMultTranspose(const Vector &x, Vector &y) const override;
70 
71  /** @brief Gather the degrees of freedom, i.e. goes from face E-Vector to
72  L-Vector.
73 
74  @param[in,out] x The face E-Vector degrees of freedom with the given format:
75  face_dofs x vdim x nf
76  where nf is the number of interior or boundary faces
77  requested by @a type in the constructor.
78  The face_dofs should be ordered according to the given
79  ElementDofOrdering.
80  @param[in,out] y The L-vector degrees of freedom.
81 
82  @note This method is an optimization of AddMultTranspose where the @a x
83  Vector is used and modified to avoid memory allocation and memcpy. */
84  void AddMultTransposeInPlace(Vector &x, Vector &y) const override;
85 
86 private:
87  /** @brief Compute the scatter indices: L-vector to E-vector, the offsets
88  for the gathering: E-vector to L-vector, and the interpolators from
89  coarse to fine face for master non-comforming faces.
90 
91  @param[in] ordering Request a specific element ordering.
92  @param[in] type Request internal or boundary faces dofs.
93  */
94  void ComputeScatterIndicesAndOffsets(const ElementDofOrdering ordering,
95  const FaceType type);
96 
97  /** @brief Compute the gather indices: E-vector to L-vector.
98 
99  Note: Requires the gather offsets to be computed.
100 
101  @param[in] ordering Request a specific element ordering.
102  @param[in] type Request internal or boundary faces dofs.
103  */
104  void ComputeGatherIndices(const ElementDofOrdering ordering,
105  const FaceType type);
106 
107 public: // For nvcc
108  /** @brief Apply a change of basis from coarse element basis to fine element
109  basis for the coarse face dofs.
110 
111  @param[in,out] x The dofs vector that needs coarse dofs to be express in
112  term of the fine basis.
113  */
114  void NonconformingInterpolation(Vector& x) const;
115 
116  /** @brief Apply a change of basis from fine element basis to coarse element
117  basis for the coarse face dofs.
118 
119  @param[in] x The dofs vector that needs coarse dofs to be express in term
120  of the coarse basis, the result is stored in x_interp.
121  */
122  void NonconformingTransposeInterpolation(const Vector& x) const;
123 
124  /** @brief Apply a change of basis from fine element basis to coarse element
125  basis for the coarse face dofs.
126 
127  @param[in] x The dofs vector that needs coarse dofs to be express in term
128  of the coarse basis, the result is stored in x_interp.
129  */
131 };
132 
133 /// Operator that extracts Face degrees of freedom in parallel.
134 /** Objects of this type are typically created and owned by
135  ParFiniteElementSpace objects, see
136  ParFiniteElementSpace::GetFaceRestriction(). */
138 {
139 protected:
140  /** @brief Constructs an ParL2FaceRestriction.
141 
142  @param[in] fes The ParFiniteElementSpace on which this operates
143  @param[in] ordering Request a specific ordering
144  @param[in] type Request internal or boundary faces dofs
145  @param[in] m Request the face dofs for elem1, or both elem1 and
146  elem2
147  @param[in] build Request the ParL2FaceRestriction to compute the
148  scatter/gather indices. False should only be used
149  when inheriting from ParL2FaceRestriction. */
151  ElementDofOrdering ordering,
152  FaceType type,
153  L2FaceValues m,
154  bool build);
155 
156 public:
157  /** @brief Constructs an ParL2FaceRestriction.
158 
159  @param[in] fes The ParFiniteElementSpace on which this operates
160  @param[in] ordering Request a specific ordering
161  @param[in] type Request internal or boundary faces dofs
162  @param[in] m Request the face dofs for elem1, or both elem1 and
163  elem2 */
165  ElementDofOrdering ordering,
166  FaceType type,
168 
169  /** @brief Scatter the degrees of freedom, i.e. goes from L-Vector to
170  face E-Vector.
171 
172  @param[in] x The L-vector degrees of freedom.
173  @param[out] y The face E-Vector degrees of freedom with the given format:
174  if L2FacesValues::DoubleValued (face_dofs x vdim x 2 x nf),
175  if L2FacesValues::SingleValued (face_dofs x vdim x nf),
176  where nf is the number of interior or boundary faces
177  requested by @a type in the constructor.
178  The face_dofs are ordered according to the given
179  ElementDofOrdering. */
180  void Mult(const Vector &x, Vector &y) const override;
181 
182  /** Fill the I array of SparseMatrix corresponding to the sparsity pattern
183  given by this ParL2FaceRestriction.
184 
185  @param[in,out] mat The sparse matrix for which we want to initialize the
186  row offsets.
187  @param[in] keep_nbr_block When set to true the SparseMatrix will
188  include the rows (in addition to the columns)
189  corresponding to face-neighbor dofs. The
190  default behavior is to disregard those rows. */
191  void FillI(SparseMatrix &mat,
192  const bool keep_nbr_block = false) const override;
193 
194  /** Fill the I array of SparseMatrix corresponding to the sparsity pattern
195  given by this ParL2FaceRestriction. @a mat contains the interior dofs
196  contribution, the @a face_mat contains the shared dofs contribution.*/
197  void FillI(SparseMatrix &mat,
198  SparseMatrix &face_mat) const;
199 
200  /** Fill the J and Data arrays of SparseMatrix corresponding to the sparsity
201  pattern given by this ParL2FaceRestriction, and the values of ea_data.
202  @a mat contains the interior dofs contribution, the @a face_mat contains
203  the shared dofs contribution.*/
204  void FillJAndData(const Vector &ea_data,
205  SparseMatrix &mat,
206  SparseMatrix &face_mat) const;
207 
208  /** @brief Fill the J and Data arrays of the SparseMatrix corresponding to
209  the sparsity pattern given by this ParL2FaceRestriction, and the values of
210  fea_data.
211 
212  @param[in] fea_data The dense matrices representing the local operators
213  on each face. The format is:
214  face_dofs x face_dofs x 2 x nf.
215  On each face the first local matrix corresponds to
216  the contribution of elem1 on elem2, and the second to
217  the contribution of elem2 on elem1.
218  @param[in,out] mat The sparse matrix that is getting filled.
219  @param[in] keep_nbr_block When set to true the SparseMatrix will
220  include the rows (in addition to the columns)
221  corresponding to face-neighbor dofs. The
222  default behavior is to disregard those rows. */
223  void FillJAndData(const Vector &fea_data,
224  SparseMatrix &mat,
225  const bool keep_nbr_block = false) const override;
226 
227 private:
228  /** @brief Compute the scatter indices: L-vector to E-vector, and the offsets
229  for the gathering: E-vector to L-vector.
230 
231  @param[in] ordering Request a specific element ordering.
232  @param[in] type Request internal or boundary faces dofs.
233  */
234  void ComputeScatterIndicesAndOffsets(const ElementDofOrdering ordering,
235  const FaceType type);
236 
237  /** @brief Compute the gather indices: E-vector to L-vector.
238 
239  Note: Requires the gather offsets to be computed.
240 
241  @param[in] ordering Request a specific element ordering.
242  @param[in] type Request internal or boundary faces dofs.
243  */
244  void ComputeGatherIndices(const ElementDofOrdering ordering,
245  const FaceType type);
246 
247 public:
248  /** @brief Scatter the degrees of freedom, i.e. goes from L-Vector to
249  face E-Vector. Should only be used with conforming faces and when:
250  m == L2FacesValues::DoubleValued
251 
252  @param[in] x The L-vector degrees of freedom.
253  @param[out] y The face E-Vector degrees of freedom with the given format:
254  face_dofs x vdim x 2 x nf
255  where nf is the number of interior or boundary faces
256  requested by @a type in the constructor.
257  The face_dofs are ordered according to the given
258  ElementDofOrdering. */
259  void DoubleValuedConformingMult(const Vector& x, Vector& y) const override;
260 };
261 
262 /// Operator that extracts Face degrees of freedom for NCMesh in parallel.
263 /** Objects of this type are typically created and owned by
264  ParFiniteElementSpace objects, see
265  ParFiniteElementSpace::GetFaceRestriction(). */
268 {
269 public:
270  /** @brief Constructs an ParNCL2FaceRestriction.
271 
272  @param[in] fes The ParFiniteElementSpace on which this operates
273  @param[in] ordering Request a specific ordering
274  @param[in] type Request internal or boundary faces dofs
275  @param[in] m Request the face dofs for elem1, or both elem1 and
276  elem2 */
278  ElementDofOrdering ordering,
279  FaceType type,
281 
282  /** @brief Scatter the degrees of freedom, i.e. goes from L-Vector to
283  face E-Vector.
284 
285  @param[in] x The L-vector degrees of freedom.
286  @param[out] y The face E-Vector degrees of freedom with the given format:
287  if L2FacesValues::DoubleValued (face_dofs x vdim x 2 x nf),
288  if L2FacesValues::SingleValued (face_dofs x vdim x nf),
289  where nf is the number of interior or boundary faces
290  requested by @a type in the constructor.
291  The face_dofs are ordered according to the given
292  ElementDofOrdering. */
293  void Mult(const Vector &x, Vector &y) const override;
294 
295  /** @brief Gather the degrees of freedom, i.e. goes from face E-Vector to
296  L-Vector.
297 
298  @param[in] x The face E-Vector degrees of freedom with the given format:
299  if L2FacesValues::DoubleValued (face_dofs x vdim x 2 x nf),
300  if L2FacesValues::SingleValued (face_dofs x vdim x nf),
301  where nf is the number of interior or boundary faces
302  requested by @a type in the constructor.
303  The face_dofs should be ordered according to the given
304  ElementDofOrdering
305  @param[in,out] y The L-vector degrees of freedom. */
306  void AddMultTranspose(const Vector &x, Vector &y) const override;
307 
308  /** @brief Gather the degrees of freedom, i.e. goes from face E-Vector to
309  L-Vector.
310 
311  @param[in,out] x The face E-Vector degrees of freedom with the given format:
312  if L2FacesValues::DoubleValued (face_dofs x vdim x 2 x nf),
313  if L2FacesValues::SingleValued (face_dofs x vdim x nf),
314  where nf is the number of interior or boundary faces
315  requested by @a type in the constructor.
316  The face_dofs should be ordered according to the given
317  ElementDofOrdering
318  @param[in,out] y The L-vector degrees of freedom.
319 
320  @note @a x is used for computation. */
321  void AddMultTransposeInPlace(Vector &x, Vector &y) const override;
322 
323  /** @brief Fill the I array of SparseMatrix corresponding to the sparsity
324  pattern given by this ParNCL2FaceRestriction.
325 
326  @param[in,out] mat The sparse matrix for which we want to initialize the
327  row offsets.
328  @param[in] keep_nbr_block When set to true the SparseMatrix will
329  include the rows (in addition to the columns)
330  corresponding to face-neighbor dofs. The
331  default behavior is to disregard those rows.
332 
333  @warning This method is not implemented yet. */
334  void FillI(SparseMatrix &mat,
335  const bool keep_nbr_block = false) const override;
336 
337  /** Fill the I array of SparseMatrix corresponding to the sparsity pattern
338  given by this ParNCL2FaceRestriction. @a mat contains the interior dofs
339  contribution, the @a face_mat contains the shared dofs contribution.
340 
341  @warning This method is not implemented yet. */
342  void FillI(SparseMatrix &mat,
343  SparseMatrix &face_mat) const;
344 
345  /** Fill the J and Data arrays of SparseMatrix corresponding to the sparsity
346  pattern given by this ParNCL2FaceRestriction, and the values of ea_data.
347  @a mat contains the interior dofs contribution, the @a face_mat contains
348  the shared dofs contribution.
349 
350  @warning This method is not implemented yet. */
351  void FillJAndData(const Vector &fea_data,
352  SparseMatrix &mat,
353  SparseMatrix &face_mat) const;
354 
355  /** @brief Fill the J and Data arrays of the SparseMatrix corresponding to
356  the sparsity pattern given by this ParNCL2FaceRestriction, and the values
357  of ea_data.
358 
359  @param[in] fea_data The dense matrices representing the local operators
360  on each face. The format is:
361  face_dofs x face_dofs x 2 x nf.
362  On each face the first local matrix corresponds to
363  the contribution of elem1 on elem2, and the second to
364  the contribution of elem2 on elem1.
365  @param[in,out] mat The sparse matrix that is getting filled.
366  @param[in] keep_nbr_block When set to true the SparseMatrix will
367  include the rows (in addition to the columns)
368  corresponding to face-neighbor dofs. The
369  default behavior is to disregard those rows.
370 
371  @warning This method is not implemented yet. */
372  void FillJAndData(const Vector &fea_data,
373  SparseMatrix &mat,
374  const bool keep_nbr_block = false) const override;
375 
376 private:
377  /** @brief Compute the scatter indices: L-vector to E-vector, the offsets
378  for the gathering: E-vector to L-vector, and the interpolators from
379  coarse to fine face for master non-comforming faces.
380 
381  @param[in] ordering Request a specific element ordering.
382  @param[in] type Request internal or boundary faces dofs.
383  */
384  void ComputeScatterIndicesAndOffsets(const ElementDofOrdering ordering,
385  const FaceType type);
386 
387  /** @brief Compute the gather indices: E-vector to L-vector.
388 
389  Note: Requires the gather offsets to be computed.
390 
391  @param[in] ordering Request a specific element ordering.
392  @param[in] type Request internal or boundary faces dofs.
393  */
394  void ComputeGatherIndices(const ElementDofOrdering ordering,
395  const FaceType type);
396 
397 public:
398  /** @brief Scatter the degrees of freedom, i.e. goes from L-Vector to
399  face E-Vector. Should only be used with nonconforming faces and when:
400  L2FaceValues m == L2FaceValues::SingleValued
401 
402  @param[in] x The L-vector degrees of freedom.
403  @param[out] y The face E-Vector degrees of freedom with the given format:
404  (face_dofs x vdim x nf),
405  where nf is the number of interior or boundary faces
406  requested by @a type in the constructor.
407  The face_dofs are ordered according to the given
408  ElementDofOrdering. */
409  void SingleValuedNonconformingMult(const Vector& x, Vector& y) const;
410 
411  /** @brief Scatter the degrees of freedom, i.e. goes from L-Vector to
412  face E-Vector. Should only be used with nonconforming faces and when:
413  L2FaceValues m == L2FaceValues::DoubleValued
414 
415  @param[in] x The L-vector degrees of freedom.
416  @param[out] y The face E-Vector degrees of freedom with the given format:
417  (face_dofs x vdim x 2 x nf),
418  where nf is the number of interior or boundary faces
419  requested by @a type in the constructor.
420  The face_dofs are ordered according to the given
421  ElementDofOrdering. */
422  void DoubleValuedNonconformingMult(const Vector& x, Vector& y) const override;
423 };
424 
425 }
426 
427 #endif // MFEM_USE_MPI
428 
429 #endif // MFEM_PRESTRICTION
void Mult(const Vector &x, Vector &y) const override
Scatter the degrees of freedom, i.e. goes from L-Vector to face E-Vector.
Operator that extracts Face degrees of freedom in parallel.
void DoubleValuedNonconformingMult(const Vector &x, Vector &y) const override
Scatter the degrees of freedom, i.e. goes from L-Vector to face E-Vector. Should only be used with no...
void AddMultTranspose(const Vector &x, Vector &y) const override
Gather the degrees of freedom, i.e. goes from face E-Vector to L-Vector.
Operator that extracts Face degrees of freedom for H1 FiniteElementSpaces.
void Mult(const Vector &x, Vector &y) const override
Scatter the degrees of freedom, i.e. goes from L-Vector to face E-Vector.
ParL2FaceRestriction(const ParFiniteElementSpace &fes, ElementDofOrdering ordering, FaceType type, L2FaceValues m, bool build)
Constructs an ParL2FaceRestriction.
ParNCH1FaceRestriction(const ParFiniteElementSpace &fes, ElementDofOrdering ordering, FaceType type)
Constructs an ParNCH1FaceRestriction.
InterpolationManager interpolations
Operator that extracts face degrees of freedom for L2 nonconforming spaces.
Abstract parallel finite element space.
Definition: pfespace.hpp:28
const L2FaceValues m
void Mult(const Vector &x, Vector &y) const override
Scatter the degrees of freedom, i.e. goes from L-Vector to face E-Vector.
ParNCL2FaceRestriction(const ParFiniteElementSpace &fes, ElementDofOrdering ordering, FaceType type, L2FaceValues m=L2FaceValues::DoubleValued)
Constructs an ParNCL2FaceRestriction.
void NonconformingTransposeInterpolation(const Vector &x) const
Apply a change of basis from fine element basis to coarse element basis for the coarse face dofs...
void AddMultTransposeInPlace(Vector &x, Vector &y) const override
Gather the degrees of freedom, i.e. goes from face E-Vector to L-Vector.
FaceType
Definition: mesh.hpp:45
const FiniteElementSpace & fes
void AddMultTransposeInPlace(Vector &x, Vector &y) const override
Gather the degrees of freedom, i.e. goes from face E-Vector to L-Vector.
Data type sparse matrix.
Definition: sparsemat.hpp:50
Operator that extracts Face degrees of freedom for L2 spaces.
Operator that extracts Face degrees of freedom for NCMesh in parallel.
const FiniteElementSpace & fes
void FillJAndData(const Vector &fea_data, SparseMatrix &mat, SparseMatrix &face_mat) const
This class manages the storage and computation of the interpolations from master (coarse) face to sla...
void DoubleValuedConformingMult(const Vector &x, Vector &y) const override
Scatter the degrees of freedom, i.e. goes from L-Vector to face E-Vector. Should only be used with co...
void SingleValuedNonconformingMult(const Vector &x, Vector &y) const
Scatter the degrees of freedom, i.e. goes from L-Vector to face E-Vector. Should only be used with no...
ElementDofOrdering
Constants describing the possible orderings of the DOFs in one element.
Definition: fespace.hpp:74
void NonconformingTransposeInterpolationInPlace(Vector &x) const
Apply a change of basis from fine element basis to coarse element basis for the coarse face dofs...
Operator that extracts Face degrees of freedom for NCMesh in parallel.
Vector data type.
Definition: vector.hpp:60
void FillJAndData(const Vector &ea_data, SparseMatrix &mat, SparseMatrix &face_mat) const
void NonconformingInterpolation(Vector &x) const
Apply a change of basis from coarse element basis to fine element basis for the coarse face dofs...
void AddMultTranspose(const Vector &x, Vector &y) const override
Gather the degrees of freedom, i.e. goes from face E-Vector to L-Vector.
void FillI(SparseMatrix &mat, const bool keep_nbr_block=false) const override
void FillI(SparseMatrix &mat, const bool keep_nbr_block=false) const override
Fill the I array of SparseMatrix corresponding to the sparsity pattern given by this ParNCL2FaceRestr...