On this page:
3.1 The simulation-environment Structure
make-simulation-environment
default-simulation-environment
3.2 Current Simulation Environment
current-simulation-environment
with-simulation-environment
with-new-simulation-environment
3.3 Current Simulation Environment Fields
current-simulation-running?
current-simulation-time
current-simulation-now-event-list
current-simulation-future-event-list
current-simulation-loop-next
current-simulation-loop-exit
current-simulation-event
current-simulation-process
current-simulation-parent
current-simulation-children
current-simulation-continuous-event-list
current-simulation-evolve
current-simulation-control
current-simulation-step-type
current-simulation-step
current-simulation-system
current-simulation-step-size
current-simulation-dimension
current-simulation-y
current-simulation-dydy
current-simulation-dydt
current-simulation-state-changed?
current-simulation-max-step-size
current-simulation-monitor
Version: 4.1.3

3 Simulation Environments (Basic)

    3.1 The simulation-environment Structure

    3.2 Current Simulation Environment

    3.3 Current Simulation Environment Fields

A simulation environment encapsulates the state of an executing simulation model. This state information includes the following:

The PLT Scheme Simulation Collection supports multiple simulation environments existing at the same time. This is useful in implementing various simulation techniques:

This chapter describes the basic features of basic simulation environment.

3.1 The simulation-environment Structure

The simulation-environment structure defines a simulation environment.

  (struct simulation-environment (running?
                                  time
                                  now-event-list
                                  future-event-list
                                  loop-next
                                  loop-exit
                                  event
                                  process
                                  parent
                                  children
                                  continuous-event-list
                                  evolve
                                  control
                                  step-type
                                  step
                                  system
                                  step-size
                                  dimension
                                  y
                                  dydt
                                  state-changed?
                                  max-step-size
                                  monitor))
  
    running? : boolean?
    time : (>=/c 0.0)
    now-event-list : event-list?
    future-event-list : event-list?
    loop-next : (or/c procedure? false/c)
    loop-exit : (or/c procedure? false/c)
    event : (or/c event? false/c)
    process : (or/c process? false/c)
    parent : (or/c simulation-environment? false/c)
    children : (listof simulation-environment?)
    continuous-event-list : event-list?
    evolve : (or/c ode-evolve? false/c)
    control : (or/c ode-control? false/c)
    step-type : (or/c ode-step-type? false/c)
    step : (or/c ode-step? false/c)
    system : (or/c ode-system? false/c)
    step-size : (>/c 0.0)
    dimension : exact-nonnegative-integer?
    y : (vectorof real?)
    dydt : (vectorof real?)
    state-changed? : boolean?
    max-step-size : (>/c 0.0)
    monitor : (or/c procedure? false/c)

See Section 3.3 Current Simulation Environment Fields for more information on accesing the fields of the current simulation environment.

(make-simulation-environment [parent])  simulation-environment?
  parent : (or/c simulation-environment? false/c) = #f

