Actual source code: solveriterative.h

  1: #ifndef __PETSc_SolverIterative_h__

  4: // this contains the PETSc definition of solveriterative
 5:  #include petscksp.h

 7:  #include esi/petsc/vector.h

  9: #include "esi/Operator.h"
 10: #include "esi/Preconditioner.h"
 11: #include "esi/Solver.h"
 12: // The esi::petsc::solveriterative supports the
 13: #include "esi/SolverIterative.h"

 15: namespace esi{namespace petsc{

 17: /**=========================================================================**/
 18: template<class Scalar,class Ordinal>
 19: class SolverIterative : public virtual esi::SolverIterative<Scalar,Ordinal>,
 20:                         public         esi::petsc::Object
 21: {
 22:   public:

 24:     // Default destructor.
 25:     ~SolverIterative(void);

 27:     // Construct a solveriterative from a MPI_Comm
 28:     SolverIterative(MPI_Comm comm);

 30:     // Construct a solveriterative from a PETSc KSP
 31:     SolverIterative(KSP ksp);

 33:     //  Interface for esi::Object  ---------------

 35:     virtual esi::ErrorCode getInterface(const char* name, void*& iface) ;
 36:     virtual esi::ErrorCode getInterfacesSupported(esi::Argv * list);

 38:     //  Interface for esi::Operator  ---------------

 40:     virtual esi::ErrorCode setup(void);
 41:     virtual esi::ErrorCode apply( esi::Vector<Scalar,Ordinal>& x, esi::Vector<Scalar,Ordinal>& y);

 43:     //  Interface for esi::Solver  ---------------
 44:     virtual esi::ErrorCode solve( esi::Vector<Scalar, Ordinal> & b, esi::Vector<Scalar, Ordinal> & x );

 46:     /** Set the input control parameters. */
 47:     virtual esi::ErrorCode parameters( int numParams, char** paramStrings );

 49:     //  Interface for esi::Solveriterative  ---------------
 50:     virtual esi::ErrorCode getOperator( esi::Operator<Scalar, Ordinal> * & A );

 52:     /** Set the operator. */
 53:     virtual esi::ErrorCode setOperator( esi::Operator<Scalar, Ordinal> & A );

 55:     /** Get the preconditioner. */
 56:     virtual esi::ErrorCode getPreconditioner( esi::Preconditioner<Scalar, Ordinal> * & pc );

 58:     /** Set the preconditioner. */
 59:     virtual esi::ErrorCode setPreconditioner( esi::Preconditioner<Scalar, Ordinal> & pc );

 61:     /** Get the convergence tolerance. */
 62:     virtual esi::ErrorCode getTolerance( TYPENAME esi::SolverIterative<Scalar,Ordinal>::magnitude_type & tol );

 64:     /** Set the convergence tolerance. */
 65:     virtual esi::ErrorCode setTolerance( TYPENAME esi::SolverIterative<Scalar,Ordinal>::magnitude_type tol );

 67:     /** Get the maximum number of iterations. */
 68:     virtual esi::ErrorCode getMaxIterations( Ordinal & maxIterations );

 70:     /** Set the maximum number of iterations. */
 71:     virtual esi::ErrorCode setMaxIterations( Ordinal maxIterations );

 73:     /** Query the number of iterations that were taken during the previous solve.
 74:      */
 75:     virtual esi::ErrorCode getNumIterationsTaken(Ordinal& itersTaken);

 77:     class Factory : public virtual esi::SolverIterative<Scalar,Ordinal>::Factory
 78:     {
 79:       public:

 81:         // Destructor.
 82:         virtual ~Factory(void){};

 84:         // Construct a SolverIterative
 85:         virtual esi::ErrorCode create(char *commname,void *comm,esi::SolverIterative<Scalar,Ordinal>*&v);
 86:     };

 88:   private:
 89:     KSP                                  ksp;
 90:     ::esi::Preconditioner<Scalar,Ordinal> *pre;
 91:     ::esi::Operator<Scalar,Ordinal>       *op;
 92: };

 94: template<>
 95: class SolverIterative<double,int> : public virtual esi::SolverIterative<double,int>,
 96:                                     public         esi::petsc::Object
 97: {
 98:   public:

100:     // Default destructor.
101:     ~SolverIterative(void);

103:     // Construct a solveriterative from a MPI_Comm
104:     SolverIterative(MPI_Comm comm);

106:     // Construct a solveriterative from a PETSc KSP
107:     SolverIterative(KSP ksp);

109:     //  Interface for esi::Object  ---------------

111:     virtual esi::ErrorCode getInterface(const char* name, void*& iface) ;
112:     virtual esi::ErrorCode getInterfacesSupported(esi::Argv * list);


115:     //  Interface for esi::Operator  ---------------

117:     virtual esi::ErrorCode setup(void);
118:     virtual esi::ErrorCode apply( esi::Vector<double,int>& x, esi::Vector<double,int>& y);

120:     //  Interface for esi::Solver  ---------------
121:     virtual esi::ErrorCode solve( esi::Vector<double, int> & b, esi::Vector<double, int> & x );

123:     /** Set the input control parameters. */
124:     virtual esi::ErrorCode parameters( int numParams, char** paramStrings );

126:     //  Interface for esi::SolverIterative  ---------------
127:     virtual esi::ErrorCode getOperator( esi::Operator<double, int> * & A );

129:     /** Set the operator. */
130:     virtual esi::ErrorCode setOperator( esi::Operator<double, int> & A );

132:     /** Get the preconditioner. */
133:     virtual esi::ErrorCode getPreconditioner( esi::Preconditioner<double, int> * & pc );

135:     /** Set the preconditioner. */
136:     virtual esi::ErrorCode setPreconditioner( esi::Preconditioner<double, int> & pc );

138:     /** Get the convergence tolerance. */
139:     virtual esi::ErrorCode getTolerance( magnitude_type & tol );

141:     /** Set the convergence tolerance. */
142:     virtual esi::ErrorCode setTolerance( magnitude_type tol );

144:     /** Get the maximum number of iterations. */
145:     virtual esi::ErrorCode getMaxIterations( int & maxIterations );

147:     /** Set the maximum number of iterations. */
148:     virtual esi::ErrorCode setMaxIterations( int maxIterations );

150:     /** Query the number of iterations that were taken during the previous solve.
151:      */
152:     virtual esi::ErrorCode getNumIterationsTaken(int& itersTaken);

154:     class Factory : public virtual esi::SolverIterative<double,int>::Factory
155:     {
156:       public:

158:         // Destructor.
159:         virtual ~Factory(void){};

161:         // Construct a SolverIterative
162:         virtual esi::ErrorCode create(char *commname,void *comm,esi::SolverIterative<double,int>*&v);
163:     };

165:   private:
166:     KSP                              ksp;
167:     ::esi::Preconditioner<double,int> *pre;
168:     ::esi::Operator<double,int>       *op;
169: };

171: }}


174: #endif