Actual source code: vector.h
1: #ifndef __PETSc_Vector_h__
4: // The esi::petsc::Vector supports the
5: // esi::Vector<Scalar,Ordinal>
6: // esi::Vector<Scalar,Ordinal>ReplaceAccess interfaces
8: #include esi/petsc/indexspace.h
10: #include "esi/Vector.h"
11: #include "esi/VectorReplaceAccess.h"
13: // this contains the PETSc definition of Vector
14: #include petscvec.h
16: namespace esi{namespace petsc{
18: /**=========================================================================**/
19: template<class Scalar,class Ordinal>
20: class Vector : public virtual esi::VectorReplaceAccess<Scalar,Ordinal>, public esi::petsc::Object
21: {
22: public:
24: // Destructor.
25: virtual ~Vector(void);
27: // Construct a Vector from a IndexSpace.
28: Vector( esi::IndexSpace<Ordinal> *source);
30: // Construct a Vector from a PETSc Vector
31: Vector(Vec pvec);
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_Vector ---------------
39:
40: virtual esi::ErrorCode clone(esi::Vector<Scalar,Ordinal>*& x);
41: virtual esi::ErrorCode getGlobalSize( Ordinal & dim) ;
42: virtual esi::ErrorCode getLocalSize( Ordinal & dim) ;
43: virtual esi::ErrorCode getIndexSpace( esi::IndexSpace<Ordinal>*& outmap) ;
44: virtual esi::ErrorCode copy( esi::Vector<Scalar,Ordinal>& x) ;
45: virtual esi::ErrorCode put( Scalar scalar) ;
46: virtual esi::ErrorCode scale( Scalar scalar) ;
47: virtual esi::ErrorCode scaleDiagonal( esi::Vector<Scalar,Ordinal>& x) ;
48: virtual esi::ErrorCode norm1( TYPENAME esi::Vector<Scalar,Ordinal>::magnitude_type& norm) ;
49: virtual esi::ErrorCode norm2( TYPENAME esi::Vector<Scalar,Ordinal>::magnitude_type& norm) ;
50: virtual esi::ErrorCode norm2squared( TYPENAME esi::Vector<Scalar,Ordinal>::magnitude_type& norm) ;
51: virtual esi::ErrorCode normInfinity( TYPENAME esi::Vector<Scalar,Ordinal>::magnitude_type& norm) ;
52: virtual esi::ErrorCode dot( esi::Vector<Scalar,Ordinal>& x, Scalar& product) ;
53: virtual esi::ErrorCode axpy( esi::Vector<Scalar,Ordinal>& x, Scalar scalar) ;
54: virtual esi::ErrorCode aypx(Scalar scalar, esi::Vector<Scalar,Ordinal>& x) ;
56: virtual esi::ErrorCode minAbsCoef(TYPENAME esi::Vector<Scalar,Ordinal>::magnitude_type&) {return 1;}
57: virtual esi::ErrorCode axpby(Scalar,esi::Vector<Scalar,Ordinal>&,Scalar,esi::Vector<Scalar,Ordinal>&);
58: virtual esi::ErrorCode getCoefPtrReadLock(Scalar *&) ;
59: virtual esi::ErrorCode getCoefPtrReadWriteLock(Scalar *&);
60: virtual esi::ErrorCode releaseCoefPtrLock(Scalar *&) ;
62: // Interface for ESI_VectorReplaceAccess
63:
64: virtual esi::ErrorCode setArrayPointer(Scalar* array, Ordinal length);
66: class Factory : public virtual ::esi::Vector<Scalar,Ordinal>::Factory
67: {
68: public:
70: // Destructor.
71: virtual ~Factory(void){};
73: // Construct a Vector
74: virtual esi::ErrorCode create(esi::IndexSpace<Ordinal>&,esi::Vector<Scalar,Ordinal>*&v);
75: };
77: private:
78: Vec vec;
79: esi::IndexSpace<Ordinal> *map;
80: };
82: /**=========================================================================**/
83: template<>
84: class Vector<double,int>: public virtual esi::VectorReplaceAccess<double,int>, public esi::petsc::Object
85: {
86: public:
88: // Destructor.
89: virtual ~Vector(void);
91: // Construct a Vector from a IndexSpace.
92: Vector( esi::IndexSpace<int> *source);
94: // Construct a Vector from a PETSc Vector
95: Vector(Vec pvec);
97: // Interface for esi::Object ---------------
99: virtual esi::ErrorCode getInterface(const char* name, void*& iface);
100: virtual esi::ErrorCode getInterfacesSupported(esi::Argv * list);
103: // Interface for ESI_Vector ---------------
104:
105: virtual esi::ErrorCode clone(esi::Vector<double,int>*& x);
106: virtual esi::ErrorCode getGlobalSize( int & dim) ;
107: virtual esi::ErrorCode getLocalSize( int & dim) ;
108: virtual esi::ErrorCode getIndexSpace( esi::IndexSpace<int>*& outmap) ;
109: virtual esi::ErrorCode copy( esi::Vector<double,int>& x) ;
110: virtual esi::ErrorCode put( double scalar) ;
111: virtual esi::ErrorCode scale( double scalar) ;
112: virtual esi::ErrorCode scaleDiagonal( esi::Vector<double,int>& x) ;
113: virtual esi::ErrorCode norm1( magnitude_type& norm) ;
114: virtual esi::ErrorCode norm2( magnitude_type& norm) ;
115: virtual esi::ErrorCode norm2squared( magnitude_type& norm) ;
116: virtual esi::ErrorCode normInfinity( magnitude_type& norm) ;
117: virtual esi::ErrorCode dot( esi::Vector<double,int>& x, double& product) ;
118: virtual esi::ErrorCode axpy( esi::Vector<double,int>& x, double scalar) ;
119: virtual esi::ErrorCode aypx(double scalar, esi::Vector<double,int>& x) ;
121: virtual esi::ErrorCode minAbsCoef(magnitude_type&) {return 1;}
122: virtual esi::ErrorCode axpby(double,esi::Vector<double,int>&,double,esi::Vector<double,int>&);
123: virtual esi::ErrorCode getCoefPtrReadLock(double *&) ;
124: virtual esi::ErrorCode getCoefPtrReadWriteLock(double *&);
125: virtual esi::ErrorCode releaseCoefPtrLock(double *&) ;
127: // Interface for ESI_VectorReplaceAccess
128:
129: virtual esi::ErrorCode setArrayPointer(double* array, int length);
131: class Factory : public virtual ::esi::Vector<double,int>::Factory
132: {
133: public:
135: // Destructor.
136: virtual ~Factory(void){};
138: // Construct a Vector
139: virtual esi::ErrorCode create(esi::IndexSpace<int>&,esi::Vector<double,int>*&v);
140: };
142: private:
143: Vec vec;
144: ::esi::IndexSpace<int> *map;
145: };
147: }}
148: EXTERN int VecESIWrap(Vec,esi::Vector<double,int>**);
150: #endif