Skip to content
Projects

simgeometry.objects.aperture3d

Three-dimensional aperture helpers for geometric object definitions.

Classes

NameDescription
Aperture3DRepresent a three-dimensional aperture embedded in a simulation domain.

Aperture3Dclass#

class Aperture3D(axis: str, center_coords: tuple, vertices: tuple[tuple[float, float], ...], lower_bound: tuple, upper_bound: tuple, bc: ConfigValue = None, inverted: bool = True)

Bases: Shape3D

Represent a three-dimensional aperture embedded in a simulation domain.

Numerics

radius

r(z)=rk−1+z−zk−1zk−zk−1 (rk−rk−1),zk−1<z≤zkr(z) = r_{k-1} + \frac{z - z_{k-1}}{z_k - z_{k-1}}\,(r_k - r_{k-1}), \qquad z_{k-1} < z \le z_k

opening

open  ⟺  ρ2<rmin⁡2  or  ρ2≤r(z)2,ρ2=∣p⊥−c∣2\text{open} \iff \rho^2 < r_{\min}^2 \;\text{or}\; \rho^2 \le r(z)^2, \qquad \rho^2 = |p_\perp - c|^2

inside

p∈S  ⟺  l≤p<u  and  ¬ open(inverted, the default)p \in S \iff l \le p < u \;\text{and}\; \lnot\,\text{open} \quad (\text{inverted, the default})

Assumptions:

  • the profile of (axial position zkz_k, radius rkr_k) vertices about the axis through center_coords; kk from searchsorted (side left)
  • beyond the first or last vertex the end radius holds
  • the inversion applies before the half-open box test: the solid is the material around the opening within the box only
  • no level set and no analytic crossing: crossings are sampled

axisattributeinstance attribute#

axis = axis

axis_indexattributeinstance attribute#

axis_index = {'x': 0, 'y': 1, 'z': 2}[axis]

center_coordsattributeinstance attribute#

center_coords = xp.array(center_coords, dtype=float)

solid_within_bounding_boxattributeclass attributeinstance attribute#

solid_within_bounding_box = True

verticesattributeinstance attribute#

vertices = xp.array(vertices)

max_radiusproperty#

max_radius: float

Return the largest aperture radius.

min_radiusproperty#

min_radius: float

Return the smallest aperture radius.

containsmethod#

def contains(coords: Array) -> bool

Check if the given coordinates are inside the aperture.

Parameters: coords (list or tuple): 3D coordinates.

Returns: bool: True if the coordinates are inside the aperture, False otherwise.

contains_pointsmethod#

def contains_points(points: Array) -> Array

Vectorized contains: a mask of the (3, n) points inside.

copymethod#

def copy() -> Aperture3D

Create a copy of the aperture.

Returns

Aperture3DAperture3D
A new instance of Aperture3D with the same properties.

get_verticesmethod#

def get_vertices(slice_axis: int, slice_position: float) -> ConfigValue

Get the vertices of a slice of the aperture along a given axis.

Parameters: slice_axis (int): Axis along which to slice (0 for x, 1 for y, 2 for z). slice_position (float): Position along the slice_axis where the slice is taken.

vertices (ndarray): Array of vertices defining the slice shape. If the slice does not intersect the aperture, returns an empty array.

mirrormethod#

def mirror(axis: int, position: float) -> None

Mirror the aperture across a specified axis at a given position.

Parameters

NameTypeDescription
axisintAxis index (0 for x-axis, 1 for y-axis, 2 for z-axis).
positionfloatPosition along the axis to mirror.

surface_areamethod#

def surface_area() -> None

Declare the aperture surface-area interface.

translatemethod#

def translate(offset: tuple[float, float, float]) -> None

Translate the aperture by the given offset.

Parameters

NameTypeDescription
offsettuple(dx, dy, dz) translation vector.

volumemethod#

def volume() -> None

Declare the aperture volume interface.

Inherited from simgeometry.shapes.Shape

has_level_setattributeclass attributeinstance attribute#

has_level_set: bool = False

