43#ifndef THYRA_TPETRA_VECTOR_SPACE_HPP
44#define THYRA_TPETRA_VECTOR_SPACE_HPP
47#include "Thyra_TpetraVectorSpace_decl.hpp"
48#include "Thyra_TpetraThyraWrappers.hpp"
49#include "Thyra_TpetraVector.hpp"
50#include "Thyra_TpetraMultiVector.hpp"
51#include "Thyra_TpetraEuclideanScalarProd.hpp"
52#include "Tpetra_Details_StaticView.hpp"
57template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 const RCP<
const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
73 tpetraMap_ = tpetraMap;
74 this->
updateState(tpetraMap->getGlobalNumElements(),
75 !tpetraMap->isDistributed());
83template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
88 weakSelfPtr_.create_strong().getConst(),
90 new Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_,
false)
96template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
101 weakSelfPtr_.create_strong().getConst(),
103 Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(
104 numMembers, tpetraMap_->getComm()
108 new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
109 tpetraMap_, numMembers,
false)
117template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
118class CopyTpetraMultiVectorViewBack {
121 :mv_(mv), raw_mv_(raw_mv)
124 bool inUse = Teuchos::get_extra_data<bool>(tmv,
"inUse");
127 "Cannot use the cached vector simultaneously more than once.");
129 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv), Teuchos::POST_DESTROY,
false);
131 ~CopyTpetraMultiVectorViewBack()
135 RTOpPack::assign_entries<Scalar>( Teuchos::outArg(raw_mv_), smv );
136 mv_->releaseDetachedView(&smv);
138 RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tmv = Teuchos::rcp_dynamic_cast<TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(mv_,
true)->getTpetraMultiVector();
139 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv), Teuchos::POST_DESTROY,
false);
142 RCP<MultiVectorBase<Scalar> > mv_;
143 const RTOpPack::SubMultiVectorView<Scalar> raw_mv_;
147template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
158 if (!tpetraMap_->isDistributed()) {
160 if (tpetraMV_.is_null() || (tpetraMV_->getNumVectors() != size_t (raw_mv.
numSubCols()))) {
161 if (!tpetraMV_.is_null())
165 "Cannot use the cached vector simultaneously more than once.");
166 using IST =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::impl_scalar_type;
167 using DT =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::device_type;
168 auto dv = ::Tpetra::Details::getStatic2dDualView<IST, DT> (tpetraMap_->getGlobalNumElements(), raw_mv.
numSubCols());
169 tpetraMV_ =
Teuchos::rcp(
new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_, dv));
171 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tpetraMV_));
174 if (tpetraDomainSpace_.is_null() || raw_mv.
numSubCols() != tpetraDomainSpace_->localSubDim())
182 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv));
187 RTOpPack::assign_entries<Scalar>(
191 mv->commitDetachedView(&smv);
193 Teuchos::set_extra_data(
195 Teuchos::rcp(
new CopyTpetraMultiVectorViewBack<Scalar,LocalOrdinal,GlobalOrdinal,Node>(Teuchos::rcpFromRef(*mv),raw_mv)),
196 "CopyTpetraMultiVectorViewBack",
204template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
214 if (!tpetraMap_->isDistributed()) {
215 if (tpetraMV_.is_null() || (tpetraMV_->getNumVectors() != size_t (raw_mv.
numSubCols()))) {
216 if (!tpetraMV_.is_null())
220 "Cannot use the cached vector simultaneously more than once.");
221 using IST =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::impl_scalar_type;
222 using DT =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::device_type;
223 auto dv = ::Tpetra::Details::getStatic2dDualView<IST, DT> (tpetraMap_->getGlobalNumElements(), raw_mv.
numSubCols());
224 tpetraMV_ =
Teuchos::rcp(
new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_, dv));
226 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tpetraMV_));
229 if (tpetraDomainSpace_.is_null() || raw_mv.
numSubCols() != tpetraDomainSpace_->localSubDim())
237 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv));
242 RTOpPack::assign_entries<Scalar>(
245 mv->commitDetachedView(&smv);
250template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
255 const Range1D rng = full_range(rng_in,0,this->
dim()-1);
258 const Ordinal myLocalSubDim = tpetraMap_.is_null () ?
259 static_cast<Ordinal> (0) : tpetraMap_->getLocalNumElements ();
261 return ( l_localOffset<=rng.
lbound() && rng.
ubound()<l_localOffset+myLocalSubDim );
265template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
272template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
282template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
290template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
293 return tpetraMap_.is_null () ?
static_cast<Ordinal> (0) :
294 static_cast<Ordinal> (tpetraMap_->getLocalNumElements ());
300template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
301TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node>::TpetraVectorSpace()
Ordinal numSubCols() const
RCP< T > create_weak() const
Interface for a collection of column vectors called a multi-vector.
virtual void setScalarProd(const RCP< const ScalarProdBase< Scalar > > &scalarProd)
Set a different scalar product.
virtual void updateState(const Ordinal globalDim, const bool isLocallyReplicated=false)
This function must be called whenever the state of this changes and some internal state must be updat...
Ordinal localOffset() const
Ordinal dim() const
Returns the sum of the local number of elements on every process.
RCP< const TpetraEuclideanScalarProd< Scalar, LocalOrdinal, GlobalOrdinal, Node > > tpetraEuclideanScalarProd()
Nonmember constructor for TpetraEuclideanScalarProd.
RCP< TpetraMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > tpetraMultiVector(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace, const RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector)
Nonmember constructor for TpetraMultiVector.
TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > this_t
RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getTpetraMap() const
Get the embedded Tpetra::Map.
RCP< TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > tpetraVectorSpace(const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &tpetraMap)
Nonmember constructor that creats a serial vector space.
bool hasInCoreView(const Range1D &rng, const EViewType viewType, const EStrideType strideType) const
Returns true if all the elements in rng are in this process.
Ordinal localSubDim() const
void initialize(const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &tpetraMap)
Initialize a serial space.
RCP< MultiVectorBase< Scalar > > createCachedMembersView(const RTOpPack::SubMultiVectorView< Scalar > &raw_mv) const
Create a (possibly) cached multi-vector member that is a non-const view of raw multi-vector data....
RCP< const VectorSpaceBase< Scalar > > clone() const
RCP< VectorBase< Scalar > > createMember() const
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
RCP< const Teuchos::Comm< Ordinal > > getComm() const
static RCP< TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > create()
Create with weak ownership to self.
RCP< TpetraVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > tpetraVector(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Nonmember constructor for TpetraVector.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
EStrideType
Determine if data is unit stride or non-unit stride.
EViewType
Determines if a view is a direct view of data or a detached copy of data.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)