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 
00006 #include <dune/common/misc.hh>
00007 #include <dune/grid/common/capabilities.hh>
00008 #include <dune/common/collectivecommunication.hh>
00009 #include <dune/grid/common/grid.hh>
00010 
00011 
00016 namespace Dune 
00017 {
00018 
00019 // forward declarations 
00020     template<int codim, int dim, class GridImp> class OneDGridEntity;
00021     template<int codim, class GridImp> class OneDGridEntityPointer;
00022     template<int codim, PartitionIteratorType pitype, class GridImp> class OneDGridLevelIterator;
00023 
00024     template<int mydim, int coorddim, class GridImp>            class OneDGridGeometry;
00025     template<class GridImp>            class OneDGridHierarchicIterator;
00026     template<class GridImp, bool LeafIterator> class OneDGridIntersectionIterator;
00027     class OneDGrid;
00028 
00029     template<int codim>                        class OneDGridLevelIteratorFactory;
00030 
00031 }  // namespace Dune
00032 
00033 #include "onedgrid/onedgridentity.hh"
00034 #include "onedgrid/onedgridentitypointer.hh"
00035 #include "onedgrid/onedgridgeometry.hh"
00036 #include "onedgrid/onedintersectionit.hh"
00037 #include "onedgrid/onedgridleveliterator.hh"
00038 #include "onedgrid/onedgridleafiterator.hh"
00039 #include "onedgrid/onedgridhieriterator.hh"
00040 #include "onedgrid/onedgridindexsets.hh"
00041 
00042 namespace Dune {
00043 
00044     // A simple double linked list
00045     template<class T>
00046     class List
00047     {
00048         
00049     public:
00050 
00051         List() : numelements(0), begin(0), rbegin(0) {}
00052 
00053         int size() const {return numelements;}
00054         
00055         T* insert_after (T* i, T* t) {
00056 
00057             // Teste Eingabe
00058             if (i==0 && begin!=0)
00059                 DUNE_THROW(DoubleLinkedListError, "invalid iterator for insert_after");
00060 
00061             // einfuegen
00062             if (begin==0) {
00063     // einfuegen in leere Liste
00064     begin = t; 
00065                 rbegin = t;
00066             }
00067             else 
00068                 {
00069                     // nach Element i.p einsetzen
00070                     t->pred_ = i;
00071                     t->succ_ = i->succ_;
00072                     i->succ_ = t;
00073 
00074                     if (t->succ_!=0) 
00075                         t->succ_->pred_ = t;
00076 
00077                     // tail neu ?
00078                     if (rbegin==i) 
00079                         rbegin = t;
00080                 }
00081 
00082             // Groesse und Rueckgabeiterator
00083             numelements = numelements+1;
00084 
00085             return t;
00086         }
00087 
00088         T* insert_before (T* i, T* t) {
00089 
00090             // Teste Eingabe
00091             if (i==0 && begin!=0) 
00092                 DUNE_THROW(DoubleLinkedListError, 
00093                            "invalid iterator for insert_before");
00094             
00095             // einfuegen
00096             if (begin==0) 
00097                 {
00098                     // einfuegen in leere Liste
00099                     begin=t; 
00100                     rbegin=t;
00101                 }
00102             else 
00103                 {
00104                     // vor Element i.p einsetzen
00105                     t->succ_ = i;
00106                     t->pred_ = i->pred_;
00107                     i->pred_ = t;
00108 
00109                     if (t->pred_!=0) 
00110                         t->pred_->succ_ = t;
00111                     // head neu ?
00112                     if (begin==i) 
00113                         begin = t;
00114                 }
00115             
00116             // Groesse und Rueckgabeiterator
00117             numelements = numelements+1;
00118             return t;
00119         }
00120 
00121         void remove (T* i)
00122         {
00123             // Teste Eingabe
00124             if (i==0)
00125                 return;
00126             
00127             // Ausfaedeln
00128             if (i->succ_!=0) 
00129                 i->succ_->pred_ = i->pred_;
00130             if (i->pred_!=0) 
00131                 i->pred_->succ_ = i->succ_;
00132             
00133             // head & tail
00134             if (begin==i) 
00135                 begin=i->succ_;
00136             if (rbegin==i) 
00137                 rbegin = i->pred_;
00138             
00139             // Groesse
00140             numelements = numelements-1;
00141         }
00142 
00143 
00144         int numelements;
00145 
00146         T* begin;
00147         T* rbegin;
00148 
00149     };
00150 
00151 template<int dim, int dimw>
00152 struct OneDGridFamily
00153 {
00154     typedef GridTraits<dim,dimw,Dune::OneDGrid,
00155                        OneDGridGeometry,
00156                        OneDGridEntity,
00157                        OneDGridEntityPointer,
00158                        OneDGridLevelIterator,
00159                        OneDGridLeafIntersectionIterator, // leaf  intersection iter 
00160                        OneDGridLevelIntersectionIterator, // level intersection iter 
00161                        OneDGridHierarchicIterator,
00162                        OneDGridLeafIterator,
00163                        OneDGridLevelIndexSet<const OneDGrid>,
00164              OneDGridLevelIndexSetTypes<const OneDGrid>,
00165                        OneDGridLeafIndexSet<const OneDGrid>,
00166              OneDGridLeafIndexSetTypes<const OneDGrid>,
00167                        OneDGridIdSet<const OneDGrid>,
00168                        unsigned int,
00169                        OneDGridIdSet<const OneDGrid>,
00170                        unsigned int,
00171              CollectiveCommunication<Dune::OneDGrid> > 
00172   Traits;
00173 };
00174 
00175 //**********************************************************************
00176 //
00177 // --OneDGrid
00178 //
00179 //**********************************************************************
00180 
00192 class OneDGrid : public GridDefaultImplementation <1, 1,double,OneDGridFamily<1,1> >
00193 {
00194     // Grid and world dimension are hardwired in this grid
00195     enum {dim = 1};
00196     enum {dimworld = 1};
00197 
00198     friend class OneDGridLevelIteratorFactory <0>;
00199     friend class OneDGridLevelIteratorFactory <1>;
00200     friend class OneDGridEntity <0,dim,OneDGrid>;
00201     friend class OneDGridEntity <dim,dim,OneDGrid>;
00202     friend class OneDGridHierarchicIterator<OneDGrid>;
00203     friend class OneDGridLeafIntersectionIterator<OneDGrid>;
00204     friend class OneDGridLevelIntersectionIterator<OneDGrid>;
00205 
00206     friend class OneDGridLevelIndexSet<const OneDGrid>;
00207     friend class OneDGridLeafIndexSet<const OneDGrid>;
00208     friend class OneDGridIdSet<const OneDGrid>;
00209 
00210     template <int codim_, PartitionIteratorType PiType_, class GridImp_>
00211     friend class OneDGridLeafIterator;
00212 
00213     template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
00214     friend class Entity;
00215 
00216     // **********************************************************
00217     // The Interface Methods
00218     // **********************************************************
00219 
00220 public:  
00221 
00228     typedef double ctype;
00229 
00231     typedef OneDGridFamily<dim,dimworld> GridFamily;
00232 
00234     typedef OneDGridFamily<dim,dimworld>::Traits Traits;
00235 
00237     OneDGrid(const std::vector<ctype>& coords);
00238 
00240     OneDGrid(int numElements, const ctype& leftBoundary, const ctype& rightBoundary);
00241 
00243     ~OneDGrid();
00244    
00249     int maxLevel() const {return vertices.size()-1;}
00250 
00252   template<int codim>
00253   typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
00254 
00256   template<int codim>
00257   typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
00258 
00260     template<int codim, PartitionIteratorType PiType>
00261     typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
00262 
00264     template<int codim, PartitionIteratorType PiType>
00265     typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
00266 
00268   template<int codim>
00269   typename Traits::template Codim<codim>::LeafIterator leafbegin () const;
00270 
00272   template<int codim>
00273   typename Traits::template Codim<codim>::LeafIterator leafend () const;
00274 
00276     template<int codim, PartitionIteratorType PiType>
00277     typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const;
00278 
00280     template<int codim, PartitionIteratorType PiType>
00281     typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const;
00282 
00285     int size (int level, int codim) const {
00286         if (codim<0 || codim>1)
00287             DUNE_THROW(GridError, "There are no codim " << codim << " entities in a OneDGrid!");
00288 
00289         if (codim==0)
00290             return elements[level].size();
00291         
00292         return vertices[level].size();
00293     }
00294 
00295 
00296 
00298   int size (int codim) const
00299   {
00300       return leafIndexSet().size(codim);
00301   }
00302 
00304   int size (int level, GeometryType type) const
00305   {
00306       // There is only one type for each codim
00307       return size(level,1-type.dim());
00308   }
00309 
00311   int size (GeometryType type) const
00312   {
00313       return leafIndexSet().size(type);
00314   }
00315 
00318     int overlapSize(int codim) const {
00319         return 0;
00320     }
00321 
00324     int ghostSize(int codim) const {
00325         return 0;
00326     }
00327 
00330     int overlapSize(int level, int codim) const {
00331         return 0;
00332     }
00333 
00336     int ghostSize(int level, int codim) const {
00337         return 0;
00338     }
00339 
00341     const Traits::GlobalIdSet& globalIdSet() const
00342     {
00343         return idSet_;
00344     }
00345 
00347     const Traits::LocalIdSet& localIdSet() const
00348     {
00349         return idSet_;
00350     }
00351 
00353     const Traits::LevelIndexSet& levelIndexSet(int level) const
00354     {
00355         if (! levelIndexSets_[level]) {
00356             levelIndexSets_[level] =
00357                 new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
00358             levelIndexSets_[level]->update();
00359         }
00360 
00361         return * levelIndexSets_[level];
00362     }
00363 
00365     const Traits::LeafIndexSet& leafIndexSet() const
00366     {
00367         return leafIndexSet_;
00368     }
00369 
00370 
00378     bool mark(int refCount, const Traits::Codim<0>::EntityPointer& e );
00379 
00386     int getMark(const Traits::Codim<0>::EntityPointer & e ) const;
00387 
00389     bool preAdapt();
00390 
00392     bool adapt();
00393 
00395     void postAdapt();
00396 
00398     std::string name () const { return "OneDGrid"; }
00399     
00400     // **********************************************************
00401     // End of Interface Methods
00402     // **********************************************************
00403     
00405     enum RefinementType {
00407         LOCAL,
00409         COPY};
00410 
00412     void setRefinementType(RefinementType type) {
00413         refinementType_ = type;
00414     }
00415 
00421     void globalRefine(int refCount);
00422 
00423   // dummy parallel functions
00424 
00425   template<class DataHandle>
00426   void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
00427   {
00428   }
00429 
00430   template<class DataHandle>
00431   void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
00432   {
00433   }
00434 
00435   const CollectiveCommunication<OneDGrid>& comm () const
00436   {
00437   return ccobj;
00438   }
00439 
00440 
00441 private:
00442 
00443   CollectiveCommunication<OneDGrid> ccobj;
00444 
00446     void setIndices();
00447 
00448     unsigned int getNextFreeId(int codim) {
00449         return (codim==0) ? freeElementIdCounter_++ : freeVertexIdCounter_++;
00450     }
00451         
00453     RefinementType refinementType_;
00454 
00455     OneDEntityImp<0>* getLeftUpperVertex(const OneDEntityImp<1>* eIt);
00456 
00457     OneDEntityImp<0>* getRightUpperVertex(const OneDEntityImp<1>* eIt);
00458 
00462     OneDEntityImp<1>* getLeftNeighborWithSon(OneDEntityImp<1>* eIt);
00463 
00464     // The vertices of the grid hierarchy
00465     std::vector<List<OneDEntityImp<0> > > vertices;
00466 
00467     // The elements of the grid hierarchy
00468     std::vector<List<OneDEntityImp<1> > > elements;
00469 
00470     // Our set of level indices
00471     mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
00472 
00473     OneDGridLeafIndexSet<const OneDGrid> leafIndexSet_;
00474 
00475     OneDGridIdSet<const OneDGrid> idSet_;
00476 
00477     unsigned int freeVertexIdCounter_;
00478 
00479     unsigned int freeElementIdCounter_;
00480 
00481 }; // end Class OneDGrid
00482 
00483 namespace Capabilities
00484 {
00496   template<int cdim>
00497   struct hasEntity< OneDGrid, cdim >
00498   {
00499     static const bool v = true;
00500   };
00501   
00505   template<>
00506   struct isParallel< OneDGrid >
00507   {
00508     static const bool v = false;
00509   };
00510 
00514   template<>
00515   struct isLevelwiseConforming< OneDGrid >
00516   {
00517     static const bool v = true;
00518   };
00519 
00523   template<>
00524   struct isLeafwiseConforming< OneDGrid >
00525   {
00526     static const bool v = true;
00527   };
00528 
00532   template<>
00533   struct hasHangingNodes< OneDGrid >
00534   {
00535     static const bool v = false;
00536   };
00537 
00538 }
00539 
00540 } // namespace Dune
00541 
00542 #endif

Generated on 9 Apr 2008 with Doxygen (ver 1.5.2) [logfile].