4 #ifndef DUNE_ALU2DGRID_FACTORY_HH
5 #define DUNE_ALU2DGRID_FACTORY_HH
9 #include <dune/common/array.hh>
10 #include <dune/common/mpihelper.hh>
12 #include <dune/geometry/referenceelements.hh>
24 template<
class Gr
idImp >
25 class ALU2dGridFactory
26 :
public GridFactoryInterface< GridImp >
35 typedef DuneBoundaryProjection< dimensionworld > DuneBoundaryProjectionType;
40 typedef typename Grid::template Codim< codim >::Entity Entity;
46 typedef ALU2dGridFactory< Grid > ThisType;
47 typedef GridFactoryInterface< Grid > BaseType;
52 static const unsigned int numFaceCorners = 2;
54 typedef FieldVector< ctype, dimensionworld > VertexType;
56 typedef array< unsigned int, numFaceCorners > FaceType;
58 static const int periodicBndId = ALU2dImplTraits< dimensionworld, elementType >::HBndElType::general_periodic;
61 typedef ALUGridTransformation< ctype, dimensionworld > Transformation;
64 typedef typename Transformation::WorldVector WorldVector;
66 typedef typename Transformation::WorldMatrix WorldMatrix;
71 typedef std::vector< VertexType > VertexVector;
72 typedef std::vector< ElementType > ElementVector;
73 typedef std::vector< std::pair< FaceType, int > > BoundaryIdVector;
75 typedef std::map< FaceType, const DuneBoundaryProjectionType* > BoundaryProjectionMap;
76 typedef std::vector< const DuneBoundaryProjectionType* > BoundaryProjectionVector;
78 typedef std::pair< unsigned int, int > SubEntity;
79 typedef std::map< FaceType, SubEntity, FaceLess > FaceMap;
80 typedef std::vector< Transformation > FaceTransformationVector;
81 typedef std::map< FaceType, unsigned int, FaceLess > PeriodicNeighborMap;
84 void copyAndSort(
const std::vector<unsigned int>& vertices, FaceType& faceId)
const
86 std::vector<unsigned int> tmp( vertices );
87 std::sort( tmp.begin(), tmp.end() );
90 for(
size_t i = 0; i < faceId.size(); ++i ) faceId[ i ] = tmp[ i ];
95 explicit ALU2dGridFactory (
bool removeGeneratedFile =
true );
98 explicit ALU2dGridFactory (
const std::string &filename );
101 virtual ~ALU2dGridFactory ();
107 virtual void insertVertex (
const VertexType &pos );
119 const std::vector< unsigned int > &vertices );
133 const std::vector< unsigned int > &faceVertices,
142 virtual void insertBoundary (
const int element,
const int face,
const int id );
154 const std::vector< unsigned int > &vertices,
155 const DuneBoundaryProjectionType *projection );
162 insertBoundarySegment (
const std::vector< unsigned int >& vertices ) ;
170 insertBoundarySegment (
const std::vector< unsigned int >& vertices,
171 const shared_ptr<BoundarySegment<2,dimensionworld> >& boundarySegment ) ;
177 virtual void insertBoundaryProjection (
const DuneBoundaryProjectionType& bndProjection );
188 void insertFaceTransformation (
const WorldMatrix &matrix,
const WorldVector &shift );
191 insertionIndex (
const typename Codim< 0 >::Entity &entity )
const
193 return Grid::getRealImplementation( entity ).getIndex();
197 insertionIndex (
const typename Codim< dimension >::Entity &entity )
const
199 return Grid::getRealImplementation( entity ).getIndex();
205 return intersection.boundarySegmentIndex();
211 return intersection.boundary() &&
212 ( insertionIndex(intersection) < numFacesInserted_ );
221 Grid *createGrid (
const bool addMissingBoundaries,
const std::string dgfName =
"" );
223 Grid *createGrid (
const bool addMissingBoundaries,
bool temporary,
const std::string dgfName =
"" );
225 void setTolerance (
const ctype &epsilon ) { epsilon_ = epsilon; }
229 virtual Grid* createGridObj(
const bool temporary,
230 const std::string& filename,
231 std::istream& inFile,
232 BoundaryProjectionVector* bndProjections )
234 return ( temporary ) ?
235 new Grid( filename, inFile, globalProjection_, bndProjections, grdVerbose_ ) :
236 new Grid( filename, globalProjection_ , bndProjections, grdVerbose_ );
244 void setVerbosity(
const bool verbose ) { grdVerbose_ = verbose; }
247 static void generateFace (
const ElementType &element,
const int f, FaceType &face );
248 void correctElementOrientation ();
249 typename FaceMap::const_iterator findPeriodicNeighbor(
const FaceMap &faceMap,
const FaceType &key )
const;
250 void reinsertBoundary (
const FaceMap &faceMap,
const typename FaceMap::const_iterator &pos,
const int id );
251 void recreateBoundaryIds (
const int defaultId = 1 );
253 VertexVector vertices_;
254 ElementVector elements_;
255 BoundaryIdVector boundaryIds_;
256 const DuneBoundaryProjectionType* globalProjection_ ;
257 BoundaryProjectionMap boundaryProjections_;
258 unsigned int numFacesInserted_;
260 FaceTransformationVector faceTransformations_;
261 PeriodicNeighborMap periodicNeighborMap_;
266 template<
class Gr
idImp >
267 struct ALU2dGridFactory< GridImp >::FaceLess
268 :
public std::binary_function< FaceType, FaceType, bool >
270 bool operator() (
const FaceType &a,
const FaceType &b )
const
272 for(
unsigned int i = 0; i < numFaceCorners; ++i )
274 if( a[ i ] != b[ i ] )
275 return (a[ i ] < b[ i ]);
286 class GridFactory< ALUConformGrid<2,dimw> >
287 :
public ALU2dGridFactory<ALUConformGrid<2, dimw> >
290 typedef ALUConformGrid< 2, dimw > Grid;
294 typedef ALU2dGridFactory< Grid > BaseType;
304 : BaseType( filename )
311 this->setVerbosity( verbose );
318 class GridFactory< ALUSimplexGrid<2,dimw> >
319 :
public ALU2dGridFactory<ALUSimplexGrid<2, dimw> >
322 typedef ALUSimplexGrid< 2, dimw > Grid;
326 typedef ALU2dGridFactory< Grid > BaseType;
336 : BaseType( filename )
346 this->setVerbosity( verbose );
354 class GridFactory< ALUCubeGrid<2,dimw> >
355 :
public ALU2dGridFactory<ALUCubeGrid<2,dimw> >
358 typedef ALUCubeGrid< 2, dimw > Grid;
362 typedef ALU2dGridFactory< Grid > BaseType;
372 : BaseType( filename )
382 this->setVerbosity( verbose );
390 template<
int dimw, ALUGr
idElementType eltype, ALUGr
idRefinementType refinementtype,
class Comm>
391 class GridFactory< ALUGrid<2, dimw, eltype, refinementtype, Comm > >
392 :
public ALU2dGridFactory< ALUGrid<2, dimw, eltype, refinementtype, Comm > >
395 typedef ALUGrid<2, dimw, eltype, refinementtype, Comm > Grid;
399 typedef ALU2dGridFactory< Grid > BaseType;
409 : BaseType( filename )
419 this->setVerbosity( verbose );
428 template<
class Gr
idImp >
429 inline ALU2dGridFactory< GridImp >::ALU2dGridFactory (
bool removeGeneratedFile )
430 : globalProjection_ ( 0 ),
431 numFacesInserted_ ( 0 ),
437 template<
class Gr
idImp >
438 inline ALU2dGridFactory< GridImp >::ALU2dGridFactory (
const std::string &filename )
439 : globalProjection_ ( 0 ),
440 numFacesInserted_ ( 0 ),
446 template<
class Gr
idImp >
447 inline ALU2dGridFactory< GridImp >::~ALU2dGridFactory ()
451 template<
class Gr
idImp >
452 inline GridImp *ALU2dGridFactory< GridImp >::createGrid ()
454 return createGrid(
true,
true,
"" );
458 template<
class Gr
idImp >
459 inline GridImp *ALU2dGridFactory< GridImp >
460 ::createGrid (
const bool addMissingBoundaries,
const std::string dgfName )
462 return createGrid( addMissingBoundaries,
true, dgfName );
467 #endif // #if HAVE_ALUGRID
469 #endif // #ifndef DUNE_ALU2DGRID_FACTORY_HH