aivika-1.2: A multi-paradigm simulation library

CopyrightCopyright (c) 2009-2013, David Sorokin <david.sorokin@gmail.com>
LicenseBSD3
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell98

Simulation.Aivika.Var

Description

Tested with: GHC 7.6.3

This module defines a variable that is bound up with the event queue and that keeps the history of changes storing the values in an array, which allows using the variable in differential and difference equations under some conditions.

Synopsis

Documentation

data Var a Source

Like the Ref reference but keeps the history of changes in different time points. The Var variable is usually safe in the hybrid simulation, for example, when it can be used in the differential or difference equations unless you update the variable twice in the same integration time point. Only this variable is much slower than the reference.

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 value of a variable.

It is safe to run the resulting computation with help of the runEventWith function using modes CurrentEventsOrFromPast and EarlierEventsOrFromPast, which is necessary if you are going to use the variable in the differential or difference equations. Only it is preferrable if the variable is not updated twice in the same integration time point; otherwise, different values can be returned for the same point.

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) Source

Freeze the variable and return in arrays the time points and corresponded values when the variable had changed in different time points: (1) the last actual value per each time point is provided and (2) the time points are sorted in ascending order.

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.