MFEM  v3.3
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 #include <petsc.h>
23 
24 namespace mfem
25 {
26 
27 class ParFiniteElementSpace;
28 class PetscParMatrix;
29 
30 
31 /// Wrapper for PETSc's vector class
32 class PetscParVector : public Vector
33 {
34 protected:
35  /// The actual PETSc object
36  Vec x;
37 
38  friend class PetscParMatrix;
39  friend class PetscODESolver;
40  friend class PetscLinearSolver;
41  friend class PetscPreconditioner;
42  friend class PetscNonlinearSolver;
43  friend class PetscBDDCSolver;
44 
45  // Set Vector::data and Vector::size from x
46  void _SetDataAndSize_();
47 
48 public:
49  /// Creates vector with given global size and partitioning of the columns.
50  /** Processor P owns columns [col[P],col[P+1]). */
51  PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscInt *col);
52 
53  /** @brief Creates vector with given global size, partitioning of the
54  columns, and data.
55 
56  The data must be allocated and destroyed outside. If @a _data is NULL, a
57  dummy vector without a valid data array will be created. */
58  PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscScalar *_data,
59  PetscInt *col);
60 
61  /// Creates vector compatible with @a y
63 
64  /** @brief Creates vector compatible with the Operator (i.e. in the domain
65  of) @a op or its adjoint. */
66  /** The argument @a allocate determines if the memory is actually allocated
67  to store the data. */
68  explicit PetscParVector(MPI_Comm comm, const Operator &op,
69  bool transpose = false, bool allocate = true);
70 
71  /// Creates vector compatible with (i.e. in the domain of) @a A or @a A^T
72  /** The argument @a allocate determines if the memory is actually allocated
73  to store the data. */
74  explicit PetscParVector(const PetscParMatrix &A, bool transpose = false,
75  bool allocate = true);
76 
77  /// Creates PetscParVector out of PETSc Vec object.
78  /** @param[in] y The PETSc Vec object.
79  @param[in] ref If true, we increase the reference count of @a y. */
80  explicit PetscParVector(Vec y, bool ref=false);
81 
82  /// Create a true dof parallel vector on a given ParFiniteElementSpace
83  explicit PetscParVector(ParFiniteElementSpace *pfes);
84 
85  /// Calls PETSc's destroy function
86  virtual ~PetscParVector();
87 
88  /// Get the associated MPI communicator
89  MPI_Comm GetComm() const { return PetscObjectComm((PetscObject)x); }
90 
91  /// Returns the global number of rows
92  PetscInt GlobalSize() const;
93 
94  /// Conversion function to PETSc's Vec type
95  operator Vec() const { return x; }
96 
97  /// Returns the global vector in each processor
98  Vector* GlobalVector() const;
99 
100  /// Set constant values
101  PetscParVector& operator= (PetscScalar d);
102 
103  /// Define '=' for PETSc vectors.
105 
106  /** @brief Temporarily replace the data of the PETSc Vec object. To return to
107  the original data array, call ResetArray().
108 
109  @note This method calls PETSc's VecPlaceArray() function.
110  @note The inherited Vector::data pointer is not affected by this call. */
111  void PlaceArray(PetscScalar *temp_data);
112 
113  /** @brief Reset the PETSc Vec object to use its default data. Call this
114  method after the use of PlaceArray().
115 
116  @note This method calls PETSc's VecResetArray() function. */
117  void ResetArray();
118 
119  /// Set random values
120  void Randomize(PetscInt seed);
121 
122  /// Prints the vector (to stdout if @a fname is NULL)
123  void Print(const char *fname = NULL, bool binary = false) const;
124 };
125 
126 
127 /// Wrapper for PETSc's matrix class
128 class PetscParMatrix : public Operator
129 {
130 protected:
131  /// The actual PETSc object
132  Mat A;
133 
134  /// Auxiliary vectors for typecasting
135  mutable PetscParVector *X, *Y;
136 
137  /// Initialize with defaults. Does not initialize inherited members.
138  void Init();
139 
140  /// Delete all owned data. Does not perform re-initialization with defaults.
141  void Destroy();
142 
143  /** @brief Creates a wrapper around a mfem::Operator @a op using PETSc's
144  MATSHELL object and returns the Mat in @a B.
145 
146  This does not take any reference to @a op, that should not be destroyed
147  until @a B is needed. */
148  void MakeWrapper(MPI_Comm comm, const Operator* op, Mat *B);
149 
150  /// Convert an mfem::Operator into a Mat @a B; @a op can be destroyed.
151  void ConvertOperator(MPI_Comm comm, const Operator& op, Mat *B,
152  bool assembled);
153 
154  friend class PetscLinearSolver;
155  friend class PetscPreconditioner;
156 
157 private:
158  /// Constructs a block-diagonal Mat object
159  void BlockDiagonalConstructor(MPI_Comm comm, PetscInt *row_starts,
160  PetscInt *col_starts, SparseMatrix *diag,
161  bool assembled, Mat *A);
162 
163 public:
164  /// Create an empty matrix to be used as a reference to an existing matrix.
165  PetscParMatrix();
166 
167  /// Creates PetscParMatrix out of PETSc's Mat.
168  /** @param[in] a The PETSc Mat object.
169  @param[in] ref If true, we increase the reference count of @a a. */
170  PetscParMatrix(Mat a, bool ref=false);
171 
172  /** @brief Convert a HypreParMatrix @a ha to a PetscParMatrix in the given
173  PETSc format @a tid. */
174  /** The supported type ids are: Operator::PETSC_MATAIJ,
175  Operator::PETSC_MATIS, and Operator::PETSC_MATSHELL. */
177 
178  /** @brief Convert an mfem::Operator into a PetscParMatrix in the given PETSc
179  format @a tid. */
180  /** If @a tid is Operator::PETSC_MATSHELL and @a op is not a PetscParMatrix,
181  it converts any mfem::Operator @a op implementing Operator::Mult() and
182  Operator::MultTranspose() into a PetscParMatrix. The Operator @a op
183  should not be deleted while the constructed PetscParMatrix is used.
184 
185  Otherwise, it tries to convert the operator in PETSc's classes.
186 
187  In particular, if @a op is a BlockOperator, then a MATNEST Mat object is
188  created using @a tid as the type for the blocks. */
189  PetscParMatrix(MPI_Comm comm, const Operator *op, Operator::Type tid);
190 
191  /// Creates block-diagonal square parallel matrix.
192  /** The block-diagonal is given by @a diag which must be in CSR format
193  (finalized). The new PetscParMatrix does not take ownership of any of the
194  input arrays. The type id @a tid can be either PETSC_MATAIJ (parallel
195  distributed CSR) or PETSC_MATIS. */
196  PetscParMatrix(MPI_Comm comm, PetscInt glob_size, PetscInt *row_starts,
197  SparseMatrix *diag, Operator::Type tid);
198 
199  /// Creates block-diagonal rectangular parallel matrix.
200  /** The block-diagonal is given by @a diag which must be in CSR format
201  (finalized). The new PetscParMatrix does not take ownership of any of the
202  input arrays. The type id @a tid can be either PETSC_MATAIJ (parallel
203  distributed CSR) or PETSC_MATIS. */
204  PetscParMatrix(MPI_Comm comm, PetscInt global_num_rows,
205  PetscInt global_num_cols, PetscInt *row_starts,
206  PetscInt *col_starts, SparseMatrix *diag,
207  Operator::Type tid);
208 
209  /// Calls PETSc's destroy function.
210  virtual ~PetscParMatrix() { Destroy(); }
211 
212  /// @name Assignment operators
213  ///@{
217  ///@}
218 
219  /// Matvec: @a y = @a a A @a x + @a b @a y.
220  void Mult(double a, const Vector &x, double b, Vector &y) const;
221 
222  /// Matvec transpose: @a y = @a a A^T @a x + @a b @a y.
223  void MultTranspose(double a, const Vector &x, double b, Vector &y) const;
224 
225  virtual void Mult(const Vector &x, Vector &y) const
226  { Mult(1.0, x, 0.0, y); }
227 
228  virtual void MultTranspose(const Vector &x, Vector &y) const
229  { MultTranspose(1.0, x, 0.0, y); }
230 
231  /// Get the associated MPI communicator
232  MPI_Comm GetComm() const { return PetscObjectComm((PetscObject)A); }
233 
234  /// Typecasting to PETSc's Mat type
235  operator Mat() const { return A; }
236 
237  /// Returns the local number of rows
238  PetscInt GetNumRows() const;
239 
240  /// Returns the local number of columns
241  PetscInt GetNumCols() const;
242 
243  /// Returns the global number of rows
244  PetscInt M() const;
245 
246  /// Returns the global number of columns
247  PetscInt N() const;
248 
249  /// Returns the global number of rows
250  PetscInt GetGlobalNumRows() const { return M(); }
251 
252  /// Returns the global number of columns
253  PetscInt GetGlobalNumCols() const { return N(); }
254 
255  /// Returns the number of nonzeros.
256  /** Differently from HYPRE, this call is collective on the communicator,
257  as this number is not stored inside PETSc, but needs to be computed. */
258  PetscInt NNZ() const;
259 
260  /// Returns the inner vector in the domain of A (it creates it if needed)
261  PetscParVector* GetX() const;
262 
263  /// Returns the inner vector in the range of A (it creates it if needed)
264  PetscParVector* GetY() const;
265 
266  /// Returns the transpose of the PetscParMatrix.
267  /** If @a action is false, the new matrix is constructed with the PETSc
268  function MatTranspose().
269  If @a action is true, then the matrix is not actually transposed.
270  Instead, an object that behaves like the transpose is returned. */
271  PetscParMatrix* Transpose(bool action = false);
272 
273  /// Prints the matrix (to stdout if fname is NULL)
274  void Print(const char *fname = NULL, bool binary = false) const;
275 
276  /// Scale all entries by s: A_scaled = s*A.
277  void operator*=(double s);
278 
279  /** @brief Eliminate rows and columns from the matrix, and rows from the
280  vector @a B. Modify @a B with the BC values in @a X. */
281  void EliminateRowsCols(const Array<int> &rows_cols, const HypreParVector &X,
282  HypreParVector &B);
283 
284  /** @brief Eliminate rows and columns from the matrix and store the
285  eliminated elements in a new matrix Ae (returned).
286 
287  The sum of the modified matrix and the returned matrix, Ae, is equal to
288  the original matrix. */
289  PetscParMatrix* EliminateRowsCols(const Array<int> &rows_cols);
290 
291  /// Makes this object a reference to another PetscParMatrix
292  void MakeRef(const PetscParMatrix &master);
293 
294  /** @brief Release the PETSc Mat object. If @a dereference is true, decrement
295  the refcount of the Mat object. */
296  Mat ReleaseMat(bool dereference);
297 
298  Type GetType() const;
299 };
300 
301 
302 /// Returns the matrix Rt^t * A * P
303 PetscParMatrix * RAP(PetscParMatrix *Rt, PetscParMatrix *A, PetscParMatrix *P);
304 
305 /// Returns the matrix P^t * A * P
306 PetscParMatrix * RAP(PetscParMatrix *A, PetscParMatrix *P);
307 
308 /** @brief Eliminate essential BC specified by @a ess_dof_list from the solution
309  @a X to the r.h.s. @a B.
310 
311  Here, @a A is a matrix with eliminated BC, while @a Ae is such that
312  (@a A + @a Ae) is the original (Neumann) matrix before elimination. */
313 void EliminateBC(PetscParMatrix &A, PetscParMatrix &Ae,
314  const Array<int> &ess_dof_list, const Vector &X, Vector &B);
315 
316 
317 class PetscSolverMonitor;
318 
319 
320 /// Abstract class for PETSc's solvers.
322 {
323 protected:
324  /// Boolean to handle SetFromOptions calls.
325  mutable bool clcustom;
326 
327  /// The actual PETSc object (KSP, PC, SNES or TS).
328  PetscObject obj;
329 
330  /// The class id of the actual PETSc object
331  PetscClassId cid;
332 
333  /// Right-hand side and solution vector
334  mutable PetscParVector *B, *X;
335 
336  /// Monitor context
338 
339  /// Boolean to handle SetOperator calls.
340  mutable bool operatorset;
341 
342 public:
343  /// Construct an empty PetscSolver. Initialize protected objects to NULL.
344  PetscSolver();
345 
346  /// Destroy the PetscParVectors allocated (if any).
347  virtual ~PetscSolver();
348 
349  /** @name Update of PETSc options.
350  The following Set methods can be used to update the internal PETSc
351  options.
352  @note They will be overwritten by the options in the input PETSc file. */
353  ///@{
354  void SetTol(double tol);
355  void SetRelTol(double tol);
356  void SetAbsTol(double tol);
357  void SetMaxIter(int max_iter);
358  void SetPrintLevel(int plev);
359  ///@}
360 
361  /// Customize object with options set
362  /** If @a customize is false, it disables any options customization. */
363  void Customize(bool customize = true) const;
364  int GetConverged();
365  int GetNumIterations();
366  double GetFinalNorm();
367 
368  /// Sets user-defined monitoring routine.
369  void SetMonitor(PetscSolverMonitor *ctx);
370 
371  /// Conversion function to PetscObject.
372  operator PetscObject() const { return obj; }
373 };
374 
375 
376 /// Abstract class for PETSc's linear solvers.
377 class PetscLinearSolver : public PetscSolver, public Solver
378 {
379 private:
380  /// Internal flag to handle HypreParMatrix conversion or not.
381  bool wrap;
382 
383 public:
384  PetscLinearSolver(MPI_Comm comm, const std::string &prefix = std::string());
386  const std::string &prefix = std::string());
387  /// Constructs a solver using a HypreParMatrix.
388  /** If @a wrap is true, then the MatMult ops of HypreParMatrix are wrapped.
389  No preconditioner can be automatically constructed from PETSc. If
390  @a wrap is false, the HypreParMatrix is converted into PETSc format. */
391  PetscLinearSolver(const HypreParMatrix &A, bool wrap = true,
392  const std::string &prefix = std::string());
393  virtual ~PetscLinearSolver();
394 
395  virtual void SetOperator(const Operator &op);
396  // not inherited
397  virtual void SetPreconditioner(Solver &precond);
398 
399  /// Application of the solver.
400  virtual void Mult(const Vector &b, Vector &x) const;
401 
402  /// Conversion function to PETSc's KSP type.
403  operator KSP() const { return (KSP)obj; }
404 };
405 
406 
408 {
409 public:
410  PetscPCGSolver(MPI_Comm comm, const std::string &prefix = std::string());
411  PetscPCGSolver(PetscParMatrix &A, const std::string &prefix = std::string());
412  PetscPCGSolver(HypreParMatrix &A,bool wrap=true,
413  const std::string &prefix = std::string());
414 };
415 
416 
417 /// Abstract class for PETSc's preconditioners.
418 class PetscPreconditioner : public PetscSolver, public Solver
419 {
420 public:
421  PetscPreconditioner(MPI_Comm comm,
422  const std::string &prefix = std::string());
424  const std::string &prefix = std::string());
425  PetscPreconditioner(MPI_Comm comm, Operator &op,
426  const std::string &prefix = std::string());
427  virtual ~PetscPreconditioner();
428 
429  virtual void SetOperator(const Operator &op);
430 
431  /// Application of the preconditioner.
432  virtual void Mult(const Vector &b, Vector &x) const;
433 
434  /// Conversion function to PETSc's PC type.
435  operator PC() const { return (PC)obj; }
436 };
437 
438 
439 /// Auxiliary class for BDDC customization.
441 {
442 protected:
448  friend class PetscBDDCSolver;
449 
450 public:
452  nat_dof(NULL), nat_dof_local(false)
453  {}
455 
456  /// Specify dofs on the essential boundary.
457  /** If @a loc is false, it is a list of true dofs in local ordering.
458  If @a loc is true, it is a marker for Vdofs in local ordering. */
459  void SetEssBdrDofs(const Array<int> *essdofs, bool loc = false)
460  {
461  ess_dof = essdofs;
462  ess_dof_local = loc;
463  }
464  /// Specify dofs on the natural boundary.
465  /** If @a loc is false, it is a list of true dofs in local ordering.
466  If @a loc is true, it is a marker for Vdofs in local ordering. */
467  void SetNatBdrDofs(const Array<int> *natdofs, bool loc = false)
468  {
469  nat_dof = natdofs;
470  nat_dof_local = loc;
471  }
472 };
473 
474 
476 {
477 private:
478  void BDDCSolverConstructor(const PetscBDDCSolverParams &opts);
479 
480 public:
481  PetscBDDCSolver(MPI_Comm comm, Operator &op,
483  const std::string &prefix = std::string());
486  const std::string &prefix = std::string());
487 };
488 
489 
491 {
492 public:
493  PetscFieldSplitSolver(MPI_Comm comm, Operator &op,
494  const std::string &prefix = std::string());
495 };
496 
497 
498 /// Abstract class for PETSc's nonlinear solvers.
500 {
501 public:
502  PetscNonlinearSolver(MPI_Comm comm,
503  const std::string &prefix = std::string());
504  PetscNonlinearSolver(MPI_Comm comm, Operator &op,
505  const std::string &prefix = std::string());
506  virtual ~PetscNonlinearSolver();
507 
508  /// Specification of the nonlinear operator.
509  virtual void SetOperator(const Operator &op);
510 
511  /// Application of the solver.
512  virtual void Mult(const Vector &b, Vector &x) const;
513 
514  /// Conversion function to PETSc's SNES type.
515  operator SNES() const { return (SNES)obj; }
516 };
517 
518 
519 /// Abstract class for PETSc's ODE solvers.
520 class PetscODESolver : public PetscSolver, public ODESolver
521 {
522 public:
523  PetscODESolver(MPI_Comm comm, const std::string &prefix = std::string());
524  virtual ~PetscODESolver();
525 
526  virtual void Init(TimeDependentOperator &f_);
527 
528  virtual void Step(Vector &x, double &t, double &dt);
529  virtual void Run(Vector &x, double &t, double &dt, double t_final);
530 
531  /// Conversion function to PETSc's TS type.
532  operator TS() const { return (TS)obj; }
533 };
534 
535 
536 /// Abstract class for monitoring PETSc's solvers.
538 {
539 public:
540  bool mon_sol;
541  bool mon_res;
542  PetscSolverMonitor(bool monitor_sol = false, bool monitor_res = true)
543  : mon_sol(monitor_sol), mon_res(monitor_res) {}
544  virtual ~PetscSolverMonitor() {}
545 
546  /// Monitor the solution vector x
547  virtual void MonitorSolution(PetscInt it, PetscReal norm, const Vector &x)
548  {
549  MFEM_ABORT("MonitorSolution() is not implemented!")
550  }
551 
552  /// Monitor the residual vector r
553  virtual void MonitorResidual(PetscInt it, PetscReal norm, const Vector &r)
554  {
555  MFEM_ABORT("MonitorResidual() is not implemented!")
556  }
557 };
558 
559 } // namespace mfem
560 
561 #endif // MFEM_USE_MPI
562 #endif // MFEM_USE_PETSC
563 
564 #endif
virtual void SetPreconditioner(Solver &precond)
Definition: petsc.cpp:1600
void SetPrintLevel(int plev)
Definition: petsc.cpp:1293
PetscParVector * B
Right-hand side and solution vector.
Definition: petsc.hpp:334
void Print(const char *fname=NULL, bool binary=false) const
Prints the matrix (to stdout if fname is NULL)
Definition: petsc.cpp:978
virtual void SetOperator(const Operator &op)
Specification of the nonlinear operator.
Definition: petsc.cpp:2186
Abstract class for PETSc&#39;s preconditioners.
Definition: petsc.hpp:418
PetscParMatrix & operator+=(const PetscParMatrix &B)
Definition: petsc.cpp:463
PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscInt *col)
Creates vector with given global size and partitioning of the columns.
Definition: petsc.cpp:126
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: petsc.cpp:1540
bool clcustom
Boolean to handle SetFromOptions calls.
Definition: petsc.hpp:325
double GetFinalNorm()
Definition: petsc.cpp:1479
Wrapper for PETSc&#39;s matrix class.
Definition: petsc.hpp:128
const Array< int > * nat_dof
Definition: petsc.hpp:446
Abstract class for PETSc&#39;s linear solvers.
Definition: petsc.hpp:377
Vec x
The actual PETSc object.
Definition: petsc.hpp:36
Abstract class for PETSc&#39;s solvers.
Definition: petsc.hpp:321
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:2368
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: petsc.hpp:225
ParFiniteElementSpace * fespace
Definition: petsc.hpp:443
Base abstract class for time dependent operators.
Definition: operator.hpp:140
PetscInt GetNumCols() const
Returns the local number of columns.
Definition: petsc.cpp:331
void Mult(double a, const Vector &x, double b, Vector &y) const
Matvec: y = a A x + b y.
Definition: petsc.cpp:945
PetscBDDCSolver(MPI_Comm comm, Operator &op, const PetscBDDCSolverParams &opts=PetscBDDCSolverParams(), const std::string &prefix=std::string())
Definition: petsc.cpp:2110
virtual ~PetscSolver()
Destroy the PetscParVectors allocated (if any).
Definition: petsc.cpp:1205
PetscNonlinearSolver(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:2155
PetscInt GetGlobalNumRows() const
Returns the global number of rows.
Definition: petsc.hpp:250
Type GetType() const
Definition: petsc.cpp:1149
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:2343
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:359
PetscPreconditioner(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:1697
PetscClassId cid
The class id of the actual PETSc object.
Definition: petsc.hpp:331
Abstract parallel finite element space.
Definition: pfespace.hpp:28
void SetRelTol(double tol)
Definition: petsc.cpp:1216
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:228
PetscPCGSolver(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:1667
void Destroy()
Delete all owned data. Does not perform re-initialization with defaults.
Definition: petsc.cpp:813
void SetMonitor(PetscSolverMonitor *ctx)
Sets user-defined monitoring routine.
Definition: petsc.cpp:1374
void SetMaxIter(int max_iter)
Definition: petsc.cpp:1266
Abstract class for PETSc&#39;s ODE solvers.
Definition: petsc.hpp:520
Wrapper for PETSc&#39;s vector class.
Definition: petsc.hpp:32
void Customize(bool customize=true) const
Customize object with options set.
Definition: petsc.cpp:1380
PetscInt M() const
Returns the global number of rows.
Definition: petsc.cpp:338
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Definition: petsc.cpp:2227
PetscParVector * Y
Definition: petsc.hpp:135
virtual ~PetscLinearSolver()
Definition: petsc.cpp:1657
PetscInt GetNumRows() const
Returns the local number of rows.
Definition: petsc.cpp:324
void Randomize(PetscInt seed)
Set random values.
Definition: petsc.cpp:285
void Print(const char *fname=NULL, bool binary=false) const
Prints the vector (to stdout if fname is NULL)
Definition: petsc.cpp:297
void EliminateBC(HypreParMatrix &A, HypreParMatrix &Ae, const Array< int > &ess_dof_list, const Vector &X, Vector &B)
Definition: hypre.cpp:1435
void ResetArray()
Reset the PETSc Vec object to use its default data. Call this method after the use of PlaceArray()...
Definition: petsc.cpp:280
PetscParMatrix * Transpose(bool action=false)
Returns the transpose of the PetscParMatrix.
Definition: petsc.cpp:926
PetscObject obj
The actual PETSc object (KSP, PC, SNES or TS).
Definition: petsc.hpp:328
Abstract class for monitoring PETSc&#39;s solvers.
Definition: petsc.hpp:537
Data type sparse matrix.
Definition: sparsemat.hpp:38
Auxiliary class for BDDC customization.
Definition: petsc.hpp:440
virtual ~PetscPreconditioner()
Definition: petsc.cpp:1806
MPI_Comm GetComm() const
Get the associated MPI communicator.
Definition: petsc.hpp:232
HypreParMatrix * RAP(HypreParMatrix *A, HypreParMatrix *P)
Returns the matrix P^t * A * P.
Definition: hypre.cpp:1385
PetscParMatrix & operator=(const PetscParMatrix &B)
Definition: petsc.cpp:447
virtual ~PetscParVector()
Calls PETSc&#39;s destroy function.
Definition: petsc.cpp:144
PetscFieldSplitSolver(MPI_Comm comm, Operator &op, const std::string &prefix=std::string())
Definition: petsc.cpp:2119
PetscParMatrix()
Create an empty matrix to be used as a reference to an existing matrix.
Definition: petsc.cpp:366
Abstract class for PETSc&#39;s nonlinear solvers.
Definition: petsc.hpp:499
int GetNumIterations()
Definition: petsc.cpp:1446
PetscLinearSolver(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:1506
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:72
Type
Enumeration defining IDs for some classes derived from Operator.
Definition: operator.hpp:123
PetscInt NNZ() const
Returns the number of nonzeros.
Definition: petsc.cpp:352
virtual void Mult(const Vector &b, Vector &x) const
Application of the preconditioner.
Definition: petsc.cpp:1776
Mat A
The actual PETSc object.
Definition: petsc.hpp:132
PetscInt N() const
Returns the global number of columns.
Definition: petsc.cpp:345
PetscParVector * GetY() const
Returns the inner vector in the range of A (it creates it if needed)
Definition: petsc.cpp:916
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:614
bool operatorset
Boolean to handle SetOperator calls.
Definition: petsc.hpp:340
PetscParVector * X
Auxiliary vectors for typecasting.
Definition: petsc.hpp:135
void MultTranspose(double a, const Vector &x, double b, Vector &y) const
Matvec transpose: y = a A^T x + b y.
Definition: petsc.cpp:961
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
Definition: petsc.cpp:2277
virtual ~PetscSolverMonitor()
Definition: petsc.hpp:544
virtual ~PetscNonlinearSolver()
Definition: petsc.cpp:2178
virtual ~PetscODESolver()
Definition: petsc.cpp:2269
int GetConverged()
Definition: petsc.cpp:1413
PetscSolver()
Construct an empty PetscSolver. Initialize protected objects to NULL.
Definition: petsc.cpp:1196
Mat ReleaseMat(bool dereference)
Release the PETSc Mat object. If dereference is true, decrement the refcount of the Mat object...
Definition: petsc.cpp:1136
virtual void MonitorSolution(PetscInt it, PetscReal norm, const Vector &x)
Monitor the solution vector x.
Definition: petsc.hpp:547
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: petsc.cpp:1732
void SetSpace(ParFiniteElementSpace *fe)
Definition: petsc.hpp:454
MPI_Comm GetComm() const
Get the associated MPI communicator.
Definition: petsc.hpp:89
PetscInt GlobalSize() const
Returns the global number of rows.
Definition: petsc.cpp:119
PetscParVector * X
Definition: petsc.hpp:334
const Array< int > * ess_dof
Definition: petsc.hpp:444
void _SetDataAndSize_()
Definition: petsc.cpp:108
void SetAbsTol(double tol)
Definition: petsc.cpp:1241
void EliminateRowsCols(const Array< int > &rows_cols, const HypreParVector &X, HypreParVector &B)
Eliminate rows and columns from the matrix, and rows from the vector B. Modify B with the BC values i...
Definition: petsc.cpp:1129
PetscParVector * GetX() const
Returns the inner vector in the domain of A (it creates it if needed)
Definition: petsc.cpp:906
void SetTol(double tol)
Definition: petsc.cpp:1211
PetscParVector & operator=(PetscScalar d)
Set constant values.
Definition: petsc.cpp:263
PetscSolverMonitor(bool monitor_sol=false, bool monitor_res=true)
Definition: petsc.hpp:542
virtual void MonitorResidual(PetscInt it, PetscReal norm, const Vector &r)
Monitor the residual vector r.
Definition: petsc.hpp:553
Vector data type.
Definition: vector.hpp:36
void PlaceArray(PetscScalar *temp_data)
Temporarily replace the data of the PETSc Vec object. To return to the original data array...
Definition: petsc.cpp:275
Vector * GlobalVector() const
Returns the global vector in each processor.
Definition: petsc.cpp:238
PetscODESolver(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:2250
Base class for solvers.
Definition: operator.hpp:257
PetscInt GetGlobalNumCols() const
Returns the global number of columns.
Definition: petsc.hpp:253
PetscSolverMonitor * monitor_ctx
Monitor context.
Definition: petsc.hpp:337
void SetNatBdrDofs(const Array< int > *natdofs, bool loc=false)
Specify dofs on the natural boundary.
Definition: petsc.hpp:467
Abstract operator.
Definition: operator.hpp:21
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:174
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Definition: petsc.cpp:1624
void operator*=(double s)
Scale all entries by s: A_scaled = s*A.
Definition: petsc.cpp:940
void SetEssBdrDofs(const Array< int > *essdofs, bool loc=false)
Specify dofs on the essential boundary.
Definition: petsc.hpp:459
void ConvertOperator(MPI_Comm comm, const Operator &op, Mat *B, bool assembled)
Convert an mfem::Operator into a Mat B; op can be destroyed.
Definition: petsc.cpp:635
void MakeRef(const PetscParMatrix &master)
Makes this object a reference to another PetscParMatrix.
Definition: petsc.cpp:896
virtual ~PetscParMatrix()
Calls PETSc&#39;s destroy function.
Definition: petsc.hpp:210