Tutorial 2: Free Form Deformation on a cylinder in iges file format

In this tutorial we will show the typical workflow. In particular we are going to parse the parameters file for the FFD, read an iges file of a cylinder, perform the FFD and write the results on a new iges file. We also provide the example of the show function which is not present in Tutorial 1.

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

In [1]:
from pygem import FFDParameters, FFD, IgesHandler

params = FFDParameters()

Now we have to load the iges file on which we will perform the FFD. Since it is an iges we use the IgesHandler class. The parse method extracts the control points (or poles) coordinate of the NURBS surfaces that represent each face of the iges geometry without touching the topology.

In [2]:
iges_handler = IgesHandler()
mesh_points = iges_handler.parse('../tests/test_datasets/test_pipe.iges')

We can now use the show method to visualize the iges geometry. It basically load the file and shows its geometry. It is different from the plot method since:

  • it shows directly the geometry and not its triangulation
  • it can not save the picture in a png file (it shows only)

Here you can see the result of'../tests/test_datasets/test_pipe.iges')

For some "backend" issues we can show only one shape for session. Be careful when you try to show many geometries in the same script.

Finally we can actually perform the FFD and then we can write the modified iges file with the new control points (or poles).

In [3]:
free_form = FFD(params, mesh_points)
new_mesh_points = free_form.modified_mesh_points

iges_handler.write(new_mesh_points, 'test_pipe_mod.iges')

Sometimes the write method can fail. In fact, in write function we perform some operations like

  • linking edges into a single wire;
  • trimming the surface with the wire.

Often, a CAD file has its own tolerance and some entities that seems to be, for instance, linked actually are not. The linking and trimming operations can be hard for the software to be performed, especially when the starting CAD has not been made for analysis but for design purposes. Thus, for non trivial geometries it could be necessary to increase the tolerance. For the cylinder this is not the case, but we can increse the tolerance as well and write a, indeed almost equal, result.

In [4]:
iges_handler.write(new_mesh_points, 'test_pipe_mod.iges', 1e-3)

And here we show the final shape:'test_pipe_mod.iges')