Back to module page · Back to alphabetical overview
Signature¶
AnalyticParticle(level_func, bounding_box, position, orientation = None, normal_func = None)
Summary¶
Particle from a user-supplied body-frame level function.
Documentation¶
Parameters¶
level_func(callable)level_func(coords) -> valueswithcoordsshaped (..., ndim); negative inside, positive outside, approximately a distance near the surface.bounding_box(tuple of (lo, hi)) Body-frame box containing the particle surface.position, orientation(seeParticle.)normal_func(callable, optional) Body-frame outward normal direction (need not be normalised); default: finite differences of level_func.
Source¶
class AnalyticParticle(Particle):
"""Particle from a user-supplied body-frame level function.
Parameters
----------
level_func : callable
``level_func(coords) -> values`` with ``coords`` shaped (..., ndim);
negative inside, positive outside, approximately a distance near the
surface.
bounding_box : tuple of (lo, hi)
Body-frame box containing the particle surface.
position, orientation : see :class:`Particle`.
normal_func : callable, optional
Body-frame outward normal direction (need not be normalised);
default: finite differences of *level_func*.
"""
def __init__(self, level_func, bounding_box, position, orientation=None,
normal_func=None):
super().__init__(position, orientation)
self._level_func = level_func
self._box = tuple((float(lo), float(hi)) for lo, hi in bounding_box)
if len(self._box) != self.ndim:
raise ValueError("bounding_box length must equal len(position)")
self._normal_func = normal_func
def level_body(self, coords):
return np.asarray(self._level_func(np.asarray(coords, dtype=float)))
def normal_body(self, coords):
if self._normal_func is None:
return super().normal_body(coords)
return np.asarray(self._normal_func(np.asarray(coords, dtype=float)))
def bounding_box_body(self):
return self._boxMembers¶
__init__(level_func, bounding_box, position, orientation = None, normal_func = None)¶
bounding_box(pad = 0.0)¶
World axis-aligned bounding box ((lo, hi), ...) per axis.
bounding_box_body()¶
Body-frame bounding box ((lo, hi), ...) per axis.
intersect(p0, p1)¶
Surface crossing fraction t on the segments p0 → p1.
p0/p1 are (n, ndim) batches whose endpoints straddle the
surface (level(p0) and level(p1) of opposite sign); returns
t in (0, 1) with level(p0 + t (p1 - p0)) == 0. Default:
vectorised bisection on level; shapes with closed-form
intersections override this.
level(coords)¶
Signed level function at world coords shaped (..., ndim).
level_body(coords)¶
Signed level function at body-frame coords shaped (..., ndim).
normal(coords)¶
Outward (solid→fluid) unit normal at world surface points.
normal_body(coords)¶
Gradient direction of level_body (finite differences).