Skip to main content

Simulation

Trait Simulation 

Source
pub trait Simulation: Debug {
    // Required methods
    fn x(&self, time: f64) -> f64;
    fn dx(&self, time: f64) -> f64;
    fn is_done(&self, time: f64) -> bool;
    fn tolerance(&self) -> Tolerance;
    fn set_tolerance(&mut self, tolerance: Tolerance);
}
Expand description

The base class for all simulations.

A simulation models an object, in a one-dimensional space, on which particular forces are being applied, and exposes:

  • The object’s position, x
  • The object’s velocity, dx
  • Whether the simulation is “done”, is_done

A simulation is generally “done” if the object has, to a given tolerance, come to a complete rest.

The x, dx, and is_done functions take a time argument which specifies the time for which they are to be evaluated. In principle, simulations can be stateless, and thus can be queried with arbitrary times. In practice, however, some simulations are not, and calling any of these functions will advance the simulation to the given time.

As a general rule, therefore, a simulation should only be queried using times that are equal to or greater than all times previously used for that simulation.

Simulations do not specify units for distance, velocity, and time. Client should establish a convention and use that convention consistently with all related objects.

Required Methods§

Source

fn x(&self, time: f64) -> f64

The position of the object in the simulation at the given time.

Source

fn dx(&self, time: f64) -> f64

The velocity of the object in the simulation at the given time.

Source

fn is_done(&self, time: f64) -> bool

Whether the simulation is “done” at the given time.

Source

fn tolerance(&self) -> Tolerance

How close to the actual end of the simulation a value at a particular time must be before is_done considers the simulation to be “done”.

A simulation with an asymptotic curve would never technically be “done”, but once the difference from the value at a particular time and the asymptote itself could not be seen, it would be pointless to continue. The tolerance defines how to determine if the difference could not be seen.

Source

fn set_tolerance(&mut self, tolerance: Tolerance)

Dart’s tolerance setter.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§