Go to the documentation of this file.00001
00002
00003 #ifndef petscFabric_hh
00004 #define petscFabric_hh
00005
00006 #include <list>
00007 #include "operator/PETSc.hh"
00008 #include "operator/solverFabric.hh"
00009
00010 namespace concepts {
00011
00012
00013
00027 class PETScFabric : public SolverFabric<Real> {
00028 public:
00034 PETScFabric(const Real maxeps, const std::string ksptype,
00035 const std::string pctype = std::string("none"))
00036 : maxeps_(maxeps), ksptype_(ksptype), pctype_(pctype) {}
00037 virtual Operator<Real>* operator()(Operator<Real>& matrix) {
00038 if (pctype_ == "none" || dynamic_cast<concepts::PETScMat*>(&matrix)) {
00039 return new PETSc(matrix, maxeps_, ksptype_, pctype_);
00040 } else {
00041 concepts::SparseMatrix<Real>* sparsemat =
00042 dynamic_cast<concepts::SparseMatrix<Real>*>(&matrix);
00043 if (sparsemat) {
00044 petscmat_.push_front(new concepts::PETScMat(*sparsemat));
00045 } else {
00046 sparsemat = new concepts::SparseMatrix<Real>(matrix);
00047 petscmat_.push_front(new concepts::PETScMat(*sparsemat));
00048 delete sparsemat;
00049 }
00050 return new PETSc(*(petscmat_.front()), maxeps_, ksptype_, pctype_);
00051 }
00052 }
00053 ~PETScFabric() {
00054 while (!petscmat_.empty()) {
00055 delete petscmat_.front();
00056 petscmat_.pop_front();
00057 }
00058 }
00059 protected:
00060 virtual std::ostream& info(std::ostream& os) const {
00061 return os << "PETScFabric(maxeps = " << maxeps_ << ", ksptype = "
00062 << ksptype_ << ", pctype = " << pctype_ << ")";
00063 }
00064 private:
00066 const Real maxeps_;
00068 const std::string ksptype_;
00070 const std::string pctype_;
00072 std::list<concepts::PETScMat*> petscmat_;
00073 };
00074
00075 }
00076
00077 #endif // petscFabric_hh