Mesher

class pyccx.mesh.Mesher(modelName)

Bases: object

The Mesher class provides the base interface built upon the GMSH-SDK API operations. It provides the capability to mesh multiple objects

Attributes Summary

EPSILON

Minimum tolerance used for truncating nodal coordinate values

ElementOrder

Initialised

NumThreads

OptimiseNetgen

Units

edges

The ids for all edge geometry in the model

meshAssignments

name

The name of the GMSH model

physicalGroups

The physical groups tags available in the model

points

The ids for all point geometry in the model

surfaces

The geometric entity ids for all surface geometry in the model

version

Version of the GMSH SDK available

volumes

The geometric elementary ids for all volume geometry in the model

Methods Summary

addGeometry(filename, name[, meshFactor])

Adds CAD geometry into the GMSH kernel.

boundingBox()

Returns the bounding box of the model

clearMesh()

Clears any meshes previously generated by GMSH

clearMeshAssignments([elType])

Clears the mesh assignments for the model

clearPhysicalGroups([dimension])

Clears all physical groups in the model :type dimension: Optional[int] :param dimension: Integer is the dimension of the physical group to clear.

finalize()

generateMesh([generate3DMesh])

Initialises the GMSH Meshing Procedure

getAllPhysicalGroupElements()

getChildrenFromEntities(id)

From a Entity, obtain all children associated with this volume - note may include shared entities.

getElementIds([entityId, merge])

Returns the elements for the entire model or optionally a specific entity.

getElementTypes()

getElements([entityId])

Returns the elements for the entire model or optionally a specific entity.

getElementsByPhysicalGroups(physicalGroup)

Returns all elements associated with a physical group

getElementsByType(elType[, elTag, returnElIds])

Returns all elements of type (elType) from the GMSH model, within class ElementTypes.

getEntityName(id)

Returns the name of an entity given an id (if assigned) :type id: Tuple[int, int] :param id: Dimension, Entity Id

getFacesFromId(surfIds)

getGeomBoundingBoxById(tagId)

Returns the bounding box of the geometry (volume) by id

getGeomBoundingBoxByName(volumeName)

getIdByEdgeName(edgeName)

Obtains the ID for the edge name

getIdByEntityName(entityName)

Obtains the ID for volume name

getIdBySurfaceName(surfaceName)

Obtains the elemental id for the surface name

getIdByVolumeName(volumeName)

Obtains the ID for volume name

getNodeIds()

Returns the nodal ids from the entire GMSH model :rtype: array :return:

getNodes()

Returns the nodal coordinates from the entire GMSH model.

getNodesByEntityName(entityName)

Returns all nodes for a selected surface region

getNodesFromEdgeByName(edgeName)

Returns all nodes from a geometric edge

getNodesFromEntity(entityId)

Returns all node ids from a selected entity in the GMSH model.

getNodesFromSurfaceByName(surfaceRegionName)

Returns all nodes for a selected surface region

getNodesFromVolumeByName(volumeName)

Returns all node ids from a selected volume domain in the GMSH model.

getNodesInBoundingBox(minX, minY, minZ, ...)

Returns all nodes within a bounding box

getNumThreads()

Gets the number of threads used for parallel processing by GMSH

getNumberElements([physicalGroupsOnly])

The number of elements in the mesh

getPointsFromEntity(id)

From an Id, obtain all Point Ids associated with this volume - note may include shared points.

getPointsFromVolume(id)

From a Volume Id, obtain all Point Ids associated with this volume - note may include shared points.

getPointsFromVolumeByName(volumeName)

Returns all geometric points from a given volume domain by its name (if assigned) :type volumeName: str :param volumeName: volumeName :return:

getSurfaceFacesFromRegion(regionName)

getSurfaceFacesFromSurfId(surfTagId)

getSurfacesFromVolume(id)

From a Volume Id, obtain all Surface Ids associated with this volume - note may include shared boundary surfaces.

getVolumeName(volId)

Gets the volume name (if assigned)

identifyUnassignedElements()

Returns the list of elements that have not been assigned element types

initialise()

Initialises the GMSH runtime and sets default options.

interpTri(triInd)

isDirty()

Has the model been successfully generated and no pending modifications exist.

isMeshGenerated()

Returns 'True' if the mesh has been successfully internally generated by GMSH

