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