Thyra  Version of the Day
Thyra_DefaultMultiVectorProductVector_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_HPP
43 #define THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_HPP
44 
45 
46 #include "Thyra_DefaultMultiVectorProductVector_decl.hpp"
47 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
48 #include "Thyra_AssertOp.hpp"
49 #include "Teuchos_Assert.hpp"
50 
51 
52 namespace Thyra {
53 
54 
55 // Constructors/initializers/accessors
56 
57 
58 template <class Scalar>
60 {
61  uninitialize();
62 }
63 
64 
65 template <class Scalar>
67  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace_in,
68  const RCP<MultiVectorBase<Scalar> > &multiVec
69  )
70 {
71 #ifdef TEUCHOS_DEBUG
72  TEUCHOS_TEST_FOR_EXCEPT(is_null(productSpace_in));
73  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVec));
75  "DefaultMultiVectorProductVector<Scalar>::initialize(productSpace,multiVec)",
76  *multiVec->range(), *productSpace_in->getBlock(0)
77  );
78  TEUCHOS_ASSERT_EQUALITY( multiVec->domain()->dim(), productSpace_in->numBlocks());
79 #endif
80 
81  numBlocks_ = productSpace_in->numBlocks();
82 
83  productSpace_ = productSpace_in;
84 
85  multiVec_ = multiVec;
86 
87 }
88 
89 
90 template <class Scalar>
92  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace_in,
93  const RCP<const MultiVectorBase<Scalar> > &multiVec
94  )
95 {
96 #ifdef TEUCHOS_DEBUG
97  TEUCHOS_TEST_FOR_EXCEPT(is_null(productSpace_in));
98  TEUCHOS_TEST_FOR_EXCEPT(is_null(multiVec));
100  "DefaultMultiVectorProductVector<Scalar>::initialize(productSpace_in,multiVec)",
101  *multiVec->range(), *productSpace_in->getBlock(0)
102  );
103  TEUCHOS_ASSERT_EQUALITY( multiVec->domain()->dim(), productSpace_in->numBlocks() );
104 #endif
105 
106  numBlocks_ = productSpace_in->numBlocks();
107 
108  productSpace_ = productSpace_in;
109 
110  multiVec_ = multiVec;
111 
112 }
113 
114 
115 template <class Scalar>
116 RCP<MultiVectorBase<Scalar> >
118 {
119  return multiVec_.getNonconstObj();
120 }
121 
122 
123 template <class Scalar>
124 RCP<const MultiVectorBase<Scalar> >
126 {
127  return multiVec_.getConstObj();
128 }
129 
130 
131 template <class Scalar>
133 {
134  numBlocks_ = 0;
135  productSpace_ = Teuchos::null;
136  multiVec_.uninitialize();
137 }
138 
139 
140 // Overridden from Teuchos::Describable
141 
142 
143 template<class Scalar>
145 {
146  std::ostringstream oss;
147  oss
148  << Teuchos::Describable::description()
149  << "{"
150  << "dim="<<this->space()->dim()
151  << ",numColumns = "<<numBlocks_
152  << "}";
153  return oss.str();
154 }
155 
156 template<class Scalar>
158  Teuchos::FancyOStream &out_arg,
159  const Teuchos::EVerbosityLevel verbLevel
160  ) const
161 {
162  using Teuchos::OSTab;
163  using Teuchos::describe;
164  RCP<FancyOStream> out = rcp(&out_arg,false);
165  OSTab tab(out);
166  switch(verbLevel) {
167  case Teuchos::VERB_DEFAULT:
168  case Teuchos::VERB_LOW:
169  *out << this->description() << std::endl;
170  break;
171  case Teuchos::VERB_MEDIUM:
172  case Teuchos::VERB_HIGH:
173  case Teuchos::VERB_EXTREME:
174  {
175  *out
176  << Teuchos::Describable::description() << "{"
177  << "dim=" << this->space()->dim()
178  << "}\n";
179  OSTab tab2(out);
180  *out << "multiVec = " << Teuchos::describe(*multiVec_.getConstObj(),verbLevel);
181  break;
182  }
183  default:
184  TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
185  }
186 }
187 
188 
189 // Overridden from ProductVectorBase
190 
191 
192 template <class Scalar>
193 RCP<VectorBase<Scalar> >
195 {
196 #ifdef TEUCHOS_DEBUG
197  TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ );
198 #endif
199  return multiVec_.getNonconstObj()->col(k);
200 }
201 
202 
203 template <class Scalar>
204 RCP<const VectorBase<Scalar> >
206 {
207 #ifdef TEUCHOS_DEBUG
208  TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ );
209 #endif
210  return multiVec_.getConstObj()->col(k);
211 }
212 
213 
214 // Overridden from ProductMultiVectorBase
215 
216 
217 template <class Scalar>
218 RCP<const ProductVectorSpaceBase<Scalar> >
220 {
221  return productSpace_;
222 }
223 
224 
225 template <class Scalar>
227 {
228 #ifdef TEUCHOS_DEBUG
229  TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ );
230 #endif
231  return multiVec_.isConst();
232 }
233 
234 
235 template <class Scalar>
236 RCP<MultiVectorBase<Scalar> >
238 {
239  return getNonconstVectorBlock(k);
240 }
241 
242 
243 template <class Scalar>
244 RCP<const MultiVectorBase<Scalar> >
246 {
247  return getVectorBlock(k);
248 }
249 
250 
251 // Overridden public functions from VectorBase
252 
253 
254 template <class Scalar>
255 RCP< const VectorSpaceBase<Scalar> >
257 {
258  return productSpace_;
259 }
260 
261 
262 // protected
263 
264 
265 // Overridden protected functions from VectorBase
266 
267 
268 template <class Scalar>
270  const RTOpPack::RTOpT<Scalar> &op,
271  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
272  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
273  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
274  const Ordinal global_offset
275  ) const
276 {
277  this->getDefaultProductVector()->applyOp(
278  op, vecs, targ_vecs, reduct_obj, global_offset );
279 }
280 
281 
282 template <class Scalar>
284  const Range1D& rng_in, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
285  ) const
286 {
287  this->getDefaultProductVector()->acquireDetachedView(rng_in,sub_vec);
288 }
289 
290 
291 template <class Scalar>
294  ) const
295 {
296  this->getDefaultProductVector()->releaseDetachedView(sub_vec);
297 }
298 
299 
300 template <class Scalar>
302  const Range1D& rng_in, RTOpPack::SubVectorView<Scalar>* sub_vec
303  )
304 {
305  TEUCHOS_TEST_FOR_EXCEPT("ToDo: Implement DefaultMultiVectorProductVector<Scalar>::acquireNonconstDetachedVectorViewImpl(...)!");
306 }
307 
308 
309 template <class Scalar>
312  )
313 {
314  TEUCHOS_TEST_FOR_EXCEPT("ToDo: Implement DefaultMultiVectorProductVector<Scalar>::commitNonconstDetachedVectorViewImpl(...)!");
315 }
316 
317 
318 template <class Scalar>
321  )
322 {
323  TEUCHOS_TEST_FOR_EXCEPT("ToDo: Implement DefaultMultiVectorProductVector<Scalar>::setSubVector(...)!");
324 }
325 
326 
327 // Overridden protected functions from VectorBase
328 
329 
330 template <class Scalar>
332 {
333  multiVec_.getNonconstObj()->assign(alpha);
334 }
335 
336 
337 // private
338 
339 
340 template <class Scalar>
341 RCP<const DefaultProductVector<Scalar> >
343 {
344 
345  // This function exists since in general we can not create views of a column
346  // vectors and expect the changes to be mirrored in the mulit-vector
347  // automatically. Later, we might be able to change this once we have a
348  // Thyra::MultiVectorBase::hasDirectColumnVectorView() function and it
349  // returns true. Until then, this is the safe way to do this ...
350 
351  Array<RCP<const VectorBase<Scalar> > > vecArray;
352  for ( int k = 0; k < numBlocks_; ++k) {
353  vecArray.push_back(multiVec_.getConstObj()->col(k));
354  }
355 
356  return Thyra::defaultProductVector<Scalar>(
357  productSpace_->getDefaultProductVectorSpace(),
358  vecArray()
359  );
360 
361 }
362 
363 
364 } // namespace Thyra
365 
366 
367 #endif // THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_HPP
void releaseDetachedVectorViewImpl(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
#define THYRA_ASSERT_VEC_SPACES(FUNC_NAME, VS1, VS2)
This is a very useful macro that should be used to validate that two vector spaces are compatible...
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Concrete implementation of a product vector which is really composed out of the columns of a multi-ve...
RCP< const VectorSpaceBase< Scalar > > space() const
void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)
RCP< const MultiVectorBase< Scalar > > getMultiVector() const
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
Abstract interface for finite-dimensional dense vectors.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Standard concrete implementation of a product vector space that creates product vectors fromed implic...
void initialize(const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &productSpace, const RCP< MultiVectorBase< Scalar > > &multiVec)
Initialize with a non-const multi-vector.
void applyOpImpl(const RTOpPack::RTOpT< Scalar > &op, const ArrayView< const Ptr< const VectorBase< Scalar > > > &vecs, const ArrayView< const Ptr< VectorBase< Scalar > > > &targ_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal global_offset) const
RCP< const ProductVectorSpaceBase< Scalar > > productSpace() const
RCP< MultiVectorBase< Scalar > > getNonconstMultiVectorBlock(const int k)
RCP< const MultiVectorBase< Scalar > > getMultiVectorBlock(const int k) const
RCP< VectorBase< Scalar > > getNonconstVectorBlock(const int k)
RCP< const VectorBase< Scalar > > getVectorBlock(const int k) const
Teuchos::Range1D Range1D
void setSubVectorImpl(const RTOpPack::SparseSubVectorT< Scalar > &sub_vec)