# -*- coding: utf-8 -*-
#
# This file is subject to the terms and conditions defined in
# file 'LICENSE.txt', which is part of this source code package.
#
from typing import Optional, List
import numpy as np
from Muscat.Containers.Mesh import Mesh
GlobalIdsFieldName = "GlobalIDs"
[docs]class PartitionedMesh():
""" Class PartitionedMesh, Class to store a partitioned mesh we use two field to store the global numbering of the elements
and the nodes. theses field are stored in the every mesh .nodesFields["GlobalIDs"] .elemFields["GlobalIDs"].
np.union(GlobalIds)[0] = 0 , np.union(GlobalIds)[-1] = len(np.union(GlobalIds))-1 """
def __init__(self) -> None:
super().__init__()
self.storage: List[Mesh] = []
[docs] def AddMesh(self, mesh: Mesh, nodesGlobalIDs: Optional[np.ndarray] = None, elementsGlobalIDs: Optional[np.ndarray] = None) -> None:
"""Add mesh to the PartitionedMesh
extra data is needed. "GlobalIDs" on the nodes and "GlobalIDs" on the elements. Theses int fields can be
provided inside the mesh (nodeFields, elemFields) or as extra arguments. the extra fields will be pushed
to the mesh
Parameters
----------
mesh : Mesh
the mesh
nodesGlobalIDs : Optional[np.ndarray], optional
an numpy array of ints over the nodes, by default None
elementsGlobalIDs : Optional[np.ndarray], optional
an numpy array of ints over the elements, by default None
Raises
------
RuntimeError
if no nodes GlobalIDs are provided
RuntimeError
if no elements GlobalIDs are provided
"""
if nodesGlobalIDs is None:
if GlobalIdsFieldName not in mesh.nodeFields: # pragma: no cover
raise RuntimeError("globalNodesIds not provided and absent of nodeFields")
else:
mesh.nodeFields[GlobalIdsFieldName] = nodesGlobalIDs
if elementsGlobalIDs is None:
if GlobalIdsFieldName not in mesh.elemFields: # pragma: no cover
raise RuntimeError("globalElementIds not provided and absent of elemFields")
else:
mesh.elemFields[GlobalIdsFieldName] = elementsGlobalIDs
self.storage.append(mesh)
[docs]def CheckIntegrity(GUI: bool = False):
from Muscat.Containers.MeshGraphTools import PartitionMesh
from Muscat.Containers.Filters.FilterObjects import ElementFilter
from Muscat.Containers.MeshInspectionTools import ExtractElementsByElementFilter
from Muscat.Containers.MeshCreationTools import CreateCube
myMesh = CreateCube(dimensions=[10, 10, 10], spacing=[1, 1, 1], origin=[0, 0, 0], ofTetras=False)
myMesh = ExtractElementsByElementFilter(myMesh, ElementFilter(dimensionality=3))
part = np.asarray(PartitionMesh(myMesh, 4))
myMesh.nodeFields[GlobalIdsFieldName] = np.arange(myMesh.GetNumberOfNodes())
myMesh.elemFields[GlobalIdsFieldName] = np.arange(myMesh.GetNumberOfElements())
pm = PartitionedMesh()
pm.AddMesh(myMesh)
pm.AddMesh(myMesh, nodesGlobalIDs=myMesh.nodeFields[GlobalIdsFieldName], elementsGlobalIDs=myMesh.elemFields[GlobalIdsFieldName])
return "OK"
if __name__ == '__main__':
print(CheckIntegrity(True)) # pragma: no cover