Returns a new simulation environment with the given parent simulation environment. The newly created simulation environment has time = 0.0 and the simulation main loop is not running (i.e. running? = #f, loop-next = #f, loop-exit = #f, event = #f, and process = #f).

default-simulation-environment

Contains the simulation environment that is used as the default value for the current simulation environment (see Section 3.2).

3.2 Current Simulation Environment

The current simulation environment is the simulation environment that is the current focus for most of the simulation calls. It is both thread and continuation specific.

(current-simulation-environment)  simulation-environment?
(current-simulation-environment env)  void?
  env : simulation-environment?

Gets or sets the current simulation environment. A guard procedure ensures that the value of current-simulation-environment is indeed a simulation environment, as derermined by simulation-environment?, otherwise a type error is raised.

(with-simulation-environment env
   body ...+)

Evaluates its body with the current simulation environment bound to the value of env.

(with-new-simulation-environment
   body ...+)

Evaluates its body with the current simulation environment bound to a newly created simulation environment. This is the most common way to create and use a new simulation environment.

3.3 Current Simulation Environment Fields

The most common way of accessing the current simulation environment fields is using the following procedures.

(current-simulation-running? running?)  void?
  running? : boolean?
(current-simulation-running?)  boolean?

Sets or gets the running? field of the current simulation environment.

time is by far the most frequently used field in the current simulation environment. Use (current-simulation-time) to obtain the current simulation time.

(current-simulation-time time)  void?
  time : (>=/c 0.0)
(current-simulation-time)  (>=/c 0.0)

Sets or gets the time field of the current simulation environment.

(current-simulation-now-event-list now-event-list)  void?
  now-event-list : (or/c event-list? false/c)
(current-simulation-now-event-list)
  (or/c event-list? false/c)

Sets or gets the now-event-list field of the current simulation environment.

(current-simulation-future-event-list future-event-list)
  void?
  future-event-list : (or/c event-list? false/c)
(current-simulation-future-event-list)
  (or/c event-list? false/c)

Sets or gets the future-event-list field of the current simulation environment.

(current-simulation-loop-next loop-next)  void?
  loop-next : (or/c procedure? false/c)
(current-simulation-loop-next)  (or/c procedure? false/c)

Sets or gets the loop-next field of the current simulation environment.

Calling (stop-simulation) is the best way to exit the simulation main loop.

(current-simulation-loop-exit loop-exit)  void?
  loop-exit : (or/c procedure? false/c)
(current-simulation-loop-exit)  (or/c procedure? false/c)

Sets or gets the loop-exit field of the current simulation environment.

(current-simulation-event event)  void?
  event : (or/c event? false/c)
(current-simulation-event)  (or/c procedure? false/c)

Sets or gets the event field of the current simulation environment.

(current-simulation-process process)  void?
  process : (or/c process? false/c)
(current-simulation-process)  (or/c procedure? false/c)

Sets or gets the process field of the current simulation environment.

(current-simulation-parent parent)  void?
  parent : (or/c simulation-environment? false/c)
(current-simulation-parent)
  (or/c simulation-environment? false/c)

Sets or gets the parent field of the current simulation environment.

(current-simulation-children children)  void?
  children : (listof simulation-environment?)
(current-simulation-children)
  (listof simulation-environment?)

Sets or gets the children field of the current simulation environment.

See Chapter 11 Continuous Models for more information on the use of these procedures to control the integration loop.

(current-simulation-continuous-event-list continuous-event-list)
  void?
  continuous-event-list : (or/c event-list? false/c)
(current-simulation-continuous-event-list)
  (or/c event-list? false/c)

Sets or gets the continuous-event-list field of the current simulation environment.

(current-simulation-evolve evolve)  void?
  evolve : (or/c ode-evolve? false/c)
(current-simulation-evolve)  (or/c ode-evolve? false/c)

Sets or gets the evolve field of the current simulation environment.

(current-simulation-control control)  void?
  control : (or/c ode-control? false/c)
(current-simulation-control)  (or/c ode-control? false/c)

Sets or gets the control field of the current simulation environment.

(current-simulation-step-type step-type)  void?
  step-type : (or/c ode-step-type? false/c)
(current-simulation-step-type)  (or/c ode-step-type? false/c)

Sets or gets the step-type field of the current simulation environment.

(current-simulation-step step)  void?
  step : (or/c ode-step? false/c)
(current-simulation-step)  (or/c ode-step? false/c)

Sets or gets the step field of the current simulation environment.

(current-simulation-system system)  void?
  system : (or/c ode-system? false/c)
(current-simulation-system)  (or/c ode-system? false/c)

Sets or gets the system field of the current simulation environment.

(current-simulation-step-size step-size)  void?
  step-size : (>/c 0.0)
(current-simulation-step-size)  (>/c 0.0)

Sets or gets the step-size field of the current simulation environment.

(current-simulation-dimension dimension)  void?
  dimension : natural-number/c
(current-simulation-dimension)  natural-number/c

Sets or gets the dimension field of the current simulation environment.

(current-simulation-y y)  void?
  y : (or/c (vector-of real?) false/c)
(current-simulation-y)  (or/c (vector-of real?) false/c)

Sets or gets the y field of the current simulation environment.

(current-simulation-dydy dydt)  void?
  dydt : (or/c (vector-of real?) false/c)
(current-simulation-dydt)  (or/c (vector-of real?) false/c)

Sets or gets the dydt field of the current simulation environment.

(current-simulation-state-changed? state-changed?)  void?
  state-changed? : boolean?
(current-simulation-state-changed?)  boolean?

Sets or gets the state-changed? field of the current simulation environment.

(current-simulation-max-step-size max-step-size)  void?
  max-step-size : (>/c 0.0)
(current-simulation-max-step-size)  (>/c 0.0)

Sets or gets the max-step-size field of the current simulation environment.

See Chapter 9 Monitors for more information on the use of simulation monitors.

(current-simulation-monitor monitor)  void?
  monitor : procedure?
(current-simulation-monitor)  procedure?

Sets or gets the monitor field of the current simulation environment.