00001 #ifndef DUNE_ALBERTAGRID_IMP_HH
00002 #define DUNE_ALBERTAGRID_IMP_HH
00003
00004 #if HAVE_ALBERTA
00005
00006 #include <iostream>
00007 #include <fstream>
00008 #include <dune/common/deprecated.hh>
00009
00010 #include <vector>
00011 #include <assert.h>
00012 #include <algorithm>
00013
00019
00020 #include <dune/common/misc.hh>
00021 #include <dune/common/interfaces.hh>
00022 #include <dune/common/fvector.hh>
00023 #include <dune/common/fmatrix.hh>
00024 #include <dune/grid/common/capabilities.hh>
00025 #include <dune/common/stdstreams.hh>
00026
00027 #if HAVE_MPI
00028 #include <dune/common/mpicollectivecommunication.hh>
00029 #else
00030 #include <dune/common/collectivecommunication.hh>
00031 #endif
00032
00033 #include <dune/common/exceptions.hh>
00034
00035 #include <dune/grid/common/grid.hh>
00036 #include <dune/grid/common/defaultindexsets.hh>
00037 #include <dune/grid/common/sizecache.hh>
00038 #include <dune/grid/common/intersectioniteratorwrapper.hh>
00039 #include <dune/grid/common/defaultgridview.hh>
00040
00041
00042 #include <dune/grid/common/indexstack.hh>
00043
00044
00045
00046 #include "albertaheader.hh"
00047
00048
00049 #include <dune/grid/utility/grapedataioformattypes.hh>
00050
00051
00052
00053 typedef Dune::IndexStack<int,100000> IndexManagerType;
00054
00055
00056
00057 #include "albertaextra.hh"
00058
00059 #include <dune/grid/albertagrid/exceptions.hh>
00060
00061
00062 #include "agmemory.hh"
00063
00064 namespace Dune
00065 {
00066
00067 typedef ALBERTA REAL albertCtype;
00068 }
00069
00070 #include "referencetopo.hh"
00071 #include "indexsets.hh"
00072 #include "geometry.hh"
00073
00074 namespace Dune
00075 {
00076 template<int codim, int dim, class GridImp> class AlbertaGridEntity;
00077 template<int codim, PartitionIteratorType pitype, class GridImp> class AlbertaGridTreeIterator;
00078 template<int codim, PartitionIteratorType pitype, class GridImp> class AlbertaGridLeafIterator;
00079 template<int cd, class GridImp> class AlbertaGridEntityPointer;
00080
00081 template<class GridImp> class AlbertaGridHierarchicIterator;
00082 template<class GridImp> class AlbertaGridIntersectionIterator;
00083 template<int dim, int dimworld> class AlbertaGrid;
00084 template<int dim, int dimworld> class AlbertaGridHierarchicIndexSet;
00085
00086 template <int codim, int dim, class GridImp>
00087 struct SelectEntityImp
00088 {
00089 typedef AlbertaGridEntity<codim,dim,GridImp> EntityImp;
00090 typedef Dune::Entity<codim, dim, const GridImp, AlbertaGridEntity> Entity;
00091 typedef MakeableInterfaceObject<Entity> EntityObject;
00092 };
00093
00097 class AlbertaMarkerVector
00098 {
00099 friend class AlbertaGrid<2,2>;
00100 friend class AlbertaGrid<2,3>;
00101 friend class AlbertaGrid<3,3>;
00102
00103 enum { vxBufferSize_ = 10000 };
00104 public:
00107 AlbertaMarkerVector (bool meLevel=true) : up2Date_(false), meLevel_(meLevel) {} ;
00108
00110 bool vertexNotOnElement(const int elIndex, const int vertex) const;
00111
00113 bool edgeNotOnElement(const int elIndex, const int edge) const;
00114
00116 bool faceNotOnElement(const int elIndex, const int face) const;
00117
00119 template <class GridType>
00120 void markNewVertices(GridType &grid, int level);
00121
00123 template <class GridType>
00124 void markNewLeafVertices(GridType &grid);
00125
00127 bool up2Date () const { return up2Date_; }
00128
00130 void unsetUp2Date () { up2Date_ = false; }
00131
00133 void print() const;
00134
00135 private:
00136 typedef std::vector<int> ArrayType;
00137
00138
00139 ArrayType vec_;
00140 ArrayType edgevec_;
00141 ArrayType facevec_;
00142
00143
00144 int numVertex_;
00145
00146
00147 bool up2Date_;
00148 bool meLevel_;
00149 };
00150
00151
00152
00153
00154
00155
00162 template<int cd, int dim, class GridImp>
00163 class AlbertaGridEntity :
00164 public EntityDefaultImplementation <cd,dim,GridImp,AlbertaGridEntity>
00165 {
00166 enum { dimworld = GridImp::dimensionworld };
00167 friend class AlbertaGrid < dim , dimworld >;
00168 friend class AlbertaGridEntity < 0, dim, GridImp>;
00169 friend class AlbertaGridTreeIterator < cd, All_Partition,GridImp>;
00170 friend class AlbertaGridEntityPointer<cd,GridImp>;
00171
00172 typedef AlbertaGridGeometry<dim-cd,dimworld,GridImp> GeometryImp;
00173 public:
00174 template <int cc>
00175 struct Codim
00176 {
00177 typedef typename GridImp::template Codim<cc>::EntityPointer EntityPointer;
00178 };
00179
00180 typedef typename GridImp::template Codim<cd>::Entity Entity;
00181 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00182 typedef typename GridImp::template Codim<cd>::Geometry Geometry;
00183 typedef typename GridImp::template Codim<cd>::LevelIterator LevelIterator;
00184
00186 int level () const;
00187
00189 int boundaryId () const ;
00190
00192 AlbertaGridEntity(const GridImp &grid, int level,
00193 ALBERTA TRAVERSE_STACK * travStack);
00194
00196 AlbertaGridEntity(const GridImp &grid, int level, bool);
00197
00199 AlbertaGridEntity(const AlbertaGridEntity & org);
00200
00202 PartitionType partitionType() const;
00203
00205 const Geometry & geometry () const;
00206
00208 GeometryType type () const;
00209
00210
00211
00212
00214 ALBERTA EL_INFO *getElInfo () const;
00216 ALBERTA EL *getElement () const;
00217
00219 void removeElInfo();
00220
00223 int getFEVnum () const;
00224
00226 bool equals ( const AlbertaGridEntity<cd,dim,GridImp> & i) const;
00227
00228
00229 bool leafIt () const { return false; }
00230
00231
00232 void setTraverseStack (ALBERTA TRAVERSE_STACK *travStack);
00233 void setElInfo (ALBERTA EL_INFO *elInfo, int face,
00234 int edge, int vertex );
00235
00236
00237 void setEntity (const AlbertaGridEntity<cd,dim,GridImp> & org);
00238
00239
00240 void setLevel ( int newLevel );
00241 void setNewLevel ( int newLevel , bool ) { setLevel(level); }
00242
00244 const GridImp& grid() const { return grid_; }
00245
00246 private:
00247 const GeometryImp &geoImp () const
00248 {
00249 return GridImp :: getRealImplementation( geo_ );
00250 }
00251
00252 GeometryImp &geoImp ()
00253 {
00254 return GridImp :: getRealImplementation( geo_ );
00255 }
00256
00257 private:
00258
00259 const GridImp &grid_;
00260
00261
00262 ALBERTA EL_INFO *elInfo_;
00263
00264
00265 ALBERTA EL * element_;
00266
00267
00268 ALBERTA TRAVERSE_STACK * travStack_;
00269
00271 int level_;
00272
00273
00274 typedef MakeableInterfaceObject<Geometry> GeometryObject;
00275
00277 GeometryObject geo_;
00278
00280 mutable bool builtgeometry_;
00281
00283 mutable FieldVector<albertCtype, dim> localFatherCoords_;
00284 mutable bool localFCoordCalced_;
00285
00287 int face_;
00288
00290 int edge_;
00291
00293 int vertex_;
00294 };
00295
00309
00310
00311
00312
00313
00314
00315 template<int dim, class GridImp>
00316 class AlbertaGridEntity<0,dim,GridImp> :
00317 public EntityDefaultImplementation <0,dim,GridImp,AlbertaGridEntity>
00318 {
00319 enum { dimworld = GridImp::dimensionworld };
00320 friend class AlbertaGrid < dim , GridImp::dimensionworld >;
00321 friend class AlbertaMarkerVector;
00322 friend class AlbertaGridIntersectionIterator <GridImp>;
00323 friend class AlbertaGridHierarchicIterator <GridImp>;
00324 friend class AlbertaGridTreeIterator <0,All_Partition,GridImp>;
00325 friend class AlbertaGridEntityPointer<0,GridImp>;
00326 public:
00327 template <int cd>
00328 struct Codim
00329 {
00330 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
00331 };
00332
00333 typedef typename GridImp::template Codim<0>::Entity Entity;
00334 typedef typename GridImp::template Codim<0>::Geometry Geometry;
00335 typedef AlbertaGridGeometry<dim,dimworld,GridImp> GeometryImp;
00336
00337 typedef typename GridImp::template Codim<0>::LevelIterator LevelIterator;
00338 typedef typename GridImp::template Codim<0>::HierarchicIterator HierarchicIterator;
00339 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00340
00341 typedef LeafIntersectionIteratorWrapper<GridImp> AlbertaGridLeafIntersectionIteratorType;
00342 typedef AlbertaGridLeafIntersectionIteratorType AlbertaGridIntersectionIteratorType;
00343 typedef AlbertaGridLeafIntersectionIteratorType AlbertaGridLevelIntersectionIteratorType;
00344
00345 enum { dimension = dim };
00346
00350 ~AlbertaGridEntity() {};
00351
00353 AlbertaGridEntity(const GridImp &grid, int level, bool leafIt );
00354
00355 AlbertaGridEntity(const AlbertaGridEntity & org);
00356
00358 int level () const;
00359
00361 int boundaryId () const;
00362
00364 const Geometry & geometry () const;
00365
00367 GeometryType type () const;
00368
00372
00373 template<int cc> int count () const;
00374
00377 template<int cc> typename Codim<cc>::EntityPointer entity (int i) const;
00378
00381
00382
00388 AlbertaGridLeafIntersectionIteratorType ileafbegin () const;
00389 AlbertaGridIntersectionIteratorType ibegin () const
00390 {
00391 return ileafbegin();
00392 }
00393
00394 AlbertaGridLevelIntersectionIteratorType ilevelbegin () const
00395 {
00396 DUNE_THROW(NotImplemented,"method ilevelbegin not implemented!");
00397 return ileafbegin();
00398 }
00399
00401 AlbertaGridIntersectionIteratorType ileafend () const;
00402 AlbertaGridIntersectionIteratorType iend () const{ return ileafend();}
00403 AlbertaGridLeafIntersectionIteratorType ilevelend () const
00404 {
00405 DUNE_THROW(NotImplemented,"method ilevelend not implemented!");
00406 return ibegin();
00407 }
00408
00410 bool isLeaf () const ;
00411
00414 EntityPointer father () const;
00415
00426 const Geometry & geometryInFather () const;
00427
00432 AlbertaGridHierarchicIterator<GridImp> hbegin (int maxlevel) const;
00433
00435 AlbertaGridHierarchicIterator<GridImp> hend (int maxlevel) const;
00436
00439 bool wasRefined () const DUNE_DEPRECATED {return isNew();}
00440
00443 bool mightBeCoarsened () const DUNE_DEPRECATED { return mightVanish(); }
00444
00447 bool isNew () const ;
00448
00451 bool mightVanish () const ;
00452
00455 bool hasBoundaryIntersections () const ;
00456
00458 PartitionType partitionType() const;
00459
00461 bool equals ( const AlbertaGridEntity<0,dim,GridImp> & i) const;
00462
00463
00464
00465
00466
00467 void setLeafData( int proc );
00468
00469
00470 bool master() const;
00471
00472
00473 int getFEVnum () const { return 0; }
00474
00475
00476 ALBERTA EL_INFO *getElInfo () const;
00477
00478
00479 ALBERTA EL *getElement () const;
00480
00481
00482 void removeElInfo();
00483
00484
00485 bool leafIt () const { return leafIt_; }
00486
00487
00488
00489 void setTraverseStack (ALBERTA TRAVERSE_STACK *travStack);
00490 void setElInfo (ALBERTA EL_INFO *elInfo,
00491 int face = 0,
00492 int edge = 0,
00493 int vertex = 0 );
00494
00495
00496 void setEntity (const AlbertaGridEntity<0,dim,GridImp> & org);
00497
00499 const GridImp& grid() const { return grid_; }
00500 private:
00502 int nChild () const;
00503
00505 void makeDescription();
00506
00508 const GridImp & grid_;
00509
00511 int level_;
00512
00514 ALBERTA TRAVERSE_STACK * travStack_;
00515
00517 ALBERTA EL_INFO *elInfo_;
00518
00520 ALBERTA EL *element_;
00521
00522
00523 typedef MakeableInterfaceObject<Geometry> GeometryObject;
00524
00526 mutable GeometryObject geoObj_;
00527 mutable GeometryImp & geo_;
00528 mutable bool builtgeometry_;
00529
00530
00531 bool leafIt_;
00532
00533 };
00534
00535
00536
00537
00538
00539
00540
00544 template<int cd, class GridImp>
00545 class AlbertaGridEntityPointer
00546 {
00547 enum { dim = GridImp::dimension };
00548 enum { dimworld = GridImp::dimensionworld };
00549
00550 friend class AlbertaGridEntity<cd,dim,GridImp>;
00551 friend class AlbertaGridEntity< 0,dim,GridImp>;
00552 friend class AlbertaGrid < dim , dimworld >;
00553
00554 public:
00555 enum { codimension = cd };
00556
00557 typedef typename GridImp::template Codim<cd>::Entity Entity;
00558 typedef typename SelectEntityImp<cd,dim,GridImp>::EntityImp EntityImp;
00559 typedef typename SelectEntityImp<cd,dim,GridImp>::EntityObject EntityObject;
00560 typedef AlbertaGridEntityPointer<cd,GridImp> EntityPointerImp;
00561
00563 typedef AlbertaGridEntityPointer<cd,GridImp> AlbertaGridEntityPointerType;
00564
00566 AlbertaGridEntityPointer(const GridImp & grid,
00567 int level, ALBERTA EL_INFO *elInfo,int face,int edge,int vertex);
00568
00570 AlbertaGridEntityPointer(const GridImp & grid, ALBERTA TRAVERSE_STACK * stack,
00571 int level, ALBERTA EL_INFO *elInfo,int face,int edge,int vertex);
00572
00574 AlbertaGridEntityPointer(const GridImp & grid, int level , bool isLeaf, bool done);
00575
00577 AlbertaGridEntityPointer(const EntityImp& entity);
00578
00580 AlbertaGridEntityPointer(const AlbertaGridEntityPointerType & org);
00581
00583 AlbertaGridEntityPointer(const GridImp & , const EntityImp & en);
00584
00586 AlbertaGridEntityPointer& operator= (const AlbertaGridEntityPointer& org);
00587
00589 ~AlbertaGridEntityPointer();
00590
00592 bool equals (const AlbertaGridEntityPointerType& i) const;
00593
00595 Entity & dereference () const ;
00596
00598 int level () const ;
00599
00601 void done ();
00602
00604 void compactify() {}
00605
00606 protected:
00608 bool leafIt () const { return isLeaf_; }
00609
00611 EntityImp & entityImp ();
00612
00614 const EntityImp & entityImp () const;
00615
00616
00617 const GridImp & grid_;
00618
00620 bool isLeaf_;
00621
00622
00623 EntityObject * entity_;
00624 };
00625
00626
00627
00628
00629
00630
00640 template<class GridImp>
00641 class AlbertaGridHierarchicIterator
00642 : public AlbertaGridEntityPointer<0,GridImp>
00643 {
00644 public:
00645 typedef typename GridImp::template Codim<0>::Entity Entity;
00646 typedef typename GridImp::ctype ctype;
00647
00648 typedef typename SelectEntityImp<0,GridImp::dimension,GridImp>::EntityImp EntityImp;
00649
00651 AlbertaGridHierarchicIterator(const GridImp &grid,
00652 ALBERTA TRAVERSE_STACK *travStack,
00653 int actLevel, int maxLevel, bool leafIt );
00654
00656 AlbertaGridHierarchicIterator(const GridImp &grid,
00657 int actLevel,int maxLevel);
00658
00660 AlbertaGridHierarchicIterator(const AlbertaGridHierarchicIterator<GridImp> &org);
00661
00663 AlbertaGridHierarchicIterator<GridImp> & operator = (const AlbertaGridHierarchicIterator<GridImp> &org);
00664
00666 void increment();
00667
00668 private:
00669 const int startLevel_;
00670
00672 int level_;
00673
00675 int maxlevel_;
00676
00678 EntityImp & virtualEntity_;
00679
00682 ALBERTA ManageTravStack manageStack_;
00683
00685 bool end_;
00686
00688 ALBERTA EL_INFO * recursiveTraverse(ALBERTA TRAVERSE_STACK * stack);
00689
00691 ALBERTA EL_INFO * firstChild(ALBERTA TRAVERSE_STACK * stack);
00692
00694 void makeIterator();
00695 };
00696
00697
00698
00699
00700
00701
00709 template<class GridImp>
00710 class AlbertaGridIntersectionIterator
00711 {
00712 enum { dim = GridImp::dimension };
00713 enum { dimworld = GridImp::dimensionworld };
00714
00715 friend class AlbertaGridEntity<0,dim,GridImp>;
00716 typedef AlbertaGridIntersectionIterator<GridImp> ThisType;
00717
00718 public:
00719 typedef Dune::Intersection< GridImp, Dune::AlbertaGridIntersectionIterator >
00720 Intersection;
00721 typedef ThisType ImplementationType;
00722
00723 typedef AGMemoryProvider< ThisType > StorageType;
00724 typedef typename GridImp::template Codim<0>::Entity Entity;
00725 typedef typename GridImp::template Codim<1>::Geometry Geometry;
00726 typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
00727
00728 typedef typename SelectEntityImp<0,dim,GridImp>::EntityImp EntityImp;
00729
00730
00731 typedef AlbertaGridGeometry<dim-1,dimworld,GridImp> LocalGeometryImp;
00732 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00733
00735 enum { dimension=dim };
00737 enum { dimensionworld=dimworld };
00739 typedef typename GridImp::ctype ctype;
00740
00741 const Intersection &dereference () const
00742 {
00743 return reinterpret_cast< const Intersection & >( *this );
00744 }
00745
00747 bool equals (const AlbertaGridIntersectionIterator<GridImp> & i) const;
00748
00750 void increment();
00751
00753 bool operator==(const AlbertaGridIntersectionIterator<GridImp>& i) const;
00754
00756 EntityPointer outside() const;
00757
00759 EntityPointer inside() const;
00760
00762 AlbertaGridIntersectionIterator(const GridImp & grid,
00763 int level);
00764
00766 AlbertaGridIntersectionIterator(const GridImp & grid,
00767 int level,
00768 ALBERTA EL_INFO *elInfo,
00769 bool leafIt );
00771 AlbertaGridIntersectionIterator(const AlbertaGridIntersectionIterator<GridImp> & org);
00772
00774 void assign (const AlbertaGridIntersectionIterator<GridImp> & org);
00775
00777
00778
00780 bool boundary () const;
00781
00783 bool neighbor () const;
00784
00786 int boundaryId () const;
00787
00789 bool conforming () const;
00790
00795 const LocalGeometry& intersectionSelfLocal () const;
00799 const LocalGeometry& intersectionNeighborLocal () const;
00803 const Geometry& intersectionGlobal () const;
00804
00806 int numberInSelf () const;
00808 int numberInNeighbor () const;
00809
00811 int twistInSelf() const;
00812
00814 int twistInNeighbor() const;
00815
00818 typedef FieldVector<albertCtype, GridImp::dimensionworld> NormalVecType;
00819 typedef FieldVector<albertCtype, GridImp::dimension-1> LocalCoordType;
00820
00821 const NormalVecType & unitOuterNormal (const LocalCoordType & local) const;
00822
00825 const NormalVecType & outerNormal (const LocalCoordType & local) const;
00826
00829 const NormalVecType & integrationOuterNormal (const LocalCoordType & local) const;
00830
00832 int level () const;
00833
00834
00835
00836
00837
00838
00839 template <class EntityType>
00840 void first(const EntityType & en, int level );
00841
00842
00843 void done ();
00844
00845 private:
00846
00847 bool neighborHasSameLevel () const;
00848
00850 void makeBegin (const GridImp & grid,
00851 int level,
00852 ALBERTA EL_INFO * elInfo ) const;
00853
00855 void makeEnd (const GridImp & grid,int level ) const;
00856
00857
00858 void freeObjects () const;
00859
00861 void setupVirtEn () const;
00862
00864 void calcOuterNormal () const;
00865
00866
00867
00868 bool leafIt () const { return leafIt_; }
00870
00872
00874 const GridImp& grid_;
00875
00877 mutable int level_;
00878
00880 mutable int neighborCount_;
00881
00885 mutable bool builtNeigh_;
00886
00887 bool leafIt_;
00888
00890 mutable ALBERTA EL_INFO * elInfo_;
00891
00892 typedef MakeableInterfaceObject<LocalGeometry> LocalGeometryObject;
00893
00894
00895 mutable LocalGeometryObject fakeNeighObj_;
00896 mutable LocalGeometryObject fakeSelfObj_;
00897 mutable LocalGeometryObject neighGlobObj_;
00898
00901 mutable LocalGeometryImp & fakeNeigh_;
00904 mutable LocalGeometryImp & fakeSelf_;
00907 mutable LocalGeometryImp & neighGlob_;
00908
00910 mutable ALBERTA EL_INFO neighElInfo_;
00911
00912 mutable NormalVecType outNormal_;
00913 mutable NormalVecType unitNormal_;
00914
00915
00916 mutable FieldVector<albertCtype, dimworld> tmpU_;
00917 mutable FieldVector<albertCtype, dimworld> tmpV_;
00918
00919
00920 mutable int twist_;
00921
00923 bool done_;
00924 };
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937 namespace AlbertaTreeIteratorHelp {
00938 template <class IteratorImp, int dim, int codim>
00939 struct GoNextEntity;
00940 }
00941
00945 template<int cd, PartitionIteratorType pitype, class GridImp>
00946 class AlbertaGridTreeIterator :
00947 public AlbertaGridEntityPointer<cd,GridImp>
00948 {
00949 enum { dim = GridImp::dimension };
00950 friend class AlbertaGridEntity<2,dim,GridImp>;
00951 friend class AlbertaGridEntity<1,dim,GridImp>;
00952 friend class AlbertaGridEntity<0,dim,GridImp>;
00953 friend class AlbertaGrid < dim , GridImp::dimensionworld >;
00954
00955
00956 typedef AlbertaGridTreeIterator<cd,pitype,GridImp> AlbertaGridTreeIteratorType;
00957 typedef AlbertaGridTreeIteratorType ThisType;
00958 friend class AlbertaTreeIteratorHelp::GoNextEntity<ThisType,dim,cd>;
00959 public:
00960
00961 typedef typename GridImp::template Codim<cd>::Entity Entity;
00962 typedef typename SelectEntityImp<cd,dim,GridImp>::EntityImp EntityImp;
00963
00965 AlbertaGridTreeIterator(const AlbertaGridTreeIterator<cd,pitype,GridImp> & org );
00966
00968 AlbertaGridTreeIterator<cd,pitype,GridImp> & operator = (const AlbertaGridTreeIterator<cd,pitype,GridImp> & org );
00969
00971 AlbertaGridTreeIterator(const GridImp & grid, int
00972 travLevel, int proc, bool leafIt=false );
00973
00975 AlbertaGridTreeIterator(const GridImp & grid,
00976 const AlbertaMarkerVector * vec,
00977 int travLevel,
00978 int proc,
00979 bool leafIt=false);
00980
00982 void increment();
00984
00985 private:
00986
00987 void makeIterator();
00988
00989 ALBERTA EL_INFO * goFirstElement(ALBERTA TRAVERSE_STACK *stack,
00990 ALBERTA MESH *mesh,
00991 int level, ALBERTA FLAGS fill_flag);
00992 ALBERTA EL_INFO * traverseElLevel(ALBERTA TRAVERSE_STACK * stack);
00993 ALBERTA EL_INFO * traverseElLevelInteriorBorder(ALBERTA TRAVERSE_STACK * stack);
00994 ALBERTA EL_INFO * traverseElLevelGhosts(ALBERTA TRAVERSE_STACK * stack);
00995
00996
00997
00998 ALBERTA EL_INFO * goNextEntity(ALBERTA TRAVERSE_STACK *stack,ALBERTA EL_INFO *elinfo_old);
00999
01000
01001 ALBERTA EL_INFO * goNextElInfo(ALBERTA TRAVERSE_STACK *stack,ALBERTA EL_INFO *elinfo_old);
01002 ALBERTA EL_INFO * goNextFace(ALBERTA TRAVERSE_STACK *stack,
01003 ALBERTA EL_INFO *elInfo);
01004 ALBERTA EL_INFO * goNextEdge(ALBERTA TRAVERSE_STACK *stack,
01005 ALBERTA EL_INFO *elInfo);
01006 ALBERTA EL_INFO * goNextVertex(ALBERTA TRAVERSE_STACK *stack,
01007 ALBERTA EL_INFO *elInfo);
01008
01009
01010 ALBERTA MACRO_EL * nextGhostMacro(ALBERTA MACRO_EL *mel);
01011
01013 int level_;
01014
01016 int enLevel_;
01017
01019 EntityImp & virtualEntity_;
01020
01021
01022 ALBERTA ManageTravStack manageStack_;
01023
01025 int face_;
01026 int edge_;
01027 int vertex_;
01028
01029
01030 const AlbertaMarkerVector * vertexMarker_;
01031
01032
01033 bool okReturn_;
01034
01035
01036
01037
01038 const int proc_;
01039 };
01040
01043 template<int cd, PartitionIteratorType pitype, class GridImp>
01044 class AlbertaGridLevelIterator
01045 : public AlbertaGridTreeIterator<cd,pitype,GridImp>
01046 {
01047 public:
01048 typedef typename GridImp::template Codim<cd>::Entity Entity;
01049
01051 AlbertaGridLevelIterator(const GridImp & grid, int level, int proc) :
01052 AlbertaGridTreeIterator<cd,pitype,GridImp> (grid,level,proc)
01053 {
01054 }
01055
01057 AlbertaGridLevelIterator(const GridImp & grid,
01058 const AlbertaMarkerVector * vec, int level, int proc) :
01059 AlbertaGridTreeIterator<cd,pitype,GridImp> (grid,vec,level,proc)
01060 {
01061 }
01062
01064 void increment ()
01065 {
01066 AlbertaGridTreeIterator<cd,pitype,GridImp>::increment();
01067 }
01068 };
01069
01070
01071
01072
01073
01074
01075
01077 template<int codim, PartitionIteratorType pitype, class GridImp>
01078 class AlbertaGridLeafIterator
01079 : public AlbertaGridTreeIterator<codim, pitype, GridImp>
01080 {
01081 public:
01082 typedef typename GridImp::template Codim<codim>::Entity Entity;
01083
01085 AlbertaGridLeafIterator(const GridImp & grid, int level, int proc) :
01086 AlbertaGridTreeIterator<codim,pitype,GridImp> (grid,level,proc,true)
01087 {
01088 }
01089
01091 AlbertaGridLeafIterator(const GridImp & grid,
01092 const AlbertaMarkerVector * vec, int level, int proc) :
01093 AlbertaGridTreeIterator<codim, pitype, GridImp> (grid,vec,level,proc,true)
01094 {
01095 }
01096
01098 void increment ()
01099 {
01100 AlbertaGridTreeIterator<codim, pitype, GridImp>::increment();
01101 }
01102 };
01103
01104
01105
01106
01107
01108
01109
01110
01111 template <int dim, int dimworld>
01112 struct AlbertaGridFamily
01113 {
01114 typedef AlbertaGrid<dim,dimworld> GridImp;
01115
01116 typedef DefaultLevelIndexSet< AlbertaGrid<dim,dimworld> > LevelIndexSetImp;
01117 typedef DefaultLeafIndexSet< AlbertaGrid<dim,dimworld> > LeafIndexSetImp;
01118
01119 typedef AlbertaGridIdSet<dim,dimworld> IdSetImp;
01120 typedef int IdType;
01121
01122 struct Traits
01123 {
01124 typedef GridImp Grid;
01125
01126 typedef Dune :: Intersection< const GridImp, LeafIntersectionIteratorWrapper > LeafIntersection;
01127 typedef Dune :: Intersection< const GridImp, LeafIntersectionIteratorWrapper > LevelIntersection;
01128 typedef Dune::IntersectionIterator<const GridImp, LeafIntersectionIteratorWrapper, LeafIntersectionIteratorWrapper > LeafIntersectionIterator;
01129 typedef Dune::IntersectionIterator<const GridImp, LeafIntersectionIteratorWrapper, LeafIntersectionIteratorWrapper > LevelIntersectionIterator;
01130
01131 typedef Dune::HierarchicIterator<const GridImp, AlbertaGridHierarchicIterator> HierarchicIterator;
01132
01133 typedef IdType GlobalIdType;
01134 typedef IdType LocalIdType;
01135
01136 template <int cd>
01137 struct Codim
01138 {
01139
01140 typedef Dune::Geometry<dim-cd, dimworld, const GridImp, AlbertaGridGeometry> Geometry;
01141 typedef Dune::Geometry<dim-cd, dim, const GridImp, AlbertaGridGeometry> LocalGeometry;
01142
01143
01144 typedef typename SelectEntityImp<cd,dim,GridImp>::Entity Entity;
01145
01146 typedef Dune::LevelIterator<cd,All_Partition,const GridImp,AlbertaGridLevelIterator> LevelIterator;
01147
01148 typedef Dune::LeafIterator<cd,All_Partition,const GridImp,AlbertaGridLeafIterator> LeafIterator;
01149
01150 typedef AlbertaGridEntityPointer< cd, const GridImp > EntityPointerImpl;
01151 typedef Dune::EntityPointer< const GridImp, EntityPointerImpl > EntityPointer;
01152
01153 template <PartitionIteratorType pitype>
01154 struct Partition
01155 {
01156 typedef Dune::LevelIterator<cd,pitype,const GridImp,AlbertaGridLevelIterator> LevelIterator;
01157 typedef Dune::LeafIterator<cd,pitype,const GridImp,AlbertaGridLeafIterator> LeafIterator;
01158 };
01159
01160 };
01161
01162 template <PartitionIteratorType pitype>
01163 struct Partition
01164 {
01165 typedef Dune::GridView<DefaultLevelGridViewTraits<const GridImp,pitype> >
01166 LevelGridView;
01167 typedef Dune::GridView<DefaultLeafGridViewTraits<const GridImp,pitype> >
01168 LeafGridView;
01169 };
01170
01171 typedef IndexSet<GridImp,LevelIndexSetImp,DefaultLevelIteratorTypes<GridImp> > LevelIndexSet;
01172 typedef IndexSet<GridImp,LeafIndexSetImp,DefaultLeafIteratorTypes<GridImp> > LeafIndexSet;
01173 typedef IdSet<GridImp,IdSetImp,IdType> GlobalIdSet;
01174 typedef IdSet<GridImp,IdSetImp,IdType> LocalIdSet;
01175
01176
01177
01178
01179
01180
01181 typedef Dune :: CollectiveCommunication< GridImp >
01182 CollectiveCommunication;
01183
01184 };
01185 };
01186
01232 template <int dim, int dimworld>
01233 class AlbertaGrid :
01234 public GridDefaultImplementation <dim,dimworld,albertCtype, AlbertaGridFamily<dim,dimworld> >,
01235 public HasObjectStream ,
01236 public HasHierarchicIndexSet
01237 {
01238 friend class AlbertaGridEntity <0,dim,const AlbertaGrid<dim,dimworld> >;
01239 friend class AlbertaGridEntity <1,dim,const AlbertaGrid<dim,dimworld> >;
01240 friend class AlbertaGridEntity <2,dim,const AlbertaGrid<dim,dimworld> >;
01241 friend class AlbertaGridEntity <dim,dim,const AlbertaGrid<dim,dimworld> >;
01242
01243 friend class AlbertaGridEntityPointer <0,const AlbertaGrid<dim,dimworld> >;
01244 friend class AlbertaGridEntityPointer <1,const AlbertaGrid<dim,dimworld> >;
01245 friend class AlbertaGridEntityPointer <2,const AlbertaGrid<dim,dimworld> >;
01246 friend class AlbertaGridEntityPointer <3,const AlbertaGrid<dim,dimworld> >;
01247
01248
01249 friend class AlbertaGridTreeIterator<0,All_Partition,AlbertaGrid<dim,dimworld> >;
01250 friend class AlbertaGridTreeIterator<1,All_Partition,AlbertaGrid<dim,dimworld> >;
01251 friend class AlbertaGridTreeIterator<2,All_Partition,AlbertaGrid<dim,dimworld> >;
01252 friend class AlbertaGridTreeIterator<3,All_Partition,AlbertaGrid<dim,dimworld> >;
01253
01254 friend class AlbertaGridHierarchicIterator<AlbertaGrid<dim,dimworld> >;
01255
01256 friend class AlbertaGridIntersectionIterator<AlbertaGrid<dim,dimworld> >;
01257 friend class AlbertaGridIntersectionIterator<const AlbertaGrid<dim,dimworld> >;
01258
01261
01262
01263 typedef AlbertaGrid<dim,dimworld> MyType;
01264
01265 friend class AlbertaMarkerVector;
01266 friend class AlbertaGridHierarchicIndexSet<dim,dimworld>;
01267
01268
01269 enum { defaultElementChunk_ = 100 };
01270
01271
01272
01273
01274 public:
01276 typedef AlbertaGridFamily<dim,dimworld> GridFamily;
01277 typedef GridDefaultImplementation <dim,dimworld,albertCtype,
01278 AlbertaGridFamily<dim,dimworld> > BaseType;
01279
01281 typedef typename AlbertaGridFamily<dim,dimworld> :: Traits Traits;
01282
01284 typedef AlbertaGridHierarchicIndexSet<dim,dimworld> HierarchicIndexSet;
01285
01286 private:
01288 typedef typename Traits:: CollectiveCommunication CollectiveCommunicationType;
01289
01291 typedef typename Traits::template Codim<0>::LeafIterator LeafIterator;
01292
01294 typedef typename GridFamily:: LevelIndexSetImp LevelIndexSetImp;
01295 typedef typename GridFamily:: LeafIndexSetImp LeafIndexSetImp;
01296
01298 typedef typename Traits :: LeafIndexSet LeafIndexSet;
01299
01301 typedef AlbertaGridIdSet<dim,dimworld> IdSetImp;
01302 typedef typename Traits :: GlobalIdSet GlobalIdSet;
01303 typedef typename Traits :: LocalIdSet LocalIdSet;
01304
01305 public:
01307 typedef typename ALBERTA AlbertHelp::AlbertLeafData<dimworld,dim+1> LeafDataType;
01308
01309 class ObjectStream
01310 {
01311 public:
01312 class EOFException {} ;
01313 template <class T>
01314 void readObject (T &) {}
01315 void readObject (int) {}
01316 void readObject (double) {}
01317 template <class T>
01318 void writeObject (T &) {}
01319 void writeObject (int) {}
01320 void writeObject (double) {}
01321
01322 template <class T>
01323 void read (T &) const {}
01324 template <class T>
01325 void write (const T &) {}
01326 };
01327
01328 typedef ObjectStream ObjectStreamType;
01329
01330 enum {
01332 numCodim = dim+1 };
01333
01334 enum {
01336 MAXL = 64 };
01337
01338
01339
01340
01341
01342
01344 AlbertaGrid(const std::string macroTriangFilename);
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01356 AlbertaGrid();
01357
01359 ~AlbertaGrid();
01360
01363 int maxLevel() const;
01364
01366 template<int cd, PartitionIteratorType pitype>
01367 typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
01368 lbegin (int level) const;
01369
01371 template<int cd, PartitionIteratorType pitype>
01372 typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
01373 lend (int level) const;
01374
01376 template<int cd> typename Traits::template Codim<cd>::
01377 template Partition<All_Partition>::LevelIterator
01378 lbegin (int level) const;
01379
01381 template<int cd> typename Traits::template Codim<cd>::
01382 template Partition<All_Partition>::LevelIterator
01383 lend (int level) const;
01384
01386 template <int codim, PartitionIteratorType pitype>
01387 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
01388 leafbegin () const;
01389
01391 template <int codim>
01392 typename Traits::template Codim<codim>::LeafIterator
01393 leafbegin () const;
01394
01396 template <int codim, PartitionIteratorType pitype>
01397 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
01398 leafend () const;
01399
01401 template <int codim>
01402 typename Traits::template Codim<codim>::LeafIterator
01403 leafend () const;
01404
01405 private:
01407 template <int codim, PartitionIteratorType pitype>
01408 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
01409 leafbegin ( int maxlevel, int proc = -1 ) const;
01410
01412 template <int codim>
01413 typename Traits::template Codim<codim>::LeafIterator
01414 leafbegin ( int maxlevel, int proc = -1 ) const;
01415
01417 template <int codim, PartitionIteratorType pitype>
01418 typename Traits::template Codim<codim>::template Partition<pitype>::LeafIterator
01419 leafend ( int maxlevel, int proc = -1 ) const;
01420
01422 template <int codim>
01423 typename Traits::template Codim<codim>::LeafIterator
01424 leafend ( int maxlevel, int proc = -1 ) const;
01425
01427 LeafIterator leafbegin ( int maxlevel, int proc = -1 ) const;
01428
01430 LeafIterator leafend ( int maxlevel, int proc = -1 ) const;
01431
01433 LeafIterator leafbegin () const;
01434
01436 LeafIterator leafend () const;
01437
01438 public:
01443 int size (int level, int codim) const;
01444
01446 int size (int level, GeometryType type) const;
01447
01449 int size (int codim) const;
01450
01452 int size (GeometryType type) const;
01453
01454 public:
01455
01456
01457
01459 bool mark( int refCount , const typename Traits::template Codim<0>::EntityPointer & en ) const DUNE_DEPRECATED;
01460
01462 int getMark( const typename Traits::template Codim<0>::EntityPointer & ) const DUNE_DEPRECATED;
01463
01465 int getMark( const typename Traits::template Codim<0>::Entity & ) const;
01466
01468 bool mark( int refCount , const typename Traits::template Codim<0>::Entity & en ) const;
01469
01470 public:
01472 bool globalRefine(int refCount);
01473
01477 bool adapt ( );
01478
01480 template <class DofManagerType, class RestrictProlongOperatorType>
01481 bool adapt (DofManagerType &, RestrictProlongOperatorType &, bool verbose=false );
01482
01484 bool preAdapt ();
01485
01487 bool postAdapt();
01488
01491 const CollectiveCommunicationType & comm () const
01492 {
01493 return comm_;
01494 }
01495
01497 std::string name () const { return "AlbertaGrid"; };
01498
01499
01500
01501
01503 template <GrapeIOFileFormatType ftype>
01504 bool writeGrid( const std::basic_string<char> filename, albertCtype time ) const;
01505
01507 template <GrapeIOFileFormatType ftype>
01508 bool readGrid( const std::basic_string<char> filename, albertCtype & time );
01509
01510
01511
01512
01513
01514
01515 int global_size (int codim) const;
01516
01517
01518 int myRank () const { return myRank_; };
01519
01521 void setNewCoords(const FieldVector<albertCtype, dimworld> & trans, const albertCtype scalar);
01522
01523
01524 const HierarchicIndexSet & hierarchicIndexSet () const { return hIndexSet_; }
01525
01527 const typename Traits :: LevelIndexSet & levelIndexSet (int level) const;
01528
01530 const typename Traits :: LeafIndexSet & leafIndexSet () const;
01531
01533 const GlobalIdSet & globalIdSet () const { return globalIdSet_; }
01534
01536 const LocalIdSet & localIdSet () const { return globalIdSet_; }
01537
01538
01539 ALBERTA MESH* getMesh () const { return mesh_; };
01540
01541
01542 template <int cd>
01543 AlbertaGridEntity<cd,dim,const AlbertaGrid<dim,dimworld> >&
01544 getRealEntity(typename Traits::template Codim<cd>::Entity& entity)
01545 {
01546 return this->getRealImplementation(entity);
01547 }
01548
01549 private:
01551 template <int cd>
01552 const AlbertaGridEntity<cd,dim,const AlbertaGrid<dim,dimworld> >&
01553 getRealEntity(const typename Traits::template Codim<cd>::Entity& entity) const
01554 {
01555 return this->getRealImplementation(entity);
01556 }
01557
01558 public:
01560 const std::vector < GeometryType > & geomTypes (int codim) const
01561 {
01562 assert( codim >= 0 );
01563 assert( codim < dim+1 );
01564 return geomTypes_[codim];
01565 }
01566
01567 private:
01568 friend class Conversion<AlbertaGrid<dim, dimworld>, HasObjectStream>;
01569 friend class Conversion<const AlbertaGrid<dim, dimworld>, HasObjectStream>;
01570
01571 friend class Conversion<AlbertaGrid<dim, dimworld>, HasHierarchicIndexSet >;
01572 friend class Conversion<const AlbertaGrid<dim, dimworld>, HasHierarchicIndexSet>;
01573
01574
01575 AlbertaGrid(const MyType& other);
01576
01577 MyType& operator=(const MyType& other);
01578
01579 private:
01580 typedef std::vector<int> ArrayType;
01581
01582 ArrayType ghostFlag_;
01583
01584
01585 void initGrid(int proc);
01586
01587
01588
01589 void calcExtras();
01590
01591
01592 bool writeGridXdr ( const std::basic_string<char> filename, albertCtype time ) const;
01593
01595 bool readGridXdr ( const std::basic_string<char> filename, albertCtype & time );
01596
01598 bool readGridAscii ( const std::basic_string<char> filename, albertCtype & time );
01599
01600
01601 void removeMesh();
01602
01603
01604 ALBERTA MESH *mesh_;
01605
01606
01607 CollectiveCommunicationType comm_;
01608
01609
01610 int maxlevel_;
01611
01612
01613 bool wasChanged_;
01614
01615
01616 mutable ArrayType macroVertices_;
01617
01618 public:
01619
01620
01621
01622
01623 void fillElInfo(int ichild, int actLevel ,const ALBERTA EL_INFO *elinfo_old,
01624 ALBERTA EL_INFO *elinfo, bool hierachical, bool leaf=false ) const;
01625
01626
01627 void firstNeigh(const int ichild,const ALBERTA EL_INFO *elinfo_old,
01628 ALBERTA EL_INFO *elinfo, const bool leafLevel) const;
01629
01630
01631 void secondNeigh(const int ichild, const ALBERTA EL_INFO *elinfo_old,
01632 ALBERTA EL_INFO *elinfo, const bool leafLevel) const;
01633
01634
01635 void thirdNeigh(const int ichild, const ALBERTA EL_INFO *elinfo_old,
01636 ALBERTA EL_INFO *elinfo, const bool leafLevel) const;
01637
01638 private:
01639
01640 mutable AlbertaMarkerVector vertexMarkerLeaf_;
01641
01642
01643 mutable AlbertaMarkerVector vertexMarkerLevel_[MAXL];
01644
01645
01646
01647
01648 typedef typename SelectEntityImp<0,dim,const MyType>::EntityObject EntityObject;
01649
01650 public:
01651 typedef AGMemoryProvider< EntityObject > EntityProvider;
01652
01653 typedef AlbertaGridIntersectionIterator< const MyType > IntersectionIteratorImp;
01654 typedef IntersectionIteratorImp LeafIntersectionIteratorImp;
01655 typedef AGMemoryProvider< LeafIntersectionIteratorImp > LeafIntersectionIteratorProviderType;
01656 friend class LeafIntersectionIteratorWrapper< const MyType > ;
01657
01658 typedef LeafIntersectionIteratorWrapper<const MyType >
01659 AlbertaGridIntersectionIteratorType;
01660
01661 LeafIntersectionIteratorProviderType & leafIntersetionIteratorProvider() const { return leafInterItProvider_; }
01662
01663 private:
01664 mutable EntityProvider entityProvider_;
01665 mutable LeafIntersectionIteratorProviderType leafInterItProvider_;
01666
01667 public:
01668 template< class IntersectionInterfaceType >
01669 const typename BaseType
01670 :: template ReturnImplementationType< IntersectionInterfaceType >
01671 :: ImplementationType & DUNE_DEPRECATED
01672 getRealIntersectionIterator ( const IntersectionInterfaceType &iterator ) const
01673 {
01674 return this->getRealImplementation( iterator );
01675 }
01676
01677 template< class IntersectionType >
01678 const typename BaseType
01679 :: template ReturnImplementationType< IntersectionType >
01680 :: ImplementationType &
01681 getRealIntersection ( const IntersectionType &intersection ) const
01682 {
01683 return this->getRealImplementation( intersection );
01684 }
01685
01686
01687 template <int codim>
01688 typename SelectEntityImp<codim,dim,const MyType>::EntityObject *
01689 getNewEntity (int level, bool leafIt ) const;
01690
01691
01692 template <int codim>
01693 void freeEntity (typename SelectEntityImp<codim,dim,const MyType>::EntityObject * en) const;
01694
01695 private:
01696
01697
01698
01699
01700 IndexManagerType indexStack_[AlbertHelp::numOfElNumVec];
01701
01702
01703
01704 mutable ALBERTA AlbertHelp::DOFVEC_STACK dofvecs_;
01705
01706 const ALBERTA DOF_ADMIN * elAdmin_;
01707
01708 const ALBERTA REAL_D * coordsVec_;
01709
01710
01711 const int * elNewVec_;
01712
01713
01714 const int nv_;
01715 const int dof_;
01716
01717 public:
01718
01719 void arrangeDofVec();
01720
01721
01722 bool checkElNew ( const ALBERTA EL * el ) const;
01723
01724
01725 const ALBERTA REAL_D & getCoord ( const ALBERTA EL_INFO * elInfo, int vx ) const
01726 {
01727 assert( vx>= 0);
01728 assert( vx < dim+1 );
01729 #ifndef CALC_COORD
01730 assert(coordsVec_);
01731 return coordsVec_[elInfo->el->dof[vx][0]];
01732 #else
01733 return elInfo->coord[vx];
01734 #endif
01735 }
01736
01737
01738 int getLevelOfElement ( const ALBERTA EL * el ) const;
01739
01740
01741 int getElementNumber ( const ALBERTA EL * el ) const;
01742
01743
01744 int getEdgeNumber ( const ALBERTA EL * el, int edge ) const;
01745
01746
01747 int getFaceNumber ( const ALBERTA EL * el, int face ) const;
01748
01749
01750 int getVertexNumber ( const ALBERTA EL * el, int vx ) const;
01751
01752 private:
01753
01754 const