4 #ifndef DUNE_ALU3DGRID_FACTORY_HH
5 #define DUNE_ALU3DGRID_FACTORY_HH
12 #include <dune/common/array.hh>
13 #include <dune/common/mpihelper.hh>
15 #include <dune/geometry/referenceelements.hh>
27 template<
class ALUGr
id >
66 "ALU3dGridFactory supports only grids containing "
67 "tetrahedrons or hexahedrons exclusively." );
78 typedef FieldVector< ctype, dimensionworld > VertexType;
79 typedef std::vector< unsigned int > ElementType;
80 typedef array< unsigned int, numFaceCorners > FaceType;
84 typedef std::vector< std::pair< VertexType, size_t > > VertexVector;
85 typedef std::vector< ElementType > ElementVector;
86 typedef std::pair< FaceType, int > BndPair ;
87 typedef std::map< FaceType, int > BoundaryIdMap;
88 typedef std::vector< std::pair< BndPair, BndPair > > PeriodicBoundaryVector;
89 typedef std::pair< unsigned int, int > SubEntity;
90 typedef std::map< FaceType, SubEntity, FaceLess > FaceMap;
92 typedef std::map< FaceType, const DuneBoundaryProjectionType* > BoundaryProjectionMap;
93 typedef std::vector< const DuneBoundaryProjectionType* > BoundaryProjectionVector;
95 typedef std::vector< Transformation > FaceTransformationVector;
98 void copyAndSort (
const std::vector< unsigned int > &vertices, FaceType &faceId )
const
100 std::vector<unsigned int> tmp( vertices );
101 std::sort( tmp.begin(), tmp.end() );
104 for(
size_t i = 0; i < faceId.size(); ++i ) faceId[ i ] = tmp[ i ];
109 virtual Grid* createGridObj( BoundaryProjectionVector* bndProjections,
const std::string& name )
const
111 return ( allowGridGeneration_ ) ?
112 new Grid( communicator_, globalProjection_, bndProjections , name, realGrid_ ) :
113 new
Grid( communicator_ );
119 bool removeGeneratedFile =
true );
150 const std::vector< VertexId > &vertices );
164 const std::vector< VertexId > &faceVertices,
173 virtual void insertBoundary (
const int element,
const int face,
const int id );
191 const std::vector< VertexId > &vertices,
233 Grid *
createGrid (
const bool addMissingBoundaries,
const std::string dgfName =
"" );
235 Grid *
createGrid (
const bool addMissingBoundaries,
bool temporary,
const std::string dgfName =
"" );
240 return Grid::getRealImplementation( entity ).getIndex();
245 return Grid::getRealImplementation( entity ).getIndex();
250 return intersection.boundarySegmentIndex();
255 return intersection.boundary() &&
260 size_t globalId (
const VertexId &
id )
const
262 assert(
id < vertices_.size() );
263 return vertices_[ id ].second;
266 const VertexType &position (
const VertexId &
id )
const
268 assert(
id < vertices_.size() );
269 return vertices_[ id ].first;
272 void assertGeometryType(
const GeometryType &geometry );
273 static void generateFace (
const ElementType &element,
const int f, FaceType &face );
274 void generateFace (
const SubEntity &subEntity, FaceType &face )
const;
275 void correctElementOrientation ();
276 bool identifyFaces (
const Transformation &transformation,
const FaceType &key1,
const FaceType &key2,
const int defaultId );
277 void searchPeriodicNeighbor ( FaceMap &faceMap,
const typename FaceMap::iterator &pos,
const int defaultId );
278 void reinsertBoundary (
const FaceMap &faceMap,
const typename FaceMap::const_iterator &pos,
const int id );
279 void recreateBoundaryIds (
const int defaultId = 1 );
283 VertexVector vertices_;
284 ElementVector elements_;
285 BoundaryIdMap boundaryIds_;
286 PeriodicBoundaryVector periodicBoundaries_;
288 BoundaryProjectionMap boundaryProjections_;
289 FaceTransformationVector faceTransformations_;
290 unsigned int numFacesInserted_;
292 const bool allowGridGeneration_;
299 template<
class ALUGr
id >
301 :
public std::binary_function< FaceType, FaceType, bool >
303 bool operator() (
const FaceType &a,
const FaceType &b )
const
305 for(
unsigned int i = 0; i < numFaceCorners; ++i )
307 if( a[ i ] != b[ i ] )
308 return (a[ i ] < b[ i ]);
315 template<
class ALUGr
id >
319 if( elementType ==
tetra )
321 if( !geometry.isSimplex() )
322 DUNE_THROW(
GridError,
"Only simplex geometries can be inserted into "
323 "ALUSimplexGrid< 3, 3 >." );
327 if( !geometry.isCube() )
328 DUNE_THROW( GridError,
"Only cube geometries can be inserted into "
329 "ALUCubeGrid< 3, 3 >." );
357 :
BaseType( filename, communicator )
361 template<
class,
class,
int >
friend class ALULocalGeometryStorage;
365 :
BaseType( realGrid, communicator )
394 :
BaseType( filename, communicator )
398 template<
class,
class,
int >
friend class ALULocalGeometryStorage;
402 :
BaseType( realGrid, communicator )
410 template<ALUGr
idElementType eltype, ALUGr
idRefinementType refinementtype ,
class Comm >
411 class GridFactory< ALUGrid< 3, 3, eltype, refinementtype, Comm > >
430 :
BaseType( filename, communicator )
434 template<
class,
class,
int >
friend class ALULocalGeometryStorage;
438 :
BaseType( realGrid, communicator )
447 template<
class ALUGr
id >
451 bool removeGeneratedFile )
452 : rank_( ALU3dGridCommunications< elementType,
MPICommunicatorType >::getRank( communicator ) ),
453 globalProjection_ ( 0 ),
454 numFacesInserted_ ( 0 ),
456 allowGridGeneration_( rank_ == 0 ),
457 communicator_( communicator )
460 template<
class ALUGr
id >
465 : rank_( ALU3dGridCommunications< elementType,
MPICommunicatorType >::getRank( communicator ) ),
466 globalProjection_ ( 0 ),
467 numFacesInserted_ ( 0 ),
469 allowGridGeneration_( rank_ == 0 ),
470 communicator_( communicator )
473 template<
class ALUGr
id >
478 : rank_( ALU3dGridCommunications< elementType,
MPICommunicatorType >::getRank( communicator ) ),
479 globalProjection_ ( 0 ),
480 numFacesInserted_ ( 0 ),
481 realGrid_( realGrid ),
482 allowGridGeneration_( true ),
483 communicator_( communicator )
486 template<
class ALUGr
id >
491 copyAndSort( vertices, faceId );
493 if( vertices.size() != numFaceCorners )
494 DUNE_THROW(
GridError,
"Wrong number of face vertices passed: " << vertices.size() <<
"." );
496 if( boundaryProjections_.find( faceId ) != boundaryProjections_.end() )
497 DUNE_THROW(
GridError,
"Only one boundary projection can be attached to a face." );
500 boundaryProjections_[ faceId ] = 0;
503 for(
unsigned int i = 0; i < numFaceCorners; ++i )
505 const unsigned int j = FaceTopologyMappingType::dune2aluVertex( i );
506 boundaryId.first[ j ] = vertices[ i ];
508 boundaryId.second = 1;
509 boundaryIds_.insert( boundaryId );
512 template<
class ALUGr
id >
518 copyAndSort( vertices, faceId );
520 if( vertices.size() != numFaceCorners )
521 DUNE_THROW(
GridError,
"Wrong number of face vertices passed: " << vertices.size() <<
"." );
523 if( boundaryProjections_.find( faceId ) != boundaryProjections_.end() )
524 DUNE_THROW(
GridError,
"Only one boundary projection can be attached to a face." );
526 const size_t numVx = vertices.size();
529 type.makeSimplex( dimension-1 );
531 type.makeCube( dimension-1 );
535 typedef FieldVector< double, dimensionworld > CoordType;
536 std::vector< CoordType > coords( numVx );
537 for(
size_t i = 0; i < numVx; ++i )
540 assert( vertices_.size() > vertices[ i ] );
543 const VertexType &x = position( vertices[ i ] );
544 for(
unsigned int j = 0; j < dimensionworld; ++j )
545 coords[ i ][ j ] = x[ j ];
550 boundaryProjections_[ faceId ] = prj;
553 for(
size_t i = 0; i < numVx; ++i )
555 CoordType global = (*prj)( coords [ i ] );
556 if( (global - coords[ i ]).two_norm() > 1e-6 )
557 DUNE_THROW(
GridError,
"BoundarySegment does not map face vertices to face vertices.");
562 for(
unsigned int i = 0; i < numFaceCorners; ++i )
564 const unsigned int j = FaceTopologyMappingType::dune2aluVertex( i );
565 boundaryId.first[ j ] = vertices[ i ];
567 boundaryId.second = 1;
568 boundaryIds_.insert( boundaryId );
572 template<
class ALUGr
id >
574 ::generateFace (
const SubEntity &subEntity, FaceType &face )
const
576 generateFace( elements_[ subEntity.first ], subEntity.second, face );
581 #endif // #ifdef ENABLE_ALUGRID
583 #if COMPILE_ALUGRID_INLINE