maxPhysicalGroupId(dim)

Returns the highest physical group id in the GMSH model

mergeGeometry()

Geometry is merged/fused together.

open(filename)

Opens a GMSH file and loads the geometry into the current modelling instance

recombineMesh()

Recombines the surface mesh - between triangles and quadrilaterals using the specified recombination algorithm.

removeEdgeMeshes()

Removes edges (1D mesh entities) from the GMSH model

removeSurfaceMeshes()

Removes surface meshes (2D mesh entities) from the GMSH model

renumberElements()

Renumbers the elements of the entire GMSH Model

renumberNodes()

Renumbers the nodes of the entire GMSH Model

set2DMeshingAlgorithm(meshingAlgorithm)

Sets the 2D meshing algorithm to use by GMSH for the model

set3DMeshingAlgorithm(meshingAlgorithm)

Sets the 3D meshing algorithm to use by GMSH for the model

setAsCurrentModel()

Sets the current model to that specified in the class instance because Only one instance of GMSH sdk is available so this must be dynamically switched between models for multiple instances of a Mesher.

setEdgePhysicalName(edgeId, name)

Sets the Physcal Group Name of the Curve(s)

setEdgeSet(grpTag, edgeName)

setElementOrder(elOrder)

Sets the element order globally for the entire model.

setEntityName(id, name)

Set the geometrical entity name - useful only as reference when viewing in the GMSH GUI

setEntityPhysicalName(id, name)

Sets the geometric name of the volume id

setMeshAssignmentsById(elIds, elType)

Set the element type and concatenate elements to this

setMeshAssignmentsByType(elIds, elType)

Set the element type and concatenate elements to this

setMeshSize(pnts, size)

Sets the mesh element size along an entity, however, this can only currently be performed by the assignment of the sizes onto point ids.

setMeshSizeFactor(meshSizeFactor)

The mesh factor size provides an estimate length for the initial element sizes based on proportion of the maximum bounding box length.

setModelChanged([state])

Any changes to GMSH model should call this to prevent inconsistency in a generated model

setNumThreads(numThreads)

Sets the number of threads to be used for parallel processing by GMSH

setOptimiseNetgen(state)

Sets an option for GMSH to internally use Netgen to optimise the element quality of the generated mesh.

setRecombinationAlgorithm(recombinationAlgorithm)

Sets the recombination algorithm to use by GMSH for the model

setRecombineSurfaces(surfId[, angle])

Set a constraints on the surface mesh (triangles) to be recombined to quadrilaterals based on the angle

setSurfacePhysicalName(surfId, name)

Sets the Physical Group Name of the Surfaces(s)

setSurfaceSet(grpTag, surfName)

Generates a surface set based on the geometric surface name.

setUnits(unitVal)

setVolumePhysicalName(volId, name)

Sets the Physical Group Name of the Volumes(s)

showGui()

Opens up the native GMSH Gui to inspect the geometry in the model and the mesh.

writeMesh(filename)

Writes the generated mesh to the file

writeMeshInput()

Generates the current mesh format as an abaqus (Calculix) .inp representation format

Attributes Documentation

EPSILON: float = 1e-10

Minimum tolerance used for truncating nodal coordinate values

ElementOrder: int = 1
Initialised: bool = False
NumThreads: int = 4
OptimiseNetgen: bool = True
Units: str = ''
edges

The ids for all edge geometry in the model

meshAssignments
name

The name of the GMSH model

physicalGroups

The physical groups tags available in the model

points

The ids for all point geometry in the model

surfaces

The geometric entity ids for all surface geometry in the model

version

Version of the GMSH SDK available

volumes

The geometric elementary ids for all volume geometry in the model

Methods Documentation

addGeometry(filename, name, meshFactor=0.03)

Adds CAD geometry into the GMSH kernel. The filename of compatible model files along with the mesh factor should be used to specify a target mesh size.

Parameters:
  • filename (str)

  • name (str) – Name to assign to the geometries imported

  • meshFactor (Optional[float]) – Initialise the target element size to a proportion of the average bounding box dimensions

boundingBox()

Returns the bounding box of the model

Return type:

ndarray

Returns:

The bounding box of the GMSH Model

clearMesh()

Clears any meshes previously generated by GMSH

Return type:

None

clearMeshAssignments(elType=None)

