Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Tpetra_Experimental_BlockVector_def.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //          Tpetra: Templated Linear Algebra Services Package
00005 //                 Copyright (2008) 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 Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 
00042 #ifndef TPETRA_EXPERIMENTAL_BLOCKVECTOR_DEF_HPP
00043 #define TPETRA_EXPERIMENTAL_BLOCKVECTOR_DEF_HPP
00044 
00045 namespace Tpetra {
00046 namespace Experimental {
00047 
00048   template<class Scalar, class LO, class GO, class Node>
00049   BlockVector<Scalar, LO, GO, Node>::
00050   BlockVector (const map_type& meshMap, const LO blockSize) :
00051     base_type (meshMap, blockSize, 1)
00052   {}
00053 
00054   template<class Scalar, class LO, class GO, class Node>
00055   BlockVector<Scalar, LO, GO, Node>::
00056   BlockVector (const map_type& meshMap,
00057                const map_type& pointMap,
00058                const LO blockSize) :
00059     base_type (meshMap, pointMap, blockSize, 1)
00060   {}
00061 
00062   template<class Scalar, class LO, class GO, class Node>
00063   BlockVector<Scalar, LO, GO, Node>::
00064   BlockVector (const mv_type& X_mv,
00065                const map_type& meshMap,
00066                const LO blockSize) :
00067     base_type (X_mv, meshMap, blockSize)
00068   {
00069     TEUCHOS_TEST_FOR_EXCEPTION(
00070       X_mv.getNumVectors () != 1, std::invalid_argument,
00071       "Tpetra::Experimental::BlockVector: Input MultiVector has "
00072       << X_mv.getNumVectors () << " != 1 columns.");
00073   }
00074 
00075   template<class Scalar, class LO, class GO, class Node>
00076   BlockVector<Scalar, LO, GO, Node>::
00077   BlockVector () : base_type () {}
00078 
00079   template<class Scalar, class LO, class GO, class Node>
00080   typename BlockVector<Scalar, LO, GO, Node>::vec_type
00081   BlockVector<Scalar, LO, GO, Node>::getVectorView () {
00082     Teuchos::RCP<vec_type> vPtr = this->mv_.getVectorNonConst (0);
00083     vPtr->setCopyOrView (Teuchos::View);
00084     return *vPtr; // shallow copy
00085   }
00086 
00087   template<class Scalar, class LO, class GO, class Node>
00088   bool
00089   BlockVector<Scalar, LO, GO, Node>::
00090   replaceLocalValues (const LO localRowIndex, const Scalar vals[]) const {
00091     return ((const base_type*) this)->replaceLocalValues (localRowIndex, 0, vals);
00092   }
00093 
00094   template<class Scalar, class LO, class GO, class Node>
00095   bool
00096   BlockVector<Scalar, LO, GO, Node>::
00097   replaceGlobalValues (const GO globalRowIndex, const Scalar vals[]) const {
00098     return ((const base_type*) this)->replaceGlobalValues (globalRowIndex, 0, vals);
00099   }
00100 
00101 
00102   template<class Scalar, class LO, class GO, class Node>
00103   bool
00104   BlockVector<Scalar, LO, GO, Node>::
00105   sumIntoLocalValues (const LO localRowIndex, const Scalar vals[]) const {
00106     return ((const base_type*) this)->sumIntoLocalValues (localRowIndex, 0, vals);
00107   }
00108 
00109   template<class Scalar, class LO, class GO, class Node>
00110   bool
00111   BlockVector<Scalar, LO, GO, Node>::
00112   sumIntoGlobalValues (const GO globalRowIndex, const Scalar vals[]) const {
00113     return ((const base_type*) this)->sumIntoLocalValues (globalRowIndex, 0, vals);
00114   }
00115 
00116   template<class Scalar, class LO, class GO, class Node>
00117   bool
00118   BlockVector<Scalar, LO, GO, Node>::
00119   getLocalRowView (const LO localRowIndex, Scalar*& vals) const {
00120     return ((const base_type*) this)->getLocalRowView (localRowIndex, 0, vals);
00121   }
00122 
00123   template<class Scalar, class LO, class GO, class Node>
00124   bool
00125   BlockVector<Scalar, LO, GO, Node>::
00126   getGlobalRowView (const GO globalRowIndex, Scalar*& vals) const {
00127     return ((const base_type*) this)->getGlobalRowView (globalRowIndex, 0, vals);
00128   }
00129 
00141   template<class Scalar, class LO, class GO, class Node>
00142   typename BlockVector<Scalar, LO, GO, Node>::little_vec_type
00143   BlockVector<Scalar, LO, GO, Node>::
00144   getLocalBlock (const LO localRowIndex) const
00145   {
00146     if (! this->isValidLocalMeshIndex (localRowIndex)) {
00147       return little_vec_type (NULL, 0, 0);
00148     } else {
00149       const LO strideX = this->getStrideX ();
00150       const size_t blockSize = this->getBlockSize ();
00151       const size_t offset = localRowIndex * blockSize * strideX;
00152       return little_vec_type (this->getRawPtr () + offset, blockSize, strideX);
00153     }
00154   }
00155 
00156 } // namespace Experimental
00157 } // namespace Tpetra
00158 
00159 //
00160 // Explicit instantiation macro
00161 //
00162 // Must be expanded from within the Tpetra namespace!
00163 //
00164 #define TPETRA_EXPERIMENTAL_BLOCKVECTOR_INSTANT(S,LO,GO,NODE) \
00165   template class Experimental::BlockVector< S, LO, GO, NODE >;
00166 
00167 #endif // TPETRA_EXPERIMENTAL_BLOCKVECTOR_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines