Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_DetachedMultiVectorView.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include "Thyra_MultiVectorBase.hpp"
00030 #include "Thyra_AssertOp.hpp"
00031 
00032 #ifndef THYRA_EXPLICIT_MULTI_VECTOR_VIEW_HPP
00033 #define THYRA_EXPLICIT_MULTI_VECTOR_VIEW_HPP
00034 
00035 namespace Thyra {
00036 
00041 template<class Scalar>
00042 class ConstDetachedMultiVectorView {
00043 public:
00045   ConstDetachedMultiVectorView(
00046     const MultiVectorBase<Scalar>& mv, const Range1D &rowRng = Range1D(), const Range1D &colRng = Range1D()
00047     )
00048     : mv_(mv) { mv_.acquireDetachedView(rowRng,colRng,&smv_); }
00050   ~ConstDetachedMultiVectorView() { mv_.releaseDetachedView(&smv_); }
00052   const RTOpPack::ConstSubMultiVectorView<Scalar>& smv() const { return smv_; }
00054   Teuchos_Index globalOffset() const { return smv_.globalOffset(); }
00056   Teuchos_Index subDim() const { return smv_.subDim(); }
00058   Teuchos_Index colOffset() const { return smv_.colOffset(); }
00060   Teuchos_Index numSubCols() const { return smv_.numSubCols(); }
00062   const Scalar* values() const { return smv_.values().get(); }
00064   Teuchos_Index leadingDim() const { return smv_.leadingDim(); }
00066   const Scalar& operator()(Teuchos_Index i,Teuchos_Index j) const { return smv_(i,j); }
00067 private:
00068   const MultiVectorBase<Scalar> &mv_;
00069   RTOpPack::ConstSubMultiVectorView<Scalar> smv_;
00070   // Not defined and not to be called
00071   ConstDetachedMultiVectorView();
00072   ConstDetachedMultiVectorView(const ConstDetachedMultiVectorView<Scalar>&);
00073   ConstDetachedMultiVectorView<Scalar>& operator==(const ConstDetachedMultiVectorView<Scalar>&);
00074 };
00075  
00080 template<class Scalar>
00081 class DetachedMultiVectorView {
00082 public:
00084   DetachedMultiVectorView(
00085     MultiVectorBase<Scalar>& mv, const Range1D &rowRng = Range1D(), const Range1D &colRng = Range1D()
00086     )
00087     : mv_(mv) { mv_.acquireDetachedView(rowRng,colRng,&smv_); }
00089   ~DetachedMultiVectorView() { mv_.commitDetachedView(&smv_); }
00091   const RTOpPack::SubMultiVectorView<Scalar>& smv() const { return smv_; }
00093   Teuchos_Index globalOffset() const { return smv_.globalOffset(); }
00095   Teuchos_Index subDim() const { return smv_.subDim(); }
00097   Teuchos_Index colOffset() const { return smv_.colOffset(); }
00099   Teuchos_Index numSubCols() const { return smv_.numSubCols(); }
00101   Scalar* values() const { return smv_.values().get(); }
00103   Teuchos_Index leadingDim() const { return smv_.leadingDim(); }
00105   Scalar& operator()(Teuchos_Index i,Teuchos_Index j) { return smv_(i,j); }
00106 private:
00107   MultiVectorBase<Scalar> &mv_;
00108   RTOpPack::SubMultiVectorView<Scalar> smv_;
00109   // Not defined and not to be called
00110   DetachedMultiVectorView();
00111   DetachedMultiVectorView(const DetachedMultiVectorView<Scalar>&);
00112   DetachedMultiVectorView<Scalar>& operator==(const DetachedMultiVectorView<Scalar>&);
00113 };
00114 
00119 template<class Scalar>
00120 void doExplicitMultiVectorAdjoint(
00121   const MultiVectorBase<Scalar>& mvIn, MultiVectorBase<Scalar>* mvTransOut
00122   )
00123 {
00124   typedef Teuchos::ScalarTraits<Scalar> ST;
00125 #ifdef TEUCHOS_DEBUG
00126   TEST_FOR_EXCEPT(0==mvTransOut);
00127   THYRA_ASSERT_VEC_SPACES("doExplicitMultiVectorAdjoint(...)",
00128     *mvIn.domain(), *mvTransOut->range()
00129     );
00130   THYRA_ASSERT_VEC_SPACES("doExplicitMultiVectorAdjoint(...)",
00131     *mvIn.range(), *mvTransOut->domain()
00132     );
00133 #endif
00134   ConstDetachedMultiVectorView<Scalar> dMvIn(mvIn);
00135   DetachedMultiVectorView<Scalar> dMvTransOut(*mvTransOut);
00136   const int m = dMvIn.subDim();
00137   const int n = dMvIn.numSubCols();
00138   for ( int j = 0; j < n; ++j ) {
00139     for ( int i = 0; i < m; ++i ) {
00140       dMvTransOut(j,i) = ST::conjugate(dMvIn(i,j));
00141     }
00142   }
00143 }
00144 
00145 
00146 } // namespace Thyra
00147 
00148 #endif // THYRA_EXPLICIT_MULTI_VECTOR_VIEW_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines