Skip to content

Grid info utilities

dune-grid provides helper utilities to print structural information about a grid.

Learning goals

After this page, you should be able to:

  • use Dune::gridinfo to inspect a grid quickly,
  • interpret basic level and codimension statistics,
  • connect gridinfo output to debugging and verification tasks.

Dune::gridinfo

A convenient entry point is:

#include <dune/grid/common/gridinfo.hh>

Dune::gridinfo(grid, "MyGrid");

This prints information such as:

  • dimension and world dimension,
  • numbers of entities by codimension,
  • level and leaf statistics,
  • selected geometry/index set details.

It is especially useful when:

  • debugging mesh import,
  • comparing refinement stages,
  • verifying assumptions before assembly.

Typical workflow

Use it right after grid construction or file input:

auto grid = Dune::GmshReader<Grid>::read("mesh.msh");
Dune::gridinfo(*grid, "ImportedMesh");
Runnable example: examples/04_grid_info/grid_info.cc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <array>
#include <iostream>

#include <dune/common/fvector.hh>
#include <dune/grid/common/gridinfo.hh>
#include <dune/grid/yaspgrid.hh>

int main()
{
  constexpr int dim = 2;
  Dune::FieldVector<double, dim> L(1.0);
  std::array<int, dim> N{4, 3};
  Dune::YaspGrid<dim> grid(L, N);

  auto level0 = grid.levelGridView(0);
  std::cout << "level 0 elements: " << level0.size(0) << "\n";

  grid.globalRefine(1);
  auto leaf = grid.leafGridView();
  std::cout << "leaf elements after refine: " << leaf.size(0) << "\n\n";

  Dune::gridinfo(grid, "YaspGrid Example");
  return 0;
}

Build and run:

source _env/activate.sh
cd examples/04_grid_info
dunecontrol --current all
./build/debug/example04

Output:

level 0 elements: 12
leaf elements after refine: 48

YaspGrid Example=> Dune::YaspGrid<2, Dune::EquidistantCoordinates<double, 2> > const (dim=2, dimworld=2)
YaspGrid Examplelevel 0 codim[0]=12 codim[1]=31 codim[2]=20
YaspGrid Examplelevel 1 codim[0]=48 codim[1]=110 codim[2]=63
YaspGrid Exampleleaf    codim[0]=48 codim[1]=110 codim[2]=63
YaspGrid Exampleleaf dim=2 types=((cube, 2)[0]=48,(simplex, 1)[1]=110,(simplex, 0)[2]=63)

Summary and next steps

You now have a lightweight diagnostic tool to verify grid structure and refinement state. For the broader context, return to Core modules or continue with Grid basics.