Mesh

Descriptions of the contents of the Mesh class, which contains the coordinates of the domain and aditional suporting data.

class pysemtools.datatypes.msh.Mesh(comm, data=None, x=None, y=None, z=None, create_connectivity=False, bckend='numpy')

Class that contains coordinate and partitioning data of the domain.

This class needs to be used generaly as it contains the coordinates of the domain and some information about the partitioning of the domain.

Parameters:
commComm

MPI comminicator object.

dataHexaData, optional

HexaData object that contains the coordinates of the domain.

xndarray, optional

X coordinates of the domain. shape is (nelv, lz, ly, lx).

yndarray, optional

Y coordinates of the domain. shape is (nelv, lz, ly, lx).

zndarray, optional

Z coordinates of the domain. shape is (nelv, lz, ly, lx).

create_connectivitybool, optional

If True, the connectivity of the domain will be created. (Memory intensive).

Attributes:
xndarray

X coordinates of the domain. shape is (nelv, lz, ly, lx).

yndarray

Y coordinates of the domain. shape is (nelv, lz, ly, lx).

zndarray

Z coordinates of the domain. shape is (nelv, lz, ly, lx).

lxint

Polynomial degree in x direction.

lyint

Polynomial degree in y direction.

lzint

Polynomial degree in z direction.

nelvint

Number of elements in the domain in current rank.

glb_nelvint

Total number of elements in the domain.

gdimint

Dimension of the domain.

non_linear_shared_pointslist, optional

List that show the index where the points in the domain are shared, used by coef in dssum.

Methods

get_edge_centers()

Get the edge centers of the domain.

get_facet_centers()

Get the centroid of each facet

get_vertices()

Get the vertices of the domain.

init_common(comm)

Initialize common attributes.

init_from_coords(comm, x, y, z)

Initialize from coordinates.

init_from_data(comm, data)

Initialize form data.

create_connectivity

Returns:

Examples

If a hexadata object: data is read from disk, the mesh object can be created directly from it.

>>> from pysemtools.datatypes.msh import Mesh
>>> msh = Mesh(comm, data = data)

If the coordinates are already available, the mesh object can be created from them.

>>> from pysemtools.datatypes.msh import Mesh
>>> msh = Mesh(comm, x = x, y = y, z = z)

This is useful in situations where the coordinates are generated in the code or streamed into python from another source.

get_edge_centers()

Get the edge centers of the domain.

Get all the edge centers of the domain in 2D or 3D.

Notes

We need 4 edges for 2D and 12 edges for 3D. For all cases we store 3 coordinates for each edge.

get_facet_centers()

Get the centroid of each facet

Find the “centroid of each facet. This is used to find the shared facets between elements.

Notes

This is not really the centroid, as we also find a coordinate in the dimension perpendicular to the facet. This means that these values can be outside or inside the element. However the same behaviour should be seen in the matching elements.

get_vertices()

Get the vertices of the domain.

Get all the vertices of the domain in 2D or 3D.

Notes

We need 4 vertices for 2D and 8 vertices for 3D. For all cases, we store 3 coordinates for each vertex.

init_common(comm)

Initialize common attributes.

This function is used to initialize the common attributes of the mesh object.

Parameters:
commComm

MPI communicator object.

Returns:
None

Nothing is returned, the attributes are set in the object.

init_from_coords(comm, x, y, z)

Initialize from coordinates.

This function is used to initialize the mesh object from x, y, z ndarrays.

Parameters:
commComm

MPI communicator object.

xndarray

X coordinates of the domain. shape is (nelv, lz, ly, lx).

yndarray

Y coordinates of the domain. shape is (nelv, lz, ly, lx).

zndarray

Z coordinates of the domain. shape is (nelv, lz, ly, lx).

Returns:
None

Nothing is returned, the attributes are set in the object.

init_from_data(comm, data)

Initialize form data.

This function is used to initialize the mesh object from a hexadata object.

Parameters:
commComm

MPI communicator object.

dataHexaData

HexaData object that contains the coordinates of the domain.

Returns:
None

Nothing is returned, the attributes are set in the object.

MeshConnectivity

Descriptions of the contents of the MeshConnectivity class. This class determines the connectivity from the geometry and can be used to perform parallel operations like dssum.

class pysemtools.datatypes.msh_connectivity.MeshConnectivity(comm, msh: Mesh | None = None, rel_tol=1e-05, use_hashtable=False, max_simultaneous_sends=1, max_elem_per_vertex: int | None = None, max_elem_per_edge: int | None = None, max_elem_per_face: int | None = None)

Class to compute the connectivity of the mesh

Uses facets and vertices to determine which elements are connected to each other

Parameters:
commMPI communicator

The MPI communicator

mshMesh

The mesh object

rel_tolfloat

The relative tolerance to use when comparing the coordinates of the facets/edges

use_hashtablebool

Whether to use a hashtable to define connectivity. This is faster but uses more memory

max_simultaneous_sendsint

The maximum number of simultaneous sends to use when sending data to other ranks. A lower number saves memory for buffers but is slower.

max_elem_per_vertexint

The maximum number of elements that share a vertex. The default values are 4 for 2D and 8 for 3D (Works for a structured mesh) The default value is selected if this input is left as None

max_elem_per_edgeint

The maximum number of elements that share an edge. The default values are 2 for 2D and 4 for 3D (Works for a structured mesh) The default value is selected if this input is left as None

max_elem_per_faceint

The maximum number of elements that share a face. The default values are 2 for 3D (Works for a structured mesh) The default value is selected if this input is left as None

Methods

dssum([field, msh, average])

