indexidset.hh

Go to the documentation of this file.
00001 // $Id: indexidset.hh 3467 2007-01-25 19:57:59Z oliver $
00002 
00003 #ifndef DUNE_INDEXIDSET_HH
00004 #define DUNE_INDEXIDSET_HH
00005 
00006 #include <iostream>
00007 #include <vector>
00008 #include <dune/common/exceptions.hh>
00009 #include <dune/common/helpertemplates.hh>
00010 
00011 #include <dune/common/bartonnackmanifcheck.hh>
00012 
00018 namespace Dune
00019 {
00073   template<class GridImp, class IndexSetImp, class IndexSetTypes>
00074   class IndexSet {
00075   public:
00078         template <int cd>
00079         struct Codim
00080         {
00081 
00083           template <PartitionIteratorType pitype>
00084           struct Partition
00085           {
00088                 typedef typename IndexSetTypes::template Codim<cd>::template Partition<pitype>::Iterator Iterator;
00089           };
00090         };
00091 
00092         //===========================================================
00096         //===========================================================
00097 
00104     /*
00105       We use the RemoveConst to extract the Type from the mutable class,
00106       because the const class is not instatiated yet.
00107     */
00108         template<int cc>
00109         int index (const typename RemoveConst<GridImp>::Type::
00110                Traits::template Codim<cc>::Entity& e) const 
00111         {
00112     CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
00113     return asImp().template index<cc>(e);
00114         }
00115 
00125     template<class EntityType>
00126     int index (const EntityType& e) const
00127     {
00128       enum { cc = EntityType::codimension };
00129       CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
00130       return asImp().template index<cc>(e);
00131     }
00132 
00141     /*
00142       We use the RemoveConst to extract the Type from the mutable class,
00143       because the const class is not instatiated yet.
00144     */
00145         template<int cc>
00146         int subIndex (const typename RemoveConst<GridImp>::Type::
00147                   Traits::template Codim<0>::Entity& e, int i) const
00148         {
00149     CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex<cc>(e,i)));
00150     return asImp().template subIndex<cc>(e,i);
00151         }
00153 
00154 
00155         //===========================================================
00159         //===========================================================
00160 
00168         const std::vector<GeometryType>& geomTypes (int codim) const
00169         {
00170     CHECK_INTERFACE_IMPLEMENTATION((asImp().geomTypes(codim)));
00171           return asImp().geomTypes(codim);
00172         }
00173 
00179         int size (GeometryType type) const
00180         {
00181     CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
00182     return asImp().size(type);
00183         }
00184 
00191     int size (int codim) const
00192     {
00193       CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
00194       return asImp().size(codim);
00195     }
00196 
00199     template<class EntityType>
00200     bool contains (const EntityType& e) const
00201     {
00202       CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
00203       return asImp().contains(e);
00204     }
00205 
00209         template<int cd, PartitionIteratorType pitype>
00210         typename Codim<cd>::template Partition<pitype>::Iterator begin () const
00211         {
00212     CHECK_INTERFACE_IMPLEMENTATION((asImp().begin<cd,pitype>()));
00213           return asImp().begin<cd,pitype>();
00214         }
00215   
00219         template<int cd, PartitionIteratorType pitype>
00220         typename Codim<cd>::template Partition<pitype>::Iterator end () const
00221         {
00222     CHECK_INTERFACE_IMPLEMENTATION((asImp().end<cd,pitype>()));
00223           return asImp().end<cd,pitype>();
00224         }
00226 
00227         // Must be explicitely defined although this class should get a default constructor.
00228     IndexSet() {}
00229 
00230   private:
00232     IndexSet(const IndexSet&);
00234     IndexSet& operator=(const IndexSet&);
00235 
00237           IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
00239           const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
00240   };
00241 
00242 #undef CHECK_INTERFACE_IMPLEMENTATION
00243 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
00244 
00248   template<class GridImp, class IndexSetImp, class IndexSetTypes>
00249   class IndexSetDefaultImplementation : 
00250     public IndexSet<GridImp,IndexSetImp,IndexSetTypes> 
00251   {
00252   public:
00255     template <int cd>
00256     struct Codim
00257     {
00258 
00260       template <PartitionIteratorType pitype>
00261       struct Partition
00262       {
00265       typedef typename IndexSetTypes::template Codim<cd>::template Partition<pitype>::Iterator Iterator;
00266       };
00267     };
00268 
00281     template<int cc>
00282     int subIndex (const typename RemoveConst<GridImp>::Type::
00283                     Traits::template Codim<0>::Entity& e, int i) const
00284     {
00285       return this->index( *(e.template entity<cc>(i) ));
00286     }
00287 
00295     int size (int codim) const
00296     {
00297       int s=0;
00298       const std::vector<GeometryType>& geomTs = asImp().geomTypes(codim); 
00299       for (unsigned int i=0; i<geomTs.size(); ++i)
00300       s += asImp().size(geomTs[i]);
00301       return s;
00302     }
00303 
00306     template<class EntityType>
00307     bool contains (const EntityType& e) const
00308     {
00309       enum { cd = EntityType::codimension };
00310       typedef typename Codim<cd>::template Partition<All_Partition>::Iterator IteratorType; 
00311       IteratorType iend = asImp().template end<cd,All_Partition>();
00312       for (IteratorType it = asImp().template begin<cd,All_Partition>();
00313            it != iend; ++it)
00314       {
00315         // this code is not really valid 
00316         if (it->level() == e.level() && this->index(*it) == this->index(e)) return true;
00317       }
00318       return false;
00319     }
00320 
00321   private:
00323           IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
00325           const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
00326   };
00327 
00328 
00396   template<class GridImp, class IdSetImp, class IdTypeImp>
00397   class IdSet
00398   {
00399   public:
00401         typedef IdTypeImp IdType;
00402 
00404     template<class EntityType>
00405     IdType id (const EntityType& e) const
00406     {
00407       enum { cc = EntityType::codimension };
00408       return asImp().template id<cc>(e);
00409     }
00410 
00412     /*
00413       We use the RemoveConst to extract the Type from the mutable class,
00414       because the const class is not instatiated yet.
00415     */
00416     template<int cc>
00417     IdType id (const typename RemoveConst<GridImp>::Type::
00418                  Traits::template Codim<cc>::Entity& e) const 
00419     {
00420       return asImp().template id<cc>(e);
00421     }
00422 
00424     /*
00425       We use the RemoveConst to extract the Type from the mutable class,
00426       because the const class is not instatiated yet.
00427     */
00428     template<int cc>
00429     IdType subId (const typename RemoveConst<GridImp>::Type::
00430                     Traits::template Codim<0>::Entity& e, int i) const
00431     {
00432       return asImp().template subId<cc>(e,i);
00433     }
00434 
00435     // Default constructor (is not provided automatically because copy constructor is private)
00436     IdSet() {}
00437 
00438    private:
00440     IdSet(const IdSet&);
00442     IdSet& operator=(const IdSet&);
00443 
00445           IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
00447           const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
00448   };
00449 
00463   template<class GridImp, class IdSetImp, class IdTypeImp>
00464   class IdSetDefaultImplementation : public IdSet<GridImp,IdSetImp,IdTypeImp>
00465   {
00466   public:
00468           typedef IdTypeImp IdType;
00469 
00471     /*
00472       We use the RemoveConst to extract the Type from the mutable class,
00473       because the const class is not instatiated yet.
00474       This default implementation uses the entities entity method. This is
00475       slow but works by default for ervery id set imeplementation.
00476     */
00477     template<int cc>
00478     IdType subId (const typename RemoveConst<GridImp>::Type::
00479                     Traits::template Codim<0>::Entity& e, int i) const
00480     {
00481       return this->id( *(e.template entity<cc>(i)) );
00482     }
00483   };
00484 
00485 
00486 }
00487 #endif

Generated on 12 Dec 2007 with Doxygen (ver 1.5.1)