diff --git a/fem/common/discretefunction.cc b/fem/common/discretefunction.cc index e65ab59a0495f1e72f67a7f3b7939d1ce5278476..2f5605008e5ed4334301ed3f7224a57c3b5b4c3d 100644 --- a/fem/common/discretefunction.cc +++ b/fem/common/discretefunction.cc @@ -23,15 +23,15 @@ namespace Dune DofIteratorImp ,LocalFunctionIteratorImp, DiscreteFunctionImp > &g ) const { typedef typename DiscreteFunctionSpaceType::RangeField RangeFieldType; + typedef ConstDofIteratorDefault<DofIteratorImp> ConstDofIter; RangeFieldType skp = 0.; - DofIteratorImp endit = this->dend (); - DofIteratorImp git = g.dbegin (); - DofIteratorImp it = this->dbegin(); + ConstDofIter endit = this->dend (); + ConstDofIter git = g.dbegin (); // multiply - for(; it != endit; ++it,++git) + for(ConstDofIter it = this->dbegin(); it != endit; ++it,++git) { skp += (*it) * (*git); } @@ -56,7 +56,7 @@ namespace Dune DofIteratorImp it = this->dbegin(); DofIteratorImp endit = this->dend (); - DofIteratorImp git = gc.dbegin (); + ConstDofIteratorDefault<DofIteratorImp> git = gc.dbegin (); for(; it != endit; ++it, ++git) *it = *git; @@ -80,7 +80,7 @@ namespace Dune static_cast<const DiscreteFunctionDefaultType &> ( g ); DofIteratorImp endit = this->dend (); - DofIteratorImp git = gc.dbegin (); + ConstDofIteratorDefault<DofIteratorImp> git = gc.dbegin (); for(DofIteratorImp it = this->dbegin(); it != endit; ++it,++git ) { @@ -107,7 +107,7 @@ namespace Dune static_cast<const DiscreteFunctionDefaultType &> ( g ); DofIteratorImp endit = this->dend (); - DofIteratorImp git = gc.dbegin (); + ConstDofIteratorDefault<DofIteratorImp> git = gc.dbegin (); for(DofIteratorImp it = this->dbegin(); it != endit; ++it, ++git) { *it += *git; @@ -132,7 +132,7 @@ namespace Dune static_cast<const DiscreteFunctionDefaultType &> ( g ); DofIteratorImp endit = this->dend (); - DofIteratorImp git = gc.dbegin (); + ConstDofIteratorDefault<DofIteratorImp> git = gc.dbegin (); for(DofIteratorImp it = this->dbegin(); it != endit; ++it, ++git) { *it -= *git; @@ -185,7 +185,7 @@ namespace Dune // we would need const_iterators..... DofIteratorImp endit = this->dend (); - DofIteratorImp git = gc.dbegin (); + ConstDofIteratorDefault<DofIteratorImp> git = gc.dbegin (); for(DofIteratorImp it = this->dbegin(); it != endit; ++it, ++git) { *it += (*git) * scalar; diff --git a/fem/common/discretefunction.hh b/fem/common/discretefunction.hh index c58dd41e88105f7cfc201dd83f7ffb5c73e9b5f3..27c9945bac273b98e1d833f16cffcf9eecaef8f6 100644 --- a/fem/common/discretefunction.hh +++ b/fem/common/discretefunction.hh @@ -7,6 +7,7 @@ #include <dune/common/function.hh> #include <dune/common/functionspace.hh> #include "discretefunctionspace.hh" +#include "dofiterator.hh" namespace Dune { @@ -132,13 +133,13 @@ namespace Dune { }; //! const version of dbegin - const DofIteratorType dbegin () const + ConstDofIteratorDefault<DofIteratorType> dbegin () const { return asImp().dbegin (); }; //! const version of dend - const DofIteratorType dend () const + ConstDofIteratorDefault<DofIteratorType> dend () const { return asImp().dend (); }; diff --git a/fem/common/dofiterator.hh b/fem/common/dofiterator.hh index c869d0d0d539a99b0331d191b120f8a01628368d..23242d9670ed113719b8bae0071bf76663907c61 100644 --- a/fem/common/dofiterator.hh +++ b/fem/common/dofiterator.hh @@ -36,34 +36,40 @@ namespace Dune { DofImp& operator *() { return asImp().operator *(); - }; + } + + //! return reference to dof + const DofImp& operator *() const + { + return asImp().operator *(); + } //! return global dof number of dof - int index () { return asImp().index(); }; + int index () const { return asImp().index(); } //! go to next dof DofIteratorType& operator++ () { return asImp().operator ++ (); - }; + } //! compare with other GlobalDofIterators - bool operator == (const DofIteratorType& I) + bool operator == (const DofIteratorType& I) const { return asImp().operator == (I); - }; + } //! compare with other GlobalDofIterators - bool operator != (const DofIteratorType& I) + bool operator != (const DofIteratorType& I) const { return asImp().operator != (I); - }; + } //! set the iterator to begin status void reset () { asImp().reset(); - }; + } private: //! Barton-Nackman trick @@ -98,8 +104,14 @@ namespace Dune { DofImp& operator [] (int n) { asImp().reset(); - for (int i=0; i<n; i++) - ++asImp(); + for (int i=0; i<n; i++) ++asImp(); + return asImp().operator *(); + }; + + const DofImp& operator [] (int n) const + { + asImp().reset(); + for (int i=0; i<n; i++) ++asImp(); return asImp().operator *(); }; @@ -116,6 +128,70 @@ namespace Dune { }; // end class DofIteratorDefault + //**************************************************************** + // + /*! \brief + ConstDofIteratorDefault make a const interator out of a + dof iterator. This version works for all dof iterators. + */ + //**************************************************************** + template <class DofIteratorImp> + class ConstDofIteratorDefault + : public DofIteratorDefault< typename DofIteratorImp::DofType, DofIteratorImp> + { + typedef ConstDofIteratorDefault<DofIteratorImp> MyType; + public: + typedef DofIteratorImp DofIteratorType; + typedef typename DofIteratorType::DofType DofType; + + //! Constructor + ConstDofIteratorDefault( DofIteratorImp & it ) : it_(it) {} + + //! random access operator, for efficient implementation overload in the + //! implementation class DofIteratorImp + const DofType& operator [] (int n) const + { + return it_[n]; + } + + const DofType& operator *() const + { + return (*it_); + } + + //! return global dof number of dof + int index () const { return it_.index(); } + + //! go to next dof + MyType & operator++ () + { + ++it_; + return (*this); + } + + //! compare with other GlobalDofIterators + bool operator == (const MyType& I) const + { + return it_ == I.it_; + } + + //! compare with other GlobalDofIterators + bool operator != (const MyType& I) const + { + return it_ != I.it_; + } + + //! set the iterator to begin status + void reset () + { + it_.reset(); + } + + private: + DofIteratorImp it_; + }; // end class DofIteratorDefault + + /** @} end documentation group */ } // end namespace Dune diff --git a/fem/dfadapt.hh b/fem/dfadapt.hh index 7df1b8497a8576e150bd61233175e16fea44fea6..8edc4fc317d508c4c94cb18e96a67e6167ef0ee3 100644 --- a/fem/dfadapt.hh +++ b/fem/dfadapt.hh @@ -54,6 +54,8 @@ namespace Dune { public: typedef DofIteratorAdapt<typename DiscreteFunctionSpaceType::RangeField, DofArrayType > DofIteratorType; + typedef ConstDofIteratorDefault<DofIteratorType> ConstDofIteratorType; + typedef typename DiscreteFunctionSpaceType::MemObjectType MemObjectType; @@ -92,10 +94,10 @@ namespace Dune { DofIteratorType dend ( ); //! const version of dof iterator - const DofIteratorType dbegin ( ) const; + ConstDofIteratorType dbegin ( ) const; //! const version of dof iterator - const DofIteratorType dend ( ) const; + ConstDofIteratorType dend ( ) const; //! set all dofs to zero void clear( ); @@ -266,13 +268,13 @@ namespace Dune { // --DofIteratorAdapt // //*********************************************************************** - template < class DofType, class DofArrayType > + template < class DofImp, class DofArrayType > class DofIteratorAdapt : public - DofIteratorDefault < DofType , DofIteratorAdapt < DofType, DofArrayType > > + DofIteratorDefault < DofImp , DofIteratorAdapt < DofImp, DofArrayType > > { - typedef DofIteratorAdapt<DofType,DofArrayType> MyType; + typedef DofIteratorAdapt<DofImp,DofArrayType> MyType; public: - typedef DofType T; + typedef DofImp DofType; DofIteratorAdapt ( DofArrayType & dofArray , int count ) : dofArray_ ( dofArray ) , constArray_ (dofArray) , count_ ( count ) {}; diff --git a/fem/discfuncarray.hh b/fem/discfuncarray.hh index a9b22d53273d4b38b40ade570f2ed67162f9f745..b274826fe08f1283dc2a42ed6d4dc9a6dfc4b4ac 100644 --- a/fem/discfuncarray.hh +++ b/fem/discfuncarray.hh @@ -51,12 +51,16 @@ namespace Dune { typedef typename DiscreteFunctionSpaceType::GridType GridType; - //! ??? + //! the MyType typedef DiscFuncArray <DiscreteFunctionSpaceType> DiscreteFunctionType; - //! ??? + + + //! the local function type typedef LocalFunctionArray < DiscreteFunctionSpaceType > LocalFunctionType; - //! ??? + + //! the dof iterator type of this function typedef DofIteratorArray < typename DiscreteFunctionSpaceType::RangeField > DofIteratorType; + typedef ConstDofIteratorDefault<DofIteratorType> ConstDofIteratorType; //! ??? typedef DiscreteFunctionSpaceType FunctionSpaceType; @@ -103,10 +107,10 @@ namespace Dune { // the const versions // we use the default implementation - const DofIteratorType dbegin () const; + ConstDofIteratorType dbegin () const; //! points behind the last dof of type cc - const DofIteratorType dend () const; + ConstDofIteratorType dend () const; //! Return the name of the discrete function const std::string& name() const {return name_;} @@ -287,11 +291,13 @@ namespace Dune { // //*********************************************************************** /** \brief ??? */ - template < class DofType > + template < class DofImp > class DofIteratorArray : public - DofIteratorDefault < DofType , DofIteratorArray < DofType > > + DofIteratorDefault < DofImp , DofIteratorArray < DofImp > > { public: + typedef DofImp DofType; + DofIteratorArray ( Array < DofType > & dofArray , int count ) : dofArray_ ( dofArray ) , constArray_ (dofArray) , count_ ( count ) {}; diff --git a/fem/discfuncarray/dfadapt.cc b/fem/discfuncarray/dfadapt.cc index 05124faedb2c3a1fb9b25b8f5648ca30dc6dc3d8..71b20913bb0beffb698fcbf02364f160a70cbc99 100644 --- a/fem/discfuncarray/dfadapt.cc +++ b/fem/discfuncarray/dfadapt.cc @@ -111,19 +111,21 @@ namespace Dune } template<class DiscreteFunctionSpaceType > - inline const typename DFAdapt<DiscreteFunctionSpaceType>::DofIteratorType + inline typename DFAdapt<DiscreteFunctionSpaceType>::ConstDofIteratorType DFAdapt< DiscreteFunctionSpaceType >::dbegin ( ) const { DofIteratorType tmp ( dofVec_ , 0 ); - return tmp; + ConstDofIteratorType tmp2(tmp); + return tmp2; } template<class DiscreteFunctionSpaceType > - inline const typename DFAdapt<DiscreteFunctionSpaceType>::DofIteratorType + inline typename DFAdapt<DiscreteFunctionSpaceType>::ConstDofIteratorType DFAdapt< DiscreteFunctionSpaceType >::dend () const { DofIteratorType tmp ( dofVec_ , dofVec_.size() ); - return tmp; + ConstDofIteratorType tmp2(tmp); + return tmp2; } //************************************************************************** // Read and Write Methods diff --git a/fem/discfuncarray/discfuncarray.cc b/fem/discfuncarray/discfuncarray.cc index 018bbab2538a3df307daaf7deda63da5af8f3dc2..ad5c3bab4a4cbd1946268b158fcb832394b2c4bd 100644 --- a/fem/discfuncarray/discfuncarray.cc +++ b/fem/discfuncarray/discfuncarray.cc @@ -149,19 +149,21 @@ namespace Dune } template<class DiscreteFunctionSpaceType > - inline const typename DiscFuncArray<DiscreteFunctionSpaceType>::DofIteratorType + inline typename DiscFuncArray<DiscreteFunctionSpaceType>::ConstDofIteratorType DiscFuncArray< DiscreteFunctionSpaceType >::dbegin ( ) const { DofIteratorType tmp ( dofVec_ , 0 ); - return tmp; + ConstDofIteratorType tmp2(tmp); + return tmp2; } template<class DiscreteFunctionSpaceType > - inline const typename DiscFuncArray<DiscreteFunctionSpaceType>::DofIteratorType + inline typename DiscFuncArray<DiscreteFunctionSpaceType>::ConstDofIteratorType DiscFuncArray< DiscreteFunctionSpaceType >::dend ( ) const { DofIteratorType tmp ( dofVec_ , dofVec_.size() ); - return tmp; + ConstDofIteratorType tmp2(tmp); + return tmp2; } //************************************************************************** // Read and Write Methods diff --git a/fem/feop/spmatrix.cc b/fem/feop/spmatrix.cc index 0c5e8ee877d42cee1fbc72946235af3a1e3a8010..e545bd7b758b42092aaabec60a5ae84fba14e94e 100644 --- a/fem/feop/spmatrix.cc +++ b/fem/feop/spmatrix.cc @@ -320,11 +320,12 @@ namespace Dune { typedef typename DiscFType::DofIteratorType DofFItType; typedef typename DiscFuncType::DofIteratorType DofIteratorType; + typedef typename DiscFuncType::ConstDofIteratorType ConstDofIteratorType; //! we assume that the dimension of the functionspace of f is the same as //! the size of the matrix DofIteratorType ret_it = ret.dbegin(); - const DofFItType f_it = f.dbegin(); + ConstDofIteratorType f_it = f.dbegin(); for(int row=0; row<dim_[0]; row++) {