Computes the dssum of the field

dssum_global([local_dssum_field, field, msh])

Computes the global dssum of the field

dssum_local([field, msh])

Computes the local dssum of the field

get_multiplicity(msh)

Computes the multiplicity of the elements in the mesh

global_connectivity(msh)

Computes the global connectivity of the mesh

local_connectivity(msh)

Computes the local connectivity of the mesh

dssum(field: ndarray | None = None, msh: Mesh | None = None, average: str = 'multiplicity')

Computes the dssum of the field

Parameters:
fieldnp.ndarray

The field to compute the dssum

mshMesh

The mesh object

averagestr

The averaging weights to use. Can be “multiplicity”

Returns:
np.ndarray

The dssum of the field

dssum_global(local_dssum_field: ndarray | None = None, field: ndarray | None = None, msh: Mesh | None = None)

Computes the global dssum of the field

Parameters:
local_dssum_fieldnp.ndarray

The local dssum of the field, computed with dssum_local

fieldnp.ndarray

The field to compute the dssum

mshMesh

The mesh object

Returns:
np.ndarray

The global dssum of the field

dssum_local(field: ndarray | None = None, msh: Mesh | None = None)

Computes the local dssum of the field

Parameters:
fieldnp.ndarray

The field to compute the dssum

mshMesh

The mesh object

Returns:
np.ndarray

The local dssum of the field

get_multiplicity(msh: Mesh)

Computes the multiplicity of the elements in the mesh

Parameters:
mshMesh

Notes

The multiplicity is the number of times a point in a element is shared with its own element or others. The minimum multiplicity is 1, since the point is always shared with itself.

global_connectivity(msh: Mesh)

Computes the global connectivity of the mesh

Currently this function sends data from all to all.

Parameters:
mshMesh

The mesh object

Notes

In 3D. this function sends the facet centers of the unique_efp_elem and unique_efp_facet to all other ranks. as well as the element ID and facet ID to be assigned.

We compare the unique facet centers of our rank to those of others and determine which one matches. When we find that one matches, we populate the directories: global_shared_efp_to_rank_map[(e, f)] = rank global_shared_efp_to_elem_map[(e, f)] = elem global_shared_efp_to_facet_map[(e, f)] = facet

So for each element facet pair we will know which rank has it, and which is their ID in that rank.

BE MINDFUL: Later when redistributing, send the points, but also send the element and facet ID to the other ranks so the reciever can know which is the facet that corresponds.

local_connectivity(msh: Mesh)

Computes the local connectivity of the mesh

This function checks elements within a rank

Parameters:
mshMesh

The mesh object

Notes

In 3D, the centers of the facets are compared. efp means element facet pair. One obtains a local_shared_efp_to_elem_map and a local_shared_efp_to_facet_map dictionary.

local_shared_efp_to_elem_map[(e, f)] = [e1, e2, …] gives a list with the elements e1, e2 … that share the same facet f of element e.

local_shared_efp_to_facet_map[(e, f)] = [f1, f2, …] gives a list with the facets f1, f2 … of the elements e1, e2 … that share the same facet f of element e.

In each case, the index of the element list, corresponds to the index of the facet list. Therefore, the element list might have repeated element entries.

Additionally, we create a list of unique_efp_elem and unique_efp_facet, which are the elements and facets that are not shared with any other element. These are either boundary elements or elements that are connected to other ranks. the unique pairs are the ones that are checked in global connecitivy,

MeshPartitioner

Descriptions of the contents of the MeshPartitioner class. This allows to redistribute elements among ranks based on a partitioning algorithm.

class pysemtools.datatypes.msh_partitioning.MeshPartitioner(comm, msh: Mesh | None = None, conditions: list[ndarray] | None = None)

A class that repartitons SEM mesh data using a given partitioning algorithm.

The idea is to be able to chose subdomains of the mesh and split the elements such that the load is balanced among the ranks.

One could use this to repartition the data if the condition array is full of True values, but the idea is to be able to use any condition array.

Parameters:
commMPI communicator

MPI communicator

mshMesh

Mesh object to partition

conditionslist[np.ndarray]

List of conditions to apply to the mesh elements. The conditions should be in the form of a list of numpy arrays. Each numpy array should have the same length as the number of elements in the mesh. The conditions should be boolean arrays.

Methods

create_partitioned_field([fld, ...])

Create a partitioned field object

create_partitioned_mesh([msh, ...])

Create a partitioned mesh object

redistribute_field_elements([field, ...])

Redistribute the elements of the mesh object to different ranks

create_partitioned_field(fld: Field | FieldRegistry | None = None, partitioning_algorithm: str = 'load_balanced_linear') FieldRegistry

Create a partitioned field object

Parameters:
fldField or FieldRegistry

Field object to partition

partitioning_algorithmstr

Algorithm to use for partitioning the mesh elements

Returns:
partitioned_fieldFieldRegistry

Partitioned field object

create_partitioned_mesh(msh: Mesh | None = None, partitioning_algorithm: str = 'load_balanced_linear', create_conectivity: bool = False) Mesh

Create a partitioned mesh object

Parameters:
mshMesh

Mesh object to partition

partitioning_algorithmstr

Algorithm to use for partitioning the mesh elements

Returns:
partitioned_meshMesh

Partitioned mesh object

redistribute_field_elements(field: ndarray | None = None, partitioning_algorithm: str = 'load_balanced_linear') None

Redistribute the elements of the mesh object to different ranks

Parameters:
fieldnp.ndarray

Field to redistribute based on the conditions at initialization

partitioning_algorithmstr

Algorithm to use for partitioning the mesh elements