PlayaVectorSpaceDecl.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                 Playa: Programmable Linear Algebra
00005 //                 Copyright 2012 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #ifndef PLAYA_VECTORSPACEDECL_HPP
00043 #define PLAYA_VECTORSPACEDECL_HPP
00044 
00045 #include "PlayaDefs.hpp"
00046 #include "PlayaHandle.hpp"
00047 #include "PlayaVectorSpaceBaseDecl.hpp"
00048 #include "PlayaBlockIteratorDecl.hpp"
00049 
00050 namespace Playa
00051 {
00052 using namespace Teuchos;
00053 
00054 /**
00055  *  User-level VectorSpace class.
00056  */
00057 template <class Scalar>
00058 class VectorSpace : public Playa::Handle< const VectorSpaceBase<Scalar> >
00059 {
00060 public:
00061   HANDLE_CTORS(VectorSpace<Scalar>, const VectorSpaceBase<Scalar>);
00062     
00063   /** Create a new element of this vector space */
00064   Vector<Scalar>  createMember() const ;
00065 
00066   /** Return the dimension of the space */
00067   int dim() const {return this->ptr()->dim();}
00068 
00069   /** Return the lowest global index accessible on this processor */
00070   int baseGlobalNaturalIndex() const ;
00071 
00072   /** Return the number of elements owned by this processor */
00073   int numLocalElements() const ;
00074 
00075   /** Return the MPI communicator */
00076   const MPIComm& comm() const {return this->ptr()->comm();}
00077 
00078   /** Check compatibility with another space. */
00079   bool isCompatible(const VectorSpace<Scalar>& vecSpc) const; 
00080 
00081 
00082   /** test equality between two spaces */
00083   bool operator==(const VectorSpace<Scalar>& other) const ;
00084 
00085 
00086   /** test inequality of two spaces */
00087   bool operator!=(const VectorSpace<Scalar>& other) const ;
00088 
00089 
00090   /** test whether the space contains a given vector */
00091   bool contains(const Vector<Scalar>& vec) const ;
00092 
00093 
00094   /** return the number of subblocks at the highest level. */
00095   int numBlocks() const ;
00096 
00097   /** indicate whether I am a block vector space */
00098   bool isBlockSpace() const ;
00099 
00100   /** get the i-th subblock */
00101   const VectorSpace<Scalar>& getBlock(int i) const ;
00102 
00103   /** get a subblock as specified by a block iterator */
00104   const VectorSpace<Scalar>& getBlock(const BlockIterator<Scalar>& iter) const ;
00105 
00106   /** get a subblock as specified by a deque of indices */
00107   const VectorSpace<Scalar>& getBlock(const std::deque<int>& iter) const ;
00108 
00109   /** */
00110   BlockIterator<Scalar> beginBlock() const ;
00111 
00112   /** */
00113   BlockIterator<Scalar> endBlock() const ;
00114 
00115   /** */
00116   int mapToGNI(const BlockIterator<Scalar>& b, int indexWithinBlock) const ;
00117 
00118   /** */
00119   bool containsGNI(int gni) const ;
00120 
00121   /** */
00122   void getBlockAndOffsetFromGNI(int gni,
00123     BlockIterator<Scalar>& block, int& indexWithinBlock) const ;
00124   
00125 protected:
00126   
00127 
00128 };
00129 
00130 #define PLAYA_CHECK_SPACES(space1, space2) \
00131   TEUCHOS_TEST_FOR_EXCEPTION(!space1.isCompatible(space2), std::runtime_error, \
00132     "incompatible spaces " << space1 << " and " << space2)
00133 
00134 
00135 template <class Scalar>
00136 STREAM_OUT(VectorSpace<Scalar>)
00137 
00138 
00139 
00140 }
00141 
00142 
00143 #endif

Site Contact