4#ifndef DUNE_ALU2DGRID_FACTORY_HH
5#define DUNE_ALU2DGRID_FACTORY_HH
12#include <dune/geometry/referenceelements.hh>
16#include <dune/grid/alugrid/common/persistentcontainer.hh>
17#include <dune/grid/alugrid/common/transformation.hh>
18#include <dune/grid/alugrid/2d/grid.hh>
24 template<
class Gr
idImp >
25 class ALU2dGridFactory
26 :
public GridFactoryInterface< GridImp >
28 typedef GridFactoryInterface< GridImp > Base ;
30 using Base :: insertElement ;
38 typedef DuneBoundaryProjection< dimensionworld > DuneBoundaryProjectionType;
43 typedef typename Grid::template Codim< codim >::Entity Entity;
49 typedef ALU2dGridFactory< Grid > ThisType;
54 static const ALU2DSPACE ElementType elementType = Grid::elementType;
55 static const unsigned int numFaceCorners = 2;
57 typedef FieldVector< ctype, dimensionworld > VertexType;
58 typedef std::vector< unsigned int > ElementType;
59 typedef array< unsigned int, numFaceCorners > FaceType;
61 static const int periodicBndId = ALU2dImplTraits< dimensionworld, elementType >::HBndElType::general_periodic;
64 typedef ALUGridTransformation< ctype, dimensionworld > Transformation;
67 typedef typename Transformation::WorldVector WorldVector;
69 typedef typename Transformation::WorldMatrix WorldMatrix;
74 typedef std::vector< VertexType > VertexVector;
75 typedef std::vector< ElementType > ElementVector;
76 typedef std::vector< std::pair< FaceType, int > > BoundaryIdVector;
78 typedef std::map< FaceType, const DuneBoundaryProjectionType* > BoundaryProjectionMap;
79 typedef std::vector< const DuneBoundaryProjectionType* > BoundaryProjectionVector;
81 typedef std::pair< unsigned int, int > SubEntity;
82 typedef std::map< FaceType, SubEntity, FaceLess > FaceMap;
83 typedef std::vector< Transformation > FaceTransformationVector;
84 typedef std::map< FaceType, unsigned int, FaceLess > PeriodicNeighborMap;
87 void copyAndSort(
const std::vector<unsigned int>& vertices, FaceType& faceId)
const
89 std::vector<unsigned int> tmp( vertices );
90 std::sort( tmp.begin(), tmp.end() );
93 for(
size_t i = 0; i < faceId.size(); ++i ) faceId[ i ] = tmp[ i ];
98 explicit ALU2dGridFactory (
bool removeGeneratedFile =
true );
101 explicit ALU2dGridFactory (
const std::string &filename );
104 virtual ~ALU2dGridFactory ();
110 virtual void insertVertex (
const VertexType &pos );
121 insertElement (
const GeometryType &geometry,
122 const std::vector< unsigned int > &vertices );
135 insertBoundary (
const GeometryType &geometry,
136 const std::vector< unsigned int > &faceVertices,
145 virtual void insertBoundary (
const int element,
const int face,
const int id );
156 insertBoundaryProjection (
const GeometryType &type,
157 const std::vector< unsigned int > &vertices,
158 const DuneBoundaryProjectionType *projection );
165 insertBoundarySegment (
const std::vector< unsigned int >& vertices ) ;
173 insertBoundarySegment (
const std::vector< unsigned int >& vertices,
174 const shared_ptr<BoundarySegment<2,dimensionworld> >& boundarySegment ) ;
180 virtual void insertBoundaryProjection (
const DuneBoundaryProjectionType& bndProjection );
191 void insertFaceTransformation (
const WorldMatrix &matrix,
const WorldVector &shift );
194 insertionIndex (
const typename Codim< 0 >::Entity &entity )
const
196 return Grid::getRealImplementation( entity ).getIndex();
200 insertionIndex (
const typename Codim< dimension >::Entity &entity )
const
202 return Grid::getRealImplementation( entity ).getIndex();
208 return intersection.boundarySegmentIndex();
214 return intersection.boundary() &&
215 ( insertionIndex(intersection) < numFacesInserted_ );
224 Grid *createGrid (
const bool addMissingBoundaries,
const std::string dgfName =
"" );
226 Grid *createGrid (
const bool addMissingBoundaries,
bool temporary,
const std::string dgfName =
"" );
228 void setTolerance (
const ctype &epsilon ) { epsilon_ = epsilon; }
232 virtual Grid* createGridObj(
const bool temporary,
233 const std::string& filename,
234 std::istream& inFile,
235 BoundaryProjectionVector* bndProjections )
237 return ( temporary ) ?
238 new Grid( filename, inFile, globalProjection_, bndProjections, grdVerbose_ ) :
239 new Grid( filename, globalProjection_ , bndProjections, grdVerbose_ );
247 void setVerbosity(
const bool verbose ) { grdVerbose_ = verbose; }
250 static void generateFace (
const ElementType &element,
const int f, FaceType &face );
251 void correctElementOrientation ();
252 typename FaceMap::const_iterator findPeriodicNeighbor(
const FaceMap &faceMap,
const FaceType &key )
const;
253 void reinsertBoundary (
const FaceMap &faceMap,
const typename FaceMap::const_iterator &pos,
const int id );
254 void recreateBoundaryIds (
const int defaultId = 1 );
256 VertexVector vertices_;
257 ElementVector elements_;
258 BoundaryIdVector boundaryIds_;
259 const DuneBoundaryProjectionType* globalProjection_ ;
260 BoundaryProjectionMap boundaryProjections_;
261 unsigned int numFacesInserted_;
263 FaceTransformationVector faceTransformations_;
264 PeriodicNeighborMap periodicNeighborMap_;
269 template<
class Gr
idImp >
270 struct ALU2dGridFactory< GridImp >::FaceLess
271 :
public std::binary_function< FaceType, FaceType, bool >
273 bool operator() (
const FaceType &a,
const FaceType &b )
const
275 for(
unsigned int i = 0; i < numFaceCorners; ++i )
277 if( a[ i ] != b[ i ] )
278 return (a[ i ] < b[ i ]);
289 template<
int dimw, ALUGr
idElementType eltype, ALUGr
idRefinementType refinementtype,
class Comm>
290 class GridFactory< ALUGrid<2, dimw, eltype, refinementtype, Comm > >
291 :
public ALU2dGridFactory< ALUGrid<2, dimw, eltype, refinementtype, Comm > >
294 typedef ALUGrid<2, dimw, eltype, refinementtype, Comm > Grid;
298 typedef ALU2dGridFactory< Grid > BaseType;
308 : BaseType( filename )
318 this->setVerbosity( verbose );
327 template<
class Gr
idImp >
328 inline ALU2dGridFactory< GridImp >::ALU2dGridFactory (
bool removeGeneratedFile )
329 : globalProjection_ ( 0 ),
330 numFacesInserted_ ( 0 ),
336 template<
class Gr
idImp >
337 inline ALU2dGridFactory< GridImp >::ALU2dGridFactory (
const std::string &filename )
338 : globalProjection_ ( 0 ),
339 numFacesInserted_ ( 0 ),
345 template<
class Gr
idImp >
346 inline ALU2dGridFactory< GridImp >::~ALU2dGridFactory ()
350 template<
class Gr
idImp >
351 inline GridImp *ALU2dGridFactory< GridImp >::createGrid ()
353 return createGrid(
true,
true,
"" );
357 template<
class Gr
idImp >
358 inline GridImp *ALU2dGridFactory< GridImp >
359 ::createGrid (
const bool addMissingBoundaries,
const std::string dgfName )
361 return createGrid( addMissingBoundaries,
true, dgfName );
Fallback implementation of the std::array class (a static array)
Definition: boundaryprojection.hh:67
GridFactory()
Default constructor.
Definition: gridfactory.hh:274
GridFamily::Traits::LeafIntersection LeafIntersection
A type that is a model of Dune::Intersection, an intersections of two codimension 1 of two codimensio...
Definition: grid.hh:486
@ dimensionworld
The dimension of the world the grid lives in.
Definition: grid.hh:408
@ dimension
The dimension of the grid.
Definition: grid.hh:402
ct ctype
Define type used for coordinates in grid module.
Definition: grid.hh:548
Provide a generic factory class for unstructured grids.
Helpers for dealing with MPI.
Dune namespace.
Definition: alignment.hh:10