Muscat.Containers.Mesh module

CheckIntegrity() str[source]
class Mesh[source]

Bases: object

Class to store an unstructured (i.e. general) mesh:

  • self.nodes : the nodes positions

  • self.originalIdNodes : the ids of the previous mesh/file

  • self.elements : all the element in the mesh (of type AllElements)

The manual construction of this class must always end with a call to the function mesh.PrepareForOutput() or with the context manager mesh.WithModification(). This will ensure the correctness of the internal data

AddElementToTag(globalElemNumber: int, tagname: str) None[source]

Add an element (using the global element number) to a tag (tagname)

Parameters:
  • globalElemNumber (int) – the element number

  • tagname (str) – Tag name

Raises:

Exception – if the the element is not found

AddElementToTagUsingOriginalId(oid: int, tagname: str) None[source]

Add an element (using the originalId) to a tag (tagname)

Parameters:
  • oid (int) – the original id of the element

  • tagname (str) – Tag name

Raises:

Exception – if the element with the original id is not found

AddElementsToTag(globalElemNumbers: ArrayLike, tagname: str) None[source]

Add elements (using the global element number) to a tag (tagname)

Parameters:
  • globalElemNumbers (ArrayLike) – the list of the global ids of the element

  • tagname (str) – Tag name

Raises:

Exception – if some element indices are greater than the number of elements.

AddNodeToTagUsingOriginalId(oid: int, tagname: str) None[source]

add a node (using the original id ) to a tag (tagname)

Parameters:
  • oid (int) – Original id node

  • tagname (str) – Tag name

Raises:

Exception – if the original id is not found

Clean() None[source]

Remove unnecessary data : 1) empty tags 2) empty element containers

ComputeBoundingBox() Tuple[np.ndarray, np.ndarray][source]

Compute the bounding box (min and max) of the mesh

Returns:

the min, max

Return type:

Tuple[np.ndarray, np.ndarray]

ComputeGlobalOffset() Dict[ElementType, int64][source]

Return a dict with with key the elementType and the value the number of elements in the mesh before this type

Recompute the Global Offset,

ConvertDataForNativeTreatment() None[source]

Ensure all the data is compatible with the cpp treatment (continuous in C order)

CopyProperties(other: Mesh) None[source]
DeleteElemTags(tagNames: List[str] | str) None[source]

Delete element tags

Parameters:

tagNames (List[str]) – List of element tags to be deleted

GenerateManufacturedOriginalIDs(nodesOffset: int = 0, elementsOffset: int = 0) None[source]

function to generate a valid original ids for the nodes and the elements

Parameters:

offset (int, optional) – offset to use to start counting nodes and elements. This is useful for code needing numbering stating from 1, by default 0

GetElementsDimensionality() int[source]

Return the maximal dimension of the elements

Returns:

the max of all elements dimensionality

Return type:

int

GetElementsInTag(tagname: str, useOriginalId: bool = False) np.ndarray[source]

return a list with the ids of the elements in a tag

Parameters:
  • tagname (str) – the tag name

  • useOriginalId (bool, optional) – to return the list of original ids and not the global numbers, by default False

Returns:

the list off all the element in the tag named “tagname”

Return type:

np.ndarray

GetElementsOfType(typename: ElementType | str) ElementsContainer[source]

return the element container for the element name (typename)

Parameters:

typename (str) – the name of the elements to extract

Returns:

The Element Container for element

Return type:

ElementContainer

GetElementsOriginalIDs(ef=None) np.ndarray[source]

return a single list with all the original Ids concatenated

Parameters:

ef (ElementFilter, optional) – filter to select the information, by default None

Returns:

array with all the originalId for the selected elements

Return type:

np.ndarray

GetNamesOfElementTags() List[str][source]

return a list containing all the element tags present in the mesh

Returns:

the list of all the name of the element tags present in the mesh

Return type:

List[str]

GetNodalTag(tagName: str) Tag[source]

return the Tag (instance of the class) with name tagName. If the tag does not exist a new is created

GetNumberOfElements(dim: int | None = None) int64[source]

