BasicTools.Containers.UnstructuredMesh module

class BasicTools.Containers.UnstructuredMesh.AllElements[source]

Bases: object

Class to store a list of element containers. This class is mostly a re-implementation of dict but with ordered keys. This class is sorted by keys, in lexicographic order, so the retrieving order is stable.

Note

FB: the number of different types of elements is low, I don’t think this is gonna add alot of overhead to the library

GetElementsOfType(typename: str) ElementsContainer[source]

return a ElementContainer by name

Parameters:

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

Returns:

the container

Return type:

ElementsContainer

GetTagsNames() List[str][source]

return a list with all the tags in this container

Returns:

the list of the tag names

Return type:

List[str]

IsFrozen()
UnFrozen()
items()[source]
keys()[source]
values()[source]
BasicTools.Containers.UnstructuredMesh.CheckIntegrity()[source]
class BasicTools.Containers.UnstructuredMesh.ElementsContainer(elementType)[source]

Bases: BaseOutputObject

Class to hold a list of element of the same type

  • elementType : a string from BasicTools.Containers.ElementNames

  • connectivity : the connectivity matrix starting form 0

  • tags : the tags holder class

  • originalIds : the id or number from the previous mesh/file

The user can use this data to find the mapping from the initial mesh/file to the current mesh (self).

  • self.globaloffset : this value is calculate automatically by the mesh

Deprecated since version 2.0.0.

  • self.cpt : an internal counter to do efficient add of elements one by one

The user is responsible to call self.tighten() to compact the connectivity matrix after the population ( calls AddNewElement(…) or allocate(…))

AddElementToTag(globalElemNumber: int, tagname: str) bool[source]
Add an element to a tag using a global element number, if the global number

The user must compute the globaloffset first to make this function work

Deprecated since version 2.0.0.

This function is to complex and to many side effects.

bool
True if the element is added to the tag (in the case globalElemNumber element is in this

ElementContainers ).

AddNewElement(conn: ArrayLike, originalid: int) int[source]

append a single element to the connectivity

Parameters:
  • conn (ArrayLike) – connectivity of the added element

  • originalid (int) – the original id of the added element

Returns:

the total number of elements in the container

Return type:

int

AddNewElements(conn: ArrayLike, originalids: ArrayLike | None = None) int[source]

Append a new elements to the connectivity

Parameters:
  • conn (ArrayLike) – connectivity of the added elements

  • originalids (ArrayLike, optional) – the original id of the added element, by default -1 is used

Returns:

the total number of elements in the container

Return type:

int

Allocate(nbElements: int)[source]

Allocate the storage for nbElements

the user is responsible of filling the connectivity and the originalIds with valid values

Parameters:

nbElements (int) – Number of element to Allocate

GetNodesIdFor(ids: int | ArrayLike) np.ndarray[source]

return the nodes used by the list of elements

input:

ids :

Parameters:

ids (Union[int,ArrayLike]) – the id or a list of ids of elements to treat (always a local id list)

Returns:

the ids of the nodes used by the elements ids

Return type:

np.ndarray

GetNumberOfElements() int[source]

return the number of elements in this container

Returns:

Number of elements

Return type:

int

GetNumberOfNodesPerElement() int[source]

return the number of nodes per element for the elements in this container

Returns:

the number of nodes per element for the elements in this container

Return type:

int

GetTag(tagName: str) Tag[source]

return the tag by name. If the tag does not exist a new tag is created

Parameters:

tagName (str) – the name of the tag to retrieve

Returns:

a tag with the name tagName

Return type:

Tag

IsFrozen()
Merge(other: ElementsContainer, offset: int | None = None)[source]

Merge the elements from the other container into this.

Warning!!! Non elimination of double elements is done

if an offset is supplied the connectivity of the other container is shifted by the value of the offset during the merge

Reserve(nbElements: int)[source]

Reserve the storage for nbElements

The user is responsible to call self.tighten() to compact the connectivity and the originalIds. matrix after the population

Parameters:

nbElements (int) – Number of element to reserve

UnFrozen()
tighten() None[source]

Compact the storage and free non used space.

class BasicTools.Containers.UnstructuredMesh.UnstructuredMesh[source]

Bases: MeshBase

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

  • self.nodes : the points positions

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

  • self.elements : the list of all the element in the mesh

  • self.boundingMin/Max : the bounding box of the mesh (use ComputeBoundingBox to compute it)

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

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

Add an element (using the global element number) to a tag (tagname) # you must compute the globaloffset first to make this function work

Parameters:
  • globalElemNumber (int) – the element number

  • tagname (str) – Tag name

Raises:

Exception – if the the element is not found

AddElementToTagUsingOriginalId(oid: int, tagname: str)[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)[source]

Add elements (using the global element number) to a tag (tagname) you must compute the globaloffset first to make this function work

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

  • tagname (str) – Tag name

Raises:

Exception – if some elementid 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() None[source]

to recompute the bounding box (min and max)

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

Recompute the Global Offset, This is necessary for some operation. Recomendation : Call it after changing the topology

Deprecated since version 2.0.0.

The globaloffset variable will be deprecated

ConvertDataForNativeTreatment()[source]

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

DeleteElemTags(tagNames: List[str])[source]

Delete element tags

Parameters:

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

GetDimensionality()[source]

Deprecated since version 2.0.0.

Please use GetPointsDimensionality()

return the dimensionality 2/3

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

GetElementsOriginalIDs(dim: int = None) np.ndarray[source]

return a single list with all the originalid concatenated

Parameters:

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

Returns:

array with all the originalId for the selected elements

Return type:

np.ndarray

GetNumberOfElements(dim: int | None = None) int[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() int[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

GetPosOfNode(i: int) np.ndarray[source]

Return the position of the node i

Parameters:

i (int) – id of the node

Returns:

position of the point

Return type:

np.ndarray

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()
IsUnstructured()[source]
Merge(other: UnstructuredMesh)[source]
MergeElements(other: UnstructuredMesh, force: bool = False)[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 variable)

Parameters:
  • other (UnstructuredMesh) – 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)[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)[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:

Exception – if the integrity of the mesh is compromised

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)