10 #ifndef THYRA_TPETRA_MULTIVECTOR_HPP
11 #define THYRA_TPETRA_MULTIVECTOR_HPP
13 #include "Thyra_TpetraMultiVector_decl.hpp"
14 #include "Thyra_TpetraVectorSpace.hpp"
15 #include "Thyra_TpetraVector.hpp"
16 #include "Teuchos_Assert.hpp"
25 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
30 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
37 initializeImpl(tpetraVectorSpace, domainSpace, tpetraMultiVector);
41 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
48 initializeImpl(tpetraVectorSpace, domainSpace, tpetraMultiVector);
52 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
56 return tpetraMultiVector_.getNonconstObj();
60 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
64 return tpetraMultiVector_;
71 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 tpetraMultiVector_.getNonconstObj()->putScalar(alpha);
90 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
94 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
99 tpetraMultiVector_.getNonconstObj()->assign(*tmv);
106 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
110 tpetraMultiVector_.getNonconstObj()->scale(alpha);
114 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
120 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
126 tpetraMultiVector_.getNonconstObj()->update(alpha, *tmv, ST::one());
133 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
148 bool allCastsSuccessful =
true;
150 auto mvIter = mv.begin();
151 auto tmvIter = tmvs.begin();
152 for (; mvIter != mv.end(); ++mvIter, ++tmvIter) {
153 tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromPtr(*mvIter));
157 allCastsSuccessful =
false;
165 auto len = tmvs.
size();
167 tpetraMultiVector_.getNonconstObj()->scale(beta);
168 }
else if (len == 1 && allCastsSuccessful) {
169 tpetraMultiVector_.getNonconstObj()->update(alpha[0], *tmvs[0], beta);
170 }
else if (len == 2 && allCastsSuccessful) {
171 tpetraMultiVector_.getNonconstObj()->update(alpha[0], *tmvs[0], alpha[1], *tmvs[1], beta);
172 }
else if (allCastsSuccessful) {
174 auto tmvIter = tmvs.begin();
175 auto alphaIter = alpha.
begin();
180 for (; tmvIter != tmvs.end(); ++tmvIter) {
181 if (tmvIter->getRawPtr() == tpetraMultiVector_.getConstObj().getRawPtr()) {
188 tmvIter = tmvs.
begin();
192 if ((tmvs.size() % 2) == 0) {
193 tpetraMultiVector_.getNonconstObj()->scale(beta);
195 tpetraMultiVector_.getNonconstObj()->update(*alphaIter, *(*tmvIter), beta);
199 for (; tmvIter != tmvs.end(); tmvIter+=2, alphaIter+=2) {
200 tpetraMultiVector_.getNonconstObj()->update(
201 *alphaIter, *(*tmvIter), *(alphaIter+1), *(*(tmvIter+1)), ST::one());
209 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
215 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
220 tpetraMultiVector_.getConstObj()->dot(*tmv, prods);
227 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
232 tpetraMultiVector_.getConstObj()->norm1(norms);
236 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
241 tpetraMultiVector_.getConstObj()->norm2(norms);
245 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
250 tpetraMultiVector_.getConstObj()->normInf(norms);
254 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
261 return constTpetraVector<Scalar>(
263 tpetraMultiVector_->getVector(j)
268 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
275 return tpetraVector<Scalar>(
277 tpetraMultiVector_.getNonconstObj()->getVectorNonConst(j)
282 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
288 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
289 std::cerr <<
"\nTpetraMultiVector::subView(Range1D) const called!\n";
291 const Range1D colRng = this->validateColRange(col_rng_in);
294 this->getConstTpetraMultiVector()->subView(colRng);
297 tpetraVectorSpace<Scalar>(
298 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
299 tpetraView->getNumVectors(),
300 tpetraView->getMap()->getComm()
304 return constTpetraMultiVector(
312 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
318 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
319 std::cerr <<
"\nTpetraMultiVector::subView(Range1D) called!\n";
321 const Range1D colRng = this->validateColRange(col_rng_in);
324 this->getTpetraMultiVector()->subViewNonConst(colRng);
327 tpetraVectorSpace<Scalar>(
328 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
329 tpetraView->getNumVectors(),
330 tpetraView->getMap()->getComm()
334 return tpetraMultiVector(
342 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
348 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
349 std::cerr <<
"\nTpetraMultiVector::subView(ArrayView) const called!\n";
354 cols[i] = static_cast<std::size_t>(cols_in[i]);
357 this->getConstTpetraMultiVector()->subView(cols());
360 tpetraVectorSpace<Scalar>(
361 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
362 tpetraView->getNumVectors(),
363 tpetraView->getMap()->getComm()
367 return constTpetraMultiVector(
375 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
381 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
382 std::cerr <<
"\nTpetraMultiVector::subView(ArrayView) called!\n";
387 cols[i] = static_cast<std::size_t>(cols_in[i]);
390 this->getTpetraMultiVector()->subViewNonConst(cols());
393 tpetraVectorSpace<Scalar>(
394 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
395 tpetraView->getNumVectors(),
396 tpetraView->getMap()->getComm()
400 return tpetraMultiVector(
408 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
415 const Ordinal primary_global_offset
420 primary_op, multi_vecs, targ_multi_vecs, reduct_objs, primary_global_offset);
424 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
437 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
450 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
509 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
513 return tpetraVectorSpace_;
517 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
522 *localValues = tpetraMultiVector_.getNonconstObj()->get1dViewNonConst();
523 *leadingDim = tpetraMultiVector_->getStride();
527 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
532 *localValues = tpetraMultiVector_->get1dView();
533 *leadingDim = tpetraMultiVector_->getStride();
537 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
557 "Error, conjugation without transposition is not allowed for complex scalar types!");
575 Y_tpetra->multiply(trans,
Teuchos::NO_TRANS, alpha, *tpetraMultiVector_.getConstObj(), *X_tpetra, beta);
586 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
587 template<
class TpetraMultiVector_t>
601 tpetraVectorSpace_ = tpetraVectorSpace;
602 domainSpace_ = domainSpace;
603 tpetraMultiVector_.initialize(tpetraMultiVector);
604 this->updateSpmdSpace();
608 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
609 RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
613 using Teuchos::rcp_dynamic_cast;
617 RCP<TMV> tmv = rcp_dynamic_cast<TMV>(mv);
619 return tmv->getTpetraMultiVector();
622 RCP<TV> tv = rcp_dynamic_cast<TV>(mv);
624 return tv->getTpetraVector();
627 return Teuchos::null;
630 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
631 RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
635 using Teuchos::rcp_dynamic_cast;
639 RCP<const TMV> tmv = rcp_dynamic_cast<
const TMV>(mv);
641 return tmv->getConstTpetraMultiVector();
644 RCP<const TV> tv = rcp_dynamic_cast<
const TV>(mv);
646 return tv->getConstTpetraVector();
649 return Teuchos::null;
656 #endif // THYRA_TPETRA_MULTIVECTOR_HPP
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Concrete implementation of Thyra::MultiVector in terms of Tpetra::MultiVector.
TpetraMultiVector()
Construct to uninitialized.
RCP< const VectorBase< Scalar > > colImpl(Ordinal j) const
void getNonconstLocalMultiVectorDataImpl(const Ptr< ArrayRCP< Scalar > > &localValues, const Ptr< Ordinal > &leadingDim)
Concrete implementation of an SPMD vector space for Tpetra.
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraMultiVector()
Extract the underlying non-const Tpetra::MultiVector object.
virtual void assignImpl(Scalar alpha)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
RCP< MultiVectorBase< Scalar > > nonconstContigSubViewImpl(const Range1D &colRng)
void euclideanApply(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Uses GEMM() and Teuchos::reduceAll() to implement.
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 euclideanApply(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
virtual void mvMultiReductApplyOpImpl(const RTOpPack::RTOpT< Scalar > &primary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const ArrayView< const Ptr< RTOpPack::ReductTarget > > &reduct_objs, const Ordinal primary_global_offset) const
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)...
RCP< const MultiVectorBase< Scalar > > nonContigSubViewImpl(const ArrayView< const int > &cols_in) const
Use the non-transposed operator with complex-conjugate elements (same as NOTRANS for real scalar type...
void initialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace, const RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector)
Initialize.
Use the transposed operator.
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
virtual void scaleImpl(Scalar alpha)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
RCP< const MultiVectorBase< Scalar > > contigSubViewImpl(const Range1D &colRng) const
virtual void mvMultiReductApplyOpImpl(const RTOpPack::RTOpT< Scalar > &primary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const ArrayView< const Ptr< RTOpPack::ReductTarget > > &reduct_objs, const Ordinal primary_global_offset) const
Interface for a collection of column vectors called a multi-vector.
RCP< MultiVectorBase< Scalar > > nonconstNonContigSubViewImpl(const ArrayView< const int > &cols_in)
void constInitialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace, const RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector)
Initialize.
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
Concrete Thyra::SpmdVectorBase using Tpetra::Vector.
void acquireDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
RCP< VectorBase< Scalar > > nonconstColImpl(Ordinal j)
void commitNonconstDetachedMultiVectorViewImpl(RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
bool nonnull(const boost::shared_ptr< T > &p)
void getLocalMultiVectorDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues, const Ptr< Ordinal > &leadingDim) const
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraMultiVector() const
Extract the underlying const Tpetra::MultiVector object.
RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpaceImpl() const
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
void acquireNonconstDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
RCP< const ScalarProdVectorSpaceBase< Scalar > > domainScalarProdVecSpc() const
void acquireNonconstDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
void acquireDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Default implementation of dots using RTOps.
void commitNonconstDetachedMultiVectorViewImpl(RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Default implementation of update using RTOps.