PETSc.hh

Go to the documentation of this file.
1 
9 #ifndef op_PETSC_hh
10 #define op_PETSC_hh
11 
12 extern "C" {
13  // forwards for PETSc
14  typedef struct _p_SLES* SLES;
15  typedef struct _p_Mat* Mat;
16  typedef struct _p_Vec* Vec;
17 }
18 #include <string>
19 
20 #include "compositions.hh"
21 #include "basics/typedefs.hh"
22 #include "matrix.hh"
23 
24 namespace concepts {
25 
26  // forward declarations
27  template<class F>
28  class Function;
29 
30  template<class F>
31  class Vector;
32 
33  template<class F>
34  class Space;
35 
36  template<class F, class G>
37  class BilinearForm;
38 
39  // **************************************************************** PETSc **
40 
74  class PETSc : public Operator<Real> {
75  public:
82  PETSc(Operator<Real>& A, const Real maxeps, const std::string ksptype,
83  const std::string pctype = std::string("none"));
84  ~PETSc();
85  virtual void operator()(const Function<Real>& fncY, Function<Real>& fncX);
86 
90  uint iterations() const { return iterations_; }
91  protected:
92  virtual std::ostream& info(std::ostream& os) const;
93  private:
94  typedef int (*multPointer)(Mat, Vec, Vec);
95  typedef void (*PETScmultPointer)();
96 
99 
102 
106 
109 
112  };
113 
114  // ************************************************************* PETScMat **
115 
148  class PETScMat : public Matrix<Real> {
149  public:
152  PETScMat(const Space<Real>& spcX, const Space<Real>& spcY);
153 
158 
160  PETScMat(const SparseMatrix<Real>& matrix);
161 
163 
164  virtual void operator()(const Function<double>& fncY,
165  Function<double>& fncX);
166  virtual void operator()(const Function<std::complex<double> >& fncY,
167  Function<std::complex<double> >& fncX);
168  void operator()(const Vector<double>& fncY,
169  Vector<double>& fncX);
170  virtual void transpMult(const Vector<double>& fncY,
171  Vector<double>& fncX);
172  virtual void transpMult(const Vector<std::complex<double> >& fncY,
173  Vector<std::complex<double> >& fncX);
174 
175  virtual Real operator()(const uint i, const uint j) const;
181  virtual Real& operator()(const uint i, const uint j);
182 
183  virtual const Space<double>& spaceX() const { return spcX_; }
184  virtual const Space<double>& spaceY() const { return spcY_; }
185 
187  operator Mat() { return A_; }
188 
189  void storeMatlab(const char* name) const;
190  protected:
191  std::ostream& info(std::ostream& os) const;
192  private:
195 
197  uint nX_;
198 
201 
203  uint nY_;
204 
207 
210  };
211 
212 } // namespace concepts
213 
214 #endif // op_PETSC_hh
Interface to the iterative solvers of the PETSc library.
Definition: PETSc.hh:74
virtual std::ostream & info(std::ostream &os) const
struct _p_SLES * SLES
Definition: PETSc.hh:14
const Space< Real > & spcY_
Source space.
Definition: PETSc.hh:200
virtual const Space< double > & spaceY() const
Definition: PETSc.hh:184
virtual void transpMult(const Vector< std::complex< double > > &fncY, Vector< std::complex< double > > &fncX)
uint nX_
Dimension of image space (spcX_)
Definition: PETSc.hh:197
Vec x_
PETSc vector handle.
Definition: PETSc.hh:111
void storeMatlab(const char *name) const
const Space< Real > & spcX_
Image space.
Definition: PETSc.hh:194
bool destroyPETScA_
Definition: PETSc.hh:105
virtual void operator()(const Function< Real > &fncY, Function< Real > &fncX)
Vec x_
PETSc vector handle.
Definition: PETSc.hh:206
uint nY_
Dimension of source space (spcY_)
Definition: PETSc.hh:203
virtual Real operator()(const uint i, const uint j) const
Returns entry with indices i and j.
virtual const Space< double > & spaceX() const
Definition: PETSc.hh:183
void(* PETScmultPointer)()
Definition: PETSc.hh:95
int(* multPointer)(Mat, Vec, Vec)
Definition: PETSc.hh:94
PETScMat(const Space< Real > &spc, BilinearForm< Real, Real > &bf)
Constructor.
struct _p_Mat * Mat
Definition: PETSc.hh:15
Mat A_
PETSc matrix.
Definition: PETSc.hh:209
virtual void operator()(const Function< double > &fncY, Function< double > &fncX)
Abstract class for an operator.
Definition: compositions.hh:31
PETSc(Operator< Real > &A, const Real maxeps, const std::string ksptype, const std::string pctype=std::string("none"))
Constructor.
Abstract class for an operator.
Definition: ARPACK.hh:16
PETScMat(const Space< Real > &spcX, const Space< Real > &spcY)
Constructor.
struct _p_Vec * Vec
Definition: PETSc.hh:16
Mat PETScA_
PETSc matrix handle.
Definition: PETSc.hh:104
void operator()(const Vector< double > &fncY, Vector< double > &fncX)
virtual Real & operator()(const uint i, const uint j)
Should return and allow access to entry with indices i and j.
PETScMat(const SparseMatrix< Real > &matrix)
Constructor. Copies the matrix from matrix.
Operator< Real > & A_
The operator of the matrix.
Definition: PETSc.hh:98
virtual void operator()(const Function< std::complex< double > > &fncY, Function< std::complex< double > > &fncX)
Interface to the sparse matrices from PETSc.
Definition: PETSc.hh:148
uint iterations() const
Returns the number of iterations.
Definition: PETSc.hh:90
SLES solver_
PETSc solver handle.
Definition: PETSc.hh:108
int iterations_
Number of iterations.
Definition: PETSc.hh:101
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
std::ostream & info(std::ostream &os) const
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
virtual void transpMult(const Vector< double > &fncY, Vector< double > &fncX)
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich