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, Hdf5SerializerMixin

The 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 the properties attribute or directly with connectivity[name].

If element_type is given, the connectivity is associated with one of the element types implemented in pysdic.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.int64 array. The elements attribute returns a read-only view: to change the elements, assign a new array.

Important

The properties are stored in a pysdic.core.property_container.PropertyContainer with force_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 of elements. If given, it must match this shape.

  • properties (Optional[Union[Dict[str, ArrayLike], PropertyContainer]], optional) –

    The properties of the elements:

  • 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\), while connectivity[name], name in connectivity and iter(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 the elements and element_type setters (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 of elements and element_type then raise a RuntimeError explaining 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().

Connectivity.from_array(elements, *[, ...])

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].

Connectivity.element_type

[Get/Set] The type of the elements (see the table in pysdic.Connectivity), or None if no type is associated.

Connectivity.elements

[Get/Set] The vertex indices of the elements, an array of shape \((N_e, N_{vpe})\).

Connectivity.n_elements

[Get] The number of elements \(N_e\).

Connectivity.n_properties

[Get] The number of properties of the elements.

Connectivity.n_topological_dimensions

[Get] The topological dimension \(K\) of the elements (1 for segments, 2 for triangles and quadrangles), or None if element_type is not set.

Connectivity.n_vertices_per_element

[Get] The number of vertices per element \(N_{vpe}\).

Connectivity.properties

[Get] The properties of the elements.

Connectivity.shape

[Get] The shape \((N_e, N_{vpe})\) of the elements.

Structure methods#

Connectivity.concatenate(other, *[, ...])

Concatenate two connectivities (the elements of other come after).

Connectivity.copy(*[, copy_properties])

Create a copy of the connectivity (with the same element type).

Connectivity.filter_elements(mask, *[, ...])

Keep only the elements selected by a boolean mask (the element type is kept).

Connectivity.keep_elements_by_index(indices, *)

Keep only the elements with the given indices.

Connectivity.remove_elements_by_index(indices, *)

Remove the elements with the given indices.

Checks#

Connectivity.validate(*[, recursive])

Validate the integrity of the connectivity.

Connectivity.all_close(other, *[, rtol, ...])

Check if the elements are equal to the elements of another connectivity (see numpy.allclose).

Connectivity.all_positive()

Check if all the vertex indices are non-negative (\(\geq 0\)).

Connectivity.all_lower_than(value)

Check if all the vertex indices are strictly lower than value.

Connectivity.is_positive()

Check which elements have only non-negative vertex indices (\(\geq 0\)).

Connectivity.has_negative()

Check which elements have at least one negative vertex index (\(< 0\)).

Connectivity.has_higher_than(value)

Check which elements have at least one vertex index strictly higher than value.

Conversion#

Connectivity.to_array()

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).

Connectivity.to_dict(*[, save_properties])

Convert the connectivity to a flat dictionary.

Connectivity.from_dict(data, *[, ...])

Create a connectivity from a dictionary.

Connectivity.to_json_file(file_path, *[, ...])

Serialize the object to a JSON file.

Connectivity.from_json_file(file_path, **kwargs)

Deserialize a JSON file to an object of the class.

Connectivity.to_hdf5_file(file_path, *[, ...])

Serialize the object to an HDF5 file.

Connectivity.from_hdf5_file(file_path, **kwargs)

Deserialize an object from an HDF5 file.

Connectivity.to_npz_file(file_path, *[, ...])

Serialize the object to an NPZ file.

Connectivity.from_npz_file(file_path, **kwargs)

Deserialize an object from an NPZ file.