How to dump a shell and export a mesh?¶
Commonly, we want to be able to use the objects we’ve created within other softwares. This how-to shows how to serialize a Shell
object for visualization in ParaView (dump
), scientific computation (e.g. with FEniCS; export_mesh
) and visualization with tiny-3d-engine
(export_geo
).
Dump a shell (dump
)¶
To dump a shell and its corresponding geometrical variables, just do:
shell.dump(filename)
If you have associated fields, you can also pass them, via a dict
. e.g:
my_fields = {'T': temperature}
shell.dump(filename, fields=my_fields)
Note
Each field must have the shape of the shell
instance.
Additionally, you can add the fields to the shell
object and they will be automatically dumped.
shell.fields['T'] = temperature
shell.dump(filename)
Dumps creates two files (xmf and h5). To open the xmf file in ParaView, use Xdmf Reader
.
Export a mesh (export_mesh
)¶
kokiy
relies on yamio
for mesh exporting. Therefore, you can export a mesh with any of the available formats in the package (basically everything available in meshio
and pyhip
). The extension of your file indicates the format to which export.
To export to hip
:
filename = 'shell.mesh.xmf'
shell.export_mesh(filename, elem_type='hexahedron')
This is an example output:
Warning
hip
cannot handle 3D objects that live in a 2D manifold (any Shell2D
). Therefore, you can only export volumetric objects with this format.
Note
Check out API Reference for all the available element types and yamio
for all the available file formats.
Export a simplified .geo
file (export_geo
)¶
tiny-3d-engine
is very neat for quick validations of the objects we’ve created (besides, it can be integrated in GUIs). To export a simplified .geo
mesh:
filename = 'shell.geo'
shell.export_geo(filename, show_all=False)
This is the corresponding output:
If show_all=True
, all the edges of the boundary surfaces are displayed.
Due to the limitations of tiny-3d-engine
(remember it is tiny!), sometimes it may be better to export a shell with less elements. The replicate
method is of great help here:
new_shape = (3, 6, 4)
new_shell = shell.replicate(new_shape)
new_shell.export_geo(filename, show_all=True)
Tip
Avoid reducing too much the shape of the shell, otherwise it will be unrecognizable (specially if it has a more complex shape).