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>(
105 tpetraVector_.getConstObj()->getMap()->getComm(),
106 tpetraVector_.getConstObj()->getMap()->getNode()
117 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
121 return tpetraVectorSpace_;
128 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
132 *localValues = tpetraVector_.getNonconstObj()->get1dViewNonConst();
136 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
140 *localValues = tpetraVector_->get1dView();
147 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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);
161 tpetraVector_.getNonconstObj()->reduce();
163 tpetraVector_.getNonconstObj()->randomize(l, u);
168 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
173 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
178 tpetraVector_.getNonconstObj()->abs(*tx);
181 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
182 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
188 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
193 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
198 tpetraVector_.getNonconstObj()->reciprocal(*tx);
201 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
202 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
208 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
213 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
219 tpetraVector_.getNonconstObj()->elementWiseMultiply(
220 ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
223 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
224 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
230 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
236 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
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)));
250 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
256 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
266 for (
auto itr = vecs.begin(); itr != vecs.end(); ++itr) {
267 auto tv = this->getConstTpetraVector(Teuchos::rcpFromPtr(*itr));
269 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
270 Teuchos::rcp_const_cast<TV>(tv)->
template sync<Kokkos::HostSpace>();
275 for (
auto itr = targ_vecs.begin(); itr != targ_vecs.end(); ++itr) {
276 auto tv = this->getTpetraVector(Teuchos::rcpFromPtr(*itr));
278 tv->template sync<Kokkos::HostSpace>();
279 tv->template modify<Kokkos::HostSpace>();
287 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
295 typedef typename Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
296 Teuchos::rcp_const_cast<TV>(
297 tpetraVector_.getConstObj())->
template sync<Kokkos::HostSpace>();
303 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
311 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
312 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
318 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
327 typedef typename Tpetra::Vector<
328 Scalar,LocalOrdinal,GlobalOrdinal,Node>::execution_space execution_space;
329 tpetraVector_.getNonconstObj()->template sync<execution_space>();
336 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
339 tpetraVector_.getNonconstObj()->putScalar(alpha);
343 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
347 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
352 tpetraVector_.getNonconstObj()->assign(*tmv);
355 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
356 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
362 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
365 tpetraVector_.getNonconstObj()->scale(alpha);
369 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
375 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
381 tpetraVector_.getNonconstObj()->update(alpha, *tmv, ST::one());
384 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
385 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
391 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
405 bool allCastsSuccessful =
true;
407 auto mvIter = mv.begin();
408 auto tmvIter = tmvs.begin();
409 for (; mvIter != mv.end(); ++mvIter, ++tmvIter) {
410 tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromPtr(*mvIter));
414 allCastsSuccessful =
false;
422 auto len = mv.size();
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();
437 for (; tmvIter != tmvs.end(); ++tmvIter) {
438 if (tmvIter->getRawPtr() == tpetraVector_.getConstObj().getRawPtr()) {
440 tmv = Teuchos::rcp(
new TpetraMultiVector_t(
441 *tpetraVector_.getConstObj(), Teuchos::Copy));
446 tmvIter = tmvs.begin();
450 if ((tmvs.size() % 2) == 0) {
451 tpetraVector_.getNonconstObj()->scale(beta);
453 tpetraVector_.getNonconstObj()->update(*alphaIter, *(*tmvIter), beta);
457 for (; tmvIter != tmvs.end(); tmvIter+=2, alphaIter+=2) {
458 tpetraVector_.getNonconstObj()->update(
459 *alphaIter, *(*tmvIter), *(alphaIter+1), *(*(tmvIter+1)), ST::one());
463 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
464 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
470 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
476 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
481 tpetraVector_.getConstObj()->dot(*tmv, prods);
484 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
485 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
491 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
496 tpetraVector_.getConstObj()->norm1(norms);
500 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
505 tpetraVector_.getConstObj()->norm2(norms);
509 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
514 tpetraVector_.getConstObj()->normInf(norms);
518 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
528 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
529 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
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>();
545 "Error, conjugation without transposition is not allowed for complex scalar types!");
550 trans = Teuchos::NO_TRANS;
553 trans = Teuchos::NO_TRANS;
559 trans = Teuchos::CONJ_TRANS;
563 Y_tpetra->template modify<execution_space>();
564 Y_tpetra->multiply(trans, Teuchos::NO_TRANS, alpha, *tpetraVector_.getConstObj(), *X_tpetra, beta);
566 Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->
template sync<Kokkos::HostSpace>();
576 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
577 template<
class TpetraVector_t>
587 tpetraVectorSpace_ = tpetraVectorSpace;
588 tpetraVector_.initialize(tpetraVector);
589 this->updateSpmdSpace();
593 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
598 using Teuchos::rcp_dynamic_cast;
602 RCP<TMV> tmv = rcp_dynamic_cast<TMV>(mv);
604 return tmv->getTpetraMultiVector();
607 RCP<TV> tv = rcp_dynamic_cast<TV>(mv);
609 return tv->getTpetraVector();
612 return Teuchos::null;
616 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
621 using Teuchos::rcp_dynamic_cast;
627 return tmv->getConstTpetraMultiVector();
632 return tv->getConstTpetraVector();
635 return Teuchos::null;
639 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
645 RCP<TV> tv = Teuchos::rcp_dynamic_cast<TV>(v);
647 return tv->getTpetraVector();
649 return Teuchos::null;
654 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
662 return tv->getConstTpetraVector();
664 return Teuchos::null;
672 #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.
Concrete implementation of Thyra::MultiVector in terms of Tpetra::MultiVector.
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 initialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Initialize.
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
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.
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)
Use the non-transposed operator.
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.
Use the transposed operator with complex-conjugate clements (same as TRANS for real scalar types)...
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
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 absImpl(const VectorBase< Scalar > &x)
Default implementation of abs using RTOps.
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Use the non-transposed operator with complex-conjugate elements (same as NOTRANS for real scalar type...
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
Use the transposed operator.
virtual void reciprocalImpl(const VectorBase< Scalar > &x)
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,...).
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)
RCP< const VectorSpaceBase< Scalar > > domain() const
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Default implementation of dots using RTOps.
void getLocalVectorDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues) const
void getNonconstLocalVectorDataImpl(const Ptr< ArrayRCP< Scalar > > &localValues)
Abstract interface for finite-dimensional dense vectors.
Concrete Thyra::SpmdVectorBase using Tpetra::Vector.
RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraVector()
Get the embedded non-const Tpetra::Vector.
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 randomizeImpl(Scalar l, Scalar u)
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpaceImpl() const
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)
RCP< const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraVector() const
Get the embedded non-const Tpetra::Vector.
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
Default implementation of norm_2 (weighted) using RTOps.
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Implemented through this->getLocalData()
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()