Thyra Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_TpetraMultiVector_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 #ifndef THYRA_TPETRA_MULTIVECTOR_HPP
43 #define THYRA_TPETRA_MULTIVECTOR_HPP
44 
47 #include "Thyra_TpetraVector.hpp"
48 #include "Teuchos_Assert.hpp"
49 
50 
51 namespace Thyra {
52 
53 
54 // Constructors/initializers/accessors
55 
56 
57 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
59 {}
60 
61 
62 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
64  const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
65  const RCP<const ScalarProdVectorSpaceBase<Scalar> > &domainSpace,
66  const RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector
67  )
68 {
69  initializeImpl(tpetraVectorSpace, domainSpace, tpetraMultiVector);
70 }
71 
72 
73 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
75  const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
76  const RCP<const ScalarProdVectorSpaceBase<Scalar> > &domainSpace,
77  const RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector
78  )
79 {
80  initializeImpl(tpetraVectorSpace, domainSpace, tpetraMultiVector);
81 }
82 
83 
84 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
87 {
88  return tpetraMultiVector_.getNonconstObj();
89 }
90 
91 
92 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
95 {
96  return tpetraMultiVector_;
97 }
98 
99 
100 // Overridden public functions form MultiVectorAdapterBase
101 
102 
103 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
106 {
107  return domainSpace_;
108 }
109 
110 
111 // Overridden public functions from SpmdMultiVectorBase
112 
113 
114 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
117 {
118  return tpetraVectorSpace_;
119 }
120 
121 
122 // Overridden protected functions from MultiVectorBase
123 
124 
125 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
128 {
129 #ifdef TEUCHOS_DEBUG
130  TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, this->domain()->dim());
131 #endif
132  return constTpetraVector<Scalar>(
133  tpetraVectorSpace_,
134  tpetraMultiVector_->getVector(j)
135  );
136 }
137 
138 
139 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
142 {
143 #ifdef TEUCHOS_DEBUG
144  TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, this->domain()->dim());
145 #endif
146  return tpetraVector<Scalar>(
147  tpetraVectorSpace_,
148  tpetraMultiVector_.getNonconstObj()->getVectorNonConst(j)
149  );
150 }
151 
152 
153 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
156  const Range1D& col_rng_in
157  ) const
158 {
159 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
160  std::cerr << "\nTpetraMultiVector::subView(Range1D) const called!\n";
161 #endif
162  const Range1D colRng = this->validateColRange(col_rng_in);
163 
165  this->getConstTpetraMultiVector()->subView(colRng);
166 
167  const RCP<const ScalarProdVectorSpaceBase<Scalar> > viewDomainSpace =
168  tpetraVectorSpace<Scalar>(
169  Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal>(
170  tpetraView->getNumVectors(),
171  tpetraView->getMap()->getComm(),
172  tpetraView->getMap()->getNode()
173  )
174  );
175 
176  return constTpetraMultiVector(
177  tpetraVectorSpace_,
178  viewDomainSpace,
179  tpetraView
180  );
181 }
182 
183 
184 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
187  const Range1D& col_rng_in
188  )
189 {
190 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
191  std::cerr << "\nTpetraMultiVector::subView(Range1D) called!\n";
192 #endif
193  const Range1D colRng = this->validateColRange(col_rng_in);
194 
196  this->getTpetraMultiVector()->subViewNonConst(colRng);
197 
198  const RCP<const ScalarProdVectorSpaceBase<Scalar> > viewDomainSpace =
199  tpetraVectorSpace<Scalar>(
200  Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal>(
201  tpetraView->getNumVectors(),
202  tpetraView->getMap()->getComm(),
203  tpetraView->getMap()->getNode()
204  )
205  );
206 
207  return tpetraMultiVector(
208  tpetraVectorSpace_,
209  viewDomainSpace,
210  tpetraView
211  );
212 }
213 
214 
215 /* ToDo: Implement these?
216 
217 
218 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
219 RCP<const MultiVectorBase<Scalar> >
220 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::nonContigSubViewImpl(
221  const ArrayView<const int> &cols
222  ) const
223 {
224  THYRA_DEBUG_ASSERT_MV_COLS("nonContigSubViewImpl(cols)", cols);
225  const int numCols = cols.size();
226  const ArrayRCP<Scalar> localValuesView = createContiguousCopy(cols);
227  return defaultSpmdMultiVector<Scalar>(
228  spmdRangeSpace_,
229  createSmallScalarProdVectorSpaceBase<Scalar>(spmdRangeSpace_, numCols),
230  localValuesView
231  );
232 }
233 
234 
235 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
236 RCP<MultiVectorBase<Scalar> >
237 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::nonconstNonContigSubViewImpl(
238  const ArrayView<const int> &cols )
239 {
240  THYRA_DEBUG_ASSERT_MV_COLS("nonContigSubViewImpl(cols)", cols);
241  const int numCols = cols.size();
242  const ArrayRCP<Scalar> localValuesView = createContiguousCopy(cols);
243  const Ordinal localSubDim = spmdRangeSpace_->localSubDim();
244  RCP<CopyBackSpmdMultiVectorEntries<Scalar> > copyBackView =
245  copyBackSpmdMultiVectorEntries<Scalar>(cols, localValuesView.getConst(),
246  localSubDim, localValues_.create_weak(), leadingDim_);
247  return Teuchos::rcpWithEmbeddedObjPreDestroy(
248  new TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
249  spmdRangeSpace_,
250  createSmallScalarProdVectorSpaceBase<Scalar>(spmdRangeSpace_, numCols),
251  localValuesView),
252  copyBackView
253  );
254 }
255 
256 */
257 
258 
259 // Overridden protected members from SpmdMultiVectorBase
260 
261 
262 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
264  const Ptr<ArrayRCP<Scalar> > &localValues, const Ptr<Ordinal> &leadingDim
265  )
266 {
267  *localValues = tpetraMultiVector_.getNonconstObj()->get1dViewNonConst();
268  *leadingDim = tpetraMultiVector_->getStride();
269 }
270 
271 
272 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
274  const Ptr<ArrayRCP<const Scalar> > &localValues, const Ptr<Ordinal> &leadingDim
275  ) const
276 {
277  *localValues = tpetraMultiVector_->get1dView();
278  *leadingDim = tpetraMultiVector_->getStride();
279 }
280 
281 
282 // private
283 
284 
285 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
286 template<class TpetraMultiVector_t>
288  const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
289  const RCP<const ScalarProdVectorSpaceBase<Scalar> > &domainSpace,
290  const RCP<TpetraMultiVector_t> &tpetraMultiVector
291  )
292 {
293 #ifdef THYRA_DEBUG
294  TEUCHOS_ASSERT(nonnull(tpetraVectorSpace));
295  TEUCHOS_ASSERT(nonnull(domainSpace));
296  TEUCHOS_ASSERT(nonnull(tpetraMultiVector));
297  // ToDo: Check to make sure that tpetraMultiVector is compatible with
298  // tpetraVectorSpace.
299 #endif
300  tpetraVectorSpace_ = tpetraVectorSpace;
301  domainSpace_ = domainSpace;
302  tpetraMultiVector_.initialize(tpetraMultiVector);
303  this->updateSpmdSpace();
304 }
305 
306 
307 
308 } // end namespace Thyra
309 
310 
311 #endif // THYRA_TPETRA_MULTIVECTOR_HPP
TpetraMultiVector()
Construct to uninitialized.
RCP< const VectorBase< Scalar > > colImpl(Ordinal j) const
Concrete implementation of an SPMD vector space for Tpetra.
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraMultiVector()
Extract the underlying non-const Tpetra::MultiVector object.
RCP< MultiVectorBase< Scalar > > nonconstContigSubViewImpl(const Range1D &colRng)
void getNonconstLocalDataImpl(const Ptr< ArrayRCP< Scalar > > &localValues, const Ptr< Ordinal > &leadingDim)
void initializeImpl(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace, const RCP< TpetraMultiVector_t > &tpetraMultiVector)
RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpace() const
void initialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace, const RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector)
Initialize.
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
RCP< const MultiVectorBase< Scalar > > contigSubViewImpl(const Range1D &colRng) const
void constInitialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace, const RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector)
Initialize.
RCP< VectorBase< Scalar > > nonconstColImpl(Ordinal j)
bool nonnull(const boost::shared_ptr< T > &p)
void getLocalDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues, const Ptr< Ordinal > &leadingDim) const
RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraMultiVector() const
Extract the underlying const Tpetra::MultiVector object.
#define TEUCHOS_ASSERT(assertion_test)
Teuchos_Ordinal Ordinal
RCP< const ScalarProdVectorSpaceBase< Scalar > > domainScalarProdVecSpc() const