The mathematical model of a simulation.

To communicate its state to the outside world, a Simulation contains a SimList to which are added SimObject's like PointMass, Spring, etc.

An AdvanceStrategy moves the Simulation forward in time, by solving the mathematical model for the next small increment in time. The method modifyObjects is called separately to ensure the SimObjects match the new Simulation state.

A Simulation usually keeps track of the current time, see getTime. There are no explicit units for the time, so you can regard a time unit as seconds or years as desired. See About Units Of Measurement. Changing the Simulation time by a large amount can affect synchronization with the Clock used to advance the Simulation; see SimRunner section How Simulation Advances with Clock.

A Simulation can store its initial state with saveInitialState and return to that initial state with reset. The current time is saved with the initial state.

interface Simulation {
    addObserver(observer): void;
    broadcast(evt): void;
    broadcastParameter(name): void;
    getName(): string;
    getObservers(): Observer[];
    getParameter(name): Parameter;
    getParameterBoolean(name): ParameterBoolean;
    getParameterNumber(name): ParameterNumber;
    getParameterString(name): ParameterString;
    getParameters(): Parameter[];
    getSimList(): SimList;
    getTime(): number;
    modifyObjects(): void;
    removeObserver(observer): void;
    reset(): void;
    saveInitialState(): void;
    toStringShort(): string;
}

Hierarchy (view full)

Implemented by

Methods

  • Adds the given Observer to this Subject's list of Observers, so that the Observer will be notified of changes in this Subject. An Observer may call Subject.addObserver during its observe method.

    Parameters

    Returns void

  • Notifies all Observers that the Parameter with the given name has changed by calling observe on each Observer.

    Parameters

    • name: string

      the language-independent or English name of the Parameter that has changed

    Returns void

    Throws

    if there is no Parameter with the given name

  • Return the language-independent name of this Subject for scripting purposes.

    Returns string

    name the language-independent name of this Subject

  • Returns the Parameter with the given name.

    Parameters

    • name: string

      the language-independent or English name of the Parameter

    Returns Parameter

    the Parameter with the given name

    Throws

    if there is no Parameter with the given name

  • Returns the current Simulation time.

    Returns number

    the current Simulation time.

    Throws

    if there is no time variable for the simulation

  • Updates the SimObjects to match the current internal state of the Simulation.

    Returns void

  • Removes the Observer from this Subject's list of Observers. An Observer may call removeObserver during its observe method.

    Parameters

    • observer: Observer

      the Observer to detach from list of Observers

    Returns void

  • Saves the current variables and time as the initial state, so that this initial state can be restored with reset. Broadcasts event named 'INITIAL_STATE_SAVED'.

    Returns void

  • Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.

    For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling toStringShort on that other object. For example, calling toStringShort() on a DisplayShape might return something like this:

    DisplayShape{polygon:Polygon{'chain3'}}
    

    Returns string

    a minimal string representation of this object.

Generated using TypeDoc