Actual source code: preconditioner.h

  1: #ifndef __PETSc_Preconditioner_h__

  4: // this contains the PETSc definition of Preconditioner
 5:  #include petscpc.h

 7:  #include esi/petsc/vector.h

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

 14: namespace esi{namespace petsc{

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

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

 27:     // Construct a preconditioner from a MPI_Comm
 28:     Preconditioner(MPI_Comm comm);

 30:     // Construct a preconditioner from a PETSc PC
 31:     Preconditioner(PC pc);

 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::Preconditioner  ---------------
 44:     /** Input control parameters. */
 45:     virtual esi::ErrorCode parameters( int numParams, char** paramStrings ){return 1;};

 47:     /** z = M1^(-1) y */
 48:     virtual esi::ErrorCode solveLeft( esi::Vector<Scalar, Ordinal> & y,esi::Vector<Scalar, Ordinal> & z );
 49:     /** z = M2^(-1) y */
 50:     virtual esi::ErrorCode solveRight( esi::Vector<Scalar, Ordinal> & y, esi::Vector<Scalar, Ordinal> & z );

 52:     /** z = M^(-1) y */
 53:     virtual esi::ErrorCode solve( esi::Vector<Scalar, Ordinal> & y, esi::Vector<Scalar, Ordinal> & z );
 54: 
 55:     /** z = B y */
 56:     virtual esi::ErrorCode applyB( esi::Vector<Scalar,Ordinal>& y, esi::Vector<Scalar,Ordinal>& z );

 58:     /** Get the preconditioning side. */
 59:     virtual esi::ErrorCode getPreconditionerSide( PreconditionerSide & side );

 61:     /** Set the preconditioning side. */
 62:     virtual esi::ErrorCode setPreconditionerSide( PreconditionerSide side );

 64:     virtual esi::ErrorCode setOperator( esi::Operator<Scalar,Ordinal> &op);

 66:     class Factory : public virtual esi::Preconditioner<Scalar,Ordinal>::Factory
 67:     {
 68:       public:

 70:         // Destructor.
 71:         virtual ~Factory(void){};

 73:         // Construct a Preconditioner
 74:         virtual esi::ErrorCode create(char *commname,void* comm,esi::Preconditioner<Scalar,Ordinal>*&v);
 75:     };

 77:   private:
 78:     PC                         pc;
 79:     esi::PreconditionerSide    side;
 80: };

 82: /**=========================================================================**/
 83: template<>
 84: class Preconditioner<double,int> : public virtual esi::Preconditioner<double,int>,
 85:                        public         esi::petsc::Object
 86: {
 87:   public:

 89:     // Default destructor.
 90:     ~Preconditioner(void);

 92:     // Construct a preconditioner from a MPI_Comm
 93:     Preconditioner(MPI_Comm comm);

 95:     // Construct a preconditioner from a PETSc PC
 96:     Preconditioner(PC pc);

 98:     //  Interface for esi::Object  ---------------

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


104:     //  Interface for esi::Operator  ---------------

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

109:     //  Interface for esi::Preconditioner  ---------------
110:     /** Input control parameters. */
111:     virtual esi::ErrorCode parameters( int numParams, char** paramStrings ){return 1;};

113:     /** z = M1^(-1) y */
114:     virtual esi::ErrorCode solveLeft( esi::Vector<double, int> & y,esi::Vector<double, int> & z );
115:     /** z = M2^(-1) y */
116:     virtual esi::ErrorCode solveRight( esi::Vector<double, int> & y, esi::Vector<double, int> & z );

118:     /** z = M^(-1) y */
119:     virtual esi::ErrorCode solve( esi::Vector<double, int> & y, esi::Vector<double, int> & z );
120: 
121:     /** z = B y */
122:     virtual esi::ErrorCode applyB( esi::Vector<double,int>& y, esi::Vector<double,int>& z );

124:     /** Get the preconditioning side. */
125:     virtual esi::ErrorCode getPreconditionerSide( PreconditionerSide & side );

127:     /** Set the preconditioning side. */
128:     virtual esi::ErrorCode setPreconditionerSide( PreconditionerSide side );

130:     virtual esi::ErrorCode setOperator( esi::Operator<double,int> &op);

132:     class Factory : public virtual esi::Preconditioner<double,int>::Factory
133:     {
134:       public:

136:         // Destructor.
137:         virtual ~Factory(void){};

139:         // Construct a Preconditioner
140:         virtual esi::ErrorCode create(char *commname,void* comm,esi::Preconditioner<double,int>*&v);
141:     };


144:   private:
145:     PC                       pc;
146:     esi::IndexSpace<int>     *rmap,*cmap;
147:     esi::PreconditionerSide  side;
148: };
149: }}


152: EXTERN int PCESISetPreconditioner(PC,esi::Preconditioner<double,int>*);

154: #endif