On this page:
3.1 The simulation-environment Structure
simulation-environment
make-simulation-environment
default-simulation-environment
3.2 Current Simulation Environment
current-simulation-environment
with-simulation-environment
with-new-simulation-environment
with-new-child-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
current-simulation-requeue-cont

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 Simulation Collection supports multiple simulation environments existing at the same time. This is useful in implementing various simulation techniques:

This chapter describes the 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
    root
    parent
    children
    continuous-event-list
    evolve
    control
    step-type
    step
    system
    step-size
    dimension
    y
    dydt
    state-changed?
    max-step-size
    monitor
    requeue-cont)
  #:mutable)
  running? : boolean?
  time : (>=/c 0.0)
  now-event-list : event-list?
  future-event-list : event-list?
  loop-next : (or/c continuation? false/c)
  loop-exit : (or/c continuation? false/c)
  event : (or/c event? false/c)
  process : (or/c process? false/c)
  root : (or/c simulation-environment? 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-nonegative-integer?
  y : (vectorof inexact-real?)
  dydt : (vectorof inexact-real?)
  state-changed? : boolean?
  max-step-size : (>/c 0.0)
  monitor : (or/c procedure? false/c)
  requeue-cont : (or/c continuation? false/c)

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

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, process = #f), and the other fields at their default values.

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.

Gets or sets the current simulation environment. A guard procedure ensures that the value of current-simulation-environment is indeed a simulation environment as determined 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.

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.

Evaluates its body with the current simulation environment bound to a newly created simulation environment that is a child of the current simulation environment.

3.3 Current Simulation Environment Fields

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

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.

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

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

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.

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

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

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

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.

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.

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

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

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.

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.

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.

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

Sets or gets the requeue-cont field of the current simulation environment.