level_set_exactattributeclass attributeinstance attribute#

level_set_exact: bool = False

ndimattributeinstance attribute#

ndim = ndim

bounding_boxproperty#

bounding_box: BoundingBox

Return the bounding box.

invertedproperty#

inverted: bool

Return whether this object represents an inverted region.

lower_boundproperty#

lower_bound: tuple[float, ...]

Return the lower coordinate bounds.

upper_boundproperty#

upper_bound: tuple[float, ...]

Return the upper coordinate bounds.

get_bound_verticesmethod#

def get_bound_vertices(slice_axis: int) -> xp.ndarray

Return vertices that bound the shape.

get_indices_in_objectmethod#

def get_indices_in_object(grid: Grid) -> list[int] | list[tuple[int, ...]]

Get the indices of grid points that are inside the shape.

Parameters: grid (object): Grid object containing indices and cell sizes.

Returns: list: The Grid.indices of the nodes inside, in their order.

level_setmethod#

def level_set(points: Array) -> Array

Level-set values of the (ndim, n) points: negative inside, positive outside.

The sign follows signed_distance, so it flips for an inverted shape, and the boundary is the zero level (where contains_points may go either way). The magnitude never exceeds the distance to the boundary; with level_set_exact it equals it. Values are on the active cunumpy backend, like contains_points. Raises NotImplementedError when has_level_set is False.

Numerics

inversion

ϕSc(p)=−ϕS(p)\phi_{S^c}(p) = -\phi_S(p)

bound

ϕ<0 inside,ϕ=0 on ∂S,∣ϕ(p)∣≤dist⁡(p,∂S)\phi < 0 \text{ inside}, \quad \phi = 0 \text{ on } \partial S, \quad |\phi(p)| \le \operatorname{dist}(p, \partial S)

Assumptions:

  • an inverted shape is the complement of its geometry: contains_points is negated and the level set flips sign
  • equality in the bound where level_set_exact is true: the Euclidean signed distance
  • shapes known only by their membership test (has_level_set False) raise NotImplementedError

node_maskmethod#

def node_mask(grid: Grid) -> np.ndarray

Return a host boolean array of the grid’s shape, set at the nodes inside.

One vectorised contains_points over Grid.node_points, so the cost is that of a few array passes over the grid.

set_bounding_boxmethod#

def set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> None

Set the bounding box for the shape.

Inherited from simgeometry.api.GeometryAPI

cell_fractionsmethod#

def cell_fractions(grid, *, samples_per_axis=4)

Estimate solid cell-volume and face-area fractions by subcell sampling.

Increase samples_per_axis to check convergence; unresolved thin features can be missed. This is not an exact finite-volume interface reconstruction.

closest_pointmethod#

def closest_point(points, *, resolution=64, bounds=None)

Closest surface coordinates; primitives are exact, others use a mesh.

Mesh fallback requires mesh extras. Its accuracy is controlled by resolution and may miss unresolved components. Points are (ndim, n), or one (ndim,) point; the returned array has the same layout.

crossingsmethod#

def crossings(start, end, *, samples=64, iterations=40)

First boundary crossing of every segment start[:, i] -> end[:, i].

start and end are (ndim, N), such as particle positions before and after a step. Returns a Crossings with hit, fraction, point and normal (out of the region where contains is true) on the active array backend. Polygons, circles, spheres, boxes and their affine transforms are analytic; other shapes sample samples points per segment and bisect iterations times, or refine on their level set (with its gradient as the normal) if they have one.

cut_edgesmethod#

def cut_edges(grid, **kwargs)

Locate all detected grid-edge surface hits, without solver clamping.

diagnosemethod#

def diagnose(grid, **kwargs)

Report sampled overlaps, unresolved components, and short cut distances.

differencemethod#

def difference(other)

evaluatemethod#

def evaluate(x=None, y=None, z=None, *, grid=None, bounds=None, resolution=128, quantity='occupancy')

Sample geometry as an xarray.DataArray (requires the evaluate extra).

