DOLFIN
DOLFIN C++ interface
PETScBaseMatrix.h
1 // Copyright (C) 2005-2006 Anders Logg
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Modified by Fredrik Valdmanis, 2011
19 //
20 // First added: 2005-01-17
21 // Last changed: 2011-09-07
22 
23 #ifndef __PETSC_BASE_MATRIX_H
24 #define __PETSC_BASE_MATRIX_H
25 
26 #ifdef HAS_PETSC
27 
28 #include <cinttypes>
29 #include <cstddef>
30 #include <memory>
31 #include <string>
32 #include <utility>
33 #include <petscmat.h>
34 
35 #include <dolfin/common/types.h>
36 #include <dolfin/common/Variable.h>
37 #include "PETScObject.h"
38 #include "PETScVector.h"
39 
40 namespace dolfin
41 {
42 
43  class GenericVector;
44  class PETScVector;
45 
48 
49  class PETScBaseMatrix : public PETScObject, public virtual Variable
50  {
51  public:
52 
54  PETScBaseMatrix() : _matA(nullptr) {}
55 
57  explicit PETScBaseMatrix(Mat A);
58 
61 
64 
66  std::size_t size(std::size_t dim) const;
67 
70  std::pair<std::int64_t, std::int64_t> size() const;
71 
73  std::pair<std::int64_t, std::int64_t> local_range(std::size_t dim) const;
74 
83  void init_vector(GenericVector& z, std::size_t dim) const;
84 
86  Mat mat() const
87  { return _matA; }
88 
90  MPI_Comm mpi_comm() const;
91 
93  virtual std::string str(bool verbose) const
94  { return "No str function for this PETSc matrix operator."; }
95 
96  protected:
97 
98  // PETSc Mat pointer
99  Mat _matA;
100 
101  };
102 
103 }
104 
105 #endif
106 
107 #endif
std::pair< std::int64_t, std::int64_t > size() const
Definition: PETScBaseMatrix.cpp:79
Common base class for DOLFIN variables.
Definition: Variable.h:35
~PETScBaseMatrix()
Destructor.
Definition: PETScBaseMatrix.cpp:45
Definition: adapt.h:29
MPI_Comm mpi_comm() const
Return the MPI communicator.
Definition: PETScBaseMatrix.cpp:141
std::pair< std::int64_t, std::int64_t > local_range(std::size_t dim) const
Return local range along dimension dim.
Definition: PETScBaseMatrix.cpp:89
PETScBaseMatrix()
Constructor.
Definition: PETScBaseMatrix.h:54
Definition: PETScBaseMatrix.h:49
Mat mat() const
Return PETSc Mat pointer.
Definition: PETScBaseMatrix.h:86
virtual std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: PETScBaseMatrix.h:93
Definition: PETScObject.h:33
void init_vector(GenericVector &z, std::size_t dim) const
Definition: PETScBaseMatrix.cpp:106
This class defines a common interface for vectors.
Definition: GenericVector.h:47