BasicTools.Containers.UnstructuredMeshInspectionTools module

BasicTools.Containers.UnstructuredMeshInspectionTools.CheckIntegrity(GUI=False)[source]
BasicTools.Containers.UnstructuredMeshInspectionTools.CheckIntegrity_ComputeMeshMinMaxLengthScale(GUI=False)[source]
BasicTools.Containers.UnstructuredMeshInspectionTools.CheckIntegrity_ComputeNodeToNodeConnectivity(GUI=False)[source]
BasicTools.Containers.UnstructuredMeshInspectionTools.CheckIntegrity_EnsureUniquenessElements(GUI=False)[source]
BasicTools.Containers.UnstructuredMeshInspectionTools.CheckIntegrity_ExtractElementByTags(GUI=False)[source]
BasicTools.Containers.UnstructuredMeshInspectionTools.CheckIntegrity_ExtractElementsByMask(GUI=False)[source]
BasicTools.Containers.UnstructuredMeshInspectionTools.CheckIntegrity_GetDataOverALine(GUI=False)[source]
BasicTools.Containers.UnstructuredMeshInspectionTools.CheckIntegrity_GetElementsFractionInside(GUI=False)[source]
BasicTools.Containers.UnstructuredMeshInspectionTools.CheckIntegrity_GetVolume(GUI=False)[source]
BasicTools.Containers.UnstructuredMeshInspectionTools.CheckIntegrity_MeshQualityAspectRatioBeta(GUI=False)[source]
BasicTools.Containers.UnstructuredMeshInspectionTools.ComputeElementToElementConnectivity(inmesh: UnstructuredMesh, dimensionality: int | None = None, connectivityDimension: int | None = None, maxNumConnections: int = 200) Tuple[ndarray, ndarray][source]

Generates the elements to element connectivity of an UnstructuredMesh in the following sense: an element is linked to another in the graph if they share:

  • a face if connectivityDimension = 2

  • an edge if connectivityDimension = 1

  • a vertex if connectivityDimension = 0

(if connectivityDimension is initialized to None, it will be set to dimensionality - 1)

Also provides the array of number of connection per cell.

Parameters:
  • inmesh (UnstructuredMesh) – the input mesh

  • dimensionality (int, optional) – dimensionality filter, by default inmesh.GetDimensionality()

  • connectivityDimension (int, optional) – type of connectivity, by default dimensionality - 1

  • maxNumConnections (int, optional) – the number of potential connection to a single node, normally 200 is more than enough, by default 200

Returns:

numpy.ndarray, (nb elements, max nb connections) item, the connections for each element -> element numpy.array, the number of connections per elements

Return type:

Tuple

BasicTools.Containers.UnstructuredMeshInspectionTools.ComputeMeshDensityAtNodes(mesh: UnstructuredMesh) ndarray[source]

Function to compute the mesh size at each point This is done using the length of the bars of each element and averaging the data at nodes. All the element are treated, even the lower dimensionality element (not the 0D elements of course). This means the triangles in the surface can affect the values of the nodes on the surface No weighting is done.

Parameters:

mesh (UnstructuredMesh) – The input mesh

Returns:

a numpy array (node field) with average of the mesh size at each point

Return type:

np.ndarray

BasicTools.Containers.UnstructuredMeshInspectionTools.ComputeMeshMinMaxLengthScale(mesh) Tuple[float64, float64][source]

Compute a estimation of the minimal and maximal length scale of the elements for this we compute the centroid of the element and compute the min and max distance between the centroid and each node of the mesh. Then return a tuple with (2*min,2*max) of all the distances on the mesh

Parameters:

mesh (UnstructuredMesh) – The input mesh

Returns:

tuple with (2*min_dist,2*max_dist) for all the elements in the mesh

Return type:

Tuple[PBasicFloatType,PBasicFloatType]

BasicTools.Containers.UnstructuredMeshInspectionTools.ComputeNodeToElementConnectivity(inmesh: UnstructuredMesh, maxNumConnections: int = 200) Tuple[ndarray, ndarray][source]

