MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
operator.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, 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 
17 namespace mfem
18 {
19 
20 class ConstrainedOperator;
21 class RectangularConstrainedOperator;
22 
23 /// Abstract operator
24 class Operator
25 {
26 protected:
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()
32  const Array<int> &ess_tdof_list, ConstrainedOperator* &Aout);
33 
34  /// see FormRectangularSystemOperator()
36  const Array<int> &trial_tdof_list,
37  const Array<int> &test_tdof_list,
39 
40  /// Returns RAP Operator of this, taking in input/output Prolongation matrices
41  Operator *SetupRAP(const Operator *Pi, const Operator *Po);
42 
43 public:
44  /// Defines operator diagonal policy upon elimination of rows and/or columns.
46  {
47  DIAG_ZERO, ///< Set the diagonal value to zero
48  DIAG_ONE, ///< Set the diagonal value to one
49  DIAG_KEEP ///< Keep the diagonal value
50  };
51 
52  /// Initializes memory for true vectors of linear system
53  void InitTVectors(const Operator *Po, const Operator *Ri, const Operator *Pi,
54  Vector &x, Vector &b,
55  Vector &X, Vector &B) const;
56 
57  /// Construct a square Operator with given size s (default 0).
58  explicit Operator(int s = 0) { height = width = s; }
59 
60  /** @brief Construct an Operator with the given height (output size) and
61  width (input size). */
62  Operator(int h, int w) { height = h; width = w; }
63 
64  /// Get the height (size of output) of the Operator. Synonym with NumRows().
65  inline int Height() const { return height; }
66  /** @brief Get the number of rows (size of output) of the Operator. Synonym
67  with Height(). */
68  inline int NumRows() const { return height; }
69 
70  /// Get the width (size of input) of the Operator. Synonym with NumCols().
71  inline int Width() const { return width; }
72  /** @brief Get the number of columns (size of input) of the Operator. Synonym
73  with Width(). */
74  inline int NumCols() const { return width; }
75 
76  /// Return the MemoryClass preferred by the Operator.
77  /** This is the MemoryClass that will be used to access the input and output
78  vectors in the Mult() and MultTranspose() methods.
79 
80  For example, classes using the MFEM_FORALL macro for implementation can
81  return the value returned by Device::GetMemoryClass().
82 
83  The default implementation of this method in class Operator returns
84  MemoryClass::HOST. */
85  virtual MemoryClass GetMemoryClass() const { return MemoryClass::HOST; }
86 
87  /// Operator application: `y=A(x)`.
88  virtual void Mult(const Vector &x, Vector &y) const = 0;
89 
90  /** @brief Action of the transpose operator: `y=A^t(x)`. The default behavior
91  in class Operator is to generate an error. */
92  virtual void MultTranspose(const Vector &x, Vector &y) const
93  { mfem_error("Operator::MultTranspose() is not overloaded!"); }
94 
95  /** @brief Evaluate the gradient operator at the point @a x. The default
96  behavior in class Operator is to generate an error. */
97  virtual Operator &GetGradient(const Vector &x) const
98  {
99  mfem_error("Operator::GetGradient() is not overloaded!");
100  return const_cast<Operator &>(*this);
101  }
102 
103  /** @brief Prolongation operator from linear algebra (linear system) vectors,
104  to input vectors for the operator. `NULL` means identity. */
105  virtual const Operator *GetProlongation() const { return NULL; }
106  /** @brief Restriction operator from input vectors for the operator to linear
107  algebra (linear system) vectors. `NULL` means identity. */
108  virtual const Operator *GetRestriction() const { return NULL; }
109  /** @brief Prolongation operator from linear algebra (linear system) vectors,
110  to output vectors for the operator. `NULL` means identity. */
111  virtual const Operator *GetOutputProlongation() const
112  {
113  return GetProlongation(); // Assume square unless specialized
114  }
115  /** @brief Restriction operator from output vectors for the operator to linear
116  algebra (linear system) vectors. `NULL` means identity. */
117  virtual const Operator *GetOutputRestriction() const
118  {
119  return GetRestriction(); // Assume square unless specialized
120  }
121 
122  /** @brief Form a constrained linear system using a matrix-free approach.
123 
124  Assuming square operator, form the operator linear system `A(X)=B`,
125  corresponding to it and the right-hand side @a b, by applying any
126  necessary transformations such as: parallel assembly, conforming
127  constraints for non-conforming AMR and eliminating boundary conditions.
128  @note Static condensation and hybridization are not supported for general
129  operators (cf. the analogous methods BilinearForm::FormLinearSystem() and
130  ParBilinearForm::FormLinearSystem()).
131 
132  The constraints are specified through the prolongation P from
133  GetProlongation(), and restriction R from GetRestriction() methods, which
134  are e.g. available through the (parallel) finite element space of any
135  (parallel) bilinear form operator. We assume that the operator is square,
136  using the same input and output space, so we have: `A(X)=[P^t (*this)
137  P](X)`, `B=P^t(b)`, and `X=R(x)`.
138 
139  The vector @a x must contain the essential boundary condition values.
140  These are eliminated through the ConstrainedOperator class and the vector
141  @a X is initialized by setting its essential entries to the boundary
142  conditions and all other entries to zero (@a copy_interior == 0) or
143  copied from @a x (@a copy_interior != 0).
144 
145  After solving the system `A(X)=B`, the (finite element) solution @a x can
146  be recovered by calling Operator::RecoverFEMSolution() with the same
147  vectors @a X, @a b, and @a x.
148 
149  @note The caller is responsible for destroying the output operator @a A!
150  @note If there are no transformations, @a X simply reuses the data of @a
151  x. */
152  void FormLinearSystem(const Array<int> &ess_tdof_list,
153  Vector &x, Vector &b,
154  Operator* &A, Vector &X, Vector &B,
155  int copy_interior = 0);
156 
157  /** @brief Form a column-constrained linear system using a matrix-free approach.
158 
159  Form the operator linear system `A(X)=B` corresponding to the operator
160  and the right-hand side @a b, by applying any necessary transformations
161  such as: parallel assembly, conforming constraints for non-conforming AMR
162  and eliminating boundary conditions. @note Static condensation and
163  hybridization are not supported for general operators (cf. the method
164  MixedBilinearForm::FormRectangularLinearSystem())
165 
166  The constraints are specified through the input prolongation Pi from
167  GetProlongation(), and output restriction Ro from GetOutputRestriction()
168  methods, which are e.g. available through the (parallel) finite element
169  spaces of any (parallel) mixed bilinear form operator. So we have:
170  `A(X)=[Ro (*this) Pi](X)`, `B=Ro(b)`, and `X=Pi^T(x)`.
171 
172  The vector @a x must contain the essential boundary condition values.
173  The "columns" in this operator corresponding to these values are
174  eliminated through the RectangularConstrainedOperator class.
175 
176  After solving the system `A(X)=B`, the (finite element) solution @a x can
177  be recovered by calling Operator::RecoverFEMSolution() with the same
178  vectors @a X, @a b, and @a x.
179 
180  @note The caller is responsible for destroying the output operator @a A!
181  @note If there are no transformations, @a X simply reuses the data of @a
182  x. */
183  void FormRectangularLinearSystem(const Array<int> &trial_tdof_list,
184  const Array<int> &test_tdof_list,
185  Vector &x, Vector &b,
186  Operator* &A, Vector &X, Vector &B);
187 
188  /** @brief Reconstruct a solution vector @a x (e.g. a GridFunction) from the
189  solution @a X of a constrained linear system obtained from
190  Operator::FormLinearSystem() or Operator::FormRectangularLinearSystem().
191 
192  Call this method after solving a linear system constructed using
193  Operator::FormLinearSystem() to recover the solution as an input vector,
194  @a x, for this Operator (presumably a finite element grid function). This
195  method has identical signature to the analogous method for bilinear
196  forms, though currently @a b is not used in the implementation. */
197  virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x);
198 
199  /** @brief Return in @a A a parallel (on truedofs) version of this square
200  operator.
201 
202  This returns the same operator as FormLinearSystem(), but does without
203  the transformations of the right-hand side and initial guess. */
204  void FormSystemOperator(const Array<int> &ess_tdof_list,
205  Operator* &A);
206 
207  /** @brief Return in @a A a parallel (on truedofs) version of this
208  rectangular operator (including constraints).
209 
210  This returns the same operator as FormRectangularLinearSystem(), but does
211  without the transformations of the right-hand side. */
212  void FormRectangularSystemOperator(const Array<int> &trial_tdof_list,
213  const Array<int> &test_tdof_list,
214  Operator* &A);
215 
216  /** @brief Return in @a A a parallel (on truedofs) version of this
217  rectangular operator.
218 
219  This is similar to FormSystemOperator(), but for dof-to-dof mappings
220  (discrete linear operators), which can also correspond to rectangular
221  matrices. The user should provide specializations of GetProlongation()
222  for the input dofs and GetOutputRestriction() for the output dofs in
223  their Operator implementation that are appropriate for the two spaces the
224  Operator maps between. These are e.g. available through the (parallel)
225  finite element space of any (parallel) bilinear form operator. We have:
226  `A(X)=[Rout (*this) Pin](X)`. */
227  void FormDiscreteOperator(Operator* &A);
228 
229  /// Prints operator with input size n and output size m in Matlab format.
230  void PrintMatlab(std::ostream & out, int n = 0, int m = 0) const;
231 
232  /// Virtual destructor.
233  virtual ~Operator() { }
234 
235  /// Enumeration defining IDs for some classes derived from Operator.
236  /** This enumeration is primarily used with class OperatorHandle. */
237  enum Type
238  {
239  ANY_TYPE, ///< ID for the base class Operator, i.e. any type.
240  MFEM_SPARSEMAT, ///< ID for class SparseMatrix.
241  Hypre_ParCSR, ///< ID for class HypreParMatrix.
242  PETSC_MATAIJ, ///< ID for class PetscParMatrix, MATAIJ format.
243  PETSC_MATIS, ///< ID for class PetscParMatrix, MATIS format.
244  PETSC_MATSHELL, ///< ID for class PetscParMatrix, MATSHELL format.
245  PETSC_MATNEST, ///< ID for class PetscParMatrix, MATNEST format.
246  PETSC_MATHYPRE, ///< ID for class PetscParMatrix, MATHYPRE format.
247  PETSC_MATGENERIC, ///< ID for class PetscParMatrix, unspecified format.
248  Complex_Operator, ///< ID for class ComplexOperator.
249  MFEM_ComplexSparseMat, ///< ID for class ComplexSparseMatrix.
250  Complex_Hypre_ParCSR ///< ID for class ComplexHypreParMatrix.
251  };
252 
253  /// Return the type ID of the Operator class.
254  /** This method is intentionally non-virtual, so that it returns the ID of
255  the specific pointer or reference type used when calling this method. If
256  not overridden by derived classes, they will automatically use the type ID
257  of the base Operator class, ANY_TYPE. */
258  Type GetType() const { return ANY_TYPE; }
259 };
260 
261 
262 /// Base abstract class for first order time dependent operators.
263 /** Operator of the form: (x,t) -> f(x,t), where k = f(x,t) generally solves the
264  algebraic equation F(x,k,t) = G(x,t). The functions F and G represent the
265  _implicit_ and _explicit_ parts of the operator, respectively. For explicit
266  operators, F(x,k,t) = k, so f(x,t) = G(x,t). */
268 {
269 public:
270  enum Type
271  {
272  EXPLICIT, ///< This type assumes F(x,k,t) = k, i.e. k = f(x,t) = G(x,t).
273  IMPLICIT, ///< This is the most general type, no assumptions on F and G.
274  HOMOGENEOUS ///< This type assumes that G(x,t) = 0.
275  };
276 
277  /// Evaluation mode. See SetEvalMode() for details.
278  enum EvalMode
279  {
280  /** Normal evaluation. */
282  /** Assuming additive split, f(x,t) = f1(x,t) + f2(x,t), evaluate the
283  first term, f1. */
285  /** Assuming additive split, f(x,t) = f1(x,t) + f2(x,t), evaluate the
286  second term, f2. */
288  };
289 
290 protected:
291  double t; ///< Current time.
292  Type type; ///< Describes the form of the TimeDependentOperator.
293  EvalMode eval_mode; ///< Current evaluation mode.
294 
295 public:
296  /** @brief Construct a "square" TimeDependentOperator y = f(x,t), where x and
297  y have the same dimension @a n. */
298  explicit TimeDependentOperator(int n = 0, double t_ = 0.0,
299  Type type_ = EXPLICIT)
300  : Operator(n) { t = t_; type = type_; eval_mode = NORMAL; }
301 
302  /** @brief Construct a TimeDependentOperator y = f(x,t), where x and y have
303  dimensions @a w and @a h, respectively. */
304  TimeDependentOperator(int h, int w, double t_ = 0.0, Type type_ = EXPLICIT)
305  : Operator(h, w) { t = t_; type = type_; eval_mode = NORMAL; }
306 
307  /// Read the currently set time.
308  virtual double GetTime() const { return t; }
309 
310  /// Set the current time.
311  virtual void SetTime(const double _t) { t = _t; }
312 
313  /// True if #type is #EXPLICIT.
314  bool isExplicit() const { return (type == EXPLICIT); }
315  /// True if #type is #IMPLICIT or #HOMOGENEOUS.
316  bool isImplicit() const { return !isExplicit(); }
317  /// True if #type is #HOMOGENEOUS.
318  bool isHomogeneous() const { return (type == HOMOGENEOUS); }
319 
320  /// Return the current evaluation mode. See SetEvalMode() for details.
321  EvalMode GetEvalMode() const { return eval_mode; }
322 
323  /// Set the evaluation mode of the time-dependent operator.
324  /** The evaluation mode is a switch that allows time-stepping methods to
325  request evaluation of separate components/terms of the time-dependent
326  operator. For example, IMEX methods typically assume additive split of
327  the operator: f(x,t) = f1(x,t) + f2(x,t) and they rely on the ability to
328  evaluate the two terms separately.
329 
330  Generally, setting the evaluation mode should affect the behavior of all
331  evaluation-related methods in the class, such as Mult(), ImplicitSolve(),
332  etc. However, the exact list of methods that need to support a specific
333  mode will depend on the used time-stepping method. */
334  virtual void SetEvalMode(const EvalMode new_eval_mode)
335  { eval_mode = new_eval_mode; }
336 
337  /** @brief Perform the action of the explicit part of the operator, G:
338  @a y = G(@a x, t) where t is the current time.
339 
340  Presently, this method is used by some PETSc ODE solvers, for more
341  details, see the PETSc Manual. */
342  virtual void ExplicitMult(const Vector &x, Vector &y) const;
343 
344  /** @brief Perform the action of the implicit part of the operator, F:
345  @a y = F(@a x, @a k, t) where t is the current time.
346 
347  Presently, this method is used by some PETSc ODE solvers, for more
348  details, see the PETSc Manual.*/
349  virtual void ImplicitMult(const Vector &x, const Vector &k, Vector &y) const;
350 
351  /** @brief Perform the action of the operator: @a y = k = f(@a x, t), where
352  k solves the algebraic equation F(@a x, k, t) = G(@a x, t) and t is the
353  current time. */
354  virtual void Mult(const Vector &x, Vector &y) const;
355 
356  /** @brief Solve the equation: @a k = f(@a x + @a dt @a k, t), for the
357  unknown @a k at the current time t.
358 
359  For general F and G, the equation for @a k becomes:
360  F(@a x + @a dt @a k, @a k, t) = G(@a x + @a dt @a k, t).
361 
362  The input vector @a x corresponds to time index (or cycle) n, while the
363  currently set time, #t, and the result vector @a k correspond to time
364  index n+1. The time step @a dt corresponds to the time interval between
365  cycles n and n+1.
366 
367  This method allows for the abstract implementation of some time
368  integration methods, including diagonal implicit Runge-Kutta (DIRK)
369  methods and the backward Euler method in particular.
370 
371  If not re-implemented, this method simply generates an error. */
372  virtual void ImplicitSolve(const double dt, const Vector &x, Vector &k);
373 
374  /** @brief Return an Operator representing (dF/dk @a shift + dF/dx) at the
375  given @a x, @a k, and the currently set time.
376 
377  Presently, this method is used by some PETSc ODE solvers, for more
378  details, see the PETSc Manual. */
379  virtual Operator& GetImplicitGradient(const Vector &x, const Vector &k,
380  double shift) const;
381 
382  /** @brief Return an Operator representing dG/dx at the given point @a x and
383  the currently set time.
384 
385  Presently, this method is used by some PETSc ODE solvers, for more
386  details, see the PETSc Manual. */
387  virtual Operator& GetExplicitGradient(const Vector &x) const;
388 
389  /** @brief Setup the ODE linear system \f$ A(x,t) = (I - gamma J) \f$ or
390  \f$ A = (M - gamma J) \f$, where \f$ J(x,t) = \frac{df}{dt(x,t)} \f$.
391 
392  @param[in] x The state at which \f$A(x,t)\f$ should be evaluated.
393  @param[in] fx The current value of the ODE rhs function, \f$f(x,t)\f$.
394  @param[in] jok Flag indicating if the Jacobian should be updated.
395  @param[out] jcur Flag to signal if the Jacobian was updated.
396  @param[in] gamma The scaled time step value.
397 
398  If not re-implemented, this method simply generates an error.
399 
400  Presently, this method is used by SUNDIALS ODE solvers, for more
401  details, see the SUNDIALS User Guides. */
402  virtual int SUNImplicitSetup(const Vector &x, const Vector &fx,
403  int jok, int *jcur, double gamma);
404 
405  /** @brief Solve the ODE linear system \f$ A x = b \f$ as setup by
406  the method SUNImplicitSetup().
407 
408  @param[in] b The linear system right-hand side.
409  @param[in,out] x On input, the initial guess. On output, the solution.
410  @param[in] tol Linear solve tolerance.
411 
412  If not re-implemented, this method simply generates an error.
413 
414  Presently, this method is used by SUNDIALS ODE solvers, for more
415  details, see the SUNDIALS User Guides. */
416  virtual int SUNImplicitSolve(const Vector &b, Vector &x, double tol);
417 
418  /** @brief Setup the mass matrix in the ODE system \f$ M y' = f(y,t) \f$ .
419 
420  If not re-implemented, this method simply generates an error.
421 
422  Presently, this method is used by SUNDIALS ARKStep integrator, for more
423  details, see the ARKode User Guide. */
424  virtual int SUNMassSetup();
425 
426  /** @brief Solve the mass matrix linear system \f$ M x = b \f$
427  as setup by the method SUNMassSetup().
428 
429  @param[in] b The linear system right-hand side.
430  @param[in,out] x On input, the initial guess. On output, the solution.
431  @param[in] tol Linear solve tolerance.
432 
433  If not re-implemented, this method simply generates an error.
434 
435  Presently, this method is used by SUNDIALS ARKStep integrator, for more
436  details, see the ARKode User Guide. */
437  virtual int SUNMassSolve(const Vector &b, Vector &x, double tol);
438 
439  /** @brief Compute the mass matrix-vector product \f$ v = M x \f$ .
440 
441  @param[in] x The vector to multiply.
442  @param[out] v The result of the matrix-vector product.
443 
444  If not re-implemented, this method simply generates an error.
445 
446  Presently, this method is used by SUNDIALS ARKStep integrator, for more
447  details, see the ARKode User Guide. */
448  virtual int SUNMassMult(const Vector &x, Vector &v);
449 
451 };
452 
453 
454 /** TimeDependentAdjointOperator is a TimeDependentOperator with Adjoint rate
455  equations to be used with CVODESSolver. */
457 {
458 public:
459 
460  /**
461  \brief The TimedependentAdjointOperator extends the TimeDependentOperator
462  class to use features in SUNDIALS CVODESSolver for computing quadratures
463  and solving adjoint problems.
464 
465  To solve adjoint problems one needs to implement the AdjointRateMult
466  method to tell CVODES what the adjoint rate equation is.
467 
468  QuadratureIntegration (optional) can be used to compute values over the
469  forward problem
470 
471  QuadratureSensitivityMult (optional) can be used to find the sensitivity
472  of the quadrature using the adjoint solution in part.
473 
474  SUNImplicitSetupB (optional) can be used to setup custom solvers for the
475  newton solve for the adjoint problem.
476 
477  SUNImplicitSolveB (optional) actually uses the solvers from
478  SUNImplicitSetupB to solve the adjoint problem.
479 
480  See SUNDIALS user manuals for specifics.
481 
482  \param[in] dim Dimension of the forward operator
483  \param[in] adjdim Dimension of the adjoint operator. Typically it is the
484  same size as dim. However, SUNDIALS allows users to specify the size if
485  one wants to perform custom operations.
486  \param[in] t Starting time to set
487  \param[in] type The TimeDependentOperator type
488  */
489  TimeDependentAdjointOperator(int dim, int adjdim, double t = 0.,
490  Type type = EXPLICIT) :
492  adjoint_height(adjdim)
493  {}
494 
495  /// Destructor
497 
498  /**
499  \brief Provide the operator integration of a quadrature equation
500 
501  \param[in] y The current value at time t
502  \param[out] qdot The current quadrature rate value at t
503  */
504  virtual void QuadratureIntegration(const Vector &y, Vector &qdot) const {};
505 
506  /** @brief Perform the action of the operator:
507  @a yBdot = k = f(@a y,@2 yB, t), where
508 
509  @param[in] y The primal solution at time t
510  @param[in] yB The adjoint solution at time t
511  @param[out] yBdot the rate at time t
512  */
513  virtual void AdjointRateMult(const Vector &y, Vector & yB,
514  Vector &yBdot) const = 0;
515 
516  /**
517  \brief Provides the sensitivity of the quadrature w.r.t to primal and
518  adjoint solutions
519 
520  \param[in] y the value of the primal solution at time t
521  \param[in] yB the value of the adjoint solution at time t
522  \param[out] qBdot the value of the sensitivity of the quadrature rate at
523  time t
524  */
525  virtual void QuadratureSensitivityMult(const Vector &y, const Vector &yB,
526  Vector &qBdot) const {}
527 
528  /** @brief Setup the ODE linear system \f$ A(x,t) = (I - gamma J) \f$ or
529  \f$ A = (M - gamma J) \f$, where \f$ J(x,t) = \frac{df}{dt(x,t)} \f$.
530 
531  @param[in] t The current time
532  @param[in] x The state at which \f$A(x,xB,t)\f$ should be evaluated.
533  @param[in] xB The state at which \f$A(x,xB,t)\f$ should be evaluated.
534  @param[in] fxB The current value of the ODE rhs function, \f$f(x,t)\f$.
535  @param[in] jokB Flag indicating if the Jacobian should be updated.
536  @param[out] jcurB Flag to signal if the Jacobian was updated.
537  @param[in] gammaB The scaled time step value.
538 
539  If not re-implemented, this method simply generates an error.
540 
541  Presently, this method is used by SUNDIALS ODE solvers, for more details,
542  see the SUNDIALS User Guides.
543  */
544  virtual int SUNImplicitSetupB(const double t, const Vector &x,
545  const Vector &xB, const Vector &fxB,
546  int jokB, int *jcurB, double gammaB)
547  {
548  mfem_error("TimeDependentAdjointOperator::SUNImplicitSetupB() is not "
549  "overridden!");
550  return (-1);
551  }
552 
553  /** @brief Solve the ODE linear system \f$ A(x,xB,t) xB = b \f$ as setup by
554  the method SUNImplicitSetup().
555 
556  @param[in] b The linear system right-hand side.
557  @param[in,out] x On input, the initial guess. On output, the solution.
558  @param[in] tol Linear solve tolerance.
559 
560  If not re-implemented, this method simply generates an error.
561 
562  Presently, this method is used by SUNDIALS ODE solvers, for more details,
563  see the SUNDIALS User Guides. */
564  virtual int SUNImplicitSolveB(Vector &x, const Vector &b, double tol)
565  {
566  mfem_error("TimeDependentAdjointOperator::SUNImplicitSolveB() is not "
567  "overridden!");
568  return (-1);
569  }
570 
571  /// Returns the size of the adjoint problem state space
573 
574 protected:
575  int adjoint_height; /// Size of the adjoint problem
576 };
577 
578 
579 /// Base abstract class for second order time dependent operators.
580 /** Operator of the form: (x,dxdt,t) -> f(x,dxdt,t), where k = f(x,dxdt,t)
581  generally solves the algebraic equation F(x,dxdt,k,t) = G(x,dxdt,t).
582  The functions F and G represent the_implicit_ and _explicit_ parts of
583  the operator, respectively. For explicit operators,
584  F(x,dxdt,k,t) = k, so f(x,dxdt,t) = G(x,dxdt,t). */
586 {
587 public:
588  /** @brief Construct a "square" SecondOrderTimeDependentOperator
589  y = f(x,dxdt,t), where x, dxdt and y have the same dimension @a n. */
590  explicit SecondOrderTimeDependentOperator(int n = 0, double t_ = 0.0,
591  Type type_ = EXPLICIT)
592  : TimeDependentOperator(n, t_,type_) { }
593 
594  /** @brief Construct a SecondOrderTimeDependentOperator y = f(x,dxdt,t),
595  where x, dxdt and y have the same dimension @a n. */
596  SecondOrderTimeDependentOperator(int h, int w, double t_ = 0.0,
597  Type type_ = EXPLICIT)
598  : TimeDependentOperator(h, w, t_,type_) { }
599 
601 
602  /** @brief Perform the action of the operator: @a y = k = f(@a x,@ dxdt, t),
603  where k solves the algebraic equation
604  F(@a x,@ dxdt, k, t) = G(@a x,@ dxdt, t) and t is the current time. */
605  virtual void Mult(const Vector &x, const Vector &dxdt, Vector &y) const;
606 
608  /** @brief Solve the equation:
609  @a k = f(@a x + 1/2 @a dt0^2 @a k, @a dxdt + @a dt1 @a k, t), for the
610  unknown @a k at the current time t.
611 
612  For general F and G, the equation for @a k becomes:
613  F(@a x + 1/2 @a dt0^2 @a k, @a dxdt + @a dt1 @a k, t)
614  = G(@a x + 1/2 @a dt0^2 @a k, @a dxdt + @a dt1 @a k, t).
615 
616  The input vector @a x corresponds to time index (or cycle) n, while the
617  currently set time, #t, and the result vector @a k correspond to time
618  index n+1. The time step @a dt corresponds to the time interval between
619  cycles n and n+1.
620 
621  This method allows for the abstract implementation of some time
622  integration methods.
623 
624  If not re-implemented, this method simply generates an error. */
625  virtual void ImplicitSolve(const double dt0, const double dt1,
626  const Vector &x, const Vector &dxdt, Vector &k);
627 
628 
630 };
631 
632 
633 /// Base class for solvers
634 class Solver : public Operator
635 {
636 public:
637  /// If true, use the second argument of Mult() as an initial guess.
639 
640  /** @brief Initialize a square Solver with size @a s.
641 
642  @warning Use a Boolean expression for the second parameter (not an int)
643  to distinguish this call from the general rectangular constructor. */
644  explicit Solver(int s = 0, bool iter_mode = false)
645  : Operator(s) { iterative_mode = iter_mode; }
646 
647  /// Initialize a Solver with height @a h and width @a w.
648  Solver(int h, int w, bool iter_mode = false)
649  : Operator(h, w) { iterative_mode = iter_mode; }
650 
651  /// Set/update the solver for the given operator.
652  virtual void SetOperator(const Operator &op) = 0;
653 };
654 
655 
656 /// Identity Operator I: x -> x.
658 {
659 public:
660  /// Create an identity operator of size @a n.
661  explicit IdentityOperator(int n) : Operator(n) { }
662 
663  /// Operator application
664  virtual void Mult(const Vector &x, Vector &y) const { y = x; }
665 
666  /// Application of the transpose
667  virtual void MultTranspose(const Vector &x, Vector &y) const { y = x; }
668 };
669 
670 /// Returns true if P is the identity prolongation, i.e. if it is either NULL or
671 /// an IdentityOperator.
672 inline bool IsIdentityProlongation(const Operator *P)
673 {
674  return !P || dynamic_cast<const IdentityOperator*>(P);
675 }
676 
677 /// Scaled Operator B: x -> a A(x).
678 class ScaledOperator : public Operator
679 {
680 private:
681  const Operator &A_;
682  double a_;
683 
684 public:
685  /// Create an operator which is a scalar multiple of A.
686  explicit ScaledOperator(const Operator *A, double a)
687  : Operator(A->Width(), A->Height()), A_(*A), a_(a) { }
688 
689  /// Operator application
690  virtual void Mult(const Vector &x, Vector &y) const
691  { A_.Mult(x, y); y *= a_; }
692 };
693 
694 
695 /** @brief The transpose of a given operator. Switches the roles of the methods
696  Mult() and MultTranspose(). */
698 {
699 private:
700  const Operator &A;
701 
702 public:
703  /// Construct the transpose of a given operator @a *a.
705  : Operator(a->Width(), a->Height()), A(*a) { }
706 
707  /// Construct the transpose of a given operator @a a.
709  : Operator(a.Width(), a.Height()), A(a) { }
710 
711  /// Operator application. Apply the transpose of the original Operator.
712  virtual void Mult(const Vector &x, Vector &y) const
713  { A.MultTranspose(x, y); }
714 
715  /// Application of the transpose. Apply the original Operator.
716  virtual void MultTranspose(const Vector &x, Vector &y) const
717  { A.Mult(x, y); }
718 };
719 
720 
721 /// General product operator: x -> (A*B)(x) = A(B(x)).
722 class ProductOperator : public Operator
723 {
724  const Operator *A, *B;
725  bool ownA, ownB;
726  mutable Vector z;
727 
728 public:
729  ProductOperator(const Operator *A, const Operator *B, bool ownA, bool ownB);
730 
731  virtual void Mult(const Vector &x, Vector &y) const
732  { B->Mult(x, z); A->Mult(z, y); }
733 
734  virtual void MultTranspose(const Vector &x, Vector &y) const
735  { A->MultTranspose(x, z); B->MultTranspose(z, y); }
736 
737  virtual ~ProductOperator();
738 };
739 
740 
741 /// The operator x -> R*A*P*x constructed through the actions of R^T, A and P
742 class RAPOperator : public Operator
743 {
744 private:
745  const Operator & Rt;
746  const Operator & A;
747  const Operator & P;
748  mutable Vector Px;
749  mutable Vector APx;
750  MemoryClass mem_class;
751 
752 public:
753  /// Construct the RAP operator given R^T, A and P.
754  RAPOperator(const Operator &Rt_, const Operator &A_, const Operator &P_);
755 
756  virtual MemoryClass GetMemoryClass() const { return mem_class; }
757 
758  /// Operator application.
759  virtual void Mult(const Vector & x, Vector & y) const
760  { P.Mult(x, Px); A.Mult(Px, APx); Rt.MultTranspose(APx, y); }
761 
762  /// Application of the transpose.
763  virtual void MultTranspose(const Vector & x, Vector & y) const
764  { Rt.Mult(x, APx); A.MultTranspose(APx, Px); P.MultTranspose(Px, y); }
765 };
766 
767 
768 /// General triple product operator x -> A*B*C*x, with ownership of the factors.
770 {
771  const Operator *A;
772  const Operator *B;
773  const Operator *C;
774  bool ownA, ownB, ownC;
775  mutable Vector t1, t2;
776  MemoryClass mem_class;
777 
778 public:
779  TripleProductOperator(const Operator *A, const Operator *B,
780  const Operator *C, bool ownA, bool ownB, bool ownC);
781 
782  virtual MemoryClass GetMemoryClass() const { return mem_class; }
783 
784  virtual void Mult(const Vector &x, Vector &y) const
785  { C->Mult(x, t1); B->Mult(t1, t2); A->Mult(t2, y); }
786 
787  virtual void MultTranspose(const Vector &x, Vector &y) const
788  { A->MultTranspose(x, t2); B->MultTranspose(t2, t1); C->MultTranspose(t1, y); }
789 
790  virtual ~TripleProductOperator();
791 };
792 
793 
794 /** @brief Square Operator for imposing essential boundary conditions using only
795  the action, Mult(), of a given unconstrained Operator.
796 
797  Square operator constrained by fixing certain entries in the solution to
798  given "essential boundary condition" values. This class is used by the
799  general, matrix-free system formulation of Operator::FormLinearSystem. */
801 {
802 protected:
803  Array<int> constraint_list; ///< List of constrained indices/dofs.
804  Operator *A; ///< The unconstrained Operator.
805  bool own_A; ///< Ownership flag for A.
806  mutable Vector z, w; ///< Auxiliary vectors.
808  DiagonalPolicy diag_policy; ///< Diagonal policy for constrained dofs
809 
810 public:
811  /** @brief Constructor from a general Operator and a list of essential
812  indices/dofs.
813 
814  Specify the unconstrained operator @a *A and a @a list of indices to
815  constrain, i.e. each entry @a list[i] represents an essential dof. If the
816  ownership flag @a own_A is true, the operator @a *A will be destroyed
817  when this object is destroyed. The @a diag_policy determines how the
818  operator sets entries corresponding to essential dofs. */
819  ConstrainedOperator(Operator *A, const Array<int> &list, bool own_A = false,
821 
822  /// Returns the type of memory in which the solution and temporaries are stored.
823  virtual MemoryClass GetMemoryClass() const { return mem_class; }
824 
825  /// Set the diagonal policy for the constrained operator.
826  void SetDiagonalPolicy(const DiagonalPolicy _diag_policy)
827  { diag_policy = _diag_policy; }
828 
829  /** @brief Eliminate "essential boundary condition" values specified in @a x
830  from the given right-hand side @a b.
831 
832  Performs the following steps:
833 
834  z = A((0,x_b)); b_i -= z_i; b_b = x_b;
835 
836  where the "_b" subscripts denote the essential (boundary) indices/dofs of
837  the vectors, and "_i" -- the rest of the entries. */
838  void EliminateRHS(const Vector &x, Vector &b) const;
839 
840  /** @brief Constrained operator action.
841 
842  Performs the following steps:
843 
844  z = A((x_i,0)); y_i = z_i; y_b = x_b;
845 
846  where the "_b" subscripts denote the essential (boundary) indices/dofs of
847  the vectors, and "_i" -- the rest of the entries. */
848  virtual void Mult(const Vector &x, Vector &y) const;
849 
850  /// Destructor: destroys the unconstrained Operator, if owned.
851  virtual ~ConstrainedOperator() { if (own_A) { delete A; } }
852 };
853 
854 /** @brief Rectangular Operator for imposing essential boundary conditions on
855  the input space using only the action, Mult(), of a given unconstrained
856  Operator.
857 
858  Rectangular operator constrained by fixing certain entries in the solution
859  to given "essential boundary condition" values. This class is used by the
860  general matrix-free formulation of Operator::FormRectangularLinearSystem. */
862 {
863 protected:
866  bool own_A;
867  mutable Vector z, w;
869 
870 public:
871  /** @brief Constructor from a general Operator and a list of essential
872  indices/dofs.
873 
874  Specify the unconstrained operator @a *A and two lists of indices to
875  constrain, i.e. each entry @a trial_list[i] represents an essential trial
876  dof. If the ownership flag @a own_A is true, the operator @a *A will be
877  destroyed when this object is destroyed. */
879  const Array<int> &test_list, bool own_A = false);
880  /// Returns the type of memory in which the solution and temporaries are stored.
881  virtual MemoryClass GetMemoryClass() const { return mem_class; }
882  /** @brief Eliminate columns corresponding to "essential boundary condition"
883  values specified in @a x from the given right-hand side @a b.
884 
885  Performs the following steps:
886 
887  b -= A((0,x_b));
888  b_j = 0
889 
890  where the "_b" subscripts denote the essential (boundary) indices and the
891  "_j" subscript denotes the essential test indices */
892  void EliminateRHS(const Vector &x, Vector &b) const;
893  /** @brief Rectangular-constrained operator action.
894 
895  Performs the following steps:
896 
897  y = A((x_i,0));
898  y_j = 0
899 
900  where the "_i" subscripts denote all the nonessential (boundary) trial
901  indices and the "_j" subscript denotes the essential test indices */
902  virtual void Mult(const Vector &x, Vector &y) const;
903  virtual void MultTranspose(const Vector &x, Vector &y) const;
904  virtual ~RectangularConstrainedOperator() { if (own_A) { delete A; } }
905 };
906 
907 /** @brief PowerMethod helper class to estimate the largest eigenvalue of an
908  operator using the iterative power method. */
910 {
911  Vector v1;
912 #ifdef MFEM_USE_MPI
913  MPI_Comm comm;
914 #endif
915 
916 public:
917 
918 #ifdef MFEM_USE_MPI
919  PowerMethod() : comm(MPI_COMM_NULL) {}
920 #else
922 #endif
923 
924 #ifdef MFEM_USE_MPI
925  PowerMethod(MPI_Comm _comm) : comm(_comm) {}
926 #endif
927 
928  /// @brief Returns an estimate of the largest eigenvalue of the operator \p opr
929  /// using the iterative power method.
930  /** \p v0 is being used as the vector for the iterative process and will contain
931  the eigenvector corresponding to the largest eigenvalue after convergence.
932  The maximum number of iterations may set with \p numSteps, the relative
933  tolerance with \p tolerance and the seed of the random initialization of
934  \p v0 with \p seed. */
935  double EstimateLargestEigenvalue(Operator& opr, Vector& v0,
936  int numSteps = 10, double tolerance = 1e-8,
937  int seed = 12345);
938 };
939 
940 }
941 
942 #endif
PowerMethod helper class to estimate the largest eigenvalue of an operator using the iterative power ...
Definition: operator.hpp:909
virtual double GetTime() const
Read the currently set time.
Definition: operator.hpp:308
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:284
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:172
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:405
bool isImplicit() const
True if type is IMPLICIT or HOMOGENEOUS.
Definition: operator.hpp:316
bool isHomogeneous() const
True if type is HOMOGENEOUS.
Definition: operator.hpp:318
virtual MemoryClass GetMemoryClass() const
Returns the type of memory in which the solution and temporaries are stored.
Definition: operator.hpp:881
virtual int SUNImplicitSolveB(Vector &x, const Vector &b, double tol)
Solve the ODE linear system as setup by the method SUNImplicitSetup().
Definition: operator.hpp:564
Solver(int s=0, bool iter_mode=false)
Initialize a square Solver with size s.
Definition: operator.hpp:644
virtual ~ProductOperator()
Definition: operator.cpp:320
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:525
Array< int > constraint_list
List of constrained indices/dofs.
Definition: operator.hpp:803
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
Definition: operator.hpp:759
Type type
Describes the form of the TimeDependentOperator.
Definition: operator.hpp:292
Base abstract class for first order time dependent operators.
Definition: operator.hpp:267
virtual void ImplicitSolve(const double dt, const Vector &x, Vector &k)
Solve the equation: k = f(x + dt k, t), for the unknown k at the current time t.
Definition: operator.cpp:230
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:97
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.
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
Definition: operator.hpp:71
ID for class ComplexHypreParMatrix.
Definition: operator.hpp:250
virtual void Mult(const Vector &x, Vector &y) const
Constrained operator action.
Definition: operator.cpp:448
virtual void SetTime(const double _t)
Set the current time.
Definition: operator.hpp:311
virtual Operator & GetExplicitGradient(const Vector &x) const
Return an Operator representing dG/dx at the given point x and the currently set time.
Definition: operator.cpp:244
virtual MemoryClass GetMemoryClass() const
Return the MemoryClass preferred by the Operator.
Definition: operator.hpp:782
void SetDiagonalPolicy(const DiagonalPolicy _diag_policy)
Set the diagonal policy for the constrained operator.
Definition: operator.hpp:826
virtual const Operator * GetOutputProlongation() const
Prolongation operator from linear algebra (linear system) vectors, to output vectors for the operator...
Definition: operator.hpp:111
void EliminateRHS(const Vector &x, Vector &b) const
Eliminate columns corresponding to &quot;essential boundary condition&quot; values specified in x from the give...
Definition: operator.cpp:514
void FormDiscreteOperator(Operator *&A)
Return in A a parallel (on truedofs) version of this rectangular operator.
Definition: operator.cpp:181
virtual void MultTranspose(const Vector &x, Vector &y) const
Application of the transpose.
Definition: operator.hpp:667
EvalMode eval_mode
Current evaluation mode.
Definition: operator.hpp:293
ProductOperator(const Operator *A, const Operator *B, bool ownA, bool ownB)
Definition: operator.cpp:301
ID for class PetscParMatrix, MATHYPRE format.
Definition: operator.hpp:246
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
virtual void MultTranspose(const Vector &x, Vector &y) const
Application of the transpose. Apply the original Operator.
Definition: operator.hpp:716
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
Definition: operator.hpp:638
SecondOrderTimeDependentOperator(int n=0, double t_=0.0, Type type_=EXPLICIT)
Construct a &quot;square&quot; SecondOrderTimeDependentOperator y = f(x,dxdt,t), where x, dxdt and y have the s...
Definition: operator.hpp:590
SecondOrderTimeDependentOperator(int h, int w, double 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:596
virtual MemoryClass GetMemoryClass() const
Returns the type of memory in which the solution and temporaries are stored.
Definition: operator.hpp:823
virtual ~TimeDependentAdjointOperator()
Destructor.
Definition: operator.hpp:496
bool own_A
Ownership flag for A.
Definition: operator.hpp:805
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:92
void FormRectangularConstrainedSystemOperator(const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, RectangularConstrainedOperator *&Aout)
see FormRectangularSystemOperator()
Definition: operator.cpp:147
Solver(int h, int w, bool iter_mode=false)
Initialize a Solver with height h and width w.
Definition: operator.hpp:648
double t
Current time.
Definition: operator.hpp:291
virtual int SUNImplicitSolve(const Vector &b, Vector &x, double tol)
Solve the ODE linear system as setup by the method SUNImplicitSetup().
Definition: operator.cpp:259
virtual void ExplicitMult(const Vector &x, Vector &y) const
Perform the action of the explicit part of the operator, G: y = G(x, t) where t is the current time...
Definition: operator.cpp:214
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:68
virtual void Mult(const Vector &x, Vector &y) const
Operator application. Apply the transpose of the original Operator.
Definition: operator.hpp:712
ID for class SparseMatrix.
Definition: operator.hpp:240
virtual const Operator * GetProlongation() const
Prolongation operator from linear algebra (linear system) vectors, to input vectors for the operator...
Definition: operator.hpp:105
TransposeOperator(const Operator &a)
Construct the transpose of a given operator a.
Definition: operator.hpp:708
virtual void MultTranspose(const Vector &x, Vector &y) const
Application of the transpose.
Definition: operator.hpp:763
General product operator: x -&gt; (A*B)(x) = A(B(x)).
Definition: operator.hpp:722
ID for the base class Operator, i.e. any type.
Definition: operator.hpp:239
virtual void SetEvalMode(const EvalMode new_eval_mode)
Set the evaluation mode of the time-dependent operator.
Definition: operator.hpp:334
virtual MemoryClass GetMemoryClass() const
Return the MemoryClass preferred by the Operator.
Definition: operator.hpp:85
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition: operator.hpp:65
virtual ~ConstrainedOperator()
Destructor: destroys the unconstrained Operator, if owned.
Definition: operator.hpp:851
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
Definition: error.cpp:153
void FormConstrainedSystemOperator(const Array< int > &ess_tdof_list, ConstrainedOperator *&Aout)
see FormSystemOperator()
Definition: operator.cpp:134
double b
Definition: lissajous.cpp:42
This type assumes F(x,k,t) = k, i.e. k = f(x,t) = G(x,t).
Definition: operator.hpp:272
ID for class PetscParMatrix, unspecified format.
Definition: operator.hpp:247
virtual int SUNMassSetup()
Setup the mass matrix in the ODE system .
Definition: operator.cpp:265
TimeDependentOperator(int h, int w, double t_=0.0, Type type_=EXPLICIT)
Construct a TimeDependentOperator y = f(x,t), where x and y have dimensions w and h...
Definition: operator.hpp:304
int GetAdjointHeight()
Returns the size of the adjoint problem state space.
Definition: operator.hpp:572
The operator x -&gt; R*A*P*x constructed through the actions of R^T, A and P.
Definition: operator.hpp:742
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.cpp:567
virtual void Mult(const Vector &x, Vector &y) const
Rectangular-constrained operator action.
Definition: operator.cpp:539
ID for class PetscParMatrix, MATNEST format.
Definition: operator.hpp:245
bool isExplicit() const
True if type is EXPLICIT.
Definition: operator.hpp:314
Set the diagonal value to one.
Definition: operator.hpp:48
RAPOperator(const Operator &Rt_, const Operator &A_, const Operator &P_)
Construct the RAP operator given R^T, A and P.
Definition: operator.cpp:327
virtual const Operator * GetRestriction() const
Restriction operator from input vectors for the operator to linear algebra (linear system) vectors...
Definition: operator.hpp:108
This is the most general type, no assumptions on F and G.
Definition: operator.hpp:273
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
Definition: operator.hpp:690
ID for class PetscParMatrix, MATSHELL format.
Definition: operator.hpp:244
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: operator.hpp:784
Operator(int s=0)
Construct a square Operator with given size s (default 0).
Definition: operator.hpp:58
IdentityOperator(int n)
Create an identity operator of size n.
Definition: operator.hpp:661
bool IsIdentityProlongation(const Operator *P)
Definition: operator.hpp:672
Type
Enumeration defining IDs for some classes derived from Operator.
Definition: operator.hpp:237
virtual int SUNMassSolve(const Vector &b, Vector &x, double tol)
Solve the mass matrix linear system as setup by the method SUNMassSetup().
Definition: operator.cpp:271
Scaled Operator B: x -&gt; a A(x).
Definition: operator.hpp:678
TimeDependentOperator(int n=0, double t_=0.0, Type type_=EXPLICIT)
Construct a &quot;square&quot; TimeDependentOperator y = f(x,t), where x and y have the same dimension n...
Definition: operator.hpp:298
Vector w
Auxiliary vectors.
Definition: operator.hpp:806
int NumRows() const
Get the number of rows (size of output) of the Operator. Synonym with Height().
Definition: operator.hpp:68
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
virtual Operator & GetImplicitGradient(const Vector &x, const Vector &k, double shift) const
Return an Operator representing (dF/dk shift + dF/dx) at the given x, k, and the currently set time...
Definition: operator.cpp:236
Base abstract class for second order time dependent operators.
Definition: operator.hpp:585
int NumCols() const
Get the number of columns (size of input) of the Operator. Synonym with Width().
Definition: operator.hpp:74
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:51
ScaledOperator(const Operator *A, double a)
Create an operator which is a scalar multiple of A.
Definition: operator.hpp:686
The transpose of a given operator. Switches the roles of the methods Mult() and MultTranspose().
Definition: operator.hpp:697
Type GetType() const
Return the type ID of the Operator class.
Definition: operator.hpp:258
PowerMethod(MPI_Comm _comm)
Definition: operator.hpp:925
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:85
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:734
int height
Dimension of the output / number of rows in the matrix.
Definition: operator.hpp:27
This type assumes that G(x,t) = 0.
Definition: operator.hpp:274
TimeDependentAdjointOperator(int dim, int adjdim, double t=0., Type type=EXPLICIT)
The TimedependentAdjointOperator extends the TimeDependentOperator class to use features in SUNDIALS ...
Definition: operator.hpp:489
virtual void QuadratureIntegration(const Vector &y, Vector &qdot) const
Provide the operator integration of a quadrature equation.
Definition: operator.hpp:504
double a
Definition: lissajous.cpp:41
virtual void ImplicitMult(const Vector &x, const Vector &k, Vector &y) const
Perform the action of the implicit part of the operator, F: y = F(x, k, t) where t is the current tim...
Definition: operator.cpp:219
Rectangular Operator for imposing essential boundary conditions on the input space using only the act...
Definition: operator.hpp:861
Host memory; using new[] and delete[].
void EliminateRHS(const Vector &x, Vector &b) const
Eliminate &quot;essential boundary condition&quot; values specified in x from the given right-hand side b...
Definition: operator.cpp:421
void PrintMatlab(std::ostream &out, int n=0, int m=0) const
Prints operator with input size n and output size m in Matlab format.
Definition: operator.cpp:188
Keep the diagonal value.
Definition: operator.hpp:49
ID for class PetscParMatrix, MATAIJ format.
Definition: operator.hpp:242
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:164
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
Definition: operator.hpp:45
General triple product operator x -&gt; A*B*C*x, with ownership of the factors.
Definition: operator.hpp:769
int dim
Definition: ex24.cpp:53
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
Definition: operator.hpp:664
EvalMode GetEvalMode() const
Return the current evaluation mode. See SetEvalMode() for details.
Definition: operator.hpp:321
Operator(int h, int w)
Construct an Operator with the given height (output size) and width (input size). ...
Definition: operator.hpp:62
virtual int SUNImplicitSetup(const Vector &x, const Vector &fx, int jok, int *jcur, double gamma)
Setup the ODE linear system or , where .
Definition: operator.cpp:251
virtual void Mult(const Vector &x, Vector &y) const
Perform the action of the operator: y = k = f(x, t), where k solves the algebraic equation F(x...
Definition: operator.cpp:225
TripleProductOperator(const Operator *A, const Operator *B, const Operator *C, bool ownA, bool ownB, bool ownC)
Definition: operator.cpp:361
virtual int SUNMassMult(const Vector &x, Vector &v)
Compute the mass matrix-vector product .
Definition: operator.cpp:277
ID for class ComplexSparseMatrix.
Definition: operator.hpp:249
Operator * SetupRAP(const Operator *Pi, const Operator *Po)
Returns RAP Operator of this, taking in input/output Prolongation matrices.
Definition: operator.cpp:105
virtual void SetOperator(const Operator &op)=0
Set/update the solver for the given operator.
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: operator.hpp:731
EvalMode
Evaluation mode. See SetEvalMode() for details.
Definition: operator.hpp:278
Vector data type.
Definition: vector.hpp:51
Identity Operator I: x -&gt; x.
Definition: operator.hpp:657
ID for class HypreParMatrix.
Definition: operator.hpp:241
TransposeOperator(const Operator *a)
Construct the transpose of a given operator *a.
Definition: operator.hpp:704
DiagonalPolicy diag_policy
Diagonal policy for constrained dofs.
Definition: operator.hpp:808
Base class for solvers.
Definition: operator.hpp:634
Operator * A
The unconstrained Operator.
Definition: operator.hpp:804
ID for class ComplexOperator.
Definition: operator.hpp:248
Square Operator for imposing essential boundary conditions using only the action, Mult()...
Definition: operator.hpp:800
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
double EstimateLargestEigenvalue(Operator &opr, Vector &v0, int numSteps=10, double 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:596
Abstract operator.
Definition: operator.hpp:24
virtual void ImplicitSolve(const double dt0, const double dt1, const Vector &x, const Vector &dxdt, Vector &k)
Solve the equation: k = f(x + 1/2 dt0^2 k, dxdt + dt1 k, t), for the unknown k at the current time t...
Definition: operator.cpp:291
virtual ~Operator()
Virtual destructor.
Definition: operator.hpp:233
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:787
ID for class PetscParMatrix, MATIS format.
Definition: operator.hpp:243
MemoryClass
Memory classes identify sets of memory types.
Definition: mem_manager.hpp:58
Set the diagonal value to zero.
Definition: operator.hpp:47
int width
Dimension of the input / number of columns in the matrix.
Definition: operator.hpp:28
virtual int SUNImplicitSetupB(const double t, const Vector &x, const Vector &xB, const Vector &fxB, int jokB, int *jcurB, double gammaB)
Setup the ODE linear system or , where .
Definition: operator.hpp:544
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:495
virtual const Operator * GetOutputRestriction() const
Restriction operator from output vectors for the operator to linear algebra (linear system) vectors...
Definition: operator.hpp:117
virtual MemoryClass GetMemoryClass() const
Return the MemoryClass preferred by the Operator.
Definition: operator.hpp:756