10 #ifndef THYRA_TPETRA_VECTOR_HPP
11 #define THYRA_TPETRA_VECTOR_HPP
14 #include "Thyra_TpetraVector_decl.hpp"
15 #include "Thyra_TpetraMultiVector.hpp"
23 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
28 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
34 initializeImpl(tpetraVectorSpace, tpetraVector);
38 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
44 initializeImpl(tpetraVectorSpace, tpetraVector);
48 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
52 return tpetraVector_.getNonconstObj();
56 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
65 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 if (domainSpace_.is_null()) {
70 domainSpace_ = tpetraVectorSpace<Scalar>(
71 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
73 tpetraVector_.getConstObj()->getMap()->getComm()
84 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
88 return tpetraVectorSpace_;
95 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
99 *localValues = tpetraVector_.getNonconstObj()->get1dViewNonConst();
103 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
107 *localValues = tpetraVector_->get1dView();
114 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
122 if (!tpetraVector_.getNonconstObj()->isDistributed()) {
123 auto comm = tpetraVector_.getNonconstObj()->getMap()->getComm();
124 if (tpetraVector_.getConstObj()->getMap()->getComm()->getRank() == 0)
125 tpetraVector_.getNonconstObj()->randomize(l, u);
128 tpetraVector_.getNonconstObj()->reduce();
130 tpetraVector_.getNonconstObj()->randomize(l, u);
135 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
140 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
145 tpetraVector_.getNonconstObj()->abs(*tx);
152 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
157 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
162 tpetraVector_.getNonconstObj()->reciprocal(*tx);
169 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
174 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
180 tpetraVector_.getNonconstObj()->elementWiseMultiply(
181 ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
188 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
194 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
202 = Tpetra::createVector<Scalar>(tx->getMap());
203 temp->elementWiseMultiply(
204 ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
205 return ST::magnitude(ST::squareroot(tpetraVector_.getConstObj()->dot(*temp)));
212 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
225 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
236 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
248 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
261 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
264 tpetraVector_.getNonconstObj()->putScalar(alpha);
268 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
272 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
277 tpetraVector_.getNonconstObj()->assign(*tmv);
284 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
287 tpetraVector_.getNonconstObj()->scale(alpha);
291 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
297 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
303 tpetraVector_.getNonconstObj()->update(alpha, *tmv, ST::one());
310 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
324 bool allCastsSuccessful =
true;
326 auto mvIter = mv.begin();
327 auto tmvIter = tmvs.begin();
328 for (; mvIter != mv.end(); ++mvIter, ++tmvIter) {
329 tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromPtr(*mvIter));
333 allCastsSuccessful =
false;
341 auto len = mv.size();
343 tpetraVector_.getNonconstObj()->scale(beta);
344 }
else if (len == 1 && allCastsSuccessful) {
345 tpetraVector_.getNonconstObj()->update(alpha[0], *tmvs[0], beta);
346 }
else if (len == 2 && allCastsSuccessful) {
347 tpetraVector_.getNonconstObj()->update(alpha[0], *tmvs[0], alpha[1], *tmvs[1], beta);
348 }
else if (allCastsSuccessful) {
350 auto tmvIter = tmvs.begin();
351 auto alphaIter = alpha.
begin();
356 for (; tmvIter != tmvs.end(); ++tmvIter) {
357 if (tmvIter->getRawPtr() == tpetraVector_.getConstObj().getRawPtr()) {
365 tmvIter = tmvs.begin();
369 if ((tmvs.size() % 2) == 0) {
370 tpetraVector_.getNonconstObj()->scale(beta);
372 tpetraVector_.getNonconstObj()->update(*alphaIter, *(*tmvIter), beta);
376 for (; tmvIter != tmvs.end(); tmvIter+=2, alphaIter+=2) {
377 tpetraVector_.getNonconstObj()->update(
378 *alphaIter, *(*tmvIter), *(alphaIter+1), *(*(tmvIter+1)), ST::one());
386 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
392 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
397 tpetraVector_.getConstObj()->dot(*tmv, prods);
404 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
409 tpetraVector_.getConstObj()->norm1(norms);
413 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
418 tpetraVector_.getConstObj()->norm2(norms);
422 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
427 tpetraVector_.getConstObj()->normInf(norms);
431 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
451 "Error, conjugation without transposition is not allowed for complex scalar types!");
469 Y_tpetra->multiply(trans,
Teuchos::NO_TRANS, alpha, *tpetraVector_.getConstObj(), *X_tpetra, beta);
481 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
482 template<
class TpetraVector_t>
492 tpetraVectorSpace_ = tpetraVectorSpace;
493 tpetraVector_.initialize(tpetraVector);
494 this->updateSpmdSpace();
498 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
499 RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
500 TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
501 getTpetraMultiVector(
const RCP<MultiVectorBase<Scalar> >& mv)
const
503 using Teuchos::rcp_dynamic_cast;
504 typedef TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
505 typedef TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
507 RCP<TMV> tmv = rcp_dynamic_cast<TMV>(mv);
509 return tmv->getTpetraMultiVector();
512 RCP<TV> tv = rcp_dynamic_cast<TV>(mv);
514 return tv->getTpetraVector();
517 return Teuchos::null;
521 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
522 RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
523 TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
524 getConstTpetraMultiVector(
const RCP<
const MultiVectorBase<Scalar> >& mv)
const
526 using Teuchos::rcp_dynamic_cast;
527 typedef TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
528 typedef TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
530 RCP<const TMV> tmv = rcp_dynamic_cast<
const TMV>(mv);
532 return tmv->getConstTpetraMultiVector();
535 RCP<const TV> tv = rcp_dynamic_cast<
const TV>(mv);
537 return tv->getConstTpetraVector();
540 return Teuchos::null;
544 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
545 RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
549 typedef TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TV;
550 RCP<TV> tv = Teuchos::rcp_dynamic_cast<TV>(v);
552 return tv->getTpetraVector();
554 return Teuchos::null;
559 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
560 RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
564 typedef TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TV;
565 RCP<const TV> tv = Teuchos::rcp_dynamic_cast<
const TV>(v);
567 return tv->getConstTpetraVector();
569 return Teuchos::null;
577 #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()