Compute and return the total number of elements in the mesh

Parameters:

dim (int, optional) – dimensionality filter, by default None

Returns:

number of element in the mesh (filtered by dim if dim != None)

Return type:

int

GetNumberOfNodes() int64[source]

return the total number of nodes in the mesh

Returns:

Number of node in the mesh

Return type:

int

GetPointsDimensionality() int[source]

Return the number of coordinates of the points

Returns:

number of columns in the point array

Return type:

int

GetPosOfNodes() np.ndarray[source]

return the position of all the nodes

Returns:

The position for all the nodes in the mesh

Return type:

np.ndarray

IsFrozen()
Merge(other: Mesh) None[source]

Merge the other mesh into this. no treatment is done to remove double nodes or elements.

Parameters:

other (Mesh) – the mesh to be merge into this (self)

MergeElements(other: Mesh, force: bool = False, nodesOffset: int64 = 0) None[source]

Merge the elements for a second mesh into this the nodes array must be the same (not only equal)

the user can force the merge if needed (force argument)

Parameters:
  • other (Mesh) – the other mesh

  • force (bool, optional) – True to force the merge even if the nodes are not the same, by default False

PrepareForOutput() None[source]

Function to free the extra memory used after the incremental creation of a mesh and final treatment (offset computation).

SetElementsOriginalIDs(originalIDs: ArrayLike) None[source]

Set from a single list all the element original Ids

Parameters:

originalIDs (ArrayLike) – the list of all the original ids in the order of the mesh

SetNodes(nodes: ArrayLike, originalIDNodes: ArrayLike | None = None, generateOriginalIDs: bool = False) None[source]

Set nodes and original Ids in the correct internal format.

Parameters:
  • nodes (ArrayLike) – Nodes positions of size (number of node, space dimensionality )

  • originalIDNodes (ArrayLike, optional) – original Ids, by default None

  • generateOriginalIDs (bool, optional) – if True to generate original ids with numpy.arange, by default False

UnFrozen()
VerifyIntegrity() None[source]

Integrity verification of the mesh.

Raises:

RuntimeError – if the integrity of the mesh is compromised

View() Mesh[source]

return a copy of this object recursively, numpy arrays are view to the original ones but with the flags.writeable = False

Returns:

a view of Mesh

Return type:

Mesh

WithModification() ClosingMeshAutomatically[source]

Context manager to release all the extra memory of the mesh after modification. this context manager call mesh.PrepareForOutput() automatically at the end of the block

Example

with mesh.WithModification():

# mesh.PrepareForOutput() is called at the end of this block, # even if code in the block raises an exception

elemFields: Dict[str, ndarray]

This is a dictionary containing fields defined over the elements (all the elements). The keys are the names of the fields the values are the actual data of size (nb elements, nb of components)

elements: AllElements

Attribute to store for each element type a instance of a element container (Muscat.Containers.ElementsContainers.ElementsContainer or Muscat.Containers.ElementsContainers.StructuredElementsContainer ) containing the connectivity, originalIds and the tags.

nodeFields: Dict[str, ndarray]

This is a dictionary containing fields defined over the nodes (all the nodes). The keys are the names of the fields the values are the actual data of size (nb nodes, nb of components)

nodes: ndarray

Nodes of the mesh (this are point in 2D or 3D always of format MuscatFloat)

nodesTags

Tags for the nodes

originalIDNodes: ndarray

The role of the originalIDNodes is double.

In the case the origin of the mesh is a file from disk, it is used to store the “node number” (a concept present in many file formats). In the case the mesh is a transformation of an initial mesh (extraction for example) the originalIDNodes is used to track the origin (the index) of each entity.

props: Dict[str, Any]

Metadata this is just a dictionary that can be used to transport information with the mesh, please use the class name as key of the object using/setting the information.

Special keys are:
  • “IsConstantRectilinear” : True if the mesh is constant Rectilinear

  • “spacing” : a np.array with the spacing in each direction

  • “origin” : a np.array with the origin of the mesh

  • “dimensions” : a np.array with the number of cells in each direction