Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DetachedMultiVectorView.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 #include "Thyra_MultiVectorBase.hpp"
43 #include "Thyra_AssertOp.hpp"
44 
45 #ifndef THYRA_EXPLICIT_MULTI_VECTOR_VIEW_HPP
46 #define THYRA_EXPLICIT_MULTI_VECTOR_VIEW_HPP
47 
48 namespace Thyra {
49 
50 
56 template<class Scalar>
58 public:
61  const RCP<const MultiVectorBase<Scalar> > &mv,
62  const Range1D &rowRng = Range1D(), const Range1D &colRng = Range1D()
63  )
64  : mv_(mv) { mv_->acquireDetachedView(rowRng, colRng, &smv_); }
67  const MultiVectorBase<Scalar>& mv,
68  const Range1D &rowRng = Range1D(), const Range1D &colRng = Range1D()
69  )
70  : mv_(rcpFromRef(mv)) { mv_->acquireDetachedView(rowRng, colRng, &smv_); }
72  ~ConstDetachedMultiVectorView() { mv_->releaseDetachedView(&smv_); }
74  const RTOpPack::ConstSubMultiVectorView<Scalar>& smv() const { return smv_; }
76  Ordinal globalOffset() const { return smv_.globalOffset(); }
78  Ordinal subDim() const { return smv_.subDim(); }
80  Ordinal colOffset() const { return smv_.colOffset(); }
82  Ordinal numSubCols() const { return smv_.numSubCols(); }
84  const Scalar* values() const { return smv_.values().get(); }
86  Ordinal leadingDim() const { return smv_.leadingDim(); }
90  const Scalar& operator()(Ordinal i, Ordinal j) const { return smv_(i,j); }
91 private:
94  // Not defined and not to be called
99 };
100 
101 
107 template<class Scalar>
109 public:
112  const RCP<MultiVectorBase<Scalar> >& mv,
113  const Range1D &rowRng = Range1D(), const Range1D &colRng = Range1D()
114  )
115  : mv_(mv) { mv_->acquireDetachedView(rowRng, colRng, &smv_); }
119  const Range1D &rowRng = Range1D(), const Range1D &colRng = Range1D()
120  )
121  : mv_(rcpFromRef(mv)) { mv_->acquireDetachedView(rowRng,colRng,&smv_); }
123  ~DetachedMultiVectorView() { mv_->commitDetachedView(&smv_); }
125  const RTOpPack::SubMultiVectorView<Scalar>& smv() const { return smv_; }
127  Ordinal globalOffset() const { return smv_.globalOffset(); }
129  Ordinal subDim() const { return smv_.subDim(); }
131  Ordinal colOffset() const { return smv_.colOffset(); }
133  Ordinal numSubCols() const { return smv_.numSubCols(); }
135  Scalar* values() const { return smv_.values().get(); }
137  Ordinal leadingDim() const { return smv_.leadingDim(); }
141  Scalar& operator()(Ordinal i, Ordinal j) { return smv_(i,j); }
142 private:
145  // Not defined and not to be called
150 };
151 
152 
157 template<class Scalar>
159  const MultiVectorBase<Scalar>& mvIn, MultiVectorBase<Scalar>* mvTransOut
160  )
161 {
163 #ifdef TEUCHOS_DEBUG
164  TEUCHOS_TEST_FOR_EXCEPT(0==mvTransOut);
165  THYRA_ASSERT_VEC_SPACES("doExplicitMultiVectorAdjoint(...)",
166  *mvIn.domain(), *mvTransOut->range()
167  );
168  THYRA_ASSERT_VEC_SPACES("doExplicitMultiVectorAdjoint(...)",
169  *mvIn.range(), *mvTransOut->domain()
170  );
171 #endif
173  DetachedMultiVectorView<Scalar> dMvTransOut(*mvTransOut);
174  const int m = dMvIn.subDim();
175  const int n = dMvIn.numSubCols();
176  for ( int j = 0; j < n; ++j ) {
177  for ( int i = 0; i < m; ++i ) {
178  dMvTransOut(j,i) = ST::conjugate(dMvIn(i,j));
179  }
180  }
181 }
182 
183 
184 } // namespace Thyra
185 
186 
187 #endif // THYRA_EXPLICIT_MULTI_VECTOR_VIEW_HPP
const Scalar & operator()(Ordinal i, Ordinal j) 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...
Create an explicit non-mutable (const) view of a MultiVectorBase object.
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
const RTOpPack::ConstSubMultiVectorView< Scalar > & smv() const
Create an explicit mutable (non-const) view of a MultiVectorBase object.
ConstDetachedMultiVectorView(const MultiVectorBase< Scalar > &mv, const Range1D &rowRng=Range1D(), const Range1D &colRng=Range1D())
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
const RTOpPack::SubMultiVectorView< Scalar > & smv() const
void doExplicitMultiVectorAdjoint(const MultiVectorBase< Scalar > &mvIn, MultiVectorBase< Scalar > *mvTransOut)
Do an explicit multi-vector adjoint.
DetachedMultiVectorView(MultiVectorBase< Scalar > &mv, const Range1D &rowRng=Range1D(), const Range1D &colRng=Range1D())
ConstDetachedMultiVectorView(const RCP< const MultiVectorBase< Scalar > > &mv, const Range1D &rowRng=Range1D(), const Range1D &colRng=Range1D())
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
DetachedMultiVectorView(const RCP< MultiVectorBase< Scalar > > &mv, const Range1D &rowRng=Range1D(), const Range1D &colRng=Range1D())
Scalar & operator()(Ordinal i, Ordinal j)
Teuchos::Range1D Range1D