dune-grid  2.2.0
albertareader.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALBERTA_ALBERTAREADER_HH
2 #define DUNE_ALBERTA_ALBERTAREADER_HH
3 
6 
8 
10 
11 #if HAVE_ALBERTA
12 
13 namespace Dune
14 {
15 
16  template< class Grid >
18  {
20 
21  public:
23 
24  typedef typename Grid::ctype ctype;
25 
26  static const int dimension = Grid::dimension;
28 
29  private:
30  dune_static_assert( dimensionworld == Alberta::dimWorld,
31  "AlbertaReader: world dimension must match ALBERTA's world dimension." );
32 
34 
35  MacroData macroData_;
36 
37  AlbertaReader ( const This & );
38  This &operator= ( const This & );
39 
40  public:
42  {}
43 
44  template< GrapeIOFileFormatType type >
45  void readGrid ( const std::string &fileName, GridFactory &factory )
46  {
47  dune_static_assert( type != pgm, "AlbertaReader: reading pgm format is not supported." );
48 
49  // read ALBERTA macro triangulation
50  macroData_.read( fileName, (type == xdr) );
51 
52  // insert all vertices into the factory
53  const int numVertices = macroData_.vertexCount();
54  for( int i = 0; i < numVertices; ++i )
55  {
56  FieldVector< ctype, dimensionworld > v;
57  const Alberta::GlobalVector &coords = macroData_.vertex( i );
58  for( int j = 0; j < dimensionworld; ++j )
59  v[ j ] = coords[ j ];
60  factory.insertVertex( v );
61  }
62 
63  // insert all elements into the factory
64  std::vector< unsigned int > vertices( dimension+1 );
65  const int numElements = macroData_.elementCount();
66  for( int i = 0; i < numElements; ++i )
67  {
68  const typename MacroData::ElementId &id = macroData_.element( i );
69  for( int j = 0; j <= dimension; ++j )
70  vertices[ j ] = id[ j ];
71  typedef typename GenericGeometry::SimplexTopology< dimension >::type Topology;
72  factory.insertElement( GeometryType( Topology() ), vertices );
73  }
74 
75  // release ALBERTA macro data
76  macroData_.release();
77  }
78 
79  void readGrid ( const std::string &filename, GridFactory &factory )
80  {
81  readGrid< ascii >( filename, factory );
82  }
83  };
84 
85 }
86 
87 #endif // #if HAVE_ALBERTA
88 
89 #endif