aivika-6.1.1: A multi-method simulation library
CopyrightCopyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com>
LicenseBSD3
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Simulation.Aivika.Var

Description

Tested with: GHC 8.0.1

This module defines a variable that is bound up with the event queue and that keeps the history of changes storing the values in arrays, which allows using the variable in differential and difference equations of System Dynamics within hybrid discrete-continuous simulation.

Because of using the arrays, it would usually be a logical mistake to use this variable for collecting statistics. In most cases, the statistics can actually be collected with a very small footprint by updating immutable SamplingStats and TimingStats values in a mutable Ref reference.

Synopsis

Documentation

data Var a Source #

Like the Ref reference but keeps the history of changes in different time points. The Var variable is safe to be used in the hybrid discrete-continuous simulation. Only this variable is much slower than the reference.

For example, the memoised values of the variable can be used in the differential and difference equations of System Dynamics, while the variable iself can be updated within the discrete event simulation.

Because of using arrays under the hood, it would usually be a logical mistake to use the variable for collecting statistics. In most cases, the statistics can actually be collected with a very small footprint by updating immutable SamplingStats and TimingStats values in a mutable Ref reference.

Instances

Instances details
ResultComputing Var Source # 
Instance details

Defined in Simulation.Aivika.Results

(ResultItemable (ResultValue a), ResultItemable (ResultValue (SamplingStats a))) => ResultProvider (Var (SamplingCounter a)) Source # 
Instance details

Defined in Simulation.Aivika.Results

(ResultItemable (ResultValue a), ResultItemable (ResultValue (TimingStats a))) => ResultProvider (Var (TimingCounter a)) Source # 
Instance details

Defined in Simulation.Aivika.Results

(Ix i, Show i, ResultItemable (ResultValue [e])) => ResultProvider (Var (Array i e)) Source # 
Instance details

Defined in Simulation.Aivika.Results

ResultItemable (ResultValue [e]) => ResultProvider (Var (Vector e)) Source # 
Instance details

Defined in Simulation.Aivika.Results

ResultItemable (ResultValue a) => ResultProvider (Var a) Source # 
Instance details

Defined in Simulation.Aivika.Results

varChanged :: Var a -> Signal a Source #

Return a signal that notifies about every change of the variable state.

varChanged_ :: Var a -> Signal () Source #

Return a signal that notifies about every change of the variable state.

newVar :: a -> Simulation (Var a) Source #

Create a new variable.

readVar :: Var a -> Event a Source #

Read the recent actual value of a variable for the requested time.

This computation is destined to be used within discrete event simulation.

varMemo :: Var a -> Dynamics a Source #

Read the first actual, i.e. memoised, value of a variable for the requested time actuating the current events from the queue if needed.

This computation can be used in the ordinary differential and difference equations of System Dynamics.

writeVar :: Var a -> a -> Event () Source #

Write a new value into the variable.

modifyVar :: Var a -> (a -> a) -> Event () Source #

Mutate the contents of the variable.

freezeVar :: Var a -> Event (Array Int Double, Array Int a, Array Int a) Source #

Freeze the variable and return in arrays the time points and the corresponding first and last values when the variable had changed or had been memoised in different time points: (1) the time points are sorted in ascending order; (2) the first and last actual values per each time point are provided.

If you need to get all changes including those ones that correspond to the same simulation time points then you can use the newSignalHistory function passing in the varChanged signal to it and then call function readSignalHistory.