Clears the mesh assignments for the model

Parameters:

elType – The element type to clear the assignments

Return type:

None

clearPhysicalGroups(dimension=None)

Clears all physical groups in the model :type dimension: Optional[int] :param dimension: Integer is the dimension of the physical group to clear. Default is None.

classmethod finalize()
Return type:

None

generateMesh(generate3DMesh=True)

Initialises the GMSH Meshing Procedure

Parameters:

generate3DMesh – Generates the 3D Mesh -

Return type:

None

getAllPhysicalGroupElements()
getChildrenFromEntities(id)

From a Entity, obtain all children associated with this volume - note may include shared entities.

Parameters:

id (Tuple[int, int]) – Dimension, Entity Id

Return type:

List[int]

Returns:

List of Ids

getElementIds(entityId=None, merge=True)

Returns the elements for the entire model or optionally a specific entity.

Parameters:
  • entityId (Optional[Tuple[int, int]]) – The entity id to obtain elements for

  • merge (Optional[bool]) – Merge the element ids into a single array

Returns:

A Tuple of element types, element ids and corresponding node ids

getElementTypes()
getElements(entityId=None)

Returns the elements for the entire model or optionally a specific entity.

Parameters:

entityId (Optional[Tuple[int, int]]) – The entity id to obtain elements for

Returns:

A Tuple of element types, element ids and corresponding node ids

getElementsByPhysicalGroups(physicalGroup)

Returns all elements associated with a physical group

Parameters:

physicalGroup – The physical group id

Return type:

ndarray

Returns:

The element ids associated with the physical groups

getElementsByType(elType, elTag=None, returnElIds=False)

Returns all elements of type (elType) from the GMSH model, within class ElementTypes. Note: the element ids are returned with an index starting from 1 - internally GMSH uses an index starting from 1, like most FEA pre-processors

Parameters:
  • elType (BaseElementType) – Element type

  • elTag (Optional[Tuple[int, int]]) – Optional list of element tags to filter the element types from

  • returnElIds (Optional[bool]) – ‘True’ returns the element ids along with the elements

Return type:

Union[Tuple[ndarray, ndarray], ndarray]

Returns:

List of element Ids

Raises:

Exception – If the mesh is not generated

getEntityName(id)

Returns the name of an entity given an id (if assigned) :type id: Tuple[int, int] :param id: Dimension, Entity Id

Return type:

str

getFacesFromId(surfIds)
getGeomBoundingBoxById(tagId)

Returns the bounding box of the geometry (volume) by id

Parameters:

tagId (int) – The geometry id

Return type:

ndarray

Returns:

The bounding box of the GMSH Model

getGeomBoundingBoxByName(volumeName)
getIdByEdgeName(edgeName)

Obtains the ID for the edge name

Parameters:

edgeName (str) – Geometric edge name

Return type:

int

Returns:

Edge ID

getIdByEntityName(entityName)

Obtains the ID for volume name

Parameters:

entityName (str) – str

Return type:

int

Returns:

int: Volume ID

getIdBySurfaceName(surfaceName)

Obtains the elemental id for the surface name

Parameters:

surfaceName (str) – Geometric surface name

Return type:

int

Returns:

Surface Ids

getIdByVolumeName(volumeName)

Obtains the ID for volume name

Parameters:

volumeName (str) – str

Return type:

int

Returns:

int: Volume ID

getNodeIds()

Returns the nodal ids from the entire GMSH model :rtype: array :return:

getNodes()

Returns the nodal coordinates from the entire GMSH model. These are sorted automatically by the node-id

Return type:

ndarray

Returns:

The nodal coordinates to the corresponding node ids

Raises:

Exception – If the mesh is not generated

getNodesByEntityName(entityName)

Returns all nodes for a selected surface region

Parameters:

entityName (str) – The geometric surface name

Return type:

array

Returns:

The list of node ids associated with the selected entity id

getNodesFromEdgeByName(edgeName)

Returns all nodes from a geometric edge

Parameters:

edgeName (str) – The geometric edge name

Returns:

The list of node ids associated with the selected entity id

getNodesFromEntity(entityId)

Returns all node ids from a selected entity in the GMSH model.

Parameters:

entityId (Tuple[int, int]) – The selected geometric entity id

Return type:

array

Returns:

The node ids for the selected entity

