Simulation Environments (Basic)
A simulation environment encapsulates the state of an executing simulation model. This state information includes the following:
Time
Now 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 PLT Scheme Simulation Collection supports multiple simulation environments existing at the same time. This is useful for implement various simulation techniques.
Nested simulation environments are useful for data collection across multiple simulation model runs. Typically, an outer simulation model defines the global simulation data to be collected across the model runs. It then executes the inner simulation model 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 also be used to allow a lower fidelity (but faster) simulation model to reach a steady state before starting a higher fidelity simulation model.
Multiple simulation environments can facilitate the development of multiple, independent (or cooperating) simulation models as part of a larger system.
Note that these usages of multiple simulation environments is different than hierarchical simulation environments, which allow partitioning of simulation elements within a simulation model. Hierarchical simulation models are described in Chapter 13.
This section describes the basic features of simuation environments.
3.1 The simulation-environment Structure
Structure:
simulation-environment |
Contract: (struct simulation-environment ((running? boolean?) (time (>=/c 0.0)) (now-event-list event-list?) (future-event-list event-list?) (loop-next (union/c procedure? #f)) (loop-exit (union/c procedure? #f)) (event (union/c event? #f)) (process (union/c process? #f)) (parent (union/c simulation-environment? #f)) (children (list-of simulation-environment?)) (continuous-event-list event-list?) (evolve (union/c ode-evolve? #f)) (control (union/c ode-control? #f)) (step-type (union/c ode-step-type? #f)) (step (union/c ode-step? #f)) (system (union/c ode-system? #f)) (step-size (>/c 0.0)) (dimension (integer-in 0 +inf.0)) (y (vector-of real?)) (dydt (vector-of real?)) (state-changed? boolean?) (max-step-size (>/c 0.0)) (monitor (union/c procedure? #f)))) |
|
Function:
(make-simulation-environment parent) (make-simulation-environment) |
Contract: (case-> (-> simulation-environment? simulation-environment?) (-> simulation-environment?)) |
|
default-simulation-environment
Variable:
default-simulation-environment |
|
3.2 Current Simulation Environment
The current simulation environment is the simulation environment that is the current focus for most of the simulation collection calls. It is both thread and continuation specific.
current-simulation-environment
Function:
(current-simulation-environment env) (current-simulation-environment) |
Contract: (case-> (-> simulation-environment? any) (-> simulation-environmment?)) |
|
Macro:
(with-simulation-environment simulation-environment body ...) |
|
with new-simulation-environment
Macro:
(with-new-simulation-environment body ...) |
|
3.2.1 Current Simulation Environment Fields
Function:
(current-simulation-running? running?) (current-simulation-running?) |
Contract: (case-> (-> boolean? any) (-> boolean?)) |
|
Function:
(current-simulation-time time) (current-simulation-time) |
Contract: (case-> (-> (>=/c 0.0) any) (-> (>=/c 0.0))) |
|
current-simulation-now-event-list
Function:
(current-simulation-now-event-list now-event-list) (current-simulation-now-event-list) |
Contract: (case-> (-> (union/c event-list? #f) any) (-> (union/c event-list? #f))) |
|
current-simulation-future-event-list
Function:
(current-simulation-future-event-list future-event-list) (current-simulation-future-event-list) |
Contract: (case-> (-> (union/c event-list? #f) any) (-> (union/c event-list? #f))) |
|
Function:
(current-simulation-loop-next loop-next) (current-simulation-loop-next) |
Contract: (case-> (-> (union/c procedure? #f) any) (-> (union/c procedure? #f))) |
|
Function:
(current-simulation-loop-exit loop-exit) (current-simulation-loop-exit) |
Contract: (case-> (-> (union/c procedure? #f) any) (-> (union/c procedure? #f))) |
|
Function:
(current-simulation-event event) (current-simulation-event) |
Contract: (case-> (-> (union/c event? #f) any) (-> (union/c event? #f))) |
|
Function:
(current-simulation-process process) (current-simulation-process) |
Contract: (case-> (-> (union/c process? #f) any) (-> (union/c process? #f))) |
|
Function:
(current-simulation-parent parent) (current-simulation-parent) |
Contract: (case-> (-> (union/c simulation-environment? #f) any) (-> (union/c simulation-environment? #f))) |
|
Function:
(current-simulation-children children) (current-simulation-children) |
Contract: (case-> (-> (list-of simulation-environment?) any) (-> (list-of simulation-environment?))) |
|
current-simulation-continuous-event-list
Function:
(current-simulation-continuous-event-list continuous-event-list) (current-simulation-continuous-event-list) |
Contract: (case-> (-> event-list? any) (-> event-list?)) |
|
Function:
(current-simulation-evolve evolve) (current-simulation-evolve) |
Contract: (case-> (-> (union/c ode-evolve? #f) any) (-> (union/c ode-evolve? #f))) |
|
Function:
(current-simulation-control control) (current-simulation-control) |
Contract: (case-> (-> (union/c ode-control? #f) any) (-> (union/c ode-control? #f))) |
|
Function:
(current-simulation-step-type step-type) (current-simulation-step-type) |
Contract: (case-> (-> ode-step-type? any) (-> ode-step-type?)) |
|
Function:
(current-simulation-step step) (current-simulation-step) |
Contract: (case-> (-> (union/c ode-step? #f) any) (-> (union/c ode-step? #f))) |
|
Function:
(current-simulation-system system) (current-simulation-system) |
Contract: (case-> (-> (union/c ode-system? #f) any) (-> (union/c ode-system? #f))) |
|
Function:
(current-simulation-step-size step-size) (current-simulation-step-size) |
Contract: (case-> (-> (>/c 0.0) any) (-> (>/c 0.0))) |
|
Function:
(current-simulation-dimension dimension) (current-simulation-dimension) |
Contract: (case-> (-> natural-number/c any) (-> natural-number/c)) |
|
Function:
(current-simulation-y y) (current-simulation-y) |
Contract: (case-> (-> (union/c (vector-of real?) #f) any) (-> (union/c (vector-of real?) #f))) |
|
Function:
(current-simulation-dydt dydt) (current-simulation-dydt) |
Contract: (case-> (-> (union/c (vector-of real?) #f) any) (-> (union/c (vector-of real?) #f))) |
|
current-simulation-state-changed?
Function:
(current-simulation-state-changed? state-changed?) (current-simulation-state-changed?) |
Contract: (case-> (-> boolean? any) (-> boolean?)) |
|
current-simulation-max-step-size
Function:
(current-simulation-max-step-size max-step-size) (current-simulation-max-step-size) |
Contract: (case-> (-> (>/c 0.0) any) (-> (>/c 0.0))) |
|
Function:
(current-simulation-monitor monitor) (current-simulation-monitor) |
Contract: (case-> (-> (union/c procedure? #f) any) (-> (union/c procedure? #f))) |
|