pyvista_cad.from_gmsh

On this page

pyvista_cad.from_gmsh#

from_gmsh(model_name=None)[source]#

Pull the current gmsh model into a pyvista.UnstructuredGrid.

Parameters:
model_namestr, optional

Name of the gmsh model to read. When omitted, the current model is used.

Returns:
pyvista.UnstructuredGrid

Mesh from gmsh, with one cell per gmsh element. Element types outside _GMSH_TO_VTK are skipped with a warning.

Raises:
pyvista_cad.OptionalDependencyError

If gmsh is not installed.

Parameters:

model_name (str | None)

Return type:

UnstructuredGrid

Examples

Mesh a unit square in gmsh and pull it into PyVista (requires the [gmsh] extra):

>>> import gmsh
>>> from pyvista_cad import from_gmsh
>>> gmsh.initialize()
>>> gmsh.option.setNumber('General.Terminal', 0)
>>> _ = gmsh.model.add('demo')
>>> _ = gmsh.model.occ.addRectangle(0, 0, 0, 1, 1)
>>> gmsh.model.occ.synchronize()
>>> gmsh.model.mesh.generate(2)
>>> grid = from_gmsh()
>>> type(grid).__name__
'UnstructuredGrid'
>>> grid.n_cells > 0
True
>>> gmsh.finalize()