MFEM v4.8.0
Finite element discretization library
Loading...
Searching...
No Matches
operator.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_OPERATOR
13#define MFEM_OPERATOR
14
15#include "vector.hpp"
16
17namespace mfem
18{
19
20class ConstrainedOperator;
21class RectangularConstrainedOperator;
22
23/// Abstract operator
25{
26protected:
27 int height; ///< Dimension of the output / number of rows in the matrix.
28 int width; ///< Dimension of the input / number of columns in the matrix.
29
30 /// see FormSystemOperator()
31 /** @note Uses DiagonalPolicy::DIAG_ONE. */
33 const Array<int> &ess_tdof_list, ConstrainedOperator* &Aout);
34
35 /// see FormRectangularSystemOperator()
37 const Array<int> &trial_tdof_list,
38 const Array<int> &test_tdof_list,
40
41 /** @brief Returns RAP Operator of this, using input/output Prolongation matrices
42 @a Pi corresponds to "P", @a Po corresponds to "Rt" */
43 Operator *SetupRAP(const Operator *Pi, const Operator *Po);
44
45public:
46 /// Defines operator diagonal policy upon elimination of rows and/or columns.
48 {
49 DIAG_ZERO, ///< Set the diagonal value to zero
50 DIAG_ONE, ///< Set the diagonal value to one
51 DIAG_KEEP ///< Keep the diagonal value
52 };
53
54 /// Initializes memory for true vectors of linear system
55 void InitTVectors(const Operator *Po, const Operator *Ri, const Operator *Pi,
56 Vector &x, Vector &b, Vector &X, Vector &B) const;
57
58 /// Construct a square Operator with given size s (default 0).
59 explicit Operator(int s = 0) { height = width = s; }
60
61 /** @brief Construct an Operator with the given height (output size) and
62 width (input size). */
63 Operator(int h, int w) { height = h; width = w; }
64
65 /// Get the height (size of output) of the Operator. Synonym with NumRows().
66 inline int Height() const { return height; }
67 /** @brief Get the number of rows (size of output) of the Operator. Synonym
68 with Height(). */
69 inline int NumRows() const { return height; }
70
71 /// Get the width (size of input) of the Operator. Synonym with NumCols().
72 inline int Width() const { return width; }
73 /** @brief Get the number of columns (size of input) of the Operator. Synonym
74 with Width(). */
75 inline int NumCols() const { return width; }
76
77 /// Return the MemoryClass preferred by the Operator.
78 /** This is the MemoryClass that will be used to access the input and output
79 vectors in the Mult() and MultTranspose() methods.
80
81 For example, classes using the mfem::forall macro for implementation can
82 return the value returned by Device::GetMemoryClass().
83
84 The default implementation of this method in class Operator returns
85 MemoryClass::HOST. */
86 virtual MemoryClass GetMemoryClass() const { return MemoryClass::HOST; }
87
88 /// Operator application: `y=A(x)`.
89 virtual void Mult(const Vector &x, Vector &y) const = 0;
90
91 /** @brief Action of the transpose operator: `y=A^t(x)`. The default behavior
92 in class Operator is to generate an error. */
93 virtual void MultTranspose(const Vector &x, Vector &y) const
94 { mfem_error("Operator::MultTranspose() is not overridden!"); }
95
96 /// Operator application: `y+=A(x)` (default) or `y+=a*A(x)`.
97 virtual void AddMult(const Vector &x, Vector &y, const real_t a = 1.0) const;
98
99 /// Operator transpose application: `y+=A^t(x)` (default) or `y+=a*A^t(x)`.
100 virtual void AddMultTranspose(const Vector &x, Vector &y,
101 const real_t a = 1.0) const;
102
103 /// Operator application on a matrix: `Y=A(X)`.
104 virtual void ArrayMult(const Array<const Vector *> &X,
105 Array<Vector *> &Y) const;
106
107 /// Action of the transpose operator on a matrix: `Y=A^t(X)`.
108 virtual void ArrayMultTranspose(const Array<const Vector *> &X,
109 Array<Vector *> &Y) const;
110
111 /// Operator application on a matrix: `Y+=A(X)` (default) or `Y+=a*A(X)`.
112 virtual void ArrayAddMult(const Array<const Vector *> &X, Array<Vector *> &Y,
113 const real_t a = 1.0) const;
114
115 /** @brief Operator transpose application on a matrix: `Y+=A^t(X)` (default)
116 or `Y+=a*A^t(X)`. */
117 virtual void ArrayAddMultTranspose(const Array<const Vector *> &X,
118 Array<Vector *> &Y, const real_t a = 1.0) const;
119
120 /** @brief Evaluate the gradient operator at the point @a x. The default
121 behavior in class Operator is to generate an error. */
122 virtual Operator &GetGradient(const Vector &x) const
123 {
124 mfem_error("Operator::GetGradient() is not overridden!");
125 return const_cast<Operator &>(*this);
126 }
127
128 /** @brief Computes the diagonal entries into @a diag. Typically, this
129 operation only makes sense for linear Operator%s. In some cases, only an
130 approximation of the diagonal is computed. */
131 virtual void AssembleDiagonal(Vector &diag) const
132 {
133 MFEM_CONTRACT_VAR(diag);
134 MFEM_ABORT("Not relevant or not implemented for this Operator.");
135 }
136
137 /** @brief Prolongation operator from linear algebra (linear system) vectors,
138 to input vectors for the operator. `NULL` means identity. */
139 virtual const Operator *GetProlongation() const { return NULL; }
140
141 /** @brief Restriction operator from input vectors for the operator to linear
142 algebra (linear system) vectors. `NULL` means identity. */
143 virtual const Operator *GetRestriction() const { return NULL; }
144
145 /** @brief Prolongation operator from linear algebra (linear system) vectors,
146 to output vectors for the operator. `NULL` means identity. */
147 virtual const Operator *GetOutputProlongation() const
148 {
149 return GetProlongation(); // Assume square unless specialized
150 }
151
152 /** @brief Transpose of GetOutputRestriction, directly available in this
153 form to facilitate matrix-free RAP-type operators.
154
155 `NULL` means identity. */
156 virtual const Operator *GetOutputRestrictionTranspose() const { return NULL; }
157
158 /** @brief Restriction operator from output vectors for the operator to linear
159 algebra (linear system) vectors. `NULL` means identity. */
160 virtual const Operator *GetOutputRestriction() const
161 {
162 return GetRestriction(); // Assume square unless specialized
163 }
164
165 /** @brief Form a constrained linear system using a matrix-free approach.
166
167 Assuming square operator, form the operator linear system `A(X)=B`,
168 corresponding to it and the right-hand side @a b, by applying any
169 necessary transformations such as: parallel assembly, conforming
170 constraints for non-conforming AMR and eliminating boundary conditions.
171 @note Static condensation and hybridization are not supported for general
172 operators (cf. the analogous methods BilinearForm::FormLinearSystem() and
173 ParBilinearForm::FormLinearSystem()).
174
175 The constraints are specified through the prolongation P from
176 GetProlongation(), and restriction R from GetRestriction() methods, which
177 are e.g. available through the (parallel) finite element space of any
178 (parallel) bilinear form operator. We assume that the operator is square,
179 using the same input and output space, so we have: `A(X)=[P^t (*this)
180 P](X)`, `B=P^t(b)`, and `X=R(x)`.
181
182 The vector @a x must contain the essential boundary condition values.
183 These are eliminated through the ConstrainedOperator class and the vector
184 @a X is initialized by setting its essential entries to the boundary
185 conditions and all other entries to zero (@a copy_interior == 0) or
186 copied from @a x (@a copy_interior != 0).
187
188 After solving the system `A(X)=B`, the (finite element) solution @a x can
189 be recovered by calling Operator::RecoverFEMSolution() with the same
190 vectors @a X, @a b, and @a x.
191
192 @note The caller is responsible for destroying the output operator @a A!
193 @note If there are no transformations, @a X simply reuses the data of @a
194 x. */
195 void FormLinearSystem(const Array<int> &ess_tdof_list,
196 Vector &x, Vector &b,
197 Operator* &A, Vector &X, Vector &B,
198 int copy_interior = 0);
199
200 /** @brief Form a column-constrained linear system using a matrix-free approach.
201
202 Form the operator linear system `A(X)=B` corresponding to the operator
203 and the right-hand side @a b, by applying any necessary transformations
204 such as: parallel assembly, conforming constraints for non-conforming AMR
205 and eliminating boundary conditions. @note Static condensation and
206 hybridization are not supported for general operators (cf. the method
207 MixedBilinearForm::FormRectangularLinearSystem())
208
209 The constraints are specified through the input prolongation Pi from
210 GetProlongation(), and output restriction Ro from GetOutputRestriction()
211 methods, which are e.g. available through the (parallel) finite element
212 spaces of any (parallel) mixed bilinear form operator. So we have:
213 `A(X)=[Ro (*this) Pi](X)`, `B=Ro(b)`, and `X=Pi^T(x)`.
214
215 The vector @a x must contain the essential boundary condition values.
216 The "columns" in this operator corresponding to these values are
217 eliminated through the RectangularConstrainedOperator class.
218
219 After solving the system `A(X)=B`, the (finite element) solution @a x can
220 be recovered by calling Operator::RecoverFEMSolution() with the same
221 vectors @a X, @a b, and @a x.
222
223 @note The caller is responsible for destroying the output operator @a A!
224 @note If there are no transformations, @a X simply reuses the data of @a
225 x. */
226 void FormRectangularLinearSystem(const Array<int> &trial_tdof_list,
227 const Array<int> &test_tdof_list,
228 Vector &x, Vector &b,
229 Operator* &A, Vector &X, Vector &B);
230
231 /** @brief Reconstruct a solution vector @a x (e.g. a GridFunction) from the
232 solution @a X of a constrained linear system obtained from
233 Operator::FormLinearSystem() or Operator::FormRectangularLinearSystem().
234
235 Call this method after solving a linear system constructed using
236 Operator::FormLinearSystem() to recover the solution as an input vector,
237 @a x, for this Operator (presumably a finite element grid function). This
238 method has identical signature to the analogous method for bilinear
239 forms, though currently @a b is not used in the implementation. */
240 virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x);
241
242 /** @brief Return in @a A a parallel (on truedofs) version of this square
243 operator.
244
245 This returns the same operator as FormLinearSystem(), but does without
246 the transformations of the right-hand side and initial guess. */
247 void FormSystemOperator(const Array<int> &ess_tdof_list,
248 Operator* &A);
249
250 /** @brief Return in @a A a parallel (on truedofs) version of this
251 rectangular operator (including constraints).
252
253 This returns the same operator as FormRectangularLinearSystem(), but does
254 without the transformations of the right-hand side. */
255 void FormRectangularSystemOperator(const Array<int> &trial_tdof_list,
256 const Array<int> &test_tdof_list,
257 Operator* &A);
258
259 /** @brief Return in @a A a parallel (on truedofs) version of this
260 rectangular operator.
261
262 This is similar to FormSystemOperator(), but for dof-to-dof mappings
263 (discrete linear operators), which can also correspond to rectangular
264 matrices. The user should provide specializations of GetProlongation()
265 for the input dofs and GetOutputRestriction() for the output dofs in
266 their Operator implementation that are appropriate for the two spaces the
267 Operator maps between. These are e.g. available through the (parallel)
268 finite element space of any (parallel) bilinear form operator. We have:
269 `A(X)=[Rout (*this) Pin](X)`. */
271
272 /// Prints operator with input size n and output size m in Matlab format.
273 void PrintMatlab(std::ostream & out, int n, int m = 0) const;
274
275 /// Prints operator in Matlab format.
276 virtual void PrintMatlab(std::ostream & out) const;
277
278 /// Virtual destructor.
279 virtual ~Operator() { }
280
281 /// Enumeration defining IDs for some classes derived from Operator.
282 /** This enumeration is primarily used with class OperatorHandle. */
283 enum Type
284 {
285 ANY_TYPE, ///< ID for the base class Operator, i.e. any type.
286 MFEM_SPARSEMAT, ///< ID for class SparseMatrix.
287 Hypre_ParCSR, ///< ID for class HypreParMatrix.
288 PETSC_MATAIJ, ///< ID for class PetscParMatrix, MATAIJ format.
289 PETSC_MATIS, ///< ID for class PetscParMatrix, MATIS format.
290 PETSC_MATSHELL, ///< ID for class PetscParMatrix, MATSHELL format.
291 PETSC_MATNEST, ///< ID for class PetscParMatrix, MATNEST format.
292 PETSC_MATHYPRE, ///< ID for class PetscParMatrix, MATHYPRE format.
293 PETSC_MATGENERIC, ///< ID for class PetscParMatrix, unspecified format.
294 Complex_Operator, ///< ID for class ComplexOperator.
295 MFEM_ComplexSparseMat, ///< ID for class ComplexSparseMatrix.
296 Complex_Hypre_ParCSR, ///< ID for class ComplexHypreParMatrix.
297 Complex_DenseMat, ///< ID for class ComplexDenseMatrix
298 MFEM_Block_Matrix, ///< ID for class BlockMatrix.
299 MFEM_Block_Operator ///< ID for the base class BlockOperator.
300 };
301
302 /// Return the type ID of the Operator class.
303 /** This method is intentionally non-virtual, so that it returns the ID of
304 the specific pointer or reference type used when calling this method. If
305 not overridden by derived classes, they will automatically use the type ID
306 of the base Operator class, ANY_TYPE. */
307 Type GetType() const { return ANY_TYPE; }
308};
309
310
311/// Base abstract class for first order time dependent operators.
312/** Operator of the form: (u,t) -> k(u,t), where k generally solves the
313 algebraic equation F(u,k,t) = G(u,t). The functions F and G represent the
314 _implicit_ and _explicit_ parts of the operator, respectively.
315
316 A common use for this class is representing a differential algebraic
317 equation of the form $ F(y,\frac{dy}{dt},t) = G(y,t) $.
318
319 For example, consider an ordinary differential equation of the form
320 $ M \frac{dy}{dt} = g(y,t) $. There are various ways of expressing this ODE
321 as a TimeDependentOperator depending on the choices for F and G. Here are
322 some common choices:
323
324 1. F(u,k,t) = k and G(u,t) = inv(M) g(u,t),
325 2. F(u,k,t) = M k and G(u,t) = g(u,t),
326 3. F(u,k,t) = M k - g(u,t) and G(u,t) = 0.
327
328 Note that depending on the ODE solver, some of the above choices may be
329 preferable to the others.
330*/
332{
333public:
334 /// Enum used to describe the form of the time-dependent operator.
335 /** The type should be set by classes derived from TimeDependentOperator to
336 describe the form, in terms of the functions F and G, used by the
337 specific derived class. This information can be queried by classes or
338 functions (like time stepping algorithms) to make choices about the
339 algorithm to use, or to ensure that the TimeDependentOperator uses the
340 form expected by the class/function.
341
342 For example, assume that a derived class is implementing the ODE
343 $M \frac{dy}{dt} = g(y,t)$ and chooses to define $F(u,k,t) = M k$ and
344 $G(u,t) = g(u,t)$. Then it cannot use type EXPLICIT, unless $M = I$, or
345 type HOMOGENEOUS, unless $g(u,t) = 0$. If, on the other hand, the derived
346 class chooses to define $F(u,k,t) = k$ and $G(u,t) = M^{-1} g(y,t)$, then
347 the natural choice is to set the type to EXPLICIT, even though setting it
348 to IMPLICIT is also not wrong -- doing so will simply fail to inform
349 methods that query this information that it uses a more specific
350 implementation, EXPLICIT, that may allow the use of algorithms that
351 support only the EXPLICIT type. */
352 enum Type
353 {
354 EXPLICIT, ///< This type assumes F(u,k,t) = k.
355 IMPLICIT, ///< This is the most general type, no assumptions on F and G.
356 HOMOGENEOUS ///< This type assumes that G(u,t) = 0.
357 };
358
359 /// Evaluation mode. See SetEvalMode() for details.
361 {
362 /** Normal evaluation. */
364 /** Assuming additive split, k(u,t) = k1(u,t) + k2(u,t), evaluate the
365 first term, k1. */
367 /** Assuming additive split, k(u,t) = k1(u,t) + k2(u,t), evaluate the
368 second term, k2. */
370 };
371
372protected:
373 real_t t; ///< Current time.
374 Type type; /**< @brief Describes the form of the TimeDependentOperator, see
375 the documentation of #Type. */
376 EvalMode eval_mode; ///< Current evaluation mode.
377
378public:
379 /** @brief Construct a "square" TimeDependentOperator (u,t) -> k(u,t), where
380 u and k have the same dimension @a n. */
381 explicit TimeDependentOperator(int n = 0, real_t t_ = 0.0,
382 Type type_ = EXPLICIT)
383 : Operator(n) { t = t_; type = type_; eval_mode = NORMAL; }
384
385 /** @brief Construct a TimeDependentOperator (u,t) -> k(u,t), where u and k
386 have dimensions @a w and @a h, respectively. */
387 TimeDependentOperator(int h, int w, double t_ = 0.0, Type type_ = EXPLICIT)
388 : Operator(h, w) { t = t_; type = type_; eval_mode = NORMAL; }
389
390 /// Read the currently set time.
391 virtual real_t GetTime() const { return t; }
392
393 /// Set the current time.
394 virtual void SetTime(const real_t t_) { t = t_; }
395
396 /// True if #type is #EXPLICIT.
397 bool isExplicit() const { return (type == EXPLICIT); }
398 /// True if #type is #IMPLICIT or #HOMOGENEOUS.
399 bool isImplicit() const { return !isExplicit(); }
400 /// True if #type is #HOMOGENEOUS.
401 bool isHomogeneous() const { return (type == HOMOGENEOUS); }
402
403 /// Return the current evaluation mode. See SetEvalMode() for details.
404 EvalMode GetEvalMode() const { return eval_mode; }
405
406 /// Set the evaluation mode of the time-dependent operator.
407 /** The evaluation mode is a switch that allows time-stepping methods to
408 request evaluation of separate components/terms of the time-dependent
409 operator. For example, IMEX methods typically assume additive split of
410 the operator: k(u,t) = k1(u,t) + k2(u,t) and they rely on the ability to
411 evaluate the two terms separately.
412
413 Generally, setting the evaluation mode should affect the behavior of all
414 evaluation-related methods in the class, such as Mult(), ImplicitSolve(),
415 etc. However, the exact list of methods that need to support a specific
416 mode will depend on the used time-stepping method. */
417 virtual void SetEvalMode(const EvalMode new_eval_mode)
418 { eval_mode = new_eval_mode; }
419
420 /** @brief Perform the action of the explicit part of the operator, G:
421 @a v = G(@a u, t) where t is the current time.
422
423 Presently, this method is used by some PETSc ODE solvers and the
424 SUNDIALS ARKStep integrator, for more details, see either the PETSc
425 Manual or the ARKode User Guide, respectively. */
426 virtual void ExplicitMult(const Vector &u, Vector &v) const;
427
428 /** @brief Perform the action of the implicit part of the operator, F:
429 @a v = F(@a u, @a k, t) where t is the current time.
430
431 Presently, this method is used by some PETSc ODE solvers, for more
432 details, see the PETSc Manual.*/
433 virtual void ImplicitMult(const Vector &u, const Vector &k, Vector &v) const;
434
435 /** @brief Perform the action of the operator (u,t) -> k(u,t) where t is the
436 current time set by SetTime() and @a k satisfies
437 F(@a u, @a k, t) = G(@a u, t).
438
439 For solving an ordinary differential equation of the form
440 $ M \frac{dy}{dt} = g(y,t) $, recall that F and G can be defined in
441 various ways, e.g.:
442
443 1. F(u,k,t) = k and G(u,t) = inv(M) g(u,t)
444 2. F(u,k,t) = M k and G(u,t) = g(u,t)
445 3. F(u,k,t) = M k - g(u,t) and G(u,t) = 0.
446
447 Regardless of the choice of F and G, this function should always compute
448 @a k = inv(M) g(@a u, t). */
449 void Mult(const Vector &u, Vector &k) const override;
450
451 /** @brief Solve for the unknown @a k, at the current time t, the following
452 equation:
453 F(@a u + @a gamma @a k, @a k, t) = G(@a u + @a gamma @a k, t).
454
455 For solving an ordinary differential equation of the form
456 $ M \frac{dy}{dt} = g(y,t) $, recall that F and G can be defined in
457 various ways, e.g.:
458
459 1. F(u,k,t) = k and G(u,t) = inv(M) g(u,t)
460 2. F(u,k,t) = M k and G(u,t) = g(u,t)
461 3. F(u,k,t) = M k - g(u,t) and G(u,t) = 0
462
463 Regardless of the choice of F and G, this function should solve for @a k
464 in M @a k = g(@a u + @a gamma @a k, t).
465
466 To see how @a k can be useful, consider the backward Euler method defined
467 by $ y(t + \Delta t) = y(t) + \Delta t k_0 $ where
468 $ M k_0 = g \big( y(t) + \Delta t k_0, t + \Delta t \big) $. A backward
469 Euler integrator can use @a k from this function for $k_0$, with the call
470 using @a u set to $ y(t) $, @a gamma set to $ \Delta t$, and time set to
471 $t + \Delta t$. See class BackwardEulerSolver.
472
473 Generalizing further, consider a diagonally implicit Runge-Kutta (DIRK)
474 method defined by
475 $ y(t + \Delta t) = y(t) + \Delta t \sum_{i=1}^s b_i k_i $ where
476 $ M k_i = g \big( y(t) + \Delta t \sum_{j=1}^i a_{ij} k_j,
477 t + c_i \Delta t \big) $.
478 A DIRK integrator can use @a k from this function, with @a u set to
479 $ y(t) + \Delta t \sum_{j=1}^{i-1} a_{ij} k_j $ and @a gamma set to
480 $ a_{ii} \Delta t $, for $ k_i $. For example, see class SDIRK33Solver.
481
482 If not re-implemented, this method simply generates an error. */
483 virtual void ImplicitSolve(const real_t gamma, const Vector &u, Vector &k);
484
485 /** @brief Return an Operator representing (dF/dk @a shift + dF/du) at the
486 given @a u, @a k, and the currently set time.
487
488 Presently, this method is used by some PETSc ODE solvers, for more
489 details, see the PETSc Manual. */
490 virtual Operator& GetImplicitGradient(const Vector &u, const Vector &k,
491 real_t shift) const;
492
493 /** @brief Return an Operator representing dG/du at the given point @a u and
494 the currently set time.
495
496 Presently, this method is used by some PETSc ODE solvers, for more
497 details, see the PETSc Manual. */
498 virtual Operator& GetExplicitGradient(const Vector &u) const;
499
500 /** @brief Setup a linear system as needed by some SUNDIALS ODE solvers to
501 perform a similar action to ImplicitSolve, i.e., solve for k, at the
502 current time t, in F(u + gamma k, k, t) = G(u + gamma k, t).
503
504 The SUNDIALS ODE solvers iteratively solve for k, as knew = kold + dk.
505 The linear system here is for dk, obtained by linearizing the nonlinear
506 system F(u + gamma knew, knew, t) = G(u + gamma knew, t) about dk = 0:
507 F(u + gamma (kold + dk), kold + dk, t) = G(u + gamma (kold + dk), t)
508 => [dF/dk + gamma (dF/du - dG/du)] dk = G - F + O(dk^2)
509 In other words, the linear system to be setup here is A dk = r, where
510 A = [dF/dk + gamma (dF/du - dG/du)] and r = G - F.
511
512 For solving an ordinary differential equation of the form
513 $ M \frac{dy}{dt} = g(y,t) $, recall that F and G can be defined as one
514 of the following:
515
516 1. F(u,k,t) = k and G(u,t) = inv(M) g(u,t)
517 2. F(u,k,t) = M k and G(u,t) = g(u,t)
518 3. F(u,k,t) = M k - g(u,t) and G(u,t) = 0
519
520 This function performs setup to solve $ A dk = r $ where A is either
521
522 1. A(@a y,t) = I - @a gamma inv(M) J(@a y,t)
523 2. A(@a y,t) = M - @a gamma J(@a y,t)
524 3. A(@a y,t) = M - @a gamma J(@a y,t)
525
526 with J = dg/dy (or a reasonable approximation thereof).
527
528 @param[in] y The state at which A(@a y,t) should be evaluated.
529 @param[in] v The value of inv(M) g(y,t) for 1 or g(y,t) for 2 & 3.
530 @param[in] jok Flag indicating if the Jacobian should be updated.
531 @param[out] jcur Flag to signal if the Jacobian was updated.
532 @param[in] gamma The scaled time step value.
533
534 If not re-implemented, this method simply generates an error.
535
536 Presently, this method is used by SUNDIALS ODE solvers, for more
537 details, see the SUNDIALS User Guides. */
538 virtual int SUNImplicitSetup(const Vector &y, const Vector &v,
539 int jok, int *jcur, real_t gamma);
540
541 /** @brief Solve the ODE linear system A @a dk = @a r , where A and r are
542 defined by the method SUNImplicitSetup().
543
544 For solving an ordinary differential equation of the form
545 $ M \frac{dy}{dt} = g(y,t) $, recall that F and G can be defined as one
546 of the following:
547
548 1. F(u,k,t) = k and G(u,t) = inv(M) g(u,t)
549 2. F(u,k,t) = M k and G(u,t) = g(u,t)
550 3. F(u,k,t) = M k - g(u,t) and G(u,t) = 0
551
552 @param[in] r inv(M) g(y,t) - k for 1 or g(y,t) - M k for 2 & 3.
553 @param[in,out] dk On input, the initial guess. On output, the solution.
554 @param[in] tol Linear solve tolerance.
555
556 If not re-implemented, this method simply generates an error.
557
558 Presently, this method is used by SUNDIALS ODE solvers, for more
559 details, see the SUNDIALS User Guides. */
560 virtual int SUNImplicitSolve(const Vector &r, Vector &dk, real_t tol);
561
562 /** @brief Setup the mass matrix in the ODE system
563 $ M \frac{dy}{dt} = g(y,t) $ .
564
565 If not re-implemented, this method simply generates an error.
566
567 Presently, this method is used by SUNDIALS ARKStep integrator, for more
568 details, see the ARKode User Guide. */
569 virtual int SUNMassSetup();
570
571 /** @brief Solve the mass matrix linear system M @a x = @a b, where M is
572 defined by the method SUNMassSetup().
573
574 @param[in] b The linear system right-hand side.
575 @param[in,out] x On input, the initial guess. On output, the solution.
576 @param[in] tol Linear solve tolerance.
577
578 If not re-implemented, this method simply generates an error.
579
580 Presently, this method is used by SUNDIALS ARKStep integrator, for more
581 details, see the ARKode User Guide. */
582 virtual int SUNMassSolve(const Vector &b, Vector &x, real_t tol);
583
584 /** @brief Compute the mass matrix-vector product @a v = M @a x, where M is
585 defined by the method SUNMassSetup().
586
587 @param[in] x The vector to multiply.
588 @param[out] v The result of the matrix-vector product.
589
590 If not re-implemented, this method simply generates an error.
591
592 Presently, this method is used by SUNDIALS ARKStep integrator, for more
593 details, see the ARKode User Guide. */
594 virtual int SUNMassMult(const Vector &x, Vector &v);
595
597};
598
599
600/** TimeDependentAdjointOperator is a TimeDependentOperator with Adjoint rate
601 equations to be used with CVODESSolver. */
603{
604public:
605
606 /**
607 \brief The TimedependentAdjointOperator extends the TimeDependentOperator
608 class to use features in SUNDIALS CVODESSolver for computing quadratures
609 and solving adjoint problems.
610
611 To solve adjoint problems one needs to implement the AdjointRateMult
612 method to tell CVODES what the adjoint rate equation is.
613
614 QuadratureIntegration (optional) can be used to compute values over the
615 forward problem
616
617 QuadratureSensitivityMult (optional) can be used to find the sensitivity
618 of the quadrature using the adjoint solution in part.
619
620 SUNImplicitSetupB (optional) can be used to setup custom solvers for the
621 newton solve for the adjoint problem.
622
623 SUNImplicitSolveB (optional) actually uses the solvers from
624 SUNImplicitSetupB to solve the adjoint problem.
625
626 See SUNDIALS user manuals for specifics.
627
628 \param[in] dim Dimension of the forward operator
629 \param[in] adjdim Dimension of the adjoint operator. Typically it is the
630 same size as dim. However, SUNDIALS allows users to specify the size if
631 one wants to perform custom operations.
632 \param[in] t Starting time to set
633 \param[in] type The TimeDependentOperator type
634 */
636 Type type = EXPLICIT) :
638 adjoint_height(adjdim)
639 {}
640
641 /// Destructor
643
644 /**
645 \brief Provide the operator integration of a quadrature equation
646
647 \param[in] y The current value at time t
648 \param[out] qdot The current quadrature rate value at t
649 */
650 virtual void QuadratureIntegration(const Vector &y, Vector &qdot) const {};
651
652 /** @brief Perform the action of the operator:
653 @a yBdot = k = f(@a y,@2 yB, t), where
654
655 @param[in] y The primal solution at time t
656 @param[in] yB The adjoint solution at time t
657 @param[out] yBdot the rate at time t
658 */
659 virtual void AdjointRateMult(const Vector &y, Vector & yB,
660 Vector &yBdot) const = 0;
661
662 /**
663 \brief Provides the sensitivity of the quadrature w.r.t to primal and
664 adjoint solutions
665
666 \param[in] y the value of the primal solution at time t
667 \param[in] yB the value of the adjoint solution at time t
668 \param[out] qBdot the value of the sensitivity of the quadrature rate at
669 time t
670 */
671 virtual void QuadratureSensitivityMult(const Vector &y, const Vector &yB,
672 Vector &qBdot) const {}
673
674 /** @brief Setup the ODE linear system $ A(x,t) = (I - gamma J) $ or
675 $ A = (M - gamma J) $, where $ J(x,t) = \frac{df}{dt(x,t)} $.
676
677 @param[in] t The current time
678 @param[in] x The state at which $A(x,xB,t)$ should be evaluated.
679 @param[in] xB The state at which $A(x,xB,t)$ should be evaluated.
680 @param[in] fxB The current value of the ODE rhs function, $f(x,t)$.
681 @param[in] jokB Flag indicating if the Jacobian should be updated.
682 @param[out] jcurB Flag to signal if the Jacobian was updated.
683 @param[in] gammaB The scaled time step value.
684
685 If not re-implemented, this method simply generates an error.
686
687 Presently, this method is used by SUNDIALS ODE solvers, for more details,
688 see the SUNDIALS User Guides.
689 */
690 virtual int SUNImplicitSetupB(const real_t t, const Vector &x,
691 const Vector &xB, const Vector &fxB,
692 int jokB, int *jcurB, real_t gammaB)
693 {
694 mfem_error("TimeDependentAdjointOperator::SUNImplicitSetupB() is not "
695 "overridden!");
696 return (-1);
697 }
698
699 /** @brief Solve the ODE linear system $ A(x,xB,t) xB = b $ as setup by
700 the method SUNImplicitSetup().
701
702 @param[in] b The linear system right-hand side.
703 @param[in,out] x On input, the initial guess. On output, the solution.
704 @param[in] tol Linear solve tolerance.
705
706 If not re-implemented, this method simply generates an error.
707
708 Presently, this method is used by SUNDIALS ODE solvers, for more details,
709 see the SUNDIALS User Guides. */
710 virtual int SUNImplicitSolveB(Vector &x, const Vector &b, real_t tol)
711 {
712 mfem_error("TimeDependentAdjointOperator::SUNImplicitSolveB() is not "
713 "overridden!");
714 return (-1);
715 }
716
717 /// Returns the size of the adjoint problem state space
719
720protected:
721 int adjoint_height; /// Size of the adjoint problem
722};
723
724
725/// Base abstract class for second order time dependent operators.
726/** Operator of the form: (x,dxdt,t) -> f(x,dxdt,t), where k = f(x,dxdt,t)
727 generally solves the algebraic equation F(x,dxdt,k,t) = G(x,dxdt,t).
728 The functions F and G represent the_implicit_ and _explicit_ parts of
729 the operator, respectively. For explicit operators,
730 F(x,dxdt,k,t) = k, so f(x,dxdt,t) = G(x,dxdt,t). */
732{
733public:
734 /** @brief Construct a "square" SecondOrderTimeDependentOperator
735 y = f(x,dxdt,t), where x, dxdt and y have the same dimension @a n. */
736 explicit SecondOrderTimeDependentOperator(int n = 0, real_t t_ = 0.0,
737 Type type_ = EXPLICIT)
738 : TimeDependentOperator(n, t_,type_) { }
739
740 /** @brief Construct a SecondOrderTimeDependentOperator y = f(x,dxdt,t),
741 where x, dxdt and y have the same dimension @a n. */
743 Type type_ = EXPLICIT)
744 : TimeDependentOperator(h, w, t_,type_) { }
745
747
748 /** @brief Perform the action of the operator: @a y = k = f(@a x,@ dxdt, t),
749 where k solves the algebraic equation
750 F(@a x,@ dxdt, k, t) = G(@a x,@ dxdt, t) and t is the current time. */
751 virtual void Mult(const Vector &x, const Vector &dxdt, Vector &y) const;
752
754 /** @brief Solve the equation:
755 @a k = f(@a x + @a fac0 @a k, @a dxdt + @a fac1 @a k, t), for the
756 unknown @a k at the current time t.
757
758 For general F and G, the equation for @a k becomes:
759 F(@a x + @a fac0 @a k, @a dxdt + @a fac1 @a k, t)
760 = G(@a x + @a fac0 @a k, @a dxdt + @a fac1 @a k, t).
761
762 The input vectors @a x and @a dxdt corresponds to time index (or cycle) n, while the
763 currently set time, #t, and the result vector @a k correspond to time
764 index n+1.
765
766 This method allows for the abstract implementation of some time
767 integration methods.
768
769 If not re-implemented, this method simply generates an error. */
770 virtual void ImplicitSolve(const real_t fac0, const real_t fac1,
771 const Vector &x, const Vector &dxdt, Vector &k);
772
773
775};
776
777
778/// Base class for solvers
779class Solver : public Operator
780{
781public:
782 /// If true, use the second argument of Mult() as an initial guess.
784
785 /** @brief Initialize a square Solver with size @a s.
786
787 @warning Use a Boolean expression for the second parameter (not an int)
788 to distinguish this call from the general rectangular constructor. */
789 explicit Solver(int s = 0, bool iter_mode = false)
790 : Operator(s) { iterative_mode = iter_mode; }
791
792 /// Initialize a Solver with height @a h and width @a w.
793 Solver(int h, int w, bool iter_mode = false)
794 : Operator(h, w) { iterative_mode = iter_mode; }
795
796 /// Set/update the solver for the given operator.
797 virtual void SetOperator(const Operator &op) = 0;
798};
799
800
801/// Identity Operator I: x -> x.
803{
804public:
805 /// Create an identity operator of size @a n.
806 explicit IdentityOperator(int n) : Operator(n) { }
807
808 /// Operator application
809 void Mult(const Vector &x, Vector &y) const override { y = x; }
810
811 /// Application of the transpose
812 void MultTranspose(const Vector &x, Vector &y) const override { y = x; }
813};
814
815/// Returns true if P is the identity prolongation, i.e. if it is either NULL or
816/// an IdentityOperator.
817inline bool IsIdentityProlongation(const Operator *P)
818{
819 return !P || dynamic_cast<const IdentityOperator*>(P);
820}
821
822/// Scaled Operator B: x -> a A(x).
824{
825private:
826 const Operator &A_;
827 real_t a_;
828
829public:
830 /// Create an operator which is a scalar multiple of A.
831 explicit ScaledOperator(const Operator *A, real_t a)
832 : Operator(A->Height(), A->Width()), A_(*A), a_(a) { }
833
834 /// Operator application
835 void Mult(const Vector &x, Vector &y) const override
836 { A_.Mult(x, y); y *= a_; }
837
838 /// Application of the transpose.
839 void MultTranspose(const Vector &x, Vector &y) const override
840 { A_.MultTranspose(x, y); y *= a_; }
841};
842
843
844/** @brief The transpose of a given operator. Switches the roles of the methods
845 Mult() and MultTranspose(). */
847{
848private:
849 const Operator &A;
850
851public:
852 /// Construct the transpose of a given operator @a *a.
854 : Operator(a->Width(), a->Height()), A(*a) { }
855
856 /// Construct the transpose of a given operator @a a.
858 : Operator(a.Width(), a.Height()), A(a) { }
859
860 /// Operator application. Apply the transpose of the original Operator.
861 void Mult(const Vector &x, Vector &y) const override
862 { A.MultTranspose(x, y); }
863
864 /// Application of the transpose. Apply the original Operator.
865 void MultTranspose(const Vector &x, Vector &y) const override
866 { A.Mult(x, y); }
867};
868
869/// General linear combination operator: x -> a A(x) + b B(x).
870class SumOperator : public Operator
871{
872 const Operator *A, *B;
873 const real_t alpha, beta;
874 bool ownA, ownB;
875 mutable Vector z;
876
877public:
879 const Operator *A, const real_t alpha,
880 const Operator *B, const real_t beta,
881 bool ownA, bool ownB);
882
883 void Mult(const Vector &x, Vector &y) const override
884 { z.SetSize(A->Height()); A->Mult(x, z); B->Mult(x, y); add(alpha, z, beta, y, y); }
885
886 void MultTranspose(const Vector &x, Vector &y) const override
887 { z.SetSize(A->Width()); A->MultTranspose(x, z); B->MultTranspose(x, y); add(alpha, z, beta, y, y); }
888
889 virtual ~SumOperator();
890};
891
892/// General product operator: x -> (A*B)(x) = A(B(x)).
894{
895 const Operator *A, *B;
896 bool ownA, ownB;
897 mutable Vector z;
898
899public:
900 ProductOperator(const Operator *A, const Operator *B, bool ownA, bool ownB);
901
902 void Mult(const Vector &x, Vector &y) const override
903 { B->Mult(x, z); A->Mult(z, y); }
904
905 void MultTranspose(const Vector &x, Vector &y) const override
906 { A->MultTranspose(x, z); B->MultTranspose(z, y); }
907
908 virtual ~ProductOperator();
909};
910
911
912/// The operator x -> R*A*P*x constructed through the actions of R^T, A and P
913class RAPOperator : public Operator
914{
915private:
916 const Operator & Rt;
917 const Operator & A;
918 const Operator & P;
919 mutable Vector Px;
920 mutable Vector APx;
921 MemoryClass mem_class;
922
923public:
924 /// Construct the RAP operator given R^T, A and P.
925 RAPOperator(const Operator &Rt_, const Operator &A_, const Operator &P_);
926
927 MemoryClass GetMemoryClass() const override { return mem_class; }
928
929 /// Operator application.
930 void Mult(const Vector & x, Vector & y) const override
931 { P.Mult(x, Px); A.Mult(Px, APx); Rt.MultTranspose(APx, y); }
932
933 /// Approximate diagonal of the RAP Operator.
934 /** Returns the diagonal of A, as returned by its AssembleDiagonal method,
935 multiplied be P^T.
936
937 When P is the FE space prolongation operator on a mesh without hanging
938 nodes and Rt = P, the returned diagonal is exact, as long as the diagonal
939 of A is also exact. */
940 void AssembleDiagonal(Vector &diag) const override
941 {
942 A.AssembleDiagonal(APx);
943 P.MultTranspose(APx, diag);
944
945 // TODO: For an AMR mesh, a convergent diagonal can be assembled with
946 // |P^T| APx, where |P^T| has entry-wise absolute values of the conforming
947 // prolongation transpose operator. See BilinearForm::AssembleDiagonal.
948 }
949
950 /// Application of the transpose.
951 void MultTranspose(const Vector & x, Vector & y) const override
952 { Rt.Mult(x, APx); A.MultTranspose(APx, Px); P.MultTranspose(Px, y); }
953};
954
955
956/// General triple product operator x -> A*B*C*x, with ownership of the factors.
958{
959 const Operator *A;
960 const Operator *B;
961 const Operator *C;
962 bool ownA, ownB, ownC;
963 mutable Vector t1, t2;
964 MemoryClass mem_class;
965
966public:
967 TripleProductOperator(const Operator *A, const Operator *B,
968 const Operator *C, bool ownA, bool ownB, bool ownC);
969
970 MemoryClass GetMemoryClass() const override { return mem_class; }
971
972 void Mult(const Vector &x, Vector &y) const override
973 { C->Mult(x, t1); B->Mult(t1, t2); A->Mult(t2, y); }
974
975 void MultTranspose(const Vector &x, Vector &y) const override
976 { A->MultTranspose(x, t2); B->MultTranspose(t2, t1); C->MultTranspose(t1, y); }
977
978 virtual ~TripleProductOperator();
979};
980
981
982/** @brief Square Operator for imposing essential boundary conditions using only
983 the action, Mult(), of a given unconstrained Operator.
984
985 Square operator constrained by fixing certain entries in the solution to
986 given "essential boundary condition" values. This class is used by the
987 general, matrix-free system formulation of Operator::FormLinearSystem.
988
989 Do not confuse with ConstrainedSolver, which despite the name has very
990 different functionality. */
992{
993protected:
994 Array<int> constraint_list; ///< List of constrained indices/dofs.
995 Operator *A; ///< The unconstrained Operator.
996 bool own_A; ///< Ownership flag for A.
997 mutable Vector z, w; ///< Auxiliary vectors.
999 DiagonalPolicy diag_policy; ///< Diagonal policy for constrained dofs
1000
1001public:
1002 /** @brief Constructor from a general Operator and a list of essential
1003 indices/dofs.
1004
1005 Specify the unconstrained operator @a *A and a @a list of indices to
1006 constrain, i.e. each entry @a list[i] represents an essential dof. If the
1007 ownership flag @a own_A is true, the operator @a *A will be destroyed
1008 when this object is destroyed. The @a diag_policy determines how the
1009 operator sets entries corresponding to essential dofs. */
1010 ConstrainedOperator(Operator *A, const Array<int> &list, bool own_A = false,
1012
1013 /// Returns the type of memory in which the solution and temporaries are stored.
1014 MemoryClass GetMemoryClass() const override { return mem_class; }
1015
1016 /// Set the diagonal policy for the constrained operator.
1017 void SetDiagonalPolicy(const DiagonalPolicy diag_policy_)
1018 { diag_policy = diag_policy_; }
1019
1020 /// Diagonal of A, modified according to the used DiagonalPolicy.
1021 void AssembleDiagonal(Vector &diag) const override;
1022
1023 /** @brief Eliminate "essential boundary condition" values specified in @a x
1024 from the given right-hand side @a b.
1025
1026 Performs the following steps:
1027
1028 z = A((0,x_b)); b_i -= z_i; b_b = x_b;
1029
1030 where the "_b" subscripts denote the essential (boundary) indices/dofs of
1031 the vectors, and "_i" -- the rest of the entries.
1032
1033 @note This method is consistent with `DiagonalPolicy::DIAG_ONE`. */
1034 void EliminateRHS(const Vector &x, Vector &b) const;
1035
1036 /** @brief Constrained operator action.
1037
1038 Performs the following steps:
1039
1040 z = A((x_i,0)); y_i = z_i; y_b = x_b;
1041
1042 where the "_b" subscripts denote the essential (boundary) indices/dofs of
1043 the vectors, and "_i" -- the rest of the entries. */
1044 void Mult(const Vector &x, Vector &y) const override;
1045
1046 void AddMult(const Vector &x, Vector &y, const real_t a = 1.0) const override;
1047
1048 void MultTranspose(const Vector &x, Vector &y) const override;
1049
1050 /** @brief Implementation of Mult or MultTranspose.
1051 * TODO - Generalize to allow constraining rows and columns differently.
1052 */
1053 void ConstrainedMult(const Vector &x, Vector &y, const bool transpose) const;
1054
1055 /// Destructor: destroys the unconstrained Operator, if owned.
1056 ~ConstrainedOperator() override { if (own_A) { delete A; } }
1057};
1058
1059/** @brief Rectangular Operator for imposing essential boundary conditions on
1060 the input space using only the action, Mult(), of a given unconstrained
1061 Operator.
1062
1063 Rectangular operator constrained by fixing certain entries in the solution
1064 to given "essential boundary condition" values. This class is used by the
1065 general matrix-free formulation of Operator::FormRectangularLinearSystem. */
1067{
1068protected:
1071 bool own_A;
1072 mutable Vector z, w;
1074
1075public:
1076 /** @brief Constructor from a general Operator and a list of essential
1077 indices/dofs.
1078
1079 Specify the unconstrained operator @a *A and two lists of indices to
1080 constrain, i.e. each entry @a trial_list[i] represents an essential trial
1081 dof. If the ownership flag @a own_A is true, the operator @a *A will be
1082 destroyed when this object is destroyed. */
1084 const Array<int> &test_list, bool own_A = false);
1085 /// Returns the type of memory in which the solution and temporaries are stored.
1086 MemoryClass GetMemoryClass() const override { return mem_class; }
1087 /** @brief Eliminate columns corresponding to "essential boundary condition"
1088 values specified in @a x from the given right-hand side @a b.
1089
1090 Performs the following steps:
1091
1092 b -= A((0,x_b));
1093 b_j = 0
1094
1095 where the "_b" subscripts denote the essential (boundary) indices and the
1096 "_j" subscript denotes the essential test indices */
1097 void EliminateRHS(const Vector &x, Vector &b) const;
1098 /** @brief Rectangular-constrained operator action.
1099
1100 Performs the following steps:
1101
1102 y = A((x_i,0));
1103 y_j = 0
1104
1105 where the "_i" subscripts denote all the nonessential (boundary) trial
1106 indices and the "_j" subscript denotes the essential test indices */
1107 void Mult(const Vector &x, Vector &y) const override;
1108 void MultTranspose(const Vector &x, Vector &y) const override;
1109 virtual ~RectangularConstrainedOperator() { if (own_A) { delete A; } }
1110};
1111
1112/** @brief PowerMethod helper class to estimate the largest eigenvalue of an
1113 operator using the iterative power method. */
1115{
1116 Vector v1;
1117#ifdef MFEM_USE_MPI
1118 MPI_Comm comm;
1119#endif
1120
1121public:
1122
1123#ifdef MFEM_USE_MPI
1124 PowerMethod() : comm(MPI_COMM_NULL) {}
1125#else
1127#endif
1128
1129#ifdef MFEM_USE_MPI
1130 PowerMethod(MPI_Comm comm_) : comm(comm_) {}
1131#endif
1132
1133 /// @brief Returns an estimate of the largest eigenvalue of the operator \p opr
1134 /// using the iterative power method.
1135 /** \p v0 is being used as the vector for the iterative process and will contain
1136 the eigenvector corresponding to the largest eigenvalue after convergence.
1137 The maximum number of iterations may set with \p numSteps, the relative
1138 tolerance with \p tolerance and the seed of the random initialization of
1139 \p v0 with \p seed. If \p seed is 0 \p v0 will not be random-initialized. */
1141 int numSteps = 10, real_t tolerance = 1e-8,
1142 int seed = 12345);
1143};
1144
1145}
1146
1147#endif
Square Operator for imposing essential boundary conditions using only the action, Mult(),...
Definition operator.hpp:992
MemoryClass GetMemoryClass() const override
Returns the type of memory in which the solution and temporaries are stored.
Array< int > constraint_list
List of constrained indices/dofs.
Definition operator.hpp:994
void Mult(const Vector &x, Vector &y) const override
Constrained operator action.
Definition operator.cpp:648
Operator * A
The unconstrained Operator.
Definition operator.hpp:995
void EliminateRHS(const Vector &x, Vector &b) const
Eliminate "essential boundary condition" values specified in x from the given right-hand side b.
Definition operator.cpp:559
ConstrainedOperator(Operator *A, const Array< int > &list, bool own_A=false, DiagonalPolicy diag_policy=DIAG_ONE)
Constructor from a general Operator and a list of essential indices/dofs.
Definition operator.cpp:511
void AddMult(const Vector &x, Vector &y, const real_t a=1.0) const override
Operator application: y+=A(x) (default) or y+=a*A(x).
Definition operator.cpp:660
void AssembleDiagonal(Vector &diag) const override
Diagonal of A, modified according to the used DiagonalPolicy.
Definition operator.cpp:528
DiagonalPolicy diag_policy
Diagonal policy for constrained dofs.
Definition operator.hpp:999
void ConstrainedMult(const Vector &x, Vector &y, const bool transpose) const
Implementation of Mult or MultTranspose. TODO - Generalize to allow constraining rows and columns dif...
Definition operator.cpp:586
Vector w
Auxiliary vectors.
Definition operator.hpp:997
bool own_A
Ownership flag for A.
Definition operator.hpp:996
~ConstrainedOperator() override
Destructor: destroys the unconstrained Operator, if owned.
void SetDiagonalPolicy(const DiagonalPolicy diag_policy_)
Set the diagonal policy for the constrained operator.
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 ...
Definition operator.cpp:654
Identity Operator I: x -> x.
Definition operator.hpp:803
void MultTranspose(const Vector &x, Vector &y) const override
Application of the transpose.
Definition operator.hpp:812
void Mult(const Vector &x, Vector &y) const override
Operator application.
Definition operator.hpp:809
IdentityOperator(int n)
Create an identity operator of size n.
Definition operator.hpp:806
Abstract operator.
Definition operator.hpp:25
void FormRectangularLinearSystem(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B)
Form a column-constrained linear system using a matrix-free approach.
Definition operator.cpp:131
virtual MemoryClass GetMemoryClass() const
Return the MemoryClass preferred by the Operator.
Definition operator.hpp:86
void FormConstrainedSystemOperator(const Array< int > &ess_tdof_list, ConstrainedOperator *&Aout)
see FormSystemOperator()
Definition operator.cpp:197
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B, int copy_interior=0)
Form a constrained linear system using a matrix-free approach.
Definition operator.cpp:114
int width
Dimension of the input / number of columns in the matrix.
Definition operator.hpp:28
void FormSystemOperator(const Array< int > &ess_tdof_list, Operator *&A)
Return in A a parallel (on truedofs) version of this square operator.
Definition operator.cpp:227
void FormDiscreteOperator(Operator *&A)
Return in A a parallel (on truedofs) version of this rectangular operator.
Definition operator.cpp:244
virtual void ArrayMultTranspose(const Array< const Vector * > &X, Array< Vector * > &Y) const
Action of the transpose operator on a matrix: Y=A^t(X).
Definition operator.cpp:78
Operator(int s=0)
Construct a square Operator with given size s (default 0).
Definition operator.hpp:59
virtual const Operator * GetOutputRestrictionTranspose() const
Transpose of GetOutputRestriction, directly available in this form to facilitate matrix-free RAP-type...
Definition operator.hpp:156
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition operator.hpp:66
int height
Dimension of the output / number of rows in the matrix.
Definition operator.hpp:27
virtual void ArrayAddMult(const Array< const Vector * > &X, Array< Vector * > &Y, const real_t a=1.0) const
Operator application on a matrix: Y+=A(X) (default) or Y+=a*A(X).
Definition operator.cpp:90
virtual const Operator * GetRestriction() const
Restriction operator from input vectors for the operator to linear algebra (linear system) vectors....
Definition operator.hpp:143
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
int NumCols() const
Get the number of columns (size of input) of the Operator. Synonym with Width().
Definition operator.hpp:75
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
Definition operator.hpp:48
@ DIAG_ONE
Set the diagonal value to one.
Definition operator.hpp:50
@ DIAG_KEEP
Keep the diagonal value.
Definition operator.hpp:51
@ DIAG_ZERO
Set the diagonal value to zero.
Definition operator.hpp:49
virtual const Operator * GetOutputRestriction() const
Restriction operator from output vectors for the operator to linear algebra (linear system) vectors....
Definition operator.hpp:160
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
Definition operator.hpp:72
virtual const Operator * GetOutputProlongation() const
Prolongation operator from linear algebra (linear system) vectors, to output vectors for the operator...
Definition operator.hpp:147
virtual void ArrayAddMultTranspose(const Array< const Vector * > &X, Array< Vector * > &Y, const real_t a=1.0) const
Operator transpose application on a matrix: Y+=A^t(X) (default) or Y+=a*A^t(X).
Definition operator.cpp:102
virtual void ArrayMult(const Array< const Vector * > &X, Array< Vector * > &Y) const
Operator application on a matrix: Y=A(X).
Definition operator.cpp:66
virtual const Operator * GetProlongation() const
Prolongation operator from linear algebra (linear system) vectors, to input vectors for the operator....
Definition operator.hpp:139
virtual ~Operator()
Virtual destructor.
Definition operator.hpp:279
Type
Enumeration defining IDs for some classes derived from Operator.
Definition operator.hpp:284
@ ANY_TYPE
ID for the base class Operator, i.e. any type.
Definition operator.hpp:285
@ MFEM_SPARSEMAT
ID for class SparseMatrix.
Definition operator.hpp:286
@ PETSC_MATIS
ID for class PetscParMatrix, MATIS format.
Definition operator.hpp:289
@ MFEM_ComplexSparseMat
ID for class ComplexSparseMatrix.
Definition operator.hpp:295
@ Hypre_ParCSR
ID for class HypreParMatrix.
Definition operator.hpp:287
@ PETSC_MATHYPRE
ID for class PetscParMatrix, MATHYPRE format.
Definition operator.hpp:292
@ Complex_Operator
ID for class ComplexOperator.
Definition operator.hpp:294
@ PETSC_MATGENERIC
ID for class PetscParMatrix, unspecified format.
Definition operator.hpp:293
@ MFEM_Block_Matrix
ID for class BlockMatrix.
Definition operator.hpp:298
@ MFEM_Block_Operator
ID for the base class BlockOperator.
Definition operator.hpp:299
@ Complex_Hypre_ParCSR
ID for class ComplexHypreParMatrix.
Definition operator.hpp:296
@ PETSC_MATAIJ
ID for class PetscParMatrix, MATAIJ format.
Definition operator.hpp:288
@ PETSC_MATNEST
ID for class PetscParMatrix, MATNEST format.
Definition operator.hpp:291
@ Complex_DenseMat
ID for class ComplexDenseMatrix.
Definition operator.hpp:297
@ PETSC_MATSHELL
ID for class PetscParMatrix, MATSHELL format.
Definition operator.hpp:290
void FormRectangularSystemOperator(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Operator *&A)
Return in A a parallel (on truedofs) version of this rectangular operator (including constraints).
Definition operator.cpp:235
Operator * SetupRAP(const Operator *Pi, const Operator *Po)
Returns RAP Operator of this, using input/output Prolongation matrices Pi corresponds to "P",...
Definition operator.cpp:168
virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x)
Reconstruct a solution vector x (e.g. a GridFunction) from the solution X of a constrained linear sys...
Definition operator.cpp:148
Type GetType() const
Return the type ID of the Operator class.
Definition operator.hpp:307
virtual void AssembleDiagonal(Vector &diag) const
Computes the diagonal entries into diag. Typically, this operation only makes sense for linear Operat...
Definition operator.hpp:131
void InitTVectors(const Operator *Po, const Operator *Ri, const Operator *Pi, Vector &x, Vector &b, Vector &X, Vector &B) const
Initializes memory for true vectors of linear system.
Definition operator.cpp:22
int NumRows() const
Get the number of rows (size of output) of the Operator. Synonym with Height().
Definition operator.hpp:69
virtual void AddMultTranspose(const Vector &x, Vector &y, const real_t a=1.0) const
Operator transpose application: y+=A^t(x) (default) or y+=a*A^t(x).
Definition operator.cpp:58
void FormRectangularConstrainedSystemOperator(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, RectangularConstrainedOperator *&Aout)
see FormRectangularSystemOperator()
Definition operator.cpp:210
Operator(int h, int w)
Construct an Operator with the given height (output size) and width (input size).
Definition operator.hpp:63
virtual 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 ...
Definition operator.hpp:93
virtual Operator & GetGradient(const Vector &x) const
Evaluate the gradient operator at the point x. The default behavior in class Operator is to generate ...
Definition operator.hpp:122
void PrintMatlab(std::ostream &out, int n, int m=0) const
Prints operator with input size n and output size m in Matlab format.
Definition operator.cpp:251
virtual void AddMult(const Vector &x, Vector &y, const real_t a=1.0) const
Operator application: y+=A(x) (default) or y+=a*A(x).
Definition operator.cpp:51
PowerMethod helper class to estimate the largest eigenvalue of an operator using the iterative power ...
real_t EstimateLargestEigenvalue(Operator &opr, Vector &v0, int numSteps=10, real_t tolerance=1e-8, int seed=12345)
Returns an estimate of the largest eigenvalue of the operator opr using the iterative power method.
Definition operator.cpp:781
PowerMethod(MPI_Comm comm_)
General product operator: x -> (A*B)(x) = A(B(x)).
Definition operator.hpp:894
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 ...
Definition operator.hpp:905
ProductOperator(const Operator *A, const Operator *B, bool ownA, bool ownB)
Definition operator.cpp:407
void Mult(const Vector &x, Vector &y) const override
Operator application: y=A(x).
Definition operator.hpp:902
virtual ~ProductOperator()
Definition operator.cpp:426
The operator x -> R*A*P*x constructed through the actions of R^T, A and P.
Definition operator.hpp:914
void Mult(const Vector &x, Vector &y) const override
Operator application.
Definition operator.hpp:930
void AssembleDiagonal(Vector &diag) const override
Approximate diagonal of the RAP Operator.
Definition operator.hpp:940
RAPOperator(const Operator &Rt_, const Operator &A_, const Operator &P_)
Construct the RAP operator given R^T, A and P.
Definition operator.cpp:433
MemoryClass GetMemoryClass() const override
Return the MemoryClass preferred by the Operator.
Definition operator.hpp:927
void MultTranspose(const Vector &x, Vector &y) const override
Application of the transpose.
Definition operator.hpp:951
Rectangular Operator for imposing essential boundary conditions on the input space using only the act...
MemoryClass GetMemoryClass() const override
Returns the type of memory in which the solution and temporaries are stored.
RectangularConstrainedOperator(Operator *A, const Array< int > &trial_list, const Array< int > &test_list, bool own_A=false)
Constructor from a general Operator and a list of essential indices/dofs.
Definition operator.cpp:667
void EliminateRHS(const Vector &x, Vector &b) const
Eliminate columns corresponding to "essential boundary condition" values specified in x from the give...
Definition operator.cpp:686
void Mult(const Vector &x, Vector &y) const override
Rectangular-constrained operator action.
Definition operator.cpp:712
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 ...
Definition operator.cpp:746
Scaled Operator B: x -> a A(x).
Definition operator.hpp:824
ScaledOperator(const Operator *A, real_t a)
Create an operator which is a scalar multiple of A.
Definition operator.hpp:831
void MultTranspose(const Vector &x, Vector &y) const override
Application of the transpose.
Definition operator.hpp:839
void Mult(const Vector &x, Vector &y) const override
Operator application.
Definition operator.hpp:835
Base abstract class for second order time dependent operators.
Definition operator.hpp:732
virtual void Mult(const Vector &x, const Vector &dxdt, Vector &y) const
Perform the action of the operator: y = k = f(x,@ dxdt, t), where k solves the algebraic equation F(x...
Definition operator.cpp:352
virtual void ImplicitSolve(const real_t fac0, const real_t fac1, const Vector &x, const Vector &dxdt, Vector &k)
Solve the equation: k = f(x + fac0 k, dxdt + fac1 k, t), for the unknown k at the current time t.
Definition operator.cpp:359
SecondOrderTimeDependentOperator(int h, int w, real_t t_=0.0, Type type_=EXPLICIT)
Construct a SecondOrderTimeDependentOperator y = f(x,dxdt,t), where x, dxdt and y have the same dimen...
Definition operator.hpp:742
SecondOrderTimeDependentOperator(int n=0, real_t t_=0.0, Type type_=EXPLICIT)
Construct a "square" SecondOrderTimeDependentOperator y = f(x,dxdt,t), where x, dxdt and y have the s...
Definition operator.hpp:736
Base class for solvers.
Definition operator.hpp:780
Solver(int h, int w, bool iter_mode=false)
Initialize a Solver with height h and width w.
Definition operator.hpp:793
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
Definition operator.hpp:783
virtual void SetOperator(const Operator &op)=0
Set/update the solver for the given operator.
Solver(int s=0, bool iter_mode=false)
Initialize a square Solver with size s.
Definition operator.hpp:789
General linear combination operator: x -> a A(x) + b B(x).
Definition operator.hpp:871
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 ...
Definition operator.hpp:886
void Mult(const Vector &x, Vector &y) const override
Operator application: y=A(x).
Definition operator.hpp:883
virtual ~SumOperator()
Definition operator.cpp:401
SumOperator(const Operator *A, const real_t alpha, const Operator *B, const real_t beta, bool ownA, bool ownB)
Definition operator.cpp:368
virtual int SUNImplicitSolveB(Vector &x, const Vector &b, real_t tol)
Solve the ODE linear system as setup by the method SUNImplicitSetup().
Definition operator.hpp:710
virtual int SUNImplicitSetupB(const real_t t, const Vector &x, const Vector &xB, const Vector &fxB, int jokB, int *jcurB, real_t gammaB)
Setup the ODE linear system or , where .
Definition operator.hpp:690
virtual void AdjointRateMult(const Vector &y, Vector &yB, Vector &yBdot) const =0
Perform the action of the operator: yBdot = k = f(y,@2 yB, t), where.
virtual void QuadratureSensitivityMult(const Vector &y, const Vector &yB, Vector &qBdot) const
Provides the sensitivity of the quadrature w.r.t to primal and adjoint solutions.
Definition operator.hpp:671
virtual void QuadratureIntegration(const Vector &y, Vector &qdot) const
Provide the operator integration of a quadrature equation.
Definition operator.hpp:650
virtual ~TimeDependentAdjointOperator()
Destructor.
Definition operator.hpp:642
TimeDependentAdjointOperator(int dim, int adjdim, real_t t=0., Type type=EXPLICIT)
The TimedependentAdjointOperator extends the TimeDependentOperator class to use features in SUNDIALS ...
Definition operator.hpp:635
int GetAdjointHeight()
Returns the size of the adjoint problem state space.
Definition operator.hpp:718
Base abstract class for first order time dependent operators.
Definition operator.hpp:332
bool isHomogeneous() const
True if type is HOMOGENEOUS.
Definition operator.hpp:401
EvalMode
Evaluation mode. See SetEvalMode() for details.
Definition operator.hpp:361
bool isExplicit() const
True if type is EXPLICIT.
Definition operator.hpp:397
EvalMode eval_mode
Current evaluation mode.
Definition operator.hpp:376
virtual void ImplicitSolve(const real_t gamma, const Vector &u, Vector &k)
Solve for the unknown k, at the current time t, the following equation: F(u + gamma k,...
Definition operator.cpp:298
virtual int SUNImplicitSolve(const Vector &r, Vector &dk, real_t tol)
Solve the ODE linear system A dk = r , where A and r are defined by the method SUNImplicitSetup().
Definition operator.cpp:327
TimeDependentOperator(int h, int w, double t_=0.0, Type type_=EXPLICIT)
Construct a TimeDependentOperator (u,t) -> k(u,t), where u and k have dimensions w and h,...
Definition operator.hpp:387
virtual int SUNMassMult(const Vector &x, Vector &v)
Compute the mass matrix-vector product v = M x, where M is defined by the method SUNMassSetup().
Definition operator.cpp:345
Type
Enum used to describe the form of the time-dependent operator.
Definition operator.hpp:353
@ HOMOGENEOUS
This type assumes that G(u,t) = 0.
Definition operator.hpp:356
@ EXPLICIT
This type assumes F(u,k,t) = k.
Definition operator.hpp:354
@ IMPLICIT
This is the most general type, no assumptions on F and G.
Definition operator.hpp:355
virtual Operator & GetExplicitGradient(const Vector &u) const
Return an Operator representing dG/du at the given point u and the currently set time.
Definition operator.cpp:312
bool isImplicit() const
True if type is IMPLICIT or HOMOGENEOUS.
Definition operator.hpp:399
virtual int SUNMassSetup()
Setup the mass matrix in the ODE system .
Definition operator.cpp:333
TimeDependentOperator(int n=0, real_t t_=0.0, Type type_=EXPLICIT)
Construct a "square" TimeDependentOperator (u,t) -> k(u,t), where u and k have the same dimension n.
Definition operator.hpp:381
real_t t
Current time.
Definition operator.hpp:373
void Mult(const Vector &u, Vector &k) const override
Perform the action of the operator (u,t) -> k(u,t) where t is the current time set by SetTime() and k...
Definition operator.cpp:293
virtual int SUNMassSolve(const Vector &b, Vector &x, real_t tol)
Solve the mass matrix linear system M x = b, where M is defined by the method SUNMassSetup().
Definition operator.cpp:339
virtual void ExplicitMult(const Vector &u, Vector &v) const
Perform the action of the explicit part of the operator, G: v = G(u, t) where t is the current time.
Definition operator.cpp:282
virtual Operator & GetImplicitGradient(const Vector &u, const Vector &k, real_t shift) const
Return an Operator representing (dF/dk shift + dF/du) at the given u, k, and the currently set time.
Definition operator.cpp:304
virtual void SetEvalMode(const EvalMode new_eval_mode)
Set the evaluation mode of the time-dependent operator.
Definition operator.hpp:417
virtual void SetTime(const real_t t_)
Set the current time.
Definition operator.hpp:394
EvalMode GetEvalMode() const
Return the current evaluation mode. See SetEvalMode() for details.
Definition operator.hpp:404
virtual void ImplicitMult(const Vector &u, const Vector &k, Vector &v) const
Perform the action of the implicit part of the operator, F: v = F(u, k, t) where t is the current tim...
Definition operator.cpp:287
Type type
Describes the form of the TimeDependentOperator, see the documentation of Type.
Definition operator.hpp:374
virtual int SUNImplicitSetup(const Vector &y, const Vector &v, int jok, int *jcur, real_t gamma)
Setup a linear system as needed by some SUNDIALS ODE solvers to perform a similar action to ImplicitS...
Definition operator.cpp:319
virtual real_t GetTime() const
Read the currently set time.
Definition operator.hpp:391
The transpose of a given operator. Switches the roles of the methods Mult() and MultTranspose().
Definition operator.hpp:847
void MultTranspose(const Vector &x, Vector &y) const override
Application of the transpose. Apply the original Operator.
Definition operator.hpp:865
void Mult(const Vector &x, Vector &y) const override
Operator application. Apply the transpose of the original Operator.
Definition operator.hpp:861
TransposeOperator(const Operator *a)
Construct the transpose of a given operator *a.
Definition operator.hpp:853
TransposeOperator(const Operator &a)
Construct the transpose of a given operator a.
Definition operator.hpp:857
General triple product operator x -> A*B*C*x, with ownership of the factors.
Definition operator.hpp:958
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 ...
Definition operator.hpp:975
TripleProductOperator(const Operator *A, const Operator *B, const Operator *C, bool ownA, bool ownB, bool ownC)
Definition operator.cpp:467
void Mult(const Vector &x, Vector &y) const override
Operator application: y=A(x).
Definition operator.hpp:972
MemoryClass GetMemoryClass() const override
Return the MemoryClass preferred by the Operator.
Definition operator.hpp:970
Vector data type.
Definition vector.hpp:82
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:558
Vector beta
const real_t alpha
Definition ex15.cpp:369
int dim
Definition ex24.cpp:53
real_t b
Definition lissajous.cpp:42
real_t a
Definition lissajous.cpp:41
real_t u(const Vector &xvec)
Definition lor_mms.hpp:22
void mfem_error(const char *msg)
Definition error.cpp:154
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition globals.hpp:66
void add(const Vector &v1, const Vector &v2, Vector &v)
Definition vector.cpp:391
MemoryClass
Memory classes identify sets of memory types.
bool IsIdentityProlongation(const Operator *P)
Definition operator.hpp:817
float real_t
Definition config.hpp:43