aivika-lattice 0.1 → 0.1.1
raw patch · 6 files changed
+104/−18 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Simulation.Aivika.Lattice.Estimate: latticeTimeStep :: Parameter LIO Double
+ Simulation.Aivika.Lattice.Estimate: estimateAt :: Int -> Int -> Estimate LIO a -> Estimate LIO a
+ Simulation.Aivika.Lattice.Estimate: shiftEstimate :: Int -> Int -> Estimate LIO a -> Estimate LIO a
+ Simulation.Aivika.Lattice.LIO: findLatticeTimeIndex :: Double -> Parameter LIO Double
+ Simulation.Aivika.Lattice.LIO: latticeSize :: Parameter LIO Int
+ Simulation.Aivika.Lattice.LIO: latticeTime :: Parameter LIO Double
+ Simulation.Aivika.Lattice.LIO: latticeTimeStep :: Parameter LIO Double
Files
- CHANGELOG.md +10/−0
- Simulation/Aivika/Lattice/Estimate.hs +44/−12
- Simulation/Aivika/Lattice/Internal/Estimate.hs +1/−0
- Simulation/Aivika/Lattice/Internal/LIO.hs +43/−4
- Simulation/Aivika/Lattice/LIO.hs +5/−1
- aivika-lattice.cabal +1/−1
CHANGELOG.md view
@@ -1,4 +1,14 @@ +Version 0.1.1+-----++* Added function shiftEstimate.++* Added functions latticeSize, findLatticeTimeIndex.++* Added function estimateAt.++ Version 0.1 -----
Simulation/Aivika/Lattice/Estimate.hs view
@@ -10,8 +10,8 @@ -- The module defines the 'Estimate' monad transformer which is destined for estimating -- computations within lattice nodes. Such computations are separated from the 'Event' -- computations. An idea is that the forward-traversing 'Event' computations provide with--- something that can be observed, while the backward-traversing 'Estimate' computations--- estimate the received information.+-- something that can be observed, while the 'Estimate' computations estimate the received+-- information and they can be backward-traversing. -- module Simulation.Aivika.Lattice.Estimate (-- * Estimate Monad@@ -19,13 +19,14 @@ EstimateLift(..), runEstimateInStartTime, estimateTime,- latticeTimeStep, -- * Computations within Lattice foldEstimate, memoEstimate, estimateUpSide, estimateDownSide, estimateFuture,+ shiftEstimate,+ estimateAt, -- * Error Handling catchEstimate, finallyEstimate,@@ -71,7 +72,7 @@ -- -- It is merely equivalent to the following definition: ----- @estimateUpSide = estimateFuture 1 0@+-- @estimateUpSide = shiftEstimate 1 0@ -- estimateUpSide :: Estimate LIO a -> Estimate LIO a estimateUpSide m =@@ -90,7 +91,7 @@ -- -- It is merely equivalent to the following definition: ----- @estimateDownSide = estimateFuture 1 1@+-- @estimateDownSide = shiftEstimate 1 1@ -- estimateDownSide :: Estimate LIO a -> Estimate LIO a estimateDownSide m =@@ -105,17 +106,36 @@ invokeEstimate p' m -- | Estimate the computation in the shifted lattice node, where the first parameter--- specifies the positive 'latticeTimeIndex' shift, but the second parameter--- specifies the 'latticeMemberIndex' shift af any sign.+-- specifies the 'latticeTimeIndex' shift of any sign, but the second parameter+-- specifies the 'latticeMemberIndex' shift af any sign too. ----- It allows looking into the future computations. The lattice is constructed in such a way+-- It allows looking into the future or past computations. The lattice is constructed in such a way -- that we can define the past 'Estimate' computation in terms of the future @Estimate@ -- computation. That is the point. ----- Regarding the 'Event' computation, a quite opposite rule is true. The future @Event@ computation--- depends on the past @Event@ computation. But we can update 'Ref' references within+-- Regarding the 'Event' computation, it is quite different. The future @Event@ computation+-- depends strongly on the past @Event@ computations. But we can update 'Ref' references within -- the corresponding discrete event simulation and then read them within the @Estimate@ -- computation, because @Ref@ is 'Observable'.+shiftEstimate :: Int+ -- ^ a shift of the lattice time index+ -> Int+ -- ^ a shift of the lattice member index+ -> Estimate LIO a+ -- ^ the source computation+ -> Estimate LIO a+shiftEstimate di dk m =+ Estimate $ \p ->+ LIO $ \ps ->+ do let ps' = shiftLIOParams di dk ps+ r = pointRun p+ p' <- invokeLIO ps' $+ invokeParameter r+ latticePoint+ invokeLIO ps' $+ invokeEstimate p' m++-- | Like 'shiftEstimate' but only the first argument must be possitive. estimateFuture :: Int -- ^ a positive shift of the lattice time index -> Int@@ -123,10 +143,22 @@ -> Estimate LIO a -- ^ the source computation -> Estimate LIO a-estimateFuture di dk m =+estimateFuture di dk m+ | di <= 0 = error "Expected to see a positive time index shift: estimateFuture"+ | otherwise = shiftEstimate di dk m++-- | Estimate the computation at the specified 'latticeTimeIndex' and 'latticeMemberIndex'.+estimateAt :: Int+ -- ^ the lattice time index+ -> Int+ -- ^ the lattice size index+ -> Estimate LIO a+ -- ^ the computation+ -> Estimate LIO a+estimateAt i k m = Estimate $ \p -> LIO $ \ps ->- do let ps' = shiftLIOParams di dk ps+ do let ps' = lioParamsAt i k r = pointRun p p' <- invokeLIO ps' $ invokeParameter r
Simulation/Aivika/Lattice/Internal/Estimate.hs view
@@ -146,6 +146,7 @@ runEstimateInStartTime (Estimate m) = runEventInStartTime (Event m) -- | Like 'time' estimates the current modeling time.+-- It is more effcient than 'latticeTime'. estimateTime :: MonadDES m => Estimate m Double {-# INLINE estimateTime #-} estimateTime = Estimate $ return . pointTime
Simulation/Aivika/Lattice/Internal/LIO.hs view
@@ -22,11 +22,14 @@ upSideLIOParams, downSideLIOParams, shiftLIOParams,+ lioParamsAt, latticeTimeIndex, latticeMemberIndex, latticeTime, latticeTimeStep,- latticePoint) where+ latticePoint,+ latticeSize,+ findLatticeTimeIndex) where import Data.IORef import Data.Maybe@@ -136,7 +139,7 @@ where i = lioTimeIndex ps k = lioMemberIndex ps --- | Return the derived LIO params with the specified shift in 'latticeTimeIndex' and+-- | Return the derived parameters with the specified shift in 'latticeTimeIndex' and -- 'latticeMemberIndex' respectively, where the first parameter can be positive only. shiftLIOParams :: Int -- ^ a positive shift the lattice time index@@ -146,7 +149,7 @@ -- ^ the source parameters -> LIOParams shiftLIOParams di dk ps- | di <= 0 = error "The time index shift must be positive: shiftLIOParams"+ | i' < 0 = error "The time index cannot be negative: shiftLIOParams" | k' < 0 = error "The member index cannot be negative: shiftLIOParams" | k' > i' = error "The member index cannot be greater than the time index: shiftLIOParams" | otherwise = ps { lioTimeIndex = i', lioMemberIndex = k' }@@ -155,7 +158,20 @@ k = lioMemberIndex ps k' = k + dk +-- | Return the parameters at the specified 'latticeTimeIndex' and 'latticeMemberIndex'.+lioParamsAt :: Int+ -- ^ the lattice time index+ -> Int+ -- ^ the lattice member index+ -> LIOParams+lioParamsAt i k+ | i < 0 = error "The time index cannot be negative: lioParamsAt"+ | k < 0 = error "The member index cannot be negative: lioParamsAt"+ | k > i = error "The member index cannot be greater than the time index: lioParamsAt"+ | otherwise = LIOParams { lioTimeIndex = i, lioMemberIndex = k }+ -- | Return the lattice time index starting from 0. It corresponds to the integration time point.+-- The index should be less than 'latticeSize'. latticeTimeIndex :: LIO Int latticeTimeIndex = LIO $ return . lioTimeIndex @@ -169,8 +185,10 @@ Parameter $ \r -> LIO $ \ps -> let sc = runSpecs r+ t0 = spcStartTime sc+ dt = spcDT sc i = lioTimeIndex ps- t = spcStartTime sc + (fromInteger $ toInteger i) * (spcDT sc)+ t = t0 + (fromInteger $ toInteger i) * dt in return t -- | Return the point in the corresponding lattice node.@@ -191,3 +209,24 @@ -- | The time step used when constructing the lattice. Currently, it is equivalent to 'dt'. latticeTimeStep :: Parameter LIO Double latticeTimeStep = dt++-- | Return the lattice size.+latticeSize :: Parameter LIO Int+latticeSize =+ Parameter $ \r ->+ do let sc = runSpecs r+ t0 = spcStartTime sc+ t2 = spcStopTime sc+ dt = spcDT sc+ i = fromIntegral $ floor ((t2 - t0) / dt)+ return (i + 1)++-- | Find the lattice time index for the specified modeling time.+findLatticeTimeIndex :: Double -> Parameter LIO Double+findLatticeTimeIndex t =+ Parameter $ \r ->+ do let sc = runSpecs r+ t0 = spcStartTime sc+ dt = spcDT sc+ i = fromIntegral $ floor ((t - t0) / dt)+ return i
Simulation/Aivika/Lattice/LIO.hs view
@@ -13,7 +13,11 @@ (LIO, runLIO, latticeTimeIndex,- latticeMemberIndex) where+ latticeMemberIndex,+ latticeSize,+ latticeTime,+ latticeTimeStep,+ findLatticeTimeIndex) where import Simulation.Aivika.Trans.Comp import Simulation.Aivika.Trans.DES
aivika-lattice.cabal view
@@ -1,5 +1,5 @@ name: aivika-lattice-version: 0.1+version: 0.1.1 synopsis: Nested discrete event simulation module for the Aivika library using lattice description: This experimental package extends the aivika-transformers [1] library with facilities for