MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
bilinearform_ext.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, 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_BILINEARFORM_EXT
13#define MFEM_BILINEARFORM_EXT
14
15#include "../config/config.hpp"
16#include "fespace.hpp"
17#include "../general/device.hpp"
18
19namespace mfem
20{
21
22class BilinearForm;
23class MixedBilinearForm;
24class DiscreteLinearOperator;
25
26/// Class extending the BilinearForm class to support different AssemblyLevels.
27/** FA - Full Assembly
28 PA - Partial Assembly
29 EA - Element Assembly
30 MF - Matrix Free
31*/
33{
34protected:
35 BilinearForm *a; ///< Not owned
36
37public:
39
40 MemoryClass GetMemoryClass() const override
42
43 /// Get the finite element space prolongation matrix
44 const Operator *GetProlongation() const override;
45
46 /// Get the finite element space restriction matrix
47 const Operator *GetRestriction() const override;
48
49 /// Assemble at the level given for the BilinearFormExtension subclass
50 virtual void Assemble() = 0;
51
52 void AssembleDiagonal(Vector &diag) const override
53 {
54 MFEM_ABORT("AssembleDiagonal not implemented for this assembly level!");
55 }
56
57 virtual void FormSystemMatrix(const Array<int> &ess_tdof_list,
58 OperatorHandle &A) = 0;
59 virtual void FormLinearSystem(const Array<int> &ess_tdof_list,
60 Vector &x, Vector &b,
61 OperatorHandle &A, Vector &X, Vector &B,
62 int copy_interior = 0) = 0;
63 virtual void Update() = 0;
64};
65
66/// Data and methods for partially-assembled bilinear forms
68{
69protected:
70 const FiniteElementSpace *trial_fes, *test_fes; // Not owned
71 /// Attributes of all mesh elements.
72 const Array<int> *elem_attributes; // Not owned
73 const Array<int> *bdr_face_attributes; // Not owned
74 mutable Vector tmp_evec; // Work array
80 const Operator *elem_restrict; // Not owned
83
84public:
86
87 void Assemble() override;
88 void AssembleDiagonal(Vector &diag) const override;
89 void FormSystemMatrix(const Array<int> &ess_tdof_list,
90 OperatorHandle &A) override;
91 void FormLinearSystem(const Array<int> &ess_tdof_list,
92 Vector &x, Vector &b,
93 OperatorHandle &A, Vector &X, Vector &B,
94 int copy_interior = 0) override;
95 void Mult(const Vector &x, Vector &y) const override
96 { MultInternal(x,y); }
97 void AbsMult(const Vector &x, Vector &y) const override
98 { MultInternal(x,y, true); }
99 void MultTranspose(const Vector &x, Vector &y) const override;
100 void Update() override;
101
102protected:
104 void MultInternal(const Vector &x, Vector &y,
105 const bool useAbs = false) const;
106
107 /// @brief Accumulate the action (or transpose) of the integrator on @a x
108 /// into @a y, taking into account the (possibly null) @a markers array.
109 ///
110 /// If @a markers is non-null, then only those elements or boundary elements
111 /// whose attribute is marked in the markers array will be added to @a y.
112 ///
113 /// @param integ The integrator (domain, boundary, or boundary face).
114 /// @param x Input E-vector.
115 /// @param markers Marked attributes (possibly null, meaning all attributes).
116 /// @param attributes Array of element or boundary element attributes.
117 /// @param transpose Compute the action or transpose of the integrator .
118 /// @param y Output E-vector
119 /// @param useAbs Apply absolute-value operator
121 const Vector &x,
122 const Array<int> *markers,
123 const Array<int> &attributes,
124 const bool transpose,
125 Vector &y,
126 const bool useAbs = false) const;
127
128 /// @brief Performs the same function as AddMultWithMarkers, but takes as
129 /// input and output face normal derivatives.
130 ///
131 /// This is required when the integrator requires face normal derivatives,
132 /// for example, DGDiffusionIntegrator.
133 ///
134 /// This is called when the integrator's member function
135 /// BilinearFormIntegrator::RequiresFaceNormalDerivatives() returns true.
137 const BilinearFormIntegrator &integ,
138 const Vector &x,
139 const Vector &dxdn,
140 const Array<int> *markers,
141 const Array<int> &attributes,
142 Vector &y,
143 Vector &dydn) const;
144};
145
146/// Data and methods for element-assembled bilinear forms
148{
149protected:
150 int ne;
152 // The element matrices are stored row major
158
159public:
161
162 void Assemble() override;
163
164 void Mult(const Vector &x, Vector &y) const override
165 { MultInternal(x, y, false); }
166 void AbsMult(const Vector &x, Vector &y) const override
167 { MultInternal(x, y, false, true); }
168 void MultTranspose(const Vector &x, Vector &y) const override
169 { MultInternal(x, y, true); }
170 void AbsMultTranspose(const Vector &x, Vector &y) const override
171 { MultInternal(x, y, true, true); }
172
173 /// @brief Populates @a element_matrices with the element matrices.
174 ///
175 /// The element matrices are converted from row-major (how they are stored in
176 /// @a ea_data) to column-major format.
177 ///
178 /// If @a ordering is ElementDofOrdering::NATIVE, then the matrices are
179 /// reordered from the lexicographic ordering used internally.
180 void GetElementMatrices(DenseTensor &element_matrices,
181 ElementDofOrdering ordering,
182 bool add_bdr);
183
184 // This method needs to be public due to 'nvcc' restriction.
185 void MultInternal(const Vector &x, Vector &y, const bool useTranspose,
186 const bool useAbs = false) const;
187};
188
189/// Data and methods for fully-assembled bilinear forms
191{
192private:
193 SparseMatrix *mat;
194 mutable Vector dg_x, dg_y;
195
196public:
198
199 void Assemble() override;
200 void RAP(OperatorHandle &A);
201 /** @note Always does `DIAG_ONE` policy to be consistent with
202 `Operator::FormConstrainedSystemOperator`. */
203 void EliminateBC(const Array<int> &ess_dofs, OperatorHandle &A);
204 void FormSystemMatrix(const Array<int> &ess_tdof_list,
205 OperatorHandle &A) override;
206 void FormLinearSystem(const Array<int> &ess_tdof_list,
207 Vector &x, Vector &b,
208 OperatorHandle &A, Vector &X, Vector &B,
209 int copy_interior = 0) override;
210 void Mult(const Vector &x, Vector &y) const override;
211 void MultTranspose(const Vector &x, Vector &y) const override;
212
213 /** DGMult and DGMultTranspose use the extended L-vector to perform the
214 computation. */
215 void DGMult(const Vector &x, Vector &y) const;
216 void DGMultTranspose(const Vector &x, Vector &y) const;
217};
218
219/// Data and methods for matrix-free bilinear forms
221{
222protected:
223 const FiniteElementSpace *trial_fes, *test_fes; // Not owned
227 const Operator *elem_restrict; // Not owned
230
231public:
233
234 void Assemble() override;
235 void AssembleDiagonal(Vector &diag) const override;
236 void FormSystemMatrix(const Array<int> &ess_tdof_list,
237 OperatorHandle &A) override;
238 void FormLinearSystem(const Array<int> &ess_tdof_list,
239 Vector &x, Vector &b,
240 OperatorHandle &A, Vector &X, Vector &B,
241 int copy_interior = 0) override;
242 void Mult(const Vector &x, Vector &y) const override;
243 void MultTranspose(const Vector &x, Vector &y) const override;
244 void Update() override;
245};
246
247/// Class extending the MixedBilinearForm class to support different AssemblyLevels.
248/** FA - Full Assembly
249 PA - Partial Assembly
250 EA - Element Assembly
251 MF - Matrix Free
252*/
254{
255protected:
256 MixedBilinearForm *a; ///< Not owned
257
258public:
260
262 { return Device::GetMemoryClass(); }
263
264 /// Get the finite element space prolongation matrix
265 const Operator *GetProlongation() const override;
266
267 /// Get the finite element space restriction matrix
268 const Operator *GetRestriction() const override;
269
270 /// Get the output finite element space restriction matrix
271 const Operator *GetOutputProlongation() const override;
272
273 /// Get the output finite element space restriction matrix
274 const Operator *GetOutputRestriction() const override;
275
276 virtual void Assemble() = 0;
277 virtual void FormRectangularSystemOperator(const Array<int> &trial_tdof_list,
278 const Array<int> &test_tdof_list,
279 OperatorHandle &A) = 0;
280 virtual void FormRectangularLinearSystem(const Array<int> &trial_tdof_list,
281 const Array<int> &test_tdof_list,
282 Vector &x, Vector &b,
283 OperatorHandle &A, Vector &X, Vector &B) = 0;
284
285 virtual void AssembleDiagonal_ADAt(const Vector &D, Vector &diag) const = 0;
286
287 virtual void Update() = 0;
288};
289
290/// Data and methods for partially-assembled mixed bilinear forms
292{
293protected:
294 const FiniteElementSpace *trial_fes, *test_fes; // Not owned
296 const Operator *elem_restrict_trial; // Not owned
297 const Operator *elem_restrict_test; // Not owned
298
299 /// Helper function to set up inputs/outputs for Mult or MultTranspose
300 void SetupMultInputs(const Operator *elem_restrict_x,
301 const Vector &x, Vector &localX,
302 const Operator *elem_restrict_y,
303 Vector &y, Vector &localY, const real_t c) const;
304
305public:
307
308 /// Partial assembly of all internal integrators
309 void Assemble() override;
310 /**
311 @brief Setup OperatorHandle A to contain constrained linear operator
312
313 OperatorHandle A contains matrix-free constrained operator formed for RAP
314 system where ess_tdof_list are in trial space and eliminated from
315 "columns" of A.
316 */
317 void FormRectangularSystemOperator(const Array<int> &trial_tdof_list,
318 const Array<int> &test_tdof_list,
319 OperatorHandle &A) override;
320 /**
321 Setup OperatorHandle A to contain constrained linear operator and
322 eliminate columns corresponding to essential dofs from system,
323 updating RHS B vector with the results.
324 */
325 void FormRectangularLinearSystem(const Array<int> &trial_tdof_list,
326 const Array<int> &test_tdof_list,
327 Vector &x, Vector &b,
328 OperatorHandle &A, Vector &X, Vector &B) override;
329 /// y = A*x
330 void Mult(const Vector &x, Vector &y) const override;
331 /// y += c*A*x
332 void AddMult(const Vector &x, Vector &y, const real_t c=1.0) const override;
333 /// y = A^T*x
334 void MultTranspose(const Vector &x, Vector &y) const override;
335 /// y += c*A^T*x
336 void AddMultTranspose(const Vector &x, Vector &y,
337 const real_t c=1.0) const override;
338 /// Assemble the diagonal of ADA^T for a diagonal vector D.
339 void AssembleDiagonal_ADAt(const Vector &D, Vector &diag) const override;
340
341 /// Update internals for when a new MixedBilinearForm is given to this class
342 void Update() override;
343};
344
345
346/**
347 @brief Partial assembly extension for DiscreteLinearOperator
348
349 This acts very much like PAMixedBilinearFormExtension, but its
350 FormRectangularSystemOperator implementation emulates 'Set' rather than
351 'Add' in the assembly case.
352*/
354{
355public:
357
358 /// Partial assembly of all internal integrators
359 void Assemble() override;
360
361 void AddMult(const Vector &x, Vector &y, const real_t c=1.0) const override;
362
363 void AddMultTranspose(const Vector &x, Vector &y,
364 const real_t c=1.0) const override;
365
367 OperatorHandle& A) override;
368
369 const Operator * GetOutputRestrictionTranspose() const override;
370
371private:
372 Vector test_multiplicity;
373};
374
375}
376
377#endif
Class extending the BilinearForm class to support different AssemblyLevels.
virtual void Assemble()=0
Assemble at the level given for the BilinearFormExtension subclass.
BilinearFormExtension(BilinearForm *form)
void AssembleDiagonal(Vector &diag) const override
Computes the diagonal entries into diag. Typically, this operation only makes sense for linear Operat...
virtual void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)=0
virtual void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)=0
const Operator * GetRestriction() const override
Get the finite element space restriction matrix.
MemoryClass GetMemoryClass() const override
Return the MemoryClass preferred by the Operator.
BilinearForm * a
Not owned.
const Operator * GetProlongation() const override
Get the finite element space prolongation matrix.
Abstract base class BilinearFormIntegrator.
A "square matrix" operator for the associated FE space and BLFIntegrators The sum of all the BLFInteg...
Rank 3 tensor (array of matrices)
static MemoryClass GetMemoryClass()
(DEPRECATED) Equivalent to GetDeviceMemoryClass().
Definition device.hpp:289
static MemoryClass GetDeviceMemoryClass()
Get the current Device MemoryClass. This is the MemoryClass used by most MFEM device kernels to acces...
Definition device.hpp:285
Data and methods for element-assembled bilinear forms.
void Mult(const Vector &x, Vector &y) const override
Operator application: y=A(x).
void GetElementMatrices(DenseTensor &element_matrices, ElementDofOrdering ordering, bool add_bdr)
Populates element_matrices with the element matrices.
void MultInternal(const Vector &x, Vector &y, const bool useTranspose, const bool useAbs=false) const
void MultTranspose(const Vector &x, Vector &y) const override
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
EABilinearFormExtension(BilinearForm *form)
void Assemble() override
Assemble at the level given for the BilinearFormExtension subclass.
void AbsMult(const Vector &x, Vector &y) const override
Action of the absolute-value operator: y=|A|(x). The default behavior in class Operator is to generat...
void AbsMultTranspose(const Vector &x, Vector &y) const override
Action of the transpose absolute-value operator: y=|A|^t(x). The default behavior in class Operator i...
Data and methods for fully-assembled bilinear forms.
void MultTranspose(const Vector &x, Vector &y) const override
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
void DGMultTranspose(const Vector &x, Vector &y) const
void EliminateBC(const Array< int > &ess_dofs, OperatorHandle &A)
void DGMult(const Vector &x, Vector &y) const
void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A) override
void Mult(const Vector &x, Vector &y) const override
Operator application: y=A(x).
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0) override
void Assemble() override
Assemble at the level given for the BilinearFormExtension subclass.
FABilinearFormExtension(BilinearForm *form)
Base class for operators that extracts Face degrees of freedom.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:208
Data and methods for matrix-free bilinear forms.
void Mult(const Vector &x, Vector &y) const override
Operator application: y=A(x).
const FiniteElementSpace * trial_fes
void AssembleDiagonal(Vector &diag) const override
Computes the diagonal entries into diag. Typically, this operation only makes sense for linear Operat...
const FaceRestriction * bdr_face_restrict_lex
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0) override
void MultTranspose(const Vector &x, Vector &y) const override
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
void Assemble() override
Assemble at the level given for the BilinearFormExtension subclass.
const FiniteElementSpace * test_fes
const FaceRestriction * int_face_restrict_lex
void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A) override
MFBilinearFormExtension(BilinearForm *form)
Class extending the MixedBilinearForm class to support different AssemblyLevels.
MixedBilinearForm * a
Not owned.
virtual void AssembleDiagonal_ADAt(const Vector &D, Vector &diag) const =0
const Operator * GetOutputProlongation() const override
Get the output finite element space restriction matrix.
virtual void FormRectangularSystemOperator(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, OperatorHandle &A)=0
const Operator * GetProlongation() const override
Get the finite element space prolongation matrix.
MemoryClass GetMemoryClass() const override
Return the MemoryClass preferred by the Operator.
const Operator * GetOutputRestriction() const override
Get the output finite element space restriction matrix.
MixedBilinearFormExtension(MixedBilinearForm *form)
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)=0
const Operator * GetRestriction() const override
Get the finite element space restriction matrix.
Pointer to an Operator of a specified type.
Definition handle.hpp:34
Abstract operator.
Definition operator.hpp:25
Data and methods for partially-assembled bilinear forms.
void AbsMult(const Vector &x, Vector &y) const override
Action of the absolute-value operator: y=|A|(x). The default behavior in class Operator is to generat...
void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A) override
void AssembleDiagonal(Vector &diag) const override
Computes the diagonal entries into diag. Typically, this operation only makes sense for linear Operat...
const FiniteElementSpace * trial_fes
const FaceRestriction * int_face_restrict_lex
const FaceRestriction * bdr_face_restrict_lex
void MultInternal(const Vector &x, Vector &y, const bool useAbs=false) const
void AddMultNormalDerivativesWithMarkers(const BilinearFormIntegrator &integ, const Vector &x, const Vector &dxdn, const Array< int > *markers, const Array< int > &attributes, Vector &y, Vector &dydn) const
Performs the same function as AddMultWithMarkers, but takes as input and output face normal derivativ...
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0) override
void MultTranspose(const Vector &x, Vector &y) const override
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
const FiniteElementSpace * test_fes
void Assemble() override
Assemble at the level given for the BilinearFormExtension subclass.
void AddMultWithMarkers(const BilinearFormIntegrator &integ, const Vector &x, const Array< int > *markers, const Array< int > &attributes, const bool transpose, Vector &y, const bool useAbs=false) const
Accumulate the action (or transpose) of the integrator on x into y, taking into account the (possibly...
void Mult(const Vector &x, Vector &y) const override
Operator application: y=A(x).
const Array< int > * elem_attributes
Attributes of all mesh elements.
void SetupRestrictionOperators(const L2FaceValues m)
const Array< int > * bdr_face_attributes
Partial assembly extension for DiscreteLinearOperator.
void Assemble() override
Partial assembly of all internal integrators.
PADiscreteLinearOperatorExtension(DiscreteLinearOperator *linop)
void AddMult(const Vector &x, Vector &y, const real_t c=1.0) const override
Operator application: y+=A(x) (default) or y+=a*A(x).
void AddMultTranspose(const Vector &x, Vector &y, const real_t c=1.0) const override
Operator transpose application: y+=A^t(x) (default) or y+=a*A^t(x).
const Operator * GetOutputRestrictionTranspose() const override
Transpose of GetOutputRestriction, directly available in this form to facilitate matrix-free RAP-type...
void FormRectangularSystemOperator(const Array< int > &, const Array< int > &, OperatorHandle &A) override
Data and methods for partially-assembled mixed bilinear forms.
void FormRectangularSystemOperator(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, OperatorHandle &A) override
Setup OperatorHandle A to contain constrained linear operator.
const FiniteElementSpace * test_fes
void Assemble() override
Partial assembly of all internal integrators.
PAMixedBilinearFormExtension(MixedBilinearForm *form)
void MultTranspose(const Vector &x, Vector &y) const override
y = A^T*x
const FiniteElementSpace * trial_fes
void AddMultTranspose(const Vector &x, Vector &y, const real_t c=1.0) const override
y += c*A^T*x
void AssembleDiagonal_ADAt(const Vector &D, Vector &diag) const override
Assemble the diagonal of ADA^T for a diagonal vector D.
void SetupMultInputs(const Operator *elem_restrict_x, const Vector &x, Vector &localX, const Operator *elem_restrict_y, Vector &y, Vector &localY, const real_t c) const
Helper function to set up inputs/outputs for Mult or MultTranspose.
void FormRectangularLinearSystem(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B) override
void Update() override
Update internals for when a new MixedBilinearForm is given to this class.
void AddMult(const Vector &x, Vector &y, const real_t c=1.0) const override
y += c*A*x
void Mult(const Vector &x, Vector &y) const override
y = A*x
Data type sparse matrix.
Definition sparsemat.hpp:51
Vector data type.
Definition vector.hpp:82
real_t b
Definition lissajous.cpp:42
MemoryClass
Memory classes identify sets of memory types.
float real_t
Definition config.hpp:46
ElementDofOrdering
Constants describing the possible orderings of the DOFs in one element.
Definition fespace.hpp:47