dune-alugrid  2.6-git
grid_inline.hh
Go to the documentation of this file.
1 #ifndef ALUGRID_GRID_INLINE_HH
2 #define ALUGRID_GRID_INLINE_HH
3 
4 // Dune includes
5 #include <dune/common/stdstreams.hh>
6 
7 // Local includes
8 #include "alu3dinclude.hh"
9 #include "entity.hh"
10 #include "iterator.hh"
11 #include "datahandle.hh"
12 #include "grid.hh"
13 
14 namespace Dune
15 {
16 
17  // Implementation of ALU3dGrid
18  // ---------------------------
19 
20  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
22  ::ALU3dGrid ( const std::string &macroTriangFilename,
23  const MPICommunicatorType mpiComm,
24  const DuneBoundaryProjectionType *bndPrj,
25  const DuneBoundaryProjectionVector *bndVec,
26  const ALUGridRefinementType refinementType )
27  : mygrid_()
28  , maxlevel_( 0 )
29  , coarsenMarked_( 0 )
30  , refineMarked_( 0 )
31  , geomTypes_() //dim+1, std::vector<GeometryType>(1) )
32  , hIndexSet_ (*this)
33  , globalIdSet_()
34  , localIdSet_( *this )
35  , levelIndexVec_( 1, nullptr ) , leafIndexSet_()
36  , sizeCache_ ()
37  , lockPostAdapt_( false )
38  , bndPrj_ ( bndPrj )
39  , bndVec_ ( (bndVec) ? (new DuneBoundaryProjectionVector( *bndVec )) : nullptr )
40  , vertexProjection_( (bndPrj || bndVec) ? new ALUGridBoundaryProjectionType( *this ) : nullptr )
41  , communications_( new Communications( mpiComm ) )
42  , refinementType_( refinementType )
43  {
44  // generate geometry storage and geometry type vector
45  makeGeometries();
46 
47  // check macro grid file for keyword
48  checkMacroGridFile( macroTriangFilename );
49 
50  mygrid_.reset( createALUGrid( macroTriangFilename ) );
51  alugrid_assert ( mygrid_ );
52 
53  dverb << "************************************************" << std::endl;
54  dverb << "Created grid on p=" << comm().rank() << std::endl;
55  dverb << "************************************************" << std::endl;
56  checkMacroGrid ();
57 
58  clearIsNewMarkers();
59  calcExtras();
60  } // end constructor
61 
62 
63  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
64  void
66  {
67  // instantiate the static memory pool by creating an object
72 
73  alugrid_assert ( elType == tetra || elType == hexa );
74 
75  geomTypes_.clear();
76  geomTypes_.resize( dimension+1 );
77 
78  geomTypes_[ 0 ].push_back( ALU3dGridGeometry< dim, dimworld, const ThisType >().type() );
79  geomTypes_[ 1 ].push_back( ALU3dGridGeometry< dim-1, dimworld, const ThisType >().type() );
80  geomTypes_[ 2 ].push_back( ALU3dGridGeometry< dim-2, dimworld, const ThisType >().type() );
81 
82  if( dimension == 3 )
83  {
84  geomTypes_[ 3 ].push_back( ALU3dGridGeometry< 0, dimworld, const ThisType >().type() );
85  }
86  }
87 
88  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
90  {
91  // return actual size of hierarchical index set
92  // this is always up to date
93  // maxIndex is the largest index used + 1
94  return myGrid().indexManager(codim).getMaxIndex();
95  }
96 
97 
98  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
100  {
101  // return actual size of hierarchical index set
102  return myGrid().indexManager(codim).getMaxIndex();
103  }
104 
105 
106  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
108  {
109  return maxlevel_;
110  }
111 
112 
113  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
116  {
117  alugrid_assert ( mygrid_ );
118  return *mygrid_;
119  }
120 
121 
122  // lbegin methods
123  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
124  template< int cd, PartitionIteratorType pitype >
125  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator
127  {
128  alugrid_assert ( level >= 0 );
129  // if we dont have this level return empty iterator
130  if( level > maxlevel_ )
131  return this->template lend<cd,pitype> (level);
132 
133  return ALU3dGridLevelIterator< cd, pitype, const ThisType >( *this, level, true );
134  }
135 
136 
137  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
138  template< int cd, PartitionIteratorType pitype >
139  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator
141  {
142  alugrid_assert ( level >= 0 );
144  }
145 
146 
147  // lbegin methods
148  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
149  template< int cd >
150  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< All_Partition >::LevelIterator
152  {
153  return this->template lbegin<cd,All_Partition>( level );
154  }
155 
156 
157  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
158  template< int cd >
159  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< All_Partition >::LevelIterator
161  {
162  alugrid_assert ( level >= 0 );
163  return this->template lend<cd,All_Partition>( level );
164  }
165 
166 
167  //***********************************************************
168  //
169  // leaf methods , first all begin methods
170  //
171  //***********************************************************
172  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
173  template< int cd, PartitionIteratorType pitype >
174  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
176  {
177  alugrid_assert ( level >= 0 );
178  return ALU3dGridLeafIterator< cd, pitype, const ThisType >( *this, level, true );
179  }
180 
181 
182  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
183  template< int cd, PartitionIteratorType pitype >
184  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
185  ALU3dGrid< dim, dimworld, elType, Comm >::leafbegin ( int level ) const
186  {
187  return createLeafIteratorBegin<cd, pitype> (level) ;
188  }
189 
190 
191  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
192  template< int cd >
193  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::LeafIterator
194  ALU3dGrid< dim, dimworld, elType, Comm >::leafbegin ( int level ) const
195  {
196  return createLeafIteratorBegin<cd, All_Partition> (level) ;
197  }
198 
199 
200  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
201  template< int cd, PartitionIteratorType pitype >
202  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
203  ALU3dGrid< dim, dimworld, elType, Comm >::leafbegin () const
204  {
205  return createLeafIteratorBegin< cd, pitype > (maxlevel_) ;
206  }
207 
208 
209  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
210  template< int cd >
211  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::LeafIterator
212  ALU3dGrid< dim, dimworld, elType, Comm >::leafbegin () const
213  {
214  return createLeafIteratorBegin< cd, All_Partition> (maxlevel_) ;
215  }
216 
217 
218  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
220  ALU3dGrid< dim, dimworld, elType, Comm >::leafbegin ( int level ) const
221  {
222  return createLeafIteratorBegin<0, All_Partition> (level) ;
223  }
224 
225 
226  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
228  ALU3dGrid< dim, dimworld, elType, Comm >::leafbegin () const
229  {
230  return createLeafIteratorBegin<0, All_Partition> (maxlevel_) ;
231  }
232 
233 
234  //****************************************************************
235  //
236  // all leaf end methods
237  //
238  //****************************************************************
239  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
240  template< int cd, PartitionIteratorType pitype >
241  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
242  ALU3dGrid< dim, dimworld, elType, Comm >::createLeafIteratorEnd ( int level ) const
243  {
244  alugrid_assert ( level >= 0 );
245  return ALU3dGridLeafIterator<cd, pitype, const MyType> ( *this, level);
246  }
247 
248 
249  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
250  template< int cd, PartitionIteratorType pitype >
251  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
252  ALU3dGrid< dim, dimworld, elType, Comm >::leafend ( int level ) const
253  {
254  return createLeafIteratorEnd < cd, pitype> (level);
255  }
256 
257 
258  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
259  template< int cd >
260  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::LeafIterator
261  ALU3dGrid< dim, dimworld, elType, Comm >::leafend ( int level ) const
262  {
263  return createLeafIteratorEnd < cd, All_Partition> (level);
264  }
265 
266 
267  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
268  template< int cd, PartitionIteratorType pitype >
269  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
270  ALU3dGrid< dim, dimworld, elType, Comm >::leafend () const
271  {
272  return createLeafIteratorEnd < cd, pitype> (maxlevel_);
273  }
274 
275 
276  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
277  template< int cd >
278  inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::LeafIterator
279  ALU3dGrid< dim, dimworld, elType, Comm >::leafend () const
280  {
281  return createLeafIteratorEnd < cd, All_Partition> (maxlevel_);
282  }
283 
284 
285  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
287  ALU3dGrid< dim, dimworld, elType, Comm >::leafend ( int level ) const
288  {
289  return createLeafIteratorEnd <0, All_Partition> (level);
290  }
291 
292 
293  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
295  ALU3dGrid< dim, dimworld, elType, Comm >::leafend () const
296  {
297  return createLeafIteratorEnd <0,All_Partition> (maxlevel_);
298  }
299 
300 
301  //*****************************************************************
302 
303  // mark given entity
304  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
306  ::mark ( int ref, const typename Traits::template Codim< 0 >::Entity &entity )
307  {
308  bool marked = (this->getRealImplementation( entity )).mark( ref, conformingRefinement() );
309  if(marked)
310  {
311  if(ref > 0) ++refineMarked_;
312  if(ref < 0) ++coarsenMarked_;
313  }
314  return marked;
315  }
316 
317 
318  // get Mark of given entity
319  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
321  ::getMark ( const typename Traits::template Codim< 0 >::Entity &entity ) const
322  {
323  return this->getRealImplementation( entity ).getMark();
324  }
325 
326 
327  // global refine
328  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
329  template< class GridImp, class DataHandle >
330  inline
332  ::globalRefine ( int refCount, AdaptDataHandleInterface< GridImp, DataHandle > &handle )
333  {
334  for( int count = refCount; count > 0; --count )
335  {
336  const LeafIteratorType end = leafend();
337  for( LeafIteratorType it = leafbegin(); it != end; ++it )
338  mark( 1 , *it );
339  adapt( handle );
340  }
341  }
342 
343 
344  // adapt grid
345  // --adapt
346  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
347  template< class GridImp, class DataHandle >
348  inline
350  ::adapt ( AdaptDataHandleInterface< GridImp, DataHandle > &handle )
351  {
352  typedef AdaptDataHandleInterface< GridImp, DataHandle > AdaptDataHandle;
353 
354  // true if at least one element was marked for coarsening
355  bool mightCoarse = preAdapt();
356 
357  bool refined = false ;
358  if(globalIdSet_)
359  {
360  // if global id set exists then include into
361  // prolongation process
362  ALU3DSPACE AdaptRestrictProlongGlSet< MyType, AdaptDataHandle, GlobalIdSetImp >
363  rp(*this,
364  handle,
365  *globalIdSet_);
366 
367  refined = myGrid().duneAdapt(rp); // adapt grid
368  }
369  else
370  {
371  ALU3DSPACE AdaptRestrictProlongImpl< MyType, AdaptDataHandle >
372  rp(*this,
373  handle);
374 
375  refined = myGrid().duneAdapt(rp); // adapt grid
376  }
377 
378  if(refined || mightCoarse)
379  {
380  // only calc extras and skip maxLevel calculation, because of
381  // refinement maxLevel was calculated already
382  updateStatus();
383 
384  // no need to call postAdapt here, because markers
385  // are cleand during refinement callback
386  }
387 
388  return refined;
389  }
390 
391 
392 
393  // load balance grid ( lbData might be a pointer to NULL )
394  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
396  {
397  if( comm().size() <= 1 )
398  return false;
399 
400  // call load Balance
401  const bool changed = myGrid().loadBalance( lbData );
402 
403  if( changed )
404  {
405  // reset boundary segment index
406  macroBoundarySegmentIndexSet_.invalidate();
407 
408  // reset size and things
409  // maxLevel does not need to be recalculated
410  calcExtras();
411 
412 
413  // build new Id Set. Only do that after calcExtras, because here
414  // the item lists are needed
415  if( globalIdSet_ )
416  globalIdSet_->updateIdSet();
417 
418  // compress data if lbData is valid and has user data
419  if( lbData && lbData->hasUserData() )
420  lbData->compress() ;
421  else // this only needs to be done if no user is present
422  clearIsNewMarkers();
423  }
424  return changed;
425  }
426 
427  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
429  {
430  // distribute the grid
431  loadBalance();
432 
433  // free memory by reinitializing the grid
434  mygrid_.reset( GitterImplType :: compress( mygrid_.release() ) );
435 
436  // update all internal structures
437  updateStatus();
438 
439  // call post adapt
440  clearIsNewMarkers();
441  }
442 
443 
444  // return Grid name
445  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
447  {
448  if( elType == hexa )
449  return "ALUCubeGrid";
450  else
451  return "ALUSimplexGrid";
452  }
453 
454 } // end namespace Dune
455 #endif
#define ALU3DSPACE
Definition: alu3dinclude.hh:24
#define alugrid_assert(EX)
Definition: alugrid_assert.hh:20
Definition: alu3dinclude.hh:80
@ hexa
Definition: topology.hh:12
@ tetra
Definition: topology.hh:12
bool checkMacroGrid(ALU3dGridElementType elType, const std::string filename)
ALUGridRefinementType
available refinement types for ALUGrid
Definition: declaration.hh:24
[ provides Dune::Grid ]
Definition: alugrid/3d/grid.hh:463
void globalRefine(int refCount)
uses the interface, mark on entity and refineLocal
Definition: grid_imp.cc:405
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e)
Definition: grid_inline.hh:306
bool loadBalance()
Calculates load of each process and repartition by using ALUGrid's default partitioning method....
Definition: alugrid/3d/grid.hh:935
int maxLevel() const
Return maximum level defined in this grid. Levels are numbered maxLevel with 0 the coarsest level.
Definition: grid_inline.hh:107
Traits::DuneBoundaryProjectionType DuneBoundaryProjectionType
boundary projection type
Definition: alugrid/3d/grid.hh:580
int hierSetSize(int cd) const
Definition: grid_inline.hh:99
GitterImplType & myGrid() const
Definition: grid_inline.hh:115
void finalizeGridCreation()
Definition: grid_inline.hh:428
bool adapt()
Definition: grid_imp.cc:430
static std::string name()
for grid identification
Definition: grid_inline.hh:446
ALU3dGrid(const std::string &macroTriangFilename, const MPICommunicatorType mpiComm, const DuneBoundaryProjectionType *bndPrj, const DuneBoundaryProjectionVector *bndVec, const ALUGridRefinementType refinementType)
Definition: grid_inline.hh:22
void makeGeometries()
Definition: grid_inline.hh:65
Traits::template Codim< cd >::template Partition< pitype >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: grid_inline.hh:126
Comm MPICommunicatorType
Definition: alugrid/3d/grid.hh:632
ALU3DSPACE GatherScatter GatherScatterType
Definition: alugrid/3d/grid.hh:898
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Definition: grid_inline.hh:321
ALU3dImplTraits< elType, Comm >::GitterImplType GitterImplType
Definition: alugrid/3d/grid.hh:617
Traits::template Codim< cd >::template Partition< pitype >::LevelIterator lend(int level) const
one past the end on this level
Definition: grid_inline.hh:140
Traits::DuneBoundaryProjectionVector DuneBoundaryProjectionVector
boundary projection type
Definition: alugrid/3d/grid.hh:582
int global_size(int cd) const
number of grid entities on all levels for given codim
Definition: grid_inline.hh:89
Traits::template Codim< 0 >::LeafIterator LeafIteratorType
Definition: alugrid/3d/grid.hh:612
Definition: iterator.hh:554
Definition: geometry.hh:632
Leaf iterator.
Definition: iterator.hh:639
Definition: alugrid/3d/grid.hh:135
Definition: alugrid/3d/grid.hh:530
ALUGrid boundary projection implementation DuneBndProjection has to fulfil the DuneBoundaryProjection...
Definition: bndprojection.hh:11