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>
89 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
90 size, tpetraMap_->getComm() ) );
97template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
102 weakSelfPtr_.create_strong().getConst(),
104 new Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_,
false)
110template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
115 weakSelfPtr_.create_strong().getConst(),
116 this->createLocallyReplicatedVectorSpace(numMembers),
118 new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
119 tpetraMap_, numMembers,
false)
125template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
126class CopyTpetraMultiVectorViewBack {
129 :mv_(mv), raw_mv_(raw_mv)
132 bool inUse = Teuchos::get_extra_data<bool>(tmv,
"inUse");
135 "Cannot use the cached vector simultaneously more than once.");
137 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv), Teuchos::POST_DESTROY,
false);
139 ~CopyTpetraMultiVectorViewBack()
143 RTOpPack::assign_entries<Scalar>( Teuchos::outArg(raw_mv_), smv );
144 mv_->releaseDetachedView(&smv);
146 RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tmv = Teuchos::rcp_dynamic_cast<TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(mv_,
true)->getTpetraMultiVector();
147 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv), Teuchos::POST_DESTROY,
false);
150 RCP<MultiVectorBase<Scalar> > mv_;
151 const RTOpPack::SubMultiVectorView<Scalar> raw_mv_;
155template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
166 if (!tpetraMap_->isDistributed()) {
168 if (tpetraMV_.is_null() || (tpetraMV_->getNumVectors() != size_t (raw_mv.
numSubCols()))) {
169 if (!tpetraMV_.is_null())
173 "Cannot use the cached vector simultaneously more than once.");
174 using IST =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::impl_scalar_type;
175 using DT =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::device_type;
176 auto dv = ::Tpetra::Details::getStatic2dDualView<IST, DT> (tpetraMap_->getGlobalNumElements(), raw_mv.
numSubCols());
177 tpetraMV_ =
Teuchos::rcp(
new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_, dv));
179 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tpetraMV_));
182 if (tpetraDomainSpace_.is_null() || raw_mv.
numSubCols() != tpetraDomainSpace_->localSubDim())
190 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv));
195 RTOpPack::assign_entries<Scalar>(
199 mv->commitDetachedView(&smv);
201 Teuchos::set_extra_data(
203 Teuchos::rcp(
new CopyTpetraMultiVectorViewBack<Scalar,LocalOrdinal,GlobalOrdinal,Node>(Teuchos::rcpFromRef(*mv),raw_mv)),
204 "CopyTpetraMultiVectorViewBack",
212template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
222 if (!tpetraMap_->isDistributed()) {
223 if (tpetraMV_.is_null() || (tpetraMV_->getNumVectors() != size_t (raw_mv.
numSubCols()))) {
224 if (!tpetraMV_.is_null())
228 "Cannot use the cached vector simultaneously more than once.");
229 using IST =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::impl_scalar_type;
230 using DT =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::device_type;
231 auto dv = ::Tpetra::Details::getStatic2dDualView<IST, DT> (tpetraMap_->getGlobalNumElements(), raw_mv.
numSubCols());
232 tpetraMV_ =
Teuchos::rcp(
new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_, dv));
234 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tpetraMV_));
237 if (tpetraDomainSpace_.is_null() || raw_mv.
numSubCols() != tpetraDomainSpace_->localSubDim())
245 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv));
250 RTOpPack::assign_entries<Scalar>(
253 mv->commitDetachedView(&smv);
258template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
263 const Range1D rng = full_range(rng_in,0,this->
dim()-1);
266 const Ordinal myLocalSubDim = tpetraMap_.is_null () ?
267 static_cast<Ordinal
> (0) : tpetraMap_->getLocalNumElements ();
269 return ( l_localOffset<=rng.
lbound() && rng.
ubound()<l_localOffset+myLocalSubDim );
273template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
280template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
290template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
298template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
301 return tpetraMap_.
is_null () ?
static_cast<Ordinal
> (0) :
302 static_cast<Ordinal
> (tpetraMap_->getLocalNumElements ());
308template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
309TpetraVectorSpace<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 non-const TpetraMultiVector.
Concrete implementation of an SPMD vector space for Tpetra.
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.
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)