In this tutorial we show how to perform the Free Form Deformation on a hexaedral mesh of a cylinder. In particular, above what already seen in the previous tutorials, we give some information about how to set the desired continuity to the geometry we are morphing.

First of all we just import the required PyGeM classes and we read a parameters file.

In [1]:

```
from pygem import FFDParameters, FFD, UnvHandler
params = FFDParameters()
params.read_parameters(filename='../tests/test_datasets/parameters_test_ffd_pipe_unv_C0.prm')
```

The following is the parameters file for the case at hand. In particular, if you look at the Box info section, there is 2-by-2-by-3 lattice around a cylinder. Since we want to shift the middle section of the cylinder along the x direction we modify only the parameter x weights corresponding to the middle point in z direction (index==1). In the following we show only the important parts of the parameters file

In [2]:

```
%cat ../tests/test_datasets/parameters_test_ffd_pipe_unv_C0.prm
```

We now load the unv file!

In [3]:

```
unv_handler = UnvHandler()
mesh_points = unv_handler.parse('../tests/test_datasets/test_pipe.unv')
```

and visualize the undeformed mesh.

We now, as always, perform the FFD and write out the results in another unv file.

In [4]:

```
free_form = FFD(params, mesh_points)
free_form.perform()
new_mesh_points = free_form.modified_mesh_points
unv_handler.write(new_mesh_points, 'test_pipe_mod_C0.unv')
```

Let us see the result.

As you can easily see the deformation makes the mesh only C0 continuous.

This is not wrong a priori, but it can have some drawbacks.

First of all, if you start with a smooth geometry, probably you do not want to end up with a geometry with more edges.

For large deformations this can cause inaccurancy errors when you try to perform analysis on the deformed mesh. In fact, it can happen that we have very stretched cells that the solver can not treat properly. Of course it depends mainly on the solver choosen, but, in general, it is not very clever to have "spiky" cells.

Moreover, if you are interested in some quantities, such as grandients and normal vectors, it can be difficult to compute them close to the "artificial edges".

Thus, we can rely on the properties of the Bernstein polynomials (on which FFD is built upon) to overcome this potential problem. In fact, if we add 2 new control points in the z direction we can move only the middle one, leaving the first two and the last two still. The new parameter file becomes:

In [5]:

```
%cat ../tests/test_datasets/parameters_test_ffd_pipe_unv_C1.prm
```

We again load the new parameter file, perform the FFD and write out the results in another unv file.

In [6]:

```
params = FFDParameters()
params.read_parameters(filename='../tests/test_datasets/parameters_test_ffd_pipe_unv_C1.prm')
free_form = FFD(params, mesh_points)
free_form.perform()
new_mesh_points = free_form.modified_mesh_points
unv_handler.write(new_mesh_points, 'test_pipe_mod_C1.unv')
```

And here it is the C1 mesh on the cylinder.

You can add some other points to increase again the continuity of the mesh!