Simulation
public struct Simulation<F> : Advanceable where F : SimulationFunction
Simulator
simulates changes to a value over time, based on
a function that calculates acceleration after each time step.
The RK4 method is used to integrate the acceleration function.
Constant time steps are not guaranteed elsewhere in the framework. Due to
the nature of dynamic functions, however, it is desirable to maintain
a constant update interval for a dynamic simulation. Simulation
instances maintain their own internal time state. When `advance(elapsed:)
is called on an instance, it may run an arbitrary number of time steps
internally (and call the underlying function as needed) in order to catch
up
to the outside time. It then uses linear interpolation to match the
internal state to the required external time in order to return the most
precise calculations.
-
The function driving the simulation.
Declaration
Swift
public var function: F { get set }
-
Returns
true
if the solver has converged and does not currently need to be advanced on each frame.Declaration
Swift
fileprivate(set) public var hasConverged: Bool
-
Creates a new
DynamicSolver
instance.Declaration
Swift
public init(function: F, value: F.VectorType, velocity: F.VectorType = F.VectorType.zero)
Parameters
function
The function that will drive the simulation.
value
The initial value of the simulation.
velocity
The initial velocity of the simulation.
-
Advances the simulation.
Declaration
Swift
public mutating func advance(by time: Double)
Parameters
elapsed
The duration by which to advance the simulation in seconds.
-
The current value.
Declaration
Swift
public var value: F.VectorType { get set }
-
The current velocity.
Declaration
Swift
public var velocity: F.VectorType { get set }