00001 /* @HEADER@ */ 00002 // 00003 /* @HEADER@ */ 00004 00005 #ifndef PLAYA_VECTORSPACEDECL_HPP 00006 #define PLAYA_VECTORSPACEDECL_HPP 00007 00008 #include "PlayaDefs.hpp" 00009 #include "PlayaHandle.hpp" 00010 #include "PlayaVectorSpaceBaseDecl.hpp" 00011 #include "PlayaBlockIteratorDecl.hpp" 00012 00013 namespace Playa 00014 { 00015 using namespace Teuchos; 00016 00017 /** 00018 * User-level VectorSpace class. 00019 */ 00020 template <class Scalar> 00021 class VectorSpace : public Playa::Handle< const VectorSpaceBase<Scalar> > 00022 { 00023 public: 00024 HANDLE_CTORS(VectorSpace<Scalar>, const VectorSpaceBase<Scalar>); 00025 00026 /** Create a new element of this vector space */ 00027 Vector<Scalar> createMember() const ; 00028 00029 /** Return the dimension of the space */ 00030 int dim() const {return this->ptr()->dim();} 00031 00032 /** Return the lowest global index accessible on this processor */ 00033 int baseGlobalNaturalIndex() const ; 00034 00035 /** Return the number of elements owned by this processor */ 00036 int numLocalElements() const ; 00037 00038 /** Return the MPI communicator */ 00039 const MPIComm& comm() const {return this->ptr()->comm();} 00040 00041 /** Check compatibility with another space. */ 00042 bool isCompatible(const VectorSpace<Scalar>& vecSpc) const; 00043 00044 00045 /** test equality between two spaces */ 00046 bool operator==(const VectorSpace<Scalar>& other) const ; 00047 00048 00049 /** test inequality of two spaces */ 00050 bool operator!=(const VectorSpace<Scalar>& other) const ; 00051 00052 00053 /** test whether the space contains a given vector */ 00054 bool contains(const Vector<Scalar>& vec) const ; 00055 00056 00057 /** return the number of subblocks at the highest level. */ 00058 int numBlocks() const ; 00059 00060 /** indicate whether I am a block vector space */ 00061 bool isBlockSpace() const ; 00062 00063 /** get the i-th subblock */ 00064 const VectorSpace<Scalar>& getBlock(int i) const ; 00065 00066 /** get a subblock as specified by a block iterator */ 00067 const VectorSpace<Scalar>& getBlock(const BlockIterator<Scalar>& iter) const ; 00068 00069 /** get a subblock as specified by a deque of indices */ 00070 const VectorSpace<Scalar>& getBlock(const std::deque<int>& iter) const ; 00071 00072 /** */ 00073 BlockIterator<Scalar> beginBlock() const ; 00074 00075 /** */ 00076 BlockIterator<Scalar> endBlock() const ; 00077 00078 /** */ 00079 int mapToGNI(const BlockIterator<Scalar>& b, int indexWithinBlock) const ; 00080 00081 /** */ 00082 bool containsGNI(int gni) const ; 00083 00084 /** */ 00085 void getBlockAndOffsetFromGNI(int gni, 00086 BlockIterator<Scalar>& block, int& indexWithinBlock) const ; 00087 00088 protected: 00089 00090 00091 }; 00092 00093 #define PLAYA_CHECK_SPACES(space1, space2) \ 00094 TEUCHOS_TEST_FOR_EXCEPTION(!space1.isCompatible(space2), std::runtime_error, \ 00095 "incompatible spaces " << space1 << " and " << space2) 00096 00097 00098 template <class Scalar> 00099 STREAM_OUT(VectorSpace<Scalar>) 00100 00101 00102 00103 } 00104 00105 00106 #endif