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;
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>
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));
}
};
Finally, lets map our initial grid using the GridTransformation we defined:
typedef GridTransformation<dim> GridTransformation;
GridTransformation gTrafo;
Grid grid(sgrid,gTrafo);
Full example code: recipe-geometry-grid.cc
|
Legal Statements / Impressum |
Hosted by TU Dresden |
generated with Hugo v0.111.3
(Dec 21, 23:30, 2024)