MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
pbilinearform.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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
24namespace mfem
25{
26
27/// Class for parallel bilinear form
29{
31protected:
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
46private:
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
53public:
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. */
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. */
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. */
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,
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 */
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. */
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,
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 real_t a = 1.0) const;
175
176 /// Compute $ y^T M x $
177 /** @warning The calculation is performed on local dofs, assuming that
178 the local vectors are consistent with the prolongations of the true
179 vectors (see ParGridFunction::Distribute()). If this is not the case,
180 use TrueInnerProduct(const ParGridFunction &, const ParGridFunction &)
181 instead.
182 @note It is assumed that the local matrix is assembled and it has
183 not been replaced by the parallel matrix through FormSystemMatrix().
184 @see TrueInnerProduct(const ParGridFunction&, const ParGridFunction&) */
186 const ParGridFunction &y) const;
187
188 /// Compute $ y^T M x $ on true dofs (grid function version)
189 /** @note The ParGridFunction%s are restricted to the true-vectors for
190 for calculation.
191 @note It is assumed that the parallel system matrix is assembled,
192 see FormSystemMatrix().
193 @see ParInnerProduct(const ParGridFunction&, const ParGridFunction&) */
195 const ParGridFunction &y) const;
196
197 /// Compute $ y^T M x $ on true dofs (Hypre vector version)
198 /** @note It is assumed that the parallel system matrix is assembled,
199 see FormSystemMatrix(). */
201
202 /// Compute $ y^T M x $ on true dofs (true-vector version)
203 /** @note It is assumed that the parallel system matrix is assembled,
204 see FormSystemMatrix(). */
205 real_t TrueInnerProduct(const Vector &x, const Vector &y) const;
206
207 /// Return the parallel FE space associated with the ParBilinearForm.
209
210 /// Return the parallel trace FE space associated with static condensation.
213
214 /// Get the parallel finite element space prolongation matrix
215 virtual const Operator *GetProlongation() const
216 { return pfes->GetProlongationMatrix(); }
217 /// Get the transpose of GetRestriction, useful for matrix-free RAP
218 virtual const Operator *GetRestrictionTranspose() const
220 /// Get the parallel finite element space restriction matrix
221 virtual const Operator *GetRestriction() const
222 { return pfes->GetRestrictionMatrix(); }
223
226
227 virtual void FormLinearSystem(const Array<int> &ess_tdof_list, Vector &x,
228 Vector &b, OperatorHandle &A, Vector &X,
229 Vector &B, int copy_interior = 0);
230
231 virtual void FormSystemMatrix(const Array<int> &ess_tdof_list,
232 OperatorHandle &A);
233
234 /** Call this method after solving a linear system constructed using the
235 FormLinearSystem method to recover the solution as a ParGridFunction-size
236 vector in x. Use the same arguments as in the FormLinearSystem call. */
237 virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x);
238
239 virtual void Update(FiniteElementSpace *nfes = NULL);
240
241 void EliminateVDofsInRHS(const Array<int> &vdofs, const Vector &x, Vector &b);
242
243 virtual ~ParBilinearForm() { }
244};
245
246/// Class for parallel bilinear form using different test and trial FE spaces.
248{
249protected:
250 /// Points to the same object as #trial_fes
252 /// Points to the same object as #test_fes
254 /// Auxiliary objects used in TrueAddMult().
256
257 /// Matrix and eliminated matrix
259
260private:
261 /// Copy construction is not supported; body is undefined.
263
264 /// Copy assignment is not supported; body is undefined.
265 ParMixedBilinearForm &operator=(const ParMixedBilinearForm &);
266
267public:
268 /** @brief Construct a ParMixedBilinearForm on the given FiniteElementSpace%s
269 @a trial_fes and @a test_fes. */
270 /** The pointers @a trial_fes and @a test_fes are not owned by the newly
271 constructed object. */
280
281 /** @brief Create a ParMixedBilinearForm on the given FiniteElementSpace%s
282 @a trial_fes and @a test_fes, using the same integrators as the
283 ParMixedBilinearForm @a mbf.
284
285 The pointers @a trial_fes and @a test_fes are not owned by the newly
286 constructed object.
287
288 The integrators in @a mbf are copied as pointers and they are not owned
289 by the newly constructed ParMixedBilinearForm. */
299
300 /// Returns the matrix assembled on the true dofs, i.e. P_test^t A P_trial.
302
303 /** @brief Returns the matrix assembled on the true dofs, i.e.
304 @a A = P_test^t A_local P_trial, in the format (type id) specified by
305 @a A. */
307
310
311 /** @brief Return in @a A a parallel (on truedofs) version of this operator.
312
313 This returns the same operator as FormRectangularLinearSystem(), but does
314 without the transformations of the right-hand side. */
315 virtual void FormRectangularSystemMatrix(const Array<int> &trial_tdof_list,
316 const Array<int> &test_tdof_list,
317 OperatorHandle &A);
318
319 /** @brief Form the parallel linear system A X = B, corresponding to this mixed
320 bilinear form and the linear form @a b(.).
321
322 Return in @a A a *reference* to the system matrix that is column-constrained.
323 The reference will be invalidated when SetOperatorType(), Update(), or the
324 destructor is called. */
325 virtual void FormRectangularLinearSystem(const Array<int> &trial_tdof_list,
326 const Array<int> &test_tdof_list, Vector &x,
327 Vector &b, OperatorHandle &A, Vector &X,
328 Vector &B);
329
330 /// Compute y += a (P^t A P) x, where x and y are vectors on the true dofs
331 void TrueAddMult(const Vector &x, Vector &y, const real_t a = 1.0) const;
332
334};
335
336/** The parallel matrix representation a linear operator between parallel finite
337 element spaces */
339{
340protected:
341 /// Points to the same object as #trial_fes
343 /// Points to the same object as #test_fes
345
346private:
347 /// Copy construction is not supported; body is undefined.
349
350 /// Copy assignment is not supported; body is undefined.
352
353public:
354 /** @brief Construct a ParDiscreteLinearOperator on the given
355 FiniteElementSpace%s @a dfes (domain FE space) and @a rfes (range FE
356 space). */
357 /** The pointers @a dfes and @a rfes are not owned by the newly constructed
358 object. */
362
363 /// Returns the matrix "assembled" on the true dofs
365
366 /** @brief Returns the matrix assembled on the true dofs, i.e.
367 @a A = R_test A_local P_trial, in the format (type id) specified by
368 @a A. */
370
371 /** Extract the parallel blocks corresponding to the vector dimensions of the
372 domain and range parallel finite element spaces */
373 void GetParBlocks(Array2D<HypreParMatrix *> &blocks) const;
374
376
377 /** @brief Return in @a A a parallel (on truedofs) version of this operator. */
379
381};
382
383}
384
385#endif // MFEM_USE_MPI
386
387#endif
Dynamic 2D array using row-major layout.
Definition array.hpp:372
A "square matrix" operator for the associated FE space and BLFIntegrators The sum of all the BLFInteg...
Hybridization * hybridization
Owned.
SparseMatrix * mat
Sparse matrix to be associated with the form. Owned.
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(....
StaticCondensation * static_cond
Owned.
virtual void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
Form the linear system matrix A, see FormLinearSystem() for details.
SparseMatrix * mat_e
Sparse Matrix used to store the eliminations from the b.c. Owned. .
Data and methods for fully-assembled bilinear forms.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:220
const Operator * GetRestrictionTransposeOperator() const
Return an operator that performs the transpose of GetRestrictionOperator.
Definition fespace.cpp:1324
void SetOperatorType(Operator::Type tid)
Set the operator type id for the parallel hybridized matrix/operator.
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:388
void EliminateRowsCols(const Array< int > &rows_cols, const HypreParVector &X, HypreParVector &B)
Definition hypre.cpp:2356
Wrapper for hypre's parallel vector class.
Definition hypre.hpp:206
virtual void FormRectangularSystemMatrix(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, OperatorHandle &A)
Return in A that is column-constrained.
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(....
FiniteElementSpace * trial_fes
Not owned.
FiniteElementSpace * test_fes
Not owned.
Pointer to an Operator of a specified type.
Definition handle.hpp:34
void SetType(Operator::Type tid)
Invoke Clear() and set a new type id.
Definition handle.hpp:132
Abstract operator.
Definition operator.hpp:25
Type
Enumeration defining IDs for some classes derived from Operator.
Definition operator.hpp:284
@ Hypre_ParCSR
ID for class HypreParMatrix.
Definition operator.hpp:287
Class for parallel bilinear form.
void SetOperatorType(Operator::Type tid)
Set the operator type id for the parallel matrix/operator when using AssemblyLevel::LEGACY.
Vector Xaux
Auxiliary vectors used in TrueAddMult(): L-, L-, and T-vector, resp.
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(....
virtual const Operator * GetRestriction() const
Get the parallel finite element space restriction matrix.
ParBilinearForm(ParFiniteElementSpace *pf)
Creates parallel bilinear form associated with the FE space *pf.
ParFiniteElementSpace * pfes
Points to the same object as fes.
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()
Returns the matrix assembled on the true dofs, i.e. P^t A P.
HypreParMatrix * ParallelAssembleElim()
Returns the eliminated matrix assembled on the true dofs, i.e. P^t A_e P.
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.
real_t ParInnerProduct(const ParGridFunction &x, const ParGridFunction &y) const
Compute .
void Assemble(int skip_zeros=1)
Assemble the local matrix.
virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x)
virtual const Operator * GetProlongation() const
Get the parallel finite element space prolongation matrix.
void AssembleSharedFaces(int skip_zeros=1)
ParFiniteElementSpace * SCParFESpace() const
Return the parallel trace FE space associated with static condensation.
virtual void Update(FiniteElementSpace *nfes=NULL)
Update the FiniteElementSpace and delete all data associated with the old one.
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...
HypreParMatrix * ParallelEliminateTDofs(const Array< int > &tdofs_list, HypreParMatrix &A) const
Eliminate essential true DOFs from a parallel assembled matrix A.
ParFiniteElementSpace * ParFESpace() const
Return the parallel FE space associated with the ParBilinearForm.
ParBilinearForm(ParFiniteElementSpace *pf, ParBilinearForm *bf)
Create a ParBilinearForm on the ParFiniteElementSpace *pf, using the same integrators as the ParBilin...
virtual void AssembleDiagonal(Vector &diag) const
Assemble the diagonal of the bilinear form into diag. Note that diag is a true-dof Vector.
void KeepNbrBlock(bool knb=true)
virtual const Operator * GetRestrictionTranspose() const
Get the transpose of GetRestriction, useful for matrix-free RAP.
void ParallelAssembleElim(OperatorHandle &A_elim)
real_t TrueInnerProduct(const ParGridFunction &x, const ParGridFunction &y) const
Compute on true dofs (grid function version)
virtual void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
Form the linear system matrix A, see FormLinearSystem() for details.
void TrueAddMult(const Vector &x, Vector &y, const real_t a=1.0) const
Compute y += a (P^t A P) x, where x and y are vectors on the true dofs.
void EliminateVDofsInRHS(const Array< int > &vdofs, const Vector &x, Vector &b)
void GetParBlocks(Array2D< HypreParMatrix * > &blocks) const
ParFiniteElementSpace * range_fes
Points to the same object as test_fes.
HypreParMatrix * ParallelAssemble() const
Returns the matrix "assembled" on the true dofs.
ParFiniteElementSpace * domain_fes
Points to the same object as trial_fes.
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.
Abstract parallel finite element space.
Definition pfespace.hpp:29
const Operator * GetProlongationMatrix() const override
The returned Operator is owned by the FiniteElementSpace.
const SparseMatrix * GetRestrictionMatrix() const override
Get the R matrix which restricts a local dof vector to true dof vector.
Definition pfespace.hpp:389
Class for parallel grid function.
Definition pgridfunc.hpp:33
Class for parallel bilinear form using different test and trial FE spaces.
ParGridFunction Xaux
Auxiliary objects used in TrueAddMult().
OperatorHandle p_mat
Matrix and eliminated matrix.
void TrueAddMult(const Vector &x, Vector &y, const real_t a=1.0) const
Compute y += a (P^t A P) x, where x and y are vectors on the true dofs.
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...
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.
HypreParMatrix * ParallelAssemble()
Returns the matrix assembled on the true dofs, i.e. P_test^t A P_trial.
ParFiniteElementSpace * test_pfes
Points to the same object as test_fes.
ParFiniteElementSpace * trial_pfes
Points to the same object as trial_fes.
ParMixedBilinearForm(ParFiniteElementSpace *trial_fes, ParFiniteElementSpace *test_fes, ParMixedBilinearForm *mbf)
Create a ParMixedBilinearForm on the given FiniteElementSpaces trial_fes and test_fes,...
ParMixedBilinearForm(ParFiniteElementSpace *trial_fes, ParFiniteElementSpace *test_fes)
Construct a ParMixedBilinearForm on the given FiniteElementSpaces trial_fes and test_fes.
Data type sparse matrix.
Definition sparsemat.hpp:51
void SetOperatorType(Operator::Type tid)
Set the operator type id for the parallel reduced matrix/operator.
ParFiniteElementSpace * GetParTraceFESpace()
Return a pointer to the parallel reduced/trace FE space.
Vector data type.
Definition vector.hpp:80
real_t b
Definition lissajous.cpp:42
real_t a
Definition lissajous.cpp:41
float real_t
Definition config.hpp:43