RTOpPack_OldTypes.hpp

Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00006 //                  Copyright (2003) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 */
00030 
00031 #ifndef RTOPPACK_OLD_TYPES_HPP
00032 #define RTOPPACK_OLD_TYPES_HPP
00033 
00034 #include "RTOpPack_Types.hpp"
00035 #include "RTOpPack_SparseSubVectorT.hpp"
00036 #include "RTOp.h"
00037 
00038 namespace RTOpPack {
00039 
00042 template<class Scalar>
00043 class SubVectorT1B {
00044 public:
00046   SubVectorT1B() : globalOffset_(0), subDim_(0), values_(Teuchos::null), stride_(0) {}
00048   SubVectorT1B(Teuchos_Index globalOffset, Teuchos_Index subDim, const Scalar *values, ptrdiff_t stride)
00049     :globalOffset_(globalOffset), subDim_(subDim), values_(values,0,subDim*stride,false), stride_(stride) 
00050     {}
00052   SubVectorT1B( const SubVectorT1B<Scalar>& sv )
00053     :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()), values_(sv.arcp_values()), stride_(sv.stride()) 
00054     {}
00056   SubVectorT1B( const ConstSubVectorView<Scalar>& sv )
00057     :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()), values_(sv.values()), stride_(sv.stride()) 
00058     {}
00060   operator ConstSubVectorView<Scalar>()
00061     { return ConstSubVectorView<Scalar>(globalOffset(),subDim(),arcp_values(),stride()); }
00063   void initialize(Teuchos_Index globalOffset, Teuchos_Index subDim, const Scalar *values, ptrdiff_t stride)
00064     { globalOffset_=globalOffset; subDim_=subDim; values_=Teuchos::arcp(values,0,subDim*stride,false); stride_=stride; }
00066   void set_uninitialized()
00067     { globalOffset_ = 0; subDim_=0; values_=Teuchos::null; stride_ = 0; }
00069   void setGlobalOffset(Teuchos_Index globalOffset) { globalOffset_ = globalOffset; } 
00071   Teuchos_Index globalOffset() const { return globalOffset_; }
00073   Teuchos_Index subDim() const { return subDim_; }
00075   const Scalar* values() const { return values_.get(); }
00077   const Teuchos::ArrayRCP<const Scalar> arcp_values() const { return values_; }
00079   ptrdiff_t stride() const { return stride_; }
00081   const Scalar& operator[](Teuchos_Index i) const
00082     {
00083 #ifdef TEUCHOS_DEBUG
00084       TEST_FOR_EXCEPTION(
00085         !( 0 <= i && i < subDim_ ), std::logic_error
00086         ,"Error, index i="<<i<<" does not fall in the range [0,"<<(subDim_-1)<<"]!"
00087         );
00088 #endif
00089       return values_[ stride_*i ];
00090     }
00092   const Scalar& operator()(Teuchos_Index i) const { return (*this)[i-1]; }
00093 private:
00094   Teuchos_Index globalOffset_;
00095   Teuchos_Index subDim_;
00096   Teuchos::ArrayRCP<const Scalar> values_;
00097   ptrdiff_t stride_;
00098 };
00099 
00102 template<class Scalar>
00103 class MutableSubVectorT1B : public SubVectorT1B<Scalar> {
00104 public:
00106   MutableSubVectorT1B() {}
00108   MutableSubVectorT1B(Teuchos_Index globalOffset, Teuchos_Index subDim, Scalar *values, ptrdiff_t stride)
00109     :SubVectorT1B<Scalar>(globalOffset, subDim, values, stride)
00110     {}
00112   MutableSubVectorT1B( const MutableSubVectorT1B<Scalar> & sv)
00113     :SubVectorT1B<Scalar>(sv)
00114     {}
00116   MutableSubVectorT1B( const SubVectorView<Scalar>& sv )
00117     :SubVectorT1B<Scalar>(ConstSubVectorView<Scalar>(sv))
00118     {}
00120   operator SubVectorView<Scalar>()
00121     { return SubVectorView<Scalar>(this->globalOffset(),this->subDim(),this->arcp_values(),this->stride()); }
00123   void initialize(Teuchos_Index globalOffset, Teuchos_Index subDim, Scalar *values, ptrdiff_t stride)
00124     { SubVectorT1B<Scalar>::initialize(globalOffset, subDim, values, stride); }
00126   void set_uninitialized()
00127     { SubVectorT1B<Scalar>::set_uninitialized(); }
00129   Scalar* values() const { return const_cast<Scalar*>(SubVectorT1B<Scalar>::values()); }
00131   const Teuchos::ArrayRCP<Scalar> arcp_values() const { return Teuchos::arcp_const_cast<Scalar>(SubVectorT1B<Scalar>::arcp_values()); }
00133   Scalar& operator[](Teuchos_Index i) const { return const_cast<Scalar&>(SubVectorT1B<Scalar>::operator[](i)); } // Is range changed in subclass!
00135   Scalar& operator()(Teuchos_Index i) const { return (*this)[i-1]; }
00136 };
00137 
00138 template<class Scalar>
00139 void assign_entries( const MutableSubVectorT1B<Scalar> *msv, const SubVectorT1B<Scalar> &sv )
00140 {
00141 #ifdef TEUCHOS_DEBUG
00142   TEST_FOR_EXCEPT(msv==NULL);
00143   TEST_FOR_EXCEPT(msv->subDim() != sv.subDim());
00144 #endif
00145   for( int i = 1; i <= sv.subDim(); ++i ) {
00146     (*msv)(i) = sv(i);
00147   }
00148 }
00149 
00152 template<class Scalar>
00153 class SubMultiVectorT1B {
00154 public:
00156   SubMultiVectorT1B()
00157     :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0)
00158     ,values_(NULL), leadingDim_(0)
00159     {}
00161   SubMultiVectorT1B(
00162     Teuchos_Index globalOffset, Teuchos_Index subDim
00163     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00164     ,const Scalar *values, Teuchos_Index leadingDim
00165     )
00166     :globalOffset_(globalOffset), subDim_(subDim)
00167     ,colOffset_(colOffset), numSubCols_(numSubCols)
00168     ,values_(values), leadingDim_(leadingDim)
00169     {}
00171   SubMultiVectorT1B( const SubMultiVectorT1B<Scalar>& smv )
00172     :globalOffset_(smv.globalOffset()), subDim_(smv.subDim())
00173     ,colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols())
00174     ,values_(smv.values()), leadingDim_(smv.leadingDim())
00175     {}
00176 /*
00177   SubMultiVectorT1B( const ConstSubMultiVectorView<Scalar>& smv )
00178   :globalOffset_(smv.globalOffset()), subDim_(smv.subDim())
00179   ,colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols())
00180   ,values_(smv.values()), leadingDim_(smv.leadingDim())
00181   {}
00182   operator ConstSubMultiVectorView<Scalar>()
00183   { return ConstSubMultiVectorView<Scalar>(globalOffset(),subDim(),colOffset(),numSubCols(),values(),leadingDim()); }
00184 */
00186   void initialize(
00187     Teuchos_Index globalOffset, Teuchos_Index subDim
00188     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00189     ,const Scalar *values, Teuchos_Index leadingDim
00190     )
00191     { globalOffset_=globalOffset; subDim_=subDim; colOffset_=colOffset; numSubCols_=numSubCols;
00192       values_=values; leadingDim_=leadingDim; }
00194   void set_uninitialized()
00195     { globalOffset_ = 0; subDim_=0; colOffset_=0, numSubCols_=0; values_=NULL; leadingDim_=0; }
00197   void setGlobalOffset(Teuchos_Index globalOffset) { globalOffset_ = globalOffset; } 
00199   Teuchos_Index   globalOffset()   const { return globalOffset_; }
00201   Teuchos_Index   subDim()         const { return subDim_; }
00203   Teuchos_Index   colOffset()      const { return colOffset_; }
00205   Teuchos_Index   numSubCols()     const { return numSubCols_; }
00207   const Scalar*   values()         const { return values_; }
00209   Teuchos_Index   leadingDim()     const { return leadingDim_;  }
00211   const Scalar& operator()(Teuchos_Index i, Teuchos_Index j) const
00212     {
00213 #ifdef TEUCHOS_DEBUG
00214       TEST_FOR_EXCEPTION(
00215         !( 1 <= i && i < subDim_ ), std::logic_error
00216         ,"Error, index i="<<i<<" does not fall in the range [1,"<<(subDim_-1)<<"]!"
00217         );
00218       TEST_FOR_EXCEPTION(
00219         !( 1 <= j && j <= numSubCols_ ), std::logic_error
00220         ,"Error, index j="<<j<<" does not fall in the range [1,"<<(numSubCols_-1)<<"]!"
00221         );
00222 #endif
00223       return values_[ (i-1) + leadingDim_*(j-1) ];
00224     }
00226   SubVectorT1B<Scalar> col( const Teuchos_Index j ) const
00227     {
00228 #ifdef TEUCHOS_DEBUG
00229       TEST_FOR_EXCEPTION(
00230         !( 1 <= j && j <= numSubCols_ ), std::logic_error
00231         ,"Error, index j="<<j<<" does not fall in the range [1,"<<(numSubCols_-1)<<"]!"
00232         );
00233 #endif
00234       return SubVectorT1B<Scalar>(globalOffset(),subDim(),values()+(j-1)*leadingDim(),1);
00235     }
00236 private:
00237   Teuchos_Index     globalOffset_;
00238   Teuchos_Index     subDim_;
00239   Teuchos_Index     colOffset_;
00240   Teuchos_Index     numSubCols_;
00241   const Scalar        *values_;
00242   Teuchos_Index     leadingDim_;
00243 };
00244 
00247 template<class Scalar>
00248 class MutableSubMultiVectorT1B : public SubMultiVectorT1B<Scalar> {
00249 public:
00251   MutableSubMultiVectorT1B() {}
00253   MutableSubMultiVectorT1B(
00254     Teuchos_Index globalOffset, Teuchos_Index subDim
00255     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00256     ,const Scalar *values, Teuchos_Index leadingDim
00257     )
00258     :SubMultiVectorT1B<Scalar>(globalOffset,subDim,colOffset,numSubCols,values,leadingDim)
00259     {}
00261   MutableSubMultiVectorT1B( const MutableSubMultiVectorT1B<Scalar> & smv)
00262     :SubMultiVectorT1B<Scalar>(smv)
00263     {}
00264 /*
00265   MutableSubMultiVectorT1B( const SubMultiVectorView<Scalar>& smv )
00266   :SubMultiVectorT1B<Scalar>(
00267   MutableSubMultiVectorT1B<Scalar>(
00268   smv.globalOffset(),smv.subDim(),smv.colOffset(),smv.numSubCols()
00269   ,smv.values(),smv.leadingDim()
00270   )
00271   )
00272   {}
00273   operator SubMultiVectorView<Scalar>()
00274   { return SubMultiVectorView<Scalar>(this->globalOffset(),this->subDim(),this->colOffset(),this->numSubCols(),this->values(),this->leadingDim()); }
00275 */
00277   void initialize(
00278     Teuchos_Index globalOffset, Teuchos_Index subDim
00279     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00280     ,const Scalar *values, Teuchos_Index leadingDim
00281     )
00282     { SubMultiVectorT1B<Scalar>::initialize(globalOffset,subDim,colOffset,numSubCols,values,leadingDim); }
00284   void set_uninitialized()
00285     { SubMultiVectorT1B<Scalar>::set_uninitialized(); }
00287   Scalar* values() const { return const_cast<Scalar*>(SubMultiVectorT1B<Scalar>::values());  }
00289   Scalar& operator()(Teuchos_Index i, Teuchos_Index j) const
00290     { return const_cast<Scalar&>(SubMultiVectorT1B<Scalar>::operator()(i,j)); } // Is range checked in subclass
00292   MutableSubVectorT1B<Scalar> col( const Teuchos_Index j ) const
00293     {
00294 #ifdef TEUCHOS_DEBUG
00295       TEST_FOR_EXCEPTION(
00296         !( 1 <= j && j <= this->numSubCols() ), std::logic_error
00297         ,"Error, index j="<<j<<" does not fall in the range [1,"<<(this->numSubCols())<<"]!"
00298         );
00299 #endif
00300       return MutableSubVectorT1B<Scalar>(this->globalOffset(),this->subDim(),values()+(j-1)*this->leadingDim(),1);
00301     }
00302 };
00303 
00304 template<class Scalar>
00305 void assign_entries( const MutableSubMultiVectorT1B<Scalar> *msmv, const SubMultiVectorT1B<Scalar> &smv )
00306 {
00307 #ifdef TEUCHOS_DEBUG
00308   TEST_FOR_EXCEPT(msmv==NULL);
00309   TEST_FOR_EXCEPT(msmv->subDim() != smv.subDim());
00310   TEST_FOR_EXCEPT(msmv->numSubCols() != smv.numSubCols());
00311 #endif
00312   for( Teuchos_Index j = 1; j <= smv.numSubCols(); ++j ) {
00313     for( Teuchos_Index i = 1; i < smv.subDim(); ++i ) {
00314       (*msmv)(i,j) = smv(i,j);
00315     }
00316   }
00317 }
00318 
00319 //
00320 // Typedefs
00321 //
00322 
00324 typedef SubVectorT1B<RTOp_value_type>              SubVector;
00326 typedef MutableSubVectorT1B<RTOp_value_type>       MutableSubVector;
00328 typedef SparseSubVectorT<RTOp_value_type>          SparseSubVector;
00330 typedef SubMultiVectorT1B<RTOp_value_type>         SubMultiVector;
00332 typedef MutableSubMultiVectorT1B<RTOp_value_type>  MutableSubMultiVector;
00334 typedef RTOpT<RTOp_value_type>                     RTOp;
00335 
00336 } // namespace RTOpPack
00337 
00338 #endif // RTOPPACK_OLD_TYPES_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:11:01 2011 for MOOCHO (Single Doxygen Collection) by  doxygen 1.6.3