dune-grid  2.2beta1
onedgrid.hh
Go to the documentation of this file.
00001 #ifndef DUNE_ONE_D_GRID_HH
00002 #define DUNE_ONE_D_GRID_HH
00003 
00004 #include <vector>
00005 #include <list>
00006 
00007 #include <dune/common/misc.hh>
00008 #include <dune/common/collectivecommunication.hh>
00009 #include <dune/common/tuples.hh>
00010 
00011 #include <dune/grid/common/capabilities.hh>
00012 #include <dune/grid/common/grid.hh>
00013 #include <dune/grid/common/gridfactory.hh>
00014 
00015 #include <dune/geometry/genericgeometry/topologytypes.hh>
00016 
00021 #include "onedgrid/onedgridlist.hh"
00022 #include "onedgrid/nulliteratorfactory.hh"
00023 #include "onedgrid/onedgridentity.hh"
00024 #include "onedgrid/onedgridentitypointer.hh"
00025 #include "onedgrid/onedgridentityseed.hh"
00026 #include "onedgrid/onedgridgeometry.hh"
00027 #include "onedgrid/onedgridintersections.hh"
00028 #include "onedgrid/onedgridintersectioniterators.hh"
00029 #include "onedgrid/onedgridleveliterator.hh"
00030 #include "onedgrid/onedgridleafiterator.hh"
00031 #include "onedgrid/onedgridhieriterator.hh"
00032 #include "onedgrid/onedgridindexsets.hh"
00033 
00034 namespace Dune {
00035 
00036     class OneDGrid;
00037 
00038 template<int dim, int dimw>
00039 struct OneDGridFamily
00040 {
00041     typedef GridTraits<dim,dimw,Dune::OneDGrid,
00042                        OneDGridGeometry,
00043                        OneDGridEntity,
00044                        OneDGridEntityPointer,
00045                        OneDGridLevelIterator,
00046                        OneDGridLeafIntersection,
00047                        OneDGridLevelIntersection,
00048                        OneDGridLeafIntersectionIterator,
00049                        OneDGridLevelIntersectionIterator,
00050                        OneDGridHierarchicIterator,
00051                        OneDGridLeafIterator,
00052                        OneDGridLevelIndexSet<const OneDGrid>,
00053                        OneDGridLeafIndexSet<const OneDGrid>,
00054                        OneDGridIdSet<const OneDGrid>,
00055                        unsigned int,
00056                        OneDGridIdSet<const OneDGrid>,
00057                        unsigned int,
00058                        CollectiveCommunication<Dune::OneDGrid>,
00059                        DefaultLevelGridViewTraits,
00060                        DefaultLeafGridViewTraits,
00061                        OneDGridEntitySeed> 
00062   Traits;
00063 };
00064 
00065 //**********************************************************************
00066 //
00067 // --OneDGrid
00068 //
00069 //**********************************************************************
00070 
00081 class OneDGrid : public GridDefaultImplementation <1, 1,double,OneDGridFamily<1,1> >
00082 {
00083     // Grid and world dimension are hardwired in this grid
00084     enum {dim = 1};
00085     enum {dimworld = 1};
00086 
00087     template <int, class >
00088     friend class OneDGridEntityPointer;
00089 
00090     template <int , PartitionIteratorType, class >
00091     friend class OneDGridLevelIterator;
00092 
00093     friend class OneDGridHierarchicIterator<const OneDGrid>;
00094 
00095     template <int codim_, int dim_, class GridImp_>
00096     friend class OneDGridEntity;
00097     friend class OneDGridHierarchicIterator<OneDGrid>;
00098     friend class OneDGridLeafIntersection<const OneDGrid>;
00099     friend class OneDGridLevelIntersection<const OneDGrid>;
00100     friend class OneDGridLeafIntersectionIterator<const OneDGrid>;
00101     friend class OneDGridLevelIntersectionIterator<const OneDGrid>;
00102 
00103     friend class OneDGridLevelIndexSet<const OneDGrid>;
00104     friend class OneDGridLeafIndexSet<const OneDGrid>;
00105     friend class OneDGridIdSet<const OneDGrid>;
00106 
00107     template <int codim_, PartitionIteratorType PiType_, class GridImp_>
00108     friend class OneDGridLeafIterator;
00109 
00110     template <class GridType_>
00111     friend class GridFactory;
00112 
00113     template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
00114     friend class Entity;
00115 
00117     OneDGrid();
00118 
00119     // **********************************************************
00120     // The Interface Methods
00121     // **********************************************************
00122 
00123 public:  
00124 
00131     typedef double ctype;
00132 
00134     typedef OneDGridFamily<dim,dimworld> GridFamily;
00135 
00136     //Provides the standard grid types 
00137     typedef OneDGridFamily<dim,dimworld>::Traits Traits;
00138 
00140     OneDGrid(const std::vector<ctype>& coords);
00141 
00143     OneDGrid(int numElements, const ctype& leftBoundary, const ctype& rightBoundary);
00144 
00146     ~OneDGrid();
00147    
00152     int maxLevel() const {return entityImps_.size()-1;}
00153 
00155   template<int codim>
00156   typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
00157 
00159   template<int codim>
00160   typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
00161 
00163     template<int codim, PartitionIteratorType PiType>
00164     typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
00165 
00167     template<int codim, PartitionIteratorType PiType>
00168     typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
00169 
00171   template<int codim>
00172   typename Traits::template Codim<codim>::LeafIterator leafbegin () const;
00173 
00175   template<int codim>
00176   typename Traits::template Codim<codim>::LeafIterator leafend () const;
00177 
00179     template<int codim, PartitionIteratorType PiType>
00180     typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const;
00181 
00183     template<int codim, PartitionIteratorType PiType>
00184     typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const;
00185 
00187     template <int codim>
00188     static typename Traits::template Codim<codim>::EntityPointer
00189     entityPointer(const OneDGridEntitySeed<codim, const OneDGrid>& seed)
00190     {
00191         return typename Traits::template Codim<codim>::EntityPointer(seed.target());
00192     }
00193 
00194 
00197     int size (int level, int codim) const {
00198         if (codim<0 || codim>1)
00199             DUNE_THROW(GridError, "There are no codim " << codim << " entities in a OneDGrid!");
00200 
00201         if (codim==0)
00202             return elements(level).size();
00203         
00204         return vertices(level).size();
00205     }
00206 
00207 
00208 
00210   int size (int codim) const
00211   {
00212       return leafIndexSet().size(codim);
00213   }
00214 
00216   int size (int level, GeometryType type) const
00217   {
00218       // There is only one type for each codim
00219       return size(level,1-type.dim());
00220   }
00221 
00223   int size (GeometryType type) const
00224   {
00225       return leafIndexSet().size(type);
00226   }
00227 
00233     size_t numBoundarySegments() const
00234     {
00235         return 2;
00236     }
00237 
00240     int overlapSize(int codim) const {
00241         return 0;
00242     }
00243 
00246     int ghostSize(int codim) const {
00247         return 0;
00248     }
00249 
00252     int overlapSize(int level, int codim) const {
00253         return 0;
00254     }
00255 
00258     int ghostSize(int level, int codim) const {
00259         return 0;
00260     }
00261 
00263     const Traits::GlobalIdSet& globalIdSet() const
00264     {
00265         return idSet_;
00266     }
00267 
00269     const Traits::LocalIdSet& localIdSet() const
00270     {
00271         return idSet_;
00272     }
00273 
00275     const Traits::LevelIndexSet& levelIndexSet(int level) const
00276     {
00277         if (! levelIndexSets_[level]) {
00278             levelIndexSets_[level] =
00279                 new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
00280             levelIndexSets_[level]->update();
00281         }
00282 
00283         return * levelIndexSets_[level];
00284     }
00285 
00287     const Traits::LeafIndexSet& leafIndexSet() const
00288     {
00289         return leafIndexSet_;
00290     }
00291 
00292 
00300     bool mark(int refCount, const Traits::Codim<0>::Entity& e );
00301 
00308     int getMark(const Traits::Codim<0>::Entity& e ) const;
00309 
00311     bool preAdapt();
00312 
00314     bool adapt();
00315 
00317     void postAdapt();
00318 
00319     // **********************************************************
00320     // End of Interface Methods
00321     // **********************************************************
00322     
00324     enum RefinementType {
00326         LOCAL,
00328         COPY};
00329 
00331     void setRefinementType(RefinementType type) {
00332         refinementType_ = type;
00333     }
00334 
00340     void globalRefine(int refCount);
00341 
00342   // dummy parallel functions
00343 
00344   template<class DataHandle>
00345   void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
00346   {
00347   }
00348 
00349   template<class DataHandle>
00350   void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
00351   {
00352   }
00353 
00354   const CollectiveCommunication &comm () const
00355   {
00356   return ccobj;
00357   }
00358 
00359 
00360 private:
00361 
00363     OneDGridList<OneDEntityImp<0> >& vertices(int level) {
00364         return Dune::get<0>(entityImps_[level]);
00365     }
00366 
00368     const OneDGridList<OneDEntityImp<0> >& vertices(int level) const {
00369         return Dune::get<0>(entityImps_[level]);
00370     }
00371 
00373     OneDGridList<OneDEntityImp<1> >& elements(int level) {
00374         return Dune::get<1>(entityImps_[level]);
00375     }
00376 
00378     const OneDGridList<OneDEntityImp<1> >& elements(int level) const {
00379         return Dune::get<1>(entityImps_[level]);
00380     }
00381 
00382   CollectiveCommunication ccobj;
00383 
00385     void setIndices();
00386 
00387     unsigned int getNextFreeId(int codim) {
00388         return (codim==0) ? freeElementIdCounter_++ : freeVertexIdCounter_++;
00389     }
00390         
00392     RefinementType refinementType_;
00393 
00394     OneDGridList<OneDEntityImp<0> >::iterator getLeftUpperVertex(const OneDEntityImp<1>* eIt);
00395 
00396     OneDGridList<OneDEntityImp<0> >::iterator getRightUpperVertex(const OneDEntityImp<1>* eIt);
00397 
00401     OneDGridList<OneDEntityImp<1> >::iterator getLeftNeighborWithSon(OneDGridList<OneDEntityImp<1> >::iterator eIt);
00402 
00403     // The vertices and elements of the grid hierarchy
00404     std::vector<tuple<OneDGridList<OneDEntityImp<0> >,
00405                       OneDGridList<OneDEntityImp<1> > > > entityImps_;
00406 
00407     // Our set of level indices
00408     mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
00409 
00410     OneDGridLeafIndexSet<const OneDGrid> leafIndexSet_;
00411 
00412     OneDGridIdSet<const OneDGrid> idSet_;
00413 
00414     unsigned int freeVertexIdCounter_;
00415 
00416     unsigned int freeElementIdCounter_;
00417 
00421     bool reversedBoundarySegmentNumbering_;
00422 
00423 }; // end Class OneDGrid
00424 
00425 namespace Capabilities
00426 {
00438   template< >
00439   struct hasSingleGeometryType< OneDGrid >
00440   {
00441     static const bool v = true;
00442     static const unsigned int topologyId = GenericGeometry :: CubeTopology< 1 > :: type :: id ;
00443   };
00444 
00445 
00449   template<int cdim>
00450   struct hasEntity< OneDGrid, cdim >
00451   {
00452     static const bool v = true;
00453   };
00454   
00458   template<>
00459   struct isParallel< OneDGrid >
00460   {
00461     static const bool v = false;
00462   };
00463 
00467   template<>
00468   struct isLevelwiseConforming< OneDGrid >
00469   {
00470     static const bool v = true;
00471   };
00472 
00476   template<>
00477   struct isLeafwiseConforming< OneDGrid >
00478   {
00479     static const bool v = true;
00480   };
00481 
00482 }
00483 
00484 } // namespace Dune
00485 
00486 // Include the GridFactory specialization for OneDGrid, so everybody
00487 // who includes the grid also gets the factory.  Since OneDGrid is
00488 // not a template class, it needs to be a complete type before
00489 // GridFactory<OneDGrid> can be defined.  This is why the #include-
00490 // directive is at _the end_ of this file.
00491 #include <dune/grid/onedgrid/onedgridfactory.hh>
00492 
00493 
00494 #endif