Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultProductVectorSpace_decl.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_DECL_HPP
11 #define THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_DECL_HPP
12 
13 #include "Thyra_ProductVectorSpaceBase.hpp"
14 #include "Thyra_VectorSpaceDefaultBase.hpp"
15 #include "Teuchos_implicit_cast.hpp"
16 
17 namespace Thyra {
18 
19 
103 template<class Scalar>
104 class DefaultProductVectorSpace
105  : virtual public ProductVectorSpaceBase<Scalar>,
106  virtual protected VectorSpaceDefaultBase<Scalar>
107 {
108 public:
109 
112 
115 
118  const ArrayView<const RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
119  );
120 
159  virtual void initialize(
160  const ArrayView<const RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
161  );
162 
169  bool hasBeenCloned() const;
170 
191  virtual void uninitialize(
192  const ArrayView<RCP<const VectorSpaceBase<Scalar> > > &vecSpaces = Teuchos::null
193  );
194 
203  virtual const RCP<const VectorSpaceBase<Scalar> >* vecSpaces() const;
204 
213  virtual const Ordinal* vecSpacesOffsets() const;
214 
243  void getVecSpcPoss( Ordinal i, int* kth_vector_space, Ordinal* kth_global_offset ) const;
244 
246 
249 
251  int numBlocks() const;
253  RCP<const VectorSpaceBase<Scalar> > getBlock(const int k) const;
254 
256 
259 
261  Ordinal dim() const;
262 
266  bool isCompatible( const VectorSpaceBase<Scalar>& vecSpc ) const;
267 
269  RCP< VectorBase<Scalar> > createMember() const;
270 
274  Scalar scalarProd(
275  const VectorBase<Scalar>& x, const VectorBase<Scalar>& y ) const;
276 
280  void scalarProdsImpl(
281  const MultiVectorBase<Scalar>& X, const MultiVectorBase<Scalar>& Y,
282  const ArrayView<Scalar> &scalarProds ) const;
283 
287  bool hasInCoreView(const Range1D& rng, const EViewType viewType,
288  const EStrideType strideType) const;
289 
291  RCP< const VectorSpaceFactoryBase<Scalar> > smallVecSpcFcty() const;
292 
294  RCP< MultiVectorBase<Scalar> > createMembers(int numMembers) const;
295 
297  RCP< const VectorSpaceBase<Scalar> > clone() const;
298 
300 
303 
307  std::string description() const;
308 
316  void describe(
318  const Teuchos::EVerbosityLevel verbLevel
319  ) const;
320 
322 
323 protected:
324 
325  // ///////////////////////////////////
326  // Protected member functions
327 
328 private:
329 
330  // ///////////////////////////////////
331  // Private types
332 
333  typedef Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaces_t;
334  typedef Array<Ordinal> vecSpacesOffsets_t;
335 
336  // ///////////////////////////////////
337  // Private data members
338 
339  int numBlocks_;
340  RCP<vecSpaces_t> vecSpaces_;
341  RCP<vecSpacesOffsets_t> vecSpacesOffsets_;
342  // cached info
343  Ordinal dim_;
344  bool isInCore_;
345 
346  // ///////////////////////////////////
347  // Private member functions
348 
349  void assertInitialized() const;
350 
351 };
352 
353 
358 template<class Scalar>
359 inline
360 RCP<DefaultProductVectorSpace<Scalar> >
362 {
364 }
365 
366 
371 template<class Scalar>
372 inline
375  const ArrayView<RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
376  )
377 {
378  return Teuchos::rcp(new DefaultProductVectorSpace<Scalar>(vecSpaces));
379 }
380 
381 
387 template<class Scalar>
388 inline
391  const RCP<const VectorSpaceBase<Scalar> > &vecSpace,
392  const int numBlocks
393  )
394 {
395  Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaceBlocks;
396  for ( int i = 0; i < numBlocks; ++i )
397  vecSpaceBlocks.push_back(vecSpace);
398  return productVectorSpace<Scalar>(vecSpaceBlocks());
399 }
400 
401 
402 // /////////////////////////////////
403 // Inline members
404 
405 
406 template<class Scalar>
407 inline const RCP<const VectorSpaceBase<Scalar> >*
409 {
410  return ( dim_ ? &(*vecSpaces_)[0] : NULL );
411 }
412 
413 
414 template<class Scalar>
415 inline const Ordinal*
417 {
418  return ( dim_ ? &(*vecSpacesOffsets_)[0] : NULL );
419 }
420 
421 
422 template<class Scalar>
424 {
425  return vecSpaces_.strong_count() > 1;
426 }
427 
428 
429 template<class Scalar>
430 inline
432 {
434 #ifdef TEUCHOS_DEBUG
435  TEUCHOS_TEST_FOR_EXCEPT( is_null(vecSpaces_) );
436 #endif
437 }
438 
439 
440 } // namespace Thyra
441 
442 
443 #endif // THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_DECL_HPP
RCP< DefaultProductVectorSpace< Scalar > > productVectorSpace(const ArrayView< RCP< const VectorSpaceBase< Scalar > > > &vecSpaces)
Nonmember constructor that takes an array of vector spaces.
RCP< const VectorSpaceBase< Scalar > > getBlock(const int k) const
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)
Ordinal dim() const
Returns the summation of the constituent vector spaces.
RCP< DefaultProductVectorSpace< Scalar > > productVectorSpace()
Nonmember constructor that constructs to uninitialized.
Scalar scalarProd(const VectorBase< Scalar > &x, const VectorBase< Scalar > &y) const
Returns the sum of the scalar products of the constituent vectors.
bool hasBeenCloned() const
Return if this vector space was cloned.
RCP< const VectorSpaceFactoryBase< Scalar > > smallVecSpcFcty() const
Returns getBlock(0)-&gt;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.
RCP< DefaultProductVectorSpace< Scalar > > productVectorSpace(const RCP< const VectorSpaceBase< Scalar > > &vecSpace, const int numBlocks)
Nonmember constructor that duplicates a block vector space numBlock times to form a product space...
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. `*.
virtual void uninitialize(const ArrayView< RCP< const VectorSpaceBase< Scalar > > > &vecSpaces=Teuchos::null)
Uninitialize.
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
Returns a DefaultProductMultiVector object.
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.
TypeTo implicit_cast(const TypeFrom &t)
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 ...
void push_back(const value_type &x)
bool isCompatible(const VectorSpaceBase< Scalar > &vecSpc) const
Returns true only if also a product vector space and all constituent vectors are compatible.
EStrideType
Determine if data is unit stride or non-unit stride.
void scalarProds(const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y, const ArrayView< Scalar > &scalarProds_out) const
Return the scalar product of each column in two multi-vectors in the vector space.
virtual const RCP< const VectorSpaceBase< Scalar > > * vecSpaces() const
Returns a pointer to an array (of length this-&gt;numBlocks()) to the constituent vector spaces...
std::string description() const
Prints just the name DefaultProductVectorSpace along with the overall dimension and the number of blo...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
virtual const Ordinal * vecSpacesOffsets() const
Returns a pointer to an array (of length this-&gt;numBlocks()+1) of offset into each constituent vector ...
DefaultProductVectorSpace()
Default construct to uninitialized.
Teuchos::Range1D Range1D