pysdic.fem.locate_points#

locate_points(vertices_coordinates, connectivity_array, element_type, points, *, n_subdivisions=None, max_iteration=20, tolerance=1e-10)[source]#

Locate points in a 2D surface mesh (\(K = 2\), \(E = 2\)): compute the element containing each point and its natural coordinates \(\Xi = (\xi, \eta)\) such that \(X(\Xi) = \vec{x}\).

  • triangle_3: the mapping is affine, the natural coordinates are computed exactly in the candidate elements (the elements whose bounding box contains the point, found with a uniform grid).

  • Other element types: the mapping \(X(\Xi)\) is not affine, so the points are located in three steps:

    1. Each element is subdivided into triangles (n_subdivisions segments per edge in the reference element) and the points are located exactly in these triangles. This gives the element and a first approximation \(\Xi_0\) of the natural coordinates.

    2. The natural coordinates are refined with Newton iterations on \(X(\Xi) - \vec{x} = 0\) from \(\Xi_0\).

    3. The points not located by the first two steps (points between a curved edge and its subdivision, or near an edge between two elements) are searched in all the candidate elements (bounding boxes enlarged for the curved edges), with Newton iterations from the center of the reference element.

A point is located in an element if its natural coordinates are inside the reference element (enlarged by tolerance).

A point is unlocated (element index -1) if it is outside the mesh, not finite, or if the Newton iterations do not converge. A point on the boundary between several elements (or in overlapping elements) is located in the element of lowest index.

The natural coordinates accepted within the tolerance are moved onto the reference element, so that they are inside their element for the strict checks of the other functions.

Note

  • Inputs vertices_coordinates and points will be converted to numpy.float64.

  • Input connectivity_array will be converted to numpy.int64.

See also

Parameters:
  • vertices_coordinates (ArrayLike) – An array of shape \((N_v, 2)\) with the finite coordinates of the vertices.

  • connectivity_array (ArrayLike) – An array of shape \((N_e, N_{vpe})\) with the vertex indices of each element.

  • element_type (str) – The type of the elements (case insensitive), a surface element type (triangle_3, triangle_6, quadrangle_4 or quadrangle_8).

  • points (ArrayLike) – An array of shape \((N_p, 2)\) with the coordinates of the points to locate. Non-finite points are unlocated.

  • n_subdivisions (Optional[Integral], optional (default: None)) – The number of segments per edge of the reference element for the first approximation (\(\geq 1\)). By default, 1 for quadrangle_4 (2 triangles per element) and 2 for the quadratic elements. Ignored for triangle_3.

  • max_iteration (Integral, optional (default: 20)) – The maximum number of Newton iterations (\(\geq 1\)). Ignored for triangle_3.

  • tolerance (Real, optional (default: 1e-10)) – The convergence tolerance of the Newton iterations on the natural coordinates, also used to check that a point is inside an element (strictly positive).

Returns:

  • natural_coordinates (numpy.ndarray) – An array of shape \((N_p, 2)\) with the natural coordinates \((\xi, \eta)\) of the points (NaN for the unlocated points).

  • element_indices (numpy.ndarray) – An array of shape \((N_p,)\) with the index of the element containing each point (-1 for the unlocated points).

Raises:
  • TypeError – If an input has a wrong type.

  • ValueError – If the mesh is not a 2D surface mesh or an input has a wrong shape or value.

Return type:

Tuple[ndarray, ndarray]

Examples

Locate two points in a mesh made of two triangles.

 1import numpy
 2from pysdic.fem import locate_points
 3
 4vertices_coordinates = numpy.array([[0, 0], [1, 0], [1, 1], [0, 1]])
 5connectivity_array = numpy.array([[0, 1, 2], [0, 2, 3]])
 6
 7natural_coordinates, element_indices = locate_points(
 8    vertices_coordinates, connectivity_array, "triangle_3", [[0.75, 0.25], [2.0, 0.5]]
 9)
10print(natural_coordinates, element_indices)
[[0.5  0.25]
 [ nan  nan]] [ 0 -1]