dune-grid  2.3.1
albertareader.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_ALBERTA_ALBERTAREADER_HH
4 #define DUNE_ALBERTA_ALBERTAREADER_HH
5 
8 
10 
12 
13 #if HAVE_ALBERTA
14 
15 namespace Dune
16 {
17 
18  template< class Grid >
20  {
22 
23  public:
25 
26  typedef typename Grid::ctype ctype;
27 
28  static const int dimension = Grid::dimension;
30 
31  private:
32  dune_static_assert( dimensionworld == Alberta::dimWorld,
33  "AlbertaReader: world dimension must match ALBERTA's world dimension." );
34 
36 
37  MacroData macroData_;
38 
39  AlbertaReader ( const This & );
40  This &operator= ( const This & );
41 
42  public:
44  {}
45 
46  template< GrapeIOFileFormatType type >
47  void readGrid ( const std::string &fileName, GridFactory &factory )
48  {
49  dune_static_assert( type != pgm, "AlbertaReader: reading pgm format is not supported." );
50 
51  // read ALBERTA macro triangulation
52  macroData_.read( fileName, (type == xdr) );
53 
54  // insert all vertices into the factory
55  const int numVertices = macroData_.vertexCount();
56  for( int i = 0; i < numVertices; ++i )
57  {
58  FieldVector< ctype, dimensionworld > v;
59  const Alberta::GlobalVector &coords = macroData_.vertex( i );
60  for( int j = 0; j < dimensionworld; ++j )
61  v[ j ] = coords[ j ];
62  factory.insertVertex( v );
63  }
64 
65  // insert all elements into the factory
66  std::vector< unsigned int > vertices( dimension+1 );
67  const int numElements = macroData_.elementCount();
68  for( int i = 0; i < numElements; ++i )
69  {
70  const typename MacroData::ElementId &id = macroData_.element( i );
71  for( int j = 0; j <= dimension; ++j )
72  vertices[ j ] = id[ j ];
73  typedef typename GenericGeometry::SimplexTopology< dimension >::type Topology;
74  factory.insertElement( GeometryType( Topology() ), vertices );
75  }
76 
77  // release ALBERTA macro data
78  macroData_.release();
79  }
80 
81  void readGrid ( const std::string &filename, GridFactory &factory )
82  {
83  readGrid< ascii >( filename, factory );
84  }
85  };
86 
87 }
88 
89 #endif // #if HAVE_ALBERTA
90 
91 #endif
AlbertaReader()
Definition: albertareader.hh:43
static const int dimWorld
Definition: misc.hh:43
Grid::ctype ctype
Definition: albertareader.hh:26
void readGrid(const std::string &fileName, GridFactory &factory)
Definition: albertareader.hh:47
Definition: grapedataioformattypes.hh:16
Definition: grapedataioformattypes.hh:18
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Dune::GridFactory< Grid > GridFactory
Definition: albertareader.hh:24
void readGrid(const std::string &filename, GridFactory &factory)
Definition: albertareader.hh:81
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
Insert an element into the coarse grid.
Definition: common/gridfactory.hh:290
Provide a generic factory class for unstructured grids.
ALBERTA REAL_D GlobalVector
Definition: misc.hh:47
The dimension of the world the grid lives in.
Definition: common/grid.hh:406
int vertexCount() const
Definition: macrodata.hh:61
The dimension of the grid.
Definition: common/grid.hh:400
Definition: albertareader.hh:19
provides a wrapper for ALBERTA's macro_data structure
ElementId & element(int i) const
Definition: macrodata.hh:243
void read(const std::string &filename, bool binary=false)
Definition: macrodata.hh:447
ct ctype
Define type used for coordinates in grid module.
Definition: common/grid.hh:546
GlobalVector & vertex(int i) const
Definition: macrodata.hh:252
Different resources needed by all grid implementations.
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: common/gridfactory.hh:279
static const int dimension
Definition: albertareader.hh:28
int ElementId[numVertices]
Definition: macrodata.hh:46
void release()
release the macro data structure
Definition: macrodata.hh:125
static const int dimensionworld
Definition: albertareader.hh:29
int elementCount() const
Definition: macrodata.hh:66