- Home
- About DUNE
- Download
- Documentation
- Community
- Development
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 #include <dune/grid/genericgeometry/topologytypes.hh> 00015 00020 #include "onedgrid/onedgridlist.hh" 00021 #include "onedgrid/nulliteratorfactory.hh" 00022 #include "onedgrid/onedgridentity.hh" 00023 #include "onedgrid/onedgridentitypointer.hh" 00024 #include "onedgrid/onedgridgeometry.hh" 00025 #include "onedgrid/onedgridintersections.hh" 00026 #include "onedgrid/onedgridintersectioniterators.hh" 00027 #include "onedgrid/onedgridleveliterator.hh" 00028 #include "onedgrid/onedgridleafiterator.hh" 00029 #include "onedgrid/onedgridhieriterator.hh" 00030 #include "onedgrid/onedgridindexsets.hh" 00031 00032 namespace Dune { 00033 00034 class OneDGrid; 00035 00036 template<int dim, int dimw> 00037 struct OneDGridFamily 00038 { 00039 typedef GridTraits<dim,dimw,Dune::OneDGrid, 00040 OneDGridGeometry, 00041 OneDGridEntity, 00042 OneDGridEntityPointer, 00043 OneDGridLevelIterator, 00044 OneDGridLeafIntersection, 00045 OneDGridLevelIntersection, 00046 OneDGridLeafIntersectionIterator, 00047 OneDGridLevelIntersectionIterator, 00048 OneDGridHierarchicIterator, 00049 OneDGridLeafIterator, 00050 OneDGridLevelIndexSet<const OneDGrid>, 00051 OneDGridLeafIndexSet<const OneDGrid>, 00052 OneDGridIdSet<const OneDGrid>, 00053 unsigned int, 00054 OneDGridIdSet<const OneDGrid>, 00055 unsigned int, 00056 CollectiveCommunication<Dune::OneDGrid> > 00057 Traits; 00058 }; 00059 00060 //********************************************************************** 00061 // 00062 // --OneDGrid 00063 // 00064 //********************************************************************** 00065 00076 class OneDGrid : public GridDefaultImplementation <1, 1,double,OneDGridFamily<1,1> > 00077 { 00078 // Grid and world dimension are hardwired in this grid 00079 enum {dim = 1}; 00080 enum {dimworld = 1}; 00081 00082 template <int, class > 00083 friend class OneDGridEntityPointer; 00084 00085 template <int , PartitionIteratorType, class > 00086 friend class OneDGridLevelIterator; 00087 00088 friend class OneDGridHierarchicIterator<const OneDGrid>; 00089 00090 template <int codim_, int dim_, class GridImp_> 00091 friend class OneDGridEntity; 00092 friend class OneDGridHierarchicIterator<OneDGrid>; 00093 friend class OneDGridLeafIntersection<const OneDGrid>; 00094 friend class OneDGridLevelIntersection<const OneDGrid>; 00095 friend class OneDGridLeafIntersectionIterator<const OneDGrid>; 00096 friend class OneDGridLevelIntersectionIterator<const OneDGrid>; 00097 00098 friend class OneDGridLevelIndexSet<const OneDGrid>; 00099 friend class OneDGridLeafIndexSet<const OneDGrid>; 00100 friend class OneDGridIdSet<const OneDGrid>; 00101 00102 template <int codim_, PartitionIteratorType PiType_, class GridImp_> 00103 friend class OneDGridLeafIterator; 00104 00105 template <class GridType_> 00106 friend class GridFactory; 00107 00108 template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_> 00109 friend class Entity; 00110 00112 OneDGrid(); 00113 00114 // ********************************************************** 00115 // The Interface Methods 00116 // ********************************************************** 00117 00118 public: 00119 00126 typedef double ctype; 00127 00129 typedef OneDGridFamily<dim,dimworld> GridFamily; 00130 00131 //Provides the standard grid types 00132 typedef OneDGridFamily<dim,dimworld>::Traits Traits; 00133 00135 OneDGrid(const std::vector<ctype>& coords); 00136 00138 OneDGrid(int numElements, const ctype& leftBoundary, const ctype& rightBoundary); 00139 00141 ~OneDGrid(); 00142 00147 int maxLevel() const {return entityImps_.size()-1;} 00148 00150 template<int codim> 00151 typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const; 00152 00154 template<int codim> 00155 typename Traits::template Codim<codim>::LevelIterator lend (int level) const; 00156 00158 template<int codim, PartitionIteratorType PiType> 00159 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const; 00160 00162 template<int codim, PartitionIteratorType PiType> 00163 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const; 00164 00166 template<int codim> 00167 typename Traits::template Codim<codim>::LeafIterator leafbegin () const; 00168 00170 template<int codim> 00171 typename Traits::template Codim<codim>::LeafIterator leafend () const; 00172 00174 template<int codim, PartitionIteratorType PiType> 00175 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const; 00176 00178 template<int codim, PartitionIteratorType PiType> 00179 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const; 00180 00183 int size (int level, int codim) const { 00184 if (codim<0 || codim>1) 00185 DUNE_THROW(GridError, "There are no codim " << codim << " entities in a OneDGrid!"); 00186 00187 if (codim==0) 00188 return elements(level).size(); 00189 00190 return vertices(level).size(); 00191 } 00192 00193 00194 00196 int size (int codim) const 00197 { 00198 return leafIndexSet().size(codim); 00199 } 00200 00202 int size (int level, GeometryType type) const 00203 { 00204 // There is only one type for each codim 00205 return size(level,1-type.dim()); 00206 } 00207 00209 int size (GeometryType type) const 00210 { 00211 return leafIndexSet().size(type); 00212 } 00213 00219 size_t numBoundarySegments() const 00220 { 00221 return 2; 00222 } 00223 00226 int overlapSize(int codim) const { 00227 return 0; 00228 } 00229 00232 int ghostSize(int codim) const { 00233 return 0; 00234 } 00235 00238 int overlapSize(int level, int codim) const { 00239 return 0; 00240 } 00241 00244 int ghostSize(int level, int codim) const { 00245 return 0; 00246 } 00247 00249 const Traits::GlobalIdSet& globalIdSet() const 00250 { 00251 return idSet_; 00252 } 00253 00255 const Traits::LocalIdSet& localIdSet() const 00256 { 00257 return idSet_; 00258 } 00259 00261 const Traits::LevelIndexSet& levelIndexSet(int level) const 00262 { 00263 if (! levelIndexSets_[level]) { 00264 levelIndexSets_[level] = 00265 new OneDGridLevelIndexSet<const OneDGrid>(*this, level); 00266 levelIndexSets_[level]->update(); 00267 } 00268 00269 return * levelIndexSets_[level]; 00270 } 00271 00273 const Traits::LeafIndexSet& leafIndexSet() const 00274 { 00275 return leafIndexSet_; 00276 } 00277 00278 00286 bool mark(int refCount, const Traits::Codim<0>::Entity& e ); 00287 00294 int getMark(const Traits::Codim<0>::Entity& e ) const; 00295 00297 bool preAdapt(); 00298 00300 bool adapt(); 00301 00303 void postAdapt(); 00304 00306 std::string name () const DUNE_DEPRECATED { return "OneDGrid"; } 00307 00308 // ********************************************************** 00309 // End of Interface Methods 00310 // ********************************************************** 00311 00313 enum RefinementType { 00315 LOCAL, 00317 COPY}; 00318 00320 void setRefinementType(RefinementType type) { 00321 refinementType_ = type; 00322 } 00323 00329 void globalRefine(int refCount); 00330 00331 // dummy parallel functions 00332 00333 template<class DataHandle> 00334 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const 00335 { 00336 } 00337 00338 template<class DataHandle> 00339 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const 00340 { 00341 } 00342 00343 const CollectiveCommunication &comm () const 00344 { 00345 return ccobj; 00346 } 00347 00348 00349 private: 00350 00352 OneDGridList<OneDEntityImp<0> >& vertices(int level) { 00353 return Dune::get<0>(entityImps_[level]); 00354 } 00355 00357 const OneDGridList<OneDEntityImp<0> >& vertices(int level) const { 00358 return Dune::get<0>(entityImps_[level]); 00359 } 00360 00362 OneDGridList<OneDEntityImp<1> >& elements(int level) { 00363 return Dune::get<1>(entityImps_[level]); 00364 } 00365 00367 const OneDGridList<OneDEntityImp<1> >& elements(int level) const { 00368 return Dune::get<1>(entityImps_[level]); 00369 } 00370 00371 CollectiveCommunication ccobj; 00372 00374 void setIndices(); 00375 00376 unsigned int getNextFreeId(int codim) { 00377 return (codim==0) ? freeElementIdCounter_++ : freeVertexIdCounter_++; 00378 } 00379 00381 RefinementType refinementType_; 00382 00383 OneDGridList<OneDEntityImp<0> >::iterator getLeftUpperVertex(const OneDEntityImp<1>* eIt); 00384 00385 OneDGridList<OneDEntityImp<0> >::iterator getRightUpperVertex(const OneDEntityImp<1>* eIt); 00386 00390 OneDGridList<OneDEntityImp<1> >::iterator getLeftNeighborWithSon(OneDGridList<OneDEntityImp<1> >::iterator eIt); 00391 00392 // The vertices and elements of the grid hierarchy 00393 std::vector<tuple<OneDGridList<OneDEntityImp<0> >, 00394 OneDGridList<OneDEntityImp<1> > > > entityImps_; 00395 00396 // Our set of level indices 00397 mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_; 00398 00399 OneDGridLeafIndexSet<const OneDGrid> leafIndexSet_; 00400 00401 OneDGridIdSet<const OneDGrid> idSet_; 00402 00403 unsigned int freeVertexIdCounter_; 00404 00405 unsigned int freeElementIdCounter_; 00406 00410 bool reversedBoundarySegmentNumbering_; 00411 00412 }; // end Class OneDGrid 00413 00414 namespace Capabilities 00415 { 00427 template< > 00428 struct hasSingleGeometryType< OneDGrid > 00429 { 00430 static const bool v = true; 00431 static const unsigned int topologyId = GenericGeometry :: CubeTopology< 1 > :: type :: id ; 00432 }; 00433 00434 00438 template<int cdim> 00439 struct hasEntity< OneDGrid, cdim > 00440 { 00441 static const bool v = true; 00442 }; 00443 00447 template<> 00448 struct isParallel< OneDGrid > 00449 { 00450 static const bool v = false; 00451 }; 00452 00456 template<> 00457 struct isLevelwiseConforming< OneDGrid > 00458 { 00459 static const bool v = true; 00460 }; 00461 00465 template<> 00466 struct isLeafwiseConforming< OneDGrid > 00467 { 00468 static const bool v = true; 00469 }; 00470 00471 } 00472 00473 } // namespace Dune 00474 00475 // Include the GridFactory specialization for OneDGrid, so everybody 00476 // who includes the grid also gets the factory. Since OneDGrid is 00477 // not a template class, it needs to be a complete type before 00478 // GridFactory<OneDGrid> can be defined. This is why the #include- 00479 // directive is at _the end_ of this file. 00480 #include <dune/grid/onedgrid/onedgridfactory.hh> 00481 00482 00483 #endif
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].