Module phi.physics.sph

Tools for running Smoothed Particle Hydrodynamics (SPH) simulations.

  1. Create particles as a Geometry collections.
  2. Use neighbor_graph() to find neighbor particles and compute kernel weights.
  3. Use custom function or built-in physics operations to integrate the dynamics.

Functions

def evaluate_kernel(delta, distance, h, spatial_rank: int, kernel: str, types: Sequence[str] = ('kernel',)) ‑> Dict[str, phiml.math._tensors.Tensor]

Compute the SPH kernel value or a derivative of the kernel function.

For kernels that only depends on the squared distance, such as poly6, the distance variable is not used. Instead, the squared distance is derived from delta.

Args

delta
Vectors to neighbors, i.e. position differences.
distance
Scalar distance to neighbors.
h
Support radius / smoothing length / maximum distance / cutoff.
spatial_rank
Dimensionality of the simulation.
kernel
Which kernel to use, one of 'quintic-spline', 'wendland-c2', 'poly6'.
types
Ordered tuple of derivatives to compute, 'kernel', 'grad', 'laplace'.

Returns

phi.math.Tensor

def expected_neighbors(volume: phiml.math._tensors.Tensor, support_radius, spatial_rank: int)

Given the average element volume and support radius, returns the average number of neighbors for a region filled with particles.

Args

volume
Average particle volume.
support_radius
Other elements are considered neighbors if their center lies within a sphere of this radius around a particle.
spatial_rank
Spatial rank of the simulation.

Returns

Number of expected neighbors.

def neighbor_graph(nodes: phi.geom._geom.Geometry, kernel: str, boundary: Dict[str, Dict[str, slice]] = None, desired_neighbors: float = None, compute: str = 'kernel,grad', format='sparse', search_method='auto', domain: phi.geom._box.Box = None, periodic: Union[bool, phiml.math._tensors.Tensor] = False) ‑> phi.geom._graph.Graph

Build a Graph based on proximity of nodes and evaluates the kernel function.

Args

nodes
Particles including obstacle particles as Geometry collection.
kernel
Kernel function to evaluate.
boundary
Marks ranges of nodes as boundary particles, see Graph.
desired_neighbors
Target average number of neighbors per particle. This determines the support radius (cutoff) used.
compute
Comma-separated str of kernel properties to compute on the graph edges. Can contain 'kernel', 'grad', 'laplace'. If no kernel property is given, the edge values will be set to the inverse distance between nodes instead.
format
Sparse format in which store neighborhood information. Allowed strings are 'dense','csr', 'coo', 'csc'`.
search_method
Neighborhood search method, see phi.math.pairwise_differences.
domain
(Optional) Specify a fixed domain size in which the centers of all nodes must be located. This is required for periodic domains.
periodic
Which domain boundaries should be treated as periodic, i.e. particles on opposite sides are neighbors. Can be specified as a bool for all sides or as a vector-valued boolean Tensor to specify periodicity by direction.

Returns

Graph with edge values storing the kernel values, i.e. the interaction strength between particles.