42 #ifndef THYRA_TPETRA_VECTOR_HPP
43 #define THYRA_TPETRA_VECTOR_HPP
46 #include "Thyra_TpetraVector_decl.hpp"
47 #include "Thyra_TpetraMultiVector.hpp"
55 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
60 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
63 const RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector
66 initializeImpl(tpetraVectorSpace, tpetraVector);
70 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
73 const RCP<
const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector
76 initializeImpl(tpetraVectorSpace, tpetraVector);
80 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 return tpetraVector_.getNonconstObj();
88 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
97 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
101 if (domainSpace_.is_null()) {
102 domainSpace_ = tpetraVectorSpace<Scalar>(
103 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
105 tpetraVector_.getConstObj()->getMap()->getComm()
116 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
120 return tpetraVectorSpace_;
127 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
131 *localValues = tpetraVector_.getNonconstObj()->get1dViewNonConst();
135 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
139 *localValues = tpetraVector_->get1dView();
146 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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);
160 tpetraVector_.getNonconstObj()->reduce();
162 tpetraVector_.getNonconstObj()->randomize(l, u);
167 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
172 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
177 tpetraVector_.getNonconstObj()->abs(*tx);
180 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
181 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
182 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
184 tpetraVector_.getNonconstObj()->sync_host ();
185 tpetraVector_.getNonconstObj()->modify_host ();
192 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
197 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
202 tpetraVector_.getNonconstObj()->reciprocal(*tx);
205 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
206 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
207 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
209 tpetraVector_.getNonconstObj()->sync_host ();
210 tpetraVector_.getNonconstObj()->modify_host ();
217 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
222 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
228 tpetraVector_.getNonconstObj()->elementWiseMultiply(
229 ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
232 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
233 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
234 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
236 tpetraVector_.getNonconstObj()->sync_host ();
237 tpetraVector_.getNonconstObj()->modify_host ();
244 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
250 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
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)));
264 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
265 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
267 tpetraVector_.getNonconstObj()->sync_host ();
274 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
284 for (
auto itr = vecs.begin(); itr != vecs.end(); ++itr) {
285 auto tv = this->getConstTpetraVector(Teuchos::rcpFromPtr(*itr));
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>();
291 Teuchos::rcp_const_cast<TV>(tv)->sync_host ();
297 for (
auto itr = targ_vecs.begin(); itr != targ_vecs.end(); ++itr) {
298 auto tv = this->getTpetraVector(Teuchos::rcpFromPtr(*itr));
300 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
301 tv->template sync<Kokkos::HostSpace>();
302 tv->template modify<Kokkos::HostSpace>();
314 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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>();
327 Teuchos::rcp_const_cast<TV>(
328 tpetraVector_.getConstObj())->sync_host ();
335 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
343 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
344 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
345 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
347 tpetraVector_.getNonconstObj()->sync_host ();
348 tpetraVector_.getNonconstObj()->modify_host ();
355 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
364 typedef typename Tpetra::Vector<
365 Scalar,LocalOrdinal,GlobalOrdinal,Node>::execution_space execution_space;
366 tpetraVector_.getNonconstObj()->template sync<execution_space>();
373 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
376 tpetraVector_.getNonconstObj()->putScalar(alpha);
380 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
384 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
389 tpetraVector_.getNonconstObj()->assign(*tmv);
392 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
393 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
394 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
396 tpetraVector_.getNonconstObj()->sync_host ();
397 tpetraVector_.getNonconstObj()->modify_host ();
404 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
407 tpetraVector_.getNonconstObj()->scale(alpha);
411 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
417 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
423 tpetraVector_.getNonconstObj()->update(alpha, *tmv, ST::one());
426 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
427 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
428 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
430 tpetraVector_.getNonconstObj()->sync_host();
431 tpetraVector_.getNonconstObj()->modify_host();
438 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
452 bool allCastsSuccessful =
true;
454 auto mvIter = mv.begin();
455 auto tmvIter = tmvs.begin();
456 for (; mvIter != mv.end(); ++mvIter, ++tmvIter) {
457 tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromPtr(*mvIter));
461 allCastsSuccessful =
false;
469 auto len = mv.size();
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();
484 for (; tmvIter != tmvs.end(); ++tmvIter) {
485 if (tmvIter->getRawPtr() == tpetraVector_.getConstObj().getRawPtr()) {
493 tmvIter = tmvs.begin();
497 if ((tmvs.size() % 2) == 0) {
498 tpetraVector_.getNonconstObj()->scale(beta);
500 tpetraVector_.getNonconstObj()->update(*alphaIter, *(*tmvIter), beta);
504 for (; tmvIter != tmvs.end(); tmvIter+=2, alphaIter+=2) {
505 tpetraVector_.getNonconstObj()->update(
506 *alphaIter, *(*tmvIter), *(alphaIter+1), *(*(tmvIter+1)), ST::one());
510 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
511 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
512 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
514 tpetraVector_.getNonconstObj()->sync_host ();
515 tpetraVector_.getNonconstObj()->modify_host ();
522 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
528 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
533 tpetraVector_.getConstObj()->dot(*tmv, prods);
536 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
537 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
538 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
540 tpetraVector_.getNonconstObj()->sync_host ();
541 tpetraVector_.getNonconstObj()->modify_host ();
548 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
553 tpetraVector_.getConstObj()->norm1(norms);
557 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
562 tpetraVector_.getConstObj()->norm2(norms);
566 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
571 tpetraVector_.getConstObj()->normInf(norms);
575 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
585 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
586 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
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>();
602 "Error, conjugation without transposition is not allowed for complex scalar types!");
620 Y_tpetra->template modify<execution_space>();
621 Y_tpetra->multiply(trans,
Teuchos::NO_TRANS, alpha, *tpetraVector_.getConstObj(), *X_tpetra, beta);
623 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
624 Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->
template sync<Kokkos::HostSpace>();
626 Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->sync_host ();
637 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
638 template<
class TpetraVector_t>
648 tpetraVectorSpace_ = tpetraVectorSpace;
649 tpetraVector_.initialize(tpetraVector);
650 this->updateSpmdSpace();
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
659 using Teuchos::rcp_dynamic_cast;
660 typedef TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
661 typedef TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
663 RCP<TMV> tmv = rcp_dynamic_cast<TMV>(mv);
665 return tmv->getTpetraMultiVector();
668 RCP<TV> tv = rcp_dynamic_cast<TV>(mv);
670 return tv->getTpetraVector();
673 return Teuchos::null;
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
682 using Teuchos::rcp_dynamic_cast;
683 typedef TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
684 typedef TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
686 RCP<const TMV> tmv = rcp_dynamic_cast<
const TMV>(mv);
688 return tmv->getConstTpetraMultiVector();
691 RCP<const TV> tv = rcp_dynamic_cast<
const TV>(mv);
693 return tv->getConstTpetraVector();
696 return Teuchos::null;
700 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
701 RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
705 typedef TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TV;
706 RCP<TV> tv = Teuchos::rcp_dynamic_cast<TV>(v);
708 return tv->getTpetraVector();
710 return Teuchos::null;
715 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
716 RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
720 typedef TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TV;
721 RCP<const TV> tv = Teuchos::rcp_dynamic_cast<
const TV>(v);
723 return tv->getConstTpetraVector();
725 return Teuchos::null;
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->getLocalData()
void initialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Initialize.
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
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->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->getLocalData()