_auxilliaries
In this subpackage, we have two modules: abstraction and distance_functions. Each of these
has a very specific purpose when generating and defining new domains. In abstraction, we see two functions;
PolyMesh and Domain. A Domain object must be placed into poly_mesher to function as expected and
a PolyMesh object is outputted.
When generating custom meshes, one may bypass the use of poly_mesher entirely. If one requires the use of
DGFEMGeometry still however, the resulting mesh must be compatible with the PolyMesh object.
If one wants to create just a custom domain, one may use some of the already built-in distance functions to speed up the design process. As in the original PolyMesher code by Talishi et al. [^1], these functions are used to describe the distance a given point is from each of the boundary facets. One may look at the built-in domains to see how these functions interact with each other in the final setting.
Custom meshes also become easier to define in this context; one may define a domain with fixed points, which remain the same
under the poly_mesher algorithm (see examples/discontinuous_solutions.ipynb for more information on applying
this concept).
abstraction
- class reyna.polymesher.two_dimensional._auxilliaries.abstraction.Domain(bounding_box: ndarray, fixed_points: ndarray | None = None)
Bases:
objectFoundational class for domain generation. Every (custom) domain must be built on this ABC to function correctly with the poly_mesher function. Defines the common interface for all domains.
Notes
The variable fixed points works with ‘poly_mesher’ and gives a set of points that remain as fixed centres during LLoyds algorithm.
- abstract area() float
This function returns the area of a domain.
- Returns:
Area of the domain.
- Return type:
float
- abstract distances(points: ndarray) ndarray
The distance function for a domain. This gives some indication of ‘how far’ a given point is from the boundary of the domain. Negative values determine the inside of a domain. This explicitly defines the domain.
- Parameters:
points (np.ndarray) – Points to calculate the distances from.
- Returns:
Distances calculated from the points.
- Return type:
np.ndarray
- abstract pFix() ndarray | None
This function returns a set of fixed points. This ‘getter’ is used if the set of fixed points is in fact dependent on additional domain parameters. If no more points are required, then use ‘return self.fixed_points’.
- Returns:
Array of fixed points.
- Return type:
Optional[np.ndarray]
- class reyna.polymesher.two_dimensional._auxilliaries.abstraction.PolyMesh(vertices, filtered_regions, filtered_points, domain)
Bases:
objectThis ABC defines the PolyMesh class for this package. This may be used by the user to generate meshes not availible with the standard set to be able to be used with the numerical methods of this package.
- vertices
Array of vertices.
- Type:
np.ndarray
- filtered_regions
Elements of the mesh (list of lists of integer indecies to ‘vertices’)
- Type:
List[list]
- filtered_points
The corresponding centers of these elements.
- Type:
np.ndarray
Notes
The ‘filtered_points” may be any points so long as they lie in the kernel of the element (e.g. Voronoi centers if the mesh is Voronoi). I.e. the elements must be relatively convex with respect to this point.
distance_functions
- reyna.polymesher.two_dimensional._auxilliaries.distance_functions.d_combination(d1: ndarray, d2: ndarray, functionality: str) ndarray
Combines two distance arrays using a specified operation on their last column.
This function concatenates the non-last columns of d1 and d2 and then applies an operation on the last column of each array according to the functionality argument. The resulting array includes all original columns plus the combined last column.
This is used to construct the more complicated ‘d_intersect’, ‘d_union’, and ‘d_difference’ functions.
- Parameters:
d1 (np.ndarray) – First array of distances with shape (n, m1), where the last column is used for the combination operation.
d2 (np.ndarray) – Second array of distances with shape (n, m2), where the last column is used for the combination operation.
functionality (str) –
Specifies how to combine the last columns of d1 and d2. Supported options are: “min”: Take the element-wise minimum. “max”: Take the element-wise maximum. “diff”: Take
the element-wise maximum of d1 and the negative of d2.
- Returns:
- Combined array containing the original columns from d1 and d2
(excluding their original last columns) and the new last column resulting from the specified combination.
- Return type:
np.ndarray
- Raises:
ValueError – If functionality is not one of “min”, “max”, or “diff”.
- reyna.polymesher.two_dimensional._auxilliaries.distance_functions.d_difference(d1: ndarray, d2: ndarray) ndarray
Combines two distance arrays using a difference operation on their last column.
- Parameters:
d1 (np.ndarray) – First array of distances with shape (n, m1), where the last column is used for the combination operation.
d2 (np.ndarray) – Second array of distances with shape (n, m2), where the last column is used for the combination operation.
- Returns:
Combined array containing the difference of the original columns, d1 and d2.
- Return type:
np.ndarray
- reyna.polymesher.two_dimensional._auxilliaries.distance_functions.d_hexagon(p: ndarray, x: float = 0.0, y: float = 0.0, scale: float = 1.0) ndarray
Calculates signed distances from points to a specified hexagon.
Given an array of 2D coordinates p, this function computes the signed distance to a given hexagon.
- Parameters:
p (np.ndarray) – Array of 2D points.
x (float) – x value of the centre of the hexagon.
y (float) – y value of the centre of the hexagon.
scale (float) – the scale of the hexagon.
- Returns:
Array of signed distances.
- Return type:
np.ndarray
- reyna.polymesher.two_dimensional._auxilliaries.distance_functions.d_intersect(d1: ndarray, d2: ndarray) ndarray
Combines two distance arrays using an intersection operation on their last column.
- Parameters:
d1 (np.ndarray) – First array of distances with shape (n, m1), where the last column is used for the combination operation.
d2 (np.ndarray) – Second array of distances with shape (n, m2), where the last column is used for the combination operation.
- Returns:
Combined array containing the intersection of the original columns, d1 and d2.
- Return type:
np.ndarray
- reyna.polymesher.two_dimensional._auxilliaries.distance_functions.d_line(p: ndarray, x1: float, y1: float, x2: float, y2: float) ndarray
Calculates signed distances from points to a line.
Given an array of 2D coordinates p, this function computes the signed distance to a given line. This is a constructor object and can be used to build more complicated domains. Defined with two points which the line passes through. The interior side is defined as the positive normal.
- Parameters:
p (np.ndarray) – Array of 2D points.
x1 (float) – First points x value.
y1 (float) – First points y value.
x2 (float) – Second points x value.
y2 (float) – Second points y value.
- Returns:
Array of signed distances.
- Return type:
np.ndarray
- reyna.polymesher.two_dimensional._auxilliaries.distance_functions.d_rectangle(p: ndarray, x1: float, x2: float, y1: float, y2: float) ndarray
Calculates signed distances from points to a rectangular domain.
Given an array of 2D coordinates p, this function computes the signed distance of to the rectangular domain.
- Parameters:
p (np.ndarray) – Array of 2D points.
x1 (float) – Lower x bound.
x2 (float) – Upper x bound.
y1 (float) – Lower y bound.
y2 (float) – Upper y bound.
- Returns:
Array of signed distances.
- Return type:
np.ndarray
- reyna.polymesher.two_dimensional._auxilliaries.distance_functions.d_sphere(p: ndarray, center: ndarray | None = None, radius: float = 1.0) ndarray
Calculates signed distances from points to a spherical domain.
Given an array of coordinates p in the form [p_0, p_1, …, p_n] where each p_i is [x_i, y_i] or [x_i, y_i, z_i], this function computes the distance of each point from the center of a sphere. The distances are “translated” by the radius such that they are negative inside the sphere and positive outside.
- Parameters:
p (np.ndarray) – Array of points of the form [p_0, p_1, …, p_n] where each p_i is [x_i, y_i] or [x_i, y_i, z_i].
center (np.ndarray, optional) – The center of the spherical domain. Defaults to the origin of the corresponding dimension if None.
radius (float, optional) – Radius of the spherical domain. Defaults to 1.0.
- Returns:
- Array of signed distances in the form [d_0, d_1, …, d_n],
where negative values indicate points inside the sphere and positive values outside.
- Return type:
np.ndarray
- Raises:
Exception – p must contain points of dimention 2 or 3.
Exception – center must be of equal dimensio to p.
- reyna.polymesher.two_dimensional._auxilliaries.distance_functions.d_union(d1: ndarray, d2: ndarray) ndarray
Combines two distance arrays using a union operation on their last column.
- Parameters:
d1 (np.ndarray) – First array of distances with shape (n, m1), where the last column is used for the combination operation.
d2 (np.ndarray) – Second array of distances with shape (n, m2), where the last column is used for the combination operation.
- Returns:
Combined array containing the union of the original columns, d1 and d2.
- Return type:
np.ndarray