3 Simulation Environments (Basic)
A simulation environment encapsulates the state of an executing simulation model. This state information includes the following:
Current simulation time
Now, continuous, and future event lists
Main loop and exit continuations
Process and event being executed
Environment hierarchy
Ordinary differential equation (ODE) solver state
Simulation monitoring hooks
The Simulation Collection supports multiple simulation environments existing at the same time. This is useful in implementing various simulation techniques:
Nested simulation environments are useful for data collections across multiple simulation model runs. Typically, the outer simulation model defines the global simulation data to be collected across the model runs. It then executes the inner simulation model(s) multiple times and updates the global simulation data with the results of each run. See the Open Loop and Closed Loop examples in Section 8.6, Data Collection Across Multiple Runs for examples.
Nested simulation environments can be used to allow a lower fidelity (but faster) simulation model to reach a steady state before switching to a higher fidelity simulation model.
Multiple simulation can facilitate the development of multiple, independent (or cooperating) simulation models as part of a larger system. See Section 15, Simulation Components, for examples.
Hierarchical simulation environments allow partitioning of simulation element within a simulation model. Hierarchical simulation models are described in Chapter 14.
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.
running?—
true, #t, if the simulation main loop is running in this simulation environment and false, #f, otherwise. time—
the simulation clock for the simulation model. now-event-list—
an event list containing the events to be executed now, i.e. before the simulation clock is advanced. future-event-list—
an event list containing the events to be executed in the (simulated) future, i.e. the simulation clock is advanced before the next of these future events is executed. loop-next—
the continuation to return to the simulation main loop that is running in this simulation environment. Calling this continuation signifies the end of process of the current event. This field is false, #f, if the simulation main loop is not running in this simulation environment. loop-exit—
the continuation to exit the simulation main loop that is running in this simulation environment. Calling this continuation signifies the end of the execution of the simulation model. This field is false, #f, if the simulation main loop is not running in this simulation environment. event—
the event currently being executed in the simulation environment or false, #f. process—
the process currently being executed in the simulation environment or false, #f. parent—
the parent simulation environment of this simulation environment. (See Chapter 14, Hierarchical Environments). children—
a list of the children simulation environments of this simulation environment. (See Chapter 14, Hierarchical Environments) continuous-event-list—
the event list containing the events to be executed continuously. (See Chapter 10, Continuous Simulation Models) evolve—
the ordinary differential equation evolver object. This is created internally. (See Chapter 11, Continuous Simulation Models) control—
the ordinary differential equation control object or false, #f, for fixed step size. This may be specified by the user. (See Chapter 11, Continuous Simulation Models) step-type—
the ordinary differential equation step-type object. This may be specified by the user. (See Chapter 11, Continuous Simulation Models) step—
the ordinary differential equation stepper object. This is created internally. (See Chapter 11, Continuous Simulation Models) system—
the ordinary differential equation system of equations. This is created internally from the continuous variables in the processes currently working continuously (i.e. on the continuous event list). (See Chapter 11, Continuous Simulation Models) step-size—
the current (last) step size for the ordinary differential equation solver. If the control field is false, #f, this specifies the fixed step size. Otherwise, it is controlled by the control object. (See Chapter 11, Continuous Simulation Models) dimension—
the dimensionality of the system of equations for the ordinary differential equation solver. This is set internally. (See Chapter 11, Continuous Simulation Models) y—
the state vector for the system of equations for the ordinary differential equation solver. This is created internally from the continuous variables in the processes currently working continuously (i.e. on the continuous event list). (See Chapter 11 Continuous Simulation Models) dydt—
the derivative vector for the system of equations for the ordinary differential equation solver. This is created internally from the continuous variables in the processes currently working continuously (i.e. on the continuous event list). (See Chapter 11, Continuous Simulation Models) state-changed?—
true, #t, if the system of equations for the ordinary differential equation solver has changed and false, #f, otherwise. This is created internally. (See Chapter 11, Continuous Simulation Models) max-step-size—
the limit on the step size for the ordinary differential equation solver. This may be specified by the user. (See Chapter 11, Continuous Simulation Models) monitor—
a procedure that, if specified, is executed prior to advancing the simulation clock. (See Chapter 9, Monitors) requeue-cont—
the continuation to requeue an interprocess communication (i.e., a rendezvous). This is maintained internally.
(make-simulation-environment [parent]) → simulation-environment? parent : (or/c simulation-environment? false/c) = #f
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?
(with-simulation-environment env body ...+)
(with-new-simulation-environment body ...+)
(with-new-child-simulation-environment body ...+)
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?
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)
(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)
(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)
(current-simulation-loop-next loop-next) → void? loop-next : (or/c procedure? false/c) (current-simulation-loop-next) → (or/c procedure? false/c)
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)
(current-simulation-event event) → void? event : (or/c event? false/c) (current-simulation-event) → (or/c procedure? false/c)
(current-simulation-process process) → void? process : (or/c process? false/c) (current-simulation-process) → (or/c procedure? false/c)
(current-simulation-parent parent) → void? parent : (or/c simulation-environment? false/c) (current-simulation-parent) → (or/c simulation-environment? false/c)
(current-simulation-children children) → void? children : (listof simulation-environment?) (current-simulation-children) → (listof 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)
(current-simulation-evolve evolve) → void? evolve : (or/c ode-evolve? false/c) (current-simulation-evolve) → (or/c ode-evolve? false/c)
(current-simulation-control control) → void? control : (or/c ode-control? false/c) (current-simulation-control) → (or/c ode-control? false/c)
(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)
(current-simulation-step step) → void? step : (or/c ode-step? false/c) (current-simulation-step) → (or/c ode-step? false/c)
(current-simulation-system system) → void? system : (or/c ode-system? false/c) (current-simulation-system) → (or/c ode-system? false/c)
(current-simulation-step-size step-size) → void? step-size : (>/c 0.0) (current-simulation-step-size) → (>/c 0.0)
(current-simulation-dimension dimension) → void? dimension : natural-number/c (current-simulation-dimension) → natural-number/c
(current-simulation-y y) → void? y : (or/c (vector-of real?) false/c) (current-simulation-y) → (or/c (vector-of real?) false/c)
(current-simulation-dydy dydt) → void? dydt : (or/c (vector-of real?) false/c) (current-simulation-dydt) → (or/c (vector-of real?) false/c)
(current-simulation-state-changed? state-changed?) → void? state-changed? : boolean? (current-simulation-state-changed?) → boolean?
(current-simulation-max-step-size max-step-size) → void? max-step-size : (>/c 0.0) (current-simulation-max-step-size) → (>/c 0.0)
See Chapter 9, Monitors for more information on the use of simulation monitors.
(current-simulation-monitor monitor) → void? monitor : procedure? (current-simulation-monitor) → procedure?
(current-simulation-requeue-cont requeue-cont) → void? requeue-cont : (or/c continuation? false/c) (current-simulation-requeue-cont) → (or/c continuation? false/c)