MFEM  v4.5.2
Finite element discretization library
pbilinearform.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_PBILINEARFORM
13 #define MFEM_PBILINEARFORM
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_MPI
18 
19 #include <mpi.h>
20 #include "pfespace.hpp"
21 #include "pgridfunc.hpp"
22 #include "bilinearform.hpp"
23 
24 namespace mfem
25 {
26 
27 /// Class for parallel bilinear form
29 {
31 protected:
32  ParFiniteElementSpace *pfes; ///< Points to the same object as #fes
33 
34  /// Auxiliary vectors used in TrueAddMult(): L-, L-, and T-vector, resp.
35  mutable Vector Xaux, Yaux, Ytmp;
36 
38 
40 
41  // Allocate mat - called when (mat == NULL && fbfi.Size() > 0)
42  void pAllocMat();
43 
44  void AssembleSharedFaces(int skip_zeros = 1);
45 
46 private:
47  /// Copy construction is not supported; body is undefined.
49 
50  /// Copy assignment is not supported; body is undefined.
51  ParBilinearForm &operator=(const ParBilinearForm &);
52 
53 public:
54  /// Creates parallel bilinear form associated with the FE space @a *pf.
55  /** The pointer @a pf is not owned by the newly constructed object. */
57  : BilinearForm(pf), pfes(pf),
59  { keep_nbr_block = false; }
60 
61  /** @brief Create a ParBilinearForm on the ParFiniteElementSpace @a *pf,
62  using the same integrators as the ParBilinearForm @a *bf.
63 
64  The pointer @a pf is not owned by the newly constructed object.
65 
66  The integrators in @a bf are copied as pointers and they are not owned by
67  the newly constructed ParBilinearForm. */
69  : BilinearForm(pf, bf), pfes(pf),
71  { keep_nbr_block = false; }
72 
73  /** When set to true and the ParBilinearForm has interior face integrators,
74  the local SparseMatrix will include the rows (in addition to the columns)
75  corresponding to face-neighbor dofs. The default behavior is to disregard
76  those rows. Must be called before the first Assemble call. */
77  void KeepNbrBlock(bool knb = true) { keep_nbr_block = knb; }
78 
79  /** @brief Set the operator type id for the parallel matrix/operator when
80  using AssemblyLevel::LEGACY. */
81  /** If using static condensation or hybridization, call this method *after*
82  enabling it. */
84  {
85  p_mat.SetType(tid); p_mat_e.SetType(tid);
88  }
89 
90  /// Assemble the local matrix
91  void Assemble(int skip_zeros = 1);
92 
93  /** @brief Assemble the diagonal of the bilinear form into @a diag. Note that
94  @a diag is a true-dof Vector.
95 
96  When the AssemblyLevel is not LEGACY, and the mesh is nonconforming,
97  this method returns |P^T| d_l, where d_l is the local diagonal of the
98  form before applying parallel/conforming assembly, P^T is the transpose
99  of the parallel/conforming prolongation, and |.| denotes the entry-wise
100  absolute value. In general, this is just an approximation of the exact
101  diagonal for this case. */
102  virtual void AssembleDiagonal(Vector &diag) const;
103 
104  /// Returns the matrix assembled on the true dofs, i.e. P^t A P.
105  /** The returned matrix has to be deleted by the caller. */
107 
108  /// Returns the eliminated matrix assembled on the true dofs, i.e. P^t A_e P.
109  /** The returned matrix has to be deleted by the caller. */
111 
112  /// Return the matrix @a m assembled on the true dofs, i.e. P^t A P.
113  /** The returned matrix has to be deleted by the caller. */
115 
116  /** @brief Compute parallel RAP operator and store it in @a A as a HypreParMatrix.
117 
118  @param[in] loc_A The rank-local `SparseMatrix`.
119  @param[out] A The `OperatorHandle` containing the global `HypreParMatrix`.
120  @param[in] steal_loc_A Have the `HypreParMatrix` in @a A take ownership of
121  the memory objects in @a loc_A.
122  */
123  void ParallelRAP(SparseMatrix &loc_A,
124  OperatorHandle &A,
125  bool steal_loc_A = false);
126 
127  /** @brief Returns the matrix assembled on the true dofs, i.e.
128  @a A = P^t A_local P, in the format (type id) specified by @a A. */
130 
131  /** Returns the eliminated matrix assembled on the true dofs, i.e.
132  @a A_elim = P^t A_elim_local P in the format (type id) specified by @a A.
133  */
135  { ParallelAssemble(A_elim, mat_e); }
136 
137  /** Returns the matrix @a A_local assembled on the true dofs, i.e.
138  @a A = P^t A_local P in the format (type id) specified by @a A. */
139  void ParallelAssemble(OperatorHandle &A, SparseMatrix *A_local);
140 
141  /// Eliminate essential boundary DOFs from a parallel assembled system.
142  /** The array @a bdr_attr_is_ess marks boundary attributes that constitute
143  the essential part of the boundary. */
144  void ParallelEliminateEssentialBC(const Array<int> &bdr_attr_is_ess,
145  HypreParMatrix &A,
146  const HypreParVector &X,
147  HypreParVector &B) const;
148 
149  /// Eliminate essential boundary DOFs from a parallel assembled matrix @a A.
150  /** The array @a bdr_attr_is_ess marks boundary attributes that constitute
151  the essential part of the boundary. The eliminated part is stored in a
152  matrix A_elim such that A_original = A_new + A_elim. Returns a pointer to
153  the newly allocated matrix A_elim which should be deleted by the caller.
154  The matrices @a A and A_elim can be used to eliminate boundary conditions
155  in multiple right-hand sides, by calling the function EliminateBC() (from
156  hypre.hpp). */
158  HypreParMatrix &A) const;
159 
160  /// Eliminate essential true DOFs from a parallel assembled matrix @a A.
161  /** Given a list of essential true dofs and the parallel assembled matrix
162  @a A, eliminate the true dofs from the matrix, storing the eliminated
163  part in a matrix A_elim such that A_original = A_new + A_elim. Returns a
164  pointer to the newly allocated matrix A_elim which should be deleted by
165  the caller. The matrices @a A and A_elim can be used to eliminate
166  boundary conditions in multiple right-hand sides, by calling the function
167  EliminateBC() (from hypre.hpp). */
169  HypreParMatrix &A) const
170  { return A.EliminateRowsCols(tdofs_list); }
171 
172  /** @brief Compute @a y += @a a (P^t A P) @a x, where @a x and @a y are
173  vectors on the true dofs. */
174  void TrueAddMult(const Vector &x, Vector &y, const double a = 1.0) const;
175 
176  /// Return the parallel FE space associated with the ParBilinearForm.
177  ParFiniteElementSpace *ParFESpace() const { return pfes; }
178 
179  /// Return the parallel trace FE space associated with static condensation.
181  { return static_cond ? static_cond->GetParTraceFESpace() : NULL; }
182 
183  /// Get the parallel finite element space prolongation matrix
184  virtual const Operator *GetProlongation() const
185  { return pfes->GetProlongationMatrix(); }
186  /// Get the transpose of GetRestriction, useful for matrix-free RAP
187  virtual const Operator *GetRestrictionTranspose() const
189  /// Get the parallel finite element space restriction matrix
190  virtual const Operator *GetRestriction() const
191  { return pfes->GetRestrictionMatrix(); }
192 
195 
196  virtual void FormLinearSystem(const Array<int> &ess_tdof_list, Vector &x,
197  Vector &b, OperatorHandle &A, Vector &X,
198  Vector &B, int copy_interior = 0);
199 
200  virtual void FormSystemMatrix(const Array<int> &ess_tdof_list,
201  OperatorHandle &A);
202 
203  /** Call this method after solving a linear system constructed using the
204  FormLinearSystem method to recover the solution as a ParGridFunction-size
205  vector in x. Use the same arguments as in the FormLinearSystem call. */
206  virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x);
207 
208  virtual void Update(FiniteElementSpace *nfes = NULL);
209 
210  void EliminateVDofsInRHS(const Array<int> &vdofs, const Vector &x, Vector &b);
211 
212  virtual ~ParBilinearForm() { }
213 };
214 
215 /// Class for parallel bilinear form using different test and trial FE spaces.
217 {
218 protected:
219  /// Points to the same object as #trial_fes
221  /// Points to the same object as #test_fes
223  /// Auxiliary objects used in TrueAddMult().
225 
226  /// Matrix and eliminated matrix
228 
229 private:
230  /// Copy construction is not supported; body is undefined.
232 
233  /// Copy assignment is not supported; body is undefined.
234  ParMixedBilinearForm &operator=(const ParMixedBilinearForm &);
235 
236 public:
237  /** @brief Construct a ParMixedBilinearForm on the given FiniteElementSpace%s
238  @a trial_fes and @a test_fes. */
239  /** The pointers @a trial_fes and @a test_fes are not owned by the newly
240  constructed object. */
245  {
248  }
249 
250  /** @brief Create a ParMixedBilinearForm on the given FiniteElementSpace%s
251  @a trial_fes and @a test_fes, using the same integrators as the
252  ParMixedBilinearForm @a mbf.
253 
254  The pointers @a trial_fes and @a test_fes are not owned by the newly
255  constructed object.
256 
257  The integrators in @a mbf are copied as pointers and they are not owned
258  by the newly constructed ParMixedBilinearForm. */
261  ParMixedBilinearForm * mbf)
264  {
267  }
268 
269  /// Returns the matrix assembled on the true dofs, i.e. P_test^t A P_trial.
271 
272  /** @brief Returns the matrix assembled on the true dofs, i.e.
273  @a A = P_test^t A_local P_trial, in the format (type id) specified by
274  @a A. */
276 
279 
280  /** @brief Return in @a A a parallel (on truedofs) version of this operator.
281 
282  This returns the same operator as FormRectangularLinearSystem(), but does
283  without the transformations of the right-hand side. */
284  virtual void FormRectangularSystemMatrix(const Array<int> &trial_tdof_list,
285  const Array<int> &test_tdof_list,
286  OperatorHandle &A);
287 
288  /** @brief Form the parallel linear system A X = B, corresponding to this mixed
289  bilinear form and the linear form @a b(.).
290 
291  Return in @a A a *reference* to the system matrix that is column-constrained.
292  The reference will be invalidated when SetOperatorType(), Update(), or the
293  destructor is called. */
294  virtual void FormRectangularLinearSystem(const Array<int> &trial_tdof_list,
295  const Array<int> &test_tdof_list, Vector &x,
296  Vector &b, OperatorHandle &A, Vector &X,
297  Vector &B);
298 
299  /// Compute y += a (P^t A P) x, where x and y are vectors on the true dofs
300  void TrueAddMult(const Vector &x, Vector &y, const double a = 1.0) const;
301 
302  virtual ~ParMixedBilinearForm() { }
303 };
304 
305 /** The parallel matrix representation a linear operator between parallel finite
306  element spaces */
308 {
309 protected:
310  /// Points to the same object as #trial_fes
312  /// Points to the same object as #test_fes
314 
315 private:
316  /// Copy construction is not supported; body is undefined.
318 
319  /// Copy assignment is not supported; body is undefined.
321 
322 public:
323  /** @brief Construct a ParDiscreteLinearOperator on the given
324  FiniteElementSpace%s @a dfes (domain FE space) and @a rfes (range FE
325  space). */
326  /** The pointers @a dfes and @a rfes are not owned by the newly constructed
327  object. */
329  ParFiniteElementSpace *rfes)
330  : DiscreteLinearOperator(dfes, rfes) { domain_fes=dfes; range_fes=rfes; }
331 
332  /// Returns the matrix "assembled" on the true dofs
334 
335  /** @brief Returns the matrix assembled on the true dofs, i.e.
336  @a A = R_test A_local P_trial, in the format (type id) specified by
337  @a A. */
339 
340  /** Extract the parallel blocks corresponding to the vector dimensions of the
341  domain and range parallel finite element spaces */
342  void GetParBlocks(Array2D<HypreParMatrix *> &blocks) const;
343 
345 
346  /** @brief Return in @a A a parallel (on truedofs) version of this operator. */
348 
350 };
351 
352 }
353 
354 #endif // MFEM_USE_MPI
355 
356 #endif
ParDiscreteLinearOperator(ParFiniteElementSpace *dfes, ParFiniteElementSpace *rfes)
Construct a ParDiscreteLinearOperator on the given FiniteElementSpaces dfes (domain FE space) and rfe...
virtual void FormRectangularSystemMatrix(OperatorHandle &A)
Return in A a parallel (on truedofs) version of this operator.
void SetOperatorType(Operator::Type tid)
Set the operator type id for the parallel reduced matrix/operator.
Definition: staticcond.hpp:174
void EliminateRowsCols(const Array< int > &rows_cols, const HypreParVector &X, HypreParVector &B)
Definition: hypre.cpp:2273
ParFiniteElementSpace * ParFESpace() const
Return the parallel FE space associated with the ParBilinearForm.
virtual const Operator * GetProlongationMatrix() const
The returned Operator is owned by the FiniteElementSpace.
Definition: pfespace.cpp:1153
virtual void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)
Form the linear system A X = B, corresponding to this bilinear form and the linear form b(...
void KeepNbrBlock(bool knb=true)
virtual void FormRectangularSystemMatrix(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, OperatorHandle &A)
Return in A that is column-constrained.
void TrueAddMult(const Vector &x, Vector &y, const double a=1.0) const
Compute y += a (P^t A P) x, where x and y are vectors on the true dofs.
Pointer to an Operator of a specified type.
Definition: handle.hpp:33
ParFiniteElementSpace * GetParTraceFESpace()
Return a pointer to the parallel reduced/trace FE space.
Definition: staticcond.hpp:113
void ParallelRAP(SparseMatrix &loc_A, OperatorHandle &A, bool steal_loc_A=false)
Compute parallel RAP operator and store it in A as a HypreParMatrix.
HypreParMatrix * ParallelAssemble() const
Returns the matrix "assembled" on the true dofs.
virtual void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)
Form the linear system A X = B, corresponding to this bilinear form and the linear form b(...
OperatorHandle p_mat_e
void GetParBlocks(Array2D< HypreParMatrix *> &blocks) const
Abstract parallel finite element space.
Definition: pfespace.hpp:28
void AssembleSharedFaces(int skip_zeros=1)
virtual const SparseMatrix * GetRestrictionMatrix() const
Get the R matrix which restricts a local dof vector to true dof vector.
Definition: pfespace.hpp:389
HypreParMatrix * ParallelAssemble()
Returns the matrix assembled on the true dofs, i.e. P^t A P.
virtual void Update(FiniteElementSpace *nfes=NULL)
Update the FiniteElementSpace and delete all data associated with the old one.
HypreParMatrix * ParallelAssemble()
Returns the matrix assembled on the true dofs, i.e. P_test^t A P_trial.
void SetOperatorType(Operator::Type tid)
Set the operator type id for the parallel hybridized matrix/operator.
void SetOperatorType(Operator::Type tid)
Set the operator type id for the parallel matrix/operator when using AssemblyLevel::LEGACY.
ParFiniteElementSpace * pfes
Points to the same object as fes.
void ParallelAssembleElim(OperatorHandle &A_elim)
virtual const Operator * GetRestrictionTransposeOperator() const
Return logical transpose of restriction matrix, but in non-assembled optimized matrix-free form...
Definition: pfespace.cpp:1217
virtual const Operator * GetRestriction() const
Get the parallel finite element space restriction matrix.
Data type sparse matrix.
Definition: sparsemat.hpp:50
virtual void AssembleDiagonal(Vector &diag) const
Assemble the diagonal of the bilinear form into diag. Note that diag is a true-dof Vector...
StaticCondensation * static_cond
Owned.
virtual const Operator * GetProlongation() const
Get the parallel finite element space prolongation matrix.
SparseMatrix * mat
Sparse matrix to be associated with the form. Owned.
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)
Form the linear system A X = B, corresponding to this mixed bilinear form and the linear form b(...
Data and methods for fully-assembled bilinear forms.
double b
Definition: lissajous.cpp:42
void EliminateVDofsInRHS(const Array< int > &vdofs, const Vector &x, Vector &b)
void Assemble(int skip_zeros=1)
Assemble the local matrix.
void TrueAddMult(const Vector &x, Vector &y, const double a=1.0) const
Compute y += a (P^t A P) x, where x and y are vectors on the true dofs.
virtual void FormRectangularSystemMatrix(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, OperatorHandle &A)
Return in A a parallel (on truedofs) version of this operator.
virtual void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
Form the linear system matrix A, see FormLinearSystem() for details.
ParFiniteElementSpace * test_pfes
Points to the same object as test_fes.
ParFiniteElementSpace * SCParFESpace() const
Return the parallel trace FE space associated with static condensation.
Dynamic 2D array using row-major layout.
Definition: array.hpp:354
SparseMatrix * mat_e
Sparse Matrix used to store the eliminations from the b.c. Owned. .
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:161
ParFiniteElementSpace * domain_fes
Points to the same object as trial_fes.
Type
Enumeration defining IDs for some classes derived from Operator.
Definition: operator.hpp:283
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:96
HypreParMatrix * ParallelEliminateTDofs(const Array< int > &tdofs_list, HypreParMatrix &A) const
Eliminate essential true DOFs from a parallel assembled matrix A.
HypreParMatrix * ParallelAssembleElim()
Returns the eliminated matrix assembled on the true dofs, i.e. P^t A_e P.
ParGridFunction Xaux
Auxiliary objects used in TrueAddMult().
void ParallelEliminateEssentialBC(const Array< int > &bdr_attr_is_ess, HypreParMatrix &A, const HypreParVector &X, HypreParVector &B) const
Eliminate essential boundary DOFs from a parallel assembled system.
virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x)
ParBilinearForm(ParFiniteElementSpace *pf)
Creates parallel bilinear form associated with the FE space *pf.
FiniteElementSpace * test_fes
Not owned.
double a
Definition: lissajous.cpp:41
virtual void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
Form the linear system matrix A, see FormLinearSystem() for details.
A "square matrix" operator for the associated FE space and BLFIntegrators The sum of all the BLFInteg...
Class for parallel bilinear form using different test and trial FE spaces.
ParBilinearForm(ParFiniteElementSpace *pf, ParBilinearForm *bf)
Create a ParBilinearForm on the ParFiniteElementSpace *pf, using the same integrators as the ParBilin...
ParFiniteElementSpace * range_fes
Points to the same object as test_fes.
Vector Xaux
Auxiliary vectors used in TrueAddMult(): L-, L-, and T-vector, resp.
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)
Form the parallel linear system A X = B, corresponding to this mixed bilinear form and the linear for...
ParMixedBilinearForm(ParFiniteElementSpace *trial_fes, ParFiniteElementSpace *test_fes, ParMixedBilinearForm *mbf)
Create a ParMixedBilinearForm on the given FiniteElementSpaces trial_fes and test_fes, using the same integrators as the ParMixedBilinearForm mbf.
Class for parallel bilinear form.
ParFiniteElementSpace * trial_pfes
Points to the same object as trial_fes.
FiniteElementSpace * trial_fes
Not owned.
OperatorHandle p_mat
Vector data type.
Definition: vector.hpp:60
ID for class HypreParMatrix.
Definition: operator.hpp:287
Hybridization * hybridization
Owned.
ParMixedBilinearForm(ParFiniteElementSpace *trial_fes, ParFiniteElementSpace *test_fes)
Construct a ParMixedBilinearForm on the given FiniteElementSpaces trial_fes and test_fes.
virtual const Operator * GetRestrictionTranspose() const
Get the transpose of GetRestriction, useful for matrix-free RAP.
Class for parallel grid function.
Definition: pgridfunc.hpp:32
Array< int > vdofs
Abstract operator.
Definition: operator.hpp:24
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:343
OperatorHandle p_mat
Matrix and eliminated matrix.
void SetType(Operator::Type tid)
Invoke Clear() and set a new type id.
Definition: handle.hpp:132
void ParallelAssemble(OperatorHandle &A)
Returns the matrix assembled on the true dofs, i.e. A = P^t A_local P, in the format (type id) specif...