Thyra  Version of the Day
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>(
104  1,
105  tpetraVector_.getConstObj()->getMap()->getComm(),
106  tpetraVector_.getConstObj()->getMap()->getNode()
107  )
108  );
109  }
110  return domainSpace_;
111 }
112 
113 
114 // Overridden from SpmdMultiVectorBase
115 
116 
117 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
120 {
121  return tpetraVectorSpace_;
122 }
123 
124 
125 // Overridden from SpmdVectorBase
126 
127 
128 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
130  const Ptr<ArrayRCP<Scalar> > &localValues )
131 {
132  *localValues = tpetraVector_.getNonconstObj()->get1dViewNonConst();
133 }
134 
135 
136 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
138  const Ptr<ArrayRCP<const Scalar> > &localValues ) const
139 {
140  *localValues = tpetraVector_->get1dView();
141 }
142 
143 
144 // Overridden from VectorBase
145 
146 
147 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
149  Scalar l,
150  Scalar u
151  )
152 {
153  // Tpetra randomizes with different seed for each proc, so need a global
154  // reduction to get locally-replicated random vector same on each proc.
155  if (!tpetraVector_.getNonconstObj()->isDistributed()) {
156  auto comm = tpetraVector_.getNonconstObj()->getMap()->getComm();
157  if (tpetraVector_.getConstObj()->getMap()->getComm()->getRank() == 0)
158  tpetraVector_.getNonconstObj()->randomize(l, u);
159  else
160  tpetraVector_.getNonconstObj()->putScalar(Teuchos::ScalarTraits<Scalar>::zero());
161  tpetraVector_.getNonconstObj()->reduce();
162  } else {
163  tpetraVector_.getNonconstObj()->randomize(l, u);
164  }
165 }
166 
167 
168 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
170  const VectorBase<Scalar>& x
171  )
172 {
173  auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
174 
175  // If the cast succeeded, call Tpetra directly.
176  // Otherwise, fall back to the RTOp implementation.
177  if (nonnull(tx)) {
178  tpetraVector_.getNonconstObj()->abs(*tx);
179  } else {
180  // This version will require/modify the host view of this vector.
181  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
182  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
184  }
185 }
186 
187 
188 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
190  const VectorBase<Scalar>& x
191  )
192 {
193  auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
194 
195  // If the cast succeeded, call Tpetra directly.
196  // Otherwise, fall back to the RTOp implementation.
197  if (nonnull(tx)) {
198  tpetraVector_.getNonconstObj()->reciprocal(*tx);
199  } else {
200  // This version will require/modify the host view of this vector.
201  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
202  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
204  }
205 }
206 
207 
208 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
210  const VectorBase<Scalar>& x
211  )
212 {
213  auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
214 
215  // If the cast succeeded, call Tpetra directly.
216  // Otherwise, fall back to the RTOp implementation.
217  if (nonnull(tx)) {
219  tpetraVector_.getNonconstObj()->elementWiseMultiply(
220  ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
221  } else {
222  // This version will require/modify the host view of this vector.
223  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
224  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
226  }
227 }
228 
229 
230 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
233  const VectorBase<Scalar>& x
234  ) const
235 {
236  auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
237 
238  // If the cast succeeded, call Tpetra directly.
239  // Otherwise, fall back to the RTOp implementation.
240  if (nonnull(tx)) {
241  // Weighted 2-norm function for Tpetra vector seems to be deprecated...
244  = Tpetra::createVector<Scalar>(tx->getMap());
245  temp->elementWiseMultiply(
246  ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
247  return ST::magnitude(ST::squareroot(tpetraVector_.getConstObj()->dot(*temp)));
248  } else {
249  // This version will require the host view of this vector.
250  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
252  }
253 }
254 
255 
256 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
258  const RTOpPack::RTOpT<Scalar> &op,
259  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
260  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
261  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
262  const Ordinal global_offset
263  ) const
264 {
265  // Sync any non-target Tpetra vecs to host space
266  for (auto itr = vecs.begin(); itr != vecs.end(); ++itr) {
267  auto tv = this->getConstTpetraVector(Teuchos::rcpFromPtr(*itr));
268  if (nonnull(tv)) {
269  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
270  Teuchos::rcp_const_cast<TV>(tv)->template sync<Kokkos::HostSpace>();
271  }
272  }
273 
274  // Sync any target Tpetra vecs and mark modified on host
275  for (auto itr = targ_vecs.begin(); itr != targ_vecs.end(); ++itr) {
276  auto tv = this->getTpetraVector(Teuchos::rcpFromPtr(*itr));
277  if (nonnull(tv)) {
278  tv->template sync<Kokkos::HostSpace>();
279  tv->template modify<Kokkos::HostSpace>();
280  }
281  }
282 
283  SpmdVectorDefaultBase<Scalar>::applyOpImpl(op, vecs, targ_vecs, reduct_obj, global_offset);
284 }
285 
286 
287 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
290  const Range1D& rng,
292  ) const
293 {
294  // Only viewing data, so just sync dual view to host space
295  typedef typename Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
296  Teuchos::rcp_const_cast<TV>(
297  tpetraVector_.getConstObj())->template sync<Kokkos::HostSpace>();
298 
300 }
301 
302 
303 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
306  const Range1D& rng,
308  )
309 {
310  // Sync to host and mark as modified
311  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
312  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
313 
315 }
316 
317 
318 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
322  )
323 {
325 
326  // Sync changes from host view to execution space
327  typedef typename Tpetra::Vector<
328  Scalar,LocalOrdinal,GlobalOrdinal,Node>::execution_space execution_space;
329  tpetraVector_.getNonconstObj()->template sync<execution_space>();
330 }
331 
332 
333 // Overridden protected functions from MultiVectorBase
334 
335 
336 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
338 {
339  tpetraVector_.getNonconstObj()->putScalar(alpha);
340 }
341 
342 
343 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
346 {
347  auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
348 
349  // If cast succeeded, call Tpetra directly.
350  // Otherwise, fall back to the RTOp implementation.
351  if (nonnull(tmv)) {
352  tpetraVector_.getNonconstObj()->assign(*tmv);
353  } else {
354  // This version will require/modify the host view of this vector.
355  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
356  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
358  }
359 }
360 
361 
362 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
364 {
365  tpetraVector_.getNonconstObj()->scale(alpha);
366 }
367 
368 
369 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
371  Scalar alpha,
372  const MultiVectorBase<Scalar>& mv
373  )
374 {
375  auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
376 
377  // If cast succeeded, call Tpetra directly.
378  // Otherwise, fall back to the RTOp implementation.
380  if (nonnull(tmv)) {
381  tpetraVector_.getNonconstObj()->update(alpha, *tmv, ST::one());
382  } else {
383  // This version will require/modify the host view of this vector.
384  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
385  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
387  }
388 }
389 
390 
391 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
393  const ArrayView<const Scalar>& alpha,
394  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > >& mv,
395  const Scalar& beta
396  )
397 {
398 #ifdef TEUCHOS_DEBUG
399  TEUCHOS_ASSERT_EQUALITY(alpha.size(), mv.size());
400 #endif
401 
402  // Try to cast mv to Tpetra objects
405  bool allCastsSuccessful = true;
406  {
407  auto mvIter = mv.begin();
408  auto tmvIter = tmvs.begin();
409  for (; mvIter != mv.end(); ++mvIter, ++tmvIter) {
410  tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromPtr(*mvIter));
411  if (nonnull(tmv)) {
412  *tmvIter = tmv;
413  } else {
414  allCastsSuccessful = false;
415  break;
416  }
417  }
418  }
419 
420  // If casts succeeded, or input arrays are size 0, call Tpetra directly.
421  // Otherwise, fall back to the RTOp implementation.
422  auto len = mv.size();
423  if (len == 0) {
424  tpetraVector_.getNonconstObj()->scale(beta);
425  } else if (len == 1 && allCastsSuccessful) {
426  tpetraVector_.getNonconstObj()->update(alpha[0], *tmvs[0], beta);
427  } else if (len == 2 && allCastsSuccessful) {
428  tpetraVector_.getNonconstObj()->update(alpha[0], *tmvs[0], alpha[1], *tmvs[1], beta);
429  } else if (allCastsSuccessful) {
431  auto tmvIter = tmvs.begin();
432  auto alphaIter = alpha.begin();
433 
434  // Check if any entry of tmvs aliases this object's wrapped vector.
435  // If so, replace that entry in the array with a copy.
436  tmv = Teuchos::null;
437  for (; tmvIter != tmvs.end(); ++tmvIter) {
438  if (tmvIter->getRawPtr() == tpetraVector_.getConstObj().getRawPtr()) {
439  if (tmv.is_null()) {
440  tmv = Teuchos::rcp(new TpetraMultiVector_t(
441  *tpetraVector_.getConstObj(), Teuchos::Copy));
442  }
443  *tmvIter = tmv;
444  }
445  }
446  tmvIter = tmvs.begin();
447 
448  // We add two MVs at a time, so only scale if even num MVs,
449  // and additionally do the first addition if odd num MVs.
450  if ((tmvs.size() % 2) == 0) {
451  tpetraVector_.getNonconstObj()->scale(beta);
452  } else {
453  tpetraVector_.getNonconstObj()->update(*alphaIter, *(*tmvIter), beta);
454  ++tmvIter;
455  ++alphaIter;
456  }
457  for (; tmvIter != tmvs.end(); tmvIter+=2, alphaIter+=2) {
458  tpetraVector_.getNonconstObj()->update(
459  *alphaIter, *(*tmvIter), *(alphaIter+1), *(*(tmvIter+1)), ST::one());
460  }
461  } else {
462  // This version will require/modify the host view of this vector.
463  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
464  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
466  }
467 }
468 
469 
470 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
472  const MultiVectorBase<Scalar>& mv,
473  const ArrayView<Scalar>& prods
474  ) const
475 {
476  auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
477 
478  // If the cast succeeded, call Tpetra directly.
479  // Otherwise, fall back to the RTOp implementation.
480  if (nonnull(tmv)) {
481  tpetraVector_.getConstObj()->dot(*tmv, prods);
482  } else {
483  // This version will require/modify the host view of this vector.
484  tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
485  tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
487  }
488 }
489 
490 
491 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
493  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms
494  ) const
495 {
496  tpetraVector_.getConstObj()->norm1(norms);
497 }
498 
499 
500 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
502  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms
503  ) const
504 {
505  tpetraVector_.getConstObj()->norm2(norms);
506 }
507 
508 
509 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
511  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms
512  ) const
513 {
514  tpetraVector_.getConstObj()->normInf(norms);
515 }
516 
517 
518 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
520  const EOpTransp M_trans,
521  const MultiVectorBase<Scalar> &X,
522  const Ptr<MultiVectorBase<Scalar> > &Y,
523  const Scalar alpha,
524  const Scalar beta
525  ) const
526 {
527  // Try to extract Tpetra objects from X and Y
528  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
529  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
530  Teuchos::RCP<const TMV> X_tpetra = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(X));
531  Teuchos::RCP<TMV> Y_tpetra = this->getTpetraMultiVector(Teuchos::rcpFromPtr(Y));
532 
533  // If the cast succeeded, call Tpetra directly.
534  // Otherwise, fall back to the default implementation.
535  if (nonnull(X_tpetra) && nonnull(Y_tpetra)) {
536  // Sync everything to the execution space
537  typedef typename TMV::execution_space execution_space;
538  Teuchos::rcp_const_cast<TMV>(X_tpetra)->template sync<execution_space>();
539  Y_tpetra->template sync<execution_space>();
540  Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->template sync<execution_space>();
541 
543  TEUCHOS_TEST_FOR_EXCEPTION(ST::isComplex && (M_trans == CONJ),
544  std::logic_error,
545  "Error, conjugation without transposition is not allowed for complex scalar types!");
546 
547  Teuchos::ETransp trans = Teuchos::NO_TRANS;
548  switch (M_trans) {
549  case NOTRANS:
550  trans = Teuchos::NO_TRANS;
551  break;
552  case CONJ:
553  trans = Teuchos::NO_TRANS;
554  break;
555  case TRANS:
556  trans = Teuchos::TRANS;
557  break;
558  case CONJTRANS:
559  trans = Teuchos::CONJ_TRANS;
560  break;
561  }
562 
563  Y_tpetra->template modify<execution_space>();
564  Y_tpetra->multiply(trans, Teuchos::NO_TRANS, alpha, *tpetraVector_.getConstObj(), *X_tpetra, beta);
565  } else {
566  Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->template sync<Kokkos::HostSpace>();
567  VectorDefaultBase<Scalar>::applyImpl(M_trans, X, Y, alpha, beta);
568  }
569 
570 }
571 
572 
573 // private
574 
575 
576 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
577 template<class TpetraVector_t>
579  const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
580  const RCP<TpetraVector_t> &tpetraVector
581  )
582 {
583 #ifdef TEUCHOS_DEBUG
584  TEUCHOS_ASSERT(nonnull(tpetraVectorSpace));
585  TEUCHOS_ASSERT(nonnull(tpetraVector));
586 #endif
587  tpetraVectorSpace_ = tpetraVectorSpace;
588  tpetraVector_.initialize(tpetraVector);
589  this->updateSpmdSpace();
590 }
591 
592 
593 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
594 RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
595 TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
596 getTpetraMultiVector(const RCP<MultiVectorBase<Scalar> >& mv) const
597 {
598  using Teuchos::rcp_dynamic_cast;
599  typedef TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
600  typedef TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
601 
602  RCP<TMV> tmv = rcp_dynamic_cast<TMV>(mv);
603  if (nonnull(tmv)) {
604  return tmv->getTpetraMultiVector();
605  }
606 
607  RCP<TV> tv = rcp_dynamic_cast<TV>(mv);
608  if (nonnull(tv)) {
609  return tv->getTpetraVector();
610  }
611 
612  return Teuchos::null;
613 }
614 
615 
616 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
617 RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
618 TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
619 getConstTpetraMultiVector(const RCP<const MultiVectorBase<Scalar> >& mv) const
620 {
621  using Teuchos::rcp_dynamic_cast;
622  typedef TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
623  typedef TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
624 
625  RCP<const TMV> tmv = rcp_dynamic_cast<const TMV>(mv);
626  if (nonnull(tmv)) {
627  return tmv->getConstTpetraMultiVector();
628  }
629 
630  RCP<const TV> tv = rcp_dynamic_cast<const TV>(mv);
631  if (nonnull(tv)) {
632  return tv->getConstTpetraVector();
633  }
634 
635  return Teuchos::null;
636 }
637 
638 
639 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
640 RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
642 getTpetraVector(const RCP<VectorBase<Scalar> >& v) const
643 {
644  typedef TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TV;
645  RCP<TV> tv = Teuchos::rcp_dynamic_cast<TV>(v);
646  if (nonnull(tv)) {
647  return tv->getTpetraVector();
648  } else {
649  return Teuchos::null;
650  }
651 }
652 
653 
654 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
655 RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
657 getConstTpetraVector(const RCP<const VectorBase<Scalar> >& v) const
658 {
659  typedef TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TV;
660  RCP<const TV> tv = Teuchos::rcp_dynamic_cast<const TV>(v);
661  if (nonnull(tv)) {
662  return tv->getConstTpetraVector();
663  } else {
664  return Teuchos::null;
665  }
666 }
667 
668 
669 } // end namespace Thyra
670 
671 
672 #endif // THYRA_TPETRA_VECTOR_HPP
Thyra::VectorDefaultBase::eleWiseScaleImpl
virtual void eleWiseScaleImpl(const VectorBase< Scalar > &x)
Default implementation of ele_wise_scale using RTOps.
Definition: Thyra_VectorDefaultBase_def.hpp:241
Thyra::TpetraVector::acquireDetachedVectorViewImpl
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Definition: Thyra_TpetraVector_def.hpp:289
Thyra::TpetraVector::assignImpl
virtual void assignImpl(Scalar alpha)
Definition: Thyra_TpetraVector_def.hpp:337
Thyra::TpetraVector::spmdSpaceImpl
RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpaceImpl() const
Definition: Thyra_TpetraVector_def.hpp:119
Thyra::TpetraVector::assignMultiVecImpl
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
Definition: Thyra_TpetraVector_def.hpp:345
Thyra::TpetraVector::applyImpl
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Definition: Thyra_TpetraVector_def.hpp:519
Thyra::SpmdVectorDefaultBase::applyOpImpl
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,...).
Definition: Thyra_SpmdVectorDefaultBase_def.hpp:182
Thyra::EOpTransp
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
Definition: Thyra_OperatorVectorTypes.hpp:160
Thyra::VectorDefaultBase::absImpl
virtual void absImpl(const VectorBase< Scalar > &x)
Default implementation of abs using RTOps.
Definition: Thyra_VectorDefaultBase_def.hpp:221
Thyra::TpetraVector::commitNonconstDetachedVectorViewImpl
void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)
Definition: Thyra_TpetraVector_def.hpp:320
Thyra::MultiVectorDefaultBase::linearCombinationImpl
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.
Definition: Thyra_MultiVectorDefaultBase_def.hpp:147
Thyra::TpetraVector::randomizeImpl
virtual void randomizeImpl(Scalar l, Scalar u)
Definition: Thyra_TpetraVector_def.hpp:148
Thyra::TpetraVector::norm2WeightedImpl
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
Definition: Thyra_TpetraVector_def.hpp:232
Thyra::VectorDefaultBase::reciprocalImpl
virtual void reciprocalImpl(const VectorBase< Scalar > &x)
Default implementation of reciprocal using RTOps.
Definition: Thyra_VectorDefaultBase_def.hpp:231
Thyra::TpetraVector::constInitialize
void constInitialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Initialize.
Definition: Thyra_TpetraVector_def.hpp:71
Thyra::TpetraVector::TpetraVector
TpetraVector()
Construct to uninitialized.
Definition: Thyra_TpetraVector_def.hpp:56
Thyra::MultiVectorDefaultBase::assignMultiVecImpl
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
Default implementation of assign(MV) using RTOps.
Definition: Thyra_MultiVectorDefaultBase_def.hpp:104
TEUCHOS_ASSERT
#define TEUCHOS_ASSERT(assertion_test)
RTOpPack::ConstSubVectorView
Thyra::TpetraVector::norms1Impl
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Definition: Thyra_TpetraVector_def.hpp:492
Thyra::TpetraVector::getLocalVectorDataImpl
void getLocalVectorDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues) const
Definition: Thyra_TpetraVector_def.hpp:137
Thyra::TpetraVector::absImpl
virtual void absImpl(const VectorBase< Scalar > &x)
Definition: Thyra_TpetraVector_def.hpp:169
Teuchos::ArrayView
Teuchos::RCP
Teuchos::Ptr
Thyra::Ordinal
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Definition: Thyra_OperatorVectorTypes.hpp:127
TEUCHOS_ASSERT_EQUALITY
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
Teuchos::Array
Thyra::TpetraVector::initialize
void initialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Initialize.
Definition: Thyra_TpetraVector_def.hpp:61
Teuchos::ArrayView::begin
iterator begin() const
Thyra::TpetraVector::getTpetraVector
RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraVector()
Get the embedded non-const Tpetra::Vector.
Definition: Thyra_TpetraVector_def.hpp:82
Thyra::TpetraVector
Concrete Thyra::SpmdVectorBase using Tpetra::Vector.
Definition: Thyra_TpetraVector_decl.hpp:60
Thyra::TpetraVector::getConstTpetraVector
RCP< const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraVector() const
Get the embedded non-const Tpetra::Vector.
Definition: Thyra_TpetraVector_def.hpp:90
Teuchos::ArrayRCP
Thyra::TpetraVector::acquireNonconstDetachedVectorViewImpl
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
Definition: Thyra_TpetraVector_def.hpp:305
Teuchos::ArrayView::size
size_type size() const
Thyra::CONJTRANS
Use the transposed operator with complex-conjugate clements (same as TRANS for real scalar types).
Definition: Thyra_OperatorVectorTypes.hpp:172
Thyra::TpetraVector::getNonconstLocalVectorDataImpl
void getNonconstLocalVectorDataImpl(const Ptr< ArrayRCP< Scalar > > &localValues)
Definition: Thyra_TpetraVector_def.hpp:129
Thyra::MultiVectorBase
Interface for a collection of column vectors called a multi-vector.
Definition: Thyra_MultiVectorBase_decl.hpp:493
Thyra::SpmdVectorDefaultBase::acquireNonconstDetachedVectorViewImpl
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
Implemented through this->getLocalData()
Definition: Thyra_SpmdVectorDefaultBase_def.hpp:266
Teuchos::ScalarTraits
Thyra::TpetraVector::norms2Impl
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Definition: Thyra_TpetraVector_def.hpp:501
Thyra::SpmdVectorDefaultBase::commitNonconstDetachedVectorViewImpl
void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)
Implemented through this->commitLocalData()
Definition: Thyra_SpmdVectorDefaultBase_def.hpp:310
Thyra::TpetraVector::dotsImpl
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Definition: Thyra_TpetraVector_def.hpp:471
Thyra::VectorDefaultBase::norm2WeightedImpl
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
Default implementation of norm_2 (weighted) using RTOps.
Definition: Thyra_VectorDefaultBase_def.hpp:304
Thyra::NOTRANS
Use the non-transposed operator.
Definition: Thyra_OperatorVectorTypes.hpp:162
RTOpPack::SubVectorView
RTOpPack::RTOpT< Scalar >
Thyra::MultiVectorDefaultBase::updateImpl
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Default implementation of update using RTOps.
Definition: Thyra_MultiVectorDefaultBase_def.hpp:134
nonnull
bool nonnull(const boost::shared_ptr< T > &p)
Thyra::VectorBase
Abstract interface for finite-dimensional dense vectors.
Definition: Thyra_OperatorVectorTypes.hpp:370
Thyra::TpetraVector::updateImpl
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Definition: Thyra_TpetraVector_def.hpp:370
Thyra::TpetraVector::scaleImpl
virtual void scaleImpl(Scalar alpha)
Definition: Thyra_TpetraVector_def.hpp:363
Thyra::TpetraVectorSpace
Concrete implementation of an SPMD vector space for Tpetra.
Definition: Thyra_TpetraVectorSpace_decl.hpp:59
Thyra::SpmdVectorDefaultBase::acquireDetachedVectorViewImpl
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Implemented through this->getLocalData()
Definition: Thyra_SpmdVectorDefaultBase_def.hpp:196
Thyra::VectorDefaultBase::applyImpl
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.
Definition: Thyra_VectorDefaultBase_def.hpp:590
Thyra::MultiVectorDefaultBase::dotsImpl
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Default implementation of dots using RTOps.
Definition: Thyra_MultiVectorDefaultBase_def.hpp:221
Teuchos::ScalarTraits::magnitudeType
T magnitudeType
Thyra::TpetraVector::domain
RCP< const VectorSpaceBase< Scalar > > domain() const
Definition: Thyra_TpetraVector_def.hpp:99
Thyra::TpetraVector::reciprocalImpl
virtual void reciprocalImpl(const VectorBase< Scalar > &x)
Definition: Thyra_TpetraVector_def.hpp:189
Thyra::CONJ
Use the non-transposed operator with complex-conjugate elements (same as NOTRANS for real scalar type...
Definition: Thyra_OperatorVectorTypes.hpp:166
Thyra::TpetraVector::applyOpImpl
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
Definition: Thyra_TpetraVector_def.hpp:257
Teuchos::Range1D
Thyra::TpetraVector::eleWiseScaleImpl
virtual void eleWiseScaleImpl(const VectorBase< Scalar > &x)
Definition: Thyra_TpetraVector_def.hpp:209
TEUCHOS_TEST_FOR_EXCEPTION
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Thyra::TpetraVector::linearCombinationImpl
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
Definition: Thyra_TpetraVector_def.hpp:392
Thyra::TRANS
Use the transposed operator.
Definition: Thyra_OperatorVectorTypes.hpp:168
Thyra::TpetraVector::normsInfImpl
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Definition: Thyra_TpetraVector_def.hpp:510
Teuchos::ETransp
ETransp