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;
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,
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." );
204 if( globalProjection_ )
205 DUNE_THROW(
GridError,
"Only one global boundary projection can be attached to a grid." );
217 insertBoundaryProjection( GeometryTypes::simplex(
dimension-1 ), vertices, 0 );
227 const std::shared_ptr< BoundarySegment > &boundarySegment )
229 auto refSimplex = ReferenceElements< ctype, dimension-1 >::simplex();
231 if( !boundarySegment )
232 DUNE_THROW(
GridError,
"Trying to insert null as a boundary segment." );
233 if( (
int)vertices.size() != refSimplex.size(
dimension-1 ) )
234 DUNE_THROW(
GridError,
"Wrong number of face vertices passed: " << vertices.size() <<
"." );
236 std::vector< WorldVector > coords( refSimplex.size(
dimension-1 ) );
240 for(
int j = 0; j < dimensionworld; ++j )
241 coords[ i ][ j ] = x[ j ];
242 if( ((*boundarySegment)( refSimplex.position( i,
dimension-1 ) ) - coords[ i ]).two_norm() > 1e-6 )
243 DUNE_THROW(
GridError,
"Boundary segment does not interpolate the corners." );
248 insertBoundaryProjection( gt, vertices, prj );
264 void insertFaceTransformation (
const WorldMatrix &matrix,
const WorldVector &shift );
276 macroData_.markLongestEdge();
293 macroData_.finalize();
294 if( macroData_.elementCount() == 0 )
295 DUNE_THROW(
GridError,
"Cannot create empty AlbertaGrid." );
298 assert( macroData_.checkNeighbors() );
299 macroData_.checkCycles();
300 ProjectionFactory projectionFactory( *
this );
301 return std::make_unique<Grid>( macroData_, projectionFactory );
319 bool write (
const std::string &filename )
321 macroData_.finalize();
324 assert( macroData_.checkNeighbors() );
325 return macroData_.write( filename,
false );
337 const int elIndex =
insertionIndex( entity.impl().elementInfo() );
338 const typename MacroData::ElementId &elementId = macroData_.element( elIndex );
339 return elementId[ entity.impl().subEntity() ];
345 const Grid &grid = intersection.impl().grid();
346 const ElementInfo &elementInfo = intersection.impl().elementInfo();
347 const int face = grid.
generic2alberta( 1, intersection.indexInInside() );
358 unsigned int insertionIndex (
const ElementInfo &elementInfo )
const;
359 unsigned int insertionIndex (
const ElementInfo &elementInfo,
const int face )
const;
361 FaceId faceId (
const ElementInfo &elementInfo,
const int face )
const;
363 MacroData macroData_;
364 NumberingMap numberingMap_;
365 DuneProjectionPtr globalProjection_;
366 BoundaryMap boundaryMap_;
367 std::vector< DuneProjectionPtr > boundaryProjections_;
371 template<
int dim,
int dimworld >
374 macroData_.release();
378 template<
int dim,
int dimworld >
384 for(
int i = 0; i < dimworld; ++i )
385 for(
int j = 0; j < dimworld; ++j )
388 const ctype epsilon = (8*dimworld)*std::numeric_limits< ctype >::epsilon();
390 if(
std::abs( matrix[ i ] * matrix[ j ] - delta ) > epsilon )
393 "Matrix of face transformation is not orthogonal." );
399 for(
int i = 0; i < dimworld; ++i )
400 for(
int j = 0; j < dimworld; ++j )
401 M[ i ][ j ] = matrix[ i ][ j ];
405 for(
int i = 0; i < dimworld; ++i )
409 macroData_.insertWallTrafo( M, t );
413 template<
int dim,
int dimworld >
416 ::insertionIndex (
const ElementInfo &elementInfo )
const
418 const MacroElement ¯oElement = elementInfo.macroElement();
419 const unsigned int index = macroElement.index;
422 const typename MacroData::ElementId &elementId = macroData_.element( index );
423 for(
int i = 0; i <= dimension; ++i )
427 for(
int j = 0; j < dimensionworld; ++j )
429 if( x[ j ] != y[ j ] )
430 DUNE_THROW(
GridError,
"Vertex in macro element does not coincide with same vertex in macro data structure." );
439 template<
int dim,
int dimworld >
441 GridFactory< AlbertaGrid< dim, dimworld > >
442 ::insertionIndex (
const ElementInfo &elementInfo,
const int face )
const
444 typedef typename BoundaryMap::const_iterator Iterator;
445 const Iterator it = boundaryMap_.find( faceId( elementInfo, face ) );
446 if( it != boundaryMap_.end() )
453 template<
int dim,
int dimworld >
454 inline typename GridFactory< AlbertaGrid< dim, dimworld > >::FaceId
455 GridFactory< AlbertaGrid< dim, dimworld > >
456 ::faceId (
const ElementInfo &elementInfo,
const int face )
const
458 const unsigned int index = insertionIndex( elementInfo );
459 const typename MacroData::ElementId &elementId = macroData_.element( index );
462 for(
size_t i = 0; i < faceId.size(); ++i )
464 const int k = Alberta::MapVertices< dimension, 1 >::apply( face, i );
465 faceId[ i ] = elementId[ k ];
467 std::sort( faceId.begin(), faceId.end() );
476 template<
int dim,
int dimworld >
480 typedef ProjectionFactory This;
492 : gridFactory_( gridFactory )
497 if( gridFactory().globalProjection_ )
500 const unsigned int index = gridFactory().insertionIndex( elementInfo, face );
502 return bool( gridFactory().boundaryProjections_[ index ] );
509 return bool( gridFactory().globalProjection_ );
514 const unsigned int index = gridFactory().insertionIndex( elementInfo, face );
517 const DuneProjectionPtr &projection = gridFactory().boundaryProjections_[ index ];
522 assert( gridFactory().globalProjection_ );
523 return Projection( gridFactory().globalProjection_ );
528 assert( gridFactory().globalProjection_ );
529 return Projection( gridFactory().globalProjection_ );
provides the AlbertaGrid class
Include standard header files.
Definition: agrid.hh:58
void abs(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:326
ALBERTA REAL_DD GlobalMatrix
Definition: misc.hh:49
ALBERTA REAL Real
Definition: misc.hh:46
int max(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:335
ALBERTA REAL_D GlobalVector
Definition: misc.hh:48
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:130
[ provides Dune::Grid ]
Definition: agrid.hh:107
int generic2alberta(int codim, int i) const
Definition: agrid.hh:485
GridFamily::ctype ctype
Definition: agrid.hh:141
specialization of the generic GridFactory for AlbertaGrid
Definition: albertagrid/gridfactory.hh:49
DuneBoundaryProjection< dimensionworld > DuneProjection
Definition: albertagrid/gridfactory.hh:69
FieldVector< ctype, dimensionworld > WorldVector
type of vector for world coordinates
Definition: albertagrid/gridfactory.hh:65
virtual unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
Definition: albertagrid/gridfactory.hh:329
virtual bool wasInserted(const typename Grid::LeafIntersection &intersection) const
Definition: albertagrid/gridfactory.hh:352
std::shared_ptr< const DuneProjection > DuneProjectionPtr
Definition: albertagrid/gridfactory.hh:70
AlbertaGrid< dim, dimworld > Grid
type of grid this factory is for
Definition: albertagrid/gridfactory.hh:54
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
FieldMatrix< ctype, dimensionworld, dimensionworld > WorldMatrix
type of matrix from world coordinates to world coordinates
Definition: albertagrid/gridfactory.hh:67
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
insert an element into the macro grid
Definition: albertagrid/gridfactory.hh:125
std::unique_ptr< Grid > createGrid()
finalize grid creation and hand over the grid
Definition: albertagrid/gridfactory.hh:291
Dune::BoundarySegment< dimension, dimensionworld > BoundarySegment
Definition: albertagrid/gridfactory.hh:71
void markLongestEdge()
mark the longest edge as refinemet edge
Definition: albertagrid/gridfactory.hh:274
Grid::ctype ctype
type of (scalar) coordinates
Definition: albertagrid/gridfactory.hh:57
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
GridFactory()
Definition: albertagrid/gridfactory.hh:103
static void destroyGrid(Grid *grid)
destroy a grid previously obtain from this factory
Definition: albertagrid/gridfactory.hh:308
virtual unsigned int insertionIndex(const typename Codim< dimension >::Entity &entity) const
Definition: albertagrid/gridfactory.hh:335
bool write(const std::string &filename)
write out the macro triangulation in native grid file format
Definition: albertagrid/gridfactory.hh:319
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:226
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:343
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
const GridFactory & gridFactory() const
Definition: albertagrid/gridfactory.hh:532
bool hasProjection(const ElementInfo &) const
Definition: albertagrid/gridfactory.hh:507
Base::ElementInfo ElementInfo
Definition: albertagrid/gridfactory.hh:487
Base::Projection Projection
Definition: albertagrid/gridfactory.hh:486
ProjectionFactory(const GridFactory &gridFactory)
Definition: albertagrid/gridfactory.hh:491
Projection projection(const ElementInfo &elementInfo, const int face) const
Definition: albertagrid/gridfactory.hh:512
Projection::Projection DuneProjection
Definition: albertagrid/gridfactory.hh:489
Projection projection(const ElementInfo &) const
Definition: albertagrid/gridfactory.hh:526
bool hasProjection(const ElementInfo &elementInfo, const int face) const
Definition: albertagrid/gridfactory.hh:495
Definition: macroelement.hh:22
Definition: albertagrid/projection.hh:133
Base::Projection Projection
Definition: albertagrid/projection.hh:138
Definition: albertagrid/projection.hh:34
Interface class for vertex projection at the boundary.
Definition: boundaryprojection.hh:31
Definition: boundaryprojection.hh:131
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:92
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
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:459
@ dimensionworld
The dimension of the world the grid lives in.
Definition: common/grid.hh:392
@ dimension
The dimension of the grid.
Definition: common/grid.hh:386
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:71
virtual unsigned int insertionIndex([[maybe_unused]] const typename Codim< 0 >::Entity &entity) const
obtain an element's insertion index
Definition: common/gridfactory.hh:218
static const int dimension
dimension of the grid
Definition: common/gridfactory.hh:75
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:312
Provide a generic factory class for unstructured grids.