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-1marks a point not located in any element (accepted withallow_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)\):
Supported element types#
|
Description |
\(K\) |
\(N_{vpe}\) |
|
VTK cell type |
|---|---|---|---|---|---|
|
Linear segment |
1 |
2 |
|
3 |
|
Quadratic segment |
1 |
3 |
|
21 |
|
Linear triangle |
2 |
3 |
|
5 |
|
Quadratic triangle |
2 |
6 |
|
22 |
|
Bilinear quadrangle |
2 |
4 |
|
9 |
|
Serendipity quadrangle |
2 |
8 |
|
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.
compute_shape_functions: Shape functions for any supported element type.
compute_segment_2_shape_functions: Shape functions of the 2-node segment.
compute_segment_3_shape_functions: Shape functions of the 3-node segment.
compute_triangle_3_shape_functions: Shape functions of the 3-node triangle.
compute_triangle_6_shape_functions: Shape functions of the 6-node triangle.
compute_quadrangle_4_shape_functions: Shape functions of the 4-node quadrangle.
compute_quadrangle_8_shape_functions: Shape functions of the 8-node (serendipity) quadrangle.
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)\).
get_gauss_points: Gauss points for any supported element type.
get_segment_2_gauss_points: 1-point rule of the 2-node segment.
get_segment_3_gauss_points: 2-point rule of the 3-node segment.
get_triangle_3_gauss_points: 1-point rule of the 3-node triangle.
get_triangle_6_gauss_points: 3-point rule of the 6-node triangle.
get_quadrangle_4_gauss_points: \(2 \times 2\) rule of the 4-node quadrangle.
get_quadrangle_8_gauss_points: \(3 \times 3\) rule of the 8-node quadrangle.
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#
assemble_shape_function_matrix: Assemble the shape function matrix \(\mathcal{N}\) with shape \((N_p, N_v)\) (dense or sparse).
compute_shape_function_matrix: Compute and assemble the shape function matrix \(\mathcal{N}\).
remap_vertices_coordinates: Coordinates of the vertices of the element of each integration point, with shape \((N_p, N_{vpe}, E)\).
assemble_jacobian_matrix: Assemble the Jacobian \(J = \frac{\partial X}{\partial \Xi}\) with shape \((N_p, E, K)\).
compute_jacobian_matrix: Compute and assemble the Jacobian \(J = \frac{\partial X}{\partial \Xi}\).
Interpolation, derivative and projection of a property#
assemble_property_interpolation: Interpolate a nodal property at integration points from precomputed shape functions.
compute_property_interpolation: Interpolate a nodal property at integration points.
assemble_property_derivative: Derivative of a nodal property with respect to the global coordinates from precomputed derivatives and Jacobians.
compute_property_derivative: Derivative of a nodal property with respect to the global coordinates at integration points.
assemble_property_projection: Project a property defined at integration points back to the vertices from a precomputed shape function matrix.
compute_property_projection: Project a property defined at integration points back to the vertices.
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).
compute_elements_centers: Center of each element.
compute_elements_areas: Area of each surface element (\(K = 2\)), integrated with the Gauss points.
compute_integration_points_normals: Unit normal of a 3D surface mesh at integration points.
compute_elements_normals: Unit normal of each element of a 3D surface mesh, at its center.
compute_vertices_normals: Unit normal at each vertex of a 3D surface mesh (mean of the normals of the elements weighted by their areas).
compute_strains: Linear strain tensor \(\boldsymbol{\varepsilon} = \frac{1}{2} (\nabla U + \nabla U^T)\) of a displacement field at integration points.
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_3mesh.
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#
assemble_vertices_adjacency_graph: Adjacency graph of the vertices of a mesh.
assemble_elements_adjacency_graph: Adjacency graph of the elements of a mesh.
Distances#
bfs_distance: Shortest path distances from a starting node to all the nodes of a graph.
compute_distance_matrix: Shortest path distances between all the pairs of nodes of a graph.
compute_vertices_distance_matrix: Shortest path distances between all the pairs of vertices of a mesh.
compute_elements_distance_matrix: Shortest path distances between all the pairs of elements of a mesh.
Neighborhoods#
bfs_neighborhood: Nodes within a given distance from a starting node of a graph.
compute_neighborhood: Neighborhood of each node of a graph.
compute_vertices_neighborhood: Neighborhood of each vertex of a mesh.
compute_elements_neighborhood: Neighborhood of each element of a mesh.
remap_integration_points_neighborhood: Remap a neighborhood of the elements to the integration points located in these elements.
compute_integration_points_neighborhood: Integration points located in the neighborhood of each element.
compute_neighborhood_statistics: Statistics of values over the neighborhood of each node.