10 #ifndef THYRA_TPETRA_VECTOR_HPP
11 #define THYRA_TPETRA_VECTOR_HPP
23 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
28 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
31 const RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector
34 initializeImpl(tpetraVectorSpace, tpetraVector);
38 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
41 const RCP<
const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector
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>
97 const Ptr<ArrayRCP<Scalar> > &localValues )
99 *localValues = tpetraVector_.getNonconstObj()->get1dViewNonConst();
103 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
105 const Ptr<ArrayRCP<const Scalar> > &localValues )
const
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>
137 const VectorBase<Scalar>& x
140 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
145 tpetraVector_.getNonconstObj()->abs(*tx);
147 VectorDefaultBase<Scalar>::absImpl(x);
152 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
154 const VectorBase<Scalar>& x
157 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
162 tpetraVector_.getNonconstObj()->reciprocal(*tx);
164 VectorDefaultBase<Scalar>::reciprocalImpl(x);
169 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
171 const VectorBase<Scalar>& x
174 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
180 tpetraVector_.getNonconstObj()->elementWiseMultiply(
181 ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
183 VectorDefaultBase<Scalar>::eleWiseScaleImpl(x);
188 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
191 const VectorBase<Scalar>& x
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)));
207 return VectorDefaultBase<Scalar>::norm2WeightedImpl(x);
212 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
215 const ArrayView<
const Ptr<
const VectorBase<Scalar> > > &vecs,
216 const ArrayView<
const Ptr<VectorBase<Scalar> > > &targ_vecs,
217 const Ptr<RTOpPack::ReductTarget> &reduct_obj,
221 SpmdVectorDefaultBase<Scalar>::applyOpImpl(op, vecs, targ_vecs, reduct_obj, global_offset);
225 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
232 SpmdVectorDefaultBase<Scalar>::acquireDetachedVectorViewImpl(rng, sub_vec);
236 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
244 SpmdVectorDefaultBase<Scalar>::acquireNonconstDetachedVectorViewImpl(rng, sub_vec);
248 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
254 SpmdVectorDefaultBase<Scalar>::commitNonconstDetachedVectorViewImpl(sub_vec);
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);
279 MultiVectorDefaultBase<Scalar>::assignMultiVecImpl(mv);
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>
294 const MultiVectorBase<Scalar>& mv
297 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
303 tpetraVector_.getNonconstObj()->update(alpha, *tmv, ST::one());
305 MultiVectorDefaultBase<Scalar>::updateImpl(alpha, mv);
310 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
313 const ArrayView<
const Ptr<
const MultiVectorBase<Scalar> > >& mv,
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());
381 MultiVectorDefaultBase<Scalar>::linearCombinationImpl(alpha, mv, beta);
386 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
388 const MultiVectorBase<Scalar>& mv,
392 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
397 tpetraVector_.getConstObj()->dot(*tmv, prods);
399 MultiVectorDefaultBase<Scalar>::dotsImpl(mv, prods);
404 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
406 const ArrayView<
typename ScalarTraits<Scalar>::magnitudeType>& norms
409 tpetraVector_.getConstObj()->norm1(norms);
413 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
415 const ArrayView<
typename ScalarTraits<Scalar>::magnitudeType>& norms
418 tpetraVector_.getConstObj()->norm2(norms);
422 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
424 const ArrayView<
typename ScalarTraits<Scalar>::magnitudeType>& norms
427 tpetraVector_.getConstObj()->normInf(norms);
431 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
433 const EOpTransp M_trans,
434 const MultiVectorBase<Scalar> &X,
435 const Ptr<MultiVectorBase<Scalar> > &Y,
441 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
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);
472 VectorDefaultBase<Scalar>::applyImpl(M_trans, X, Y, alpha, 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>
503 using Teuchos::rcp_dynamic_cast;
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();
521 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
526 using Teuchos::rcp_dynamic_cast;
532 return tmv->getConstTpetraMultiVector();
537 return tv->getConstTpetraVector();
544 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
550 RCP<TV> tv = Teuchos::rcp_dynamic_cast<TV>(v);
552 return tv->getTpetraVector();
559 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
567 return tv->getConstTpetraVector();
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.
Concrete implementation of Thyra::MultiVector in terms of Tpetra::MultiVector.
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraMultiVector(const RCP< MultiVectorBase< Scalar > > &mv) const
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)
void initialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Initialize.
RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraMultiVector(const RCP< const MultiVectorBase< Scalar > > &mv) const
TpetraVector()
Construct to uninitialized.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
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 norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
void getLocalVectorDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues) const
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
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
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)
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > TpetraMultiVector_t
RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpaceImpl() const
void initializeImpl(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< TpetraVector_t > &tpetraVector)
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.
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 void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
virtual void scaleImpl(Scalar alpha)
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)