Thyra  Version of the Day
Thyra_DefaultProductVector_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_DECL_HPP
43 #define THYRA_DEFAULT_PRODUCT_VECTOR_DECL_HPP
44 
45 #include "Thyra_ProductVectorBase.hpp"
46 #include "Thyra_VectorDefaultBase.hpp"
47 #include "Teuchos_ConstNonconstObjectContainer.hpp"
48 #include "Teuchos_as.hpp"
49 
50 
51 namespace Thyra {
52 
53 
55 template <class Scalar> class DefaultProductVectorSpace;
56 
57 
71 template<class Scalar>
73  : virtual public ProductVectorBase<Scalar>,
74  virtual protected VectorDefaultBase<Scalar>
75 {
76 public:
77 
80 
83 
87  );
88 
93  void initialize(
95  );
96 
101  void initialize(
103  const ArrayView<const RCP<VectorBase<Scalar> > > &vecs
104  );
105 
110  void initialize(
112  const ArrayView<const RCP<const VectorBase<Scalar> > > &vecs
113  );
114 
119  void uninitialize();
120 
122 
125 
127  std::string description() const;
128 
130  void describe(
131  Teuchos::FancyOStream &out,
132  const Teuchos::EVerbosityLevel verbLevel
133  ) const;
134 
136 
139 
141  void setBlock(int i, const RCP<const VectorBase<Scalar> >& b);
143  void setNonconstBlock(int i, const RCP<VectorBase<Scalar> >& b);
145 
148 
150  RCP<VectorBase<Scalar> > getNonconstVectorBlock(const int k);
152  RCP<const VectorBase<Scalar> > getVectorBlock(const int k) const;
153 
155 
158 
160  RCP<const ProductVectorSpaceBase<Scalar> > productSpace() const;
162  bool blockIsConst(const int k) const;
164  RCP<MultiVectorBase<Scalar> >
165  getNonconstMultiVectorBlock(const int k);
167  RCP<const MultiVectorBase<Scalar> >
168  getMultiVectorBlock(const int k) const;
169 
171 
174 
176  RCP< const VectorSpaceBase<Scalar> > space() const;
177 
179 
180 protected:
181 
184 
186  void applyOpImpl(
187  const RTOpPack::RTOpT<Scalar> &op,
188  const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
189  const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
190  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
191  const Ordinal global_offset
192  ) const;
195  const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
196  ) const;
200  ) const;
203  const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
204  );
208  );
210  void setSubVectorImpl(
212  );
213 
215 
218 
220  void assignImpl(Scalar alpha);
221 
222  //#}
223 
224 public:
225 
226 private:
227 
228  // //////////////////////////////
229  // Private types
230 
231  typedef Teuchos::ConstNonconstObjectContainer<VectorBase<Scalar> > CNVC;
232 
233  // //////////////////////////////
234  // Private data members
235 
236  RCP<const DefaultProductVectorSpace<Scalar> > productSpace_;
237  Array<CNVC> vecs_;
238  // cache
239  int numBlocks_;
240 
241 };
242 
243 
248 template<class Scalar>
249 inline
250 RCP<DefaultProductVector<Scalar> >
252 {
253  return Teuchos::rcp(new DefaultProductVector<Scalar>);
254 }
255 
256 
261 template<class Scalar>
262 inline
263 RCP<DefaultProductVector<Scalar> >
265  const RCP<const DefaultProductVectorSpace<Scalar> > &productSpace
266  )
267 {
268  return Teuchos::rcp(
269  new DefaultProductVector<Scalar>(productSpace)
270  );
271 }
272 
273 
278 template<class Scalar>
279 RCP<DefaultProductVector<Scalar> >
281  const RCP<const DefaultProductVectorSpace<Scalar> > &productSpace,
282  const ArrayView<const RCP<VectorBase<Scalar> > > &vecs
283  )
284 {
285  RCP<DefaultProductVector<Scalar> > pv = defaultProductVector<Scalar>();
286  pv->initialize(productSpace, vecs);
287  return pv;
288 }
289 
290 
295 template<class Scalar>
296 RCP<DefaultProductVector<Scalar> >
298  const RCP<const DefaultProductVectorSpace<Scalar> > &productSpace,
299  const ArrayView<const RCP<const VectorBase<Scalar> > > &vecs
300  )
301 {
302  RCP<DefaultProductVector<Scalar> > pv = defaultProductVector<Scalar>();
303  pv->initialize(productSpace, vecs);
304  return pv;
305 }
306 
307 
313 template<class Scalar>
314 RCP<ProductVectorBase<Scalar> >
315 castOrCreateNonconstProductVectorBase(const RCP<VectorBase<Scalar> > v);
316 
317 
323 template<class Scalar>
324 RCP<const ProductVectorBase<Scalar> >
325 castOrCreateProductVectorBase(const RCP<const VectorBase<Scalar> > v);
326 
327 
328 } // namespace Thyra
329 
330 
331 #endif // THYRA_DEFAULT_PRODUCT_VECTOR_DECL_HPP
void setSubVectorImpl(const RTOpPack::SparseSubVectorT< Scalar > &sub_vec)
void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)
Base interface for product vectors.
RCP< DefaultProductVector< Scalar > > defaultProductVector(const RCP< const DefaultProductVectorSpace< Scalar > > &productSpace)
Nonmember constructor.
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 MultiVectorBase< Scalar > > getMultiVectorBlock(const int k) const
RCP< DefaultProductVector< Scalar > > defaultProductVector()
Nonmember constructor.
void setNonconstBlock(int i, const RCP< VectorBase< Scalar > > &b)
Convenient node subclass for concrete VectorBase subclasses that relies on a default MultiVectorBase ...
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
RCP< const ProductVectorSpaceBase< Scalar > > productSpace() const
DefaultProductVector()
Construct to uninitialized.
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
Abstract interface for finite-dimensional dense vectors.
RCP< const VectorBase< Scalar > > getVectorBlock(const int k) const
void releaseDetachedVectorViewImpl(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Concrete implementation of a product vector.
RCP< VectorBase< Scalar > > getNonconstVectorBlock(const int k)
RCP< const VectorSpaceBase< Scalar > > space() const
RCP< MultiVectorBase< Scalar > > getNonconstMultiVectorBlock(const int k)
RCP< DefaultProductVector< Scalar > > defaultProductVector(const RCP< const DefaultProductVectorSpace< Scalar > > &productSpace, const ArrayView< const RCP< const VectorBase< Scalar > > > &vecs)
Nonmember constructor.
RCP< DefaultProductVector< Scalar > > defaultProductVector(const RCP< const DefaultProductVectorSpace< Scalar > > &productSpace, const ArrayView< const RCP< VectorBase< Scalar > > > &vecs)
Nonmember constructor.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void setBlock(int i, const RCP< const VectorBase< Scalar > > &b)
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
void initialize(const RCP< const DefaultProductVectorSpace< Scalar > > &productSpace)
Initialize.
Teuchos::Range1D Range1D