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/grid/common/capabilities.hh>
00009 #include <dune/common/collectivecommunication.hh>
00010 #include <dune/grid/common/grid.hh>
00011
00012
00017 namespace Dune
00018 {
00019
00020
00021 template<int codim, int dim, class GridImp> class OneDGridEntity;
00022 template<int codim, class GridImp> class OneDGridEntityPointer;
00023 template<int codim, PartitionIteratorType pitype, class GridImp> class OneDGridLevelIterator;
00024
00025 template<int mydim, int coorddim, class GridImp> class OneDGridGeometry;
00026 template<class GridImp> class OneDGridHierarchicIterator;
00027 template<class GridImp, bool LeafIterator> class OneDGridIntersectionIterator;
00028 class OneDGrid;
00029
00030 template<int codim> class OneDGridLevelIteratorFactory;
00031
00032 }
00033
00034 #include "onedgrid/onedgridlist.hh"
00035 #include "onedgrid/nulliteratorfactory.hh"
00036 #include "onedgrid/onedgridentity.hh"
00037 #include "onedgrid/onedgridentitypointer.hh"
00038 #include "onedgrid/onedgridgeometry.hh"
00039 #include "onedgrid/onedintersectionit.hh"
00040 #include "onedgrid/onedgridleveliterator.hh"
00041 #include "onedgrid/onedgridleafiterator.hh"
00042 #include "onedgrid/onedgridhieriterator.hh"
00043 #include "onedgrid/onedgridindexsets.hh"
00044
00045 namespace Dune {
00046
00047 template<int dim, int dimw>
00048 struct OneDGridFamily
00049 {
00050 typedef GridTraits<dim,dimw,Dune::OneDGrid,
00051 OneDGridGeometry,
00052 OneDGridEntity,
00053 OneDGridEntityPointer,
00054 OneDGridLevelIterator,
00055 OneDGridLeafIntersectionIterator,
00056 OneDGridLevelIntersectionIterator,
00057 OneDGridLeafIntersectionIterator,
00058 OneDGridLevelIntersectionIterator,
00059 OneDGridHierarchicIterator,
00060 OneDGridLeafIterator,
00061 OneDGridLevelIndexSet<const OneDGrid>,
00062 OneDGridLevelIndexSetTypes<const OneDGrid>,
00063 OneDGridLeafIndexSet<const OneDGrid>,
00064 OneDGridLeafIndexSetTypes<const OneDGrid>,
00065 OneDGridIdSet<const OneDGrid>,
00066 unsigned int,
00067 OneDGridIdSet<const OneDGrid>,
00068 unsigned int,
00069 CollectiveCommunication<Dune::OneDGrid> >
00070 Traits;
00071 };
00072
00073
00074
00075
00076
00077
00078
00090 class OneDGrid : public GridDefaultImplementation <1, 1,double,OneDGridFamily<1,1> >
00091 {
00092
00093 enum {dim = 1};
00094 enum {dimworld = 1};
00095
00096 friend class OneDGridLevelIteratorFactory <0>;
00097 friend class OneDGridLevelIteratorFactory <1>;
00098 template <int codim_, int dim_, class GridImp_>
00099 friend class OneDGridEntity;
00100 friend class OneDGridHierarchicIterator<OneDGrid>;
00101 friend class OneDGridLeafIntersectionIterator<const OneDGrid>;
00102 friend class OneDGridLevelIntersectionIterator<const OneDGrid>;
00103
00104 friend class OneDGridLevelIndexSet<const OneDGrid>;
00105 friend class OneDGridLeafIndexSet<const OneDGrid>;
00106 friend class OneDGridIdSet<const OneDGrid>;
00107
00108 template <int codim_, PartitionIteratorType PiType_, class GridImp_>
00109 friend class OneDGridLeafIterator;
00110
00111 template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
00112 friend class Entity;
00113
00114
00115
00116
00117
00118 public:
00119
00126 typedef double ctype;
00127
00129 typedef OneDGridFamily<dim,dimworld> GridFamily;
00130
00131
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 vertices.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
00205 return size(level,1-type.dim());
00206 }
00207
00209 int size (GeometryType type) const
00210 {
00211 return leafIndexSet().size(type);
00212 }
00213
00216 int overlapSize(int codim) const {
00217 return 0;
00218 }
00219
00222 int ghostSize(int codim) const {
00223 return 0;
00224 }
00225
00228 int overlapSize(int level, int codim) const {
00229 return 0;
00230 }
00231
00234 int ghostSize(int level, int codim) const {
00235 return 0;
00236 }
00237
00239 const Traits::GlobalIdSet& globalIdSet() const
00240 {
00241 return idSet_;
00242 }
00243
00245 const Traits::LocalIdSet& localIdSet() const
00246 {
00247 return idSet_;
00248 }
00249
00251 const Traits::LevelIndexSet& levelIndexSet(int level) const
00252 {
00253 if (! levelIndexSets_[level]) {
00254 levelIndexSets_[level] =
00255 new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
00256 levelIndexSets_[level]->update();
00257 }
00258
00259 return * levelIndexSets_[level];
00260 }
00261
00263 const Traits::LeafIndexSet& leafIndexSet() const
00264 {
00265 return leafIndexSet_;
00266 }
00267
00268
00276 bool mark(int refCount, const Traits::Codim<0>::EntityPointer& e ) DUNE_DEPRECATED;
00277
00285 bool mark(int refCount, const Traits::Codim<0>::Entity& e );
00286
00293 int getMark(const Traits::Codim<0>::EntityPointer & e ) const DUNE_DEPRECATED;
00294
00301 int getMark(const Traits::Codim<0>::Entity& e ) const;
00302
00304 bool preAdapt();
00305
00307 bool adapt();
00308
00310 void postAdapt();
00311
00313 std::string name () const { return "OneDGrid"; }
00314
00315
00316
00317
00318
00320 enum RefinementType {
00322 LOCAL,
00324 COPY};
00325
00327 void setRefinementType(RefinementType type) {
00328 refinementType_ = type;
00329 }
00330
00336 void globalRefine(int refCount);
00337
00338
00339
00340 template<class DataHandle>
00341 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
00342 {
00343 }
00344
00345 template<class DataHandle>
00346 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
00347 {
00348 }
00349
00350 const CollectiveCommunication<OneDGrid>& comm () const
00351 {
00352 return ccobj;
00353 }
00354
00355
00356 private:
00357
00358 CollectiveCommunication<OneDGrid> ccobj;
00359
00361 void setIndices();
00362
00363 unsigned int getNextFreeId(int codim) {
00364 return (codim==0) ? freeElementIdCounter_++ : freeVertexIdCounter_++;
00365 }
00366
00368 RefinementType refinementType_;
00369
00370 OneDGridList<OneDEntityImp<0> >::iterator getLeftUpperVertex(const OneDEntityImp<1>* eIt);
00371
00372 OneDGridList<OneDEntityImp<0> >::iterator getRightUpperVertex(const OneDEntityImp<1>* eIt);
00373
00377 OneDGridList<OneDEntityImp<1> >::iterator getLeftNeighborWithSon(OneDGridList<OneDEntityImp<1> >::iterator eIt);
00378
00379
00380 std::vector<OneDGridList<OneDEntityImp<0> > > vertices;
00381
00382
00383
00384 std::vector<OneDGridList<OneDEntityImp<1> > > elements;
00385
00386
00387 mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
00388
00389 OneDGridLeafIndexSet<const OneDGrid> leafIndexSet_;
00390
00391 OneDGridIdSet<const OneDGrid> idSet_;
00392
00393 unsigned int freeVertexIdCounter_;
00394
00395 unsigned int freeElementIdCounter_;
00396
00397 };
00398
00399 namespace Capabilities
00400 {
00412 template<int cdim>
00413 struct hasEntity< OneDGrid, cdim >
00414 {
00415 static const bool v = true;
00416 };
00417
00421 template<>
00422 struct isParallel< OneDGrid >
00423 {
00424 static const bool v = false;
00425 };
00426
00430 template<>
00431 struct isLevelwiseConforming< OneDGrid >
00432 {
00433 static const bool v = true;
00434 };
00435
00439 template<>
00440 struct isLeafwiseConforming< OneDGrid >
00441 {
00442 static const bool v = true;
00443 };
00444
00448 template<>
00449 struct hasHangingNodes< OneDGrid >
00450 {
00451 static const bool v = false;
00452 };
00453
00454 }
00455
00456 }
00457
00458 #endif