Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_TpetraVector_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 #ifndef THYRA_TPETRA_VECTOR_HPP
43 #define THYRA_TPETRA_VECTOR_HPP
44 
45 
46 #include "Thyra_TpetraVector_decl.hpp"
47 #include "Thyra_TpetraMultiVector.hpp"
48 
49 namespace Thyra {
50 
51 
52 // Constructors/initializers/accessors
53 
54 
55 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
57 {}
58 
59 
60 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
62  const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
63  const RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector
64  )
65 {
66  initializeImpl(tpetraVectorSpace, tpetraVector);
67 }
68 
69 
70 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
72  const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
73  const RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector
74  )
75 {
76  initializeImpl(tpetraVectorSpace, tpetraVector);
77 }
78 
79 
80 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
83 {
84  return tpetraVector_.getNonconstObj();
85 }
86 
87 
88 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
91 {
92  return tpetraVector_;
93 }
94 
95 
96 // Overridden from VectorDefaultBase
97 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
100 {
101  if (domainSpace_.is_null()) {
102  domainSpace_ = tpetraVectorSpace<Scalar>(
103  Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
104  1,
105  tpetraVector_.getConstObj()->getMap()->getComm()
106  )
107  );
108  }
109  return domainSpace_;
110 }
111 
112 
113 // Overridden from SpmdMultiVectorBase
114 
115 
116 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
119 {
120  return tpetraVectorSpace_;
121 }
122 
123 
124 // Overridden from SpmdVectorBase
125 
126 
127 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
129  const Ptr<ArrayRCP<Scalar> > &localValues )
130 {
131  *localValues = tpetraVector_.getNonconstObj()->get1dViewNonConst();
132 }
133 
134 
135 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
137  const Ptr<ArrayRCP<const Scalar> > &localValues ) const
138 {
139  *localValues = tpetraVector_->get1dView();
140 }
141 
142 
143 // Overridden from VectorBase
144 
145 
146 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
148  Scalar l,
149  Scalar u
150  )
151 {
152  // Tpetra randomizes with different seed for each proc, so need a global
153  // reduction to get locally-replicated random vector same on each proc.
154  if (!tpetraVector_.getNonconstObj()->isDistributed()) {
155  auto comm = tpetraVector_.getNonconstObj()->getMap()->getComm();
156  if (tpetraVector_.getConstObj()->getMap()->getComm()->getRank() == 0)
157  tpetraVector_.getNonconstObj()->randomize(l, u);
158  else
159  tpetraVector_.getNonconstObj()->putScalar(Teuchos::ScalarTraits<Scalar>::zero());
160  tpetraVector_.getNonconstObj()->reduce();
161  } else {
162  tpetraVector_.getNonconstObj()->randomize(l, u);
163  }
164 }
165 
166 
167 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
169  const VectorBase<Scalar>& x
170  )
171 {
172  auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
173 
174  // If the cast succeeded, call Tpetra directly.
175  // Otherwise, fall back to the RTOp implementation.
176  if (nonnull(tx)) {
177  tpetraVector_.getNonconstObj()->abs(*tx);
178  } else {
179  // This version will require/modify the host view of this vector.
180 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
181  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
182  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
183 #else
184  tpetraVector_.getNonconstObj()->sync_host ();
185  tpetraVector_.getNonconstObj()->modify_host ();
186 #endif
188  }
189 }
190 
191 
192 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
194  const VectorBase<Scalar>& x
195  )
196 {
197  auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
198 
199  // If the cast succeeded, call Tpetra directly.
200  // Otherwise, fall back to the RTOp implementation.
201  if (nonnull(tx)) {
202  tpetraVector_.getNonconstObj()->reciprocal(*tx);
203  } else {
204  // This version will require/modify the host view of this vector.
205 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
206  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
207  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
208 #else
209  tpetraVector_.getNonconstObj()->sync_host ();
210  tpetraVector_.getNonconstObj()->modify_host ();
211 #endif
213  }
214 }
215 
216 
217 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
219  const VectorBase<Scalar>& x
220  )
221 {
222  auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
223 
224  // If the cast succeeded, call Tpetra directly.
225  // Otherwise, fall back to the RTOp implementation.
226  if (nonnull(tx)) {
228  tpetraVector_.getNonconstObj()->elementWiseMultiply(
229  ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
230  } else {
231  // This version will require/modify the host view of this vector.
232 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
233  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
234  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
235 #else
236  tpetraVector_.getNonconstObj()->sync_host ();
237  tpetraVector_.getNonconstObj()->modify_host ();
238 #endif
240  }
241 }
242 
243 
244 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
247  const VectorBase<Scalar>& x
248  ) const
249 {
250  auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
251 
252  // If the cast succeeded, call Tpetra directly.
253  // Otherwise, fall back to the RTOp implementation.
254  if (nonnull(tx)) {
255  // Weighted 2-norm function for Tpetra vector seems to be deprecated...
258  = Tpetra::createVector<Scalar>(tx->getMap());
259  temp->elementWiseMultiply(
260  ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
261  return ST::magnitude(ST::squareroot(tpetraVector_.getConstObj()->dot(*temp)));
262  } else {
263  // This version will require the host view of this vector.
264 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
265  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
266 #else
267  tpetraVector_.getNonconstObj()->sync_host ();
268 #endif
270  }
271 }
272 
273 
274 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
276  const RTOpPack::RTOpT<Scalar> &op,
277  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
278  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
279  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
280  const Ordinal global_offset
281  ) const
282 {
283  // Sync any non-target Tpetra vecs to host space
284  for (auto itr = vecs.begin(); itr != vecs.end(); ++itr) {
285  auto tv = this->getConstTpetraVector(Teuchos::rcpFromPtr(*itr));
286  if (nonnull(tv)) {
287  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
288 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
289  Teuchos::rcp_const_cast<TV>(tv)->template sync<Kokkos::HostSpace>();
290 #else
291  Teuchos::rcp_const_cast<TV>(tv)->sync_host ();
292 #endif
293  }
294  }
295 
296  // Sync any target Tpetra vecs and mark modified on host
297  for (auto itr = targ_vecs.begin(); itr != targ_vecs.end(); ++itr) {
298  auto tv = this->getTpetraVector(Teuchos::rcpFromPtr(*itr));
299  if (nonnull(tv)) {
300 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
301  tv->template sync<Kokkos::HostSpace>();
302  tv->template modify<Kokkos::HostSpace>();
303 #else
304  tv->sync_host ();
305  tv->modify_host ();
306 #endif
307  }
308  }
309 
310  SpmdVectorDefaultBase<Scalar>::applyOpImpl(op, vecs, targ_vecs, reduct_obj, global_offset);
311 }
312 
313 
314 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
317  const Range1D& rng,
319  ) const
320 {
321  // Only viewing data, so just sync dual view to host space
322  typedef typename Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
323 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
324  Teuchos::rcp_const_cast<TV>(
325  tpetraVector_.getConstObj())->template sync<Kokkos::HostSpace>();
326 #else
327  Teuchos::rcp_const_cast<TV>(
328  tpetraVector_.getConstObj())->sync_host ();
329 #endif
330 
332 }
333 
334 
335 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
338  const Range1D& rng,
340  )
341 {
342  // Sync to host and mark as modified
343 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
344  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
345  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
346 #else
347  tpetraVector_.getNonconstObj()->sync_host ();
348  tpetraVector_.getNonconstObj()->modify_host ();
349 #endif
350 
352 }
353 
354 
355 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
359  )
360 {
362 
363  // Sync changes from host view to execution space
364  typedef typename Tpetra::Vector<
365  Scalar,LocalOrdinal,GlobalOrdinal,Node>::execution_space execution_space;
366  tpetraVector_.getNonconstObj()->template sync<execution_space>();
367 }
368 
369 
370 // Overridden protected functions from MultiVectorBase
371 
372 
373 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
375 {
376  tpetraVector_.getNonconstObj()->putScalar(alpha);
377 }
378 
379 
380 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
383 {
384  auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
385 
386  // If cast succeeded, call Tpetra directly.
387  // Otherwise, fall back to the RTOp implementation.
388  if (nonnull(tmv)) {
389  tpetraVector_.getNonconstObj()->assign(*tmv);
390  } else {
391  // This version will require/modify the host view of this vector.
392 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
393  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
394  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
395 #else
396  tpetraVector_.getNonconstObj()->sync_host ();
397  tpetraVector_.getNonconstObj()->modify_host ();
398 #endif
400  }
401 }
402 
403 
404 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
406 {
407  tpetraVector_.getNonconstObj()->scale(alpha);
408 }
409 
410 
411 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
413  Scalar alpha,
414  const MultiVectorBase<Scalar>& mv
415  )
416 {
417  auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
418 
419  // If cast succeeded, call Tpetra directly.
420  // Otherwise, fall back to the RTOp implementation.
422  if (nonnull(tmv)) {
423  tpetraVector_.getNonconstObj()->update(alpha, *tmv, ST::one());
424  } else {
425  // This version will require/modify the host view of this vector.
426 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
427  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
428  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
429 #else
430  tpetraVector_.getNonconstObj()->sync_host();
431  tpetraVector_.getNonconstObj()->modify_host();
432 #endif
434  }
435 }
436 
437 
438 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
440  const ArrayView<const Scalar>& alpha,
441  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > >& mv,
442  const Scalar& beta
443  )
444 {
445 #ifdef TEUCHOS_DEBUG
446  TEUCHOS_ASSERT_EQUALITY(alpha.size(), mv.size());
447 #endif
448 
449  // Try to cast mv to Tpetra objects
452  bool allCastsSuccessful = true;
453  {
454  auto mvIter = mv.begin();
455  auto tmvIter = tmvs.begin();
456  for (; mvIter != mv.end(); ++mvIter, ++tmvIter) {
457  tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromPtr(*mvIter));
458  if (nonnull(tmv)) {
459  *tmvIter = tmv;
460  } else {
461  allCastsSuccessful = false;
462  break;
463  }
464  }
465  }
466 
467  // If casts succeeded, or input arrays are size 0, call Tpetra directly.
468  // Otherwise, fall back to the RTOp implementation.
469  auto len = mv.size();
470  if (len == 0) {
471  tpetraVector_.getNonconstObj()->scale(beta);
472  } else if (len == 1 && allCastsSuccessful) {
473  tpetraVector_.getNonconstObj()->update(alpha[0], *tmvs[0], beta);
474  } else if (len == 2 && allCastsSuccessful) {
475  tpetraVector_.getNonconstObj()->update(alpha[0], *tmvs[0], alpha[1], *tmvs[1], beta);
476  } else if (allCastsSuccessful) {
478  auto tmvIter = tmvs.begin();
479  auto alphaIter = alpha.begin();
480 
481  // Check if any entry of tmvs aliases this object's wrapped vector.
482  // If so, replace that entry in the array with a copy.
483  tmv = Teuchos::null;
484  for (; tmvIter != tmvs.end(); ++tmvIter) {
485  if (tmvIter->getRawPtr() == tpetraVector_.getConstObj().getRawPtr()) {
486  if (tmv.is_null()) {
487  tmv = Teuchos::rcp(new TpetraMultiVector_t(
488  *tpetraVector_.getConstObj(), Teuchos::Copy));
489  }
490  *tmvIter = tmv;
491  }
492  }
493  tmvIter = tmvs.begin();
494 
495  // We add two MVs at a time, so only scale if even num MVs,
496  // and additionally do the first addition if odd num MVs.
497  if ((tmvs.size() % 2) == 0) {
498  tpetraVector_.getNonconstObj()->scale(beta);
499  } else {
500  tpetraVector_.getNonconstObj()->update(*alphaIter, *(*tmvIter), beta);
501  ++tmvIter;
502  ++alphaIter;
503  }
504  for (; tmvIter != tmvs.end(); tmvIter+=2, alphaIter+=2) {
505  tpetraVector_.getNonconstObj()->update(
506  *alphaIter, *(*tmvIter), *(alphaIter+1), *(*(tmvIter+1)), ST::one());
507  }
508  } else {
509  // This version will require/modify the host view of this vector.
510 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
511  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
512  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
513 #else
514  tpetraVector_.getNonconstObj()->sync_host ();
515  tpetraVector_.getNonconstObj()->modify_host ();
516 #endif
518  }
519 }
520 
521 
522 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
524  const MultiVectorBase<Scalar>& mv,
525  const ArrayView<Scalar>& prods
526  ) const
527 {
528  auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
529 
530  // If the cast succeeded, call Tpetra directly.
531  // Otherwise, fall back to the RTOp implementation.
532  if (nonnull(tmv)) {
533  tpetraVector_.getConstObj()->dot(*tmv, prods);
534  } else {
535  // This version will require/modify the host view of this vector.
536 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
537  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
538  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
539 #else
540  tpetraVector_.getNonconstObj()->sync_host ();
541  tpetraVector_.getNonconstObj()->modify_host ();
542 #endif
544  }
545 }
546 
547 
548 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
550  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms
551  ) const
552 {
553  tpetraVector_.getConstObj()->norm1(norms);
554 }
555 
556 
557 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
559  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms
560  ) const
561 {
562  tpetraVector_.getConstObj()->norm2(norms);
563 }
564 
565 
566 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
568  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms
569  ) const
570 {
571  tpetraVector_.getConstObj()->normInf(norms);
572 }
573 
574 
575 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
577  const EOpTransp M_trans,
578  const MultiVectorBase<Scalar> &X,
579  const Ptr<MultiVectorBase<Scalar> > &Y,
580  const Scalar alpha,
581  const Scalar beta
582  ) const
583 {
584  // Try to extract Tpetra objects from X and Y
585  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
586  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
587  Teuchos::RCP<const TMV> X_tpetra = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(X));
588  Teuchos::RCP<TMV> Y_tpetra = this->getTpetraMultiVector(Teuchos::rcpFromPtr(Y));
589 
590  // If the cast succeeded, call Tpetra directly.
591  // Otherwise, fall back to the default implementation.
592  if (nonnull(X_tpetra) && nonnull(Y_tpetra)) {
593  // Sync everything to the execution space
594  typedef typename TMV::execution_space execution_space;
595  Teuchos::rcp_const_cast<TMV>(X_tpetra)->template sync<execution_space>();
596  Y_tpetra->template sync<execution_space>();
597  Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->template sync<execution_space>();
598 
600  TEUCHOS_TEST_FOR_EXCEPTION(ST::isComplex && (M_trans == CONJ),
601  std::logic_error,
602  "Error, conjugation without transposition is not allowed for complex scalar types!");
603 
605  switch (M_trans) {
606  case NOTRANS:
607  trans = Teuchos::NO_TRANS;
608  break;
609  case CONJ:
610  trans = Teuchos::NO_TRANS;
611  break;
612  case TRANS:
613  trans = Teuchos::TRANS;
614  break;
615  case CONJTRANS:
616  trans = Teuchos::CONJ_TRANS;
617  break;
618  }
619 
620  Y_tpetra->template modify<execution_space>();
621  Y_tpetra->multiply(trans, Teuchos::NO_TRANS, alpha, *tpetraVector_.getConstObj(), *X_tpetra, beta);
622  } else {
623 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
624  Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->template sync<Kokkos::HostSpace>();
625 #else
626  Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->sync_host ();
627 #endif
628  VectorDefaultBase<Scalar>::applyImpl(M_trans, X, Y, alpha, beta);
629  }
630 
631 }
632 
633 
634 // private
635 
636 
637 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
638 template<class TpetraVector_t>
640  const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
641  const RCP<TpetraVector_t> &tpetraVector
642  )
643 {
644 #ifdef TEUCHOS_DEBUG
645  TEUCHOS_ASSERT(nonnull(tpetraVectorSpace));
646  TEUCHOS_ASSERT(nonnull(tpetraVector));
647 #endif
648  tpetraVectorSpace_ = tpetraVectorSpace;
649  tpetraVector_.initialize(tpetraVector);
650  this->updateSpmdSpace();
651 }
652 
653 
654 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
655 RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
656 TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
657 getTpetraMultiVector(const RCP<MultiVectorBase<Scalar> >& mv) const
658 {
659  using Teuchos::rcp_dynamic_cast;
660  typedef TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
661  typedef TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
662 
663  RCP<TMV> tmv = rcp_dynamic_cast<TMV>(mv);
664  if (nonnull(tmv)) {
665  return tmv->getTpetraMultiVector();
666  }
667 
668  RCP<TV> tv = rcp_dynamic_cast<TV>(mv);
669  if (nonnull(tv)) {
670  return tv->getTpetraVector();
671  }
672 
673  return Teuchos::null;
674 }
675 
676 
677 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
678 RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
679 TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
680 getConstTpetraMultiVector(const RCP<const MultiVectorBase<Scalar> >& mv) const
681 {
682  using Teuchos::rcp_dynamic_cast;
683  typedef TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
684  typedef TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
685 
686  RCP<const TMV> tmv = rcp_dynamic_cast<const TMV>(mv);
687  if (nonnull(tmv)) {
688  return tmv->getConstTpetraMultiVector();
689  }
690 
691  RCP<const TV> tv = rcp_dynamic_cast<const TV>(mv);
692  if (nonnull(tv)) {
693  return tv->getConstTpetraVector();
694  }
695 
696  return Teuchos::null;
697 }
698 
699 
700 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
701 RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
703 getTpetraVector(const RCP<VectorBase<Scalar> >& v) const
704 {
705  typedef TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TV;
706  RCP<TV> tv = Teuchos::rcp_dynamic_cast<TV>(v);
707  if (nonnull(tv)) {
708  return tv->getTpetraVector();
709  } else {
710  return Teuchos::null;
711  }
712 }
713 
714 
715 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
716 RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
718 getConstTpetraVector(const RCP<const VectorBase<Scalar> >& v) const
719 {
720  typedef TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TV;
721  RCP<const TV> tv = Teuchos::rcp_dynamic_cast<const TV>(v);
722  if (nonnull(tv)) {
723  return tv->getConstTpetraVector();
724  } else {
725  return Teuchos::null;
726  }
727 }
728 
729 
730 } // end namespace Thyra
731 
732 
733 #endif // THYRA_TPETRA_VECTOR_HPP
void constInitialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Initialize.
void applyOpImpl(const RTOpPack::RTOpT< Scalar > &op, const ArrayView< const Ptr< const VectorBase< Scalar > > > &vecs, const ArrayView< const Ptr< VectorBase< Scalar > > > &targ_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal global_offset) const
Calls applyOpImplWithComm(null,op,...).
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Concrete implementation of an SPMD vector space for Tpetra.
void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Implemented through this-&gt;getLocalData()
void initialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Initialize.
iterator begin() const
TpetraVector()
Construct to uninitialized.
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
Default implementation of assign(MV) using RTOps.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Use the non-transposed operator.
virtual void applyOpImpl(const RTOpPack::RTOpT< Scalar > &op, const ArrayView< const Ptr< const VectorBase< Scalar > > > &vecs, const ArrayView< const Ptr< VectorBase< Scalar > > > &targ_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal global_offset) const
size_type size() const
virtual void eleWiseScaleImpl(const VectorBase< Scalar > &x)
Default implementation of ele_wise_scale using RTOps.
virtual void reciprocalImpl(const VectorBase< Scalar > &x)
Default implementation of reciprocal using RTOps.
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
Default implementation of linear_combination using RTOps.
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Use the transposed operator with complex-conjugate clements (same as TRANS for real scalar types)...
void getLocalVectorDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues) const
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
virtual void absImpl(const VectorBase< Scalar > &x)
Default implementation of abs using RTOps.
Use the non-transposed operator with complex-conjugate elements (same as NOTRANS for real scalar type...
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
Use the transposed operator.
RCP< const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraVector() const
Get the embedded non-const Tpetra::Vector.
virtual void reciprocalImpl(const VectorBase< Scalar > &x)
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
virtual void absImpl(const VectorBase< Scalar > &x)
void getNonconstLocalVectorDataImpl(const Ptr< ArrayRCP< Scalar > > &localValues)
Abstract interface for finite-dimensional dense vectors.
RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpaceImpl() const
Concrete Thyra::SpmdVectorBase using Tpetra::Vector.
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraVector()
Get the embedded non-const Tpetra::Vector.
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
. Applies vector or its adjoint (transpose) as a linear operator.
void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)
Implemented through this-&gt;commitLocalData()
bool nonnull(const boost::shared_ptr< T > &p)
virtual void assignImpl(Scalar alpha)
virtual void eleWiseScaleImpl(const VectorBase< Scalar > &x)
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
RCP< const VectorSpaceBase< Scalar > > domain() const
virtual void randomizeImpl(Scalar l, Scalar u)
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
Default implementation of norm_2 (weighted) using RTOps.
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
virtual void scaleImpl(Scalar alpha)
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Default implementation of dots using RTOps.
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Default implementation of update using RTOps.
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
Implemented through this-&gt;getLocalData()