Note
Go to the end to download the full example code.
Conversion#
The mymesh.converter module contains many functions to convert between different types of meshes.
This example will highlight a few of them.
We’ll start with a volumetric sphere mesh, that begins as a mix of hexahedra, tetrahedra, pyramids, and wedges. Most of the sphere is made of hexahedra (gray), the core is made up of pyramids (orange), and the central axis is made up of wedges (blue), except in the core where there are a few small tetrahedra (green).
from mymesh import converter, primitives, mesh
sphere = primitives.Sphere([0,0,0], 1, Type='vol')
sphere.ElemData['Element Type'] = [len(elem) for elem in sphere.NodeConn]
sphere.verbose = False
sphere.Clip().plot(scalars='Element Type', show_edges=True, view='trimetric', color='Accent', show_colorbar=False)
print(sphere.ElemType)

RFBOutputContext()
['hex', 'tet', 'pyr', 'wdg']
Note
Most functions in converter take as inputs NodeCoords,
NodeConn and return updated versions of both.
NewCoords, NewConn = converter.solid2tets(NodeCoords, NodeConn)
NewMesh = mesh(NewCoords, NewConn)
can be simplified as
NewMesh = mesh(*converter.solid2tets(NodeCoords, NodeConn))
Element Type#
This mixed-element mesh can be converted to a purely tetrahedral mesh with
solid2tets().
Mixed-element surface meshes can be similarly converted to triangular meshes
with surf2tris().
tet_sphere = mesh(*converter.solid2tets(sphere.NodeCoords, sphere.NodeConn), verbose=False)
print(tet_sphere.ElemType)
['tet']
Mesh Type#
This mixed-element mesh can be converted to a purely tetrahedral mesh with
solid2surface().
surf_sphere = mesh(sphere.NodeCoords, converter.solid2surface(sphere.NodeCoords, sphere.NodeConn), verbose=False)
print(surf_sphere.ElemType)
['tri', 'quad']
Or equivalently, the Surface property can be used
surf_sphere = sphere.Surface
print(surf_sphere.ElemType)
['tri', 'quad']
Element Order#
Most meshes and functions in mymesh use first-order (or “linear”)
elements (e.g. 4 node tetrahedra, 8 node hexahedra) by default, but for some
types of simulations, such as finite element methods, second-order (or
“quadratic”) elements (e.g. 10 node tetrahedra, 20 node hexahedra) are
sometimes preferable for improved accuracy in simulations.
This conversion can be achieved with linear2quadratic().
See also Element Types.
quadratic_sphere = mesh(*converter.linear2quadratic(sphere.NodeCoords, sphere.NodeConn), verbose=False)
print(quadratic_sphere.ElemType)
['tet10', 'hex20', 'pyr13', 'wdg15']
The reverse operation can be performed with quadratic2linear().
This function removes the excess nodes from the node connectivity, but keeps
them in NodeCoords, so any data associate with the nodes will still
match with the mesh.
To remove the excess nodes, you can use cleanup() or
mymesh.utils.RemoveNodes().
linear_sphere = mesh(*converter.quadratic2linear(quadratic_sphere.NodeCoords, quadratic_sphere.NodeConn), verbose=False)
print(linear_sphere.ElemType)
['hex', 'tet', 'pyr', 'wdg']
Total running time of the script: (0 minutes 0.234 seconds)