mesh.Mesh.convert#
- Mesh.convert(totype, fuse=None, remove_degenerate=True, verbose=False)#
Convert a Mesh to another element type.
Converting a Mesh from one element type to another can only be done if both element types are of the same dimensionality. Thus, 3D elements can only be converted to 3D elements.
Parameters#
- totype: str or ElementType
The name or type of the target element to which to convert. A generic type ‘linear’ may be specified to convert to the linear element type of the same family.
- fuse: bool, optional
If True, the resulting Mesh will be run through
fuse()before returning. If False, no fuse will be done. The default (None) is a smart mode: a fuse will be applied if new nodes were added during the conversion.- remove_degenerate: bool, default=True
Whether to remove degenerate elements (e.g. with 2 coinciding nodes) using the
remove_degenerate()before returning.- verbose: bool, optional
If True, intermediate steps during the conversion will be reported.
Returns#
- Mesh
A Mesh of the requested element type, representing the same geometry (possibly approximatively) as the original Mesh.
Raises#
- ValueError
If the Mesh can not be transformed to the specified eltype.
Notes#
The conversion uses two basic methods for converting the element type: split the elements in smaller parts and add new nodes to the elements. Adding new nodes may produce duplicate nodes at the common border of elements. Not using a final fuse operation will then likely produce unwanted results.
In many cases a conversion is done over one (or more) intermediary element types. The fuse operation is only done once, after all transformation steps have occurred.
If the user wants/needs to apply multiple conversions in sequence, he may opt to switch off the fusing for all but the last conversion.
Not all conversions between elements of the same dimensionality are possible. The possible conversion strategies are implemented in a table in
elements. New strategies may be added however.Important
To convert a volumetric mesh to a surface mesh, you first need to lower the Mesh dimension, e.g. by applying the method
border_mesh(). The resulting surface mesh can then be converted to the correct element type (e.g. tri3).Examples#
>>> M = Mesh(eltype='quad4').convert('tri3') >>> M.coords Coords([[0., 0., 0.], [1., 0., 0.], [1., 1., 0.], [0., 1., 0.]]) >>> M.elems Elems([[0, 1, 2], [2, 3, 0]]..., eltype=Tri3) >>> M = Mesh(eltype='quad4').subdivide(2).convert('tri3-r') >>> print(M.n_elems()) 8 >>> M = Mesh(eltype='quad12').convert('quad16') >>> print(M.n_coords()) 16