dune-alugrid 3.0.0
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
14namespace Dune
15{
16
17 // Implementation of ALU3dGrid
18 // ---------------------------
19
20 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
21 inline ALU3dGrid< dim, dimworld, elType, 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
46
47 // check macro grid file for keyword
48 checkMacroGridFile( macroTriangFilename );
49
50 mygrid_.reset( createALUGrid( macroTriangFilename ) );
52
53 dverb << "************************************************" << std::endl;
54 dverb << "Created grid on p=" << comm().rank() << std::endl;
55 dverb << "************************************************" << std::endl;
57
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 GeometryType tmpType;
78 for( int codim = 0; codim <= dimension; ++codim )
79 {
80 if (elType == tetra)
81 tmpType.makeSimplex( dimension - codim );
82 else
83 tmpType.makeCube( dimension - codim );
84
85 geomTypes_[ codim ].push_back( tmpType );
86 }
87 }
88
89 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
91 {
92 // return actual size of hierarchical index set
93 // this is always up to date
94 // maxIndex is the largest index used + 1
95 return myGrid().indexManager(codim).getMaxIndex();
96 }
97
98
99 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
101 {
102 // return actual size of hierarchical index set
103 return myGrid().indexManager(codim).getMaxIndex();
104 }
105
106
107 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
109 {
110 return maxlevel_;
111 }
112
113
114 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
117 {
118 alugrid_assert ( mygrid_ );
119 return *mygrid_;
120 }
121
122
123 // lbegin methods
124 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
125 template< int cd, PartitionIteratorType pitype >
126 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator
128 {
129 alugrid_assert ( level >= 0 );
130 // if we dont have this level return empty iterator
131 if( level > maxlevel_ )
132 return this->template lend<cd,pitype> (level);
133
134 return ALU3dGridLevelIterator< cd, pitype, const ThisType >( *this, level, true );
135 }
136
137
138 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
139 template< int cd, PartitionIteratorType pitype >
140 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator
142 {
143 alugrid_assert ( level >= 0 );
145 }
146
147
148 // lbegin methods
149 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
150 template< int cd >
151 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< All_Partition >::LevelIterator
153 {
154 return this->template lbegin<cd,All_Partition>( level );
155 }
156
157
158 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
159 template< int cd >
160 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< All_Partition >::LevelIterator
162 {
163 alugrid_assert ( level >= 0 );
164 return this->template lend<cd,All_Partition>( level );
165 }
166
167
168 //***********************************************************
169 //
170 // leaf methods , first all begin methods
171 //
172 //***********************************************************
173 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
174 template< int cd, PartitionIteratorType pitype >
175 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
177 {
178 alugrid_assert ( level >= 0 );
179 return ALU3dGridLeafIterator< cd, pitype, const ThisType >( *this, level, true );
180 }
181
182
183 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
184 template< int cd, PartitionIteratorType pitype >
185 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
186 ALU3dGrid< dim, dimworld, elType, Comm >::leafbegin ( int level ) const
187 {
188 return createLeafIteratorBegin<cd, pitype> (level) ;
189 }
190
191
192 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
193 template< int cd >
194 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::LeafIterator
195 ALU3dGrid< dim, dimworld, elType, Comm >::leafbegin ( int level ) const
196 {
197 return createLeafIteratorBegin<cd, All_Partition> (level) ;
198 }
199
200
201 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
202 template< int cd, PartitionIteratorType pitype >
203 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
205 {
206 return createLeafIteratorBegin< cd, pitype > (maxlevel_) ;
207 }
208
209
210 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
211 template< int cd >
212 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::LeafIterator
214 {
215 return createLeafIteratorBegin< cd, All_Partition> (maxlevel_) ;
216 }
217
218
219 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
222 {
223 return createLeafIteratorBegin<0, All_Partition> (level) ;
224 }
225
226
227 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
229 ALU3dGrid< dim, dimworld, elType, Comm >::leafbegin () const
230 {
231 return createLeafIteratorBegin<0, All_Partition> (maxlevel_) ;
232 }
233
234
235 //****************************************************************
236 //
237 // all leaf end methods
238 //
239 //****************************************************************
240 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
241 template< int cd, PartitionIteratorType pitype >
242 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
243 ALU3dGrid< dim, dimworld, elType, Comm >::createLeafIteratorEnd ( int level ) const
244 {
245 alugrid_assert ( level >= 0 );
246 return ALU3dGridLeafIterator<cd, pitype, const MyType> ( *this, level);
247 }
248
249
250 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
251 template< int cd, PartitionIteratorType pitype >
252 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
253 ALU3dGrid< dim, dimworld, elType, Comm >::leafend ( int level ) const
254 {
255 return createLeafIteratorEnd < cd, pitype> (level);
256 }
257
258
259 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
260 template< int cd >
261 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::LeafIterator
262 ALU3dGrid< dim, dimworld, elType, Comm >::leafend ( int level ) const
263 {
264 return createLeafIteratorEnd < cd, All_Partition> (level);
265 }
266
267
268 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
269 template< int cd, PartitionIteratorType pitype >
270 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
272 {
273 return createLeafIteratorEnd < cd, pitype> (maxlevel_);
274 }
275
276
277 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
278 template< int cd >
279 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::LeafIterator
281 {
282 return createLeafIteratorEnd < cd, All_Partition> (maxlevel_);
283 }
284
285
286 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
289 {
290 return createLeafIteratorEnd <0, All_Partition> (level);
291 }
292
293
294 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
296 ALU3dGrid< dim, dimworld, elType, Comm >::leafend () const
297 {
298 return createLeafIteratorEnd <0,All_Partition> (maxlevel_);
299 }
300
301
302 //*****************************************************************
303
304 // mark given entity
305 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
306 inline bool ALU3dGrid< dim, dimworld, elType, Comm >
307 ::mark ( int ref, const typename Traits::template Codim< 0 >::Entity &entity )
308 {
309 bool marked = (this->getRealImplementation( entity )).mark( ref, conformingRefinement() );
310 if(marked)
311 {
312 if(ref > 0) ++refineMarked_;
313 if(ref < 0) ++coarsenMarked_;
314 }
315 return marked;
316 }
317
318
319 // get Mark of given entity
320 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
322 ::getMark ( const typename Traits::template Codim< 0 >::Entity &entity ) const
323 {
324 return this->getRealImplementation( entity ).getMark();
325 }
326
327
328 // global refine
329 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
330 template< class GridImp, class DataHandle >
331 inline
333 ::globalRefine ( int refCount, AdaptDataHandleInterface< GridImp, DataHandle > &handle )
334 {
335 for( int count = refCount; count > 0; --count )
336 {
337 const LeafIteratorType end = leafend();
338 for( LeafIteratorType it = leafbegin(); it != end; ++it )
339 mark( 1 , *it );
340 adapt( handle );
341 }
342 }
343
344
345 // adapt grid
346 // --adapt
347 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
348 template< class GridImp, class DataHandle >
349 inline
351 ::adapt ( AdaptDataHandleInterface< GridImp, DataHandle > &handle )
352 {
353 typedef AdaptDataHandleInterface< GridImp, DataHandle > AdaptDataHandle;
354
355 // true if at least one element was marked for coarsening
356 bool mightCoarse = preAdapt();
357
358 bool refined = false ;
359 if(globalIdSet_)
360 {
361 // if global id set exists then include into
362 // prolongation process
363 ALU3DSPACE AdaptRestrictProlongGlSet< MyType, AdaptDataHandle, GlobalIdSetImp >
364 rp(*this,
365 handle,
366 *globalIdSet_);
367
368 refined = myGrid().duneAdapt(rp); // adapt grid
369 }
370 else
371 {
372 ALU3DSPACE AdaptRestrictProlongImpl< MyType, AdaptDataHandle >
373 rp(*this,
374 handle);
375
376 refined = myGrid().duneAdapt(rp); // adapt grid
377 }
378
379 if(refined || mightCoarse)
380 {
381 // only calc extras and skip maxLevel calculation, because of
382 // refinement maxLevel was calculated already
383 updateStatus();
384
385 // no need to call postAdapt here, because markers
386 // are cleand during refinement callback
387 }
388
389 return refined;
390 }
391
392
393
394 // load balance grid ( lbData might be a pointer to NULL )
395 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
397 {
398 if( comm().size() <= 1 )
399 return false;
400
401 // call load Balance
402 const bool changed = myGrid().loadBalance( lbData );
403
404 if( changed )
405 {
406 // reset size and things
407 // maxLevel does not need to be recalculated
408 calcExtras();
409
410 // build new Id Set. Only do that after calcExtras, because here
411 // the item lists are needed
412 if( globalIdSet_ )
413 globalIdSet_->updateIdSet();
414
415 // compress data if lbData is valid and has user data
416 if( lbData && lbData->hasUserData() )
417 lbData->compress() ;
418 else // this only needs to be done if no user is present
419 clearIsNewMarkers();
420 }
421 return changed;
422 }
423
424 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
426 {
427 // distribute the grid
428 loadBalance();
429
430 // free memory by reinitializing the grid
431 mygrid_.reset( GitterImplType :: compress( mygrid_.release() ) );
432
433 // update all internal structures
434 updateStatus();
435
436 // call post adapt
437 clearIsNewMarkers();
438 }
439
440
441 // return Grid name
442 template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
444 {
445 if( elType == hexa )
446 return "ALUCubeGrid";
447 else
448 return "ALUSimplexGrid";
449 }
450
451} // end namespace Dune
452#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
ALUGridRefinementType
available refinement types for ALUGrid
Definition declaration.hh:24
[ provides Dune::Grid ]
Definition 3d/grid.hh:468
void calcExtras()
reset size and global size, update Level- and LeafIndexSet, if they exist
Definition grid_imp.cc:344
bool loadBalance()
Calculates load of each process and repartition by using ALUGrid's default partitioning method....
Definition 3d/grid.hh:928
const CollectiveCommunication & comm() const
Definition 3d/grid.hh:1066
int maxLevel() const
Return maximum level defined in this grid. Levels are numbered maxLevel with 0 the coarsest level.
Definition grid_inline.hh:108
Traits::DuneBoundaryProjectionType DuneBoundaryProjectionType
boundary projection type
Definition 3d/grid.hh:575
ALU3dGridCommunications< dim, dimworld, elType, Comm > Communications
Definition 3d/grid.hh:629
int hierSetSize(int cd) const
Definition grid_inline.hh:100
GitterImplType & myGrid() const
Definition grid_inline.hh:116
void finalizeGridCreation()
Definition grid_inline.hh:425
void checkMacroGridFile(const std::string filename)
check whether macro grid format is of our type
Definition grid_imp.cc:605
virtual GitterImplType * createALUGrid(const std::string &macroName)
Definition 3d/grid.hh:1141
static std::string name()
for grid identification
Definition grid_inline.hh:443
Traits::template Codim< 0 >::LeafIterator LeafIteratorType
Definition 3d/grid.hh:607
void clearIsNewMarkers()
clear all entity new markers
Definition grid_imp.cc:491
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:127
std::unique_ptr< GitterImplType > mygrid_
Definition 3d/grid.hh:1314
Comm MPICommunicatorType
Definition 3d/grid.hh:627
ALU3DSPACE GatherScatter GatherScatterType
Definition 3d/grid.hh:891
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Definition grid_inline.hh:322
Traits::template Codim< cd >::template Partition< pitype >::LevelIterator lend(int level) const
one past the end on this level
Definition grid_inline.hh:141
ALU3dImplTraits< elType, Comm >::GitterImplType GitterImplType
Definition 3d/grid.hh:612
Traits::DuneBoundaryProjectionVector DuneBoundaryProjectionVector
boundary projection type
Definition 3d/grid.hh:577
int global_size(int cd) const
number of grid entities on all levels for given codim
Definition grid_inline.hh:90
void checkMacroGrid()
check whether macro grid has the right element type
Definition grid_imp.cc:644
Definition iterator.hh:550
Definition geometry.hh:632
Leaf iterator.
Definition iterator.hh:635
Definition 3d/grid.hh:535
ALUGrid boundary projection implementation DuneBndProjection has to fulfil the DuneBoundaryProjection...
Definition bndprojection.hh:11