Skip to content

Fluid

Source: fluid.h

Fluid

class Fluid
src/light/powerfunctions/fluid.h:16

A stable-fluid velocity field: the medium itself, simulated rather than sampled.

Its velocity is state that evolves from its own past, so a vortex forms because the maths says it must. Stam's solver, in fixed point because the render path is integer.

The four-step frame order and why sixteen fraction bits: power-functions.md#the-fluid-solver

Public Methods

inline explicit Fluid(MoonModule & owner)

inline bool resize(lengthType w, lengthType h, lengthType d = 1) : Size (or free) the grids. Returns whether a field is available, which is what an effect reports.

inline void release() : Drop every field, returning the solver to its unsized state.

inline void reset() : Re-seed to rest: every velocity zero. The resync point, for a fixture that has been reconfigured under a running simulation.

inline bool valid() const : Ready to step. Read from the buffers, not from a cached shape.

inline lengthType width() const : The grid's width in cells.

inline lengthType height() const : Its height in cells.

inline lengthType depth() const : How many slices it carries.

inline size_t plane() const : Cells per slice: a slice's fields start at z * plane() in [velocityX()]/velocityY().

inline const int32_t * velocityX() const : The x velocity field, one Q16.16 value per cell.

inline const int32_t * velocityY() const : The y velocity field, laid out the same way.

inline void addVelocity(lengthType x, lengthType y, int32_t dvx, int32_t dvy, lengthType z = 0) : Push the medium at one cell. The source term: an emitter, a control, a beat.

inline void step(int32_t viscosity, int32_t dt, uint8_t iterations) : One frame of the simulation. viscosity and dt are Q16.16.

Public Static Attributes

constexpr int32_t kOne = 1 << 16 : Q16.16: the fixed-point format the whole solver works in.