MFEM  v4.1.0
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) 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 // Author: Stefano Zampini <stefano.zampini@gmail.com>
13 
14 #ifndef MFEM_PETSC
15 #define MFEM_PETSC
16 
17 #include "../config/config.hpp"
18 
19 #ifdef MFEM_USE_PETSC
20 #ifdef MFEM_USE_MPI
21 
22 #include <limits>
23 
24 #include "handle.hpp"
25 #include "hypre.hpp"
26 #include "ode.hpp"
27 
28 #include "petscconf.h"
29 #if !defined(PETSC_USE_REAL_DOUBLE)
30 #error "MFEM does not work with PETSc compiled without double precision"
31 #endif
32 #if defined(PETSC_USE_COMPLEX)
33 #error "MFEM does not work with PETSc compiled with complex numbers support"
34 #endif
35 #if defined(PETSC_USE_64BIT_INDICES) && !defined(HYPRE_BIGINT)
36 #error "Mismatch between HYPRE (32bit) and PETSc (64bit) integer types"
37 #endif
38 #if !defined(PETSC_USE_64BIT_INDICES) && defined(HYPRE_BIGINT)
39 #error "Mismatch between HYPRE (64bit) and PETSc (32bit) integer types"
40 #endif
41 
42 #include "petscversion.h"
43 #if PETSC_VERSION_GE(3,12,0)
44 #include "petscsystypes.h"
45 #else
46 typedef HYPRE_Int PetscInt;
47 typedef double PetscScalar;
48 typedef double PetscReal;
49 typedef int PetscClassId;
50 typedef struct _p_PetscObject *PetscObject;
51 #endif
52 
53 // forward declarations of PETSc objects
54 typedef struct _p_Vec *Vec;
55 typedef struct _p_Mat *Mat;
56 typedef struct _p_KSP *KSP;
57 typedef struct _p_PC *PC;
58 typedef struct _p_SNES *SNES;
59 typedef struct _p_TS *TS;
60 
61 
62 namespace mfem
63 {
64 
65 /// Convenience functions to initialize/finalize PETSc
66 void MFEMInitializePetsc();
67 void MFEMInitializePetsc(int*,char***);
68 void MFEMInitializePetsc(int*,char***,const char[],const char[]);
69 void MFEMFinalizePetsc();
70 
71 class ParFiniteElementSpace;
72 class PetscParMatrix;
73 
74 /// Wrapper for PETSc's vector class
75 class PetscParVector : public Vector
76 {
77 protected:
78  /// The actual PETSc object
79  Vec x;
80 
81  friend class PetscParMatrix;
82  friend class PetscODESolver;
83  friend class PetscLinearSolver;
84  friend class PetscPreconditioner;
85  friend class PetscNonlinearSolver;
86  friend class PetscBDDCSolver;
87 
88  // Set Vector::data and Vector::size from x
89  void _SetDataAndSize_();
90 
91 public:
92  /// Creates vector with given global size and partitioning of the columns.
93  /** If @a col is provided, processor P owns columns [col[P],col[P+1]).
94  Otherwise, PETSc decides the partitioning */
95  PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscInt *col = NULL);
96 
97  /** @brief Creates vector with given global size, partitioning of the
98  columns, and data.
99 
100  The data must be allocated and destroyed outside. If @a _data is NULL, a
101  dummy vector without a valid data array will be created. */
102  PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscScalar *_data,
103  PetscInt *col);
104 
105  /// Creates vector compatible with @a y
106  PetscParVector(const PetscParVector &y);
107 
108  /** @brief Creates a PetscParVector from a Vector
109  @param[in] comm MPI communicator on which the new object lives
110  @param[in] _x The mfem Vector (data is not shared)
111  @param[in] copy Whether to copy the data in _x or not */
112  PetscParVector(MPI_Comm comm, const Vector &_x, bool copy = false);
113 
114  /** @brief Creates vector compatible with the Operator (i.e. in the domain
115  of) @a op or its adjoint. */
116  /** The argument @a allocate determines if the memory is actually allocated
117  to store the data. */
118  explicit PetscParVector(MPI_Comm comm, const Operator &op,
119  bool transpose = false, bool allocate = true);
120 
121  /// Creates vector compatible with (i.e. in the domain of) @a A or @a A^T
122  /** The argument @a allocate determines if the memory is actually allocated
123  to store the data. */
124  explicit PetscParVector(const PetscParMatrix &A, bool transpose = false,
125  bool allocate = true);
126 
127  /// Creates PetscParVector out of PETSc Vec object.
128  /** @param[in] y The PETSc Vec object.
129  @param[in] ref If true, we increase the reference count of @a y. */
130  explicit PetscParVector(Vec y, bool ref=false);
131 
132  /// Create a true dof parallel vector on a given ParFiniteElementSpace
133  explicit PetscParVector(ParFiniteElementSpace *pfes);
134 
135  /// Calls PETSc's destroy function
136  virtual ~PetscParVector();
137 
138  /// Get the associated MPI communicator
139  MPI_Comm GetComm() const;
140 
141  /// Returns the global number of rows
142  PetscInt GlobalSize() const;
143 
144  /// Typecasting to PETSc's Vec type
145  operator Vec() const { return x; }
146 
147  /// Typecasting to PETSc object
148  operator PetscObject() const { return (PetscObject)x; }
149 
150  /// Returns the global vector in each processor
151  Vector* GlobalVector() const;
152 
153  /// Set constant values
155 
156  /** @brief Set values in a vector.
157 
158  @note any process can insert in any location
159  @note This is a collective operation, so all process needs to call it */
161 
162  /** @brief Add values in a vector.
163 
164  @note any process can add to any location
165  @note This is a collective operation, so all process needs to call it */
167 
168  /// Define operators for PETSc vectors.
174 
175  /** @brief Temporarily replace the data of the PETSc Vec object. To return to
176  the original data array, call ResetArray().
177 
178  @note This method calls PETSc's VecPlaceArray() function.
179  @note The inherited Vector::data pointer is not affected by this call. */
180  void PlaceArray(PetscScalar *temp_data);
181 
182  /** @brief Reset the PETSc Vec object to use its default data. Call this
183  method after the use of PlaceArray().
184 
185  @note This method calls PETSc's VecResetArray() function. */
186  void ResetArray();
187 
188  /// Set random values
189  void Randomize(PetscInt seed = 0);
190 
191  /// Prints the vector (to stdout if @a fname is NULL)
192  void Print(const char *fname = NULL, bool binary = false) const;
193 };
194 
195 
196 /// Wrapper for PETSc's matrix class
197 class PetscParMatrix : public Operator
198 {
199 protected:
200  /// The actual PETSc object
202 
203  /// Auxiliary vectors for typecasting
204  mutable PetscParVector *X, *Y;
205 
206  /// Initialize with defaults. Does not initialize inherited members.
207  void Init();
208 
209  /// Delete all owned data. Does not perform re-initialization with defaults.
210  void Destroy();
211 
212  /** @brief Creates a wrapper around a mfem::Operator @a op using PETSc's
213  MATSHELL object and returns the Mat in @a B.
214 
215  This does not take any reference to @a op, that should not be destroyed
216  until @a B is needed. */
217  void MakeWrapper(MPI_Comm comm, const Operator* op, Mat *B);
218 
219  /// Convert an mfem::Operator into a Mat @a B; @a op can be destroyed unless
220  /// tid == PETSC_MATSHELL or tid == PETSC_MATHYPRE
221  /// if op is a BlockOperator, the operator type is relevant to the individual
222  /// blocks
223  void ConvertOperator(MPI_Comm comm, const Operator& op, Mat *B,
224  Operator::Type tid);
225 
226  friend class PetscLinearSolver;
227  friend class PetscPreconditioner;
228 
229 private:
230  /// Constructs a block-diagonal Mat object
231  void BlockDiagonalConstructor(MPI_Comm comm, PetscInt *row_starts,
232  PetscInt *col_starts, SparseMatrix *diag,
233  bool assembled, Mat *A);
234 
235 public:
236  /// Create an empty matrix to be used as a reference to an existing matrix.
237  PetscParMatrix();
238 
239  /// Creates PetscParMatrix out of PETSc's Mat.
240  /** @param[in] a The PETSc Mat object.
241  @param[in] ref If true, we increase the reference count of @a a. */
242  PetscParMatrix(Mat a, bool ref=false);
243 
244  /** @brief Convert a PetscParMatrix @a pa with a new PETSc format @a tid.
245  Note that if @a pa is already a PetscParMatrix of the same type as
246  @a tid, the resulting PetscParMatrix will share the same Mat object */
247  explicit PetscParMatrix(const PetscParMatrix *pa, Operator::Type tid);
248 
249  /** @brief Creates a PetscParMatrix extracting the submatrix of @a A with
250  @a rows row indices and @a cols column indices */
252  const mfem::Array<PetscInt>& cols);
253 
254  /** @brief Convert a HypreParMatrix @a ha to a PetscParMatrix in the given
255  PETSc format @a tid. */
256  /** The supported type ids are: Operator::PETSC_MATAIJ,
257  Operator::PETSC_MATIS, Operator::PETSC_MATSHELL and
258  Operator::PETSC_MATHYPRE
259  @a ha can be destroyed unless tid == PETSC_MATSHELL or
260  tid == PETSC_MATHYPRE */
261  explicit PetscParMatrix(const HypreParMatrix *ha,
263 
264  /** @brief Convert a SparseMatrix @a ha to a PetscParMatrix in the given
265  PETSc format @a tid. */
266  explicit PetscParMatrix(const SparseMatrix *sa,
268 
269  /** @brief Convert an mfem::Operator into a PetscParMatrix in the given PETSc
270  format @a tid. */
271  /** If @a tid is Operator::PETSC_MATSHELL and @a op is not a PetscParMatrix,
272  it converts any mfem::Operator @a op implementing Operator::Mult() and
273  Operator::MultTranspose() into a PetscParMatrix. The Operator @a op
274  should not be deleted while the constructed PetscParMatrix is used.
275 
276  Otherwise, it tries to convert the operator in PETSc's classes.
277  @a op cannot be destroyed if tid == PETSC_MATHYPRE.
278 
279  In particular, if @a op is a BlockOperator, then a MATNEST Mat object is
280  created using @a tid as the type for the blocks.
281  Note that if @a op is already a PetscParMatrix of the same type as
282  @a tid, the resulting PetscParMatrix will share the same Mat object */
283  PetscParMatrix(MPI_Comm comm, const Operator *op,
285 
286  /// Creates block-diagonal square parallel matrix.
287  /** The block-diagonal is given by @a diag which must be in CSR format
288  (finalized). The new PetscParMatrix does not take ownership of any of the
289  input arrays. The type id @a tid can be either PETSC_MATAIJ (parallel
290  distributed CSR) or PETSC_MATIS. */
291  PetscParMatrix(MPI_Comm comm, PetscInt glob_size, PetscInt *row_starts,
292  SparseMatrix *diag, Operator::Type tid);
293 
294  /// Creates block-diagonal rectangular parallel matrix.
295  /** The block-diagonal is given by @a diag which must be in CSR format
296  (finalized). The new PetscParMatrix does not take ownership of any of the
297  input arrays. The type id @a tid can be either PETSC_MATAIJ (parallel
298  distributed CSR) or PETSC_MATIS. */
299  PetscParMatrix(MPI_Comm comm, PetscInt global_num_rows,
300  PetscInt global_num_cols, PetscInt *row_starts,
301  PetscInt *col_starts, SparseMatrix *diag,
302  Operator::Type tid);
303 
304  /// Calls PETSc's destroy function.
305  virtual ~PetscParMatrix() { Destroy(); }
306 
307  /// Replace the inner Mat Object. The reference count of newA is increased
308  void SetMat(Mat newA);
309 
310  /// @name Assignment operators
311  ///@{
316  ///@}
317 
318  /// Matvec: @a y = @a a A @a x + @a b @a y.
319  void Mult(double a, const Vector &x, double b, Vector &y) const;
320 
321  /// Matvec transpose: @a y = @a a A^T @a x + @a b @a y.
322  void MultTranspose(double a, const Vector &x, double b, Vector &y) const;
323 
324  virtual void Mult(const Vector &x, Vector &y) const
325  { Mult(1.0, x, 0.0, y); }
326 
327  virtual void MultTranspose(const Vector &x, Vector &y) const
328  { MultTranspose(1.0, x, 0.0, y); }
329 
330  /// Get the associated MPI communicator
331  MPI_Comm GetComm() const;
332 
333  /// Typecasting to PETSc's Mat type
334  operator Mat() const { return A; }
335 
336  /// Typecasting to PETSc object
337  operator PetscObject() const { return (PetscObject)A; }
338 
339  /// Returns the global index of the first local row
340  PetscInt GetRowStart() const;
341 
342  /// Returns the global index of the first local column
343  PetscInt GetColStart() const;
344 
345  /// Returns the local number of rows
346  PetscInt GetNumRows() const;
347 
348  /// Returns the local number of columns
349  PetscInt GetNumCols() const;
350 
351  /// Returns the global number of rows
352  PetscInt M() const;
353 
354  /// Returns the global number of columns
355  PetscInt N() const;
356 
357  /// Returns the global number of rows
358  PetscInt GetGlobalNumRows() const { return M(); }
359 
360  /// Returns the global number of columns
361  PetscInt GetGlobalNumCols() const { return N(); }
362 
363  /// Returns the number of nonzeros.
364  /** Differently from HYPRE, this call is collective on the communicator,
365  as this number is not stored inside PETSc, but needs to be computed. */
366  PetscInt NNZ() const;
367 
368  /// Returns the inner vector in the domain of A (it creates it if needed)
369  PetscParVector* GetX() const;
370 
371  /// Returns the inner vector in the range of A (it creates it if needed)
372  PetscParVector* GetY() const;
373 
374  /// Returns the transpose of the PetscParMatrix.
375  /** If @a action is false, the new matrix is constructed with the PETSc
376  function MatTranspose().
377  If @a action is true, then the matrix is not actually transposed.
378  Instead, an object that behaves like the transpose is returned. */
379  PetscParMatrix* Transpose(bool action = false);
380 
381  /// Prints the matrix (to stdout if fname is NULL)
382  void Print(const char *fname = NULL, bool binary = false) const;
383 
384  /// Scale all entries by s: A_scaled = s*A.
385  void operator*=(double s);
386 
387  /** @brief Eliminate rows and columns from the matrix, and rows from the
388  vector @a B. Modify @a B with the BC values in @a X. Put @a diag
389  on the diagonal corresponding to eliminated entries */
390  void EliminateRowsCols(const Array<int> &rows_cols, const PetscParVector &X,
391  PetscParVector &B, double diag = 1.);
392  void EliminateRowsCols(const Array<int> &rows_cols, const HypreParVector &X,
393  HypreParVector &B, double diag = 1.);
394 
395  /** @brief Eliminate rows and columns from the matrix and store the
396  eliminated elements in a new matrix Ae (returned).
397 
398  The sum of the modified matrix and the returned matrix, Ae, is equal to
399  the original matrix. */
400  PetscParMatrix* EliminateRowsCols(const Array<int> &rows_cols);
401 
402  /// Scale the local row i by s(i).
403  void ScaleRows(const Vector & s);
404 
405  /// Scale the local col i by s(i).
406  void ScaleCols(const Vector & s);
407 
408  /// Shift diagonal by a constant
409  void Shift(double s);
410 
411  /// Shift diagonal by a vector
412  void Shift(const Vector & s);
413 
414  /** @brief Eliminate only the rows from the matrix */
415  void EliminateRows(const Array<int> &rows);
416 
417  /// Makes this object a reference to another PetscParMatrix
418  void MakeRef(const PetscParMatrix &master);
419 
420  /** @brief Release the PETSc Mat object. If @a dereference is true, decrement
421  the refcount of the Mat object. */
422  Mat ReleaseMat(bool dereference);
423 
424  Type GetType() const;
425 };
426 
427 /// Returns the matrix A * B
428 PetscParMatrix * ParMult(const PetscParMatrix *A, const PetscParMatrix *B);
429 
430 /// Returns the matrix Rt^t * A * P
431 PetscParMatrix * RAP(PetscParMatrix *Rt, PetscParMatrix *A, PetscParMatrix *P);
432 
433 /// Returns the matrix R * A * P
434 PetscParMatrix * TripleMatrixProduct(PetscParMatrix *R, PetscParMatrix *A,
435  PetscParMatrix *P);
436 
437 /// Returns the matrix P^t * A * P
438 PetscParMatrix * RAP(PetscParMatrix *A, PetscParMatrix *P);
439 
440 /// Returns the matrix P^t * A * P
441 PetscParMatrix * RAP(HypreParMatrix *A, PetscParMatrix *P);
442 
443 /** @brief Eliminate essential BC specified by @a ess_dof_list from the solution
444  @a X to the r.h.s. @a B.
445 
446  Here, @a A is a matrix with eliminated BC, while @a Ae is such that
447  (@a A + @a Ae) is the original (Neumann) matrix before elimination. */
448 void EliminateBC(PetscParMatrix &A, PetscParMatrix &Ae,
449  const Array<int> &ess_dof_list, const Vector &X, Vector &B);
450 
451 /// Helper class for handling essential boundary conditions.
453 {
454 public:
455  enum Type
456  {
458  CONSTANT, ///< Constant in time b.c.
460  };
461 
463  bctype(_type), setup(false), eval_t(0.0),
464  eval_t_cached(std::numeric_limits<double>::min()) {}
465  PetscBCHandler(Array<int>& ess_tdof_list, Type _type = ZERO);
466 
467  virtual ~PetscBCHandler() {}
468 
469  /// Returns the type of boundary conditions
470  Type GetType() const { return bctype; }
471 
472  /// Sets the type of boundary conditions
473  void SetType(enum Type _type) { bctype = _type; setup = false; }
474 
475  /// Boundary conditions evaluation
476  /** In the result vector, @a g, only values at the essential dofs need to be
477  set. */
478  virtual void Eval(double t, Vector &g)
479  { mfem_error("PetscBCHandler::Eval method not overloaded"); }
480 
481  /// Sets essential dofs (local, per-process numbering)
482  void SetTDofs(Array<int>& list);
483 
484  /// Gets essential dofs (local, per-process numbering)
485  Array<int>& GetTDofs() { return ess_tdof_list; }
486 
487  /// Sets the current time
488  void SetTime(double t) { eval_t = t; }
489 
490  /// SetUp the helper object, where @a n is the size of the solution vector
491  void SetUp(PetscInt n);
492 
493  /// y = x on ess_tdof_list_c and y = g (internally evaluated) on ess_tdof_list
494  void ApplyBC(const Vector &x, Vector &y);
495 
496  /// Replace boundary dofs with the current value
497  void ApplyBC(Vector &x);
498 
499  /// y = x-g on ess_tdof_list, the rest of y is unchanged
500  void FixResidualBC(const Vector& x, Vector& y);
501 
502  /// Replace boundary dofs with 0
503  void Zero(Vector &x);
504 
505  /// y = x on ess_tdof_list_c and y = 0 on ess_tdof_list
506  void ZeroBC(const Vector &x, Vector &y);
507 
508 private:
509  enum Type bctype;
510  bool setup;
511 
512  double eval_t;
513  double eval_t_cached;
514  Vector eval_g;
515 
516  Array<int> ess_tdof_list; //Essential true dofs
517 };
518 
519 // Helper class for user-defined preconditioners that needs to be setup
521 {
522 private:
523  std::string name;
524 public:
525  PetscPreconditionerFactory(const std::string &_name = "MFEM Factory")
526  : name(_name) { }
527  const char* GetName() { return name.c_str(); }
528  virtual Solver *NewPreconditioner(const OperatorHandle& oh) = 0;
530 };
531 
532 // Forward declarations of helper classes
533 class PetscSolverMonitor;
534 
535 /// Abstract class for PETSc's solvers.
537 {
538 protected:
539  /// Boolean to handle SetFromOptions calls.
540  mutable bool clcustom;
541 
542  /// The actual PETSc object (KSP, PC, SNES or TS).
544 
545  /// The class id of the actual PETSc object
547 
548  /// Right-hand side and solution vector
549  mutable PetscParVector *B, *X;
550 
551  /// Handler for boundary conditions
553 
554  /// Private context for solver
555  void *private_ctx;
556 
557  /// Boolean to handle SetOperator calls.
558  mutable bool operatorset;
559 
560 public:
561  /// Construct an empty PetscSolver. Initialize protected objects to NULL.
562  PetscSolver();
563 
564  /// Destroy the PetscParVectors allocated (if any).
565  virtual ~PetscSolver();
566 
567  /** @name Update of PETSc options.
568  The following Set methods can be used to update the internal PETSc
569  options.
570  @note They will be overwritten by the options in the input PETSc file. */
571  ///@{
572  void SetTol(double tol);
573  void SetRelTol(double tol);
574  void SetAbsTol(double tol);
575  void SetMaxIter(int max_iter);
576  void SetPrintLevel(int plev);
577  ///@}
578 
579  /// Customize object with options set
580  /** If @a customize is false, it disables any options customization. */
581  void Customize(bool customize = true) const;
582  int GetConverged();
583  int GetNumIterations();
584  double GetFinalNorm();
585 
586  /// Sets user-defined monitoring routine.
587  void SetMonitor(PetscSolverMonitor *ctx);
588 
589  /// Sets the object to handle essential boundary conditions
590  void SetBCHandler(PetscBCHandler *bch);
591 
592  /// Sets the object for the creation of the preconditioner
594 
595  /// Conversion function to PetscObject.
596  operator PetscObject() const { return obj; }
597 
598  /// Get the associated MPI communicator
599  MPI_Comm GetComm() const;
600 
601 protected:
602  /// These two methods handle creation and destructions of
603  /// private data for the Solver objects
604  void CreatePrivateContext();
605  void FreePrivateContext();
606 };
607 
608 
609 /// Abstract class for PETSc's linear solvers.
610 class PetscLinearSolver : public PetscSolver, public Solver
611 {
612 private:
613  /// Internal flag to handle HypreParMatrix conversion or not.
614  bool wrap;
615  void MultKernel(const Vector &b, Vector &x, bool trans) const;
616 
617 public:
618  PetscLinearSolver(MPI_Comm comm, const std::string &prefix = std::string(),
619  bool wrap = true);
621  const std::string &prefix = std::string());
622  /// Constructs a solver using a HypreParMatrix.
623  /** If @a wrap is true, then the MatMult ops of HypreParMatrix are wrapped.
624  No preconditioner can be automatically constructed from PETSc. If
625  @a wrap is false, the HypreParMatrix is converted into a the AIJ
626  PETSc format, which is suitable for most preconditioning methods. */
627  PetscLinearSolver(const HypreParMatrix &A, bool wrap = true,
628  const std::string &prefix = std::string());
629  virtual ~PetscLinearSolver();
630 
631  /// Sets the operator to be used for mat-vec operations and
632  /// for the construction of the preconditioner
633  virtual void SetOperator(const Operator &op);
634 
635  /// Allows to prescribe a different operator (@a pop) to construct
636  /// the preconditioner
637  void SetOperator(const Operator &op, const Operator &pop);
638 
639  /// Sets the solver to perform preconditioning
640  /// preserves the linear operator for the mat-vec
641  void SetPreconditioner(Solver &precond);
642 
643  /// Application of the solver.
644  virtual void Mult(const Vector &b, Vector &x) const;
645  virtual void MultTranspose(const Vector &b, Vector &x) const;
646 
647  /// Conversion function to PETSc's KSP type.
648  operator KSP() const { return (KSP)obj; }
649 };
650 
651 
653 {
654 public:
655  PetscPCGSolver(MPI_Comm comm, const std::string &prefix = std::string());
656  PetscPCGSolver(PetscParMatrix &A, const std::string &prefix = std::string());
657  PetscPCGSolver(HypreParMatrix &A,bool wrap=true,
658  const std::string &prefix = std::string());
659 };
660 
661 
662 /// Abstract class for PETSc's preconditioners.
663 class PetscPreconditioner : public PetscSolver, public Solver
664 {
665 private:
666  void MultKernel(const Vector &b, Vector &x, bool trans) const;
667 
668 public:
669  PetscPreconditioner(MPI_Comm comm,
670  const std::string &prefix = std::string());
672  const std::string &prefix = std::string());
673  PetscPreconditioner(MPI_Comm comm, Operator &op,
674  const std::string &prefix = std::string());
675  virtual ~PetscPreconditioner();
676 
677  virtual void SetOperator(const Operator &op);
678 
679  /// Application of the preconditioner.
680  virtual void Mult(const Vector &b, Vector &x) const;
681  virtual void MultTranspose(const Vector &b, Vector &x) const;
682 
683  /// Conversion function to PETSc's PC type.
684  operator PC() const { return (PC)obj; }
685 };
686 
687 
688 /// Auxiliary class for BDDC customization.
690 {
691 protected:
697  bool netflux;
698  friend class PetscBDDCSolver;
699 
700 public:
702  nat_dof(NULL), nat_dof_local(false), netflux(false)
703  {}
705 
706  /// Specify dofs on the essential boundary.
707  /** If @a loc is false, it is a list of true dofs in local ordering.
708  If @a loc is true, it is a marker for Vdofs in local ordering. */
709  void SetEssBdrDofs(const Array<int> *essdofs, bool loc = false)
710  {
711  ess_dof = essdofs;
712  ess_dof_local = loc;
713  }
714  /// Specify dofs on the natural boundary.
715  /** If @a loc is false, it is a list of true dofs in local ordering.
716  If @a loc is true, it is a marker for Vdofs in local ordering. */
717  void SetNatBdrDofs(const Array<int> *natdofs, bool loc = false)
718  {
719  nat_dof = natdofs;
720  nat_dof_local = loc;
721  }
722  /// Setup BDDC with no-net-flux local solvers. Needs a ParFiniteElementSpace attached
723  void SetComputeNetFlux(bool net = true)
724  {
725  netflux = net;
726  }
727 };
728 
729 
731 {
732 private:
733  void BDDCSolverConstructor(const PetscBDDCSolverParams &opts);
734 
735 public:
736  PetscBDDCSolver(MPI_Comm comm, Operator &op,
738  const std::string &prefix = std::string());
741  const std::string &prefix = std::string());
742 };
743 
744 
746 {
747 public:
748  PetscFieldSplitSolver(MPI_Comm comm, Operator &op,
749  const std::string &prefix = std::string());
750 };
751 
752 
753 /// Abstract class for PETSc's nonlinear solvers.
755 {
756 public:
757  PetscNonlinearSolver(MPI_Comm comm,
758  const std::string &prefix = std::string());
759  PetscNonlinearSolver(MPI_Comm comm, Operator &op,
760  const std::string &prefix = std::string());
761  virtual ~PetscNonlinearSolver();
762 
763  /// Specification of the nonlinear operator.
764  virtual void SetOperator(const Operator &op);
765 
766  /// Specifies the desired format of the Jacobian in case a PetscParMatrix
767  /// is not returned by the GetGradient method.
768  void SetJacobianType(Operator::Type type);
769 
770  /// Application of the solver.
771  virtual void Mult(const Vector &b, Vector &x) const;
772 
773  /// Specification of an objective function to be used for line search.
774  void SetObjective(void (*obj)(Operator* op, const Vector &x, double *f));
775 
776  /// User-defined routine to be applied after a successful line search step.
777  /// The user can change the current direction Y and/or the updated solution W
778  /// (with W = X - lambda * Y) but not the previous solution X.
779  /// If Y or W have been changed, the corresponding booleans need to updated.
780  void SetPostCheck(void (*post)(Operator *op, const Vector &X, Vector &Y,
781  Vector &W, bool &changed_y, bool &changed_w));
782 
783  /// General purpose update function to be called at the beginning of each step
784  /// it is the current nonlinear iteration number
785  /// F is the current function value, X the current solution
786  /// D the previous step taken, and P the previous solution
787  void SetUpdate(void (*update)(Operator *op, int it,
788  const mfem::Vector& F, const mfem::Vector& X,
789  const mfem::Vector& D, const mfem::Vector& P));
790 
791  /// Conversion function to PETSc's SNES type.
792  operator SNES() const { return (SNES)obj; }
793 };
794 
795 
796 /// Abstract class for PETSc's ODE solvers.
797 class PetscODESolver : public PetscSolver, public ODESolver
798 {
799 public:
800  /// The type of the ODE. Use ODE_SOLVER_LINEAR if the jacobians
801  /// are linear and independent of time.
802  enum Type
803  {
806  };
807 
808  PetscODESolver(MPI_Comm comm, const std::string &prefix = std::string());
809  virtual ~PetscODESolver();
810 
811  /// Initialize the ODE solver.
812  virtual void Init(TimeDependentOperator &f_,
813  enum PetscODESolver::Type type);
815 
818 
819  /// Specifies the desired format of the Jacobian in case a PetscParMatrix
820  /// is not returned by the GetGradient methods
821  void SetJacobianType(Operator::Type type);
822 
823  virtual void Step(Vector &x, double &t, double &dt);
824  virtual void Run(Vector &x, double &t, double &dt, double t_final);
825 
826  /// Conversion function to PETSc's TS type.
827  operator TS() const { return (TS)obj; }
828 };
829 
830 
831 /// Abstract class for monitoring PETSc's solvers.
833 {
834 public:
835  bool mon_sol;
836  bool mon_res;
837  PetscSolverMonitor(bool monitor_sol = false, bool monitor_res = true)
838  : mon_sol(monitor_sol), mon_res(monitor_res) {}
839  virtual ~PetscSolverMonitor() {}
840 
841  /// Monitor the solution vector x
842  virtual void MonitorSolution(PetscInt it, PetscReal norm, const Vector &x)
843  {
844  MFEM_ABORT("MonitorSolution() is not implemented!")
845  }
846 
847  /// Monitor the residual vector r
848  virtual void MonitorResidual(PetscInt it, PetscReal norm, const Vector &r)
849  {
850  MFEM_ABORT("MonitorResidual() is not implemented!")
851  }
852 
853  /// Generic monitor to take access to the solver
854  virtual void MonitorSolver(PetscSolver* solver) {}
855 };
856 
857 
858 } // namespace mfem
859 
860 #endif // MFEM_USE_MPI
861 #endif // MFEM_USE_PETSC
862 
863 #endif
PetscPreconditionerFactory(const std::string &_name="MFEM Factory")
Definition: petsc.hpp:525
void SetPreconditioner(Solver &precond)
Definition: petsc.cpp:2500
void SetPrintLevel(int plev)
Definition: petsc.cpp:1856
PetscParVector * B
Right-hand side and solution vector.
Definition: petsc.hpp:549
void CreatePrivateContext()
Definition: petsc.cpp:2147
void Print(const char *fname=NULL, bool binary=false) const
Prints the matrix (to stdout if fname is NULL)
Definition: petsc.cpp:1427
virtual void SetOperator(const Operator &op)
Specification of the nonlinear operator.
Definition: petsc.cpp:3335
Abstract class for PETSc&#39;s preconditioners.
Definition: petsc.hpp:663
PetscParMatrix & operator+=(const PetscParMatrix &B)
Definition: petsc.cpp:655
double PetscScalar
Definition: petsc.hpp:47
struct _p_TS * TS
Definition: petsc.hpp:59
virtual void SetOperator(const Operator &op)
Definition: petsc.cpp:2354
HypreParMatrix * RAP(const HypreParMatrix *A, const HypreParMatrix *P)
Returns the matrix P^t * A * P.
Definition: hypre.cpp:1636
bool clcustom
Boolean to handle SetFromOptions calls.
Definition: petsc.hpp:540
void SetObjective(void(*obj)(Operator *op, const Vector &x, double *f))
Specification of an objective function to be used for line search.
Definition: petsc.cpp:3394
HYPRE_Int PetscInt
Definition: petsc.hpp:46
void ConvertOperator(MPI_Comm comm, const Operator &op, Mat *B, Operator::Type tid)
Definition: petsc.cpp:858
double GetFinalNorm()
Definition: petsc.cpp:2122
virtual void MultTranspose(const Vector &b, Vector &x) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Definition: petsc.cpp:2754
Wrapper for PETSc&#39;s matrix class.
Definition: petsc.hpp:197
PetscParVector & operator+=(const PetscParVector &y)
Definition: petsc.cpp:404
const Array< int > * nat_dof
Definition: petsc.hpp:695
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:2230
Abstract class for PETSc&#39;s linear solvers.
Definition: petsc.hpp:610
Vec x
The actual PETSc object.
Definition: petsc.hpp:79
Abstract class for PETSc&#39;s solvers.
Definition: petsc.hpp:536
PetscODESolver::Type GetType() const
Definition: petsc.cpp:3561
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:3610
void SetPostCheck(void(*post)(Operator *op, const Vector &X, Vector &Y, Vector &W, bool &changed_y, bool &changed_w))
Definition: petsc.cpp:3405
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: petsc.hpp:324
ParFiniteElementSpace * fespace
Definition: petsc.hpp:692
Type GetType() const
Returns the type of boundary conditions.
Definition: petsc.hpp:470
Base abstract class for first order time dependent operators.
Definition: operator.hpp:259
PetscInt GetNumCols() const
Returns the local number of columns.
Definition: petsc.cpp:501
void SetType(PetscODESolver::Type)
Definition: petsc.cpp:3567
virtual void MonitorSolver(PetscSolver *solver)
Generic monitor to take access to the solver.
Definition: petsc.hpp:854
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:1394
PetscBDDCSolver(MPI_Comm comm, Operator &op, const PetscBDDCSolverParams &opts=PetscBDDCSolverParams(), const std::string &prefix=std::string())
Definition: petsc.cpp:3249
PetscParVector & AddValues(const Array< PetscInt > &, const Array< PetscScalar > &)
Add values in a vector.
Definition: petsc.cpp:385
void SetMat(Mat newA)
Replace the inner Mat Object. The reference count of newA is increased.
Definition: petsc.cpp:1277
virtual ~PetscSolver()
Destroy the PetscParVectors allocated (if any).
Definition: petsc.cpp:1767
PetscNonlinearSolver(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:3295
PetscInt GetGlobalNumRows() const
Returns the global number of rows.
Definition: petsc.hpp:358
Type GetType() const
Definition: petsc.cpp:1709
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:3585
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:529
PetscPreconditioner(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:2630
PetscClassId cid
The class id of the actual PETSc object.
Definition: petsc.hpp:546
Abstract parallel finite element space.
Definition: pfespace.hpp:28
Constant in time b.c.
Definition: petsc.hpp:458
void SetRelTol(double tol)
Definition: petsc.cpp:1779
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:327
void Randomize(PetscInt seed=0)
Set random values.
Definition: petsc.cpp:438
PetscPCGSolver(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:2600
void Destroy()
Delete all owned data. Does not perform re-initialization with defaults.
Definition: petsc.cpp:1252
void SetMonitor(PetscSolverMonitor *ctx)
Sets user-defined monitoring routine.
Definition: petsc.cpp:1933
void SetMaxIter(int max_iter)
Definition: petsc.cpp:1829
Abstract class for PETSc&#39;s ODE solvers.
Definition: petsc.hpp:797
PetscParVector & operator*=(PetscScalar d)
Definition: petsc.cpp:416
HypreParMatrix * ParMult(const HypreParMatrix *A, const HypreParMatrix *B, bool own_matrix)
Definition: hypre.cpp:1610
struct _p_SNES * SNES
Definition: petsc.hpp:58
void EliminateRowsCols(const Array< int > &rows_cols, const PetscParVector &X, PetscParVector &B, double diag=1.)
Eliminate rows and columns from the matrix, and rows from the vector B. Modify B with the BC values i...
Definition: petsc.cpp:1653
double PetscReal
Definition: petsc.hpp:48
Wrapper for PETSc&#39;s vector class.
Definition: petsc.hpp:75
void Customize(bool customize=true) const
Customize object with options set.
Definition: petsc.cpp:2023
PetscInt M() const
Returns the global number of rows.
Definition: petsc.cpp:508
int PetscClassId
Definition: petsc.hpp:49
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Definition: petsc.cpp:3432
PetscParVector * Y
Definition: petsc.hpp:204
virtual ~PetscLinearSolver()
Definition: petsc.cpp:2590
PetscInt GetNumRows() const
Returns the local number of rows.
Definition: petsc.cpp:494
void Print(const char *fname=NULL, bool binary=false) const
Prints the vector (to stdout if fname is NULL)
Definition: petsc.cpp:453
struct _p_PC * PC
Definition: petsc.hpp:57
void EliminateBC(HypreParMatrix &A, HypreParMatrix &Ae, const Array< int > &ess_dof_list, const Vector &X, Vector &B)
Definition: hypre.cpp:1690
void ResetArray()
Reset the PETSc Vec object to use its default data. Call this method after the use of PlaceArray()...
Definition: petsc.cpp:433
PetscParVector & SetValues(const Array< PetscInt > &, const Array< PetscScalar > &)
Set values in a vector.
Definition: petsc.cpp:372
virtual void Init(TimeDependentOperator &f_, enum PetscODESolver::Type type)
Initialize the ODE solver.
Definition: petsc.cpp:3488
PetscParMatrix * Transpose(bool action=false)
Returns the transpose of the PetscParMatrix.
Definition: petsc.cpp:1375
PetscObject obj
The actual PETSc object (KSP, PC, SNES or TS).
Definition: petsc.hpp:543
Abstract class for monitoring PETSc&#39;s solvers.
Definition: petsc.hpp:832
Data type sparse matrix.
Definition: sparsemat.hpp:40
void SetJacobianType(Operator::Type type)
Definition: petsc.cpp:3388
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
double b
Definition: lissajous.cpp:42
Auxiliary class for BDDC customization.
Definition: petsc.hpp:689
virtual ~PetscPreconditioner()
Definition: petsc.cpp:2759
MPI_Comm GetComm() const
Get the associated MPI communicator.
Definition: petsc.cpp:823
void FixResidualBC(const Vector &x, Vector &y)
y = x-g on ess_tdof_list, the rest of y is unchanged
Definition: petsc.cpp:2279
PetscParMatrix & operator=(const PetscParMatrix &B)
Definition: petsc.cpp:639
PetscInt GetColStart() const
Returns the global index of the first local column.
Definition: petsc.cpp:487
virtual ~PetscParVector()
Calls PETSc&#39;s destroy function.
Definition: petsc.cpp:243
PetscFieldSplitSolver(MPI_Comm comm, Operator &op, const std::string &prefix=std::string())
Definition: petsc.cpp:3258
PetscBCHandler * bchandler
Handler for boundary conditions.
Definition: petsc.hpp:552
PetscParMatrix & operator-=(const PetscParMatrix &B)
Definition: petsc.cpp:670
virtual Solver * NewPreconditioner(const OperatorHandle &oh)=0
void ScaleRows(const Vector &s)
Scale the local row i by s(i).
Definition: petsc.cpp:1452
void Zero(Vector &x)
Replace boundary dofs with 0.
Definition: petsc.cpp:2298
MPI_Comm GetComm() const
Get the associated MPI communicator.
Definition: petsc.cpp:1928
void Shift(double s)
Shift diagonal by a constant.
Definition: petsc.cpp:1474
void SetTime(double t)
Sets the current time.
Definition: petsc.hpp:488
ID for class PetscParMatrix, MATSHELL format.
Definition: operator.hpp:236
void trans(const Vector &x, Vector &p)
Definition: toroid.cpp:239
PetscParMatrix()
Create an empty matrix to be used as a reference to an existing matrix.
Definition: petsc.cpp:536
void SetType(enum Type _type)
Sets the type of boundary conditions.
Definition: petsc.hpp:473
Abstract class for PETSc&#39;s nonlinear solvers.
Definition: petsc.hpp:754
int GetNumIterations()
Definition: petsc.cpp:2089
void SetBCHandler(PetscBCHandler *bch)
Sets the object to handle essential boundary conditions.
Definition: petsc.cpp:1963
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:73
void ZeroBC(const Vector &x, Vector &y)
y = x on ess_tdof_list_c and y = 0 on ess_tdof_list
Definition: petsc.cpp:2307
virtual void Eval(double t, Vector &g)
Boundary conditions evaluation.
Definition: petsc.hpp:478
Type
Enumeration defining IDs for some classes derived from Operator.
Definition: operator.hpp:229
PetscBCHandler(Type _type=ZERO)
Definition: petsc.hpp:462
PetscInt NNZ() const
Returns the number of nonzeros.
Definition: petsc.cpp:522
PetscLinearSolver(MPI_Comm comm, const std::string &prefix=std::string(), bool wrap=true)
Definition: petsc.cpp:2319
virtual void Mult(const Vector &b, Vector &x) const
Application of the preconditioner.
Definition: petsc.cpp:2749
Mat A
The actual PETSc object.
Definition: petsc.hpp:201
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
Definition: petsc.hpp:814
struct _p_Mat * Mat
Definition: petsc.hpp:55
PetscInt N() const
Returns the global number of columns.
Definition: petsc.cpp:515
PetscParVector * GetY() const
Returns the inner vector in the range of A (it creates it if needed)
Definition: petsc.cpp:1365
void SetJacobianType(Operator::Type type)
Definition: petsc.cpp:3555
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:836
void SetUpdate(void(*update)(Operator *op, int it, const mfem::Vector &F, const mfem::Vector &X, const mfem::Vector &D, const mfem::Vector &P))
Definition: petsc.cpp:3419
bool operatorset
Boolean to handle SetOperator calls.
Definition: petsc.hpp:558
PetscParVector * X
Auxiliary vectors for typecasting.
Definition: petsc.hpp:204
void MultTranspose(double a, const Vector &x, double b, Vector &y) const
Matvec transpose: y = a A^T x + b y.
Definition: petsc.cpp:1410
PetscParVector & operator-=(const PetscParVector &y)
Definition: petsc.cpp:410
virtual ~PetscSolverMonitor()
Definition: petsc.hpp:839
double a
Definition: lissajous.cpp:41
void MFEMFinalizePetsc()
Definition: petsc.cpp:182
virtual ~PetscNonlinearSolver()
Definition: petsc.cpp:3327
void SetComputeNetFlux(bool net=true)
Setup BDDC with no-net-flux local solvers. Needs a ParFiniteElementSpace attached.
Definition: petsc.hpp:723
virtual ~PetscODESolver()
Definition: petsc.cpp:3480
virtual ~PetscBCHandler()
Definition: petsc.hpp:467
int GetConverged()
Definition: petsc.cpp:2056
PetscSolver()
Construct an empty PetscSolver. Initialize protected objects to NULL.
Definition: petsc.cpp:1757
void SetPreconditionerFactory(PetscPreconditionerFactory *factory)
Sets the object for the creation of the preconditioner.
Definition: petsc.cpp:1982
void MFEMInitializePetsc()
Convenience functions to initialize/finalize PETSc.
Definition: petsc.cpp:165
Mat ReleaseMat(bool dereference)
Release the PETSc Mat object. If dereference is true, decrement the refcount of the Mat object...
Definition: petsc.cpp:1696
PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscInt *col=NULL)
Creates vector with given global size and partitioning of the columns.
Definition: petsc.cpp:225
virtual void MonitorSolution(PetscInt it, PetscReal norm, const Vector &x)
Monitor the solution vector x.
Definition: petsc.hpp:842
ID for class PetscParMatrix, MATAIJ format.
Definition: operator.hpp:234
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: petsc.cpp:2665
void SetSpace(ParFiniteElementSpace *fe)
Definition: petsc.hpp:704
MPI_Comm GetComm() const
Get the associated MPI communicator.
Definition: petsc.cpp:336
PetscInt GlobalSize() const
Returns the global number of rows.
Definition: petsc.cpp:201
PetscParVector * X
Definition: petsc.hpp:549
const Array< int > * ess_dof
Definition: petsc.hpp:693
void _SetDataAndSize_()
Definition: petsc.cpp:190
PetscInt GetRowStart() const
Returns the global index of the first local row.
Definition: petsc.cpp:480
struct _p_PetscObject * PetscObject
Definition: petsc.hpp:50
void SetAbsTol(double tol)
Definition: petsc.cpp:1804
Helper class for handling essential boundary conditions.
Definition: petsc.hpp:452
struct _p_KSP * KSP
Definition: petsc.hpp:56
PetscParVector * GetX() const
Returns the inner vector in the domain of A (it creates it if needed)
Definition: petsc.cpp:1355
Array< int > & GetTDofs()
Gets essential dofs (local, per-process numbering)
Definition: petsc.hpp:485
void SetTol(double tol)
Definition: petsc.cpp:1774
PetscParVector & operator=(PetscScalar d)
Set constant values.
Definition: petsc.cpp:366
PetscSolverMonitor(bool monitor_sol=false, bool monitor_res=true)
Definition: petsc.hpp:837
virtual void MonitorResidual(PetscInt it, PetscReal norm, const Vector &r)
Monitor the residual vector r.
Definition: petsc.hpp:848
PetscParMatrix * TripleMatrixProduct(PetscParMatrix *R, PetscParMatrix *A, PetscParMatrix *P)
Returns the matrix R * A * P.
Definition: petsc.cpp:1493
Vector data type.
Definition: vector.hpp:48
struct _p_Vec * Vec
Definition: petsc.hpp:54
void PlaceArray(PetscScalar *temp_data)
Temporarily replace the data of the PETSc Vec object. To return to the original data array...
Definition: petsc.cpp:428
void FreePrivateContext()
Definition: petsc.cpp:2179
Vector * GlobalVector() const
Returns the global vector in each processor.
Definition: petsc.cpp:341
PetscODESolver(MPI_Comm comm, const std::string &prefix=std::string())
Definition: petsc.cpp:3455
void EliminateRows(const Array< int > &rows)
Eliminate only the rows from the matrix.
Definition: petsc.cpp:1682
Base class for solvers.
Definition: operator.hpp:500
PetscInt GetGlobalNumCols() const
Returns the global number of columns.
Definition: petsc.hpp:361
void SetNatBdrDofs(const Array< int > *natdofs, bool loc=false)
Specify dofs on the natural boundary.
Definition: petsc.hpp:717
Abstract operator.
Definition: operator.hpp:24
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:187
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Definition: petsc.cpp:2580
void operator*=(double s)
Scale all entries by s: A_scaled = s*A.
Definition: petsc.cpp:1389
void SetEssBdrDofs(const Array< int > *essdofs, bool loc=false)
Specify dofs on the essential boundary.
Definition: petsc.hpp:709
void SetTDofs(Array< int > &list)
Sets essential dofs (local, per-process numbering)
Definition: petsc.cpp:2207
virtual void MultTranspose(const Vector &b, Vector &x) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Definition: petsc.cpp:2585
void * private_ctx
Private context for solver.
Definition: petsc.hpp:555
void SetUp(PetscInt n)
SetUp the helper object, where n is the size of the solution vector.
Definition: petsc.cpp:2214
void MakeRef(const PetscParMatrix &master)
Makes this object a reference to another PetscParMatrix.
Definition: petsc.cpp:1345
void ScaleCols(const Vector &s)
Scale the local col i by s(i).
Definition: petsc.cpp:1463
virtual ~PetscParMatrix()
Calls PETSc&#39;s destroy function.
Definition: petsc.hpp:305