getNodesFromSurfaceByName(surfaceRegionName)

Returns all nodes for a selected surface region

Parameters:

surfaceRegionName (str) – The geometric surface name

Returns:

The list of node ids associated with the selected entity id

getNodesFromVolumeByName(volumeName)

Returns all node ids from a selected volume domain in the GMSH model.

Parameters:

volumeName (str) – Volume name

Return type:

array

Returns:

The list of node ids associated with the selected entity id

getNodesInBoundingBox(minX, minY, minZ, maxX, maxY, maxZ)

Returns all nodes within a bounding box

Parameters:
  • minX (int) – Minimum X

  • minY (int) – Minimum Y

  • minZ (int) – Minimum Z

  • maxX (int) – Maximum X

  • maxY (int) – Maximum Y

  • maxZ (int) – Maximum Z

Return type:

array

Returns:

The node ids within the bounding box

classmethod getNumThreads()

Gets the number of threads used for parallel processing by GMSH

Return type:

int

getNumberElements(physicalGroupsOnly=True)

The number of elements in the mesh

Parameters:

physicalGroupsOnly – If True` mesh number consists only physical grups - default is True

Returns:

getPointsFromEntity(id)

From an Id, obtain all Point Ids associated with this volume - note may include shared points.

Parameters:

id (Tuple[int, int]) – Dimension and Entity ID

Return type:

List[int]

Returns:

List of Point Ids

getPointsFromVolume(id)

From a Volume Id, obtain all Point Ids associated with this volume - note may include shared points.

Parameters:

id (int) – Volume ID

Return type:

List[int]

Returns:

list(int) - List of Point Ids

getPointsFromVolumeByName(volumeName)

Returns all geometric points from a given volume domain by its name (if assigned) :type volumeName: str :param volumeName: volumeName :return:

getSurfaceFacesFromRegion(regionName)
getSurfaceFacesFromSurfId(surfTagId)
getSurfacesFromVolume(id)

From a Volume Id, obtain all Surface Ids associated with this volume - note may include shared boundary surfaces.

Parameters:

id (int) – Volume Id

Return type:

List[int]

Returns:

List of surface Ids

getVolumeName(volId)

Gets the volume name (if assigned)

Parameters:

volId (int) – int: Volume id of a region

Return type:

str

identifyUnassignedElements()

Returns the list of elements that have not been assigned element types

Return type:

array

Returns:

List of elements that have no element type designated

classmethod initialise()

Initialises the GMSH runtime and sets default options. This is called automatically once.

Return type:

None

interpTri(triInd)
isDirty()

Has the model been successfully generated and no pending modifications exist.

Return type:

bool

isMeshGenerated()

Returns ‘True’ if the mesh has been successfully internally generated by GMSH

Return type:

bool

maxPhysicalGroupId(dim)

Returns the highest physical group id in the GMSH model

Parameters:

dim (int) – int: The chosen dimension

Return type:

int

Returns:

int: The highest group id used for the chosen dimension

mergeGeometry()

Geometry is merged/fused together. Coincident surfaces and points are automatically merged together, which enables a coherent mesh to be generated when these align exactly.

Return type:

None

open(filename)

Opens a GMSH file and loads the geometry into the current modelling instance

Parameters:

filename (str) – The filename of the GMSH file

Return type:

None

recombineMesh()

Recombines the surface mesh - between triangles and quadrilaterals using the specified recombination algorithm.

removeEdgeMeshes()

Removes edges (1D mesh entities) from the GMSH model

Return type:

None

removeSurfaceMeshes()

Removes surface meshes (2D mesh entities) from the GMSH model

renumberElements()

Renumbers the elements of the entire GMSH Model

Return type:

None

renumberNodes()

Renumbers the nodes of the entire GMSH Model

Return type:

None

set2DMeshingAlgorithm(meshingAlgorithm)

Sets the 2D meshing algorithm to use by GMSH for the model

Parameters:

meshingAlgorithm (MeshingAlgorithm2D) – The selected 2D Meshing Algorithm used

Return type:

None

set3DMeshingAlgorithm(meshingAlgorithm)

Sets the 3D meshing algorithm to use by GMSH for the model

Parameters:

meshingAlgorithm (MeshingAlgorithm3D) – The selected 3D Meshing Algorithm used

Return type:

None

setAsCurrentModel()

Sets the current model to that specified in the class instance because Only one instance of GMSH sdk is available so this must be dynamically switched between models for multiple instances of a Mesher.

Return type:

None

setEdgePhysicalName(edgeId, name)

Sets the Physcal Group Name of the Curve(s)

Parameters:
  • surfId – The set of curve ids

  • name (str) – Name assigned to volume

Return type:

int

setEdgeSet(grpTag, edgeName)
Return type:

None

classmethod setElementOrder(elOrder)

Sets the element order globally for the entire model. Note that different element orders cannot be used within the same GMSH model during generation

Parameters:

elOrder (int) – The element order

Return type:

None

setEntityName(id, name)

Set the geometrical entity name - useful only as reference when viewing in the GMSH GUI

Parameters:
  • id (Tuple[int, int]) – Entity Dimension and Entity Id

  • name (str) – The entity name

Return type:

None

setEntityPhysicalName(id, name)

Sets the geometric name of the volume id

Parameters:
  • id (Tuple[int, int]) – Dimension, Entity id tuple(int, int):

  • name (str) – str: Name assigned to entity

Return type:

int

setMeshAssignmentsById(elIds, elType)

Set the element type and concatenate elements to this

Parameters:
  • elType (BaseElementType)

  • el

Return type:

None

Returns:

setMeshAssignmentsByType(elIds, elType)

Set the element type and concatenate elements to this

Parameters:
  • elType (BaseElementType)

  • el

Return type:

None

Returns:

setMeshSize(pnts, size)

Sets the mesh element size along an entity, however, this can only currently be performed by the assignment of the sizes onto point ids.

Parameters:
  • pnts (List[int]) – Point ids to set the mesh size

  • size (float) – Set the desired mesh length size at this point

Return type:

None

classmethod setMeshSizeFactor(meshSizeFactor)

The mesh factor size provides an estimate length for the initial element sizes based on proportion of the maximum bounding box length.

Parameters:

meshSizeFactor (float) – The mesh factor size between [0.,1.0]

Return type:

None

setModelChanged(state=False)

Any changes to GMSH model should call this to prevent inconsistency in a generated model

Parameters:

state (Optional[bool]) – Force the model to be shown as generated

Return type:

None

classmethod setNumThreads(numThreads)

Sets the number of threads to be used for parallel processing by GMSH

Parameters:

numThreads (int)

Return type:

None

classmethod setOptimiseNetgen(state)

Sets an option for GMSH to internally use Netgen to optimise the element quality of the generated mesh. Enabled by default.

Parameters:

state (bool) – Toggles the option

Return type:

None

setRecombinationAlgorithm(recombinationAlgorithm)

Sets the recombination algorithm to use by GMSH for the model

Parameters:

recombinationAlgorithm (RecombinationAlgorithm) – The selected recombination algorithm for use

Return type:

None

setRecombineSurfaces(surfId, angle=45)

Set a constraints on the surface mesh (triangles) to be recombined to quadrilaterals based on the angle

Parameters:
  • surfId – The surface identity

  • angle – The angle in degrees for recombination

setSurfacePhysicalName(surfId, name)

Sets the Physical Group Name of the Surfaces(s)

Parameters:
  • surfId (Any) – The set of surface ids

  • name (str) – Name assigned to volume

Return type:

int

setSurfaceSet(grpTag, surfName)

Generates a surface set based on the geometric surface name. GMSH creates an associative surface mesh, which will later be automatically removed.

Parameters:
  • grpTag (int) – int: A unique Geometric Id used to associate the surface set as a physical group

  • surfName (str) – str: The surface name for the set

Return type:

None

Returns:

classmethod setUnits(unitVal)
Return type:

None

setVolumePhysicalName(volId, name)

Sets the Physical Group Name of the Volumes(s)

Parameters:
  • volId (Any) – The set of volume ids

  • name (str) – The name assigned to volume group

Return type:

int

classmethod showGui()

Opens up the native GMSH Gui to inspect the geometry in the model and the mesh. This will block the Python script until the GUI is exited.

writeMesh(filename)

Writes the generated mesh to the file

Parameters:

filename (str) – str - Filename (including the type) to save to.

Return type:

None

writeMeshInput()

Generates the current mesh format as an abaqus (Calculix) .inp representation format

Returns:

The mesh string format