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
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 }
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
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
00058 if (i==0 && begin!=0)
00059 DUNE_THROW(DoubleLinkedListError, "invalid iterator for insert_after");
00060
00061
00062 if (begin==0) {
00063
00064 begin = t;
00065 rbegin = t;
00066 }
00067 else
00068 {
00069
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
00078 if (rbegin==i)
00079 rbegin = t;
00080 }
00081
00082
00083 numelements = numelements+1;
00084
00085 return t;
00086 }
00087
00088 T* insert_before (T* i, T* t) {
00089
00090
00091 if (i==0 && begin!=0)
00092 DUNE_THROW(DoubleLinkedListError,
00093 "invalid iterator for insert_before");
00094
00095
00096 if (begin==0)
00097 {
00098
00099 begin=t;
00100 rbegin=t;
00101 }
00102 else
00103 {
00104
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
00112 if (begin==i)
00113 begin = t;
00114 }
00115
00116
00117 numelements = numelements+1;
00118 return t;
00119 }
00120
00121 void remove (T* i)
00122 {
00123
00124 if (i==0)
00125 return;
00126
00127
00128 if (i->succ_!=0)
00129 i->succ_->pred_ = i->pred_;
00130 if (i->pred_!=0)
00131 i->pred_->succ_ = i->succ_;
00132
00133
00134 if (begin==i)
00135 begin=i->succ_;
00136 if (rbegin==i)
00137 rbegin = i->pred_;
00138
00139
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,
00160 OneDGridLevelIntersectionIterator,
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
00178
00179
00180
00192 class OneDGrid : public GridDefaultImplementation <1, 1,double,OneDGridFamily<1,1> >
00193 {
00194
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
00217 typedef double OneDCType;
00218
00219
00220
00221
00222
00223 public:
00225 typedef OneDGridFamily<dim,dimworld> GridFamily;
00226
00228 typedef OneDGridFamily<dim,dimworld>::Traits Traits;
00229
00231 OneDGrid(const std::vector<OneDCType>& coords);
00232
00234 OneDGrid(int numElements, double leftBoundary, double rightBoundary);
00235
00237 ~OneDGrid();
00238
00243 int maxLevel() const {return vertices.size()-1;}
00244
00246 template<int codim>
00247 typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
00248
00250 template<int codim>
00251 typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
00252
00254 template<int codim, PartitionIteratorType PiType>
00255 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
00256
00258 template<int codim, PartitionIteratorType PiType>
00259 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
00260
00262 template<int codim>
00263 typename Traits::template Codim<codim>::LeafIterator leafbegin () const;
00264
00266 template<int codim>
00267 typename Traits::template Codim<codim>::LeafIterator leafend () const;
00268
00270 template<int codim, PartitionIteratorType PiType>
00271 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const;
00272
00274 template<int codim, PartitionIteratorType PiType>
00275 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const;
00276
00279 int size (int level, int codim) const {
00280 if (codim<0 || codim>1)
00281 DUNE_THROW(GridError, "There are no codim " << codim << " entities in a OneDGrid!");
00282
00283 if (codim==0)
00284 return elements[level].size();
00285
00286 return vertices[level].size();
00287 }
00288
00289
00290
00292 int size (int codim) const
00293 {
00294 return leafIndexSet().size(codim);
00295 }
00296
00298 int size (int level, GeometryType type) const
00299 {
00300
00301 return size(level,1-type.dim());
00302 }
00303
00305 int size (GeometryType type) const
00306 {
00307 return leafIndexSet().size(type);
00308 }
00309
00312 int overlapSize(int codim) const {
00313 return 0;
00314 }
00315
00318 int ghostSize(int codim) const {
00319 return 0;
00320 }
00321
00324 int overlapSize(int level, int codim) const {
00325 return 0;
00326 }
00327
00330 int ghostSize(int level, int codim) const {
00331 return 0;
00332 }
00333
00335 const Traits::GlobalIdSet& globalIdSet() const
00336 {
00337 return idSet_;
00338 }
00339
00341 const Traits::LocalIdSet& localIdSet() const
00342 {
00343 return idSet_;
00344 }
00345
00347 const Traits::LevelIndexSet& levelIndexSet(int level) const
00348 {
00349 if (! levelIndexSets_[level]) {
00350 levelIndexSets_[level] =
00351 new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
00352 levelIndexSets_[level]->update();
00353 }
00354
00355 return * levelIndexSets_[level];
00356 }
00357
00359 const Traits::LeafIndexSet& leafIndexSet() const
00360 {
00361 return leafIndexSet_;
00362 }
00363
00364
00372 bool mark(int refCount, const Traits::Codim<0>::EntityPointer& e );
00373
00380 int getMark(const Traits::Codim<0>::EntityPointer & e ) const;
00381
00383 bool preAdapt();
00384
00386 bool adapt();
00387
00389 void postAdapt();
00390
00392 std::string name () const { return "OneDGrid"; }
00393
00394
00395
00396
00397
00399 enum RefinementType {
00401 LOCAL,
00403 COPY};
00404
00406 void setRefinementType(RefinementType type) {
00407 refinementType_ = type;
00408 }
00409
00415 void globalRefine(int refCount);
00416
00417
00418
00419 template<class DataHandle>
00420 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
00421 {
00422 }
00423
00424 template<class DataHandle>
00425 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
00426 {
00427 }
00428
00429 const CollectiveCommunication<OneDGrid>& comm () const
00430 {
00431 return ccobj;
00432 }
00433
00434
00435 private:
00436
00437 CollectiveCommunication<OneDGrid> ccobj;
00438
00440 void setIndices();
00441
00442 unsigned int getNextFreeId(int codim) {
00443 return (codim==0) ? freeElementIdCounter_++ : freeVertexIdCounter_++;
00444 }
00445
00447 RefinementType refinementType_;
00448
00449 OneDEntityImp<0>* getLeftUpperVertex(const OneDEntityImp<1>* eIt);
00450
00451 OneDEntityImp<0>* getRightUpperVertex(const OneDEntityImp<1>* eIt);
00452
00456 OneDEntityImp<1>* getLeftNeighborWithSon(OneDEntityImp<1>* eIt);
00457
00458
00459 std::vector<List<OneDEntityImp<0> > > vertices;
00460
00461
00462 std::vector<List<OneDEntityImp<1> > > elements;
00463
00464
00465 mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
00466
00467 OneDGridLeafIndexSet<const OneDGrid> leafIndexSet_;
00468
00469 OneDGridIdSet<const OneDGrid> idSet_;
00470
00471 unsigned int freeVertexIdCounter_;
00472
00473 unsigned int freeElementIdCounter_;
00474
00475 };
00476
00477 namespace Capabilities
00478 {
00490 template<int cdim>
00491 struct hasEntity< OneDGrid, cdim >
00492 {
00493 static const bool v = true;
00494 };
00495
00499 template<>
00500 struct isParallel< OneDGrid >
00501 {
00502 static const bool v = false;
00503 };
00504
00508 template<>
00509 struct isLevelwiseConforming< OneDGrid >
00510 {
00511 static const bool v = true;
00512 };
00513
00517 template<>
00518 struct isLeafwiseConforming< OneDGrid >
00519 {
00520 static const bool v = true;
00521 };
00522
00526 template<>
00527 struct hasHangingNodes< OneDGrid >
00528 {
00529 static const bool v = false;
00530 };
00531
00532 }
00533
00534 }
00535
00536 #endif