alu3dgridfactory.hh
00001 #ifndef DUNE_ALU3DGRID_FACTORY_HH
00002 #define DUNE_ALU3DGRID_FACTORY_HH
00003
00004 #include <dune/common/fixedarray.hh>
00005
00006 #include <dune/grid/common/gridfactory.hh>
00007 #include <dune/grid/alugrid.hh>
00008
00009 namespace Dune
00010 {
00011
00013 template< template< int, int > class ALUGrid >
00014 class ALU3dGridFactory
00015 : public GridFactoryInterface< ALUGrid< 3, 3 > >
00016 {
00017 typedef ALU3dGridFactory< ALUGrid > ThisType;
00018 typedef GridFactoryInterface< ALUGrid< 3, 3 > > BaseType;
00019
00020 public:
00021 typedef ALUGrid< 3, 3 > GridType;
00022
00023 typedef MPIHelper :: MPICommunicator MPICommunicatorType;
00024
00025 private:
00026 typedef typename GridType :: ctype ctype;
00027
00028 static const ALU3dGridElementType elementType = GridType :: elementType;
00029
00030 dune_static_assert( (elementType == tetra || elementType == hexa),
00031 "ALU3dGridFactory supports only grids containing "
00032 "tetrahedrons or hexahedrons exclusively." );
00033
00034 static const unsigned int dimension = GridType :: dimension;
00035 static const unsigned int dimensionworld = GridType :: dimensionworld;
00036
00037 static const unsigned int numCorners
00038 = EntityCount< elementType > :: numVertices;
00039 static const unsigned int numFaceCorners
00040 = EntityCount< elementType > :: numVerticesPerFace;
00041
00042 typedef ElementTopologyMapping< elementType > ElementTopologyMappingType;
00043 typedef FaceTopologyMapping< elementType > FaceTopologyMappingType;
00044
00045 typedef FieldVector< ctype, dimensionworld > VertexType;
00046 typedef array< unsigned int, numCorners > ElementType;
00047 typedef array< unsigned int, numFaceCorners > FaceType;
00048
00049 private:
00050 const std::string filename_;
00051 MPICommunicatorType communicator_;
00052 bool removeGeneratedFile_;
00053 #if ALU3DGRID_PARALLEL
00054 int rank_;
00055 #endif
00056 std :: vector< VertexType > vertices_;
00057 std :: vector< ElementType > elements_;
00058 std :: vector< std :: pair< FaceType, int > > boundaryIds_;
00059
00060 public:
00062 explicit ALU3dGridFactory ( const MPICommunicatorType &communicator
00063 = MPIHelper :: getCommunicator(),
00064 bool removeGeneratedFile = true );
00065
00067 explicit ALU3dGridFactory ( const std::string &filename,
00068 const MPICommunicatorType &communicator
00069 = MPIHelper :: getCommunicator() );
00070
00072 virtual ~ALU3dGridFactory ();
00073
00078 virtual void insertVertex ( const VertexType &pos );
00079
00088 virtual void
00089 insertElement ( const GeometryType &geometry,
00090 const std :: vector< unsigned int > &vertices );
00091
00102 virtual void
00103 insertBoundary ( const GeometryType &geometry,
00104 const std :: vector< unsigned int > &faceVertices,
00105 int id );
00106
00111 virtual GridType *createGrid ();
00112
00113 private:
00114 inline void assertGeometryType( const GeometryType &geometry );
00115 inline static std :: string temporaryFileName ();
00116 };
00117
00118
00119 template< template< int, int > class ALUGrid >
00120 inline void ALU3dGridFactory< ALUGrid >
00121 :: assertGeometryType( const GeometryType &geometry )
00122 {
00123 if( elementType == tetra )
00124 {
00125 if( !geometry.isSimplex() )
00126 DUNE_THROW( GridError, "Only simplex geometries can be inserted into "
00127 "ALUSimplexGrid< 3, 3 >." );
00128 }
00129 else
00130 {
00131 if( !geometry.isCube() )
00132 DUNE_THROW( GridError, "Only cube geometries can be inserted into "
00133 "ALUCubeGrid< 3, 3 >." );
00134 }
00135 }
00136
00137
00140 template<>
00141 class GridFactory< ALUSimplexGrid< 3, 3 > >
00142 : public ALU3dGridFactory< ALUSimplexGrid >
00143 {
00144 typedef GridFactory< ALUSimplexGrid< 3, 3 > > ThisType;
00145 typedef ALU3dGridFactory< ALUSimplexGrid > BaseType;
00146
00147 public:
00148 typedef ALUSimplexGrid< 3, 3 > GridType;
00149
00150 typedef MPIHelper :: MPICommunicator MPICommunicatorType;
00151
00152 public:
00154 explicit GridFactory ( const MPICommunicatorType &communicator
00155 = MPIHelper :: getCommunicator() )
00156 : BaseType( communicator )
00157 {}
00158
00160 GridFactory ( const std::string filename,
00161 const MPICommunicatorType &communicator
00162 = MPIHelper :: getCommunicator() )
00163 : BaseType( filename, communicator )
00164 {}
00165 };
00166
00167
00168
00171 template<>
00172 class GridFactory< ALUCubeGrid< 3, 3 > >
00173 : public ALU3dGridFactory< ALUCubeGrid >
00174 {
00175 typedef GridFactory< ALUCubeGrid< 3, 3 > > ThisType;
00176 typedef ALU3dGridFactory< ALUCubeGrid > BaseType;
00177
00178 public:
00179 typedef ALUCubeGrid< 3, 3 > GridType;
00180
00181 typedef MPIHelper :: MPICommunicator MPICommunicatorType;
00182
00183 public:
00185 explicit GridFactory ( const MPICommunicatorType &communicator
00186 = MPIHelper :: getCommunicator() )
00187 : BaseType( communicator )
00188 {}
00189
00191 GridFactory ( const std::string filename,
00192 const MPICommunicatorType &communicator
00193 = MPIHelper :: getCommunicator() )
00194 : BaseType( filename, communicator )
00195 {}
00196 };
00197
00198 }
00199
00200
00201
00202 #include "alu3dgridfactory.cc"
00203 #endif