Thyra  Version of the Day
Thyra_DefaultMultiVectorProductVector_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_MULTI_VECTOR_PRODUCT_VECTOR_DECL_HPP
43 #define THYRA_MULTI_VECTOR_PRODUCT_VECTOR_DECL_HPP
44 
45 
46 #include "Thyra_ProductVectorBase.hpp" // Interface
47 #include "Thyra_VectorDefaultBase.hpp" // Implementation
48 #include "Thyra_DefaultProductVector.hpp"
49 #include "Teuchos_ConstNonconstObjectContainer.hpp"
50 
51 
52 namespace Thyra {
53 
54 
55 template<class Scalar> class DefaultMultiVectorProductVectorSpace;
56 
57 
69 template<class Scalar>
71  : virtual public ProductVectorBase<Scalar>,
72  virtual protected VectorDefaultBase<Scalar>
73 {
74 public:
75 
78 
81 
83  void initialize(
85  const RCP<MultiVectorBase<Scalar> > &multiVec
86  );
87 
89  void initialize(
91  const RCP<const MultiVectorBase<Scalar> > &multiVec
92  );
93 
94  // ToDo: Add const version of above function also when needed!
95 
97  RCP<MultiVectorBase<Scalar> >
99 
101  RCP<const MultiVectorBase<Scalar> >
102  getMultiVector() const;
103 
105  void uninitialize();
106 
108 
111 
113  std::string description() const;
114 
116  void describe(
117  Teuchos::FancyOStream &out,
118  const Teuchos::EVerbosityLevel verbLevel
119  ) const;
120 
122 
125 
127  RCP<VectorBase<Scalar> >
128  getNonconstVectorBlock(const int k);
130  RCP<const VectorBase<Scalar> >
131  getVectorBlock(const int k) const;
132 
134 
137 
139  RCP<const ProductVectorSpaceBase<Scalar> >
140  productSpace() const;
142  bool blockIsConst(const int k) const;
144  RCP<MultiVectorBase<Scalar> >
145  getNonconstMultiVectorBlock(const int k);
147  RCP<const MultiVectorBase<Scalar> >
148  getMultiVectorBlock(const int k) const;
149 
151 
154 
156  RCP< const VectorSpaceBase<Scalar> > space() const;
157 
159 
160 protected:
161 
164 
166  void applyOpImpl(
167  const RTOpPack::RTOpT<Scalar> &op,
168  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
169  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
170  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
171  const Ordinal global_offset
172  ) const;
175  const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
176  ) const;
180  ) const;
183  const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
184  );
188  );
190  void setSubVectorImpl(
192  );
193 
195 
198 
200  void assignImpl(Scalar alpha);
201 
203 
204 private:
205 
206  // //////////////////////////////
207  // Private types
208 
209  typedef Teuchos::ConstNonconstObjectContainer<MultiVectorBase<Scalar> > CNMVC;
210 
211  // //////////////////////////////
212  // Private data members
213 
214  int numBlocks_;
215  RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > productSpace_;
216  CNMVC multiVec_;
217 
218  // //////////////////////////////
219  // Private member functions
220 
221  RCP<const DefaultProductVector<Scalar> >
222  getDefaultProductVector() const;
223 
224 };
225 
226 
232 template<class Scalar>
233 inline
234 RCP<DefaultMultiVectorProductVector<Scalar> >
236  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace,
237  const RCP<MultiVectorBase<Scalar> > &multiVec
238  )
239 {
240  RCP<DefaultMultiVectorProductVector<Scalar> > multiVecProdVec
241  = Teuchos::rcp(new DefaultMultiVectorProductVector<Scalar>());
242  multiVecProdVec->initialize(productSpace,multiVec);
243  return multiVecProdVec;
244 }
245 
246 
252 template<class Scalar>
253 inline
254 RCP<const DefaultMultiVectorProductVector<Scalar> >
256  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace,
257  const RCP<const MultiVectorBase<Scalar> > &multiVec
258  )
259 {
260  RCP<DefaultMultiVectorProductVector<Scalar> > multiVecProdVec
261  = Teuchos::rcp(new DefaultMultiVectorProductVector<Scalar>());
262  multiVecProdVec->initialize(productSpace,multiVec);
263  return multiVecProdVec;
264 }
265 
266 
267 // ToDo: Add non-const and const versions of the nonmember constructor
268 // functions to wrap already created multi-vectors once needed!
269 
270 
276 template<class Scalar>
277 inline
278 RCP<DefaultMultiVectorProductVector<Scalar> >
280  const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace
281  )
282 {
283 #ifdef TEUCHOS_DEBUG
284  TEUCHOS_TEST_FOR_EXCEPT(is_null(productSpace));
285 #endif
286  return multiVectorProductVector(
287  productSpace,
288  createMembers(productSpace->getBlock(0),productSpace->numBlocks())
289  );
290 }
291 
292 
293 } // namespace Thyra
294 
295 
296 #endif // THYRA_MULTI_VECTOR_PRODUCT_VECTOR_DECL_HPP
void releaseDetachedVectorViewImpl(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Base interface for product vectors.
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
Convenient node subclass for concrete VectorBase subclasses that relies on a default MultiVectorBase ...
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
RCP< DefaultMultiVectorProductVector< Scalar > > multiVectorProductVector(const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &productSpace)
Nonmember constructor that creates a new uninitialized product vector represented underneath as a mul...
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 DefaultMultiVectorProductVector< Scalar > > multiVectorProductVector(const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &productSpace, const RCP< const MultiVectorBase< Scalar > > &multiVec)
Nonmember constructor that just wraps an existing const MultiVector as a const product vector...
RCP< const ProductVectorSpaceBase< Scalar > > productSpace() const
RCP< MultiVectorBase< Scalar > > getNonconstMultiVectorBlock(const int k)
RCP< DefaultMultiVectorProductVector< Scalar > > multiVectorProductVector(const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &productSpace, const RCP< MultiVectorBase< Scalar > > &multiVec)
Nonmember constructor that just wraps an existing non-const MultiVector as a non-const product vector...
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)