Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Dune includes
#include <dune/common/stdstreams.hh>
// Local includes
#include "alu3dinclude.hh"
#include "entity.hh"
#include "iterator.hh"
#include "datahandle.hh"
#include "grid.hh"
namespace Dune
{
// Implementation of ALU3dGrid
// ---------------------------
template< ALU3dGridElementType elType, class Comm >
inline ALU3dGrid< elType, Comm >
::ALU3dGrid ( const std::string ¯oTriangFilename,
const MPICommunicatorType mpiComm,
const DuneBoundaryProjectionType *bndPrj,
const DuneBoundaryProjectionVector *bndVec,
const ALUGridRefinementType refinementType )
: mygrid_( 0 )
, maxlevel_( 0 )
, coarsenMarked_( 0 )
, refineMarked_( 0 )
, geomTypes_() //dim+1, std::vector<GeometryType>(1) )
, hIndexSet_ (*this)
, globalIdSet_( 0 )
, localIdSet_( *this )
, levelIndexVec_(MAXL,0) , leafIndexSet_(0)
, referenceElement_( elType == tetra
? ReferenceElements< alu3d_ctype, dimension > :: simplex()
: ReferenceElements< alu3d_ctype, dimension > :: cube() )
, sizeCache_ ( 0 )
, factory_( *this )
, lockPostAdapt_( false )
, bndPrj_ ( bndPrj )
, bndVec_ ( (bndVec) ? (new DuneBoundaryProjectionVector( *bndVec )) : 0 )
, vertexProjection_( (bndPrj || bndVec) ? new ALUGridBoundaryProjectionType( *this ) : 0 )
, communications_( new Communications( mpiComm ) )
, refinementType_( refinementType )
, nonConformingGeoInFatherStorage_( makeGeometries() )
{
// check macro grid file for keyword
checkMacroGridFile( macroTriangFilename );
mygrid_ = createALUGrid( macroTriangFilename );
dverb << "************************************************" << std::endl;
dverb << "Created grid on p=" << comm().rank() << std::endl;
dverb << "************************************************" << std::endl;
checkMacroGrid ();
} // end constructor
template< ALU3dGridElementType elType, class Comm >
const typename ALU3dGrid< elType, Comm >::GeometryInFatherStorage&
ALU3dGrid< elType, Comm >::makeGeometries()
{
alugrid_assert ( elType == tetra || elType == hexa );
geomTypes_.clear();
geomTypes_.resize( dimension+1 );
GeometryType tmpType;
for( int codim = 0; codim <= dimension; ++codim )
{
if (elType == tetra)
tmpType.makeSimplex( dimension - codim );
else
tmpType.makeCube( dimension - codim );
geomTypes_[ codim ].push_back( tmpType );
}
// initialize static storage variables
ALU3dGridGeometry< 0, 3, const ThisType> :: geoProvider();
ALU3dGridGeometry< 1, 3, const ThisType> :: geoProvider();
ALU3dGridGeometry< 2, 3, const ThisType> :: geoProvider();
ALU3dGridGeometry< 3, 3, const ThisType> :: geoProvider();
// return non-conforming geometryInFather storage
// true == non-conforming
return GeometryInFatherStorage :: storage( geomTypes_[ 0 ][ 0 ], true );
}
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
template< ALU3dGridElementType elType, class Comm >
inline int ALU3dGrid< elType, Comm >::global_size ( int codim ) const
{
// return actual size of hierarchical index set
// this is always up to date
// maxIndex is the largest index used + 1
return myGrid().indexManager(codim).getMaxIndex();
}
template< ALU3dGridElementType elType, class Comm >
inline int ALU3dGrid< elType, Comm >::hierSetSize ( int codim ) const
{
// return actual size of hierarchical index set
return myGrid().indexManager(codim).getMaxIndex();
}
template< ALU3dGridElementType elType, class Comm >
inline int ALU3dGrid< elType, Comm >::maxLevel () const
{
return maxlevel_;
}
template< ALU3dGridElementType elType, class Comm >
inline typename ALU3dGrid< elType, Comm >::GitterImplType &
ALU3dGrid< elType, Comm >::myGrid () const
{
return *mygrid_;
}
// lbegin methods
template< ALU3dGridElementType elType, class Comm >
template< int cd, PartitionIteratorType pitype >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator
ALU3dGrid< elType, Comm >::lbegin ( int level ) const
{
// if we dont have this level return empty iterator
if( level > maxlevel_ )
return this->template lend<cd,pitype> (level);
return ALU3dGridLevelIterator< cd, pitype, const ThisType >( factory(), level, true );
}
template< ALU3dGridElementType elType, class Comm >
template< int cd, PartitionIteratorType pitype >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator
ALU3dGrid< elType, Comm >::lend ( int level ) const
{
return ALU3dGridLevelIterator< cd, pitype, const ThisType >( factory(), level );
}
// lbegin methods
template< ALU3dGridElementType elType, class Comm >
template< int cd >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< All_Partition >::LevelIterator
ALU3dGrid< elType, Comm >::lbegin ( int level ) const
{
return this->template lbegin<cd,All_Partition>( level );
}
template< ALU3dGridElementType elType, class Comm >
template< int cd >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< All_Partition >::LevelIterator
ALU3dGrid< elType, Comm >::lend ( int level ) const
{
return this->template lend<cd,All_Partition>( level );
}
//***********************************************************
//
// leaf methods , first all begin methods
//
//***********************************************************
template< ALU3dGridElementType elType, class Comm >
template< int cd, PartitionIteratorType pitype >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
ALU3dGrid< elType, Comm >::createLeafIteratorBegin ( int level ) const
{
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
return ALU3dGridLeafIterator< cd, pitype, const ThisType >( factory(), level, true );
}
template< ALU3dGridElementType elType, class Comm >
template< int cd, PartitionIteratorType pitype >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
ALU3dGrid< elType, Comm >::leafbegin ( int level ) const
{
return createLeafIteratorBegin<cd, pitype> (level) ;
}
template< ALU3dGridElementType elType, class Comm >
template< int cd >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
ALU3dGrid< elType, Comm >::leafbegin ( int level ) const
{
return createLeafIteratorBegin<cd, All_Partition> (level) ;
}
template< ALU3dGridElementType elType, class Comm >
template< int cd, PartitionIteratorType pitype >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
ALU3dGrid< elType, Comm >::leafbegin () const
{
return createLeafIteratorBegin< cd, pitype > (maxlevel_) ;
}
template< ALU3dGridElementType elType, class Comm >
template< int cd >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
ALU3dGrid< elType, Comm >::leafbegin () const
{
return createLeafIteratorBegin< cd, All_Partition> (maxlevel_) ;
}
template< ALU3dGridElementType elType, class Comm >
inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
ALU3dGrid< elType, Comm >::leafbegin ( int level ) const
{
return createLeafIteratorBegin<0, All_Partition> (level) ;
}
template< ALU3dGridElementType elType, class Comm >
inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
ALU3dGrid< elType, Comm >::leafbegin () const
{
return createLeafIteratorBegin<0, All_Partition> (maxlevel_) ;
}
//****************************************************************
//
// all leaf end methods
//
//****************************************************************
template< ALU3dGridElementType elType, class Comm >
template< int cd, PartitionIteratorType pitype >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
ALU3dGrid< elType, Comm >::createLeafIteratorEnd ( int level ) const
{
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
return ALU3dGridLeafIterator<cd, pitype, const MyType> ( factory() , level);
}
template< ALU3dGridElementType elType, class Comm >
template< int cd, PartitionIteratorType pitype >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
ALU3dGrid< elType, Comm >::leafend ( int level ) const
{
return createLeafIteratorEnd < cd, pitype> (level);
}
template< ALU3dGridElementType elType, class Comm >
template< int cd >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
ALU3dGrid< elType, Comm >::leafend ( int level ) const
{
return createLeafIteratorEnd < cd, All_Partition> (level);
}
template< ALU3dGridElementType elType, class Comm >
template< int cd, PartitionIteratorType pitype >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
ALU3dGrid< elType, Comm >::leafend () const
{
return createLeafIteratorEnd < cd, pitype> (maxlevel_);
}
template< ALU3dGridElementType elType, class Comm >
template< int cd >
inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
ALU3dGrid< elType, Comm >::leafend () const
{
return createLeafIteratorEnd < cd, All_Partition> (maxlevel_);
}
template< ALU3dGridElementType elType, class Comm >
inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
ALU3dGrid< elType, Comm >::leafend ( int level ) const
{
return createLeafIteratorEnd <0, All_Partition> (level);
}
template< ALU3dGridElementType elType, class Comm >
inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
ALU3dGrid< elType, Comm >::leafend () const
{
return createLeafIteratorEnd <0,All_Partition> (maxlevel_);
}
//*****************************************************************
// mark given entity
template< ALU3dGridElementType elType, class Comm >
inline bool ALU3dGrid< elType, Comm >
::mark ( int ref, const typename Traits::template Codim< 0 >::Entity &entity )
{
bool marked = (this->getRealImplementation( entity )).mark(ref);
if(marked)
{
if(ref > 0) ++refineMarked_;
if(ref < 0) ++coarsenMarked_;
}
return marked;
}
// get Mark of given entity
template< ALU3dGridElementType elType, class Comm >
inline int ALU3dGrid< elType, Comm >
::getMark ( const typename Traits::template Codim< 0 >::Entity &entity ) const
{
return this->getRealImplementation( entity ).getMark();
}
// global refine
template< ALU3dGridElementType elType, class Comm >
template< class GridImp, class DataHandle >
inline
void ALU3dGrid< elType, Comm >
::globalRefine ( int refCount, AdaptDataHandleInterface< GridImp, DataHandle > &handle )
{
alugrid_assert ( (refCount + maxLevel()) < MAXL );
for( int count = refCount; count > 0; --count )
{
const LeafIteratorType end = leafend();
for( LeafIteratorType it = leafbegin(); it != end; ++it )
mark( 1 , *it );
adapt( handle );
}
}
// adapt grid
// --adapt
template< ALU3dGridElementType elType, class Comm >
template< class GridImp, class DataHandle >
inline
bool ALU3dGrid< elType, Comm >
::adapt ( AdaptDataHandleInterface< GridImp, DataHandle > &handle )
{
typedef AdaptDataHandleInterface< GridImp, DataHandle > AdaptDataHandle;
typedef typename EntityObject::ImplementationType EntityImp;
EntityObject father( EntityImp( factory(), this->maxLevel() ) );
EntityObject son ( EntityImp( factory(), this->maxLevel() ) );
// true if at least one element was marked for coarsening
bool mightCoarse = preAdapt();
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
bool refined = false ;
if(globalIdSet_)
{
// if global id set exists then include into
// prolongation process
ALU3DSPACE AdaptRestrictProlongGlSet< MyType, AdaptDataHandle, GlobalIdSetImp >
rp(*this,
father,this->getRealImplementation(father),
son, this->getRealImplementation(son),
handle,
*globalIdSet_);
refined = myGrid().duneAdapt(rp); // adapt grid
}
else
{
ALU3DSPACE AdaptRestrictProlongImpl< MyType, AdaptDataHandle >
rp(*this,
father,this->getRealImplementation(father),
son, this->getRealImplementation(son),
handle);
refined = myGrid().duneAdapt(rp); // adapt grid
}
if(refined || mightCoarse)
{
// only calc extras and skip maxLevel calculation, because of
// refinement maxLevel was calculated already
updateStatus();
// no need to call postAdapt here, because markers
// are cleand during refinement callback
}
return refined;
}
// load balance grid ( lbData might be a pointer to NULL )
template< ALU3dGridElementType elType, class Comm >
inline bool ALU3dGrid< elType, Comm >::loadBalance( GatherScatterType* lbData )
if( comm().size() <= 1 )
return false;
// call load Balance
const bool changed = myGrid().loadBalance( lbData );
// maxLevel does not need to be recalculated
calcExtras();
// build new Id Set. Only do that after updateStatus, because here
// the item lists are needed
if( globalIdSet_ )
globalIdSet_->updateIdSet();
// compress data if lbData is valid and has user data
if( lbData && lbData->hasUserData() )
else // this only needs to be done if no user is present
clearIsNewMarkers();
template< ALU3dGridElementType elType, class Comm >
inline void ALU3dGrid< elType, Comm >::finalizeGridCreation()
{
// distribute the grid
loadBalance();
// free memory by reinitializing the grid
mygrid_ = GitterImplType :: compress( mygrid_ );
// update all internal structures
updateStatus();
// call post adapt
// return Grid name
template< ALU3dGridElementType elType, class Comm >
inline std::string ALU3dGrid< elType, Comm >::name ()
{
if( elType == hexa )
return "ALUCubeGrid";
else
return "ALUSimplexGrid";
}
} // end namespace Dune