pysdic.Connectivity#
The pysdic.Connectivity stores the \(N_e\) elements of a mesh, each defined by the indices of its \(N_{vpe}\) vertices (shape \((N_e, N_{vpe})\)), with an optional element type and properties for each element.
Connectivity class#
- class Connectivity(elements, *, n_vertices_per_element=None, properties=None, element_type=None)[source]#
Bases:
LockableMixin,JsonSerializerMixin,NpzSerializerMixin,Hdf5SerializerMixinThe connectivity of a mesh: \(N_e\) elements, each defined by the indices of its \(N_{vpe}\) vertices.
Each element can carry additional properties (material, labels, …) stored in a
pysdic.core.property_container.PropertyContainer, accessible through thepropertiesattribute or directly withconnectivity[name].If
element_typeis given, the connectivity is associated with one of the element types implemented inpysdic.fem(shape functions, Gauss points, VTK export, …):Element Type
Description
“segment_2”
2-node line element
“segment_3”
3-node line element
“triangle_3”
3-node triangular element
“triangle_6”
6-node triangular element
“quadrangle_4”
4-node quadrilateral element
“quadrangle_8”
8-node quadrilateral element
Note
Only the number of vertices per element is checked against
element_type: the ordering of the vertices inside each element is the responsibility of the user.Note
The vertex indices are copied when they are set and stored as a
numpy.int64array. Theelementsattribute returns a read-only view: to change the elements, assign a new array.Important
The properties are stored in a
pysdic.core.property_container.PropertyContainerwithforce_2d=True, i.e. with shape \((N_e, P)\). A container given by the user with other settings is accepted, but some operations (like VTK export) may behave unexpectedly.- Parameters:
elements (ArrayLike) – An integer array of shape \((N_e, N_{vpe})\) with the non-negative vertex indices of each element. Floats are accepted only if they are integral (no truncation). A 1D array of shape \((N_e,)\) is accepted if
n_vertices_per_element=1.n_vertices_per_element (Optional[Integral], optional (default:
None)) – The number of vertices per element \(N_{vpe}\). By default, it is inferred from the shape ofelements. If given, it must match this shape.properties (Optional[Union[Dict[str, ArrayLike], PropertyContainer]], optional) –
The properties of the elements:
a dictionary mapping names to arrays of shape \((N_e, \dots)\), which are copied into a new
pysdic.core.property_container.PropertyContainer,or a
pysdic.core.property_container.PropertyContainerwith \(N = N_e\), which is shared (not copied).
element_type (Optional[str], optional (default:
None)) – The type of the elements (case insensitive, see the table above). Its number of vertices must match \(N_{vpe}\).
Notes
len(connectivity)gives the number of elements \(N_e\), whileconnectivity[name],name in connectivityanditer(connectivity)refer to the properties.The methods never modify the connectivity in place: the methods that change the elements (
filter_elements(),keep_elements_by_index(), …) return a new connectivity. Only theelementsandelement_typesetters (same number of elements) and the properties modify an existing connectivity.Note
A connectivity can be locked by an object of the package that owns it (for example the mesh of an SDIC analysis, see
pysdic.core.lockable.LockableMixin): the setters ofelementsandelement_typethen raise aRuntimeErrorexplaining why. The properties can always be modified. A copy (copy) is always unlocked.
Instantiation#
The Connectivity class can be instantiated:
From an array of elements of shape \((N_e, N_{vpe})\) with the constructor or the classmethod
from_array().
|
Create a connectivity from an array of elements. |
Implemented methods and attributes#
The following sections provide an overview of the attributes and methods defined
in the pysdic.Connectivity class.
Attributes#
The elements can carry properties stored in a property container (see Core Tools), accessible with obj.properties or directly with obj[name].
[Get/Set] The type of the elements (see the table in |
|
[Get/Set] The vertex indices of the elements, an array of shape \((N_e, N_{vpe})\). |
|
[Get] The number of elements \(N_e\). |
|
[Get] The number of properties of the elements. |
|
[Get] The topological dimension \(K\) of the elements (1 for segments, 2 for triangles and quadrangles), or |
|
[Get] The number of vertices per element \(N_{vpe}\). |
|
[Get] The properties of the elements. |
|
[Get] The shape \((N_e, N_{vpe})\) of the elements. |
Structure methods#
|
Concatenate two connectivities (the elements of |
|
Create a copy of the connectivity (with the same element type). |
|
Keep only the elements selected by a boolean mask (the element type is kept). |
|
Keep only the elements with the given indices. |
|
Remove the elements with the given indices. |
Checks#
|
Validate the integrity of the connectivity. |
|
Check if the elements are equal to the elements of another connectivity (see |
Check if all the vertex indices are non-negative (\(\geq 0\)). |
|
|
Check if all the vertex indices are strictly lower than |
Check which elements have only non-negative vertex indices (\(\geq 0\)). |
|
Check which elements have at least one negative vertex index (\(< 0\)). |
|
|
Check which elements have at least one vertex index strictly higher than |
Conversion#
Return a copy of the elements. |
Serialization methods#
The pysdic.Connectivity is converted to a flat dictionary with to_dict (and created back with
from_dict). It inherits the file methods of the serialization mixins
(see Core Tools).
|
Convert the connectivity to a flat dictionary. |
|
Create a connectivity from a dictionary. |
|
Serialize the object to a JSON file. |
|
Deserialize a JSON file to an object of the class. |
|
Serialize the object to an HDF5 file. |
|
Deserialize an object from an HDF5 file. |
|
Serialize the object to an NPZ file. |
|
Deserialize an object from an NPZ file. |