dune-grid 2.10
|
A fundamental task in many finite element-type discretizations is iterating over the elements of a grid, for example in order to numerically compute integrals on it. All DUNE grids provide a unified interface for this and related operations.
First, we set up a simple structured grid. Here we use the Dune::YaspGrid class in four dimensions in order to demonstrate that even dimension larger than three can be used.
Grids in Dune are hierarchical, i.e. they are organized into levels (originating from refinement) and entities that are not further refined. Each of these subsets is accessible via Dune::GridView and iteration over is possible only over grid views. So we extract the Dune::LeafGridView:
Now we can iterate over all the entities of a certain codimension in a grid view using a range-based for loop:
As an example we extract the type of an element and test for it to be a cube.
Instead of specifying the codimension explicitly you can also use the following predefined names in the range-based for loop:
Finally, from entities of codimension 0 (aka elements) you can access all subentities of all codimensions using the following code:
Full example code: recipe-iterate-over-grid.cc