DUNE PDELab (2.8)

Transforming a cartesian mesh

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:

\( y = F(x) : \Omega -> \hat \Omega. \)

First, let's set up a rectangular grid:

const unsigned int dim = 2;
std::array<int,dim> N ={64,32};
typedef Dune::YaspGrid<dim> SquareGrid;
SquareGrid sgrid(L,N);
vector space out of a tensor product of fields.
Definition: fvector.hh:95
[ provides Dune::Grid ]
Definition: yaspgrid.hh:160

Then, lets define a function that maps the grid to a new geometry:

template <int dim>
class GridTransformation
: public Dune :: AnalyticalCoordFunction< double, dim, dim, GridTransformation <dim> >{
typedef GridTransformation This;
typedef Dune :: AnalyticalCoordFunction< double, dim, dim, This > Base;
public:
typedef typename Base :: DomainVector DomainVector;
typedef typename Base :: RangeVector RangeVector;
GridTransformation(){}
void evaluate(const DomainVector &x, RangeVector &y) const{
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));
}
};
Dune namespace.
Definition: alignedallocator.hh:11

Finally, lets map our initial grid using the GridTransformation we defined:

typedef GridTransformation<dim> GridTransformation;
GridTransformation gTrafo;
Grid grid(sgrid,gTrafo);
grid wrapper replacing the geometries
Definition: grid.hh:84

Full example code: recipe-geometry-grid.cc

Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Mar 28, 23:30, 2024)