simgeometry.collection
Named collections with explicit overlap precedence, display styles and voltages.
Attributes
| Name | Description |
|---|---|
Voltage | No description. |
Classes
| Name | Description |
|---|---|
DirichletValues | The object and the voltage at each point of GeometryCollection.dirichlet_values. |
GeometryCollection | Named objects; last listed object wins labels in overlaps. |
DirichletValuesclassdataclass#
class DirichletValues(labels: np.ndarray, voltages: np.ndarray, names: tuple[str, ...])The object and the voltage at each point of GeometryCollection.dirichlet_values.
labels are the collection’s labels (0 outside every object, i inside
names[i - 1], the last listed object winning in overlaps). voltages is the
voltage of that object at the requested time, NaN outside every object and inside
objects without a voltage. Both have the shape of the grid, or (n,) for points.
labelsattributeinstance attribute#
labels: np.ndarraynamesattributeinstance attribute#
names: tuple[str, ...]voltagesattributeinstance attribute#
voltages: np.ndarrayconductorproperty#
conductor: np.ndarrayWhere a point is inside a conductor, so its voltage is fixed.
GeometryCollectionclass#
class GeometryCollection(objects, *, bounds=None, styles=None, voltages=None)Bases: Shape
Named objects; last listed object wins labels in overlaps.
Label 0 is background, labels 1..N follow insertion order. Styles map object names to plotting keyword dictionaries. Explicit bounds also permit an empty collection and define the default viewing/sampling region, without clipping object membership. Collection objects are references, not snapshots.
voltages makes named objects conductors: it maps names to a voltage, either a
number or a function of the time t (a ramped or RF electrode). Objects without
a voltage are not conductors. with_voltages returns the same geometry with
other voltages, voltages_at evaluates them at a time and
dirichlet_values gives the voltage at points or grid nodes.
The level set, when every object has one, is the minimum of theirs (the union).
Numerics
labels
level set
dirichlet
Assumptions:
- objects in insertion order: the last listed object wins overlaps, also one without a voltage
- the level set, when every object has one, is that of the union: a bound on the distance
level_set_exactattributeclass attributeinstance attribute#
level_set_exact = Falsenamed_objectsattributeinstance attribute#
named_objects = dict(objects)namesattributeinstance attribute#
names = tuple(self.named_objects)objectsattributeinstance attribute#
objects = list(self.named_objects.values())stylesattributeinstance attribute#
styles = dict(styles or {})voltagesattributeinstance attribute#
voltages = self._checked_voltages(voltages or {})conductorsproperty#
conductorsNames of the objects with a voltage, in insertion order.
has_level_setproperty#
has_level_setWhether every object has a level set.
containsmethod#
def contains(coords)contains_pointsmethod#
def contains_points(points)dirichlet_valuesmethod#
def dirichlet_values(where, *, t=0.0)The label and the voltage of the object at each point, for Dirichlet nodes.
where is a Grid (results have its shape) or
(ndim, n) points. Returns DirichletValues; a point outside every
conductor has a NaN voltage. Overlaps follow labels: the last listed
object wins, even if it is not a conductor.
evaluatemethod#
def evaluate(*args, quantity='labels', **kwargs)labelsmethod#
def labels(points)Integer object identities for (ndim, n) points; last object wins.
level_setmethod#
def level_set(points)The minimum of the objects’ level sets: the level set of their union.
voltages_atmethod#
def voltages_at(t=0.0)The voltage of every conductor at time t, as {name: float}.
with_voltagesmethod#
def with_voltages(voltages=None, /, **overrides)The same objects, bounds and styles with some voltages replaced.
voltages (a mapping, for any name) and keyword arguments set the voltage of
those objects; None removes it. The geometry is shared, not rebuilt, so
each run of a parameter scan can set its own voltages cheaply::
lens = electrodes.with_voltages(focus=500.0)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 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 contains_points over 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.
crossingsmethod#
simgeometry.api.GeometryAPIView sourcedef crossings(start, end, *, samples=64, iterations=40)First boundary crossing of every segment start[:, i] -> end[:, i].
start and end are (ndim, N), such as particle positions before and
after a step. Returns a Crossings with hit,
fraction, point and normal (out of the region where contains is
true) on the active array backend. Polygons, circles, spheres, boxes and their
affine transforms are analytic; other shapes sample samples points per
segment and bisect iterations times, or refine on their level set (with its
gradient as the normal) if they have one.
cut_edgesmethod#
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)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)level_set_fieldmethod#
simgeometry.api.GeometryAPIView sourcedef level_set_field(resolution=64, bounds=None)The level set on a 3D grid, laid out for plasma-plots’ 3D views.
shape.level_set_field().plasma.plot.isosurface(values=[0]) draws the
surface (requires the interactive extra and import plasma_plots).
plotmethod#
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, simple polygons and every shape whose level set is
exact (level_set_exact, such as cylinders, tubes, cones, tori and their
rigid motions), which it returns directly; otherwise distance to the
sampled surface mesh. A membership function is not itself a distance.
slicemethod#
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)yee_fractionsmethod#
simgeometry.api.GeometryAPIView sourcedef yee_fractions(grid, **kwargs)Edge-length and face-area fractions of a Yee grid, and the surface’s traces.
Exact for planes; see simgeometry.fractions.yee_fractions.