42 #ifndef THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_HPP
43 #define THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_HPP
46 #include "Thyra_DefaultProductVectorSpace_decl.hpp"
47 #include "Thyra_DefaultProductVector.hpp"
48 #include "Thyra_DefaultProductMultiVector.hpp"
49 #include "Thyra_ProductMultiVectorBase.hpp"
50 #include "Teuchos_Workspace.hpp"
51 #include "Teuchos_dyn_cast.hpp"
60 template<
class Scalar>
62 : numBlocks_(-1), dim_(-1), isInCore_(false)
66 template<
class Scalar>
70 : numBlocks_(-1), dim_(-1)
76 template<
class Scalar>
85 const int nBlocks = vecSpaces_in.size();
89 bool overallHasInCoreView =
true;
90 for (
int k = 0; k < nBlocks; ++k) {
93 vecSpaces_in[k].
get() == NULL, std::invalid_argument
94 ,
"Error, the smart pointer vecSpaces["<<k<<
"] can not be NULL!"
97 if (!vecSpaces_in[k]->hasInCoreView()) overallHasInCoreView =
false;
103 numBlocks_ = nBlocks;
105 *vecSpaces_ = vecSpaces_in;
107 (*vecSpacesOffsets_)[0] = 0;
109 for(
int k = 1; k <= nBlocks; ++k ) {
110 const Ordinal dim_km1 = vecSpaces_in[k-1]->dim();
111 (*vecSpacesOffsets_)[k] = (*vecSpacesOffsets_)[k-1] + dim_km1;
114 isInCore_ = overallHasInCoreView;
119 template<
class Scalar>
125 vecSpaces_ = Teuchos::null;
126 vecSpacesOffsets_ = Teuchos::null;
133 template<
class Scalar>
141 !(0 <= i && i < this->dim()), std::out_of_range
142 ,
"VectorSpaceBlocked::get_vector_space_position(...): Error, i = "
143 << i <<
" is not in range [0,"<<(this->dim()-1)<<
"]"
146 *kth_vector_space = 0;
147 *kth_global_offset = 0;
148 while( *kth_vector_space < numBlocks_ ) {
149 const Ordinal off_kp1 = (*vecSpacesOffsets_)[*kth_vector_space+1];
151 *kth_global_offset = (*vecSpacesOffsets_)[*kth_vector_space];
154 ++(*kth_vector_space);
163 template<
class Scalar>
170 template<
class Scalar>
175 return (*vecSpaces_)[k];
182 template<
class Scalar>
189 template<
class Scalar>
194 using Teuchos::ptrFromRef;
195 using Teuchos::ptr_dynamic_cast;
197 const int nBlocks = this->numBlocks();
205 if( nBlocks != pvsb->numBlocks() )
207 for(
int i = 0; i < nBlocks; ++i ) {
208 if( !this->getBlock(i)->isCompatible(*pvsb->getBlock(i)) )
226 template<
class Scalar>
230 return defaultProductVector<Scalar>(Teuchos::rcpFromRef(*
this));
234 template<
class Scalar>
240 const int nBlocks = this->numBlocks();
247 || nBlocks!=y.productSpace()->numBlocks()
251 for(
int k = 0; k < nBlocks; ++k )
252 scalarProd_rtn += (*vecSpaces_)[k]->scalarProd(
255 return scalarProd_rtn;
259 template<
class Scalar>
277 scalarProds_out[0] = this->scalarProd(*X_in.
col(0),*Y_in.
col(0));
282 const int nBlocks = this->numBlocks();
289 Workspace<Scalar> _scalarProds_out(wss, m,
false);
290 std::fill( scalarProds_out.
begin(), scalarProds_out.
end(),
292 for(
int k = 0; k < nBlocks; ++k ) {
293 (*vecSpaces_)[k]->scalarProds(
295 for(
int j = 0; j < m; ++j )
296 scalarProds_out[j] += _scalarProds_out[j];
301 template<
class Scalar>
304 const Range1D rng = full_range(rng_in,0,dim_-1);
306 int kth_vector_space = -1;
308 this->getVecSpcPoss(rng.
lbound(),&kth_vector_space,&kth_global_offset);
312 if( rng.
lbound() + rng.
size() <= kth_global_offset + (*vecSpaces_)[kth_vector_space]->dim() ) {
313 return (*vecSpaces_)[kth_vector_space]->hasInCoreView(rng_in-kth_global_offset,viewType,strideType);
337 template<
class Scalar>
342 return (*vecSpaces_)[0]->smallVecSpcFcty();
343 return Teuchos::null;
347 template<
class Scalar>
351 return defaultProductMultiVector<Scalar>(Teuchos::rcpFromRef(*
this),
356 template<
class Scalar>
364 pvs = productVectorSpace<Scalar>();
365 pvs->numBlocks_ = numBlocks_;
366 pvs->vecSpaces_ = vecSpaces_;
367 pvs->vecSpacesOffsets_ = vecSpacesOffsets_;
369 pvs->isInCore_ = isInCore_;
377 template<
class Scalar>
380 std::ostringstream oss;
384 <<
",numBlocks="<<numBlocks_
390 template<
class Scalar>
401 *out << this->description() << std::endl;
405 *out <<
"Constituent vector spaces V[0], V[1], ... V[numBlocks-1]:\n";
407 for(
int k = 0; k < numBlocks_; ++k ) {
408 *out <<
"V["<<k<<
"] = " << Teuchos::describe(*(*vecSpaces_)[k],verbLevel);
417 #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.