MFEM  v3.3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
petsc.hpp
Go to the documentation of this file.
1 // Copyright (c) 2016, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 // Author: Stefano Zampini <stefano.zampini@gmail.com>
13 
14 #ifndef MFEM_PETSC
15 #define MFEM_PETSC
16 
17 #include "../config/config.hpp"
18 #include "linalg.hpp"
19 
20 #ifdef MFEM_USE_PETSC
21 #ifdef MFEM_USE_MPI
22 
23 #include <petsc.h>
24 #include <limits>
25 
26 namespace mfem
27 {
28 
29 class ParFiniteElementSpace;
30 class PetscParMatrix;
31 
32 /// Wrapper for PETSc's vector class
33 class PetscParVector : public Vector
34 {
35 protected:
36  /// The actual PETSc object
37  Vec x;
38 
39  friend class PetscParMatrix;
40  friend class PetscODESolver;
41  friend class PetscLinearSolver;
42  friend class PetscPreconditioner;
43  friend class PetscNonlinearSolver;
44  friend class PetscBDDCSolver;
45 
46  // Set Vector::data and Vector::size from x
47  void _SetDataAndSize_();
48 
49 public:
50  /// Creates vector with given global size and partitioning of the columns.
51  /** If @a col is provided, processor P owns columns [col[P],col[P+1]).
52  Otherwise, PETSc decides the partitioning */
53  PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscInt *col = NULL);
54 
55  /** @brief Creates vector with given global size, partitioning of the
56  columns, and data.
57 
58  The data must be allocated and destroyed outside. If @a _data is NULL, a
59  dummy vector without a valid data array will be created. */
60  PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscScalar *_data,
61  PetscInt *col);
62 
63  /// Creates vector compatible with @a y
65 
66  /// Creates a PetscParVector from a Vector (data is not copied)
67  PetscParVector(MPI_Comm comm, const Vector &_x);
68 
69  /** @brief Creates vector compatible with the Operator (i.e. in the domain
70  of) @a op or its adjoint. */
71  /** The argument @a allocate determines if the memory is actually allocated
72  to store the data. */
73  explicit PetscParVector(MPI_Comm comm, const Operator &op,
74  bool transpose = false, bool allocate = true);
75 
76  /// Creates vector compatible with (i.e. in the domain of) @a A or @a A^T
77  /** The argument @a allocate determines if the memory is actually allocated
78  to store the data. */
79  explicit PetscParVector(const PetscParMatrix &A, bool transpose = false,
80  bool allocate = true);
81 
82  /// Creates PetscParVector out of PETSc Vec object.
83  /** @param[in] y The PETSc Vec object.
84  @param[in] ref If true, we increase the reference count of @a y. */
85  explicit PetscParVector(Vec y, bool ref=false);
86 
87  /// Create a true dof parallel vector on a given ParFiniteElementSpace
88  explicit PetscParVector(ParFiniteElementSpace *pfes);
89 
90  /// Calls PETSc's destroy function
91  virtual ~PetscParVector();
92 
93  /// Get the associated MPI communicator
94  MPI_Comm GetComm() const { return PetscObjectComm((PetscObject)x); }
95 
96  /// Returns the global number of rows
97  PetscInt GlobalSize() const;
98 
99  /// Conversion function to PETSc's Vec type
100  operator Vec() const { return x; }
101 
102  /// Returns the global vector in each processor
103  Vector* GlobalVector() const;
104 
105  /// Set constant values
106  PetscParVector& operator= (PetscScalar d);
107 
108  /// Define '=' for PETSc vectors.
110 
111  /** @brief Temporarily replace the data of the PETSc Vec object. To return to
112  the original data array, call ResetArray().
113 
114  @note This method calls PETSc's VecPlaceArray() function.
115  @note The inherited Vector::data pointer is not affected by this call. */
116  void PlaceArray(PetscScalar *temp_data);
117 
118  /** @brief Reset the PETSc Vec object to use its default data. Call this
119  method after the use of PlaceArray().
120 
121  @note This method calls PETSc's VecResetArray() function. */
122  void ResetArray();
123 
124  /// Set random values
125  void Randomize(PetscInt seed);
126 
127  /// Prints the vector (to stdout if @a fname is NULL)
128  void Print(const char *fname = NULL, bool binary = false) const;
129 };
130 
131 
132 /// Wrapper for PETSc's matrix class
133 class PetscParMatrix : public Operator
134 {
135 protected:
136  /// The actual PETSc object
137  Mat A;
138 
139  /// Auxiliary vectors for typecasting
140  mutable PetscParVector *X, *Y;
141 
142  /// Initialize with defaults. Does not initialize inherited members.
143  void Init();
144 
145  /// Delete all owned data. Does not perform re-initialization with defaults.
146  void Destroy();
147 
148  /** @brief Creates a wrapper around a mfem::Operator @a op using PETSc's
149  MATSHELL object and returns the Mat in @a B.
150 
151  This does not take any reference to @a op, that should not be destroyed
152  until @a B is needed. */
153  void MakeWrapper(MPI_Comm comm, const Operator* op, Mat *B);
154 
155  /// Convert an mfem::Operator into a Mat @a B; @a op can be destroyed unless
156  /// tid == PETSC_MATSHELL
157  /// if op is a BlockOperator, the operator type is relevant to the individual
158  /// blocks
159  void ConvertOperator(MPI_Comm comm, const Operator& op, Mat *B,
160  Operator::Type tid);
161 
162  friend class PetscLinearSolver;
163  friend class PetscPreconditioner;
164 
165 private:
166  /// Constructs a block-diagonal Mat object
167  void BlockDiagonalConstructor(MPI_Comm comm, PetscInt *row_starts,
168  PetscInt *col_starts, SparseMatrix *diag,
169  bool assembled, Mat *A);
170 
171 public:
172  /// Create an empty matrix to be used as a reference to an existing matrix.
173  PetscParMatrix();
174 
175  /// Creates PetscParMatrix out of PETSc's Mat.
176  /** @param[in] a The PETSc Mat object.
177  @param[in] ref If true, we increase the reference count of @a a. */
178  PetscParMatrix(Mat a, bool ref=false);
179 
180  /** @brief Convert a HypreParMatrix @a ha to a PetscParMatrix in the given
181  PETSc format @a tid. */
182  /** The supported type ids are: Operator::PETSC_MATAIJ,
183  Operator::PETSC_MATIS, and Operator::PETSC_MATSHELL. */
185 
186  /** @brief Convert an mfem::Operator into a PetscParMatrix in the given PETSc
187  format @a tid. */
188  /** If @a tid is Operator::PETSC_MATSHELL and @a op is not a PetscParMatrix,
189  it converts any mfem::Operator @a op implementing Operator::Mult() and
190  Operator::MultTranspose() into a PetscParMatrix. The Operator @a op
191  should not be deleted while the constructed PetscParMatrix is used.
192 
193  Otherwise, it tries to convert the operator in PETSc's classes.
194 
195  In particular, if @a op is a BlockOperator, then a MATNEST Mat object is
196  created using @a tid as the type for the blocks.
197  Note that if @a op is already a PetscParMatrix of the same type as
198  @a tid, the resulting PetscParMatrix will share the same Mat object */
199  PetscParMatrix(MPI_Comm comm, const Operator *op, Operator::Type tid);
200 
201  /// Creates block-diagonal square parallel matrix.
202  /** The block-diagonal is given by @a diag which must be in CSR format
203  (finalized). The new PetscParMatrix does not take ownership of any of the
204  input arrays. The type id @a tid can be either PETSC_MATAIJ (parallel
205  distributed CSR) or PETSC_MATIS. */
206  PetscParMatrix(MPI_Comm comm, PetscInt glob_size, PetscInt *row_starts,
207  SparseMatrix *diag, Operator::Type tid);
208 
209  /// Creates block-diagonal rectangular parallel matrix.
210  /** The block-diagonal is given by @a diag which must be in CSR format
211  (finalized). The new PetscParMatrix does not take ownership of any of the
212  input arrays. The type id @a tid can be either PETSC_MATAIJ (parallel
213  distributed CSR) or PETSC_MATIS. */
214  PetscParMatrix(MPI_Comm comm, PetscInt global_num_rows,
215  PetscInt global_num_cols, PetscInt *row_starts,
216  PetscInt *col_starts, SparseMatrix *diag,
217  Operator::Type tid);
218 
219  /// Calls PETSc's destroy function.
220  virtual ~PetscParMatrix() { Destroy(); }
221 
222  /// @name Assignment operators
223  ///@{
227  ///@}
228 
229  /// Matvec: @a y = @a a A @a x + @a b @a y.
230  void Mult(double a, const Vector &x, double b, Vector &y) const;
231 
232  /// Matvec transpose: @a y = @a a A^T @a x + @a b @a y.
233  void MultTranspose(double a, const Vector &x, double b, Vector &y) const;
234 
235  virtual void Mult(const Vector &x, Vector &y) const
236  { Mult(1.0, x, 0.0, y); }
237 
238  virtual void MultTranspose(const Vector &x, Vector &y) const
239  { MultTranspose(1.0, x, 0.0, y); }
240 
241  /// Get the associated MPI communicator
242  MPI_Comm GetComm() const { return PetscObjectComm((PetscObject)A); }
243 
244  /// Typecasting to PETSc's Mat type
245  operator Mat() const { return A; }
246 
247  /// Returns the local number of rows
248  PetscInt GetNumRows() const;
249 
250  /// Returns the local number of columns
251  PetscInt GetNumCols() const;
252 
253  /// Returns the global number of rows
254  PetscInt M() const;
255 
256  /// Returns the global number of columns
257  PetscInt N() const;
258 
259  /// Returns the global number of rows
260  PetscInt GetGlobalNumRows() const { return M(); }
261 
262  /// Returns the global number of columns
263  PetscInt GetGlobalNumCols() const { return N(); }
264 
265  /// Returns the number of nonzeros.
266  /** Differently from HYPRE, this call is collective on the communicator,
267  as this number is not stored inside PETSc, but needs to be computed. */
268  PetscInt NNZ() const;
269 
270  /// Returns the inner vector in the domain of A (it creates it if needed)
271  PetscParVector* GetX() const;
272 
273  /// Returns the inner vector in the range of A (it creates it if needed)
274  PetscParVector* GetY() const;
275 
276  /// Returns the transpose of the PetscParMatrix.
277  /** If @a action is false, the new matrix is constructed with the PETSc
278  function MatTranspose().
279  If @a action is true, then the matrix is not actually transposed.
280  Instead, an object that behaves like the transpose is returned. */
281  PetscParMatrix* Transpose(bool action = false);
282 
283  /// Prints the matrix (to stdout if fname is NULL)
284  void Print(const char *fname = NULL, bool binary = false) const;
285 
286  /// Scale all entries by s: A_scaled = s*A.
287  void operator*=(double s);
288 
289  /** @brief Eliminate rows and columns from the matrix, and rows from the
290  vector @a B. Modify @a B with the BC values in @a X. */
291  void EliminateRowsCols(const Array<int> &rows_cols, const PetscParVector &X,
292  PetscParVector &B);
293  void EliminateRowsCols(const Array<int> &rows_cols, const HypreParVector &X,
294  HypreParVector &B);
295 
296  /** @brief Eliminate rows and columns from the matrix and store the
297  eliminated elements in a new matrix Ae (returned).
298 
299  The sum of the modified matrix and the returned matrix, Ae, is equal to
300  the original matrix. */
301  PetscParMatrix* EliminateRowsCols(const Array<int> &rows_cols);
302 
303  /// Makes this object a reference to another PetscParMatrix
304  void MakeRef(const PetscParMatrix &master);
305 
306  /** @brief Release the PETSc Mat object. If @a dereference is true, decrement
307  the refcount of the Mat object. */
308  Mat ReleaseMat(bool dereference);
309 
310  Type GetType() const;
311 };
312 
313 /// Returns the matrix Rt^t * A * P
314 PetscParMatrix * RAP(PetscParMatrix *Rt, PetscParMatrix *A, PetscParMatrix *P);
315 
316 /// Returns the matrix P^t * A * P
317 PetscParMatrix * RAP(PetscParMatrix *A, PetscParMatrix *P);
318 
319 /** @brief Eliminate essential BC specified by @a ess_dof_list from the solution
320  @a X to the r.h.s. @a B.
321 
322  Here, @a A is a matrix with eliminated BC, while @a Ae is such that
323  (@a A + @a Ae) is the original (Neumann) matrix before elimination. */
324 void EliminateBC(PetscParMatrix &A, PetscParMatrix &Ae,
325  const Array<int> &ess_dof_list, const Vector &X, Vector &B);
326 
327 /// Helper class for handling essential boundary conditions.
329 {
330 public:
331  enum Type
332  {
334  CONSTANT, ///< Constant in time b.c.
336  };
337 
339  bctype(_type), setup(false), eval_t(0.0),
340  eval_t_cached(std::numeric_limits<double>::min()) {}
341  PetscBCHandler(Array<int>& ess_tdof_list, Type _type = ZERO);
342 
343  virtual ~PetscBCHandler() {}
344 
345  /// Returns the type of boundary conditions
346  Type GetType() const { return bctype; }
347 
348  /// Sets the type of boundary conditions
349  void SetType(enum Type _type) { bctype = _type; setup = false; }
350 
351  /// Boundary conditions evaluation
352  /** In the result vector, @a g, only values at the essential dofs need to be
353  set. */
354  virtual void Eval(double t, Vector &g)
355  { mfem_error("PetscBCHandler::Eval method not overloaded"); }
356 
357  /// Sets essential dofs (local, per-process numbering)
358  void SetTDofs(Array<int>& list);
359 
360  /// Gets essential dofs (local, per-process numbering)
361  Array<int>& GetTDofs() { return ess_tdof_list; }
362 
363  /// Sets the current time
364  void SetTime(double t) { eval_t = t; }
365 
366  /// SetUp the helper object, where @a n is the size of the solution vector
367  void SetUp(PetscInt n);
368 
369  /// y = x on ess_tdof_list_c and y = g (internally evaluated) on ess_tdof_list
370  void ApplyBC(const Vector &x, Vector &y);
371 
372  /// y = x-g on ess_tdof_list, the rest of y is unchanged
373  void FixResidualBC(const Vector& x, Vector& y);
374 
375 private:
376  enum Type bctype;
377  bool setup;
378 
379  double eval_t;
380  double eval_t_cached;
381  Vector eval_g;
382 
383  Array<int> ess_tdof_list; //Essential true dofs
384 };
385 
386 // Helper class for user-defined preconditioners that needs to be setup
388 {
389 private:
390  std::string name;
391 public:
392  PetscPreconditionerFactory(const std::string &_name = "MFEM Factory")
393  : name(_name) { }
394  const char* GetName() { return name.c_str(); }
395  virtual Solver *NewPreconditioner(const OperatorHandle& oh) = 0;
397 };
398 
399 // Forward declarations of helper classes
400 class PetscSolverMonitor;
401 
402 /// Abstract class for PETSc's solvers.
404 {
405 protected:
406  /// Boolean to handle SetFromOptions calls.
407  mutable bool clcustom;
408 
409  /// The actual PETSc object (KSP, PC, SNES or TS).
410  PetscObject obj;
411 
412  /// The class id of the actual PETSc object
413  PetscClassId cid;
414 
415  /// Right-hand side and solution vector
416  mutable PetscParVector *B, *X;
417 
418  /// Handler for boundary conditions
420 
421  /// Private context for solver
422  void *private_ctx;
423 
424  /// Boolean to handle SetOperator calls.
425  mutable bool operatorset;
426 
427 public:
428  /// Construct an empty PetscSolver. Initialize protected objects to NULL.
429  PetscSolver();
430 
431  /// Destroy the PetscParVectors allocated (if any).
432  virtual ~PetscSolver();
433 
434  /** @name Update of PETSc options.
435  The following Set methods can be used to update the internal PETSc
436  options.
437  @note They will be overwritten by the options in the input PETSc file. */
438  ///@{
439  void SetTol(double tol);
440  void SetRelTol(double tol);
441  void SetAbsTol(double tol);
442  void SetMaxIter(int max_iter);
443  void SetPrintLevel(int plev);
444  ///@}
445 
446  /// Customize object with options set
447  /** If @a customize is false, it disables any options customization. */
448  void Customize(bool customize = true) const;
449  int GetConverged();
450  int GetNumIterations();
451  double GetFinalNorm();
452 
453  /// Sets user-defined monitoring routine.
454  void SetMonitor(PetscSolverMonitor *ctx);
455 
456  /// Sets the object to handle essential boundary conditions
457  void SetBCHandler(PetscBCHandler *bch);
458 
459  /// Sets the object for the creation of the preconditioner
461 
462  /// Conversion function to PetscObject.
463  operator PetscObject() const { return obj; }
464 
465 protected:
466  /// These two methods handle creation and destructions of
467  /// private data for the Solver objects
468  void CreatePrivateContext();
469  void FreePrivateContext();
470 };
471 
472 
473 /// Abstract class for PETSc's linear solvers.
474 class PetscLinearSolver : public PetscSolver, public Solver
475 {
476 private:
477  /// Internal flag to handle HypreParMatrix conversion or not.
478  bool wrap;
479 
480 public:
481  PetscLinearSolver(MPI_Comm comm, const std::string &prefix = std::string(),
482  bool wrap = false);
484  const std::string &prefix = std::string());
485  /// Constructs a solver using a HypreParMatrix.
486  /** If @a wrap is true, then the MatMult ops of HypreParMatrix are wrapped.
487  No preconditioner can be automatically constructed from PETSc. If
488  @a wrap is false, the HypreParMatrix is converted into PETSc format. */
489  PetscLinearSolver(const HypreParMatrix &A, bool wrap = true,
490  const std::string &prefix = std::string());
491  virtual ~PetscLinearSolver();
492 
493  virtual void SetOperator(const Operator &op);
494 
495  /// Allows to prescribe a different operator (@a pop) to construct
496  /// the preconditioner
497  void SetOperator(const Operator &op, const Operator &pop);
498 
499  /// Sets the solver to perform preconditioning
500  void SetPreconditioner(Solver &precond);
501 
502  /// Application of the solver.
503  virtual void Mult(const Vector &b, Vector &x) const;
504 
505  /// Conversion function to PETSc's KSP type.
506  operator KSP() const { return (KSP)obj; }
507 };
508 
509 
511 {
512 public:
513  PetscPCGSolver(MPI_Comm comm, const std::string &prefix = std::string());
514  PetscPCGSolver(PetscParMatrix &A, const std::string &prefix = std::string());
515  PetscPCGSolver(HypreParMatrix &A,bool wrap=true,
516  const std::string &prefix = std::string());
517 };
518 
519 
520 /// Abstract class for PETSc's preconditioners.
521 class PetscPreconditioner : public PetscSolver, public Solver
522 {
523 public:
524  PetscPreconditioner(MPI_Comm comm,
525  const std::string &prefix = std::string());
527  const std::string &prefix = std::string());
528  PetscPreconditioner(MPI_Comm comm, Operator &op,
529  const std::string &prefix = std::string());
530  virtual ~PetscPreconditioner();
531 
532  virtual void SetOperator(const Operator &op);
533 
534  /// Application of the preconditioner.
535  virtual void Mult(const Vector &b, Vector &x) const;
536 
537  /// Conversion function to PETSc's PC type.
538  operator PC() const { return (PC)obj; }
539 };
540 
541 
542 /// Auxiliary class for BDDC customization.
544 {
545 protected:
551  friend class PetscBDDCSolver;
552 
553 public:
555  nat_dof(NULL), nat_dof_local(false)
556  {}
558 
559  /// Specify dofs on the essential boundary.
560  /** If @a loc is false, it is a list of true dofs in local ordering.
561  If @a loc is true, it is a marker for Vdofs in local ordering. */
562  void SetEssBdrDofs(const Array<int> *essdofs, bool loc = false)
563  {
564  ess_dof = essdofs;
565  ess_dof_local = loc;
566  }
567  /// Specify dofs on the natural boundary.
568  /** If @a loc is false, it is a list of true dofs in local ordering.
569  If @a loc is true, it is a marker for Vdofs in local ordering. */
570  void SetNatBdrDofs(const Array<int> *natdofs, bool loc = false)
571  {
572  nat_dof = natdofs;
573  nat_dof_local = loc;
574  }
575 };
576 
577 
579 {
580 private:
581  void BDDCSolverConstructor(const PetscBDDCSolverParams &opts);
582 
583 public:
584  PetscBDDCSolver(MPI_Comm comm, Operator &op,
586  const std::string &prefix = std::string());
589  const std::string &prefix = std::string());
590 };
591 
592 
594 {
595 public:
596  PetscFieldSplitSolver(MPI_Comm comm, Operator &op,
597  const std::string &prefix = std::string());
598 };
599 
600 
601 /// Abstract class for PETSc's nonlinear solvers.
603 {
604 public:
605  PetscNonlinearSolver(MPI_Comm comm,
606  const std::string &prefix = std::string());
607  PetscNonlinearSolver(MPI_Comm comm, Operator &op,
608  const std::string &prefix = std::string());
609  virtual ~PetscNonlinearSolver();
610 
611  /// Specification of the nonlinear operator.
612  virtual void SetOperator(const Operator &op);
613 
614  /// Specifies the desired format of the Jacobian in case a PetscParMatrix
615  /// is not returned by the GetGradient method
616  void SetJacobianType(Operator::Type type);
617 
618  /// Application of the solver.
619  virtual void Mult(const Vector &b, Vector &x) const;
620 
621  /// Conversion function to PETSc's SNES type.
622  operator SNES() const { return (SNES)obj; }
623 };
624 
625 
626 /// Abstract class for PETSc's ODE solvers.
627 class PetscODESolver : public PetscSolver, public ODESolver
628 {
629 public:
630  /// The type of the ODE. Use ODE_SOLVER_LINEAR if the jacobians
631  /// are linear and independent of time.
632  enum Type
633  {
636  };
637 
638  PetscODESolver(MPI_Comm comm, const std::string &prefix = std::string());
639  virtual ~PetscODESolver();
640 
641  /// Initialize the ODE solver.
642  virtual void Init(TimeDependentOperator &f_,
643  enum PetscODESolver::Type type);
645 
646  /// Specifies the desired format of the Jacobian in case a PetscParMatrix
647  /// is not returned by the GetGradient methods
648  void SetJacobianType(Operator::Type type);
649 
650  virtual void Step(Vector &x, double &t, double &dt);
651  virtual void Run(Vector &x, double &t, double &dt, double t_final);
652 
653  /// Conversion function to PETSc's TS type.
654  operator TS() const { return (TS)obj; }
655 };
656 
657 
658 /// Abstract class for monitoring PETSc's solvers.
660 {
661 public:
662  bool mon_sol;
663  bool mon_res;
664  PetscSolverMonitor(bool monitor_sol = false, bool monitor_res = true)
665  : mon_sol(monitor_sol), mon_res(monitor_res) {}
666  virtual ~PetscSolverMonitor() {}
667 
668  /// Monitor the solution vector x
669  virtual void MonitorSolution(PetscInt it, PetscReal norm, const Vector &x)
670  {
671  MFEM_ABORT("MonitorSolution() is not implemented!")
672  }
673 
674  /// Monitor the residual vector r
675  virtual void MonitorResidual(PetscInt it, PetscReal norm, const Vector &r)
676  {
677  MFEM_ABORT("MonitorResidual() is not implemented!")
678  }
679 };
680 
681 
682 } // namespace mfem
683 
684 #endif // MFEM_USE_MPI
685 #endif // MFEM_USE_PETSC
686 
687 #endif
PetscPreconditionerFactory(const std::string &_name="MFEM Factory")
Definition: petsc.hpp:392
void SetPreconditioner(Solver &precond)
Sets the solver to perform preconditioning.
Definition: petsc.cpp:2003
void SetPrintLevel(int plev)
Definition: petsc.cpp:1407
PetscParVector * B
Right-hand side and solution vector.
Definition: petsc.hpp:416
void CreatePrivateContext()
Definition: petsc.cpp:1679
void Print(const char *fname=NULL, bool binary=false) const
Prints the matrix (to stdout if fname is NULL)
Definition: petsc.cpp:1072
virtual void SetOperator(const Operator &op)
Specification of the nonlinear operator.
Definition: petsc.cpp:2616
Abstract class for PETSc&#39;s preconditioners.
Definition: petsc.hpp:521
PetscParMatrix & operator+=(const PetscParMatrix &B)
Definition: petsc.cpp:484
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: petsc.cpp:1839
HypreParMatrix * RAP(const HypreParMatrix *A, const HypreParMatrix *P)
Returns the matrix P^t * A * P.
Definition: hypre.cpp:1476
bool clcustom
Boolean to handle SetFromOptions calls.
Definition: petsc.hpp:407
void ConvertOperator(MPI_Comm comm, const Operator &op, Mat *B, Operator::Type tid)
Definition: petsc.cpp:656
double GetFinalNorm()
Definition: petsc.cpp:1654
Wrapper for PETSc&#39;s matrix class.
Definition: petsc.hpp:133
const Array< int > * nat_dof
Definition: petsc.hpp:549
void ApplyBC(const Vector &x, Vector &y)
y = x on ess_tdof_list_c and y = g (internally evaluated) on ess_tdof_list
Definition: petsc.cpp:1758
Abstract class for PETSc&#39;s linear solvers.
Definition: petsc.hpp:474
Vec x
The actual PETSc object.
Definition: petsc.hpp:37
Abstract class for PETSc&#39;s solvers.
Definition: petsc.hpp:403
virtual void Run(Vector &x, double &t, double &dt, double t_final)
Perform time integration from time t [in] to time tf [in].
Definition: petsc.cpp:2849
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: petsc.hpp:235
ParFiniteElementSpace * fespace
Definition: petsc.hpp:546
Type GetType() const
Returns the type of boundary conditions.
Definition: petsc.hpp:346
Base abstract class for time dependent operators.
Definition: operator.hpp:142
PetscInt GetNumCols() const
Returns the local number of columns.
Definition: petsc.cpp:366
Pointer to an Operator of a specified type.
Definition: handle.hpp:33
void Mult(double a, const Vector &x, double b, Vector &y) const
Matvec: y = a A x + b y.
Definition: petsc.cpp:1039
PetscBDDCSolver(MPI_Comm comm, Operator &op, const PetscBDDCSolverParams &opts=PetscBDDCSolverParams(), const std::string &prefix=std::string())
Definition: petsc.cpp:2531
virtual ~PetscSolver()
Destroy the PetscParVectors allocated (if any).
Definition: petsc.cpp:1318
PetscNonlinearSolver(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:2576
PetscInt GetGlobalNumRows() const
Returns the global number of rows.
Definition: petsc.hpp:260
Type GetType() const
Definition: petsc.cpp:1260
virtual void Step(Vector &x, double &t, double &dt)
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in]...
Definition: petsc.cpp:2822
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
Definition: ode.hpp:22
void Init()
Initialize with defaults. Does not initialize inherited members.
Definition: petsc.cpp:394
PetscPreconditioner(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:2116
PetscClassId cid
The class id of the actual PETSc object.
Definition: petsc.hpp:413
Abstract parallel finite element space.
Definition: pfespace.hpp:31
Constant in time b.c.
Definition: petsc.hpp:334
void SetRelTol(double tol)
Definition: petsc.cpp:1330
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: petsc.hpp:238
PetscPCGSolver(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:2086
void Destroy()
Delete all owned data. Does not perform re-initialization with defaults.
Definition: petsc.cpp:907
void SetMonitor(PetscSolverMonitor *ctx)
Sets user-defined monitoring routine.
Definition: petsc.cpp:1479
void SetMaxIter(int max_iter)
Definition: petsc.cpp:1380
Abstract class for PETSc&#39;s ODE solvers.
Definition: petsc.hpp:627
Wrapper for PETSc&#39;s vector class.
Definition: petsc.hpp:33
void Customize(bool customize=true) const
Customize object with options set.
Definition: petsc.cpp:1555
PetscInt M() const
Returns the global number of rows.
Definition: petsc.cpp:373
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Definition: petsc.cpp:2667
PetscParVector * Y
Definition: petsc.hpp:140
virtual ~PetscLinearSolver()
Definition: petsc.cpp:2076
PetscInt GetNumRows() const
Returns the local number of rows.
Definition: petsc.cpp:359
void Randomize(PetscInt seed)
Set random values.
Definition: petsc.cpp:320
void Print(const char *fname=NULL, bool binary=false) const
Prints the vector (to stdout if fname is NULL)
Definition: petsc.cpp:332
void EliminateBC(HypreParMatrix &A, HypreParMatrix &Ae, const Array< int > &ess_dof_list, const Vector &X, Vector &B)
Definition: hypre.cpp:1530
void ResetArray()
Reset the PETSc Vec object to use its default data. Call this method after the use of PlaceArray()...
Definition: petsc.cpp:315
virtual void Init(TimeDependentOperator &f_, enum PetscODESolver::Type type)
Initialize the ODE solver.
Definition: petsc.cpp:2725
PetscParMatrix * Transpose(bool action=false)
Returns the transpose of the PetscParMatrix.
Definition: petsc.cpp:1020
PetscObject obj
The actual PETSc object (KSP, PC, SNES or TS).
Definition: petsc.hpp:410
Abstract class for monitoring PETSc&#39;s solvers.
Definition: petsc.hpp:659
Data type sparse matrix.
Definition: sparsemat.hpp:38
void SetJacobianType(Operator::Type type)
Definition: petsc.cpp:2661
Auxiliary class for BDDC customization.
Definition: petsc.hpp:543
virtual ~PetscPreconditioner()
Definition: petsc.cpp:2227
MPI_Comm GetComm() const
Get the associated MPI communicator.
Definition: petsc.hpp:242
void FixResidualBC(const Vector &x, Vector &y)
y = x-g on ess_tdof_list, the rest of y is unchanged
Definition: petsc.cpp:1783
PetscParMatrix & operator=(const PetscParMatrix &B)
Definition: petsc.cpp:468
void EliminateRowsCols(const Array< int > &rows_cols, const PetscParVector &X, PetscParVector &B)
Eliminate rows and columns from the matrix, and rows from the vector B. Modify B with the BC values i...
Definition: petsc.cpp:1219
virtual ~PetscParVector()
Calls PETSc&#39;s destroy function.
Definition: petsc.cpp:180
PetscFieldSplitSolver(MPI_Comm comm, Operator &op, const std::string &prefix=std::string())
Definition: petsc.cpp:2540
PetscBCHandler * bchandler
Handler for boundary conditions.
Definition: petsc.hpp:419
virtual Solver * NewPreconditioner(const OperatorHandle &oh)=0
PetscLinearSolver(MPI_Comm comm, const std::string &prefix=std::string(), bool wrap=false)
Definition: petsc.cpp:1804
void SetTime(double t)
Sets the current time.
Definition: petsc.hpp:364
PetscParMatrix()
Create an empty matrix to be used as a reference to an existing matrix.
Definition: petsc.cpp:401
void SetType(enum Type _type)
Sets the type of boundary conditions.
Definition: petsc.hpp:349
Abstract class for PETSc&#39;s nonlinear solvers.
Definition: petsc.hpp:602
int GetNumIterations()
Definition: petsc.cpp:1621
void SetBCHandler(PetscBCHandler *bch)
Sets the object to handle essential boundary conditions.
Definition: petsc.cpp:1502
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:73
virtual void Eval(double t, Vector &g)
Boundary conditions evaluation.
Definition: petsc.hpp:354
Type
Enumeration defining IDs for some classes derived from Operator.
Definition: operator.hpp:123
PetscBCHandler(Type _type=ZERO)
Definition: petsc.hpp:338
PetscInt NNZ() const
Returns the number of nonzeros.
Definition: petsc.cpp:387
virtual void Mult(const Vector &b, Vector &x) const
Application of the preconditioner.
Definition: petsc.cpp:2197
void mfem_error(const char *msg)
Definition: error.cpp:107
Mat A
The actual PETSc object.
Definition: petsc.hpp:137
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
Definition: petsc.hpp:644
PetscInt N() const
Returns the global number of columns.
Definition: petsc.cpp:380
PetscParVector * GetY() const
Returns the inner vector in the range of A (it creates it if needed)
Definition: petsc.cpp:1010
void SetJacobianType(Operator::Type type)
Definition: petsc.cpp:2816
void MakeWrapper(MPI_Comm comm, const Operator *op, Mat *B)
Creates a wrapper around a mfem::Operator op using PETSc&#39;s MATSHELL object and returns the Mat in B...
Definition: petsc.cpp:635
bool operatorset
Boolean to handle SetOperator calls.
Definition: petsc.hpp:425
PetscParVector * X
Auxiliary vectors for typecasting.
Definition: petsc.hpp:140
void MultTranspose(double a, const Vector &x, double b, Vector &y) const
Matvec transpose: y = a A^T x + b y.
Definition: petsc.cpp:1055
virtual ~PetscSolverMonitor()
Definition: petsc.hpp:666
virtual ~PetscNonlinearSolver()
Definition: petsc.cpp:2608
virtual ~PetscODESolver()
Definition: petsc.cpp:2717
virtual ~PetscBCHandler()
Definition: petsc.hpp:343
int GetConverged()
Definition: petsc.cpp:1588
PetscSolver()
Construct an empty PetscSolver. Initialize protected objects to NULL.
Definition: petsc.cpp:1308
void SetPreconditionerFactory(PetscPreconditionerFactory *factory)
Sets the object for the creation of the preconditioner.
Definition: petsc.cpp:1521
Mat ReleaseMat(bool dereference)
Release the PETSc Mat object. If dereference is true, decrement the refcount of the Mat object...
Definition: petsc.cpp:1247
PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscInt *col=NULL)
Creates vector with given global size and partitioning of the columns.
Definition: petsc.cpp:162
virtual void MonitorSolution(PetscInt it, PetscReal norm, const Vector &x)
Monitor the solution vector x.
Definition: petsc.hpp:669
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: petsc.cpp:2151
void SetSpace(ParFiniteElementSpace *fe)
Definition: petsc.hpp:557
MPI_Comm GetComm() const
Get the associated MPI communicator.
Definition: petsc.hpp:94
PetscInt GlobalSize() const
Returns the global number of rows.
Definition: petsc.cpp:147
PetscParVector * X
Definition: petsc.hpp:416
const Array< int > * ess_dof
Definition: petsc.hpp:547
void _SetDataAndSize_()
Definition: petsc.cpp:136
void SetAbsTol(double tol)
Definition: petsc.cpp:1355
Helper class for handling essential boundary conditions.
Definition: petsc.hpp:328
PetscParVector * GetX() const
Returns the inner vector in the domain of A (it creates it if needed)
Definition: petsc.cpp:1000
Array< int > & GetTDofs()
Gets essential dofs (local, per-process numbering)
Definition: petsc.hpp:361
void SetTol(double tol)
Definition: petsc.cpp:1325
PetscParVector & operator=(PetscScalar d)
Set constant values.
Definition: petsc.cpp:298
PetscSolverMonitor(bool monitor_sol=false, bool monitor_res=true)
Definition: petsc.hpp:664
virtual void MonitorResidual(PetscInt it, PetscReal norm, const Vector &r)
Monitor the residual vector r.
Definition: petsc.hpp:675
Vector data type.
Definition: vector.hpp:41
void PlaceArray(PetscScalar *temp_data)
Temporarily replace the data of the PETSc Vec object. To return to the original data array...
Definition: petsc.cpp:310
void FreePrivateContext()
Definition: petsc.cpp:1708
Vector * GlobalVector() const
Returns the global vector in each processor.
Definition: petsc.cpp:273
PetscODESolver(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:2692
Base class for solvers.
Definition: operator.hpp:259
PetscInt GetGlobalNumCols() const
Returns the global number of columns.
Definition: petsc.hpp:263
void SetNatBdrDofs(const Array< int > *natdofs, bool loc=false)
Specify dofs on the natural boundary.
Definition: petsc.hpp:570
Abstract operator.
Definition: operator.hpp:21
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:175
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Definition: petsc.cpp:2043
void operator*=(double s)
Scale all entries by s: A_scaled = s*A.
Definition: petsc.cpp:1034
void SetEssBdrDofs(const Array< int > *essdofs, bool loc=false)
Specify dofs on the essential boundary.
Definition: petsc.hpp:562
void SetTDofs(Array< int > &list)
Sets essential dofs (local, per-process numbering)
Definition: petsc.cpp:1735
void * private_ctx
Private context for solver.
Definition: petsc.hpp:422
void SetUp(PetscInt n)
SetUp the helper object, where n is the size of the solution vector.
Definition: petsc.cpp:1742
void MakeRef(const PetscParMatrix &master)
Makes this object a reference to another PetscParMatrix.
Definition: petsc.cpp:990
virtual ~PetscParMatrix()
Calls PETSc&#39;s destroy function.
Definition: petsc.hpp:220