Scalars fix axes, sequences form a tensor product, and DataArrays with shared dimension names describe scattered points. Unspecified axes use grid nodes, or resolution samples across bounds/the shape bounds. quantity is occupancy, labels (collections), signed_distance, or level_set (the analytic level set, or the signed distance without one). This is a local host operation, with no implicit MPI collectives.

exportmethod#

def export(path, **kwargs)

Export a sampled mesh as NPZ, OBJ, or STL (3D only).

intersect_segmentmethod#

def intersect_segment(start, end, *, samples=256, tolerance=1e-10)

Return ordered surface hits, including multiple crossings and tangencies.

Primitive intersections are analytic. Generic membership functions use samples intervals and may miss features smaller than that sampling. Result.exact distinguishes these cases. Coincident surface segments do not have a discrete set of hits; their end contacts may be returned.

intersectionmethod#

def intersection(other)

level_set_fieldmethod#

def level_set_field(resolution=64, bounds=None)

The level set on a 3D grid, laid out for plasma-plots’ 3D views.

shape.level_set_field().plasma.plot.isosurface(values=[0]) draws the surface (requires the interactive extra and import plasma_plots).

plotmethod#

def plot(ax=None, **kwargs)

Draw without displaying and return axes for composition.

rotatedmethod#

def rotated(angle, *, axis=(0, 0, 1), origin=None)

Return a rotated snapshot; angle is in degrees, about origin (default 0).

sample_interiormethod#

def sample_interior(count, *, rng=None, bounds=None, max_draws=1000000)

Uniform rejection samples, returned as (ndim, count).

Supply bounds for inverted/unbounded shapes. Raises if max_draws is exhausted; it never silently returns too few samples.

sample_surfacemethod#

def sample_surface(count, *, rng=None, resolution=64, bounds=None)

Uniform-by-length/area samples from the faceted boundary mesh.

scaledmethod#

def scaled(factors, *, origin=None)

Return a snapshot scaled by a nonzero scalar or per-axis factors.

showmethod#

def show(**kwargs)

Display geometry, dispatching to 3D unless a slice is requested.

Returns Matplotlib axes, or a PyVista plotter for backend='pyvista'. Set display=False for scripts. save=path saves the figure.

show_3dmethod#

def show_3d(**kwargs)

Display a surface with optional wireframe, normals and clipping.

backend='pyvista' enables an interactive clipping-plane widget via clip=True (requires the interactive extra). Matplotlib supports a static clip=(origin, normal) plane. Meshes are resolution-dependent.

signed_distancemethod#

def signed_distance(points, *, resolution=64, bounds=None)

Distance to the boundary, negative inside, positive outside.

Exact for balls, boxes, simple polygons and every shape whose level set is exact (level_set_exact, such as cylinders, tubes, cones, tori and their rigid motions), which it returns directly; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.

slicemethod#

def slice(x=None, y=None, z=None, origin=None, normal=None)

Return a queryable section with local-to-world coordinate mappings.

Fix exactly one coordinate, or give a 3D plane’s origin and normal. Axis-aligned sections retain the remaining coordinate names; oblique sections use x/y as their local plane coordinates.

surface_normalmethod#

def surface_normal(points, *, scale=None)

Outward unit normals at boundary points; NaN where undefined.

Primitive faces use analytic normals. Other geometries estimate the normal from nearby membership samples. At corners normals are not unique.

to_meshmethod#

def to_mesh(resolution=64, bounds=None)

Return sampled contours (2D) or triangles (3D), with spacing metadata.

Requires the mesh extra. Open contours/surfaces at the sampling bounds remain open; no artificial caps are added. Refine to resolve thin features.

transformedmethod#

def transformed(matrix, offset=None)

Return an affine-transformed snapshot; the source is unchanged.

translatedmethod#

def translated(offset)

Return a translated snapshot (unlike legacy in-place translate).

unionmethod#

def union(other)

yee_fractionsmethod#

def yee_fractions(grid, **kwargs)

Edge-length and face-area fractions of a Yee grid, and the surface’s traces.

Exact for planes; see simgeometry.fractions.yee_fractions.