Compute the node to connectivity connection for every point

Parameters:
  • inmesh (UnstructuredMesh) – the mesh

  • maxNumConnections (int, optional) – the number of potential connection to a single node, normally 200 is more than enough, by default 200

Returns:

numpy.ndarray, (nb point, max nb connections) item, the connectivity for each node -> element numpy.array, the number of connections per point

Return type:

Tuple

BasicTools.Containers.UnstructuredMeshInspectionTools.ComputeNodeToNodeConnectivity(inmesh: UnstructuredMesh, maxNumConnections=200) Tuple[ndarray, ndarray][source]

Compute the node to node connection for every node in the mesh

Parameters:
  • inmesh (UnstructuredMesh) – the mesh

  • maxNumConnections (int, optional) – the number of potential connection to a single node, normally 200 is more than enough, by default 200

Returns:

numpy.ndarray, (nb point, max nb connections) item, the connectivity for each node -> node numpy.array, the number of connections per point

Return type:

Tuple

BasicTools.Containers.UnstructuredMeshInspectionTools.EnsureUniquenessElements(mesh: UnstructuredMesh) None[source]

Ensure that every element if present only once on the mesh

Parameters:

mesh (UnstructuredMesh) – input mesh

Raises:

Exception – if 2 element (event if the connectivity is permuted) a exception is raised

BasicTools.Containers.UnstructuredMeshInspectionTools.ExtractElementByTags(inmesh: UnstructuredMesh, tagsToKeep: List[str], allNodes: bool = False, dimensionalityFilter: int | None = None, cleanLonelyNodes: bool = True) UnstructuredMesh[source]

Extract element by tags. create a new UnstructuredMesh with element present in the tags

Parameters:
  • inmesh (UnstructuredMesh) – the input mesh

  • tagsToKeep (List[str]) – List of Tag name to extract element can contain tag name for nodes tags

  • allNodes (bool, optional) – if tagsToKeep point to a node tags then this option controls if all the nodes of the element must be in the tag to select the element , by default False

  • dimensionalityFilter (int, optional) – keep all the element of dimensionality dimensionalityFilter, by default None

  • cleanLonelyNodes (bool, optional) – true to apply a after the extraction, by default True

Returns:

a new UnstructuredMesh with the extracted elements (the tags are updated)

Return type:

UnstructuredMesh

BasicTools.Containers.UnstructuredMeshInspectionTools.ExtractElementsByElementFilter(inmesh: UnstructuredMesh, elementFilter: ElementFilter, copy: bool = True) UnstructuredMesh[source]

Create a new mesh with the selected element by elementFilter For the moment this function make a copy of nodes

Parameters:
  • inmesh (UnstructuredMesh) – the input mesh

  • elementFilter (ElementFilter) – the ElementFilter to select the element to extract

  • copy (bool) – if true this function will try to make reuse as mush as possible the memory of the input mesh. Warning!!! Making modification of one of the two meshes will potentially invalidate the other mesh

Returns:

the mesh with the extracted elements

Return type:

UnstructuredMesh

BasicTools.Containers.UnstructuredMeshInspectionTools.ExtractElementsByMask(inElementContainer: ElementsContainer, mask: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) ElementsContainer[source]

Create a new ElementContainer with the element selected by the mask

Parameters:
  • inelems (ElementsContainer) – _description_

  • mask (ArrayLike) – a vector of bool (a boolean mask) or a vector with the indices to extract

Returns:

a new container with the extracted elements (the tags are updated)

Return type:

ElementsContainer

BasicTools.Containers.UnstructuredMeshInspectionTools.GetDataOverALine(startPoint: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], stopPoint: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], nbPoints: int, mesh: UnstructuredMesh, fields: List, method: str | None = None) UnstructuredMesh[source]

Compute the values of a mesh/field over a line startPoint and stopPoint are used to construct a line with nbPoints points. the data in mesh.nodeFields, mesh.elemFields and fields are evaluated at every point of the line

