simgeometry.objects
Package exports for geometric object definitions.
Classes
| Name | Description |
|---|---|
Aperture2D | Represent a two-dimensional aperture embedded in a simulation domain. |
Aperture3D | Represent a three-dimensional aperture embedded in a simulation domain. |
Circle | Represent a circular geometry object. |
Cuboid | Represent a cuboid geometry object. |
FunctionObject2D | Represent an arbitrary 2D geometry object defined by a Boolean function. |
FunctionObject3D | Represent an arbitrary 3D geometry object defined by a Boolean function. |
Line | Represent a line geometry object. |
Polygon | Represent a polygon geometry object. |
Rectangle | Represent a rectangular geometry object. |
Sphere | Represent a spherical geometry object. |
Triangle | Represent a triangular geometry object. |
Modules
aperture2dTwo-dimensional aperture helpers for geometric object definitions.aperture3dThree-dimensional aperture helpers for geometric object definitions.circleCircle helpers for geometric object definitions.cuboidCuboid helpers for geometric object definitions.function_objectFunction-based geometric object definitions.lineLine helpers for geometric object definitions.polygonPolygon helpers for geometric object definitions.rectangleRectangle helpers for geometric object definitions.sphereSphere helpers for geometric object definitions.triangleTriangle helpers for geometric object definitions.
Aperture2Dclass#
simgeometry.objects.aperture2dView sourceclass Aperture2D(axis: int, position: float, vertices: tuple[tuple[float, float], ...], bc: ConfigValue = None, inverted: bool = False)Bases: Shape2D
Represent a two-dimensional aperture embedded in a simulation domain.
axispropertywritable#
axis: intReturn the aperture axis.
positionproperty#
position: floatReturn the object position.
rvecproperty#
rvec: listReturn the radial aperture coordinate vector.
verticespropertywritable#
vertices: tuple[tuple[float, float], ...]Return object vertices.
zvecproperty#
zvec: listReturn the axial aperture coordinate vector.
containsmethod#
def contains(coords: ndarray) -> boolCheck if the given coordinates are inside the polygon.
Parameters: coords (list or tuple): Coordinates (x, y).
Returns: bool: True if the point is inside the polygon, False otherwise.
contains_pointsmethod#
def contains_points(points: ndarray) -> ndarrayVectorised :meth:contains: a mask of the (2, n) points inside.
get_verticesmethod#
def get_vertices() -> list[PointList]Return the vertices that define the object.
get_vertices_lowermethod#
def get_vertices_lower() -> xp.ndarrayReturn the vertices of the polygon.
Returns: list: List of vertices as (x, y) coordinates.
get_vertices_uppermethod#
def get_vertices_upper() -> xp.ndarrayReturn the vertices of the polygon.
Returns: list: List of vertices as (x, y) coordinates.
Inherited from simgeometry.shapes.Shape2D
plotmethod#
simgeometry.shapes.Shape2DView sourcedef plot(ax: Any = None, **kwargs: Any) -> AnyDraw the shape as filled polygons into ax and return the axes.
Keyword arguments style the polygons (facecolor, alpha, …).
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
copymethod#
simgeometry.api.GeometryAPIView sourcedef copy()Return an independent deep copy.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)Aperture3Dclass#
simgeometry.objects.aperture3dView sourceclass 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.
axisattributeinstance attribute#
axis = axisaxis_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 = Trueverticesattributeinstance attribute#
vertices = xp.array(vertices)max_radiusproperty#
max_radius: floatReturn the largest aperture radius.
min_radiusproperty#
min_radius: floatReturn the smallest aperture radius.
containsmethod#
def contains(coords: Array) -> boolCheck 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) -> ArrayVectorized :meth:contains: a mask of the (3, n) points inside.
copymethod#
def copy() -> Aperture3DCreate 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) -> ConfigValueGet 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) -> NoneMirror the aperture across a specified axis at a given position.
surface_areamethod#
def surface_area() -> NoneDeclare the aperture surface-area interface.
translatemethod#
def translate(offset: tuple[float, float, float]) -> NoneTranslate the aperture by the given offset.
Parameters
| Name | Type | Description |
|---|---|---|
offset | tuple | (dx, dy, dz) translation vector. |
volumemethod#
def volume() -> NoneDeclare the aperture volume interface.
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)plotmethod#
simgeometry.api.GeometryAPIView sourcedef plot(ax=None, **kwargs)Draw without displaying and return axes for composition.
rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)Circleclass#
simgeometry.objects.circleView sourceclass Circle(midpoint: BoundsLike, radius: float, bc: ConfigValue = None, inverted: bool = False)Bases: Shape2D
Represent a circular geometry object.
midpointattributeinstance attribute#
midpoint = list(midpoint)radiusattributeinstance attribute#
radius = radiuscontainsmethod#
def contains(coords: Array) -> boolCheck if the given coordinates are inside the circle.
Parameters: coords (list or tuple): Coordinates for each dimension.
Returns: bool: True if the coordinates are inside the circle, False otherwise.
contains_pointsmethod#
def contains_points(points: Array) -> ArrayVectorised :meth:contains: a mask of the (2, n) points inside.
copymethod#
def copy() -> CircleCreate a copy of the circle.
Returns
CircleCircle- A new instance of Circle with the same midpoint, radius, and boundary conditions.
get_verticesmethod#
def get_vertices(num_vertices: int = 100) -> ConfigValueGet the vertices approximating the circle.
Parameters: num_vertices (int): Number of vertices to approximate the circle.
Returns: list: List of vertices as (x, y) coordinates.
mirrormethod#
def mirror(axis: int, position: float) -> NoneMirror the circle across a specified axis at a given position.
translatemethod#
def translate(offset: tuple[float, float]) -> NoneTranslate the xyz by the given offset.
Parameters
| Name | Type | Description |
|---|---|---|
offset | tuple | (dx, dy) translation vector. |
Inherited from simgeometry.shapes.Shape2D
plotmethod#
simgeometry.shapes.Shape2DView sourcedef plot(ax: Any = None, **kwargs: Any) -> AnyDraw the shape as filled polygons into ax and return the axes.
Keyword arguments style the polygons (facecolor, alpha, …).
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)Cuboidclass#
simgeometry.objects.cuboidView sourceclass Cuboid(midpoint: BoundsLike, side_lengths: BoundsLike, bc: ConfigValue = None, inverted: bool = False)Bases: Shape3D
Represent a cuboid geometry object.
midpointattributeinstance attribute#
midpoint = xp.array(midpoint)side_lengthsattributeinstance attribute#
side_lengths = xp.array(side_lengths)containsmethod#
def contains(coords: Array) -> boolCheck if the given coordinates are inside the cuboid.
Parameters: coords (list or tuple): Coordinates for each dimension.
Returns: bool: True if all coordinates are inside the cuboid, False otherwise.
contains_pointsmethod#
def contains_points(points: Array) -> ArrayVectorised :meth:contains: a mask of the (3, n) points inside.
copymethod#
def copy() -> CuboidCreate a copy of the cuboid.
Returns
CuboidCuboid- A new instance of Cuboid with the same midpoint, side lengths, and boundary conditions.
get_verticesmethod#
def get_vertices(slice_axis: int, slice_position: float) -> ConfigValueGet the corner vertices of a slice of the cuboid along a given axis.
Parameters
Returns
verticeslist- List of corner vertices defining the slice polygon.
mirrormethod#
def mirror(axis: int, position: float) -> NoneMirror the cuboid across a specified axis at a given position.
surface_areamethod#
def surface_area() -> floatCalculate the surface area of the cuboid.
translatemethod#
def translate(offset: tuple[float, float, float]) -> NoneTranslate the cuboid by the given offset.
Parameters
| Name | Type | Description |
|---|---|---|
offset | tuple | (dx, dy, dz) translation vector. |
volumemethod#
def volume() -> floatCalculate the volume of the cuboid.
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)plotmethod#
simgeometry.api.GeometryAPIView sourcedef plot(ax=None, **kwargs)Draw without displaying and return axes for composition.
rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)FunctionObject2Dclass#
simgeometry.objects.function_objectView sourceclass FunctionObject2D(func: Callable[[Array], bool], lower_bound: BoundsLike, upper_bound: BoundsLike, bc: ConfigValue = None, inverted: bool = False)Bases: Shape2D
Represent an arbitrary 2D geometry object defined by a Boolean function.
The object interior is the set of all points for which func(coords)
returns True. A bounding box must be supplied by the caller because
it cannot in general be derived from an arbitrary function.
Example
Create a ring (annulus) with inner radius 1 and outer radius 2::
def ring(coords): x, y = coords r2 = x**2 + y**2 return 1.0**2 <= r2 <= 2.0**2
obj = FunctionObject2D( func=ring, lower_bound=(-2.0, -2.0), upper_bound=(2.0, 2.0),)containsmethod#
def contains(coords: Array) -> boolCheck if the given coordinates are inside the object.
Parameters
coords:
(x, y) coordinates to test.
Returns
bool
True if func(coords) is truthy (falsy when inverted).
get_verticesmethod#
def get_vertices() -> listReturn an empty list; vertices cannot be derived from an arbitrary function.
Inherited from simgeometry.shapes.Shape2D
plotmethod#
simgeometry.shapes.Shape2DView sourcedef plot(ax: Any = None, **kwargs: Any) -> AnyDraw the shape as filled polygons into ax and return the axes.
Keyword arguments style the polygons (facecolor, alpha, …).
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
contains_pointsmethod#
simgeometry.shapes.ShapeView sourcedef contains_points(points: Array) -> ArrayReturn a mask of the (ndim, n) points inside the shape.
The default calls :meth:contains point by point; shapes override it with a
vectorised test.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
copymethod#
simgeometry.api.GeometryAPIView sourcedef copy()Return an independent deep copy.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)FunctionObject3Dclass#
simgeometry.objects.function_objectView sourceclass FunctionObject3D(func: Callable[[Array], bool], lower_bound: BoundsLike, upper_bound: BoundsLike, bc: ConfigValue = None, inverted: bool = False)Bases: Shape3D
Represent an arbitrary 3D geometry object defined by a Boolean function.
The object interior is the set of all points for which func(coords)
returns True. A bounding box must be supplied by the caller because
it cannot in general be derived from an arbitrary function.
Example
Create a solid torus with major radius 3 and tube radius 1::
def torus(coords): x, y, z = coords r = (x**2 + y**2)**0.5 return (r - 3.0)**2 + z**2 <= 1.0**2
obj = FunctionObject3D( func=torus, lower_bound=(-4.0, -4.0, -1.0), upper_bound=(4.0, 4.0, 1.0),)containsmethod#
def contains(coords: Array) -> boolCheck if the given coordinates are inside the object.
Parameters
coords:
(x, y, z) coordinates to test.
Returns
bool
True if func(coords) is truthy (falsy when inverted).
get_verticesmethod#
def get_vertices(slice_axis: int = 0, slice_position: float | None = None) -> tupleReturn an empty array; vertices cannot be derived from an arbitrary function.
surface_areamethod#
def surface_area() -> floatSurface area cannot be analytically derived from an arbitrary function.
volumemethod#
def volume() -> floatVolume cannot be analytically derived from an arbitrary function.
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
contains_pointsmethod#
simgeometry.shapes.ShapeView sourcedef contains_points(points: Array) -> ArrayReturn a mask of the (ndim, n) points inside the shape.
The default calls :meth:contains point by point; shapes override it with a
vectorised test.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
copymethod#
simgeometry.api.GeometryAPIView sourcedef copy()Return an independent deep copy.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)plotmethod#
simgeometry.api.GeometryAPIView sourcedef plot(ax=None, **kwargs)Draw without displaying and return axes for composition.
rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)Lineclass#
simgeometry.objects.lineView sourceclass Line(midpoint: BoundsLike, side_lengths: BoundsLike, bc: ConfigValue = None, inverted: bool = False)Bases: Shape1D
Represent a line geometry object.
midpointattributeinstance attribute#
midpoint = xp.array(midpoint)side_lengthsattributeinstance attribute#
side_lengths = xp.array(side_lengths)containsmethod#
def contains(coords: Array) -> boolCheck if the given coordinates are inside the line.
Parameters: coords (list or tuple): Coordinates for each dimension.
Returns: bool: True if the coordinates are inside the line, False otherwise.
contains_pointsmethod#
def contains_points(points: Array) -> ArrayVectorised :meth:contains: a mask of the (1, n) points inside.
copymethod#
def copy() -> LineCreate a copy of the line.
Returns
LineLine- A new instance of Line with the same midpoint, side lengths, and boundary conditions.
get_verticesmethod#
def get_vertices() -> ConfigValueReturn the vertices that define the object.
mirrormethod#
def mirror(axis: int, position: float) -> NoneMirror the line across a specified axis at a given position.
translatemethod#
def translate(offset: tuple[float]) -> NoneTranslate the line by the given offset.
Parameters
| Name | Type | Description |
|---|---|---|
offset | tuple | (dx,) translation vector. |
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)plotmethod#
simgeometry.api.GeometryAPIView sourcedef plot(ax=None, **kwargs)Draw without displaying and return axes for composition.
rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)Polygonclass#
simgeometry.objects.polygonView sourceclass Polygon(vertices: ndarray, bc: float | None = None, inverted: bool = False)Bases: Shape2D
Represent a polygon geometry object.
verticespropertywritable#
vertices: ndarrayReturn object vertices.
containsmethod#
def contains(coords: ndarray) -> boolCheck if the given coordinates are inside the (possibly inverted) polygon.
Parameters: coords (list or tuple): Coordinates (x, y).
Returns: bool: True if the point is inside the object, False otherwise.
contains_pointsmethod#
def contains_points(points: ndarray) -> ndarrayVectorised :meth:contains: a mask of the (2, n) points inside.
copymethod#
def copy() -> PolygonCreate a copy of the polygon.
Returns
PolygonPolygon- A new instance of Polygon with the same vertices and boundary conditions.
get_verticesmethod#
def get_vertices() -> PointListReturn the vertices of the polygon.
Returns: list: List of vertices as (x, y) coordinates.
mirrormethod#
def mirror(axis: int, position: float) -> NoneMirror the polygon across a specified axis at a given position.
translatemethod#
def translate(offset: tuple[float, float]) -> NoneTranslate the polygon by the given offset.
Parameters
| Name | Type | Description |
|---|---|---|
offset | tuple | (dx, dy) translation vector. |
Inherited from simgeometry.shapes.Shape2D
plotmethod#
simgeometry.shapes.Shape2DView sourcedef plot(ax: Any = None, **kwargs: Any) -> AnyDraw the shape as filled polygons into ax and return the axes.
Keyword arguments style the polygons (facecolor, alpha, …).
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)Rectangleclass#
simgeometry.objects.rectangleView sourceclass Rectangle(midpoint: tuple | list, side_lengths: tuple, bc: ConfigValue = None, inverted: bool = False)Bases: Shape2D
Represent a rectangular geometry object.
midpointattributeinstance attribute#
midpoint = list(midpoint)side_lengthsattributeinstance attribute#
side_lengths = side_lengthscontainsmethod#
def contains(coords: Array) -> boolCheck if the given coordinates are inside the rectangle.
Parameters: coords (list or tuple): Coordinates for each dimension.
Returns: bool: True if the coordinates are inside the rectangle, False otherwise.
contains_pointsmethod#
def contains_points(points: Array) -> ArrayVectorised :meth:contains: a mask of the (2, n) points inside.
copymethod#
def copy() -> RectangleCreate a copy of the rectangle.
Returns
RectangleRectangle- A new instance of Rectangle with the same midpoint, side lengths, and boundary conditions.
get_verticesmethod#
def get_vertices() -> PointListReturn the vertices that define the object.
mirrormethod#
def mirror(axis: int, position: float) -> NoneMirror the rectangle across a specified axis at a given position.
translatemethod#
def translate(offset: tuple[float, float]) -> NoneTranslate the xyz by the given offset.
Parameters
| Name | Type | Description |
|---|---|---|
offset | tuple | (dx, dy) translation vector. |
Inherited from simgeometry.shapes.Shape2D
plotmethod#
simgeometry.shapes.Shape2DView sourcedef plot(ax: Any = None, **kwargs: Any) -> AnyDraw the shape as filled polygons into ax and return the axes.
Keyword arguments style the polygons (facecolor, alpha, …).
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)Sphereclass#
simgeometry.objects.sphereView sourceclass Sphere(midpoint: list | tuple, radius: float, bc: ConfigValue = None, inverted: bool = False)Bases: Shape3D
Represent a spherical geometry object.
midpointattributeinstance attribute#
midpoint = list(midpoint)radiusattributeinstance attribute#
radius = radiuscontainsmethod#
def contains(coords: Array) -> boolCheck if the given coordinates are inside the sphere.
Parameters: coords (list or tuple): Coordinates for each dimension.
Returns: bool: True if the coordinates are inside the sphere, False otherwise.
contains_pointsmethod#
def contains_points(points: Array) -> ArrayVectorised :meth:contains: a mask of the (3, n) points inside.
copymethod#
def copy() -> SphereCreate a copy of the sphere.
Returns
SphereSphere- A new instance of Sphere with the same midpoint, radius, and boundary conditions.
get_verticesmethod#
def get_vertices(slice_axis: int, slice_position: float) -> ConfigValueGet the vertices of a slice of the sphere 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 circle. If the slice does not intersect the sphere, returns an empty array.
mirrormethod#
def mirror(axis: int, position: float) -> NoneMirror the sphere across a specified axis at a given position.
surface_areamethod#
def surface_area() -> floatCalculate the surface area of the sphere.
translatemethod#
def translate(offset: tuple[float, float]) -> NoneTranslate the xyz by the given offset.
Parameters
| Name | Type | Description |
|---|---|---|
offset | tuple | (dx, dy) translation vector. |
volumemethod#
def volume() -> floatCalculate the volume of the sphere.
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)plotmethod#
simgeometry.api.GeometryAPIView sourcedef plot(ax=None, **kwargs)Draw without displaying and return axes for composition.
rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)Triangleclass#
simgeometry.objects.triangleView sourceclass Triangle(vertices: Vertices2DLike, bc: ConfigValue = None, inverted: bool = False)Bases: Shape2D
Represent a triangular geometry object.
containsmethod#
def contains(coords: Array) -> boolCheck if the given coordinates are inside the (possibly inverted) triangle.
Parameters: coords (list or tuple): Coordinates (x, y).
Returns: bool: True if the point is inside the object, False otherwise.
contains_pointsmethod#
def contains_points(points: Array) -> ArrayVectorised :meth:contains: a mask of the (2, n) points inside.
copymethod#
def copy() -> TriangleCreate a copy of the triangle.
Returns
TriangleTriangle- A new instance of Triangle with the same vertices and boundary conditions.
get_verticesmethod#
def get_vertices() -> ConfigValueReturn the vertices of the polygon.
Returns: list: List of vertices as (x, y) coordinates.
mirrormethod#
def mirror(axis: int, position: float) -> NoneMirror the triangle across a specified axis at a given position.
translatemethod#
def translate(offset: tuple[float, float]) -> NoneTranslate the xyz by the given offset.
Parameters
| Name | Type | Description |
|---|---|---|
offset | tuple | (dx, dy) translation vector. |
Inherited from simgeometry.shapes.Shape2D
plotmethod#
simgeometry.shapes.Shape2DView sourcedef plot(ax: Any = None, **kwargs: Any) -> AnyDraw the shape as filled polygons into ax and return the axes.
Keyword arguments style the polygons (facecolor, alpha, …).
Inherited from simgeometry.shapes.Shape
ndimattributeinstance attribute#
simgeometry.shapes.ShapeView sourcendim = ndimbounding_boxproperty#
simgeometry.shapes.ShapeView sourcebounding_box: BoundingBoxReturn the bounding box.
invertedproperty#
simgeometry.shapes.ShapeView sourceinverted: boolReturn whether this object represents an inverted region.
lower_boundproperty#
simgeometry.shapes.ShapeView sourcelower_bound: tuple[float, ...]Return the lower coordinate bounds.
upper_boundproperty#
simgeometry.shapes.ShapeView sourceupper_bound: tuple[float, ...]Return the upper coordinate bounds.
get_bound_verticesmethod#
simgeometry.shapes.ShapeView sourcedef get_bound_vertices(slice_axis: int) -> xp.ndarrayReturn vertices that bound the shape.
get_indices_in_objectmethod#
simgeometry.shapes.ShapeView sourcedef 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 :attr:Grid.indices of the nodes inside, in their order.
node_maskmethod#
simgeometry.shapes.ShapeView sourcedef node_mask(grid: Grid) -> np.ndarrayReturn a host boolean array of the grid’s shape, set at the nodes inside.
One vectorised :meth:contains_points over :meth:Grid.node_points, so
the cost is that of a few array passes over the grid.
set_bounding_boxmethod#
simgeometry.shapes.ShapeView sourcedef set_bounding_box(lower_bound: tuple[float, ...], upper_bound: tuple[float, ...]) -> NoneSet the bounding box for the shape.
Inherited from simgeometry.api.GeometryAPI
cell_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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.
cut_edgesmethod#
simgeometry.api.GeometryAPIView sourcedef cut_edges(grid, **kwargs)Locate all detected grid-edge surface hits, without solver clamping.
diagnosemethod#
simgeometry.api.GeometryAPIView sourcedef diagnose(grid, **kwargs)Report sampled overlaps, unresolved components, and short cut distances.
differencemethod#
simgeometry.api.GeometryAPIView sourcedef difference(other)evaluatemethod#
simgeometry.api.GeometryAPIView sourcedef 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), or signed_distance.
This is a local host operation, with no implicit MPI collectives.
exportmethod#
simgeometry.api.GeometryAPIView sourcedef export(path, **kwargs)Export a sampled mesh as NPZ, OBJ, or STL (3D only).
intersect_segmentmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef intersection(other)rotatedmethod#
simgeometry.api.GeometryAPIView sourcedef rotated(angle, *, axis=(0, 0, 1), origin=None)Return a rotated snapshot; angle is in degrees, about origin (default 0).
sample_interiormethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef sample_surface(count, *, rng=None, resolution=64, bounds=None)Uniform-by-length/area samples from the faceted boundary mesh.
scaledmethod#
simgeometry.api.GeometryAPIView sourcedef scaled(factors, *, origin=None)Return a snapshot scaled by a nonzero scalar or per-axis factors.
showmethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef signed_distance(points, *, resolution=64, bounds=None)Distance to the boundary, negative inside, positive outside.
Exact for balls, boxes and simple polygons; otherwise distance to the sampled surface mesh. A membership function is not itself a distance.
slicemethod#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef 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#
simgeometry.api.GeometryAPIView sourcedef transformed(matrix, offset=None)Return an affine-transformed snapshot; the source is unchanged.
translatedmethod#
simgeometry.api.GeometryAPIView sourcedef translated(offset)Return a translated snapshot (unlike legacy in-place translate).
unionmethod#
simgeometry.api.GeometryAPIView sourcedef union(other)