Thyra Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_TpetraVectorSpace_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 
43 #ifndef THYRA_TPETRA_VECTOR_SPACE_HPP
44 #define THYRA_TPETRA_VECTOR_SPACE_HPP
45 
46 
49 #include "Thyra_TpetraVector.hpp"
52 
53 
54 namespace Thyra {
55 
56 
57 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
58 RCP<TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
60 {
61  const RCP<this_t> vs(new this_t);
62  vs->weakSelfPtr_ = vs.create_weak();
63  return vs;
64 }
65 
66 
67 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
69  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
70  )
71 {
72  comm_ = convertTpetraToThyraComm(tpetraMap->getComm());
73  tpetraMap_ = tpetraMap;
74  this->updateState(tpetraMap->getGlobalNumElements(),
75  !tpetraMap->isDistributed());
76  this->setScalarProd(tpetraEuclideanScalarProd<Scalar,LocalOrdinal,GlobalOrdinal,Node>());
77 }
78 
79 
80 // Overridden from VectorSpace
81 
82 
83 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
86 {
87  return tpetraVector<Scalar>(
88  weakSelfPtr_.create_strong().getConst(),
90  new Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_, false)
91  )
92  );
93 }
94 
95 
96 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
99 {
100  return tpetraMultiVector<Scalar>(
101  weakSelfPtr_.create_strong().getConst(),
102  tpetraVectorSpace<Scalar>(
103  Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(
104  numMembers, tpetraMap_->getComm()
105  )
106  ),
107  Teuchos::rcp(
108  new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
109  tpetraMap_, numMembers, false)
110  )
111  );
112  // ToDo: Create wrapper function to create locally replicated vector space
113  // and use it.
114 }
115 
116 
117 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
119  const Range1D& rng_in, const EViewType viewType, const EStrideType strideType
120  ) const
121 {
122  const Range1D rng = full_range(rng_in,0,this->dim()-1);
123  const Ordinal l_localOffset = this->localOffset();
124 
125  const Ordinal myLocalSubDim = tpetraMap_.is_null () ?
126  static_cast<Ordinal> (0) : tpetraMap_->getNodeNumElements ();
127 
128  return ( l_localOffset<=rng.lbound() && rng.ubound()<l_localOffset+myLocalSubDim );
129 }
130 
131 
132 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
135 {
136  return tpetraVectorSpace<Scalar>(tpetraMap_);
137 }
138 
139 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
142 {
143  return tpetraMap_;
144 }
145 
146 // Overridden from SpmdVectorSpaceDefaultBase
147 
148 
149 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
152 {
153  return comm_;
154 }
155 
156 
157 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
159 {
160  return tpetraMap_.is_null () ? static_cast<Ordinal> (0) :
161  static_cast<Ordinal> (tpetraMap_->getNodeNumElements ());
162 }
163 
164 // private
165 
166 
167 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
169 {
170  // The base classes should automatically default initialize to a safe
171  // uninitialized state.
172 }
173 
174 
175 } // end namespace Thyra
176 
177 
178 #endif // THYRA_TPETRA_VECTOR_SPACE_HPP
Concrete implementation of an SPMD vector space for Tpetra.
RCP< const VectorSpaceBase< Scalar > > clone() const
RCP< T > create_weak() const
static RCP< TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > create()
Create with weak ownership to self.
void initialize(const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &tpetraMap)
Initialize a serial space.
RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getTpetraMap() const
Get the embedded Tpetra::Map.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool hasInCoreView(const Range1D &rng, const EViewType viewType, const EStrideType strideType) const
Returns true if all the elements in rng are in this process.
RCP< VectorBase< Scalar > > createMember() const
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
RCP< const Teuchos::Comm< Ordinal > > getComm() const
RCP< const Teuchos::Comm< Ordinal > > convertTpetraToThyraComm(const RCP< const Teuchos::Comm< int > > &tpetraComm)
Given an Tpetra Teuchos::Comm&lt;int&gt; object, return an equivalent Teuchos::Comm&lt;Ordinal&gt; object...
Teuchos_Ordinal Ordinal