Thyra  Version of the Day
Thyra_TpetraVectorSpace_def.hpp
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 
47 #include "Thyra_TpetraVectorSpace_decl.hpp"
48 #include "Thyra_TpetraThyraWrappers.hpp"
49 #include "Thyra_TpetraVector.hpp"
50 #include "Thyra_TpetraMultiVector.hpp"
51 
52 
53 namespace Thyra {
54 
55 
56 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
57 RCP<TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
59 {
60  const RCP<this_t> vs(new this_t);
61  vs->weakSelfPtr_ = vs.create_weak();
62  return vs;
63 }
64 
65 
66 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
68  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
69  )
70 {
71  comm_ = convertTpetraToThyraComm(tpetraMap->getComm());
72  tpetraMap_ = tpetraMap;
73  this->updateState(tpetraMap->getGlobalNumElements(),
74  !tpetraMap->isDistributed());
75 }
76 
77 
78 // Overridden from VectorSpace
79 
80 
81 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
82 RCP<VectorBase<Scalar> >
84 {
85  return tpetraVector<Scalar>(
86  weakSelfPtr_.create_strong().getConst(),
87  Teuchos::rcp(
88  new Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_, false)
89  )
90  );
91 }
92 
93 
94 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
95 RCP< MultiVectorBase<Scalar> >
97 {
98  return tpetraMultiVector<Scalar>(
99  weakSelfPtr_.create_strong().getConst(),
100  tpetraVectorSpace<Scalar>(
101  Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(
102  numMembers, tpetraMap_->getComm(), tpetraMap_->getNode()
103  )
104  ),
105  Teuchos::rcp(
106  new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
107  tpetraMap_, numMembers, false)
108  )
109  );
110  // ToDo: Create wrapper function to create locally replicated vector space
111  // and use it.
112 }
113 
114 
115 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
117  const Range1D& rng_in, const EViewType viewType, const EStrideType strideType
118  ) const
119 {
120  const Range1D rng = full_range(rng_in,0,this->dim()-1);
121  const Ordinal l_localOffset = this->localOffset();
122 
123  const Ordinal myLocalSubDim = tpetraMap_.is_null () ?
124  static_cast<Ordinal> (0) : tpetraMap_->getNodeNumElements ();
125 
126  return ( l_localOffset<=rng.lbound() && rng.ubound()<l_localOffset+myLocalSubDim );
127 }
128 
129 
130 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
131 RCP< const VectorSpaceBase<Scalar> >
133 {
134  return tpetraVectorSpace<Scalar>(tpetraMap_);
135 }
136 
137 // Overridden from ScalarProdVectorSpaceBase, via SpmdVectorSpaceDefaultBase
138 
139 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
142  const ArrayView<Scalar> &scalarProds_out) const
143 {
145  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpetraMV;
146  RCP<const TpetraMV> tX = TOVE::getConstTpetraMultiVector(Teuchos::rcpFromRef(X)),
147  tY = TOVE::getConstTpetraMultiVector(Teuchos::rcpFromRef(Y));
148  tX->dot(*tY, scalarProds_out);
149 }
150 
151 // Overridden from SpmdVectorSpaceDefaultBase
152 
153 
154 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
155 RCP<const Teuchos::Comm<Ordinal> >
157 {
158  return comm_;
159 }
160 
161 
162 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
164 {
165  return tpetraMap_.is_null () ? static_cast<Ordinal> (0) :
166  static_cast<Ordinal> (tpetraMap_->getNodeNumElements ());
167 }
168 
169 // private
170 
171 
172 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
174 {
175  // The base classes should automatically default initialize to a safe
176  // uninitialized state.
177 }
178 
179 
180 } // end namespace Thyra
181 
182 
183 #endif // THYRA_TPETRA_VECTOR_SPACE_HPP
RCP< VectorBase< Scalar > > createMember() const
RCP< const VectorSpaceBase< Scalar > > clone() const
Concrete implementation of an SPMD vector space for Tpetra.
RCP< const Teuchos::Comm< Ordinal > > getComm() 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.
Traits class that enables the extraction of Tpetra operator/vector objects wrapped in Thyra operator/...
EViewType
Determines if a view is a direct view of data or a detached copy of data.
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
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< const Teuchos::Comm< Ordinal > > convertTpetraToThyraComm(const RCP< const Teuchos::Comm< int > > &tpetraComm)
Given an Tpetra Teuchos::Comm<int> object, return an equivalent Teuchos::Comm<Ordinal> object...
void scalarProdsImpl(const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y, const ArrayView< Scalar > &scalarProds_out) const
Calls getScalarProd()->scalarProds(X,Y,scalar_prods)
EStrideType
Determine if data is unit stride or non-unit stride.
Teuchos::Range1D Range1D