10 #ifndef THYRA_TPETRA_VECTOR_SPACE_HPP
11 #define THYRA_TPETRA_VECTOR_SPACE_HPP
14 #include "Thyra_TpetraVectorSpace_decl.hpp"
15 #include "Thyra_TpetraThyraWrappers.hpp"
16 #include "Thyra_TpetraVector.hpp"
17 #include "Thyra_TpetraMultiVector.hpp"
18 #include "Thyra_TpetraEuclideanScalarProd.hpp"
19 #include "Tpetra_Details_StaticView.hpp"
24 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
25 RCP<TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
34 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
40 tpetraMap_ = tpetraMap;
41 this->updateState(tpetraMap->getGlobalNumElements(),
42 !tpetraMap->isDistributed());
43 this->setScalarProd(tpetraEuclideanScalarProd<Scalar,LocalOrdinal,GlobalOrdinal,Node>());
50 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
55 return tpetraVectorSpace<Scalar>(
56 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
57 size, tpetraMap_->getComm() ) );
64 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 return tpetraVector<Scalar>(
69 weakSelfPtr_.create_strong().getConst(),
77 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
81 return tpetraMultiVector<Scalar>(
82 weakSelfPtr_.create_strong().getConst(),
83 this->createLocallyReplicatedVectorSpace(numMembers),
86 tpetraMap_, numMembers,
false)
92 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
93 class CopyTpetraMultiVectorViewBack {
96 :mv_(mv), raw_mv_(raw_mv)
99 bool inUse = Teuchos::get_extra_data<bool>(tmv,
"inUse");
102 "Cannot use the cached vector simultaneously more than once.");
104 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv), Teuchos::POST_DESTROY,
false);
106 ~CopyTpetraMultiVectorViewBack()
110 RTOpPack::assign_entries<Scalar>( Teuchos::outArg(raw_mv_), smv );
111 mv_->releaseDetachedView(&smv);
113 RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tmv = Teuchos::rcp_dynamic_cast<TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(mv_,
true)->getTpetraMultiVector();
114 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv), Teuchos::POST_DESTROY,
false);
117 RCP<MultiVectorBase<Scalar> > mv_;
122 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
123 RCP< MultiVectorBase<Scalar> >
126 const bool initialize)
const
134 if (!tpetraMap_->isDistributed()) {
136 if (tpetraMV_.is_null() || (tpetraMV_->getNumVectors() != size_t (raw_mv.
numSubCols()))) {
137 if (!tpetraMV_.is_null())
141 "Cannot use the cached vector simultaneously more than once.");
144 auto dv = ::Tpetra::Details::getStatic2dDualView<IST, DT> (tpetraMap_->getGlobalNumElements(), raw_mv.
numSubCols());
147 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tpetraMV_));
150 if (tpetraDomainSpace_.is_null() || raw_mv.
numSubCols() != tpetraDomainSpace_->localSubDim())
151 tpetraDomainSpace_ = tpetraVectorSpace<Scalar>(Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(raw_mv.
numSubCols(), tpetraMap_->getComm()));
153 mv = tpetraMultiVector<Scalar>(weakSelfPtr_.create_strong().getConst(), tpetraDomainSpace_, tpetraMV_);
155 mv = this->createMembers(raw_mv.
numSubCols());
158 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv));
164 RTOpPack::assign_entries<Scalar>(
168 mv->commitDetachedView(&smv);
171 Teuchos::set_extra_data(
173 Teuchos::rcp(
new CopyTpetraMultiVectorViewBack<Scalar,LocalOrdinal,GlobalOrdinal,Node>(Teuchos::rcpFromRef(*mv),raw_mv)),
174 "CopyTpetraMultiVectorViewBack",
182 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
192 if (!tpetraMap_->isDistributed()) {
193 if (tpetraMV_.is_null() || (tpetraMV_->getNumVectors() != size_t (raw_mv.
numSubCols()))) {
194 if (!tpetraMV_.is_null())
198 "Cannot use the cached vector simultaneously more than once.");
201 auto dv = ::Tpetra::Details::getStatic2dDualView<IST, DT> (tpetraMap_->getGlobalNumElements(), raw_mv.
numSubCols());
204 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tpetraMV_));
207 if (tpetraDomainSpace_.is_null() || raw_mv.
numSubCols() != tpetraDomainSpace_->localSubDim())
208 tpetraDomainSpace_ = tpetraVectorSpace<Scalar>(Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(raw_mv.
numSubCols(), tpetraMap_->getComm()));
210 mv = tpetraMultiVector<Scalar>(weakSelfPtr_.create_strong().getConst(), tpetraDomainSpace_, tpetraMV_);
212 mv = this->createMembers(raw_mv.
numSubCols());
215 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv));
220 RTOpPack::assign_entries<Scalar>(
223 mv->commitDetachedView(&smv);
228 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
233 const Range1D rng = full_range(rng_in,0,this->dim()-1);
234 const Ordinal l_localOffset = this->localOffset();
236 const Ordinal myLocalSubDim = tpetraMap_.is_null () ?
237 static_cast<Ordinal> (0) : tpetraMap_->getLocalNumElements ();
239 return ( l_localOffset<=rng.
lbound() && rng.
ubound()<l_localOffset+myLocalSubDim );
243 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
247 return tpetraVectorSpace<Scalar>(tpetraMap_);
250 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
260 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
268 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
271 return tpetraMap_.is_null () ?
static_cast<Ordinal> (0) :
272 static_cast<Ordinal> (tpetraMap_->getLocalNumElements ());
278 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
289 #endif // THYRA_TPETRA_VECTOR_SPACE_HPP
Concrete implementation of Thyra::MultiVector in terms of Tpetra::MultiVector.
Ordinal localSubDim() const
Concrete implementation of an SPMD vector space for Tpetra.
Ordinal numSubCols() const
RCP< const VectorSpaceBase< Scalar > > clone() const
RCP< T > create_weak() const
typename map_type::device_type device_type
RCP< TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createLocallyReplicatedVectorSpace(int size) const
Create Tpetra locally replicated vector space.
static RCP< TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > create()
Create with weak ownership to self.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void initialize(const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &tpetraMap)
Initialize a serial space.
EViewType
Determines if a view is a direct view of data or a detached copy of data.
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getTpetraMap() const
Get the embedded Tpetra::Map.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
bool hasInCoreView(const Range1D &rng, const EViewType viewType, const EStrideType strideType) const
Returns true if all the elements in rng are in this process.
RCP< const Teuchos::Comm< Ordinal > > convertTpetraToThyraComm(const RCP< const Teuchos::Comm< int > > &tpetraComm)
Given an Tpetra Teuchos::Comm<int> object, return an equivalent Teuchos::Comm<Ordinal> object...
RCP< VectorBase< Scalar > > createMember() const
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
EStrideType
Determine if data is unit stride or non-unit stride.
RCP< const Teuchos::Comm< Ordinal > > getComm() const
RCP< MultiVectorBase< Scalar > > createCachedMembersView(const RTOpPack::SubMultiVectorView< Scalar > &raw_mv, bool initialize=true) const
Create a (possibly) cached multi-vector member that is a non-const view of raw multi-vector data...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)