00001 #ifndef DUNE_SGRID_HH
00002 #define DUNE_SGRID_HH
00003
00004 #include <limits>
00005 #include <vector>
00006
00007 #include <dune/common/fvector.hh>
00008 #include <dune/common/fmatrix.hh>
00009 #include <dune/common/stack.hh>
00010 #include <dune/grid/common/capabilities.hh>
00011 #include <dune/common/bigunsignedint.hh>
00012 #include <dune/common/collectivecommunication.hh>
00013 #include <dune/grid/common/grid.hh>
00014 #include <dune/grid/sgrid/numbering.hh>
00015 #include <dune/grid/common/indexidset.hh>
00016
00022 namespace Dune {
00023
00024
00028 typedef double sgrid_ctype;
00029
00030
00031 const int sgrid_dim_bits = 24;
00032 const int sgrid_level_bits = 6;
00033 const int sgrid_codim_bits = 4;
00034
00035
00036
00037
00038 template<int dim, int dimworld, class GridImp> class SGeometry;
00039 template<int codim, int dim, class GridImp> class SEntity;
00040 template<int codim, class GridImp> class SEntityPointer;
00041 template<int codim, PartitionIteratorType, class GridImp> class SLevelIterator;
00042 template<int dim, int dimworld> class SGrid;
00043 template<class GridImp> class SIntersectionIterator;
00044 template<class GridImp> class SHierarchicIterator;
00045
00046
00077 template<int mydim, int cdim, class GridImp>
00078 class SGeometry : public GeometryDefaultImplementation<mydim,cdim,GridImp,SGeometry>
00079 {
00080 public:
00082 typedef sgrid_ctype ctype;
00083
00085 GeometryType type () const;
00086
00088 int corners () const;
00089
00091 const FieldVector<sgrid_ctype, cdim>& operator[] (int i) const;
00092
00094 FieldVector<sgrid_ctype, cdim> global (const FieldVector<sgrid_ctype, mydim>& local) const;
00095
00097 FieldVector<sgrid_ctype, mydim> local (const FieldVector<sgrid_ctype, cdim>& global) const;
00098
00100 bool checkInside (const FieldVector<sgrid_ctype, mydim>& local) const;
00101
00121 sgrid_ctype integrationElement (const FieldVector<sgrid_ctype, mydim>& local) const;
00122
00124 const FieldMatrix<sgrid_ctype,mydim,mydim>& jacobianInverseTransposed (const FieldVector<sgrid_ctype, mydim>& local) const;
00125
00127 void print (std::ostream& ss, int indent) const;
00128
00133 void make (FieldMatrix<sgrid_ctype,mydim+1,cdim>& __As);
00134
00136 SGeometry () : builtinverse(false) {};
00137
00138 private:
00139 FieldVector<sgrid_ctype, cdim> s;
00140 FieldMatrix<sgrid_ctype,mydim,cdim> A;
00141 FixedArray<FieldVector<sgrid_ctype, cdim>, 1<<mydim> c;
00142 mutable FieldMatrix<sgrid_ctype,mydim,mydim> Jinv;
00143 mutable bool builtinverse;
00144 };
00145
00147 template<int cdim, class GridImp>
00148 class SGeometry<0,cdim,GridImp> : public GeometryDefaultImplementation<0,cdim,GridImp,SGeometry>
00149 {
00150 public:
00152 typedef sgrid_ctype ctype;
00153
00155 GeometryType type () const;
00156
00158 int corners () const;
00159
00161 const FieldVector<sgrid_ctype, cdim>& operator[] (int i) const;
00162
00164 void print (std::ostream& ss, int indent) const;
00165
00167 void make (FieldMatrix<sgrid_ctype,1,cdim>& __As);
00168
00170 FieldVector<sgrid_ctype, 1> global (const FieldVector<sgrid_ctype, 0>& local) const { return this->operator[] (0); }
00171
00173 FieldVector<sgrid_ctype, 0> local (const FieldVector<sgrid_ctype, 1>& global) const { return FieldVector<sgrid_ctype,0> (0.0); }
00174
00196
00197 SGeometry () {};
00198
00204 sgrid_ctype integrationElement(const FieldVector<sgrid_ctype, 0>& local) const {
00205 return 1.;
00206 }
00207
00209 bool checkInside (const FieldVector<sgrid_ctype, 0>& local) const
00210 {
00211 return true;
00212 }
00213
00215 const FieldMatrix<sgrid_ctype,0,0>& jacobianInverseTransposed (const FieldVector<sgrid_ctype, 0>& local) const
00216 {
00217 static FieldMatrix<sgrid_ctype,0,0> dummy;
00218 return dummy;
00219 }
00220
00221 protected:
00222 FieldVector<sgrid_ctype, cdim> s;
00223 };
00224
00225 template <int mydim, int cdim, class GridImp>
00226 inline std::ostream& operator<< (std::ostream& s, SGeometry<mydim,cdim,GridImp>& e)
00227 {
00228 e.print(s,0);
00229 return s;
00230 }
00231
00232 template<int mydim, int cdim, class GridImp>
00233 class SMakeableGeometry : public Geometry<mydim, cdim, GridImp, SGeometry>
00234 {
00235 public:
00236 SMakeableGeometry() :
00237 Geometry<mydim, cdim, GridImp, SGeometry>(SGeometry<mydim, cdim, GridImp>())
00238 {};
00239
00240 void make (FieldMatrix<sgrid_ctype,mydim+1,cdim>& __As) { this->realGeometry.make(__As); }
00241 };
00242
00243
00248 template<int codim, int dim, class GridImp>
00249 class SEntityBase {
00250 friend class SEntityPointer<codim,GridImp>;
00251 friend class SIntersectionIterator<GridImp>;
00252 enum { dimworld = GridImp::dimensionworld };
00253 public:
00254 typedef typename GridImp::template Codim<codim>::Geometry Geometry;
00255 typedef SMakeableGeometry<dim-codim, dimworld, const GridImp> MakeableGeometry;
00256 typedef typename GridImp::PersistentIndexType PersistentIndexType;
00257
00259 int level () const
00260 {
00261 return l;
00262 }
00263
00266 int index () const
00267 {
00268 return compressedIndex();
00269 }
00270
00272 int globalIndex() const;
00273
00275 const Geometry& geometry () const;
00276
00278 SEntityBase (GridImp* _grid, int _l, int _id);
00279 SEntityBase ();
00280 void make (GridImp* _grid, int _l, int _id);
00281
00283 void make (int _l, int _id);
00284
00286 PersistentIndexType persistentIndex () const
00287 {
00288 if (codim!=dim)
00289 {
00290
00291
00292 PersistentIndexType id(codim);
00293
00294
00295 id = id << sgrid_level_bits;
00296 id = id+PersistentIndexType(l);
00297
00298
00299 for (int i=dim-1; i>=0; i--)
00300 {
00301 id = id << sgrid_dim_bits;
00302 id = id+PersistentIndexType(z[i]);
00303 }
00304
00305 return id;
00306 }
00307 else
00308 {
00309
00310
00311 int trailing = 1000;
00312 for (int i=0; i<dim; i++)
00313 {
00314
00315 int zeros = 0;
00316 for (int j=0; j<l; j++)
00317 if (z[i]&(1<<(j+1)))
00318 break;
00319 else
00320 zeros++;
00321 trailing = std::min(trailing,zeros);
00322 }
00323
00324
00325 int level = l-trailing;
00326
00327
00328 PersistentIndexType id(dim);
00329
00330
00331 id = id << sgrid_level_bits;
00332 id = id+PersistentIndexType(level);
00333
00334
00335 for (int i=dim-1; i>=0; i--)
00336 {
00337 id = id << sgrid_dim_bits;
00338 id = id+PersistentIndexType(z[i]>>trailing);
00339 }
00340
00341 return id;
00342 }
00343 }
00344
00346 int compressedIndex () const
00347 {
00348 return id;
00349 }
00350
00352 int compressedLeafIndex () const
00353 {
00354
00355
00356 if (codim<dim || l==grid->maxLevel())
00357 return id;
00358
00359
00360
00361 FixedArray<int,dim> coord;
00362 for (int k=0; k<dim; k++)
00363 coord[k] = z[k]*(1<<(grid->maxLevel()-l));
00364
00365
00366 return grid->n(grid->maxLevel(),coord);
00367 }
00368
00369 protected:
00370
00371 GridImp* grid;
00372 int l;
00373 int id;
00374 FixedArray<int,dim> z;
00375 mutable MakeableGeometry geo;
00376 mutable bool builtgeometry;
00377 };
00378
00379
00387 template<int codim, int dim, class GridImp>
00388 class SEntity : public SEntityBase<codim,dim,GridImp>,
00389 public EntityDefaultImplementation<codim,dim,GridImp,SEntity>
00390 {
00391 enum { dimworld = GridImp::dimensionworld };
00392 public:
00393 typedef typename GridImp::template Codim<codim>::Geometry Geometry;
00394 typedef typename GridImp::template Codim<codim>::LevelIterator LevelIterator;
00395 typedef typename GridImp::template Codim<0>::LeafIntersectionIterator IntersectionIterator;
00396 typedef typename GridImp::template Codim<0>::HierarchicIterator HierarchicIterator;
00397
00398
00400 int level () const {return SEntityBase<codim,dim,GridImp>::level();}
00401
00403 int index () const {return SEntityBase<codim,dim,GridImp>::index();}
00404
00406 const Geometry& geometry () const { return SEntityBase<codim,dim,GridImp>::geometry(); }
00407
00409 PartitionType partitionType () const { return InteriorEntity; }
00410
00411
00413 SEntity (GridImp* _grid, int _l, int _id) : SEntityBase<codim,dim,GridImp>::SEntityBase(_grid,_l,_id) {};
00414 };
00415
00433 static FixedArray <int,2> zrefGlob;
00434 static FixedArray <int,2> zentityGlob;
00435
00445 template<int dim, class GridImp>
00446 class SEntity<0,dim,GridImp> : public SEntityBase<0,dim,GridImp>,
00447 public EntityDefaultImplementation<0,dim,GridImp,SEntity>
00448 {
00449 enum { dimworld = GridImp::dimensionworld };
00450 public:
00451 typedef typename GridImp::template Codim<0>::Geometry Geometry;
00452 typedef SMakeableGeometry<dim, dimworld, const GridImp> MakeableGeometry;
00453 template <int cd>
00454 struct Codim
00455 {
00456 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
00457 };
00458 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00459 typedef typename GridImp::template Codim<0>::LeafIntersectionIterator IntersectionIterator;
00460 typedef typename GridImp::template Codim<0>::HierarchicIterator HierarchicIterator;
00461 typedef typename GridImp::PersistentIndexType PersistentIndexType;
00462
00464 friend class SHierarchicIterator<GridImp>;
00465
00466
00468 int level () const {return SEntityBase<0,dim,GridImp>::level();}
00469
00472 int index () const {return SEntityBase<0,dim,GridImp>::index();}
00473
00475 PartitionType partitionType () const { return InteriorEntity; }
00476
00478 const Geometry& geometry () const {return SEntityBase<0,dim,GridImp>::geometry();}
00479
00484 template<int cc> int count () const;
00485
00490 template<int cc> typename Codim<cc>::EntityPointer entity (int i) const;
00491
00493 template<int cc>
00494 int subCompressedIndex (int i) const
00495 {
00496 if (cc==0) return this->compressedIndex();
00497 return this->grid->template getRealEntity<cc>(*entity<cc>(i)).compressedIndex();
00498 }
00499
00501 template<int cc>
00502 int subCompressedLeafIndex (int i) const
00503 {
00504 if (cc==0) return this->compressedLeafIndex();
00505 return this->grid->template getRealEntity<cc>(*entity<cc>(i)).compressedLeafIndex();
00506 }
00507
00509 template<int cc>
00510 PersistentIndexType subPersistentIndex (int i) const
00511 {
00512 if (cc==0) return this->persistentIndex();
00513 return this->grid->template getRealEntity<cc>(*entity<cc>(i)).persistentIndex();
00514 }
00515
00523 IntersectionIterator ibegin () const;
00524 IntersectionIterator ileafbegin () const;
00525 IntersectionIterator ilevelbegin () const;
00527 IntersectionIterator iend () const;
00528 IntersectionIterator ileafend () const;
00529 IntersectionIterator ilevelend () const;
00530
00536 EntityPointer father () const;
00537
00539 bool isLeaf () const
00540 {
00541 return ( this->grid->maxLevel() == level() );
00542 }
00543
00555 const Geometry& geometryInFather () const;
00556
00563 HierarchicIterator hbegin (int maxLevel) const;
00564
00566 HierarchicIterator hend (int maxLevel) const;
00567
00568
00570 SEntity (GridImp* _grid, int _l, int _id) :
00571 SEntityBase<0,dim,GridImp>::SEntityBase(_grid,_l,_id)
00572 {
00573 built_father = false;
00574 }
00575
00576 SEntity ()
00577 {
00578 built_father = false;
00579 }
00580
00581 void make (GridImp* _grid, int _l, int _id)
00582 {
00583 SEntityBase<0,dim,GridImp>::make(_grid,_l,_id);
00584 built_father = false;
00585 }
00586
00588 void make (int _l, int _id)
00589 {
00590 SEntityBase<0,dim,GridImp>::make(_l,_id);
00591 built_father = false;
00592 }
00593
00594 private:
00595
00596 mutable bool built_father;
00597 mutable int father_id;
00598 mutable MakeableGeometry in_father_local;
00599 void make_father() const;
00600 };
00601
00611 template<int dim, class GridImp>
00612 class SEntity<dim,dim,GridImp> : public SEntityBase<dim,dim,GridImp>,
00613 public EntityDefaultImplementation <dim,dim,GridImp,SEntity>
00614 {
00615 enum { dimworld = GridImp::dimensionworld };
00616 public:
00617 typedef typename GridImp::template Codim<dim>::Geometry Geometry;
00618 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00619
00620
00622 int level () const {return SEntityBase<dim,dim,GridImp>::level();}
00623
00625 int index () const {return SEntityBase<dim,dim,GridImp>::index();}
00626
00628 PartitionType partitionType () const { return InteriorEntity; }
00629
00631 const Geometry& geometry () const {return SEntityBase<dim,dim,GridImp>::geometry();}
00632
00633
00635 SEntity (GridImp* _grid, int _l, int _id) : SEntityBase<dim,dim,GridImp>::SEntityBase(_grid,_l,_id)
00636 {
00637 built_father = false;
00638 }
00639
00641 void make (int _l, int _id)
00642 {
00643 SEntityBase<dim,dim,GridImp>::make(_l,_id);
00644 built_father = false;
00645 }
00646
00647 private:
00648 mutable bool built_father;
00649 mutable int father_id;
00650 mutable FieldVector<sgrid_ctype, dim> in_father_local;
00651 void make_father() const;
00652 };
00653
00654 template<int codim, int dim, class GridImp>
00655 class SMakeableEntity :
00656 public GridImp::template Codim<codim>::Entity
00657 {
00658 public:
00659
00660 SMakeableEntity(GridImp* _grid, int _l, int _id) :
00661 GridImp::template Codim<codim>::Entity (SEntity<codim, dim, GridImp>(_grid,_l,_id))
00662 {};
00663 SMakeableEntity(const SEntity<codim, dim, GridImp>& e) :
00664 GridImp::template Codim<codim>::Entity (e)
00665 {};
00666 void make (int _l, int _id) { this->realEntity.make(_l, _id); }
00667 };
00668
00669
00677 struct SHierarchicStackElem {
00678 int l;
00679 int id;
00680 SHierarchicStackElem () : l(-1), id(-1) {}
00681 SHierarchicStackElem (int _l, int _id) {l=_l; id=_id;}
00682 bool operator== (const SHierarchicStackElem& s) const {return !operator!=(s);}
00683 bool operator!= (const SHierarchicStackElem& s) const {return l!=s.l || id!=s.id;}
00684 };
00685
00686 template<class GridImp>
00687 class SHierarchicIterator :
00688 public Dune::SEntityPointer <0,GridImp>,
00689 public HierarchicIteratorDefaultImplementation <GridImp,SHierarchicIterator>
00690 {
00691 friend class SHierarchicIterator<const GridImp>;
00692 enum { dim = GridImp::dimension };
00693 enum { dimworld = GridImp::dimensionworld };
00694 public:
00695 typedef typename GridImp::template Codim<0>::Entity Entity;
00696 typedef typename GridImp::ctype ctype;
00697
00699 void increment();
00700
00707 SHierarchicIterator (GridImp* _grid,
00708 const Dune::SEntity<0,GridImp::dimension,GridImp>& _e,
00709 int _maxLevel, bool makeend) :
00710 Dune::SEntityPointer<0,GridImp>(_grid,_e.level(),_e.index())
00711 {
00712
00713
00714 if (makeend) return;
00715
00716
00717 orig_l = this->e.level();
00718 orig_id = _grid->template getRealEntity<0>(this->e).index();
00719
00720
00721 SHierarchicStackElem originalElement(orig_l, orig_id);
00722 stack.push(originalElement);
00723
00724
00725 maxLevel = std::min(_maxLevel,this->grid->maxLevel());
00726
00727
00728 push_sons(orig_l,orig_id);
00729
00730
00731 increment();
00732 }
00733
00734 private:
00735 int maxLevel;
00736 int orig_l, orig_id;
00737
00738 FiniteStack<SHierarchicStackElem,GridImp::MAXL> stack;
00739
00740 void push_sons (int level, int fatherid);
00741 };
00742
00743
00750 template<class GridImp>
00751 class SIntersectionIterator :
00752 public IntersectionIteratorDefaultImplementation <GridImp,SIntersectionIterator>
00753 {
00754 enum { dim=GridImp::dimension };
00755 enum { dimworld=GridImp::dimensionworld };
00756 public:
00757 typedef typename GridImp::template Codim<0>::Entity Entity;
00758 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00759 typedef typename GridImp::template Codim<1>::Geometry Geometry;
00760 typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
00762 enum { dimension=dim };
00764 enum { dimensionworld=dimworld };
00766 typedef typename GridImp::ctype ctype;
00767
00769 bool equals(const SIntersectionIterator<GridImp>& i) const;
00771 void increment();
00772
00775 EntityPointer inside() const;
00776
00779 EntityPointer outside() const;
00780
00782 bool boundary () const;
00783
00784 int boundaryId () const {
00785 if (boundary()) return count + 1;
00786 return 0;
00787 };
00789 bool neighbor () const;
00790
00792 FieldVector<ctype, GridImp::dimensionworld> outerNormal (const FieldVector<ctype, GridImp::dimension-1>& local) const
00793 {
00794 return unitOuterNormal(local);
00795 }
00797 FieldVector<ctype, GridImp::dimensionworld> unitOuterNormal (const FieldVector<ctype, GridImp::dimension-1>& local) const
00798 {
00799
00800 FieldVector<sgrid_ctype, dimworld> normal(0.0);
00801 if (count%2)
00802 normal[count/2] = 1.0;
00803 else
00804 normal[count/2] = -1.0;
00805
00806 return normal;
00807 }
00808
00812 LocalGeometry& intersectionSelfLocal () const;
00816 LocalGeometry& intersectionNeighborLocal () const;
00820 Geometry& intersectionGlobal () const;
00822 int numberInSelf () const;
00824 int numberInNeighbor () const;
00825
00827 SIntersectionIterator (GridImp* _grid, const SEntity<0,dim,GridImp >* _self, int _count);
00828
00830 SIntersectionIterator& operator = (const SIntersectionIterator& it)
00831 {
00832 assert(grid == it.grid);
00833
00834
00835 if (! self.equals(it.self))
00836 DUNE_THROW(GridError, "assignment of SIntersectionIterator "
00837 << "with different inside Entity");
00838 if (partition != it.partition)
00839 DUNE_THROW(GridError, "assignment of SIntersectionIterator "
00840 << "with different partition");
00841
00842
00843
00844 ne = it.ne;
00845 count = it.count;
00846 make(count);
00847
00848 return *this;
00849 }
00850
00851 private:
00852 void make (int _count) const;
00853 void makeintersections () const;
00854 const EntityPointer self;
00855 mutable EntityPointer ne;
00856 const GridImp * grid;
00857 const int partition;
00858 const FixedArray<int,dim> zred;
00859 mutable int count;
00860 mutable bool valid_count;
00861 mutable bool valid_nb;
00862 mutable bool is_on_boundary;
00863 mutable bool built_intersections;
00864 mutable SMakeableGeometry<dim-1,dim,const GridImp> is_self_local;
00865 mutable SMakeableGeometry<dim-1,dimworld,const GridImp> is_global;
00866 mutable SMakeableGeometry<dim-1,dim,const GridImp> is_nb_local;
00867 };
00868
00869
00870
00873 template<int codim, class GridImp>
00874 class SEntityPointer :
00875 public EntityPointerDefaultImplementation <codim, GridImp,
00876 Dune::SEntityPointer<codim,GridImp> >
00877 {
00878 enum { dim = GridImp::dimension };
00879 friend class SIntersectionIterator<GridImp>;
00880 public:
00881 typedef SEntityPointer<codim,GridImp> Base;
00882 typedef typename GridImp::template Codim<codim>::Entity Entity;
00883
00885 bool equals(const SEntityPointer<codim,GridImp>& i) const;
00887 Entity& dereference() const;
00889 int level () const;
00890
00892 SEntityPointer (GridImp * _grid, int _l, int _id) :
00893 grid(_grid), l(_l), id(_id), e(_grid,_l,_id) { }
00894
00896 SEntityPointer (const SEntity<codim,dim,GridImp> & _e) :
00897 grid(_e.grid), l(_e.l), id(_e.id), e(_e) { }
00898
00899 protected:
00900 GridImp* grid;
00901 int l;
00902 mutable int id;
00903 mutable SMakeableEntity<codim,dim,GridImp> e;
00904 };
00905
00906
00907
00910 template<int codim, PartitionIteratorType pitype, class GridImp>
00911 class SLevelIterator :
00912 public Dune::SEntityPointer <codim,GridImp>,
00913 public LevelIteratorDefaultImplementation <codim,pitype,GridImp,SLevelIterator>
00914 {
00915 friend class SLevelIterator<codim, pitype,const GridImp>;
00916 enum { dim = GridImp::dimension };
00917 public:
00918 typedef typename GridImp::template Codim<codim>::Entity Entity;
00919
00921 void increment();
00922
00924 SLevelIterator (GridImp * _grid, int _l, int _id) :
00925 Dune::SEntityPointer<codim,GridImp>(_grid,_l,_id) {}
00926 };
00927
00928
00929
00934
00935
00936 template <class GridImp>
00937 struct SGridLevelIndexSetTypes
00938 {
00940 template<int cd>
00941 struct Codim
00942 {
00943 template<PartitionIteratorType pitype>
00944 struct Partition
00945 {
00946 typedef typename GridImp::Traits::template Codim<cd>::template Partition<pitype>::LevelIterator Iterator;
00947 };
00948 };
00949 };
00950
00951 template<class GridImp>
00952 class SGridLevelIndexSet : public IndexSetDefaultImplementation<GridImp,SGridLevelIndexSet<GridImp>,SGridLevelIndexSetTypes<GridImp> >
00953 {
00954 typedef IndexSetDefaultImplementation<GridImp,SGridLevelIndexSet<GridImp>,SGridLevelIndexSetTypes<GridImp> > Base;
00955 public:
00956
00958 SGridLevelIndexSet (const GridImp& g, int l) : grid(g), level(l)
00959 {
00960
00961 for (int codim=0; codim<=GridImp::dimension; codim++)
00962 mytypes[codim].push_back(GeometryType(GeometryType::cube,GridImp::dimension-codim));
00963 }
00964
00966 template<int cd>
00967 int index (const typename GridImp::Traits::template Codim<cd>::Entity& e) const
00968 {
00969 return grid.template getRealEntity<cd>(e).compressedIndex();
00970 }
00971
00973 template<int cc>
00974 int subIndex (const typename GridImp::Traits::template Codim<0>::Entity& e, int i) const
00975 {
00976 return grid.template getRealEntity<0>(e).template subCompressedIndex<cc>(i);
00977 }
00978
00980 int size (GeometryType type) const
00981 {
00982 return grid.size(level,GridImp::dimension-type.dim());
00983 }
00984
00986 int size (int codim) const
00987 {
00988 return Base::size(codim);
00989 }
00990
00992 const std::vector<GeometryType>& geomTypes (int codim) const
00993 {
00994 return mytypes[codim];
00995 }
00996
00998 template<int cd, PartitionIteratorType pitype>
00999 typename Base::template Codim<cd>::template Partition<pitype>::Iterator begin () const
01000 {
01001 return grid.template lbegin<cd,pitype>(level);
01002 }
01003
01005 template<int cd, PartitionIteratorType pitype>
01006 typename Base::template Codim<cd>::template Partition<pitype>::Iterator end () const
01007 {
01008 return grid.template lend<cd,pitype>(level);
01009 }
01010
01011 private:
01012 const GridImp& grid;
01013 int level;
01014 std::vector<GeometryType> mytypes[GridImp::dimension+1];
01015 };
01016
01017
01018
01019 template <class GridImp>
01020 struct SGridLeafIndexSetTypes
01021 {
01023 template<int cd>
01024 struct Codim
01025 {
01026 template<PartitionIteratorType pitype>
01027 struct Partition
01028 {
01029 typedef typename GridImp::Traits::template Codim<cd>::template Partition<pitype>::LeafIterator Iterator;
01030 };
01031 };
01032 };
01033
01034 template<class GridImp>
01035 class SGridLeafIndexSet : public IndexSetDefaultImplementation<GridImp,SGridLeafIndexSet<GridImp>,SGridLeafIndexSetTypes<GridImp> >
01036 {
01037 typedef IndexSetDefaultImplementation<GridImp,SGridLeafIndexSet<GridImp>,SGridLeafIndexSetTypes<GridImp> > Base;
01038 enum {dim = RemoveConst<GridImp>::Type::dimension};
01039 public:
01040
01042 SGridLeafIndexSet (const GridImp& g) : grid(g)
01043 {
01044
01045 for (int codim=0; codim<=dim; codim++)
01046 mytypes[codim].push_back(GeometryType(GeometryType::cube,dim-codim));
01047 }
01048
01050
01051
01052
01053
01054 template<int cd>
01055 int index (const typename RemoveConst<GridImp>::Type::Traits::template Codim<cd>::Entity& e) const
01056 {
01057 return grid.template getRealEntity<cd>(e).compressedLeafIndex();
01058 }
01059
01061
01062
01063
01064
01065 template<int cc>
01066 int subIndex (const typename RemoveConst<GridImp>::Type::Traits::template Codim<0>::Entity& e, int i) const
01067 {
01068 return grid.template getRealEntity<0>(e).template subCompressedLeafIndex<cc>(i);
01069 }
01070
01072 int size (GeometryType type) const
01073 {
01074 return grid.size(grid.maxLevel(),GridImp::dimension-type.dim());
01075 }
01076
01078 int size (int codim) const
01079 {
01080 return Base::size(codim);
01081 }
01082
01084 const std::vector<GeometryType>& geomTypes (int codim) const
01085 {
01086 return mytypes[codim];
01087 }
01088
01090 template<int cd, PartitionIteratorType pitype>
01091 typename Base::template Codim<cd>::template Partition<pitype>::Iterator begin () const
01092 {
01093 return grid.template leafbegin<cd,pitype>();
01094 }
01095
01097 template<int cd, PartitionIteratorType pitype>
01098 typename Base::template Codim<cd>::template Partition<pitype>::Iterator end () const
01099 {
01100 return grid.template leafend<cd,pitype>();
01101 }
01102
01103 private:
01104 const GridImp& grid;
01105 std::vector<GeometryType> mytypes[dim+1];
01106 };
01107
01108
01109
01114
01115
01116 template<class GridImp>
01117 class SGridGlobalIdSet :
01118 public IdSetDefaultImplementation<GridImp,SGridGlobalIdSet<GridImp>, typename RemoveConst<GridImp>::Type::PersistentIndexType>
01119
01120
01121
01122
01123 {
01124 public:
01126
01127
01128
01129
01130 typedef typename RemoveConst<GridImp>::Type::PersistentIndexType IdType;
01131
01133 SGridGlobalIdSet (const GridImp& g) : grid(g) {}
01134
01136
01137
01138
01139
01140 template<int cd>
01141 IdType id (const typename RemoveConst<GridImp>::Type::Traits::template Codim<cd>::Entity& e) const
01142 {
01143 return grid.template getRealEntity<cd>(e).persistentIndex();
01144 }
01145
01147
01148
01149
01150
01151 template<int cc>
01152 IdType subId (const typename RemoveConst<GridImp>::Type::Traits::template Codim<0>::Entity& e, int i) const
01153 {
01154 return grid.template getRealEntity<0>(e).template subPersistentIndex<cc>(i);
01155 }
01156
01157 private:
01158 const GridImp& grid;
01159 };
01160
01161
01162 template<int dim, int dimworld>
01163 struct SGridFamily
01164 {
01165 typedef GridTraits<dim,dimworld,Dune::SGrid<dim,dimworld>,
01166 SGeometry,SEntity,
01167 SEntityPointer,SLevelIterator,
01168 SIntersectionIterator,
01169 SIntersectionIterator,
01170 SHierarchicIterator,
01171 SLevelIterator,
01172 SGridLevelIndexSet<const SGrid<dim,dimworld> >,
01173 SGridLevelIndexSetTypes<const SGrid<dim,dimworld> >,
01174 SGridLeafIndexSet<const SGrid<dim,dimworld> >,
01175 SGridLeafIndexSetTypes<const SGrid<dim,dimworld> >,
01176 SGridGlobalIdSet<const SGrid<dim,dimworld> >,
01177 bigunsignedint<dim*sgrid_dim_bits+sgrid_level_bits+sgrid_codim_bits>,
01178 SGridGlobalIdSet<const SGrid<dim,dimworld> >,
01179 bigunsignedint<dim*sgrid_dim_bits+sgrid_level_bits+sgrid_codim_bits>,
01180 CollectiveCommunication<Dune::SGrid<dim,dimworld> > >
01181 Traits;
01182 };
01183
01184
01185
01237 template<int dim, int dimworld>
01238 class SGrid : public GridDefaultImplementation <dim,dimworld,sgrid_ctype,SGridFamily<dim,dimworld> >
01239 {
01240 public:
01241 typedef SGridFamily<dim,dimworld> GridFamily;
01242 typedef bigunsignedint<dim*sgrid_dim_bits+sgrid_level_bits+sgrid_codim_bits> PersistentIndexType;
01243
01244
01245 typedef SGridLevelIndexSet<SGrid<dim,dimworld> > LevelIndexSetType;
01246 typedef SGridLeafIndexSet<SGrid<dim,dimworld> > LeafIndexSetType;
01247 typedef SGridGlobalIdSet<SGrid<dim,dimworld> > GlobalIdSetType;
01248
01249 typedef typename SGridFamily<dim,dimworld>::Traits Traits;
01250
01252 enum { MAXL=32 };
01253
01255 typedef sgrid_ctype ctype;
01256
01258 std::string name() const { return "SGrid"; };
01259
01260
01261
01269 SGrid (const int* N_, const sgrid_ctype* H_);
01270
01278 SGrid (const int* N_, const sgrid_ctype* L_, const sgrid_ctype* H_);
01279
01289 SGrid (FieldVector<int,dim> N_, FieldVector<sgrid_ctype,dim> L_, FieldVector<sgrid_ctype,dim> H_);
01290
01292 SGrid ();
01293
01295 ~SGrid ();
01296
01299 int maxLevel() const;
01300
01302 template<int cd, PartitionIteratorType pitype>
01303 typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator lbegin (int level) const;
01304
01306 template<int cd, PartitionIteratorType pitype>
01307 typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator lend (int level) const;
01308
01310 template<int cd>
01311 typename Traits::template Codim<cd>::template Partition<All_Partition>::LevelIterator lbegin (int level) const
01312 {
01313 return lbegin<cd,All_Partition>(level);
01314 }
01315
01317 template<int cd>
01318 typename Traits::template Codim<cd>::template Partition<All_Partition>::LevelIterator lend (int level) const
01319 {
01320 return lend<cd,All_Partition>(level);
01321 }
01322
01324 template<int cd, PartitionIteratorType pitype>
01325 typename Traits::template Codim<cd>::template Partition<pitype>::LeafIterator leafbegin () const;
01326
01328 template<int cd, PartitionIteratorType pitype>
01329 typename Traits::template Codim<cd>::template Partition<pitype>::LeafIterator leafend () const;
01330
01332 template<int cd>
01333 typename Traits::template Codim<cd>::template Partition<All_Partition>::LeafIterator leafbegin () const
01334 {
01335 return leafbegin<cd,All_Partition>();
01336 }
01337
01339 template<int cd>
01340 typename Traits::template Codim<cd>::template Partition<All_Partition>::LeafIterator leafend () const
01341 {
01342 return leafend<cd,All_Partition>();
01343 }
01344
01356 template<class T, template<class> class P, int codim>
01357 void communicate (T& t, InterfaceType iftype, CommunicationDirection dir, int level)
01358 {
01359
01360 return;
01361 }
01362
01364 int size (int level, int codim) const;
01365
01367 int size (int codim) const
01368 {
01369 return size(maxLevel(),codim);
01370 }
01371
01373 int size (int level, GeometryType type) const
01374 {
01375 return (type.isCube()) ? size(level,dim-type.dim()) : 0;
01376 }
01377
01379 int size (GeometryType type) const
01380 {
01381 return size(maxLevel(),type);
01382 }
01383
01384
01386 int global_size (int codim) const;
01387
01389 int overlapSize (int level, int codim)
01390 {
01391 return 0;
01392 }
01393
01395 int ghostSize (int level, int codim)
01396 {
01397 return 0;
01398 }
01399
01400
01401
01403 void globalRefine (int refCount);
01404
01406 const FixedArray<int, dim>& dims(int level) const {
01407 return N[level];
01408 }
01409
01411 const FieldVector<sgrid_ctype, dimworld>& lowerLeft() const {
01412 return low;
01413 }
01414
01416 FieldVector<sgrid_ctype, dimworld> upperRight() const {
01417 return H;
01418 }
01419
01421 bool adapt ()
01422 {
01423 globalRefine(1);
01424 return true;
01425 }
01426
01427
01429 FieldVector<sgrid_ctype, dim> pos (int level, FixedArray<int,dim>& z) const;
01430
01432 int calc_codim (int level, const FixedArray<int,dim>& z) const;
01433
01435 int n (int level, const FixedArray<int,dim> z) const;
01436
01438 FixedArray<int,dim> z (int level, int i, int codim) const;
01439
01441 FixedArray<int,dim> compress (int level, const FixedArray<int,dim>& z) const;
01442
01444 FixedArray<int,dim> expand (int level, const FixedArray<int,dim>& r, int b) const;
01445
01449 int partition (int level, const FixedArray<int,dim>& z) const;
01450
01452 bool exists (int level, const FixedArray<int,dim>& zred) const;
01453
01454
01455
01456 const typename Traits::GlobalIdSet& globalIdSet() const
01457 {
01458 return *theglobalidset;
01459 }
01460
01461 const typename Traits::LocalIdSet& localIdSet() const
01462 {
01463 return *theglobalidset;
01464 }
01465
01466 const typename Traits::LevelIndexSet& levelIndexSet(int level) const
01467 {
01468 assert(level>=0 && level<=maxLevel());
01469 return *(indexsets[level]);
01470 }
01471
01472 const typename Traits::LeafIndexSet& leafIndexSet() const
01473 {
01474 return *theleafindexset;
01475 }
01476
01477
01478
01479 template<class DataHandle>
01480 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
01481 {
01482 }
01483
01484 template<class DataHandle>
01485 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
01486 {
01487 }
01488
01489 const CollectiveCommunication<SGrid>& comm () const
01490 {
01491 return ccobj;
01492 }
01493
01495 int overlapSize (int level, int codim) const
01496 {
01497 return 0;
01498 }
01499
01501 int overlapSize (int codim) const
01502 {
01503 return 0;
01504 }
01505
01507 int ghostSize (int level, int codim) const
01508 {
01509 return 0;
01510 }
01511
01513 int ghostSize (int codim) const
01514 {
01515 return 0;
01516 }
01517
01518 SIntersectionIterator<const SGrid<dim, dimworld> >&
01519 getRealIntersectionIterator(typename Traits::LeafIntersectionIterator& it)
01520 {
01521 return this->getRealImplementation(it);
01522 }
01523
01524 const SIntersectionIterator<const SGrid<dim, dimworld> >&
01525 getRealIntersectionIterator(const typename Traits::LeafIntersectionIterator& it) const
01526 {
01527 return this->getRealImplementation(it);
01528 }
01529
01530
01531 private:
01532
01533
01534
01535 friend class Dune::SGridLevelIndexSet<Dune::SGrid<dim,dimworld> >;
01536 friend class Dune::SGridLeafIndexSet<Dune::SGrid<dim,dimworld> >;
01537 friend class Dune::SGridGlobalIdSet<Dune::SGrid<dim,dimworld> >;
01538 friend class Dune::SIntersectionIterator<Dune::SGrid<dim,dimworld> >;
01539 friend class Dune::SHierarchicIterator<Dune::SGrid<dim,dimworld> >;
01540 friend class Dune::SEntity<0,dim,Dune::SGrid<dim,dimworld> >;
01541
01542 friend class Dune::SGridLevelIndexSet<const Dune::SGrid<dim,dimworld> >;
01543 friend class Dune::SGridLeafIndexSet<const Dune::SGrid<dim,dimworld> >;
01544 friend class Dune::SGridGlobalIdSet<const Dune::SGrid<dim,dimworld> >;
01545 friend class Dune::SIntersectionIterator<const Dune::SGrid<dim,dimworld> >;
01546 friend class Dune::SHierarchicIterator<const Dune::SGrid<dim,dimworld> >;
01547 friend class Dune::SEntity<0,dim,const Dune::SGrid<dim,dimworld> >;
01548
01549 template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
01550 friend class Entity;
01551
01552
01553
01554
01555 template<int codim>
01556 SEntity<codim,dim,const SGrid<dim,dimworld> >& getRealEntity(typename Traits::template Codim<codim>::Entity& e )
01557 {
01558 return this->getRealImplementaion(e);
01559 }
01560
01561 template<int codim>
01562 const SEntity<codim,dim,const SGrid<dim,dimworld> >& getRealEntity(const typename Traits::template Codim<codim>::Entity& e ) const
01563 {
01564 return this->getRealImplementation(e);
01565 }
01566
01567
01568 SGrid(const SGrid &) {};
01569 SGrid & operator = (const SGrid &) { return *this; };
01570
01571 void makeSGrid (const int* N_, const sgrid_ctype* L_, const sgrid_ctype* H_);
01572
01573
01574
01575
01576 CollectiveCommunication<SGrid> ccobj;
01577
01578 std::vector<SGridLevelIndexSet<const SGrid<dim,dimworld> >*> indexsets;
01579 SGridLeafIndexSet<const SGrid<dim,dimworld> > *theleafindexset;
01580 SGridGlobalIdSet<const SGrid<dim,dimworld> > *theglobalidset;
01581
01582 int L;
01583 FieldVector<sgrid_ctype, dim> low;
01584 FieldVector<sgrid_ctype, dim> H;
01585 FixedArray<int,dim> *N;
01586 FieldVector<sgrid_ctype, dim> *h;
01587 mutable CubeMapper<dim> *mapper;
01588
01589
01590 mutable FixedArray <int,dim> zrefStatic;
01591 mutable FixedArray <int,dim> zentityStatic;
01592 };
01593
01594 namespace Capabilities
01595 {
01596
01608 template<int dim, int dimw, int cdim>
01609 struct hasEntity< SGrid<dim,dimw>, cdim>
01610 {
01611 static const bool v = true;
01612 };
01613
01617 template<int dim, int dimw>
01618 struct isLevelwiseConforming< SGrid<dim,dimw> >
01619 {
01620 static const bool v = true;
01621 };
01622
01626 template<int dim, int dimw>
01627 struct isLeafwiseConforming< SGrid<dim,dimw> >
01628 {
01629 static const bool v = true;
01630 };
01631
01635 template<int dim, int dimw>
01636 struct IsUnstructured< SGrid<dim,dimw> >
01637 {
01638 static const bool v = false;
01639 };
01640
01644 template<int dim, int dimw>
01645 struct hasHangingNodes< SGrid<dim,dimw> >
01646 {
01647 static const bool v = false;
01648 };
01649
01650 }
01651
01652 }
01653
01654 #include"sgrid/sgrid.cc"
01655
01656 #endif