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 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_DECL_HPP
43 #define THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_DECL_HPP
44 
45 #include "Thyra_ProductVectorSpaceBase.hpp"
46 #include "Thyra_VectorSpaceDefaultBase.hpp"
47 #include "Teuchos_implicit_cast.hpp"
48 
49 namespace Thyra {
50 
51 
135 template<class Scalar>
136 class DefaultProductVectorSpace
137  : virtual public ProductVectorSpaceBase<Scalar>,
138  virtual protected VectorSpaceDefaultBase<Scalar>
139 {
140 public:
141 
144 
147 
150  const ArrayView<const RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
151  );
152 
191  virtual void initialize(
192  const ArrayView<const RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
193  );
194 
201  bool hasBeenCloned() const;
202 
223  virtual void uninitialize(
224  const ArrayView<RCP<const VectorSpaceBase<Scalar> > > &vecSpaces = Teuchos::null
225  );
226 
235  virtual const RCP<const VectorSpaceBase<Scalar> >* vecSpaces() const;
236 
245  virtual const Ordinal* vecSpacesOffsets() const;
246 
275  void getVecSpcPoss( Ordinal i, int* kth_vector_space, Ordinal* kth_global_offset ) const;
276 
278 
281 
283  int numBlocks() const;
285  RCP<const VectorSpaceBase<Scalar> > getBlock(const int k) const;
286 
288 
291 
293  Ordinal dim() const;
294 
298  bool isCompatible( const VectorSpaceBase<Scalar>& vecSpc ) const;
299 
301  RCP< VectorBase<Scalar> > createMember() const;
302 
306  Scalar scalarProd(
307  const VectorBase<Scalar>& x, const VectorBase<Scalar>& y ) const;
308 
312  void scalarProdsImpl(
313  const MultiVectorBase<Scalar>& X, const MultiVectorBase<Scalar>& Y,
314  const ArrayView<Scalar> &scalarProds ) const;
315 
319  bool hasInCoreView(const Range1D& rng, const EViewType viewType,
320  const EStrideType strideType) const;
321 
323  RCP< const VectorSpaceFactoryBase<Scalar> > smallVecSpcFcty() const;
324 
326  RCP< MultiVectorBase<Scalar> > createMembers(int numMembers) const;
327 
329  RCP< const VectorSpaceBase<Scalar> > clone() const;
330 
332 
335 
339  std::string description() const;
340 
348  void describe(
350  const Teuchos::EVerbosityLevel verbLevel
351  ) const;
352 
354 
355 protected:
356 
357  // ///////////////////////////////////
358  // Protected member functions
359 
360 private:
361 
362  // ///////////////////////////////////
363  // Private types
364 
365  typedef Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaces_t;
366  typedef Array<Ordinal> vecSpacesOffsets_t;
367 
368  // ///////////////////////////////////
369  // Private data members
370 
371  int numBlocks_;
372  RCP<vecSpaces_t> vecSpaces_;
373  RCP<vecSpacesOffsets_t> vecSpacesOffsets_;
374  // cached info
375  Ordinal dim_;
376  bool isInCore_;
377 
378  // ///////////////////////////////////
379  // Private member functions
380 
381  void assertInitialized() const;
382 
383 };
384 
385 
390 template<class Scalar>
391 inline
392 RCP<DefaultProductVectorSpace<Scalar> >
394 {
396 }
397 
398 
403 template<class Scalar>
404 inline
407  const ArrayView<RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
408  )
409 {
410  return Teuchos::rcp(new DefaultProductVectorSpace<Scalar>(vecSpaces));
411 }
412 
413 
419 template<class Scalar>
420 inline
423  const RCP<const VectorSpaceBase<Scalar> > &vecSpace,
424  const int numBlocks
425  )
426 {
427  Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaceBlocks;
428  for ( int i = 0; i < numBlocks; ++i )
429  vecSpaceBlocks.push_back(vecSpace);
430  return productVectorSpace<Scalar>(vecSpaceBlocks());
431 }
432 
433 
434 // /////////////////////////////////
435 // Inline members
436 
437 
438 template<class Scalar>
439 inline const RCP<const VectorSpaceBase<Scalar> >*
441 {
442  return ( dim_ ? &(*vecSpaces_)[0] : NULL );
443 }
444 
445 
446 template<class Scalar>
447 inline const Ordinal*
449 {
450  return ( dim_ ? &(*vecSpacesOffsets_)[0] : NULL );
451 }
452 
453 
454 template<class Scalar>
456 {
457  return vecSpaces_.strong_count() > 1;
458 }
459 
460 
461 template<class Scalar>
462 inline
464 {
466 #ifdef TEUCHOS_DEBUG
467  TEUCHOS_TEST_FOR_EXCEPT( is_null(vecSpaces_) );
468 #endif
469 }
470 
471 
472 } // namespace Thyra
473 
474 
475 #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