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 "RTOp.h"
00036 
00037 namespace RTOpPack {
00038 
00041 template<class Scalar>
00042 class SubVectorT1B {
00043 public:
00045   SubVectorT1B() : globalOffset_(0), subDim_(0), values_(NULL), stride_(0) {}
00047   SubVectorT1B(Teuchos_Index globalOffset, Teuchos_Index subDim, const Scalar *values, ptrdiff_t stride)
00048     :globalOffset_(globalOffset), subDim_(subDim), values_(values), stride_(stride) 
00049     {}
00051   SubVectorT1B( const SubVectorT1B<Scalar>& sv )
00052     :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()), values_(sv.values()), stride_(sv.stride()) 
00053     {}
00055   SubVectorT1B( const ConstSubVectorView<Scalar>& sv )
00056     :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()), values_(sv.values()), stride_(sv.stride()) 
00057     {}
00059   operator ConstSubVectorView<Scalar>()
00060     { return ConstSubVectorView<Scalar>(globalOffset(),subDim(),values(),stride()); }
00062   void initialize(Teuchos_Index globalOffset, Teuchos_Index subDim, const Scalar *values, ptrdiff_t stride)
00063     { globalOffset_=globalOffset; subDim_=subDim; values_=values; stride_=stride;  }
00065   void set_uninitialized()
00066     { globalOffset_ = 0; subDim_=0; values_=NULL; stride_ = 0; }
00068   void setGlobalOffset(Teuchos_Index globalOffset) { globalOffset_ = globalOffset; } 
00070   Teuchos_Index   globalOffset() const { return globalOffset_; }
00072   Teuchos_Index   subDim()       const { return subDim_;  }
00074   const Scalar*     values()       const { return values_;  }
00076   ptrdiff_t         stride()       const { return stride_;  }
00078   const Scalar& operator[](Teuchos_Index i) const
00079     {
00080 #ifdef TEUCHOS_DEBUG
00081       TEST_FOR_EXCEPTION(
00082         !( 0 <= i && i < subDim_ ), std::logic_error
00083         ,"Error, index i="<<i<<" does not fall in the range [0,"<<(subDim_-1)<<"]!"
00084         );
00085 #endif
00086       return values_[ stride_*i ];
00087     }
00089   const Scalar& operator()(Teuchos_Index i) const { return (*this)[i-1]; }
00090 private:
00091   Teuchos_Index     globalOffset_;
00092   Teuchos_Index     subDim_;
00093   const Scalar      *values_;
00094   ptrdiff_t         stride_;
00095 };
00096 
00099 template<class Scalar>
00100 class MutableSubVectorT1B : public SubVectorT1B<Scalar> {
00101 public:
00103   MutableSubVectorT1B() {}
00105   MutableSubVectorT1B(Teuchos_Index globalOffset, Teuchos_Index subDim, Scalar *values, ptrdiff_t stride)
00106     :SubVectorT1B<Scalar>(globalOffset, subDim, values, stride)
00107     {}
00109   MutableSubVectorT1B( const MutableSubVectorT1B<Scalar> & sv)
00110     :SubVectorT1B<Scalar>(sv)
00111     {}
00113   MutableSubVectorT1B( const SubVectorView<Scalar>& sv )
00114     :SubVectorT1B<Scalar>(MutableSubVectorT1B<Scalar>(sv.globalOffset(),sv.subDim(),sv.values(),sv.stride())) 
00115     {}
00117   operator SubVectorView<Scalar>()
00118     { return SubVectorView<Scalar>(this->globalOffset(),this->subDim(),this->values(),this->stride()); }
00120   void initialize(Teuchos_Index globalOffset, Teuchos_Index subDim, Scalar *values, ptrdiff_t stride)
00121     { SubVectorT1B<Scalar>::initialize(globalOffset, subDim, values, stride); }
00123   void set_uninitialized()
00124     { SubVectorT1B<Scalar>::set_uninitialized(); }
00126   Scalar* values() const { return const_cast<Scalar*>(SubVectorT1B<Scalar>::values());  }
00128   Scalar& operator[](Teuchos_Index i) const { return const_cast<Scalar&>(SubVectorT1B<Scalar>::operator[](i)); } // Is range changed in subclass!
00130   Scalar& operator()(Teuchos_Index i) const { return (*this)[i-1]; }
00131 };
00132 
00133 template<class Scalar>
00134 void assign_entries( const MutableSubVectorT1B<Scalar> *msv, const SubVectorT1B<Scalar> &sv )
00135 {
00136 #ifdef TEUCHOS_DEBUG
00137   TEST_FOR_EXCEPT(msv==NULL);
00138   TEST_FOR_EXCEPT(msv->subDim() != sv.subDim());
00139 #endif
00140   for( int i = 1; i <= sv.subDim(); ++i ) {
00141     (*msv)(i) = sv(i);
00142   }
00143 }
00144 
00147 template<class Scalar>
00148 class SubMultiVectorT1B {
00149 public:
00151   SubMultiVectorT1B()
00152     :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0)
00153     ,values_(NULL), leadingDim_(0)
00154     {}
00156   SubMultiVectorT1B(
00157     Teuchos_Index globalOffset, Teuchos_Index subDim
00158     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00159     ,const Scalar *values, Teuchos_Index leadingDim
00160     )
00161     :globalOffset_(globalOffset), subDim_(subDim)
00162     ,colOffset_(colOffset), numSubCols_(numSubCols)
00163     ,values_(values), leadingDim_(leadingDim)
00164     {}
00166   SubMultiVectorT1B( const SubMultiVectorT1B<Scalar>& smv )
00167     :globalOffset_(smv.globalOffset()), subDim_(smv.subDim())
00168     ,colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols())
00169     ,values_(smv.values()), leadingDim_(smv.leadingDim())
00170     {}
00171 /*
00172   SubMultiVectorT1B( const ConstSubMultiVectorView<Scalar>& smv )
00173     :globalOffset_(smv.globalOffset()), subDim_(smv.subDim())
00174     ,colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols())
00175     ,values_(smv.values()), leadingDim_(smv.leadingDim())
00176     {}
00177   operator ConstSubMultiVectorView<Scalar>()
00178     { return ConstSubMultiVectorView<Scalar>(globalOffset(),subDim(),colOffset(),numSubCols(),values(),leadingDim()); }
00179 */
00181   void initialize(
00182     Teuchos_Index globalOffset, Teuchos_Index subDim
00183     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00184     ,const Scalar *values, Teuchos_Index leadingDim
00185     )
00186     { globalOffset_=globalOffset; subDim_=subDim; colOffset_=colOffset; numSubCols_=numSubCols;
00187     values_=values; leadingDim_=leadingDim; }
00189   void set_uninitialized()
00190     { globalOffset_ = 0; subDim_=0; colOffset_=0, numSubCols_=0; values_=NULL; leadingDim_=0; }
00192   void setGlobalOffset(Teuchos_Index globalOffset) { globalOffset_ = globalOffset; } 
00194   Teuchos_Index   globalOffset()   const { return globalOffset_; }
00196   Teuchos_Index   subDim()         const { return subDim_; }
00198   Teuchos_Index   colOffset()      const { return colOffset_; }
00200   Teuchos_Index   numSubCols()     const { return numSubCols_; }
00202   const Scalar*   values()         const { return values_; }
00204   Teuchos_Index   leadingDim()     const { return leadingDim_;  }
00206   const Scalar& operator()(Teuchos_Index i, Teuchos_Index j) const
00207     {
00208 #ifdef TEUCHOS_DEBUG
00209       TEST_FOR_EXCEPTION(
00210         !( 1 <= i && i < subDim_ ), std::logic_error
00211         ,"Error, index i="<<i<<" does not fall in the range [1,"<<(subDim_-1)<<"]!"
00212         );
00213       TEST_FOR_EXCEPTION(
00214         !( 1 <= j && j <= numSubCols_ ), std::logic_error
00215         ,"Error, index j="<<j<<" does not fall in the range [1,"<<(numSubCols_-1)<<"]!"
00216         );
00217 #endif
00218       return values_[ (i-1) + leadingDim_*(j-1) ];
00219     }
00221   SubVectorT1B<Scalar> col( const Teuchos_Index j ) const
00222     {
00223 #ifdef TEUCHOS_DEBUG
00224       TEST_FOR_EXCEPTION(
00225         !( 1 <= j && j <= numSubCols_ ), std::logic_error
00226         ,"Error, index j="<<j<<" does not fall in the range [1,"<<(numSubCols_-1)<<"]!"
00227         );
00228 #endif
00229       return SubVectorT1B<Scalar>(globalOffset(),subDim(),values()+(j-1)*leadingDim(),1);
00230     }
00231 private:
00232   Teuchos_Index     globalOffset_;
00233   Teuchos_Index     subDim_;
00234   Teuchos_Index     colOffset_;
00235   Teuchos_Index     numSubCols_;
00236   const Scalar        *values_;
00237   Teuchos_Index     leadingDim_;
00238 };
00239 
00242 template<class Scalar>
00243 class MutableSubMultiVectorT1B : public SubMultiVectorT1B<Scalar> {
00244 public:
00246   MutableSubMultiVectorT1B() {}
00248   MutableSubMultiVectorT1B(
00249     Teuchos_Index globalOffset, Teuchos_Index subDim
00250     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00251     ,const Scalar *values, Teuchos_Index leadingDim
00252     )
00253     :SubMultiVectorT1B<Scalar>(globalOffset,subDim,colOffset,numSubCols,values,leadingDim)
00254     {}
00256   MutableSubMultiVectorT1B( const MutableSubMultiVectorT1B<Scalar> & smv)
00257     :SubMultiVectorT1B<Scalar>(smv)
00258     {}
00259 /*
00260   MutableSubMultiVectorT1B( const SubMultiVectorView<Scalar>& smv )
00261     :SubMultiVectorT1B<Scalar>(
00262       MutableSubMultiVectorT1B<Scalar>(
00263         smv.globalOffset(),smv.subDim(),smv.colOffset(),smv.numSubCols()
00264         ,smv.values(),smv.leadingDim()
00265         )
00266       )
00267     {}
00268   operator SubMultiVectorView<Scalar>()
00269     { return SubMultiVectorView<Scalar>(this->globalOffset(),this->subDim(),this->colOffset(),this->numSubCols(),this->values(),this->leadingDim()); }
00270 */
00272   void initialize(
00273     Teuchos_Index globalOffset, Teuchos_Index subDim
00274     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00275     ,const Scalar *values, Teuchos_Index leadingDim
00276     )
00277     { SubMultiVectorT1B<Scalar>::initialize(globalOffset,subDim,colOffset,numSubCols,values,leadingDim); }
00279   void set_uninitialized()
00280     { SubMultiVectorT1B<Scalar>::set_uninitialized(); }
00282   Scalar* values() const { return const_cast<Scalar*>(SubMultiVectorT1B<Scalar>::values());  }
00284   Scalar& operator()(Teuchos_Index i, Teuchos_Index j) const
00285     { return const_cast<Scalar&>(SubMultiVectorT1B<Scalar>::operator()(i,j)); } // Is range checked in subclass
00287   MutableSubVectorT1B<Scalar> col( const Teuchos_Index j ) const
00288     {
00289 #ifdef TEUCHOS_DEBUG
00290       TEST_FOR_EXCEPTION(
00291         !( 1 <= j && j <= this->numSubCols() ), std::logic_error
00292         ,"Error, index j="<<j<<" does not fall in the range [1,"<<(this->numSubCols())<<"]!"
00293         );
00294 #endif
00295       return MutableSubVectorT1B<Scalar>(this->globalOffset(),this->subDim(),values()+(j-1)*this->leadingDim(),1);
00296     }
00297 };
00298 
00299 template<class Scalar>
00300 void assign_entries( const MutableSubMultiVectorT1B<Scalar> *msmv, const SubMultiVectorT1B<Scalar> &smv )
00301 {
00302 #ifdef TEUCHOS_DEBUG
00303   TEST_FOR_EXCEPT(msmv==NULL);
00304   TEST_FOR_EXCEPT(msmv->subDim() != smv.subDim());
00305   TEST_FOR_EXCEPT(msmv->numSubCols() != smv.numSubCols());
00306 #endif
00307   for( Teuchos_Index j = 1; j <= smv.numSubCols(); ++j ) {
00308     for( Teuchos_Index i = 1; i < smv.subDim(); ++i ) {
00309       (*msmv)(i,j) = smv(i,j);
00310     }
00311   }
00312 }
00313 
00314 //
00315 // Typedefs
00316 //
00317 
00319 typedef SubVectorT1B<RTOp_value_type>              SubVector;
00321 typedef MutableSubVectorT1B<RTOp_value_type>       MutableSubVector;
00323 typedef SparseSubVectorT<RTOp_value_type>          SparseSubVector;
00325 typedef SubMultiVectorT1B<RTOp_value_type>         SubMultiVector;
00327 typedef MutableSubMultiVectorT1B<RTOp_value_type>  MutableSubMultiVector;
00329 typedef RTOpT<RTOp_value_type>                     RTOp;
00330 
00331 } // namespace RTOpPack
00332 
00333 #endif // RTOPPACK_OLD_TYPES_HPP

Generated on Tue Oct 20 12:51:49 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7