module Simulation.Aivika.Trans.Statistics.Accumulator
(
TimingStatsAccumulator,
newTimingStatsAccumulator,
timingStatsAccumulated) where
import Simulation.Aivika.Trans.Comp
import Simulation.Aivika.Trans.Simulation
import Simulation.Aivika.Trans.Dynamics
import Simulation.Aivika.Trans.Event
import Simulation.Aivika.Trans.Ref
import Simulation.Aivika.Trans.Statistics
import Simulation.Aivika.Trans.Signal
import Simulation.Aivika.Trans.DES
newtype TimingStatsAccumulator m a =
TimingStatsAccumulator { forall (m :: * -> *) a.
TimingStatsAccumulator m a -> Ref m (TimingStats a)
timingStatsAccumulatedRef :: Ref m (TimingStats a) }
timingStatsAccumulated :: MonadDES m => TimingStatsAccumulator m a -> Event m (TimingStats a)
{-# INLINABLE timingStatsAccumulated #-}
timingStatsAccumulated :: forall (m :: * -> *) a.
MonadDES m =>
TimingStatsAccumulator m a -> Event m (TimingStats a)
timingStatsAccumulated = forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
TimingStatsAccumulator m a -> Ref m (TimingStats a)
timingStatsAccumulatedRef
newTimingStatsAccumulator :: (MonadDES m, TimingData a) => Signalable m a -> Event m (TimingStatsAccumulator m a)
{-# INLINABLE newTimingStatsAccumulator #-}
newTimingStatsAccumulator :: forall (m :: * -> *) a.
(MonadDES m, TimingData a) =>
Signalable m a -> Event m (TimingStatsAccumulator m a)
newTimingStatsAccumulator Signalable m a
x =
do Double
t0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
a
a0 <- forall (m :: * -> *) a. Signalable m a -> Event m a
readSignalable Signalable m a
x
Ref m (TimingStats a)
r <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef (forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t0 a
a0)
forall (m :: * -> *) a.
MonadDES m =>
Signal m a -> (a -> Event m ()) -> Event m ()
handleSignal_ (forall (m :: * -> *) a. MonadDES m => Signalable m a -> Signal m a
signalableChanged Signalable m a
x) forall a b. (a -> b) -> a -> b
$ \a
a ->
do Double
t <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
forall (m :: * -> *) a.
MonadDES m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef Ref m (TimingStats a)
r forall a b. (a -> b) -> a -> b
$ forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats Double
t a
a
forall (m :: * -> *) a. Monad m => a -> m a
return TimingStatsAccumulator { timingStatsAccumulatedRef :: Ref m (TimingStats a)
timingStatsAccumulatedRef = Ref m (TimingStats a)
r }