Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef op_PETSC_hh
00006 #define op_PETSC_hh
00007
00008 extern "C" {
00009
00010 typedef struct _p_SLES* SLES;
00011 typedef struct _p_Mat* Mat;
00012 typedef struct _p_Vec* Vec;
00013 }
00014 #include <string>
00015
00016 #include "compositions.hh"
00017 #include "basics/typedefs.hh"
00018 #include "matrix.hh"
00019
00020 namespace concepts {
00021
00022
00023 template<class F>
00024 class Function;
00025
00026 template<class F>
00027 class Vector;
00028
00029 template<class F>
00030 class Space;
00031
00032 template<class F, class G>
00033 class BilinearForm;
00034
00035
00036
00070 class PETSc : public Operator<Real> {
00071 public:
00078 PETSc(Operator<Real>& A, const Real maxeps, const std::string ksptype,
00079 const std::string pctype = std::string("none"));
00080 ~PETSc();
00081 virtual void operator()(const Function<Real>& fncY, Function<Real>& fncX);
00082
00086 uint iterations() const { return iterations_; }
00087 protected:
00088 virtual std::ostream& info(std::ostream& os) const;
00089 private:
00090 typedef int (*multPointer)(Mat, Vec, Vec);
00091 typedef void (*PETScmultPointer)();
00092
00094 Operator<Real>& A_;
00095
00097 int iterations_;
00098
00100 Mat PETScA_;
00101 bool destroyPETScA_;
00102
00104 SLES solver_;
00105
00107 Vec x_, y_;
00108 };
00109
00110
00111
00144 class PETScMat : public Matrix<Real> {
00145 public:
00148 PETScMat(const Space<Real>& spcX, const Space<Real>& spcY);
00149
00153 PETScMat(const Space<Real>& spc, BilinearForm<Real,Real>& bf);
00154
00156 PETScMat(const SparseMatrix<Real>& matrix);
00157
00158 ~PETScMat();
00159
00160 virtual void operator()(const Function<double>& fncY,
00161 Function<double>& fncX);
00162 virtual void operator()(const Function<std::complex<double> >& fncY,
00163 Function<std::complex<double> >& fncX);
00164 void operator()(const Vector<double>& fncY,
00165 Vector<double>& fncX);
00166 virtual void transpMult(const Vector<double>& fncY,
00167 Vector<double>& fncX);
00168 virtual void transpMult(const Vector<std::complex<double> >& fncY,
00169 Vector<std::complex<double> >& fncX);
00170
00171 virtual Real operator()(const uint i, const uint j) const;
00177 virtual Real& operator()(const uint i, const uint j);
00178
00179 virtual const Space<double>& spaceX() const { return spcX_; }
00180 virtual const Space<double>& spaceY() const { return spcY_; }
00181
00183 operator Mat() { return A_; }
00184
00185 void storeMatlab(const char* name) const;
00186 protected:
00187 std::ostream& info(std::ostream& os) const;
00188 private:
00190 const Space<Real>& spcX_;
00191
00193 uint nX_;
00194
00196 const Space<Real>& spcY_;
00197
00199 uint nY_;
00200
00202 Vec x_, y_;
00203
00205 Mat A_;
00206 };
00207
00208 }
00209
00210 #endif // op_PETSC_hh