Muscat.Containers.MeshModificationTools module¶
- AddTagPerBody(inmesh: Mesh) ndarray [source]¶
Generate nodal tag (in the form of Body_+int) per body a body is defined by all the nodes connected by the elements (connectivity filter in vtk )
- Parameters:
inmesh (Mesh) – the input mesh
- Returns:
pointsPerBody : a vector with the number of point in every body. len(pointsPerBody) is the number of unconnected bodies in the mesh
- Return type:
np.ndarray
- Raises:
Exception – in the case of an internal error
- CleanDoubleElements(mesh: Mesh)[source]¶
Remove double elements on the mesh (inPlace), even if a permutation exists
Tags of duplicated elements are merged into a single element. Only element fields of the first element are kept.
- Parameters:
mesh (Mesh) – the input mesh
- CleanDoubleNodes(mesh: Mesh, tol: float64 | None = None, nodesToTestMask: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None)[source]¶
Remove double nodes for the input mesh
- Parameters:
mesh (Mesh) – the in put mesh
tol (Optional[MuscatFloat], optional) – the tolerance, by default value is = np.linalg.norm(boundingMax - boundingMin)*1e-7 if tol is zero a faster algorithm is used
nodesToTestMask (ArrayLike, optional) – a mask of len number of nodes with the value True for nodes to be tested (this can increase the speed of the algorithm), tests all pairs of nodes present in the mask by default None
- CleanLonelyNodes(mesh: Mesh, inPlace: bool = True) Tuple[ndarray, Mesh] [source]¶
Remove nodes not used by the elements
- Parameters:
mesh (Mesh) – the input mesh
inPlace (bool, optional) – if true the nodes are removed in place, by default True
- Returns:
usedNodes: a mask of type ndarray (size the number of nodes in mesh) with the nodes present on the cleanMesh cleanMesh: Mesh the mesh without lonely nodes
- Return type:
(usedNodes, cleanMesh)
- ComputeFeatures(inputMesh: Mesh, featureAngle: float64 = 90.0, skin: Mesh | None = None) Tuple[Mesh, Mesh] [source]¶
Compute features, element of dimensionality dim-2 (edges) for a given angle
- Parameters:
inputMesh (Mesh) – the input mesh
featureAngle (MuscatFloat, optional) – the detection angle: edges with faces with an angle smaller or equal than featureAngle will be consider as ridges. We use the internal angle, by default 90.
skin (Optional[Mesh], optional) – if the user can provide the skin (to save time), by default None
- Returns:
edgeMesh: a mesh containing the edges skinMesh: a mesh containing the skin
- Return type:
- ComputeRigidBodyTransformationBetweenTwoSetOfPoints(setPoints1: ndarray, setPoints2: ndarray) Tuple[ndarray, ndarray] [source]¶
Compute the rotation and the translation operator from two sets of points setPoints1 and setPoints2 have the same dimension (nbeOfPoints,dimension)
- Parameters:
setPoints1 (np.ndarray) – First set of points
setPoints2 (np.ndarray) – Second set of points
- Returns:
A, b such that setPoints1.T approx A*setPoints2.T + b
- Return type:
Tuple[np.ndarray, np.ndarray]
- ComputeSkin(mesh: Mesh, md: int | None = None, inPlace: bool = False, skinTagName: str = 'Skin') Mesh [source]¶
Compute the skin of a mesh (mesh), if md (mesh dimensionality) is None the mesh.GetPointsDimensionality() is used to filter the element to compute the skin.
Warning if some elements are duplicated the behavior of computeSkin with the option inPlace=True is not defined (Use CleanDoubleElements before ComputeSkin)
Warning: element fields are not handled by this function and will be deleted
- Parameters:
mesh (Mesh) – the input mesh
md (Optional[int], optional) – mesh dimensionality to extract element to compute the skin, by default None
inPlace (bool, optional, by default False) – if True, the skin is added to the original mesh, a tag “Skin” is created. if False a new mesh is returned with the elements of the skin (even if some element of the skin are already present on the original mesh). If the user merged the two meshes, he must call CleanDoubleElements to clean the mesh after.
skinTagName (str, default "Skin") – name of the created eTag
- Returns:
The mesh containing the skin, (the mesh if inPlace == True, or only the skin if inPlace == False)
- Return type:
- ConvertNTagsToETags(mesh: Mesh, prefix='NTag', targetDim: int64 | None = None)[source]¶
Create eTags from nTags on the mesh. If Skin (surface element) and edges are missing, they are created to hold the eTag information. The name of the created element tags is constructed using :
prefix+str(d)+"D_"+nTagName
Where d is the dimensionality of the target elements (1 for edges, 2 for surfaces, 3 for volumes)
I.e.: “NTag1D_ForceEdgeNodes”
Warning: element fields are not handled by this function and will be deleted
- Parameters:
mesh (Mesh) – The input mesh
prefix (str, optional) – The prefix used for the creation of eTags, by default “NTag”
targetDim (int | None, optional) – if None, volume, surface and edge tags will be created, by default None if 1 only edge tags will be created if 2 only surface tags are created if 3 only volume tags are created
- CopyElementTags(sourceMesh: Mesh, targetMesh: Mesh, extendTags: bool = False)[source]¶
Copy tags from sourceMesh to the targetMesh We use the connectivity to identify the elements
- DeleteElements(mesh: Mesh, mask: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], updateElementFields: bool = False)[source]¶
Delete elements on the input mesh (inplace)
- Parameters:
mesh (Mesh) – the input mesh
mask (ArrayLike) – the mash of elements to delete
updateElementFields (bool) – True to update Element fields
- DeleteInternalFaces(mesh: Mesh)[source]¶
Delete faces not present on the skin (internal faces) (inplace)
- Parameters:
mesh (Mesh) – the mesh
- FindDuplicates(nodes: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], tol: float64 | None = 1e-16) ndarray [source]¶
Find duplicate pairs of points. Two points are coincident if the distance between is lower than tol
- Parameters:
nodes (ArrayLike) – array of with the position of the nodes (number of nodes x number of coordinates)
tol (Optional[MuscatFloat], optional) – tolerance with respect to the bounding box to detect duplicated nodes, by default 1e-16
- Returns:
nx2 array of coincident pairs (sorted such that res[:,1]>res[:,0] and res[:,0] is sorted)
- Return type:
np.ndarray
- LowerNodesDimension(mesh: Mesh) Mesh [source]¶
Remove the last columns of the mesh nodes coordinate. This is done in place
- Morphing(mesh: Mesh, targetDisplacement: ndarray, targetDisplacementMask: ndarray, radius: float64 | None = None, max_steps: int = 1, verbose: bool = False) ndarray [source]¶
method for computing the deform mesh knowing displacement of some nodes. the user can push the morphed point back to the mesh by doing : mesh.node = morphedPoints
- Parameters:
mesh (Mesh) – the input mesh, the use only the point position information
targetDisplacement (numpy array) – numpy array: the known displacement of control nodes (shape [number_of_of_known_nodes,3])
targetDisplacementMask (numpy array) – numpy array: the ids of control nodes (list of ids or boolean array) in the same order as targetDisplacement
radius (Optional[MuscatFloat], optional) – you can choose a radius by setting radius to a value, by default np.linalg.norm(boundingMax-boundingMin)/2
max_steps (int, optional) – default: 1; number of max steps for decomposing the morphing
verbose (bool, optional) – default: False; print additional information when True
- Returns:
morphedPoints: the morphed points
- Return type:
np.ndarray
- NodesPermutation(mesh: Mesh, per: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])[source]¶
Function to do a permutation of the nodes in a mesh (in place)
- Parameters:
mesh (Mesh) – mesh to be modified
per (ArrayLike) – the permutation vector ([1,0,2,3] to permute first an second node)
- RigidBodyTransformation(mesh: Mesh, rotationMatrix: ndarray, translationVector: ndarray)[source]¶
In place rigid body transformation. new pos = Q.pos + translation
the rotation matrix Q should verify: QtQ = I = QQt et det Q = 1
- Parameters:
mesh (Mesh) – The input mesh
rotationMatrix (np.ndArray) – a 3x3 rotation matrix
translationVector (np.ndArray) – a vector of size 3 with the translation