Actual source code: matrix.h

  1: #ifndef __PETSc_Matrix_h__

  4: // this contains the PETSc definition of Matrix
 5:  #include petscmat.h

 7:  #include esi/petsc/vector.h

  9: // The esi::petsc::Matrix supports the
 10: #include "esi/Operator.h"
 11: #include "esi/MatrixData.h"
 12: #include "esi/MatrixRowReadAccess.h"
 13: #include "esi/MatrixRowWriteAccess.h"

 15: namespace esi{namespace petsc{

 17: /**=========================================================================**/
 18: template<class Scalar,class Ordinal>
 19: class Matrix : public virtual esi::Operator<Scalar,Ordinal>,
 20:                public virtual esi::MatrixData<Ordinal>,
 21:                public virtual esi::MatrixRowReadAccess<Scalar,Ordinal>,
 22:                public virtual esi::MatrixRowWriteAccess<Scalar,Ordinal>,
 23:                public         esi::petsc::Object
 24: {
 25:   public:

 27:     // Default destructor.
 28:     ~Matrix();

 30:     // Construct a matrix from two IndexSpaces.
 31:     Matrix(esi::IndexSpace<Ordinal> *rsource,esi::IndexSpace<Ordinal> *csource);

 33:     // Construct a esi::petsc::matrix from a PETSc Mat
 34:     Matrix(Mat pmat);

 36:     //  Interface for esi::Object  ---------------

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

 41:     //  Interface for esi::Operator  ---------------

 43:     virtual esi::ErrorCode setup();
 44:     virtual esi::ErrorCode apply( esi::Vector<Scalar,Ordinal>& x, esi::Vector<Scalar,Ordinal>& y);

 46:     //  Interface for esi::MatrixData  ---------------
 47:     virtual esi::ErrorCode getGlobalSizes(Ordinal& rows, Ordinal& columns);
 48:     virtual esi::ErrorCode getLocalSizes(Ordinal& rows, Ordinal& columns);

 50:     //  Interface for esi::MatrixRowAccess  --------

 52:     virtual esi::ErrorCode getIndexSpaces(esi::IndexSpace<Ordinal>*& rowIndexSpace, esi::IndexSpace<Ordinal>*& colIndexSpace);
 53:     virtual esi::ErrorCode isLoaded(bool &state);
 54:     virtual esi::ErrorCode isAllocated(bool &state);
 55:     virtual esi::ErrorCode loadComplete(void);
 56:     virtual esi::ErrorCode allocate(Ordinal *rowLengths);
 57:     virtual esi::ErrorCode getDiagonal(esi::Vector<Scalar,Ordinal>& diagVector) ;
 58:     virtual esi::ErrorCode getRowSum(esi::Vector<Scalar,Ordinal>& rowSumVector) ;
 59:     virtual esi::ErrorCode getRowNonzeros(Ordinal row, Ordinal& length);
 60:     virtual esi::ErrorCode setRowLength(Ordinal row,Ordinal length);
 61:     virtual esi::ErrorCode getRow(Ordinal row, Ordinal& length, Scalar*& coefs, Ordinal*& colIndices) ;
 62:     virtual esi::ErrorCode getRowCoefs(Ordinal row, Ordinal& length, Scalar*& coefs) ;
 63:     virtual esi::ErrorCode getRowIndices(Ordinal row, Ordinal& length, Ordinal*& colIndices) ;
 64:     virtual esi::ErrorCode restoreRow(Ordinal row, Ordinal& length, Scalar*& coefs, Ordinal*& colIndices) ;
 65:     virtual esi::ErrorCode restoreRowCoefs(Ordinal row, Ordinal& length, Scalar*& coefs) ;
 66:     virtual esi::ErrorCode restoreRowIndices(Ordinal row, Ordinal& length, Ordinal*& colIndices) ;
 67:     virtual esi::ErrorCode copyIntoRow(Ordinal row,  Scalar* coefs, Ordinal* colIndices, Ordinal length);
 68:     virtual esi::ErrorCode sumIntoRow(Ordinal row,  Scalar* coefs, Ordinal* colIndices, Ordinal length);
 69:     virtual esi::ErrorCode rowMax(Ordinal row, Scalar& result) ;
 70:     virtual esi::ErrorCode rowMin(Ordinal row, Scalar& result) ;

 72:     virtual esi::ErrorCode getRowAllocatedLength(Ordinal row, int& result) {return 1;};
 73:     virtual esi::ErrorCode setAllValues(Scalar) {return 1;};
 74:     virtual esi::ErrorCode allocateRowsSameLength(Ordinal) {return 1;};
 75:     virtual esi::ErrorCode copyOutRow(Ordinal, Scalar *,int *,int,int&) ;
 76:     virtual esi::ErrorCode copyOutRowIndices(Ordinal, int *,int,int&) {return 1;};
 77:     virtual esi::ErrorCode copyOutRowCoefficients(Ordinal, Scalar *,int,int&) {return 1;};

 79:     class Factory  : public virtual esi::Operator<Scalar,Ordinal>::Factory
 80:     {
 81:       public:

 83:         // Destructor.
 84:         virtual ~Factory(void){};

 86:         // Construct a Operator
 87:         virtual esi::ErrorCode create(esi::IndexSpace<Ordinal>&,esi::IndexSpace<Ordinal>&,esi::Operator<Scalar,Ordinal>*&v);
 88:     };

 90:   private:
 91:     Mat                        mat;
 92:     ::esi::IndexSpace<Ordinal> *rmap,*cmap;
 93: };

 95: /**=========================================================================**/
 96: template<>
 97: class Matrix<double,int> : public virtual esi::Operator<double,int>,
 98:                public virtual esi::MatrixData<int>,
 99:                public virtual esi::MatrixRowReadAccess<double,int>,
100:                public virtual esi::MatrixRowWriteAccess<double,int>,
101:                public         esi::petsc::Object
102: {
103:   public:

105:     // Default destructor.
106:     ~Matrix();

108:     // Construct a matrix from two IndexSpaces.
109:     Matrix(esi::IndexSpace<int> *rsource,esi::IndexSpace<int> *csource);

111:     // Construct a esi::petsc::matrix from a PETSc Mat
112:     Matrix(Mat pmat);

114:     //  Interface for esi::Object  ---------------

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


120:     //  Interface for esi::Operator  ---------------

122:     virtual esi::ErrorCode setup();
123:     virtual esi::ErrorCode apply( esi::Vector<double,int>& x, esi::Vector<double,int>& y);

125:     //  Interface for esi::MatrixData  ---------------
126:     virtual esi::ErrorCode getGlobalSizes(int& rows, int& columns);
127:     virtual esi::ErrorCode getLocalSizes(int& rows, int& columns);

129:     //  Interface for esi::MatrixRowAccess  --------

131:     virtual esi::ErrorCode getIndexSpaces(esi::IndexSpace<int>*& rowIndexSpace, esi::IndexSpace<int>*& colIndexSpace);
132:     virtual esi::ErrorCode isLoaded(bool &state);
133:     virtual esi::ErrorCode isAllocated(bool &state);
134:     virtual esi::ErrorCode loadComplete(void);
135:     virtual esi::ErrorCode allocate(int *rowLengths);
136:     virtual esi::ErrorCode getDiagonal(esi::Vector<double,int>& diagVector) ;
137:     virtual esi::ErrorCode getRowSum(esi::Vector<double,int>& rowSumVector) ;
138:     virtual esi::ErrorCode getRowNonzeros(int row, int& length);
139:     virtual esi::ErrorCode setRowLength(int row,int length);
140:     virtual esi::ErrorCode getRow(int row, int& length, double*& coefs, int*& colIndices) ;
141:     virtual esi::ErrorCode getRowCoefs(int row, int& length, double*& coefs) ;
142:     virtual esi::ErrorCode getRowIndices(int row, int& length, int*& colIndices) ;
143:     virtual esi::ErrorCode restoreRow(int row, int& length, double*& coefs, int*& colIndices) ;
144:     virtual esi::ErrorCode restoreRowCoefs(int row, int& length, double*& coefs) ;
145:     virtual esi::ErrorCode restoreRowIndices(int row, int& length, int*& colIndices) ;
146:     virtual esi::ErrorCode copyIntoRow(int row,  double* coefs, int* colIndices, int length);
147:     virtual esi::ErrorCode sumIntoRow(int row,  double* coefs, int* colIndices, int length);
148:     virtual esi::ErrorCode rowMax(int row, double& result) ;
149:     virtual esi::ErrorCode rowMin(int row, double& result) ;

151:     virtual esi::ErrorCode getRowAllocatedLength(int row, int& result) {return 1;};
152:     virtual esi::ErrorCode setAllValues(double) {return 1;};
153:     virtual esi::ErrorCode allocateRowsSameLength(int) {return 1;};
154:     virtual esi::ErrorCode copyOutRow(int, double *,int *,int,int&) ;
155:     virtual esi::ErrorCode copyOutRowIndices(int, int *,int,int&) {return 1;};
156:     virtual esi::ErrorCode copyOutRowCoefficients(int, double *,int,int&) {return 1;};

158:     class Factory  : public virtual esi::Operator<double,int>::Factory
159:     {
160:       public:

162:         // Destructor.
163:         virtual ~Factory(void){};

165:         // Construct a Operator
166:         virtual esi::ErrorCode create(esi::IndexSpace<int>&,esi::IndexSpace<int>&,esi::Operator<double,int>*&v);
167:     };

169:   private:
170:     Mat                    mat;
171:     ::esi::IndexSpace<int> *rmap,*cmap;
172: };

174: }}



178: EXTERN int MatESIWrap(Mat,esi::Operator<double,int>**);


181: #endif