Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Tpetra_Experimental_BlockMultiVector_decl.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_BLOCKMULTIVECTOR_DECL_HPP
00043 #define TPETRA_EXPERIMENTAL_BLOCKMULTIVECTOR_DECL_HPP
00044 
00045 #include <Tpetra_MultiVector.hpp>
00046 #include <Tpetra_Experimental_BlockView.hpp>
00047 
00048 namespace Tpetra {
00049 namespace Experimental {
00050 
00051 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00052 // Forward declaration of BlockCrsMatrix, needed for debugging.
00053 template<class S, class LO, class GO, class N> class BlockCrsMatrix;
00054 #endif // DOXYGEN_SHOULD_SKIP_THIS
00055 
00143 template<class Scalar = ::Tpetra::MultiVector<>::scalar_type,
00144          class LO = typename ::Tpetra::MultiVector<Scalar>::local_ordinal_type,
00145          class GO = typename ::Tpetra::MultiVector<Scalar, LO>::global_ordinal_type,
00146          class Node = typename ::Tpetra::MultiVector<Scalar, LO, GO>::node_type>
00147 class BlockMultiVector :
00148     public Tpetra::DistObject<Scalar, LO, GO, Node>
00149 {
00150 private:
00151   typedef Tpetra::DistObject<Scalar, LO, GO, Node> dist_object_type;
00152   typedef Teuchos::ScalarTraits<Scalar> STS;
00153 
00154 protected:
00155   typedef Scalar packet_type;
00156 
00157 public:
00159 
00160 
00162   typedef Scalar scalar_type;
00164   typedef LO local_ordinal_type;
00166   typedef GO global_ordinal_type;
00168   typedef Node node_type;
00169 
00171   typedef Tpetra::Map<local_ordinal_type, global_ordinal_type,
00172                       node_type> map_type;
00174   typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
00175                               global_ordinal_type, node_type> mv_type;
00176 
00192   typedef LittleVector<Scalar, LO> little_vec_type;
00193 
00199   typedef LittleVector<const Scalar, LO> const_little_vec_type;
00200 
00202 
00203 
00204 
00235   BlockMultiVector (const map_type& meshMap,
00236                     const LO blockSize,
00237                     const LO numVecs);
00238 
00243   BlockMultiVector (const map_type& meshMap,
00244                     const map_type& pointMap,
00245                     const LO blockSize,
00246                     const LO numVecs);
00247 
00260   BlockMultiVector (const mv_type& X_mv,
00261                     const map_type& meshMap,
00262                     const LO blockSize);
00263 
00268   BlockMultiVector ();
00269 
00271 
00272 
00273 
00280   static map_type
00281   makePointMap (const map_type& meshMap, const LO blockSize);
00282 
00287   map_type getPointMap () const {
00288     return pointMap_;
00289   }
00290 
00292   LO getBlockSize () const {
00293     return blockSize_;
00294   }
00295 
00297   LO getNumVectors () const {
00298     return static_cast<LO> (mv_.getNumVectors ());
00299   }
00300 
00306   mv_type getMultiVectorView ();
00307 
00309 
00310 
00311 
00313   void putScalar (const Scalar& val);
00314 
00316   void scale (const Scalar& val);
00317 
00319 
00320 
00321 
00339   bool replaceLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]) const;
00340 
00351   bool replaceGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const;
00352 
00363   bool sumIntoLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]) const;
00364 
00375   bool sumIntoGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const;
00376 
00387   bool getLocalRowView (const LO localRowIndex, const LO colIndex, Scalar*& vals) const;
00388 
00399   bool getGlobalRowView (const GO globalRowIndex, const LO colIndex, Scalar*& vals) const;
00400 
00412   little_vec_type
00413   getLocalBlock (const LO localRowIndex, const LO colIndex) const;
00415 
00416 protected:
00423 
00424 
00425   virtual bool checkSizes (const Tpetra::SrcDistObject& source);
00426 
00427   virtual void
00428   copyAndPermute (const Tpetra::SrcDistObject& source,
00429                   size_t numSameIDs,
00430                   const Teuchos::ArrayView<const LO>& permuteToLIDs,
00431                   const Teuchos::ArrayView<const LO>& permuteFromLIDs);
00432 
00433   virtual void
00434   packAndPrepare (const Tpetra::SrcDistObject& source,
00435                   const Teuchos::ArrayView<const LO>& exportLIDs,
00436                   Teuchos::Array<packet_type>& exports,
00437                   const Teuchos::ArrayView<size_t>& numPacketsPerLID,
00438                   size_t& constantNumPackets,
00439                   Tpetra::Distributor& distor);
00440 
00441   virtual void
00442   unpackAndCombine (const Teuchos::ArrayView<const LO> &importLIDs,
00443                     const Teuchos::ArrayView<const packet_type> &imports,
00444                     const Teuchos::ArrayView<size_t> &numPacketsPerLID,
00445                     size_t constantNumPackets,
00446                     Tpetra::Distributor& distor,
00447                     Tpetra::CombineMode CM);
00449 
00450 protected:
00452   Scalar* getRawPtr () const {
00453     return mvData_;
00454   }
00455 
00457   size_t getStrideX () const {
00458     return static_cast<size_t> (1);
00459   }
00460 
00462   size_t getStrideY () const {
00463     return mv_.getStride ();
00464   }
00465 
00468   bool isValidLocalMeshIndex (const LO meshLocalIndex) const {
00469     return meshLocalIndex != Teuchos::OrdinalTraits<LO>::invalid () &&
00470       meshMap_.isNodeLocalElement (meshLocalIndex);
00471   }
00472 
00473 private:
00474   // mfh 20 May 2014: I'm only using this for debugging.
00475   template<class Scalar2, class LO2, class GO2, class Node2>
00476   friend class BlockCrsMatrix;
00477 
00483   map_type meshMap_;
00484 
00486   map_type pointMap_;
00487 
00488 protected:
00490   mv_type mv_;
00491 
00492 private:
00501   Scalar* mvData_;
00502 
00504   LO blockSize_;
00505 
00507   void
00508   replaceLocalValuesImpl (const LO localRowIndex,
00509                           const LO colIndex,
00510                           const Scalar vals[]) const;
00512   void
00513   sumIntoLocalValuesImpl (const LO localRowIndex,
00514                           const LO colIndex,
00515                           const Scalar vals[]) const;
00516 
00517   static Teuchos::RCP<const mv_type>
00518   getMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject&);
00519 
00520   static Teuchos::RCP<const BlockMultiVector<Scalar, LO, GO, Node> >
00521   getBlockMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject& src);
00522 };
00523 
00524 } // namespace Experimental
00525 } // namespace Tpetra
00526 
00527 #endif // TPETRA_EXPERIMENTAL_BLOCKMULTIVECTOR_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines