Muscat.MeshTools.MeshTools module

CheckIntegrity(GUI: bool = False)[source]
CheckIntegrity_ComputeElementDeterminant(GUI: bool = False)[source]
CheckIntegrity_ComputeSignedDistance(GUI: bool = False) → str[source]
CheckIntegrity_GenerateCompactedConnectivity(GUI: bool = False) → str[source]
CheckIntegrity_GetCellCenters(GUI: bool = False) → str[source]
CheckIntegrity_IsClose(GUI: bool = False)[source]
CheckIntegrity_TagsToRefs(GUI: bool = False) → str[source]
ComputeElementDeterminant(mesh: Mesh, elementFilter: object | None = None) → ndarray[source]

Compute the mapping determinant at the center of each selected element.

The determinant measures the local change of volume induced by the element mapping. Its sign depends on the element orientation, and a zero or negative value can indicate a degenerate or inverted element. For a linear element, the determinant is constant over the element. The returned values are ordered according to the element selections used by the integration operator.

Parameters:
  • mesh (Mesh) – Mesh whose element-mapping determinants are to be computed.

  • elementFilter (ElementFilter, optional) – Filter restricting the elements included in the result, by default None (only element of highest dimensionality).

Returns:

One determinant per mesh element. Elements excluded by elementFilter have a value of zero.

Return type:

np.ndarray

ComputeSignedDistance(mesh: Mesh, pos: ndarray) → ndarray[source]

Function to compute the signed distance

Parameters:
  • mesh (Mesh) – Mesh from which the signed distance field needs to be computed

  • pos (np.ndarray) – positions where to compute the signed distance

Returns:

signed distance field evaluated at pos

Return type:

np.ndarray

GenerateCompactedConnectivity(mesh: Mesh, elementFilter: FilterBase | FilterOperatorBase | None = None, pushConnectivityToMesh: bool = True) → Tuple[ndarray, ndarray, ndarray][source]

Generate compact connectivity arrays suitable for Pacman FE routines.

Parameters:
  • mesh (Mesh) – Input mesh containing the elements to compact.

  • elementFilter (Optional[FilterLike], optional) – Element filter selecting the elements to export. If None, all elements with the highest dimensionality are used. By default None.

  • pushConnectivityToMesh (bool, optional) – If True, replace selected element connectivity arrays by views into the compact connectivity buffer when possible. By default True.

Returns:

Connectivity values, connectivity offsets and Pacman cell type arrays.

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray]

Raises:

RuntimeError – If one of the selected element types is not supported by Pacman.

GetElementsCenters(mesh: Mesh | None = None, nodes: ArrayLike | None = None, elements: ElementsContainer | StructuredElementsContainer | None = None, dim: int | None = None) → ndarray[source]

Internal function to compute the element centers. Waring!!!! This function is used in the filters implementation no Filter can appear in this implementation

Parameters:
  • mesh (Mesh, optional) – If mesh is not none, the element center for all the element is calculated, by default None.

  • nodes (ArrayLike, optional) – If mesh is non, nodes and elements must be supplied to compute the element center only for the ElementContainer, by default None.

  • elements (ElementContainerLike, optional) – If mesh is non, nodes and elements must be supplied to compute the element center only for the ElementContainer, by default None.

  • dim (int, optional) – The dimensionality (int) to filter element to be treated, by default None.

Returns:

the center for each element

Return type:

np.ndarray

IsClose(mesh1: Mesh, mesh2: Mesh, sortFirst: bool = False) → bool[source]

Check whether two meshes contain equivalent data.

The meshes must have the same type and matching nodes, node tags, element types, element connectivities, element tags, node fields, and element fields. Numeric values are compared using numpy.isclose(); string and object fields are compared using equality.

If sortFirst is True, both meshes are first put into a canonical lexicographic ordering of their nodes and elements. This allows meshes with the same topology and data but different node or element orderings to compare as equivalent.

Parameters:
  • mesh1 (Mesh) – The first mesh to compare.

  • mesh2 (Mesh) – The second mesh to compare.

  • sortFirst (bool, optional) – Whether to lexicographically reorder both meshes before comparing them, by default False.

Returns:

True if the meshes are equivalent within the numeric comparison tolerance; otherwise False.

Return type:

bool

RefsToTags(mesh: Mesh, dictNodesRefsToTags: dict, dictElemRefsToTags: dict, prefix: str = 'new')[source]

Retrieve the mesh tags (strings) for nodes and elements.

The tags are retrieved from the elementFields and nodeFields “ref”, which are deleted after conversion to Tags. Needed for some mesh format as .mesh

Parameters:
  • mesh (a mesh with an element field and a node field named "ref")

  • dictNodesRefsToTags (a dictionnary giving for each reference number the) – corresponding node tags

  • dictElemRefsToTags (a dictionnary giving for each reference number the) – corresponding element tags

  • prefix (the prefix to add if new reference numbers have been created)

Returns:

mesh

Return type:

the mesh with the tags

TagsToRefs(mesh: Mesh)[source]

Convert node and element tags to one integer reference number.

Needed for some mesh format as .mesh

Parameters:

mesh (a mesh with tags)

Returns:

  • refByNode (a np.array giving at position i the reference number (int)) – for the node i in the mesh

  • dictNodesRefsToTags (a dictionnary giving for each reference number the) – corresponding node tags

  • refByElement (a np.array giving at position i the reference number (int)) – for the element i in the mesh

  • dictElemRefsToTags (a dictionnary giving for each reference number the) – corresponding element tags