Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Tpetra_Vector_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_VECTOR_DECL_HPP
00043 #define TPETRA_VECTOR_DECL_HPP
00044 
00045 #include "Tpetra_ConfigDefs.hpp"
00046 #include "Tpetra_MultiVector_decl.hpp"
00047 
00048 namespace Tpetra {
00049 
00068 template<class Scalar = MultiVector<>::scalar_type,
00069          class LocalOrdinal = typename MultiVector<Scalar>::local_ordinal_type,
00070          class GlobalOrdinal = typename MultiVector<Scalar, LocalOrdinal>::global_ordinal_type,
00071          class Node = typename MultiVector<Scalar, LocalOrdinal, GlobalOrdinal>::node_type>
00072 class Vector : public MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>
00073 {
00074 private:
00075   typedef MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> base_type;
00076   // need this so that MultiVector::operator() can call Vector's
00077   // private view constructor
00078   friend class MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>;
00079 
00080 public:
00082 
00083 
00085   typedef Scalar scalar_type;
00087   typedef LocalOrdinal local_ordinal_type;
00089   typedef GlobalOrdinal global_ordinal_type;
00091   typedef Node node_type;
00092 
00098   typedef typename base_type::dot_type dot_type;
00099 
00106   typedef typename base_type::mag_type mag_type;
00107 
00109   typedef Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
00110 
00112 
00113 
00114 
00120   //
00125   explicit Vector (const Teuchos::RCP<const map_type>& map,
00126                    const bool zeroOut = true);
00127 
00133   Vector (const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& source);
00134 
00152   Vector (const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& source,
00153           const Teuchos::DataAccess copyOrView);
00154 
00156   Vector (const Teuchos::RCP<const map_type>& map,
00157           const Teuchos::ArrayView<const Scalar>& A);
00158 
00160   virtual ~Vector ();
00161 
00163 
00164 
00165 
00170   template <class Node2>
00171   Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >
00172   clone (const Teuchos::RCP<Node2>& node2);
00173 
00175 
00176 
00177 
00179 
00181   void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value);
00182 
00184 
00186   void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value);
00187 
00189 
00191   void replaceLocalValue(LocalOrdinal myRow, const Scalar &value);
00192 
00194 
00196   void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value);
00197 
00199 
00201 
00202 
00203   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::get1dCopy; // overloading, not hiding
00205   void get1dCopy (Teuchos::ArrayView<Scalar> A) const;
00206 
00207   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getDataNonConst; // overloading, not hiding
00209   Teuchos::ArrayRCP<Scalar> getDataNonConst () {
00210     return this->getDataNonConst (0);
00211   }
00212 
00213   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getData; // overloading, not hiding
00215   Teuchos::ArrayRCP<const Scalar> getData() const { return getData(0); }
00216 
00218 
00220 
00221 
00222   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::dot; // overloading, not hiding
00224   Scalar dot(const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &a) const;
00225 
00226   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::norm1; // overloading, not hiding
00228   typename Teuchos::ScalarTraits<Scalar>::magnitudeType norm1() const;
00229 
00230   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::norm2; // overloading, not hiding
00232   typename Teuchos::ScalarTraits<Scalar>::magnitudeType norm2() const;
00233 
00234   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::normInf; // overloading, not hiding
00236   typename Teuchos::ScalarTraits<Scalar>::magnitudeType normInf() const;
00237 
00238   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::normWeighted; // overloading, not hiding
00240   typename Teuchos::ScalarTraits<Scalar>::magnitudeType normWeighted(const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &weights) const;
00241 
00242   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::meanValue; // overloading, not hiding
00244   Scalar meanValue() const;
00245 
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264 
00265 
00266 
00267 
00268 
00269 
00330   Teuchos::RCP<const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00331   offsetView (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& subMap,
00332               size_t offset) const;
00333 
00351   Teuchos::RCP<Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00352   offsetViewNonConst (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &subMap,
00353                       size_t offset);
00354 
00356 
00357 
00358 
00360   virtual std::string description() const;
00361 
00363   virtual void
00364   describe (Teuchos::FancyOStream& out,
00365             const Teuchos::EVerbosityLevel verbLevel =
00366             Teuchos::Describable::verbLevel_default) const;
00368 
00369 protected:
00370 
00371   template <class S,class LO,class GO,class N>
00372   friend RCP< Vector<S,LO,GO,N> >
00373   createVectorFromView(const RCP<const Map<LO,GO,N> > &,const ArrayRCP<S> &);
00374 
00375   // view constructor, sitting on user allocated data, only for CPU nodes
00376   // and his non-member constructor friend
00377   Vector (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00378           const ArrayRCP<Scalar> &view,
00379           EPrivateHostViewConstructor /* dummy tag */);
00380 
00382   Vector (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00383           const ArrayRCP<Scalar> & data);
00384 
00386   Vector (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00387           const ArrayRCP<Scalar> & data,
00388           EPrivateComputeViewConstructor /* dummy tag */);
00389 
00390   typedef KokkosClassic::MultiVector<Scalar,Node> KMV;
00391   typedef KokkosClassic::DefaultArithmetic<KMV>   MVT;
00392 }; // class Vector
00393 
00397 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00398 RCP<Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00399 createVector (const RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > &map)
00400 {
00401   const bool DO_INIT_TO_ZERO = true;
00402   return rcp (new Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map, DO_INIT_TO_ZERO));
00403 }
00404 
00406 
00409 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00410 RCP<Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00411 createVectorFromView (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00412                       const ArrayRCP<Scalar> &view)
00413 {
00414   return rcp(
00415     // this is a protected constructor, but we are friends
00416     new Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
00417       map,
00418       // this will fail to compile for unsupported node types
00419       Tpetra::details::ViewAccepter<Node>::template acceptView<Scalar>(view),
00420       HOST_VIEW_CONSTRUCTOR)
00421   );
00422 }
00423 
00424 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00425 template <class Node2>
00426 RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >
00427 Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::clone(const RCP<Node2> &node2){
00428         typedef Map<LocalOrdinal,GlobalOrdinal,Node2> Map2;
00429         typedef Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node2> V2;
00430         Teuchos::ArrayRCP<const Scalar> V_view = this->getData();
00431         Teuchos::RCP<const Map2> clonedMap = this->getMap()->template clone<Node2> (node2);
00432         Teuchos::RCP<V2> clonedV = Teuchos::rcp(new V2(clonedMap));
00433         Teuchos::ArrayRCP<Scalar> clonedV_view = clonedV->getDataNonConst();
00434         clonedV_view.deepCopy(V_view());
00435         clonedV_view = Teuchos::null;
00436         return clonedV;
00437   }
00438 
00439 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00440 Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node >
00441   createCopy( const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node >& src);
00442 } // namespace Tpetra
00443 
00444 // Include KokkosRefactor partial specialisation if enabled
00445 #if defined(TPETRA_HAVE_KOKKOS_REFACTOR)
00446 #include "Tpetra_KokkosRefactor_Vector_decl.hpp"
00447 #endif
00448 
00449 #endif // TPETRA_VECTOR_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines