- Home
- About DUNE
- Download
- Documentation
- Community
- Development
00001 #ifndef DUNE_ALBERTA_ALBERTAREADER_HH 00002 #define DUNE_ALBERTA_ALBERTAREADER_HH 00003 00004 #include <dune/grid/common/grid.hh> 00005 #include <dune/grid/common/gridfactory.hh> 00006 00007 #include <dune/grid/utility/grapedataioformattypes.hh> 00008 00009 #include <dune/grid/albertagrid/macrodata.hh> 00010 00011 #if HAVE_ALBERTA 00012 00013 namespace Dune 00014 { 00015 00016 template< class Grid > 00017 class AlbertaReader 00018 { 00019 typedef AlbertaReader< Grid > This; 00020 00021 public: 00022 typedef Dune::GridFactory< Grid > GridFactory; 00023 00024 typedef typename Grid::ctype ctype; 00025 00026 static const int dimension = Grid::dimension; 00027 static const int dimensionworld = Grid::dimensionworld; 00028 00029 private: 00030 dune_static_assert( dimensionworld == Alberta::dimWorld, 00031 "AlbertaReader: world dimension must match ALBERTA's world dimension." ); 00032 00033 typedef Alberta::MacroData< dimension > MacroData; 00034 00035 MacroData macroData_; 00036 00037 AlbertaReader ( const This & ); 00038 This &operator= ( const This & ); 00039 00040 public: 00041 AlbertaReader () 00042 {} 00043 00044 template< GrapeIOFileFormatType type > 00045 void readGrid ( const std::string &fileName, GridFactory &factory ) 00046 { 00047 dune_static_assert( type != pgm, "AlbertaReader: reading pgm format is not supported." ); 00048 00049 // read ALBERTA macro triangulation 00050 macroData_.read( fileName, (type == xdr) ); 00051 00052 // insert all vertices into the factory 00053 const int numVertices = macroData_.vertexCount(); 00054 for( int i = 0; i < numVertices; ++i ) 00055 { 00056 FieldVector< ctype, dimensionworld > v; 00057 const Alberta::GlobalVector &coords = macroData_.vertex( i ); 00058 for( int j = 0; j < dimensionworld; ++j ) 00059 v[ j ] = coords[ j ]; 00060 factory.insertVertex( v ); 00061 } 00062 00063 // insert all elements into the factory 00064 std::vector< unsigned int > vertices( dimension+1 ); 00065 const int numElements = macroData_.elementCount(); 00066 for( int i = 0; i < numElements; ++i ) 00067 { 00068 const typename MacroData::ElementId &id = macroData_.element( i ); 00069 for( int j = 0; j <= dimension; ++j ) 00070 vertices[ j ] = id[ j ]; 00071 typedef typename GenericGeometry::SimplexTopology< dimension >::type Topology; 00072 factory.insertElement( GeometryType( Topology() ), vertices ); 00073 } 00074 00075 // release ALBERTA macro data 00076 macroData_.release(); 00077 } 00078 00079 void readGrid ( const std::string &filename, GridFactory &factory ) 00080 { 00081 readGrid< ascii >( filename, factory ); 00082 } 00083 }; 00084 00085 } 00086 00087 #endif // #if HAVE_ALBERTA 00088 00089 #endif
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].