10 #ifndef THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_HPP
11 #define THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_HPP
14 #include "Thyra_DefaultProductVectorSpace_decl.hpp"
15 #include "Thyra_DefaultProductVector.hpp"
16 #include "Thyra_DefaultProductMultiVector.hpp"
17 #include "Thyra_ProductMultiVectorBase.hpp"
18 #include "Teuchos_Workspace.hpp"
19 #include "Teuchos_dyn_cast.hpp"
28 template<
class Scalar>
30 : numBlocks_(-1), dim_(-1), isInCore_(false)
34 template<
class Scalar>
38 : numBlocks_(-1), dim_(-1)
44 template<
class Scalar>
53 const int nBlocks = vecSpaces_in.size();
57 bool overallHasInCoreView =
true;
58 for (
int k = 0; k < nBlocks; ++k) {
61 vecSpaces_in[k].
get() == NULL, std::invalid_argument
62 ,
"Error, the smart pointer vecSpaces["<<k<<
"] can not be NULL!"
65 if (!vecSpaces_in[k]->hasInCoreView()) overallHasInCoreView =
false;
73 *vecSpaces_ = vecSpaces_in;
75 (*vecSpacesOffsets_)[0] = 0;
77 for(
int k = 1; k <= nBlocks; ++k ) {
78 const Ordinal dim_km1 = vecSpaces_in[k-1]->dim();
79 (*vecSpacesOffsets_)[k] = (*vecSpacesOffsets_)[k-1] + dim_km1;
82 isInCore_ = overallHasInCoreView;
87 template<
class Scalar>
93 vecSpaces_ = Teuchos::null;
94 vecSpacesOffsets_ = Teuchos::null;
101 template<
class Scalar>
109 !(0 <= i && i < this->dim()), std::out_of_range
110 ,
"VectorSpaceBlocked::get_vector_space_position(...): Error, i = "
111 << i <<
" is not in range [0,"<<(this->dim()-1)<<
"]"
114 *kth_vector_space = 0;
115 *kth_global_offset = 0;
116 while( *kth_vector_space < numBlocks_ ) {
117 const Ordinal off_kp1 = (*vecSpacesOffsets_)[*kth_vector_space+1];
119 *kth_global_offset = (*vecSpacesOffsets_)[*kth_vector_space];
122 ++(*kth_vector_space);
131 template<
class Scalar>
138 template<
class Scalar>
143 return (*vecSpaces_)[k];
150 template<
class Scalar>
157 template<
class Scalar>
162 using Teuchos::ptrFromRef;
163 using Teuchos::ptr_dynamic_cast;
165 const int nBlocks = this->numBlocks();
173 if( nBlocks != pvsb->numBlocks() )
175 for(
int i = 0; i < nBlocks; ++i ) {
176 if( !this->getBlock(i)->isCompatible(*pvsb->getBlock(i)) )
194 template<
class Scalar>
198 return defaultProductVector<Scalar>(Teuchos::rcpFromRef(*
this));
202 template<
class Scalar>
208 const int nBlocks = this->numBlocks();
215 || nBlocks!=y.productSpace()->numBlocks()
219 for(
int k = 0; k < nBlocks; ++k )
220 scalarProd_rtn += (*vecSpaces_)[k]->scalarProd(
223 return scalarProd_rtn;
227 template<
class Scalar>
245 scalarProds_out[0] = this->scalarProd(*X_in.
col(0),*Y_in.
col(0));
250 const int nBlocks = this->numBlocks();
257 Workspace<Scalar> _scalarProds_out(wss, m,
false);
258 std::fill( scalarProds_out.
begin(), scalarProds_out.
end(),
260 for(
int k = 0; k < nBlocks; ++k ) {
261 (*vecSpaces_)[k]->scalarProds(
263 for(
int j = 0; j < m; ++j )
264 scalarProds_out[j] += _scalarProds_out[j];
269 template<
class Scalar>
272 const Range1D rng = full_range(rng_in,0,dim_-1);
274 int kth_vector_space = -1;
276 this->getVecSpcPoss(rng.
lbound(),&kth_vector_space,&kth_global_offset);
280 if( rng.
lbound() + rng.
size() <= kth_global_offset + (*vecSpaces_)[kth_vector_space]->dim() ) {
281 return (*vecSpaces_)[kth_vector_space]->hasInCoreView(rng_in-kth_global_offset,viewType,strideType);
305 template<
class Scalar>
310 return (*vecSpaces_)[0]->smallVecSpcFcty();
311 return Teuchos::null;
315 template<
class Scalar>
319 return defaultProductMultiVector<Scalar>(Teuchos::rcpFromRef(*
this),
324 template<
class Scalar>
332 pvs = productVectorSpace<Scalar>();
333 pvs->numBlocks_ = numBlocks_;
334 pvs->vecSpaces_ = vecSpaces_;
335 pvs->vecSpacesOffsets_ = vecSpacesOffsets_;
337 pvs->isInCore_ = isInCore_;
345 template<
class Scalar>
348 std::ostringstream oss;
352 <<
",numBlocks="<<numBlocks_
358 template<
class Scalar>
369 *out << this->description() << std::endl;
373 *out <<
"Constituent vector spaces V[0], V[1], ... V[numBlocks-1]:\n";
375 for(
int k = 0; k < numBlocks_; ++k ) {
376 *out <<
"V["<<k<<
"] = " << Teuchos::describe(*(*vecSpaces_)[k],verbLevel);
385 #endif // THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_HPP
RCP< const VectorSpaceBase< Scalar > > getBlock(const int k) const
Base interface for product multi-vectors.
bool hasInCoreView(const Range1D &rng, const EViewType viewType, const EStrideType strideType) const
Returns true if all of the constituent vector spaces return true.
RCP< const VectorSpaceBase< Scalar > > clone() const
Clones the object as promised.
bool is_null(const boost::shared_ptr< T > &p)
Base interface for product vectors.
basic_OSTab< char > OSTab
virtual RCP< const VectorBase< Scalar > > getVectorBlock(const int k) const =0
Returns a non-persisting const view of the (zero-based) kth block vector.
Ordinal dim() const
Returns the summation of the constituent vector spaces.
The view is a direct view of data and no copies are made.
virtual Teuchos::RCP< const ProductVectorSpaceBase< Scalar > > productSpace() const =0
Returns the associated product vector space that represents the range.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Scalar scalarProd(const VectorBase< Scalar > &x, const VectorBase< Scalar > &y) const
Returns the sum of the scalar products of the constituent vectors.
T_To & dyn_cast(T_From &from)
RCP< const VectorSpaceFactoryBase< Scalar > > smallVecSpcFcty() const
Returns getBlock(0)->smallVecSpcFcty().
Abstract interface for objects that represent a space for vectors.
EViewType
Determines if a view is a direct view of data or a detached copy of data.
virtual Teuchos::RCP< const MultiVectorBase< Scalar > > getMultiVectorBlock(const int k) const =0
Returns a non-persisting const view of the (zero-based) kth block multi-vector.
void scalarProdsImpl(const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y, const ArrayView< Scalar > &scalarProds) const
Returns the sum of the scalar products of each of the columns of the constituent multi-vectors.
RCP< VectorBase< Scalar > > createMember() const
Returns a DefaultProductVector object.
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.
virtual void uninitialize(const ArrayView< RCP< const VectorSpaceBase< Scalar > > > &vecSpaces=Teuchos::null)
Uninitialize.
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
Returns a DefaultProductMultiVector object.
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
virtual void initialize(const ArrayView< const RCP< const VectorSpaceBase< Scalar > > > &vecSpaces)
Initialize with a list of constituent vector spaces.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints the details about the constituent vector spaces.
virtual std::string description() const
Abstract interface for finite-dimensional dense vectors.
void getVecSpcPoss(Ordinal i, int *kth_vector_space, Ordinal *kth_global_offset) const
Get the position of the vector space object and its offset into a composite vector that owns the ith ...
TEUCHOSCORE_LIB_DLL_EXPORT bool includesVerbLevel(const EVerbosityLevel verbLevel, const EVerbosityLevel requestedVerbLevel, const bool isDefaultLevel=false)
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
bool nonnull(const boost::shared_ptr< T > &p)
bool isCompatible(const VectorSpaceBase< Scalar > &vecSpc) const
Returns true only if also a product vector space and all constituent vectors are compatible.
TypeTo as(const TypeFrom &t)
EStrideType
Determine if data is unit stride or non-unit stride.
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
std::string description() const
Prints just the name DefaultProductVectorSpace along with the overall dimension and the number of blo...
virtual bool isCompatible(const VectorSpaceBase< Scalar > &vecSpc) const =0
Compare the compatibility of two vector spaces.
virtual Ordinal dim() const =0
Return the dimension of the vector space.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
DefaultProductVectorSpace()
Default construct to uninitialized.