Using GeometryGrid, one can transform an existing mesh into a different shape. This is particularly useful for modelling complex geometries based on efficient structured grids like YaspGrid.
A grid transformation is a user-defined function which gives the transformation of a point x in the base cartesian grid to a final geometry:

First, let's set up a rectangular grid:
const unsigned int dim = 2;
Dune::FieldVector<double,dim> L = {4.0,2.0};
std::array<int,dim> N ={64,32};
typedef Dune::YaspGrid<dim> SquareGrid;
SquareGrid sgrid(L,N);
Then, lets define a function that maps the grid to a new geometry:
template <int dim>
:
public Dune :: AnalyticalCoordFunction< double, dim, dim, GridTransformation <dim> >{
typedef Dune :: AnalyticalCoordFunction< double, dim, dim, This > Base;
public:
y = x;
if(x[0] < 0.8)
y[1] = (1.0 + 5.0/4.0 * (sin(M_PI/18.0) - 1.0) * x[0]) * (x[1] - 1.0);
else
y[1] = sin((x[0] - 0.6)/3.6 * M_PI) * (x[1] - 1.0);
if(x[0] > 3.8)
y[0] += 0.5*(x[0] - 3.8) * (1.0 - pow(x[1] - 1.0, 2.0));
}
};
Finally, lets map our initial grid using the GridTransformation we defined:
typedef typename Dune::GeometryGrid<SquareGrid,GridTransformation> Grid;
Grid grid(sgrid,gTrafo);
Full example code: recipe-geometry-grid.cc