4 #ifndef DUNE_ALBERTA_GRIDFACTORY_HH 5 #define DUNE_ALBERTA_GRIDFACTORY_HH 18 #include <dune/geometry/referenceelements.hh> 46 template<
int dim,
int dimworld >
67 typedef FieldMatrix< ctype, dimensionworld, dimensionworld >
WorldMatrix;
82 static const int numVertices
91 typedef std::array< unsigned int, dimension > FaceId;
92 typedef std::map< FaceId, size_t > BoundaryMap;
94 class ProjectionFactory;
98 static const bool supportsBoundaryIds =
true;
100 static const bool supportPeriodicity = MacroData::supportPeriodicity;
104 : globalProjection_( (const DuneProjection *) 0 )
117 macroData_.insertVertex( pos );
126 const std::vector< unsigned int > &vertices )
129 DUNE_THROW(
AlbertaError,
"Inserting element of wrong dimension: " << type.dim() );
130 if( !type.isSimplex() )
131 DUNE_THROW(
AlbertaError,
"Alberta supports only simplices." );
133 if( vertices.size() != (size_t)numVertices )
134 DUNE_THROW(
AlbertaError,
"Wrong number of vertices passed: " << vertices.size() <<
"." );
136 int array[ numVertices ];
137 for(
int i = 0; i < numVertices; ++i )
138 array[ i ] = vertices[ numberingMap_.alberta2dune( dimension, i ) ];
139 macroData_.insertElement( array );
154 if( (
id <= 0) || (
id > 127) )
155 DUNE_THROW(
AlbertaError,
"Invalid boundary id: " <<
id <<
"." );
156 macroData_.boundaryId( element, numberingMap_.dune2alberta( 1, face ) ) =
id;
171 const std::vector< unsigned int > &vertices,
172 const DuneProjection *projection )
174 if( (
int)type.dim() != dimension-1 )
175 DUNE_THROW(
AlbertaError,
"Inserting boundary face of wrong dimension: " << type.dim() );
176 if( !type.isSimplex() )
177 DUNE_THROW(
AlbertaError,
"Alberta supports only simplices." );
180 if( vertices.size() != faceId.size() )
181 DUNE_THROW(
AlbertaError,
"Wrong number of face vertices passed: " << vertices.size() <<
"." );
182 for(
size_t i = 0; i < faceId.size(); ++i )
183 faceId[ i ] = vertices[ i ];
184 std::sort( faceId.begin(), faceId.end() );
186 typedef std::pair< typename BoundaryMap::iterator, bool > InsertResult;
187 const InsertResult result = boundaryMap_.insert( std::make_pair( faceId, boundaryProjections_.size() ) );
189 DUNE_THROW(
GridError,
"Only one boundary projection can be attached to a face." );
190 boundaryProjections_.push_back( DuneProjectionPtr( projection ) );
204 if( globalProjection_ )
205 DUNE_THROW(
GridError,
"Only one global boundary projection can be attached to a grid." );
206 globalProjection_ = DuneProjectionPtr( projection );
217 typedef typename Impl::SimplexTopology< dimension-1 >::type Topology;
218 insertBoundaryProjection(
GeometryType( Topology() ), vertices, 0 );
228 const std::shared_ptr< BoundarySegment > &boundarySegment )
230 const ReferenceElement< ctype, dimension-1 > &refSimplex
231 = ReferenceElements< ctype, dimension-1 >::simplex();
233 if( !boundarySegment )
234 DUNE_THROW(
GridError,
"Trying to insert null as a boundary segment." );
235 if( (
int)vertices.size() != refSimplex.size( dimension-1 ) )
236 DUNE_THROW(
GridError,
"Wrong number of face vertices passed: " << vertices.size() <<
"." );
238 std::vector< WorldVector > coords( refSimplex.size( dimension-1 ) );
242 for(
int j = 0; j < dimensionworld; ++j )
243 coords[ i ][ j ] = x[ j ];
244 if( ((*boundarySegment)( refSimplex.position( i, dimension-1 ) ) - coords[ i ]).two_norm() > 1e-6 )
245 DUNE_THROW(
GridError,
"Boundary segment does not interpolate the corners." );
249 const DuneProjection *prj =
new BoundarySegmentWrapper( gt, coords, boundarySegment );
250 insertBoundaryProjection( gt, vertices, prj );
266 void insertFaceTransformation (
const WorldMatrix &matrix,
const WorldVector &shift );
278 macroData_.markLongestEdge();
295 macroData_.finalize();
296 if( macroData_.elementCount() == 0 )
297 DUNE_THROW(
GridError,
"Cannot create empty AlbertaGrid." );
300 assert( macroData_.checkNeighbors() );
301 macroData_.checkCycles();
302 ProjectionFactory projectionFactory( *
this );
303 return new Grid( macroData_, projectionFactory );
321 bool write (
const std::string &filename )
323 macroData_.finalize();
326 assert( macroData_.checkNeighbors() );
327 return macroData_.write( filename,
false );
333 return insertionIndex( Grid::getRealImplementation( entity ).elementInfo() );
339 const int elIndex =
insertionIndex( Grid::getRealImplementation( entity ).elementInfo() );
340 const typename MacroData::ElementId &elementId = macroData_.element( elIndex );
341 return elementId[ Grid::getRealImplementation( entity ).subEntity() ];
347 const Grid &grid = Grid::getRealImplementation( intersection ).grid();
348 const ElementInfo &elementInfo = Grid::getRealImplementation( intersection ).elementInfo();
349 const int face = grid.
generic2alberta( 1, intersection.indexInInside() );
360 unsigned int insertionIndex (
const ElementInfo &elementInfo )
const;
361 unsigned int insertionIndex (
const ElementInfo &elementInfo,
const int face )
const;
363 FaceId faceId (
const ElementInfo &elementInfo,
const int face )
const;
365 MacroData macroData_;
366 NumberingMap numberingMap_;
367 DuneProjectionPtr globalProjection_;
368 BoundaryMap boundaryMap_;
369 std::vector< DuneProjectionPtr > boundaryProjections_;
373 template<
int dim,
int dimworld >
376 macroData_.release();
380 template<
int dim,
int dimworld >
386 for(
int i = 0; i < dimworld; ++i )
387 for(
int j = 0; j < dimworld; ++j )
389 const ctype delta = (i == j ?
ctype( 1 ) : ctype( 0 ));
390 const ctype epsilon = (8*dimworld)*std::numeric_limits< ctype >::epsilon();
392 if(
std::abs( matrix[ i ] * matrix[ j ] - delta ) > epsilon )
395 "Matrix of face transformation is not orthogonal." );
401 for(
int i = 0; i < dimworld; ++i )
402 for(
int j = 0; j < dimworld; ++j )
403 M[ i ][ j ] = matrix[ i ][ j ];
407 for(
int i = 0; i < dimworld; ++i )
411 macroData_.insertWallTrafo( M, t );
415 template<
int dim,
int dimworld >
421 const unsigned int index = macroElement.index;
424 const typename MacroData::ElementId &elementId = macroData_.element( index );
429 for(
int j = 0; j < dimensionworld; ++j )
431 if( x[ j ] != y[ j ] )
432 DUNE_THROW(
GridError,
"Vertex in macro element does not coincide with same vertex in macro data structure." );
435 #endif // #ifndef NDEBUG 441 template<
int dim,
int dimworld >
446 typedef typename BoundaryMap::const_iterator Iterator;
447 const Iterator it = boundaryMap_.find( faceId( elementInfo, face ) );
448 if( it != boundaryMap_.end() )
455 template<
int dim,
int dimworld >
458 ::faceId (
const ElementInfo &elementInfo,
const int face )
const 461 const typename MacroData::ElementId &elementId = macroData_.element( index );
464 for(
size_t i = 0; i < faceId.size(); ++i )
467 faceId[ i ] = elementId[ k ];
469 std::sort( faceId.begin(), faceId.end() );
478 template<
int dim,
int dimworld >
482 typedef ProjectionFactory This;
494 : gridFactory_( gridFactory )
499 if( gridFactory().globalProjection_ )
502 const unsigned int index = gridFactory().insertionIndex( elementInfo, face );
504 return bool( gridFactory().boundaryProjections_[ index ] );
511 return bool( gridFactory().globalProjection_ );
514 Projection
projection (
const ElementInfo &elementInfo,
const int face )
const 516 const unsigned int index = gridFactory().insertionIndex( elementInfo, face );
519 const DuneProjectionPtr &projection = gridFactory().boundaryProjections_[ index ];
521 return Projection( projection );
524 assert( gridFactory().globalProjection_ );
525 return Projection( gridFactory().globalProjection_ );
528 Projection
projection (
const ElementInfo &elementInfo )
const 530 assert( gridFactory().globalProjection_ );
531 return Projection( gridFactory().globalProjection_ );
545 #endif // #if HAVE_ALBERTA 547 #endif // #ifndef DUNE_ALBERTA_GRIDFACTORY_HH
Grid::ctype ctype
type of (scalar) coordinates
Definition: albertagrid/gridfactory.hh:57
DuneBoundaryProjection< dimensionworld > DuneProjection
Definition: albertagrid/gridfactory.hh:69
void markLongestEdge()
mark the longest edge as refinemet edge
Definition: albertagrid/gridfactory.hh:276
virtual void insertBoundaryProjection(const GeometryType &type, const std::vector< unsigned int > &vertices, const DuneProjection *projection)
insert a boundary projection into the macro grid
Definition: albertagrid/gridfactory.hh:170
Projection projection(const ElementInfo &elementInfo) const
Definition: albertagrid/gridfactory.hh:528
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
provides the AlbertaGrid class
bool hasProjection(const ElementInfo &elementInfo, const int face) const
Definition: albertagrid/gridfactory.hh:497
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:263
AlbertaGrid< dim, dimworld > Grid
type of grid this factory is for
Definition: albertagrid/gridfactory.hh:54
virtual unsigned int insertionIndex(const typename Codim< dimension >::Entity &entity) const
obtain a vertex' insertion index
Definition: albertagrid/gridfactory.hh:337
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
virtual void insertBoundaryProjection(const DuneProjection *projection)
insert a global (boundary) projection into the macro grid
Definition: albertagrid/gridfactory.hh:202
virtual unsigned int insertionIndex(const typename Grid::LeafIntersection &intersection) const
Definition: albertagrid/gridfactory.hh:345
FieldVector< ctype, dimensionworld > WorldVector
type of vector for world coordinates
Definition: albertagrid/gridfactory.hh:65
Provide a generic factory class for unstructured grids.
Definition: albertagrid/projection.hh:25
std::shared_ptr< const DuneProjection > DuneProjectionPtr
Definition: albertagrid/gridfactory.hh:70
void abs(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:326
const GlobalVector & coordinate(const int vertex) const
Definition: macroelement.hh:32
static const int dimension
dimension of the grid
Definition: common/gridfactory.hh:78
[ provides Dune::Grid ]
Definition: agrid.hh:137
int generic2alberta(int codim, int i) const
Definition: agrid.hh:520
Projection::Projection DuneProjection
Definition: albertagrid/gridfactory.hh:491
virtual unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
obtain an element's insertion index
Definition: albertagrid/gridfactory.hh:331
GridFactory()
Definition: albertagrid/gridfactory.hh:103
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
insert an element into the macro grid
Definition: albertagrid/gridfactory.hh:125
virtual unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
obtain an element's insertion index
Definition: common/gridfactory.hh:179
FieldMatrix< ctype, dimensionworld, dimensionworld > WorldMatrix
type of matrix from world coordinates to world coordinates
Definition: albertagrid/gridfactory.hh:67
ALBERTA REAL_DD GlobalMatrix
Definition: misc.hh:48
specialization of the generic GridFactory for AlbertaGrid
Definition: albertagrid/gridfactory.hh:47
Projection projection(const ElementInfo &elementInfo, const int face) const
Definition: albertagrid/gridfactory.hh:514
Interface class for vertex projection at the boundary.
Definition: boundaryprojection.hh:23
GridFamily::ctype ctype
Definition: agrid.hh:175
Base::Projection Projection
Definition: albertagrid/gridfactory.hh:488
bool write(const std::string &filename)
write out the macro triangulation in native grid file format
Definition: albertagrid/gridfactory.hh:321
Include standard header files.
Definition: agrid.hh:59
Grid * createGrid()
finalize grid creation and hand over the grid
Definition: albertagrid/gridfactory.hh:293
Base::ElementInfo ElementInfo
Definition: albertagrid/gridfactory.hh:489
ProjectionFactory(const GridFactory &gridFactory)
Definition: albertagrid/gridfactory.hh:493
const GridFactory & gridFactory() const
Definition: albertagrid/gridfactory.hh:534
Definition: boundaryprojection.hh:65
virtual bool wasInserted(const typename Grid::LeafIntersection &intersection) const
Definition: albertagrid/gridfactory.hh:354
Dune::BoundarySegment< dimension, dimensionworld > BoundarySegment
Definition: albertagrid/gridfactory.hh:71
static void destroyGrid(Grid *grid)
destroy a grid previously obtain from this factory
Definition: albertagrid/gridfactory.hh:310
Definition: albertagrid/projection.hh:33
virtual void insertBoundarySegment(const std::vector< unsigned int > &vertices, const std::shared_ptr< BoundarySegment > &boundarySegment)
insert a shaped boundary segment into the macro grid
Definition: albertagrid/gridfactory.hh:227
virtual void insertBoundarySegment(const std::vector< unsigned int > &vertices)
insert a boundary segment into the macro grid
Definition: albertagrid/gridfactory.hh:215
Grid::template Codim< codim >::Entity Entity
Definition: albertagrid/gridfactory.hh:76
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:29
bool hasProjection(const ElementInfo &elementInfo) const
Definition: albertagrid/gridfactory.hh:509
const MacroElement & macroElement() const
Definition: elementinfo.hh:438
GridFamily::Traits::LeafIntersection LeafIntersection
A type that is a model of Dune::Intersection, an intersections of two codimension 1 of two codimensio...
Definition: common/grid.hh:460
The dimension of the grid.
Definition: common/grid.hh:387
Definition: macroelement.hh:20
ALBERTA REAL Real
Definition: misc.hh:45
ALBERTA REAL_D GlobalVector
Definition: misc.hh:47
virtual void insertVertex(const WorldVector &pos)
insert a vertex into the macro grid
Definition: albertagrid/gridfactory.hh:115
virtual void insertBoundary(int element, int face, int id)
mark a face as boundary (and assign a boundary id)
Definition: albertagrid/gridfactory.hh:152
int max(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:335
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:73
The dimension of the world the grid lives in.
Definition: common/grid.hh:393