dune-grid  3.0-git
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 
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  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  void readGrid ( const std::string &fileName, GridFactory &factory )
45  {
46  // read ALBERTA macro triangulation
47  macroData_.read( fileName, false );
48 
49  // insert all vertices into the factory
50  const int numVertices = macroData_.vertexCount();
51  for( int i = 0; i < numVertices; ++i )
52  {
53  FieldVector< ctype, dimensionworld > v;
54  const Alberta::GlobalVector &coords = macroData_.vertex( i );
55  for( int j = 0; j < dimensionworld; ++j )
56  v[ j ] = coords[ j ];
57  factory.insertVertex( v );
58  }
59 
60  // insert all elements into the factory
61  std::vector< unsigned int > vertices( dimension+1 );
62  const int numElements = macroData_.elementCount();
63  for( int i = 0; i < numElements; ++i )
64  {
65  const typename MacroData::ElementId &id = macroData_.element( i );
66  for( int j = 0; j <= dimension; ++j )
67  vertices[ j ] = id[ j ];
68  typedef typename GenericGeometry::SimplexTopology< dimension >::type Topology;
69  factory.insertElement( GeometryType( Topology() ), vertices );
70  }
71 
72  // release ALBERTA macro data
73  macroData_.release();
74  }
75  };
76 
77 }
78 
79 #endif // #if HAVE_ALBERTA
80 
81 #endif
Dune::GridFactory::insertVertex
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: common/gridfactory.hh:279
grid.hh
Different resources needed by all grid implementations.
gridfactory.hh
Provide a generic factory class for unstructured grids.
macrodata.hh
provides a wrapper for ALBERTA's macro_data structure
Dune::GridFactory< Grid >
Dune::Alberta::MacroData::element
ElementId & element(int i) const
Definition: macrodata.hh:243
Dune
Include standard header files.
Definition: agrid.hh:59
Dune::Alberta::MacroData::elementCount
int elementCount() const
Definition: macrodata.hh:66
Dune::VTK::GeometryType
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Dune::AlbertaReader::dimension
static const int dimension
Definition: albertareader.hh:26
Dune::Alberta::MacroData::vertex
GlobalVector & vertex(int i) const
Definition: macrodata.hh:252
Dune::Alberta::MacroData::read
void read(const std::string &filename, bool binary=false)
Definition: macrodata.hh:410
Dune::Grid::ctype
ct ctype
Define type used for coordinates in grid module.
Definition: common/grid.hh:522
Dune::AlbertaReader
Definition: albertareader.hh:17
Dune::Alberta::MacroData< dimension >
Dune::Grid::dimension
The dimension of the grid.
Definition: common/grid.hh:387
Dune::Alberta::dimWorld
static const int dimWorld
Definition: misc.hh:43
Dune::Alberta::MacroData< dimension >::ElementId
int ElementId[numVertices]
Definition: macrodata.hh:46
Dune::AlbertaReader::readGrid
void readGrid(const std::string &fileName, GridFactory &factory)
Definition: albertareader.hh:44
Dune::Alberta::MacroData::release
void release()
release the macro data structure
Definition: macrodata.hh:125
Dune::AlbertaReader::GridFactory
Dune::GridFactory< Grid > GridFactory
Definition: albertareader.hh:22
Dune::Grid::dimensionworld
The dimension of the world the grid lives in.
Definition: common/grid.hh:393
Dune::GridFactory::insertElement
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
Insert an element into the coarse grid.
Definition: common/gridfactory.hh:290
Dune::Alberta::GlobalVector
ALBERTA REAL_D GlobalVector
Definition: misc.hh:47
Dune::AlbertaReader::ctype
Grid::ctype ctype
Definition: albertareader.hh:24
Dune::AlbertaReader::dimensionworld
static const int dimensionworld
Definition: albertareader.hh:27
Dune::Alberta::MacroData::vertexCount
int vertexCount() const
Definition: macrodata.hh:61
Dune::AlbertaReader::AlbertaReader
AlbertaReader()
Definition: albertareader.hh:41