In order to run a simulation one needs to start from an equilibrium but also we need to have a mesh for our Finite Elements.

The MHD equilibrium is obtained by solving the so-called Grad-Shafranov equation. In general, we use existing codes for this purpose such as Cedres++. Such solvers provide the magnetic flux which should be used to create a mesh that flux-aligned. For this purpose, we first need to compute the connected components of the magnetic flux.

Our strategy works for any reactor (WEST, ITER, TCV, …) and is almost automatic. It is based on the segmentation problem and the Morse Theory. Let us first recall some basic fact;

Let be a Morse function defined on . Then the topological set of the iso-contours of consists of finite connected components that are either:

- Circle cells which are homeomorphic to open disks
- Circle bands which are homeomorphic to open annulus
- Saddle connections

Solving the segmentation problem using the Reeb algorithm leads to the following decomposition, where we restrict the geometry to WEST wall.

From here, we construct flux-aligned meshes using a B-Spline representation on each block. As we can see, there are still some singularities (we are interested in meshes). The polar-like singularity has already been solved while the X-point one is still under development.

Another approach of constructing a mesh, when the geometry constraint is more important, is to give up on the alignment and use another alternative such as equidistribution. This work is still in progress and is based on an Optimal Mass Transportation problem, through the resolution of the Monge-Ampère equation. For example, if one has a *monitor function* as

Solving the Monge-Ampère equation will provide us with a** one-to-one** mapping for which the mesh will look like