MOOCHO (Single Doxygen Collection) Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00039 // 
00040 // ***********************************************************************
00041 // @HEADER
00042 */
00043 
00044 #ifndef RTOPPACK_OLD_TYPES_HPP
00045 #define RTOPPACK_OLD_TYPES_HPP
00046 
00047 #include "RTOpPack_Types.hpp"
00048 #include "RTOpPack_SparseSubVectorT.hpp"
00049 #include "RTOp.h"
00050 
00051 namespace RTOpPack {
00052 
00055 template<class Scalar>
00056 class SubVectorT1B {
00057 public:
00059   SubVectorT1B() : globalOffset_(0), subDim_(0), values_(Teuchos::null), stride_(0) {}
00061   SubVectorT1B(Teuchos_Index globalOffset, Teuchos_Index subDim, const Scalar *values, ptrdiff_t stride)
00062     :globalOffset_(globalOffset), subDim_(subDim), values_(values,0,subDim*stride,false), stride_(stride) 
00063     {}
00065   SubVectorT1B( const SubVectorT1B<Scalar>& sv )
00066     :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()), values_(sv.arcp_values()), stride_(sv.stride()) 
00067     {}
00069   SubVectorT1B( const ConstSubVectorView<Scalar>& sv )
00070     :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()), values_(sv.values()), stride_(sv.stride()) 
00071     {}
00073   operator ConstSubVectorView<Scalar>()
00074     { return ConstSubVectorView<Scalar>(globalOffset(),subDim(),arcp_values(),stride()); }
00076   void initialize(Teuchos_Index globalOffset, Teuchos_Index subDim, const Scalar *values, ptrdiff_t stride)
00077     { globalOffset_=globalOffset; subDim_=subDim; values_=Teuchos::arcp(values,0,subDim*stride,false); stride_=stride; }
00079   void set_uninitialized()
00080     { globalOffset_ = 0; subDim_=0; values_=Teuchos::null; stride_ = 0; }
00082   void setGlobalOffset(Teuchos_Index globalOffset) { globalOffset_ = globalOffset; } 
00084   Teuchos_Index globalOffset() const { return globalOffset_; }
00086   Teuchos_Index subDim() const { return subDim_; }
00088   const Scalar* values() const { return values_.get(); }
00090   const Teuchos::ArrayRCP<const Scalar> arcp_values() const { return values_; }
00092   ptrdiff_t stride() const { return stride_; }
00094   const Scalar& operator[](Teuchos_Index i) const
00095     {
00096 #ifdef TEUCHOS_DEBUG
00097       TEUCHOS_TEST_FOR_EXCEPTION(
00098         !( 0 <= i && i < subDim_ ), std::logic_error
00099         ,"Error, index i="<<i<<" does not fall in the range [0,"<<(subDim_-1)<<"]!"
00100         );
00101 #endif
00102       return values_[ stride_*i ];
00103     }
00105   const Scalar& operator()(Teuchos_Index i) const { return (*this)[i-1]; }
00106 private:
00107   Teuchos_Index globalOffset_;
00108   Teuchos_Index subDim_;
00109   Teuchos::ArrayRCP<const Scalar> values_;
00110   ptrdiff_t stride_;
00111 };
00112 
00115 template<class Scalar>
00116 class MutableSubVectorT1B : public SubVectorT1B<Scalar> {
00117 public:
00119   MutableSubVectorT1B() {}
00121   MutableSubVectorT1B(Teuchos_Index globalOffset, Teuchos_Index subDim, Scalar *values, ptrdiff_t stride)
00122     :SubVectorT1B<Scalar>(globalOffset, subDim, values, stride)
00123     {}
00125   MutableSubVectorT1B( const MutableSubVectorT1B<Scalar> & sv)
00126     :SubVectorT1B<Scalar>(sv)
00127     {}
00129   MutableSubVectorT1B( const SubVectorView<Scalar>& sv )
00130     :SubVectorT1B<Scalar>(ConstSubVectorView<Scalar>(sv))
00131     {}
00133   operator SubVectorView<Scalar>()
00134     { return SubVectorView<Scalar>(this->globalOffset(),this->subDim(),this->arcp_values(),this->stride()); }
00136   void initialize(Teuchos_Index globalOffset, Teuchos_Index subDim, Scalar *values, ptrdiff_t stride)
00137     { SubVectorT1B<Scalar>::initialize(globalOffset, subDim, values, stride); }
00139   void set_uninitialized()
00140     { SubVectorT1B<Scalar>::set_uninitialized(); }
00142   Scalar* values() const { return const_cast<Scalar*>(SubVectorT1B<Scalar>::values()); }
00144   const Teuchos::ArrayRCP<Scalar> arcp_values() const { return Teuchos::arcp_const_cast<Scalar>(SubVectorT1B<Scalar>::arcp_values()); }
00146   Scalar& operator[](Teuchos_Index i) const { return const_cast<Scalar&>(SubVectorT1B<Scalar>::operator[](i)); } // Is range changed in subclass!
00148   Scalar& operator()(Teuchos_Index i) const { return (*this)[i-1]; }
00149 };
00150 
00151 template<class Scalar>
00152 void assign_entries( const MutableSubVectorT1B<Scalar> *msv, const SubVectorT1B<Scalar> &sv )
00153 {
00154 #ifdef TEUCHOS_DEBUG
00155   TEUCHOS_TEST_FOR_EXCEPT(msv==NULL);
00156   TEUCHOS_TEST_FOR_EXCEPT(msv->subDim() != sv.subDim());
00157 #endif
00158   for( int i = 1; i <= sv.subDim(); ++i ) {
00159     (*msv)(i) = sv(i);
00160   }
00161 }
00162 
00165 template<class Scalar>
00166 class SubMultiVectorT1B {
00167 public:
00169   SubMultiVectorT1B()
00170     :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0)
00171     ,values_(NULL), leadingDim_(0)
00172     {}
00174   SubMultiVectorT1B(
00175     Teuchos_Index globalOffset, Teuchos_Index subDim
00176     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00177     ,const Scalar *values, Teuchos_Index leadingDim
00178     )
00179     :globalOffset_(globalOffset), subDim_(subDim)
00180     ,colOffset_(colOffset), numSubCols_(numSubCols)
00181     ,values_(values), leadingDim_(leadingDim)
00182     {}
00184   SubMultiVectorT1B( const SubMultiVectorT1B<Scalar>& smv )
00185     :globalOffset_(smv.globalOffset()), subDim_(smv.subDim())
00186     ,colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols())
00187     ,values_(smv.values()), leadingDim_(smv.leadingDim())
00188     {}
00189 /*
00190   SubMultiVectorT1B( const ConstSubMultiVectorView<Scalar>& smv )
00191   :globalOffset_(smv.globalOffset()), subDim_(smv.subDim())
00192   ,colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols())
00193   ,values_(smv.values()), leadingDim_(smv.leadingDim())
00194   {}
00195   operator ConstSubMultiVectorView<Scalar>()
00196   { return ConstSubMultiVectorView<Scalar>(globalOffset(),subDim(),colOffset(),numSubCols(),values(),leadingDim()); }
00197 */
00199   void initialize(
00200     Teuchos_Index globalOffset, Teuchos_Index subDim
00201     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00202     ,const Scalar *values, Teuchos_Index leadingDim
00203     )
00204     { globalOffset_=globalOffset; subDim_=subDim; colOffset_=colOffset; numSubCols_=numSubCols;
00205       values_=values; leadingDim_=leadingDim; }
00207   void set_uninitialized()
00208     { globalOffset_ = 0; subDim_=0; colOffset_=0, numSubCols_=0; values_=NULL; leadingDim_=0; }
00210   void setGlobalOffset(Teuchos_Index globalOffset) { globalOffset_ = globalOffset; } 
00212   Teuchos_Index   globalOffset()   const { return globalOffset_; }
00214   Teuchos_Index   subDim()         const { return subDim_; }
00216   Teuchos_Index   colOffset()      const { return colOffset_; }
00218   Teuchos_Index   numSubCols()     const { return numSubCols_; }
00220   const Scalar*   values()         const { return values_; }
00222   Teuchos_Index   leadingDim()     const { return leadingDim_;  }
00224   const Scalar& operator()(Teuchos_Index i, Teuchos_Index j) const
00225     {
00226 #ifdef TEUCHOS_DEBUG
00227       TEUCHOS_TEST_FOR_EXCEPTION(
00228         !( 1 <= i && i < subDim_ ), std::logic_error
00229         ,"Error, index i="<<i<<" does not fall in the range [1,"<<(subDim_-1)<<"]!"
00230         );
00231       TEUCHOS_TEST_FOR_EXCEPTION(
00232         !( 1 <= j && j <= numSubCols_ ), std::logic_error
00233         ,"Error, index j="<<j<<" does not fall in the range [1,"<<(numSubCols_-1)<<"]!"
00234         );
00235 #endif
00236       return values_[ (i-1) + leadingDim_*(j-1) ];
00237     }
00239   SubVectorT1B<Scalar> col( const Teuchos_Index j ) const
00240     {
00241 #ifdef TEUCHOS_DEBUG
00242       TEUCHOS_TEST_FOR_EXCEPTION(
00243         !( 1 <= j && j <= numSubCols_ ), std::logic_error
00244         ,"Error, index j="<<j<<" does not fall in the range [1,"<<(numSubCols_-1)<<"]!"
00245         );
00246 #endif
00247       return SubVectorT1B<Scalar>(globalOffset(),subDim(),values()+(j-1)*leadingDim(),1);
00248     }
00249 private:
00250   Teuchos_Index     globalOffset_;
00251   Teuchos_Index     subDim_;
00252   Teuchos_Index     colOffset_;
00253   Teuchos_Index     numSubCols_;
00254   const Scalar        *values_;
00255   Teuchos_Index     leadingDim_;
00256 };
00257 
00260 template<class Scalar>
00261 class MutableSubMultiVectorT1B : public SubMultiVectorT1B<Scalar> {
00262 public:
00264   MutableSubMultiVectorT1B() {}
00266   MutableSubMultiVectorT1B(
00267     Teuchos_Index globalOffset, Teuchos_Index subDim
00268     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00269     ,const Scalar *values, Teuchos_Index leadingDim
00270     )
00271     :SubMultiVectorT1B<Scalar>(globalOffset,subDim,colOffset,numSubCols,values,leadingDim)
00272     {}
00274   MutableSubMultiVectorT1B( const MutableSubMultiVectorT1B<Scalar> & smv)
00275     :SubMultiVectorT1B<Scalar>(smv)
00276     {}
00277 /*
00278   MutableSubMultiVectorT1B( const SubMultiVectorView<Scalar>& smv )
00279   :SubMultiVectorT1B<Scalar>(
00280   MutableSubMultiVectorT1B<Scalar>(
00281   smv.globalOffset(),smv.subDim(),smv.colOffset(),smv.numSubCols()
00282   ,smv.values(),smv.leadingDim()
00283   )
00284   )
00285   {}
00286   operator SubMultiVectorView<Scalar>()
00287   { return SubMultiVectorView<Scalar>(this->globalOffset(),this->subDim(),this->colOffset(),this->numSubCols(),this->values(),this->leadingDim()); }
00288 */
00290   void initialize(
00291     Teuchos_Index globalOffset, Teuchos_Index subDim
00292     ,Teuchos_Index colOffset, Teuchos_Index numSubCols
00293     ,const Scalar *values, Teuchos_Index leadingDim
00294     )
00295     { SubMultiVectorT1B<Scalar>::initialize(globalOffset,subDim,colOffset,numSubCols,values,leadingDim); }
00297   void set_uninitialized()
00298     { SubMultiVectorT1B<Scalar>::set_uninitialized(); }
00300   Scalar* values() const { return const_cast<Scalar*>(SubMultiVectorT1B<Scalar>::values());  }
00302   Scalar& operator()(Teuchos_Index i, Teuchos_Index j) const
00303     { return const_cast<Scalar&>(SubMultiVectorT1B<Scalar>::operator()(i,j)); } // Is range checked in subclass
00305   MutableSubVectorT1B<Scalar> col( const Teuchos_Index j ) const
00306     {
00307 #ifdef TEUCHOS_DEBUG
00308       TEUCHOS_TEST_FOR_EXCEPTION(
00309         !( 1 <= j && j <= this->numSubCols() ), std::logic_error
00310         ,"Error, index j="<<j<<" does not fall in the range [1,"<<(this->numSubCols())<<"]!"
00311         );
00312 #endif
00313       return MutableSubVectorT1B<Scalar>(this->globalOffset(),this->subDim(),values()+(j-1)*this->leadingDim(),1);
00314     }
00315 };
00316 
00317 template<class Scalar>
00318 void assign_entries( const MutableSubMultiVectorT1B<Scalar> *msmv, const SubMultiVectorT1B<Scalar> &smv )
00319 {
00320 #ifdef TEUCHOS_DEBUG
00321   TEUCHOS_TEST_FOR_EXCEPT(msmv==NULL);
00322   TEUCHOS_TEST_FOR_EXCEPT(msmv->subDim() != smv.subDim());
00323   TEUCHOS_TEST_FOR_EXCEPT(msmv->numSubCols() != smv.numSubCols());
00324 #endif
00325   for( Teuchos_Index j = 1; j <= smv.numSubCols(); ++j ) {
00326     for( Teuchos_Index i = 1; i < smv.subDim(); ++i ) {
00327       (*msmv)(i,j) = smv(i,j);
00328     }
00329   }
00330 }
00331 
00332 //
00333 // Typedefs
00334 //
00335 
00337 typedef SubVectorT1B<RTOp_value_type>              SubVector;
00339 typedef MutableSubVectorT1B<RTOp_value_type>       MutableSubVector;
00341 typedef SparseSubVectorT<RTOp_value_type>          SparseSubVector;
00343 typedef SubMultiVectorT1B<RTOp_value_type>         SubMultiVector;
00345 typedef MutableSubMultiVectorT1B<RTOp_value_type>  MutableSubMultiVector;
00347 typedef RTOpT<RTOp_value_type>                     RTOp;
00348 
00349 } // namespace RTOpPack
00350 
00351 #endif // RTOPPACK_OLD_TYPES_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines