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 //
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_MULTI_VECTOR_PRODUCT_VECTOR_SPACE_DEF_HPP
43 #define THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_SPACE_DEF_HPP
44 
45 
46 #include "Thyra_DefaultMultiVectorProductVectorSpace_decl.hpp"
47 #include "Thyra_DefaultMultiVectorProductVector.hpp"
48 
49 
50 namespace Thyra {
51 
52 
53 // Constructors/initializers/accessors
54 
55 
56 template<class Scalar>
58  : numColumns_(-1)
59 {}
60 
61 
62 template<class Scalar>
64  const Teuchos::RCP<const VectorSpaceBase<Scalar> > &space,
65  const int numColumns
66  )
67 {
68 #ifdef TEUCHOS_DEBUG
70  TEUCHOS_TEST_FOR_EXCEPT(numColumns <= 0);
71 #endif
72  space_ = space;
73  numColumns_ = numColumns;
74  defaultProdVecSpc_ = productVectorSpace(space,numColumns);
75 }
76 
77 
78 template<class Scalar>
80  Teuchos::RCP<const VectorSpaceBase<Scalar> > * /* space */,
81  int * /* numColumns */
82  )
83 {
84  TEUCHOS_TEST_FOR_EXCEPT("ToDo: Implement when needed!");
85 }
86 
87 
88 // Overridden from DefaultMultiVectorProductVectorSpace
89 
90 
91 template<class Scalar>
93 {
94  return numColumns_;
95 }
96 
97 
98 template<class Scalar>
101 {
102  TEUCHOS_TEST_FOR_EXCEPT( k < 0 || numColumns_ < k );
103  return space_;
104 }
105 
106 
107 // Overridden from VectorSpaceBase
108 
109 
110 template<class Scalar>
112 {
113  if (nonnull(space_))
114  return numColumns_ * space_->dim();
115  return -1;
116 }
117 
118 
119 template<class Scalar>
121  const VectorSpaceBase<Scalar>& vecSpc
122  ) const
123 {
124  const DefaultMultiVectorProductVectorSpace<Scalar> *multiVecProdVecSpc
125  = dynamic_cast<const DefaultMultiVectorProductVectorSpace<Scalar>*>(&vecSpc);
126  if ( multiVecProdVecSpc != 0 ) {
127  return (
128  ( numColumns_ == multiVecProdVecSpc->numColumns_ )
129  &&
130  ( space_->isCompatible(*multiVecProdVecSpc->space_) )
131  );
132  }
133  return false;
134 }
135 
136 
137 template<class Scalar>
140 {
141  return multiVectorProductVector<Scalar>(
143  );
144 }
145 
146 
147 template<class Scalar>
149  const VectorBase<Scalar> &x_in,
150  const VectorBase<Scalar> &y_in
151  ) const
152 {
153  return defaultProdVecSpc_->scalarProd(x_in,y_in);
154  // 2007/05/23: rabartl: ToDo: Implement this in a more efficient way using
155  // the block scalar product using a single global reduction!
156 }
157 
158 template<class Scalar>
160  const MultiVectorBase<Scalar> &X_in,
161  const MultiVectorBase<Scalar> &Y_in,
162  const ArrayView<Scalar> &scalarProds_out
163  ) const
164 {
165  defaultProdVecSpc_->scalarProds(X_in, Y_in, scalarProds_out);
166  // 2007/05/23: rabartl: ToDo: Implement this in a more efficient way once
167  // you have a specialized multi-vector implementation.
168 }
169 
170 template<class Scalar>
172  const Range1D& rng_in, const EViewType viewType, const EStrideType strideType
173  ) const
174 {
175  return defaultProdVecSpc_->hasInCoreView(rng_in,viewType,strideType);
176 }
177 
178 template<class Scalar>
181 {
182  if (!is_null(space_))
183  return space_->smallVecSpcFcty();
184  return Teuchos::null;
185 }
186 
187 template<class Scalar>
190 {
192  // 2007/05/23: rabartl: ToDo: Return MultiVectorProductMultiVector object
193  // once MultiVectorProductMultiVector is created when needed!
194 }
195 
196 
197 template<class Scalar>
200 {
201  // Warning! If the client uninitialized this object then changes the
202  // constituent vector spaces then we are in trouble! The client is warned
203  // in documentation!
206  mvpvs->numColumns_ = numColumns_;
207  mvpvs->space_ = space_;
208  mvpvs->defaultProdVecSpc_ = defaultProdVecSpc_;
209  return mvpvs;
210 }
211 
212 
213 // Overridden from Teuchos::Describable
214 
215 
216 template<class Scalar>
218 {
219  std::ostringstream oss;
220  oss
222  << "dim="<<this->dim()
223  << ", numBlocks="<<numColumns_
224  << "}";
225  return oss.str();
226 }
227 
228 
229 template<class Scalar>
231  Teuchos::FancyOStream &out_arg,
232  const Teuchos::EVerbosityLevel verbLevel
233  ) const
234 {
235  using Teuchos::RCP;
236  using Teuchos::FancyOStream;
237  using Teuchos::OSTab;
238  RCP<FancyOStream> out = rcp(&out_arg,false);
239  OSTab tab(out);
240  switch(verbLevel) {
242  case Teuchos::VERB_LOW:
243  *out << this->description() << std::endl;
244  break;
246  case Teuchos::VERB_HIGH:
248  {
249  *out
250  << this->description() << std::endl;
251  if (nonnull(space_)) {
252  OSTab tab2(out);
253  *out
254  << "Constituent vector space 'space' is the same for all spaces V[0],V[1],,,V[numBlocks-1]:\n";
255  tab.incrTab();
256  *out << "space = " << Teuchos::describe(*space_,verbLevel);
257  }
258  break;
259  }
260  default:
261  TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
262  }
263 }
264 
265 
266 } // namespace Thyra
267 
268 
269 #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...