adaptive.learner.triangulation module#

class adaptive.learner.triangulation.Triangulation(coords)[source]#

Bases: object

A triangulation object.

Parameters:

coords (2d array-like of floats) – Coordinates of vertices.

vertices#

Coordinates of the triangulation vertices.

Type:

list of float tuples

simplices#

List with indices of vertices forming individual simplices

Type:

set of integer tuples

vertex_to_simplices#

Set of simplices connected to a vertex, the index of the vertex is the index of the list.

Type:

list of sets

hull#

Exterior vertices

Type:

set of int

Raises:

ValueError – if the list of coordinates is incorrect or the points do not form one or more simplices in the

add_point(point, simplex=None, transform=None)[source]#

Add a new vertex and create simplices as appropriate.

Parameters:
  • point (float vector) – Coordinates of the point to be added.

  • transform (N*N matrix of floats) – Multiplication matrix to apply to the point (and neighbouring simplices) when running the Bowyer Watson method.

  • simplex (tuple of ints, optional) – Simplex containing the point. Empty tuple indicates points outside the hull. If not provided, the algorithm costs O(N), so this should be used whenever possible.

add_simplex(simplex)[source]#
bowyer_watson(pt_index, containing_simplex=None, transform=None)[source]#

Modified Bowyer-Watson point adding algorithm.

Create a hole in the triangulation around the new point, then retriangulate this hole.

Parameters:

pt_index (number) – the index of the point to inspect

Returns:

  • deleted_simplices (set of tuples) – Simplices that have been deleted

  • new_simplices (set of tuples) – Simplices that have been added

circumscribed_circle(simplex, transform)[source]#

Compute the center and radius of the circumscribed circle of a simplex.

Parameters:

simplex (tuple of ints) – the simplex to investigate

Returns:

The center and radius of the circumscribed circle

Return type:

tuple (center point, radius)

containing(face)[source]#

Simplices containing a face.

convex_invariant(vertex)[source]#

Hull is convex.

property default_transform#
delete_simplex(simplex)[source]#
property dim#
faces(dim=None, simplices=None, vertices=None)[source]#

Iterator over faces of a simplex or vertex sequence.

get_face_sharing_neighbors(neighbors, simplex)[source]#

Keep only the simplices sharing a whole face with simplex.

get_neighbors_from_vertices(simplex)[source]#
get_opposing_vertices(simplex)[source]#
get_reduced_simplex(point, simplex, eps=1e-08) list[source]#

Check whether vertex lies within a simplex.

Returns:

vertices – Indices of vertices of the simplex to which the vertex belongs. An empty list indicates that the vertex is outside the simplex.

Return type:

list of ints

get_simplices_attached_to_points(indices)[source]#
get_vertex(index)[source]#
get_vertices(indices)[source]#
property hull#

Compute hull from triangulation.

Parameters:

check (bool, default: True) – Whether to raise an error if the computed hull is different from stored.

Returns:

hull – Vertices in the hull.

Return type:

set of int

locate_point(point)[source]#

Find to which simplex the point belongs.

Return indices of the simplex containing the point. Empty tuple means the point is outside the triangulation

point_in_cicumcircle(pt_index, simplex, transform)[source]#
point_in_simplex(point, simplex, eps=1e-08)[source]#
reference_invariant()[source]#

vertex_to_simplices and simplices are compatible.

vertex_invariant(vertex)[source]#

Simplices originating from a vertex don’t overlap.

volume(simplex)[source]#
volumes()[source]#
adaptive.learner.triangulation.circumsphere(pts)[source]#

Compute the center and radius of a N dimension sphere which touches each point in pts.

Parameters:

pts (array-like, of shape (N-dim + 1, N-dim)) – The points for which we would like to compute a circumsphere.

Returns:

  • center (tuple of floats of size N-dim)

  • radius (a positive float)

  • A valid center and radius, if a circumsphere is possible, and no points are repeated.

  • If points are repeated, or a circumsphere is not possible, will return nans, and a

  • ZeroDivisionError may occur.

  • Will fail for matrices which are not (N-dim + 1, N-dim) in size due to non-square determinants

  • will raise numpy.linalg.LinAlgError.

  • May fail for points that are integers (due to 32bit integer overflow).

adaptive.learner.triangulation.fast_2d_circumcircle(points)[source]#

Compute the center and radius of the circumscribed circle of a triangle

Parameters:

points (2D array-like) – the points of the triangle to investigate

Returns:

(center point : tuple(float), radius: float)

Return type:

tuple

adaptive.learner.triangulation.fast_2d_point_in_simplex(point, simplex, eps=1e-08)[source]#
adaptive.learner.triangulation.fast_3d_circumcircle(points)[source]#

Compute the center and radius of the circumscribed sphere of a simplex.

Parameters:

points (2D array-like) – the points of the triangle to investigate

Returns:

(center point : tuple(float), radius: float)

Return type:

tuple

adaptive.learner.triangulation.fast_det(matrix)[source]#
adaptive.learner.triangulation.fast_norm(v)[source]#

Take the vector norm for len 2, 3 vectors. Defaults to a square root of the dot product for larger vectors.

Note that for large vectors, it is possible for integer overflow to occur. For instance: vec = [49024, 59454, 12599, -63721, 18517, 27961] dot(vec, vec) = -1602973744

adaptive.learner.triangulation.is_iterable_and_sized(obj)[source]#
adaptive.learner.triangulation.orientation(face, origin)[source]#

Compute the orientation of the face with respect to a point, origin.

Parameters:
  • face (array-like, of shape (N-dim, N-dim)) – The hyperplane we want to know the orientation of Do notice that the order in which you provide the points is critical

  • origin (array-like, point of shape (N-dim)) – The point to compute the orientation from

Returns:

  • 0 if the origin lies in the same hyperplane as face,

  • -1 or 1 to indicate left or right orientation

  • If two points lie on the same side of the face, the orientation will

  • be equal, if they lie on the other side of the face, it will be negated.

adaptive.learner.triangulation.point_in_simplex(point, simplex, eps=1e-08)[source]#
adaptive.learner.triangulation.simplex_volume_in_embedding(vertices) float[source]#

Calculate the volume of a simplex in a higher dimensional embedding. That is: dim > len(vertices) - 1. For example if you would like to know the surface area of a triangle in a 3d space.

This algorithm has not been tested for numerical stability.

Parameters:

vertices (2D arraylike of floats) –

Returns:

volume – the volume of the simplex with given vertices.

Return type:

float

Raises:

ValueError – if the vertices do not form a simplex (for example, because they are coplanar, colinear or coincident).