Finite Element Tools (pysdic.fem)#

The submodule pysdic.fem provides low-level, array-based functions to work with finite element meshes: shape functions, Gauss quadrature, interpolation and differentiation of nodal properties, assembly of operators, geometric quantities, ray casting and adjacency of the elements.

All the functions work directly on numpy arrays (no mesh object is needed), so they can be reused with any mesh data structure.

Definition of Notations#

A mesh is defined in a space of dimension \(E\) by \(N_v\) vertices and \(N_e\) elements of topological dimension \(K \leq E\), each element having \(N_{vpe}\) vertices:

  • vertices_coordinates: The coordinates of the vertices with shape \((N_v, E)\).

  • connectivity_array: The vertex indices of each element with shape \((N_e, N_{vpe})\).

  • element_type: The type of the elements (see the table below).

The points inside the elements (integration points) are given by:

  • natural_coordinates: The coordinates \(\Xi = (\xi, \eta, ...)\) of the points in the reference element with shape \((N_p, K)\).

  • element_indices: The index of the element containing each point with shape \((N_p,)\). The index -1 marks a point not located in any element (accepted with allow_unlocated_points=True).

A property defined at the vertices (displacements, gray levels, …) has shape \((N_v, P)\). Its value at a point \(\Xi\) of an element is interpolated with the shape functions \(N_i(\Xi)\):

\[f(\Xi) = \sum_{i=1}^{N_{vpe}} N_i(\Xi) \, f_i\]

Supported element types#

element_type

Description

\(K\)

\(N_{vpe}\)

meshio type

VTK cell type

segment_2

Linear segment

1

2

line

3

segment_3

Quadratic segment

1

3

line3

21

triangle_3

Linear triangle

2

3

triangle

5

triangle_6

Quadratic triangle

2

6

triangle6

22

quadrangle_4

Bilinear quadrangle

2

4

quad

9

quadrangle_8

Serendipity quadrangle

2

8

quad8

23

The element_type arguments are case insensitive.

Shape functions#

Compute the shape functions \(N_i(\Xi)\) (and optionally their derivatives \(\frac{\partial N_i}{\partial \Xi}\)) at given natural coordinates in the reference element.

Gauss quadrature#

Get the natural coordinates \(\Xi_g\) and the weights \(w_g\) of the Gauss points of an element type, to integrate a function over the reference element: \(\int_{\hat{\Omega}} f(\Xi) \, d\Xi \approx \sum_g w_g f(\Xi_g)\).

Operations on the mesh#

Interpolate, differentiate and project the properties of the mesh at integration points. Each operation comes in two versions:

  • assemble_*: from precomputed shape functions (and derivatives), to reuse them for several properties.

  • compute_*: directly from the mesh and the integration points (the shape functions are computed internally).

Shape function matrix and Jacobian of the elements#

Interpolation, derivative and projection of a property#

Operators for the correlation#

  • assemble_displacement_jacobian_matrix: Assemble the operator \(\mathbf{J}\) mapping the nodal displacements to the variations of a property (e.g. gray levels) at integration points, \(\mathbf{J} \, dU = dR\).

Geometry and mechanics#

Compute geometric and mechanical quantities of the elements from their Jacobian matrices (any element type, linear or quadratic).

Location of points and ray casting#

Locate points in a 2D surface mesh (\(K = 2\), \(E = 2\)), or compute the first intersection of rays with a 3D surface mesh (\(K = 2\), \(E = 3\)), for example the rays of a camera computed with pysdic.compute_rays(). The intersections are returned as natural coordinates and element indices (-1 for the rays without intersection).

Important

The ray casting requires the optional package open3d (pip install open3d). The location of points in a 2D mesh has no optional dependency.

  • locate_points: Element and natural coordinates of points in a 2D surface mesh of any element type (exact for triangle_3, first approximation on subdivided elements refined with Newton iterations otherwise).

  • cast_rays: Intersection with a surface mesh of any element type (first approximation on subdivided elements, refined with Newton iterations on the exact surface).

  • triangle_3_cast_rays: Intersection with a triangle_3 mesh.

Adjacency and neighborhoods#

Build the adjacency graphs of a mesh and compute the shortest path distances and the neighborhoods of its vertices, elements and integration points:

  • two vertices are neighbors (distance 1) if they belong to the same element;

  • two elements are neighbors (distance 1) if they share at least one vertex.

Adjacency graphs#

Distances#

Neighborhoods#