Parameters:
  • startPoint (ArrayLike) – Start point. this is passed to the CreateUniformMeshOfBars function

  • stopPoint (ArrayLike) – Stop point. this is passed to the CreateUniformMeshOfBars function

  • nbPoints (int) – this argument is passed to the CreateUniformMeshOfBars function

  • mesh (UnstructuredMesh) – the mesh to extract mesh.nodeFields, mesh.elemFields

  • fields (List) – a list containing only FEFields

  • method (Optional[str], optional) – this argument is passed to the GetFieldTransferOp function, by default None

Returns:

a unstructured mesh with nodeFields populated with the data nodeFields with contain a dictionary for every field name and the numpy vector with the values at the points. If two or more fields have the same name only one is recovered, the priority order staring with the hightest priority are : fields, elemFields and nodeFields

Return type:

UnstructuredMesh

Raises:

Exception – In the case an IPField is present in the ‘fields’ argument

BasicTools.Containers.UnstructuredMeshInspectionTools.GetElementsFractionInside(field: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], points: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], name: str, elements: ElementsContainer, ids: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) ndarray[source]

Compute the volume fraction for each element in ids, based in the level-set field field. Function valid for simplices (bars, triangles, tetrahedrons)

Parameters:
  • field (ArrayLike) – the levelset field

  • points (ArrayLike) – the points of the mesh

  • name (str) – the element name

  • elements (ElementsContainer) – the element data

  • ids (ArrayLike) – the ids to treat

Returns:

the volume fraction for each element in ids

Return type:

np.ndarray

BasicTools.Containers.UnstructuredMeshInspectionTools.GetMeasure(inmesh: UnstructuredMesh, elementFilter: ElementFilter | None = None)[source]

Compute the measure of the mesh (volume in 3D, surface in 2D, …) Only elements of the higher dimensionality are taken into account if no element filter is supplied

Attention: if the element filter contain dimensionality mixed elements the result is the sum of the measure (volume + surface for example)

Parameters:
  • inmesh (UnstructuredMesh) – the mesh to use for the computation

  • elementFilter (ElementFilter) – element to take into account in the computation of the measure, if none all the element of the higher dimensionality are used.

Returns:

the volume if the mesh contains 3D elements the surface if the mesh contains 2D elements and no 3D elements the length if the mesh contains 1D elements and no 3D elements nor 2D elements

Return type:

PBasicFloatType

BasicTools.Containers.UnstructuredMeshInspectionTools.GetVolume(inmesh: UnstructuredMesh) float64[source]

Compute the volume of the mesh Only element of the bigger dimensionality are taken into account if no elements on mesh we return zero.

for a more general function see: GetMeasure

Parameters:

inmesh (UnstructuredMesh) – the mesh to use for the computation

Returns:

the volume if the mesh contains 3D elements the surface if the mesh contains 2D elements and no 3D elements the length if the mesh contains 1D elements and no 3D elements nor 2D elements

Return type:

PBasicFloatType

BasicTools.Containers.UnstructuredMeshInspectionTools.GetVolumePerElement(inmesh: UnstructuredMesh, elementFilter: ElementFilter | None = None) ndarray[source]

Compute the volume (surface for 2D element and length for 1D elements) for each element selected by the elementFilter

Parameters:
  • inmesh (UnstructuredMesh) – the mesh to extract elements

  • elementFilter (Optional[ElementFilter], optional) – filter to select some elements, if None the volume of all the element are computed

Returns:

a numpy array of size number of “element selected by the elementFilter” with the volume

Return type:

np.ndarray

BasicTools.Containers.UnstructuredMeshInspectionTools.MeshQualityAspectRatioBeta(mesh: UnstructuredMesh)[source]

experimental mesh quality only available for tets

Parameters:

mesh (UnstructuredMesh) – the input mesh

Raises:

Exception – raise if the quality is larger than 1000

BasicTools.Containers.UnstructuredMeshInspectionTools.PrintMeshInformation(mesh: UnstructuredMesh)[source]

Print mesh information to the screen

Parameters:

mesh (UnstructuredMesh) – the input mesh