00001 #ifndef DUNE_UGGRID_HH
00002 #define DUNE_UGGRID_HH
00003
00008 #include <dune/grid/common/capabilities.hh>
00009 #include <dune/grid/common/grid.hh>
00010 #include <dune/grid/common/boundarysegment.hh>
00011 #include <dune/common/misc.hh>
00012 #include <dune/common/collectivecommunication.hh>
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #define FOR_DUNE
00029
00030
00031 #define _2
00032
00033 #include "uggrid/ugincludes.hh"
00034
00035
00036
00037 #include "uggrid/ugwrapper2d.hh"
00038
00039
00040
00041 #include "uggrid/ug_undefs.hh"
00042 #undef _2
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #define UGTYPES_H
00053 #define __HEAPS__
00054 #define __UGENV__
00055 #define __PARGM_H__
00056 #define __DEVICESH__
00057 #define __SM__
00058
00059 #define _3
00060 #include "uggrid/ugincludes.hh"
00061
00062
00063
00064 #include "uggrid/ugwrapper3d.hh"
00065
00066
00067 #include "uggrid/ug_undefs.hh"
00068 #undef _3
00069 #undef FOR_DUNE
00070
00071
00072 #include "uggrid/uggridgeometry.hh"
00073 #include "uggrid/uggridentity.hh"
00074 #include "uggrid/uggridentitypointer.hh"
00075 #include "uggrid/ugintersectionit.hh"
00076 #include "uggrid/uggridleveliterator.hh"
00077 #include "uggrid/uggridleafiterator.hh"
00078 #include "uggrid/uggridhieriterator.hh"
00079 #include "uggrid/uggridindexsets.hh"
00080
00081 namespace Dune {
00082
00083 template<int dim, int dimworld>
00084 struct UGGridFamily
00085 {
00086 typedef GridTraits<dim,dimworld,Dune::UGGrid<dim>,
00087 UGGridGeometry,
00088 UGGridEntity,
00089 UGGridEntityPointer,
00090 UGGridLevelIterator,
00091 UGGridLeafIntersectionIterator,
00092 UGGridLevelIntersectionIterator,
00093 UGGridHierarchicIterator,
00094 UGGridLeafIterator,
00095 UGGridLevelIndexSet< const UGGrid<dim> >,
00096 UGGridLevelIndexSetTypes< const UGGrid<dim> >,
00097 UGGridLeafIndexSet< const UGGrid<dim> >,
00098 UGGridLeafIndexSetTypes< const UGGrid<dim> >,
00099 UGGridGlobalIdSet< const UGGrid<dim> >,
00100 unsigned int,
00101 UGGridLocalIdSet< const UGGrid<dim> >,
00102 unsigned int,
00103 CollectiveCommunication<Dune::UGGrid<dim> > >
00104 Traits;
00105 };
00106
00107
00108
00109
00110
00111
00112
00113
00145 template <int dim>
00146 class UGGrid : public GridDefaultImplementation <dim, dim, double, UGGridFamily<dim,dim> >
00147 {
00148 friend class UGGridEntity <0,dim,const UGGrid<dim> >;
00149 friend class UGGridEntity <dim,dim,const UGGrid<dim> >;
00150 friend class UGGridHierarchicIterator<const UGGrid<dim> >;
00151 friend class UGGridLeafIntersectionIterator<const UGGrid<dim> >;
00152 friend class UGGridLevelIntersectionIterator<const UGGrid<dim> >;
00153
00154 friend class UGGridLevelIndexSet<const UGGrid<dim> >;
00155 friend class UGGridLeafIndexSet<const UGGrid<dim> >;
00156 friend class UGGridGlobalIdSet<const UGGrid<dim> >;
00157 friend class UGGridLocalIdSet<const UGGrid<dim> >;
00158
00159 template <int codim_, PartitionIteratorType PiType_, class GridImp_>
00160 friend class UGGridLeafIterator;
00161 template <int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
00162 friend class Entity;
00163
00165 CompileTimeChecker< ((dim==2) || (dim==3)) > Use_UGGrid_only_for_2d_and_3d;
00166
00167
00168
00169 friend class UGGrid<2>;
00170 friend class UGGrid<3>;
00171
00172
00173
00174 public:
00176 typedef UGGridFamily<dim,dim> GridFamily;
00177
00179 typedef typename UGGridFamily<dim,dim>::Traits Traits;
00180
00182 typedef double ctype;
00183
00189 UGGrid(unsigned int heapSize, unsigned int envHeapSize);
00190
00196 UGGrid();
00197
00199 ~UGGrid();
00200
00203 int maxLevel() const;
00204
00206 template<int codim>
00207 typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
00208
00210 template<int codim>
00211 typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
00212
00214 template<int codim, PartitionIteratorType PiType>
00215 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
00216
00218 template<int codim, PartitionIteratorType PiType>
00219 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
00220
00222 template<int codim>
00223 typename Traits::template Codim<codim>::LeafIterator leafbegin() const {
00224 return typename Traits::template Codim<codim>::template Partition<All_Partition>::LeafIterator(*this);
00225 }
00226
00228 template<int codim>
00229 typename Traits::template Codim<codim>::LeafIterator leafend() const {
00230 return UGGridLeafIterator<codim,All_Partition, const UGGrid<dim> >();
00231 }
00232
00234 template<int codim, PartitionIteratorType PiType>
00235 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const {
00236 return typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator(*this);
00237 }
00238
00240 template<int codim, PartitionIteratorType PiType>
00241 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const {
00242 return UGGridLeafIterator<codim,PiType, const UGGrid<dim> >();
00243 }
00244
00247 int size (int level, int codim) const;
00248
00250 int size (int codim) const
00251 {
00252 return leafIndexSet().size(codim);
00253 }
00254
00256 int size (int level, GeometryType type) const
00257 {
00258 return this->levelIndexSet(level).size(type);
00259 }
00260
00262 int size (GeometryType type) const
00263 {
00264 return this->leafIndexSet().size(type);
00265 }
00266
00268 const typename Traits::GlobalIdSet& globalIdSet() const
00269 {
00270 return globalIdSet_;
00271 }
00272
00274 const typename Traits::LocalIdSet& localIdSet() const
00275 {
00276 return localIdSet_;
00277 }
00278
00280 const typename Traits::LevelIndexSet& levelIndexSet(int level) const
00281 {
00282 if (level<0 || level>maxLevel())
00283 DUNE_THROW(GridError, "levelIndexSet of nonexisting level " << level << " requested!");
00284 return *levelIndexSets_[level];
00285 }
00286
00288 const typename Traits::LeafIndexSet& leafIndexSet() const
00289 {
00290 return leafIndexSet_;
00291 }
00292
00295
00306 bool mark(int refCount, const typename Traits::template Codim<0>::EntityPointer & e );
00307
00315 bool mark(const typename Traits::template Codim<0>::EntityPointer & e,
00316 typename UG_NS<dim>::RefinementRule rule,
00317 int side=0);
00318
00320 int getMark(const typename Traits::template Codim<0>::EntityPointer& e) const;
00321
00324 bool preAdapt();
00325
00327 bool adapt();
00328
00330 void postAdapt();
00334 std::string name () const { return "UGGrid"; };
00335
00337 unsigned int overlapSize(int codim) const {
00338 return 0;
00339 }
00340
00342 unsigned int ghostSize(int codim) const {
00343 return (codim==0) ? 1 : 0;
00344 }
00345
00347 unsigned int overlapSize(int level, int codim) const {
00348 return 0;
00349 }
00350
00352 unsigned int ghostSize(int level, int codim) const {
00353 return (codim==0) ? 1 : 0;
00354 }
00355
00361 void loadBalance(int strategy, int minlevel, int depth, int maxlevel, int minelement);
00362
00363 typedef GridDefaultImplementation <dim, dim, double,
00364 UGGridFamily<dim,dim> > GridDefaultImplementationType;
00365
00367 using GridDefaultImplementationType :: loadBalance;
00368
00380 template<class T, template<class> class P, int codim>
00381 void communicate (T& t, InterfaceType iftype, CommunicationDirection dir, int level);
00382
00387 template<class DataHandle>
00388 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
00389 {}
00390
00391 template<class DataHandle>
00392 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
00393 {}
00394
00396 const CollectiveCommunication<UGGrid>& comm () const
00397 {
00398 return ccobj;
00399 }
00400
00401
00402
00403
00404
00407
00411 void createBegin();
00412
00414 void createEnd();
00415
00421 void insertBoundarySegment(const std::vector<unsigned int> vertices,
00422 const BoundarySegment<dim>* boundarySegment);
00423
00425 void insertVertex(const FieldVector<double,dim>& pos);
00426
00431 void insertElement(GeometryType type,
00432 const std::vector<unsigned int>& vertices);
00433
00444 void adaptWithoutClosure();
00445
00451 void getChildrenOfSubface(typename Traits::template Codim<0>::EntityPointer & e,
00452 int elementSide,
00453 int maxl,
00454 std::vector<typename Traits::template Codim<0>::EntityPointer>& childElements,
00455 std::vector<unsigned char>& childElementSides) const;
00456
00458 enum RefinementType {
00460 LOCAL,
00462 COPY};
00463
00465 void setRefinementType(RefinementType type) {
00466 refinementType_ = type;
00467 }
00468
00470 void collapse() {
00471 if (Collapse(multigrid_))
00472 DUNE_THROW(GridError, "UG" << dim << "d::Collapse() returned error code!");
00473
00474 setIndices();
00475 }
00476
00480 void setPosition(typename Traits::template Codim<dim>::EntityPointer& e,
00481 const FieldVector<double, dim>& pos);
00482
00487 void globalRefine(int n);
00488
00489 private:
00491 typename UG_NS<dim>::MultiGrid* multigrid_;
00492
00494 std::vector<const BoundarySegment<dim>*> boundarySegments_;
00495
00497 std::vector<FixedArray<unsigned int, dim*2-2> > boundarySegmentVertices_;
00498
00499 CollectiveCommunication<UGGrid> ccobj;
00500
00501
00502 void init(unsigned int heapSize, unsigned int envHeapSize);
00503
00508 void insertLinearSegment(const std::vector<int>& vertices,
00509 const std::vector<FieldVector<double,dim> >& coordinates,
00510 unsigned int segmentIndex);
00511
00512
00513 void setIndices();
00514
00515
00516
00517 std::string name_;
00518
00519
00520 std::vector<UGGridLevelIndexSet<const UGGrid<dim> >*> levelIndexSets_;
00521
00522 UGGridLeafIndexSet<const UGGrid<dim> > leafIndexSet_;
00523
00524 UGGridGlobalIdSet<const UGGrid<dim> > globalIdSet_;
00525
00526 UGGridLocalIdSet<const UGGrid<dim> > localIdSet_;
00527
00531 static bool useExistingDefaultsFile;
00532
00534 RefinementType refinementType_;
00535
00537 bool omitGreenClosure_;
00538
00541 std::vector<unsigned char> elementTypes_;
00542
00545 std::vector<unsigned int> elementVertices_;
00546
00548 std::vector<FieldVector<double, dim> > vertexPositions_;
00549
00557 static int numOfUGGrids;
00558
00564 bool someElementHasBeenMarkedForRefinement_;
00565
00570 unsigned int heapsize;
00571
00572
00573 };
00574
00575 namespace Capabilities
00576 {
00592 template<int dim>
00593 struct hasEntity< UGGrid<dim>, 0>
00594 {
00595 static const bool v = true;
00596 };
00597
00601 template<int dim>
00602 struct hasEntity< UGGrid<dim>, dim>
00603 {
00604 static const bool v = true;
00605 };
00606
00610 template<int dim>
00611 struct isParallel< UGGrid<dim> >
00612 {
00613 static const bool v = true;
00614 };
00615
00619 template<int dim>
00620 struct isLevelwiseConforming< UGGrid<dim> >
00621 {
00622 static const bool v = true;
00623 };
00624
00628 template<int dim>
00629 struct isLeafwiseConforming< UGGrid<dim> >
00630 {
00631 static const bool v = true;
00632 };
00633
00637 template<int dim>
00638 struct hasHangingNodes< UGGrid<dim> >
00639 {
00640 static const bool v = false;
00641 };
00642
00643 }
00644
00645 }
00646
00647 #endif