Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultMultiVectorProductVectorSpace_def.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_MULTI_VECTOR_PRODUCT_VECTOR_SPACE_DEF_HPP
11 #define THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_SPACE_DEF_HPP
12 
13 
14 #include "Thyra_DefaultMultiVectorProductVectorSpace_decl.hpp"
15 #include "Thyra_DefaultMultiVectorProductVector.hpp"
16 
17 
18 namespace Thyra {
19 
20 
21 // Constructors/initializers/accessors
22 
23 
24 template<class Scalar>
26  : numColumns_(-1)
27 {}
28 
29 
30 template<class Scalar>
32  const Teuchos::RCP<const VectorSpaceBase<Scalar> > &space,
33  const int numColumns
34  )
35 {
36 #ifdef TEUCHOS_DEBUG
38  TEUCHOS_TEST_FOR_EXCEPT(numColumns <= 0);
39 #endif
40  space_ = space;
41  numColumns_ = numColumns;
42  defaultProdVecSpc_ = productVectorSpace(space,numColumns);
43 }
44 
45 
46 template<class Scalar>
48  Teuchos::RCP<const VectorSpaceBase<Scalar> > * /* space */,
49  int * /* numColumns */
50  )
51 {
52  TEUCHOS_TEST_FOR_EXCEPT("ToDo: Implement when needed!");
53 }
54 
55 
56 // Overridden from DefaultMultiVectorProductVectorSpace
57 
58 
59 template<class Scalar>
61 {
62  return numColumns_;
63 }
64 
65 
66 template<class Scalar>
69 {
70  TEUCHOS_TEST_FOR_EXCEPT( k < 0 || numColumns_ < k );
71  return space_;
72 }
73 
74 
75 // Overridden from VectorSpaceBase
76 
77 
78 template<class Scalar>
80 {
81  if (nonnull(space_))
82  return numColumns_ * space_->dim();
83  return -1;
84 }
85 
86 
87 template<class Scalar>
89  const VectorSpaceBase<Scalar>& vecSpc
90  ) const
91 {
92  const DefaultMultiVectorProductVectorSpace<Scalar> *multiVecProdVecSpc
93  = dynamic_cast<const DefaultMultiVectorProductVectorSpace<Scalar>*>(&vecSpc);
94  if ( multiVecProdVecSpc != 0 ) {
95  return (
96  ( numColumns_ == multiVecProdVecSpc->numColumns_ )
97  &&
98  ( space_->isCompatible(*multiVecProdVecSpc->space_) )
99  );
100  }
101  return false;
102 }
103 
104 
105 template<class Scalar>
108 {
109  return multiVectorProductVector<Scalar>(
111  );
112 }
113 
114 
115 template<class Scalar>
117  const VectorBase<Scalar> &x_in,
118  const VectorBase<Scalar> &y_in
119  ) const
120 {
121  return defaultProdVecSpc_->scalarProd(x_in,y_in);
122  // 2007/05/23: rabartl: ToDo: Implement this in a more efficient way using
123  // the block scalar product using a single global reduction!
124 }
125 
126 template<class Scalar>
128  const MultiVectorBase<Scalar> &X_in,
129  const MultiVectorBase<Scalar> &Y_in,
130  const ArrayView<Scalar> &scalarProds_out
131  ) const
132 {
133  defaultProdVecSpc_->scalarProds(X_in, Y_in, scalarProds_out);
134  // 2007/05/23: rabartl: ToDo: Implement this in a more efficient way once
135  // you have a specialized multi-vector implementation.
136 }
137 
138 template<class Scalar>
140  const Range1D& rng_in, const EViewType viewType, const EStrideType strideType
141  ) const
142 {
143  return defaultProdVecSpc_->hasInCoreView(rng_in,viewType,strideType);
144 }
145 
146 template<class Scalar>
149 {
150  if (!is_null(space_))
151  return space_->smallVecSpcFcty();
152  return Teuchos::null;
153 }
154 
155 template<class Scalar>
158 {
160  // 2007/05/23: rabartl: ToDo: Return MultiVectorProductMultiVector object
161  // once MultiVectorProductMultiVector is created when needed!
162 }
163 
164 
165 template<class Scalar>
168 {
169  // Warning! If the client uninitialized this object then changes the
170  // constituent vector spaces then we are in trouble! The client is warned
171  // in documentation!
174  mvpvs->numColumns_ = numColumns_;
175  mvpvs->space_ = space_;
176  mvpvs->defaultProdVecSpc_ = defaultProdVecSpc_;
177  return mvpvs;
178 }
179 
180 
181 // Overridden from Teuchos::Describable
182 
183 
184 template<class Scalar>
186 {
187  std::ostringstream oss;
188  oss
190  << "dim="<<this->dim()
191  << ", numBlocks="<<numColumns_
192  << "}";
193  return oss.str();
194 }
195 
196 
197 template<class Scalar>
199  Teuchos::FancyOStream &out_arg,
200  const Teuchos::EVerbosityLevel verbLevel
201  ) const
202 {
203  using Teuchos::RCP;
204  using Teuchos::FancyOStream;
205  using Teuchos::OSTab;
206  RCP<FancyOStream> out = rcp(&out_arg,false);
207  OSTab tab(out);
208  switch(verbLevel) {
210  case Teuchos::VERB_LOW:
211  *out << this->description() << std::endl;
212  break;
214  case Teuchos::VERB_HIGH:
216  {
217  *out
218  << this->description() << std::endl;
219  if (nonnull(space_)) {
220  OSTab tab2(out);
221  *out
222  << "Constituent vector space 'space' is the same for all spaces V[0],V[1],,,V[numBlocks-1]:\n";
223  tab.incrTab();
224  *out << "space = " << Teuchos::describe(*space_,verbLevel);
225  }
226  break;
227  }
228  default:
229  TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
230  }
231 }
232 
233 
234 } // namespace Thyra
235 
236 
237 #endif // THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_SPACE_DEF_HPP
void uninitialize(RCP< const VectorSpaceBase< Scalar > > *space=0, int *numColumns=0)
Uninitialize.
RCP< const VectorSpaceBase< Scalar > > clone() const
Clones the object as promised.
bool is_null(const boost::shared_ptr< T > &p)
basic_OSTab< char > OSTab
Scalar scalarProd(const VectorBase< Scalar > &x, const VectorBase< Scalar > &y) const
Returns the sum of the scalar products of the constituent vectors.
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space, const int numColumns)
Initialize with a list of constituent vector spaces.
basic_FancyOStream< char > FancyOStream
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.
bool isCompatible(const VectorSpaceBase< Scalar > &vecSpc) const
RCP< const VectorSpaceFactoryBase< Scalar > > smallVecSpcFcty() const
Returns getBlock(0)-&gt;smallVecSpcFcty().
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.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints the details about the constituent vector 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.
bool hasInCoreView(const Range1D &rng, const EViewType viewType, const EStrideType strideType) const
Returns true if all of the constituent vector spaces return true.
virtual std::string description() const
Abstract interface for finite-dimensional dense vectors.
Standard concrete implementation of a product vector space that creates product vectors fromed implic...
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
RCP< VectorBase< Scalar > > createMember() const
Returns a DefaultMultiVectorProductVector object.
bool nonnull(const boost::shared_ptr< T > &p)
RCP< const VectorSpaceBase< Scalar > > getBlock(const int k) const
EStrideType
Determine if data is unit stride or non-unit stride.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
Returns a DefaultColumnwiseMultiVector object.
std::string description() const
Prints just the name DefaultMultiVectorProductVectorSpace along with the overall dimension and the nu...