00001 #ifndef PETSCLINEARSOLVER_H
00002 #define PETSCLINEARSOLVER_H
00003
00011 #include "petscksp.h"
00012 #include <iostream>
00013 #include <string>
00014 using namespace std;
00015
00016 #ifdef SINGLE
00017 #define real float
00018 #else
00019 #define real double
00020 #endif
00021
00022
00037 class PetscLinearSolver {
00038
00039 public:
00043 PetscLinearSolver();
00044
00055 void LinearSolver(int matrixSize,
00056 real **valueAMatrix,
00057 int **columnAMatrix,
00058 int totalColumn,
00059 real *rhs ,
00060 real *Sol,
00061 PCType preCond,
00062 KSPType KrylovM,
00063 real tol,
00064 int &zeroInitialGuess
00065 );
00066
00070 int finalize( );
00071
00075 ~PetscLinearSolver();
00076
00077 private:
00078 int initialize(int matrixSize,PCType preCond, KSPType KrylovM, real tol, int &zeroInitialGuess);
00079 int setRHS(real *rhs);
00080 int setAMatrix(real **AMatrix);
00081 int setSparseAMatrix(real **AMatrix, int **columnAMatrix, int totalColumn, int &zeroInitialGuess);
00082 int solve(int &zeroInitialGuess);
00083 void vecPrint(Vec x, int n);
00084 void getSol(real *Sol);
00085
00086 PetscInt n, its;
00087 PCType preConditioner;
00088 KSPType KrylovMethod;
00089
00090 Vec x, b;
00091 Mat A;
00092
00093 KSP ksp;
00094 PC pc;
00095 PetscErrorCode ierr;
00096 real KSPTolerance;
00097 };
00098
00099 #endif