{-# LANGUAGE BangPatterns, RecursiveDo, FlexibleContexts #-}
module Simulation.Aivika.Trans.SystemDynamics
(
(.==.),
(./=.),
(.<.),
(.>=.),
(.>.),
(.<=.),
maxDynamics,
minDynamics,
ifDynamics,
integ,
integEither,
smoothI,
smooth,
smooth3I,
smooth3,
smoothNI,
smoothN,
delay1I,
delay1,
delay3I,
delay3,
delayNI,
delayN,
forecast,
trend,
diffsum,
diffsumEither,
lookupDynamics,
lookupStepwiseDynamics,
delay,
delayI,
delayByDT,
delayIByDT,
step,
pulse,
pulseP,
ramp,
npv,
npve) where
import Data.Array
import Control.Monad
import Control.Monad.Trans
import Control.Monad.Fix
import Simulation.Aivika.Trans.Internal.Specs
import Simulation.Aivika.Trans.Internal.Parameter
import Simulation.Aivika.Trans.Internal.Simulation
import Simulation.Aivika.Trans.Internal.Dynamics
import Simulation.Aivika.Trans.Dynamics.Extra
import Simulation.Aivika.Trans.Table
import Simulation.Aivika.Trans.SD
import qualified Simulation.Aivika.Trans.Dynamics.Memo as M
import qualified Simulation.Aivika.Trans.Dynamics.Memo.Unboxed as MU
(.==.) :: (Monad m, Eq a) => Dynamics m a -> Dynamics m a -> Dynamics m Bool
{-# INLINE (.==.) #-}
.==. :: forall (m :: * -> *) a.
(Monad m, Eq a) =>
Dynamics m a -> Dynamics m a -> Dynamics m Bool
(.==.) = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 forall a. Eq a => a -> a -> Bool
(==)
(./=.) :: (Monad m, Eq a) => Dynamics m a -> Dynamics m a -> Dynamics m Bool
{-# INLINE (./=.) #-}
./=. :: forall (m :: * -> *) a.
(Monad m, Eq a) =>
Dynamics m a -> Dynamics m a -> Dynamics m Bool
(./=.) = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 forall a. Eq a => a -> a -> Bool
(/=)
(.<.) :: (Monad m, Ord a) => Dynamics m a -> Dynamics m a -> Dynamics m Bool
{-# INLINE (.<.) #-}
.<. :: forall (m :: * -> *) a.
(Monad m, Ord a) =>
Dynamics m a -> Dynamics m a -> Dynamics m Bool
(.<.) = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 forall a. Ord a => a -> a -> Bool
(<)
(.>=.) :: (Monad m, Ord a) => Dynamics m a -> Dynamics m a -> Dynamics m Bool
{-# INLINE (.>=.) #-}
.>=. :: forall (m :: * -> *) a.
(Monad m, Ord a) =>
Dynamics m a -> Dynamics m a -> Dynamics m Bool
(.>=.) = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 forall a. Ord a => a -> a -> Bool
(>=)
(.>.) :: (Monad m, Ord a) => Dynamics m a -> Dynamics m a -> Dynamics m Bool
{-# INLINE (.>.) #-}
.>. :: forall (m :: * -> *) a.
(Monad m, Ord a) =>
Dynamics m a -> Dynamics m a -> Dynamics m Bool
(.>.) = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 forall a. Ord a => a -> a -> Bool
(>)
(.<=.) :: (Monad m, Ord a) => Dynamics m a -> Dynamics m a -> Dynamics m Bool
{-# INLINE (.<=.) #-}
.<=. :: forall (m :: * -> *) a.
(Monad m, Ord a) =>
Dynamics m a -> Dynamics m a -> Dynamics m Bool
(.<=.) = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 forall a. Ord a => a -> a -> Bool
(<=)
maxDynamics :: (Monad m, Ord a) => Dynamics m a -> Dynamics m a -> Dynamics m a
{-# INLINE maxDynamics #-}
maxDynamics :: forall (m :: * -> *) a.
(Monad m, Ord a) =>
Dynamics m a -> Dynamics m a -> Dynamics m a
maxDynamics = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 forall a. Ord a => a -> a -> a
max
minDynamics :: (Monad m, Ord a) => Dynamics m a -> Dynamics m a -> Dynamics m a
{-# INLINE minDynamics #-}
minDynamics :: forall (m :: * -> *) a.
(Monad m, Ord a) =>
Dynamics m a -> Dynamics m a -> Dynamics m a
minDynamics = forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 forall a. Ord a => a -> a -> a
min
ifDynamics :: Monad m => Dynamics m Bool -> Dynamics m a -> Dynamics m a -> Dynamics m a
{-# INLINE ifDynamics #-}
ifDynamics :: forall (m :: * -> *) a.
Monad m =>
Dynamics m Bool -> Dynamics m a -> Dynamics m a -> Dynamics m a
ifDynamics Dynamics m Bool
cond Dynamics m a
x Dynamics m a
y =
do Bool
a <- Dynamics m Bool
cond
if Bool
a then Dynamics m a
x else Dynamics m a
y
integEuler :: Monad m
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Point m
-> m Double
{-# INLINABLE integEuler #-}
integEuler :: forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Dynamics m Double -> Dynamics m Double -> Point m -> m Double
integEuler (Dynamics Point m -> m Double
f) (Dynamics Point m -> m Double
i) (Dynamics Point m -> m Double
y) Point m
p =
case forall (m :: * -> *). Point m -> Int
pointIteration Point m
p of
Int
0 ->
Point m -> m Double
i Point m
p
Int
n -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
0
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
0 }
Double
a <- Point m -> m Double
y Point m
py
Double
b <- Point m -> m Double
f Point m
py
let !v :: Double
v = Double
a forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT (forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p) forall a. Num a => a -> a -> a
* Double
b
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
integRK2 :: Monad m
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Point m
-> m Double
{-# INLINABLE integRK2 #-}
integRK2 :: forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Dynamics m Double -> Dynamics m Double -> Point m -> m Double
integRK2 (Dynamics Point m -> m Double
f) (Dynamics Point m -> m Double
i) (Dynamics Point m -> m Double
y) Point m
p =
case forall (m :: * -> *). Point m -> Int
pointPhase Point m
p of
Int
0 -> case forall (m :: * -> *). Point m -> Int
pointIteration Point m
p of
Int
0 ->
Point m -> m Double
i Point m
p
Int
n -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
0
t1 :: Double
t1 = Double
ty
t2 :: Double
t2 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
1
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
0 }
p1 :: Point m
p1 = Point m
py
p2 :: Point m
p2 = Point m
p { pointTime :: Double
pointTime = Double
t2, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
1 }
Double
vy <- Point m -> m Double
y Point m
py
Double
k1 <- Point m -> m Double
f Point m
p1
Double
k2 <- Point m -> m Double
f Point m
p2
let !v :: Double
v = Double
vy forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Fractional a => a -> a -> a
/ Double
2.0 forall a. Num a => a -> a -> a
* (Double
k1 forall a. Num a => a -> a -> a
+ Double
k2)
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Int
1 -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
0
t1 :: Double
t1 = Double
ty
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
0 }
p1 :: Point m
p1 = Point m
py
Double
vy <- Point m -> m Double
y Point m
py
Double
k1 <- Point m -> m Double
f Point m
p1
let !v :: Double
v = Double
vy forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Num a => a -> a -> a
* Double
k1
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Int
_ ->
forall a. HasCallStack => [Char] -> a
error [Char]
"Incorrect phase: integRK2"
integRK4 :: Monad m
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Point m
-> m Double
{-# INLINABLE integRK4 #-}
integRK4 :: forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Dynamics m Double -> Dynamics m Double -> Point m -> m Double
integRK4 (Dynamics Point m -> m Double
f) (Dynamics Point m -> m Double
i) (Dynamics Point m -> m Double
y) Point m
p =
case forall (m :: * -> *). Point m -> Int
pointPhase Point m
p of
Int
0 -> case forall (m :: * -> *). Point m -> Int
pointIteration Point m
p of
Int
0 ->
Point m -> m Double
i Point m
p
Int
n -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
0
t1 :: Double
t1 = Double
ty
t2 :: Double
t2 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
1
t3 :: Double
t3 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
2
t4 :: Double
t4 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
3
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
0 }
p1 :: Point m
p1 = Point m
py
p2 :: Point m
p2 = Point m
p { pointTime :: Double
pointTime = Double
t2, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
1 }
p3 :: Point m
p3 = Point m
p { pointTime :: Double
pointTime = Double
t3, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
2 }
p4 :: Point m
p4 = Point m
p { pointTime :: Double
pointTime = Double
t4, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
3 }
Double
vy <- Point m -> m Double
y Point m
py
Double
k1 <- Point m -> m Double
f Point m
p1
Double
k2 <- Point m -> m Double
f Point m
p2
Double
k3 <- Point m -> m Double
f Point m
p3
Double
k4 <- Point m -> m Double
f Point m
p4
let !v :: Double
v = Double
vy forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Fractional a => a -> a -> a
/ Double
6.0 forall a. Num a => a -> a -> a
* (Double
k1 forall a. Num a => a -> a -> a
+ Double
2.0 forall a. Num a => a -> a -> a
* Double
k2 forall a. Num a => a -> a -> a
+ Double
2.0 forall a. Num a => a -> a -> a
* Double
k3 forall a. Num a => a -> a -> a
+ Double
k4)
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Int
1 -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
0
t1 :: Double
t1 = Double
ty
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
0 }
p1 :: Point m
p1 = Point m
py
Double
vy <- Point m -> m Double
y Point m
py
Double
k1 <- Point m -> m Double
f Point m
p1
let !v :: Double
v = Double
vy forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Fractional a => a -> a -> a
/ Double
2.0 forall a. Num a => a -> a -> a
* Double
k1
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Int
2 -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
0
t2 :: Double
t2 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
1
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
0 }
p2 :: Point m
p2 = Point m
p { pointTime :: Double
pointTime = Double
t2, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
1 }
Double
vy <- Point m -> m Double
y Point m
py
Double
k2 <- Point m -> m Double
f Point m
p2
let !v :: Double
v = Double
vy forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Fractional a => a -> a -> a
/ Double
2.0 forall a. Num a => a -> a -> a
* Double
k2
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Int
3 -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
0
t3 :: Double
t3 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
2
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
0 }
p3 :: Point m
p3 = Point m
p { pointTime :: Double
pointTime = Double
t3, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
2 }
Double
vy <- Point m -> m Double
y Point m
py
Double
k3 <- Point m -> m Double
f Point m
p3
let !v :: Double
v = Double
vy forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Num a => a -> a -> a
* Double
k3
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Int
_ ->
forall a. HasCallStack => [Char] -> a
error [Char]
"Incorrect phase: integRK4"
integRK4b :: Monad m
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Point m
-> m Double
{-# INLINABLE integRK4b #-}
integRK4b :: forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Dynamics m Double -> Dynamics m Double -> Point m -> m Double
integRK4b (Dynamics Point m -> m Double
f) (Dynamics Point m -> m Double
i) (Dynamics Point m -> m Double
y) Point m
p =
case forall (m :: * -> *). Point m -> Int
pointPhase Point m
p of
Int
0 -> case forall (m :: * -> *). Point m -> Int
pointIteration Point m
p of
Int
0 ->
Point m -> m Double
i Point m
p
Int
n -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
0
t1 :: Double
t1 = Double
ty
t2 :: Double
t2 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
1
t3 :: Double
t3 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
2
t4 :: Double
t4 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
3
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
0 }
p1 :: Point m
p1 = Point m
py
p2 :: Point m
p2 = Point m
p { pointTime :: Double
pointTime = Double
t2, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
1 }
p3 :: Point m
p3 = Point m
p { pointTime :: Double
pointTime = Double
t3, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
2 }
p4 :: Point m
p4 = Point m
p { pointTime :: Double
pointTime = Double
t4, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
3 }
Double
vy <- Point m -> m Double
y Point m
py
Double
k1 <- Point m -> m Double
f Point m
p1
Double
k2 <- Point m -> m Double
f Point m
p2
Double
k3 <- Point m -> m Double
f Point m
p3
Double
k4 <- Point m -> m Double
f Point m
p4
let !v :: Double
v = Double
vy forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Fractional a => a -> a -> a
/ Double
8.0 forall a. Num a => a -> a -> a
* (Double
k1 forall a. Num a => a -> a -> a
+ Double
3.0 forall a. Num a => a -> a -> a
* (Double
k2 forall a. Num a => a -> a -> a
+ Double
k3) forall a. Num a => a -> a -> a
+ Double
k4)
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Int
1 -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
0
t1 :: Double
t1 = Double
ty
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
0 }
p1 :: Point m
p1 = Point m
py
Double
vy <- Point m -> m Double
y Point m
py
Double
k1 <- Point m -> m Double
f Point m
p1
let !v :: Double
v = Double
vy forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Fractional a => a -> a -> a
/ Double
3.0 forall a. Num a => a -> a -> a
* Double
k1
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Int
2 -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
0
t1 :: Double
t1 = Double
ty
t2 :: Double
t2 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
1
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
0 }
p1 :: Point m
p1 = Point m
py
p2 :: Point m
p2 = Point m
p { pointTime :: Double
pointTime = Double
t2, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
1 }
Double
vy <- Point m -> m Double
y Point m
py
Double
k1 <- Point m -> m Double
f Point m
p1
Double
k2 <- Point m -> m Double
f Point m
p2
let !v :: Double
v = Double
vy forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Num a => a -> a -> a
* (- Double
k1 forall a. Fractional a => a -> a -> a
/ Double
3.0 forall a. Num a => a -> a -> a
+ Double
k2)
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Int
3 -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
0
t1 :: Double
t1 = Double
ty
t2 :: Double
t2 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
1
t3 :: Double
t3 = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc Int
n Int
2
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
0 }
p1 :: Point m
p1 = Point m
py
p2 :: Point m
p2 = Point m
p { pointTime :: Double
pointTime = Double
t2, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
1 }
p3 :: Point m
p3 = Point m
p { pointTime :: Double
pointTime = Double
t3, pointIteration :: Int
pointIteration = Int
n, pointPhase :: Int
pointPhase = Int
2 }
Double
vy <- Point m -> m Double
y Point m
py
Double
k1 <- Point m -> m Double
f Point m
p1
Double
k2 <- Point m -> m Double
f Point m
p2
Double
k3 <- Point m -> m Double
f Point m
p3
let !v :: Double
v = Double
vy forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Num a => a -> a -> a
* (Double
k1 forall a. Num a => a -> a -> a
- Double
k2 forall a. Num a => a -> a -> a
+ Double
k3)
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Int
_ ->
forall a. HasCallStack => [Char] -> a
error [Char]
"Incorrect phase: integRK4b"
integ :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE integ #-}
integ :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ Dynamics m Double
diff Dynamics m Double
i =
mdo Dynamics m Double
y <- forall (m :: * -> *) e.
MonadMemo m e =>
Dynamics m e -> Simulation m (Dynamics m e)
MU.memoDynamics Dynamics m Double
z
Dynamics m Double
z <- forall (m :: * -> *) a. (Run m -> m a) -> Simulation m a
Simulation forall a b. (a -> b) -> a -> b
$ \Run m
r ->
case forall (m :: * -> *). Specs m -> Method
spcMethod (forall (m :: * -> *). Run m -> Specs m
runSpecs Run m
r) of
Method
Euler -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Dynamics m Double -> Dynamics m Double -> Point m -> m Double
integEuler Dynamics m Double
diff Dynamics m Double
i Dynamics m Double
y
Method
RungeKutta2 -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Dynamics m Double -> Dynamics m Double -> Point m -> m Double
integRK2 Dynamics m Double
diff Dynamics m Double
i Dynamics m Double
y
Method
RungeKutta4 -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Dynamics m Double -> Dynamics m Double -> Point m -> m Double
integRK4 Dynamics m Double
diff Dynamics m Double
i Dynamics m Double
y
Method
RungeKutta4b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Dynamics m Double -> Dynamics m Double -> Point m -> m Double
integRK4b Dynamics m Double
diff Dynamics m Double
i Dynamics m Double
y
forall (m :: * -> *) a. Monad m => a -> m a
return Dynamics m Double
y
integEulerEither :: Monad m
=> Dynamics m (Either Double Double)
-> Dynamics m Double
-> Dynamics m Double
-> Point m
-> m Double
{-# INLINABLE integEulerEither #-}
integEulerEither :: forall (m :: * -> *).
Monad m =>
Dynamics m (Either Double Double)
-> Dynamics m Double -> Dynamics m Double -> Point m -> m Double
integEulerEither (Dynamics Point m -> m (Either Double Double)
f) (Dynamics Point m -> m Double
i) (Dynamics Point m -> m Double
y) Point m
p =
case forall (m :: * -> *). Point m -> Int
pointIteration Point m
p of
Int
0 ->
Point m -> m Double
i Point m
p
Int
n -> do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
0
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty, pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1, pointPhase :: Int
pointPhase = Int
0 }
Either Double Double
b <- Point m -> m (Either Double Double)
f Point m
py
case Either Double Double
b of
Left Double
v ->
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
Right Double
b -> do
Double
a <- Point m -> m Double
y Point m
py
let !v :: Double
v = Double
a forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT (forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p) forall a. Num a => a -> a -> a
* Double
b
forall (m :: * -> *) a. Monad m => a -> m a
return Double
v
integEither :: (MonadSD m, MonadFix m)
=> Dynamics m (Either Double Double)
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE integEither #-}
integEither :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m (Either Double Double)
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integEither Dynamics m (Either Double Double)
diff Dynamics m Double
i =
mdo Dynamics m Double
y <- forall (m :: * -> *) e.
MonadMemo m e =>
Dynamics m e -> Simulation m (Dynamics m e)
MU.memoDynamics Dynamics m Double
z
Dynamics m Double
z <- forall (m :: * -> *) a. (Run m -> m a) -> Simulation m a
Simulation forall a b. (a -> b) -> a -> b
$ \Run m
r ->
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
Monad m =>
Dynamics m (Either Double Double)
-> Dynamics m Double -> Dynamics m Double -> Point m -> m Double
integEulerEither Dynamics m (Either Double Double)
diff Dynamics m Double
i Dynamics m Double
y
forall (m :: * -> *) a. Monad m => a -> m a
return Dynamics m Double
y
smoothI :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE smoothI #-}
smoothI :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
smoothI Dynamics m Double
x Dynamics m Double
t Dynamics m Double
i =
mdo Dynamics m Double
y <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ ((Dynamics m Double
x forall a. Num a => a -> a -> a
- Dynamics m Double
y) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t) Dynamics m Double
i
forall (m :: * -> *) a. Monad m => a -> m a
return Dynamics m Double
y
smooth :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE smooth #-}
smooth :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
smooth Dynamics m Double
x Dynamics m Double
t = forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
smoothI Dynamics m Double
x Dynamics m Double
t Dynamics m Double
x
smooth3I :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE smooth3I #-}
smooth3I :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
smooth3I Dynamics m Double
x Dynamics m Double
t Dynamics m Double
i =
mdo Dynamics m Double
y <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ ((Dynamics m Double
s2 forall a. Num a => a -> a -> a
- Dynamics m Double
y) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t') Dynamics m Double
i
Dynamics m Double
s2 <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ ((Dynamics m Double
s1 forall a. Num a => a -> a -> a
- Dynamics m Double
s2) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t') Dynamics m Double
i
Dynamics m Double
s1 <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ ((Dynamics m Double
x forall a. Num a => a -> a -> a
- Dynamics m Double
s1) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t') Dynamics m Double
i
let t' :: Dynamics m Double
t' = Dynamics m Double
t forall a. Fractional a => a -> a -> a
/ Dynamics m Double
3.0
forall (m :: * -> *) a. Monad m => a -> m a
return Dynamics m Double
y
smooth3 :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE smooth3 #-}
smooth3 :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
smooth3 Dynamics m Double
x Dynamics m Double
t = forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
smooth3I Dynamics m Double
x Dynamics m Double
t Dynamics m Double
x
smoothNI :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Int
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE smoothNI #-}
smoothNI :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Int
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
smoothNI Dynamics m Double
x Dynamics m Double
t Int
n Dynamics m Double
i =
mdo [Dynamics m Double]
s <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Int
1 .. Int
n] forall a b. (a -> b) -> a -> b
$ \Int
k ->
if Int
k forall a. Eq a => a -> a -> Bool
== Int
1
then forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ ((Dynamics m Double
x forall a. Num a => a -> a -> a
- Array Int (Dynamics m Double)
a forall i e. Ix i => Array i e -> i -> e
! Int
1) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t') Dynamics m Double
i
else forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ ((Array Int (Dynamics m Double)
a forall i e. Ix i => Array i e -> i -> e
! (Int
k forall a. Num a => a -> a -> a
- Int
1) forall a. Num a => a -> a -> a
- Array Int (Dynamics m Double)
a forall i e. Ix i => Array i e -> i -> e
! Int
k) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t') Dynamics m Double
i
let a :: Array Int (Dynamics m Double)
a = forall i e. Ix i => (i, i) -> [e] -> Array i e
listArray (Int
1, Int
n) [Dynamics m Double]
s
t' :: Dynamics m Double
t' = Dynamics m Double
t forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Array Int (Dynamics m Double)
a forall i e. Ix i => Array i e -> i -> e
! Int
n
smoothN :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Int
-> Simulation m (Dynamics m Double)
{-# INLINABLE smoothN #-}
smoothN :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Int -> Simulation m (Dynamics m Double)
smoothN Dynamics m Double
x Dynamics m Double
t Int
n = forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Int
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
smoothNI Dynamics m Double
x Dynamics m Double
t Int
n Dynamics m Double
x
delay1I :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE delay1I #-}
delay1I :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
delay1I Dynamics m Double
x Dynamics m Double
t Dynamics m Double
i =
mdo Dynamics m Double
y <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ (Dynamics m Double
x forall a. Num a => a -> a -> a
- Dynamics m Double
y forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t) (Dynamics m Double
i forall a. Num a => a -> a -> a
* Dynamics m Double
t)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Dynamics m Double
y forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t
delay1 :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE delay1 #-}
delay1 :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
delay1 Dynamics m Double
x Dynamics m Double
t = forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
delay1I Dynamics m Double
x Dynamics m Double
t Dynamics m Double
x
delay3I :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE delay3I #-}
delay3I :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
delay3I Dynamics m Double
x Dynamics m Double
t Dynamics m Double
i =
mdo Dynamics m Double
y <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ (Dynamics m Double
s2 forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t' forall a. Num a => a -> a -> a
- Dynamics m Double
y forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t') (Dynamics m Double
i forall a. Num a => a -> a -> a
* Dynamics m Double
t')
Dynamics m Double
s2 <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ (Dynamics m Double
s1 forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t' forall a. Num a => a -> a -> a
- Dynamics m Double
s2 forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t') (Dynamics m Double
i forall a. Num a => a -> a -> a
* Dynamics m Double
t')
Dynamics m Double
s1 <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ (Dynamics m Double
x forall a. Num a => a -> a -> a
- Dynamics m Double
s1 forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t') (Dynamics m Double
i forall a. Num a => a -> a -> a
* Dynamics m Double
t')
let t' :: Dynamics m Double
t' = Dynamics m Double
t forall a. Fractional a => a -> a -> a
/ Dynamics m Double
3.0
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Dynamics m Double
y forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t'
delay3 :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE delay3 #-}
delay3 :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
delay3 Dynamics m Double
x Dynamics m Double
t = forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
delay3I Dynamics m Double
x Dynamics m Double
t Dynamics m Double
x
delayNI :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Int
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE delayNI #-}
delayNI :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Int
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
delayNI Dynamics m Double
x Dynamics m Double
t Int
n Dynamics m Double
i =
mdo [Dynamics m Double]
s <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Int
1 .. Int
n] forall a b. (a -> b) -> a -> b
$ \Int
k ->
if Int
k forall a. Eq a => a -> a -> Bool
== Int
1
then forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ (Dynamics m Double
x forall a. Num a => a -> a -> a
- (Array Int (Dynamics m Double)
a forall i e. Ix i => Array i e -> i -> e
! Int
1) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t') (Dynamics m Double
i forall a. Num a => a -> a -> a
* Dynamics m Double
t')
else forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ ((Array Int (Dynamics m Double)
a forall i e. Ix i => Array i e -> i -> e
! (Int
k forall a. Num a => a -> a -> a
- Int
1)) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t' forall a. Num a => a -> a -> a
- (Array Int (Dynamics m Double)
a forall i e. Ix i => Array i e -> i -> e
! Int
k) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t') (Dynamics m Double
i forall a. Num a => a -> a -> a
* Dynamics m Double
t')
let a :: Array Int (Dynamics m Double)
a = forall i e. Ix i => (i, i) -> [e] -> Array i e
listArray (Int
1, Int
n) [Dynamics m Double]
s
t' :: Dynamics m Double
t' = Dynamics m Double
t forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (Array Int (Dynamics m Double)
a forall i e. Ix i => Array i e -> i -> e
! Int
n) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
t'
delayN :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Int
-> Simulation m (Dynamics m Double)
{-# INLINABLE delayN #-}
delayN :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Int -> Simulation m (Dynamics m Double)
delayN Dynamics m Double
x Dynamics m Double
t Int
n = forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Int
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
delayNI Dynamics m Double
x Dynamics m Double
t Int
n Dynamics m Double
x
forecast :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE forecast #-}
forecast :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
forecast Dynamics m Double
x Dynamics m Double
at Dynamics m Double
hz =
do Dynamics m Double
y <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
smooth Dynamics m Double
x Dynamics m Double
at
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Dynamics m Double
x forall a. Num a => a -> a -> a
* (Dynamics m Double
1.0 forall a. Num a => a -> a -> a
+ (Dynamics m Double
x forall a. Fractional a => a -> a -> a
/ Dynamics m Double
y forall a. Num a => a -> a -> a
- Dynamics m Double
1.0) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
at forall a. Num a => a -> a -> a
* Dynamics m Double
hz)
trend :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE trend #-}
trend :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
trend Dynamics m Double
x Dynamics m Double
at Dynamics m Double
i =
do Dynamics m Double
y <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
smoothI Dynamics m Double
x Dynamics m Double
at (Dynamics m Double
x forall a. Fractional a => a -> a -> a
/ (Dynamics m Double
1.0 forall a. Num a => a -> a -> a
+ Dynamics m Double
i forall a. Num a => a -> a -> a
* Dynamics m Double
at))
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (Dynamics m Double
x forall a. Fractional a => a -> a -> a
/ Dynamics m Double
y forall a. Num a => a -> a -> a
- Dynamics m Double
1.0) forall a. Fractional a => a -> a -> a
/ Dynamics m Double
at
diffsum :: (MonadSD m, MonadFix m,
MU.MonadMemo m a, Num a)
=> Dynamics m a
-> Dynamics m a
-> Simulation m (Dynamics m a)
{-# INLINABLE diffsum #-}
diffsum :: forall (m :: * -> *) a.
(MonadSD m, MonadFix m, MonadMemo m a, Num a) =>
Dynamics m a -> Dynamics m a -> Simulation m (Dynamics m a)
diffsum (Dynamics Point m -> m a
diff) (Dynamics Point m -> m a
i) =
mdo Dynamics m a
y <-
forall (m :: * -> *) e.
MonadMemo m e =>
Dynamics m e -> Simulation m (Dynamics m e)
MU.memo0Dynamics forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
case forall (m :: * -> *). Point m -> Int
pointIteration Point m
p of
Int
0 -> Point m -> m a
i Point m
p
Int
n -> do
let Dynamics Point m -> m a
m = Dynamics m a
y
sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
0
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty,
pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1,
pointPhase :: Int
pointPhase = Int
0 }
a
a <- Point m -> m a
m Point m
py
a
b <- Point m -> m a
diff Point m
py
let !v :: a
v = a
a forall a. Num a => a -> a -> a
+ a
b
forall (m :: * -> *) a. Monad m => a -> m a
return a
v
forall (m :: * -> *) a. Monad m => a -> m a
return Dynamics m a
y
diffsumEither :: (MonadSD m, MonadFix m,
MU.MonadMemo m a, Num a)
=> Dynamics m (Either a a)
-> Dynamics m a
-> Simulation m (Dynamics m a)
{-# INLINABLE diffsumEither #-}
diffsumEither :: forall (m :: * -> *) a.
(MonadSD m, MonadFix m, MonadMemo m a, Num a) =>
Dynamics m (Either a a)
-> Dynamics m a -> Simulation m (Dynamics m a)
diffsumEither (Dynamics Point m -> m (Either a a)
diff) (Dynamics Point m -> m a
i) =
mdo Dynamics m a
y <-
forall (m :: * -> *) e.
MonadMemo m e =>
Dynamics m e -> Simulation m (Dynamics m e)
MU.memo0Dynamics forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
case forall (m :: * -> *). Point m -> Int
pointIteration Point m
p of
Int
0 -> Point m -> m a
i Point m
p
Int
n -> do
let Dynamics Point m -> m a
m = Dynamics m a
y
sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
ty :: Double
ty = forall (m :: * -> *). Specs m -> Int -> Int -> Double
basicTime Specs m
sc (Int
n forall a. Num a => a -> a -> a
- Int
1) Int
0
py :: Point m
py = Point m
p { pointTime :: Double
pointTime = Double
ty,
pointIteration :: Int
pointIteration = Int
n forall a. Num a => a -> a -> a
- Int
1,
pointPhase :: Int
pointPhase = Int
0 }
Either a a
b <- Point m -> m (Either a a)
diff Point m
py
case Either a a
b of
Left a
v ->
forall (m :: * -> *) a. Monad m => a -> m a
return a
v
Right a
b -> do
a
a <- Point m -> m a
m Point m
py
let !v :: a
v = a
a forall a. Num a => a -> a -> a
+ a
b
forall (m :: * -> *) a. Monad m => a -> m a
return a
v
forall (m :: * -> *) a. Monad m => a -> m a
return Dynamics m a
y
lookupDynamics :: Monad m => Dynamics m Double -> Array Int (Double, Double) -> Dynamics m Double
{-# INLINABLE lookupDynamics #-}
lookupDynamics :: forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Array Int (Double, Double) -> Dynamics m Double
lookupDynamics (Dynamics Point m -> m Double
m) Array Int (Double, Double)
tbl =
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do Double
a <- Point m -> m Double
m Point m
p
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Double -> Array Int (Double, Double) -> Double
tableLookup Double
a Array Int (Double, Double)
tbl
lookupStepwiseDynamics :: Monad m => Dynamics m Double -> Array Int (Double, Double) -> Dynamics m Double
{-# INLINABLE lookupStepwiseDynamics #-}
lookupStepwiseDynamics :: forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Array Int (Double, Double) -> Dynamics m Double
lookupStepwiseDynamics (Dynamics Point m -> m Double
m) Array Int (Double, Double)
tbl =
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do Double
a <- Point m -> m Double
m Point m
p
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Double -> Array Int (Double, Double) -> Double
tableLookupStepwise Double
a Array Int (Double, Double)
tbl
delay :: Monad m
=> Dynamics m a
-> Dynamics m Double
-> Dynamics m a
{-# INLINABLE delay #-}
delay :: forall (m :: * -> *) a.
Monad m =>
Dynamics m a -> Dynamics m Double -> Dynamics m a
delay (Dynamics Point m -> m a
x) (Dynamics Point m -> m Double
d) = forall (m :: * -> *) a. Dynamics m a -> Dynamics m a
discreteDynamics forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics Point m -> m a
r
where
r :: Point m -> m a
r Point m
p = do
let t :: Double
t = forall (m :: * -> *). Point m -> Double
pointTime Point m
p
sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
Double
a <- Point m -> m Double
d Point m
p
let t' :: Double
t' = Double
t forall a. Num a => a -> a -> a
- Double
a
n' :: Int
n' = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ forall a b. (RealFrac a, Integral b) => a -> b
floor forall a b. (a -> b) -> a -> b
$ (Double
t' forall a. Num a => a -> a -> a
- forall (m :: * -> *). Specs m -> Double
spcStartTime Specs m
sc) forall a. Fractional a => a -> a -> a
/ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc
y :: m a
y | Int
n' forall a. Ord a => a -> a -> Bool
< Int
0 = Point m -> m a
x forall a b. (a -> b) -> a -> b
$ Point m
p { pointTime :: Double
pointTime = forall (m :: * -> *). Specs m -> Double
spcStartTime Specs m
sc,
pointIteration :: Int
pointIteration = Int
0,
pointPhase :: Int
pointPhase = Int
0 }
| Int
n' forall a. Ord a => a -> a -> Bool
< Int
n = Point m -> m a
x forall a b. (a -> b) -> a -> b
$ Point m
p { pointTime :: Double
pointTime = Double
t',
pointIteration :: Int
pointIteration = Int
n',
pointPhase :: Int
pointPhase = -Int
1 }
| Int
n' forall a. Ord a => a -> a -> Bool
> Int
n = forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$
[Char]
"Cannot return the future data: delay. " forall a. [a] -> [a] -> [a]
++
[Char]
"The lag time cannot be negative."
| Bool
otherwise = forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$
[Char]
"Cannot return the current data: delay. " forall a. [a] -> [a] -> [a]
++
[Char]
"The lag time is too small."
m a
y
delayI :: MonadSD m
=> Dynamics m a
-> Dynamics m Double
-> Dynamics m a
-> Simulation m (Dynamics m a)
{-# INLINABLE delayI #-}
delayI :: forall (m :: * -> *) a.
MonadSD m =>
Dynamics m a
-> Dynamics m Double -> Dynamics m a -> Simulation m (Dynamics m a)
delayI (Dynamics Point m -> m a
x) (Dynamics Point m -> m Double
d) (Dynamics Point m -> m a
i) = forall (m :: * -> *) e.
MonadMemo m =>
Dynamics m e -> Simulation m (Dynamics m e)
M.memo0Dynamics forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics Point m -> m a
r
where
r :: Point m -> m a
r Point m
p = do
let t :: Double
t = forall (m :: * -> *). Point m -> Double
pointTime Point m
p
sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
Double
a <- Point m -> m Double
d Point m
p
let t' :: Double
t' = Double
t forall a. Num a => a -> a -> a
- Double
a
n' :: Int
n' = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ forall a b. (RealFrac a, Integral b) => a -> b
floor forall a b. (a -> b) -> a -> b
$ (Double
t' forall a. Num a => a -> a -> a
- forall (m :: * -> *). Specs m -> Double
spcStartTime Specs m
sc) forall a. Fractional a => a -> a -> a
/ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc
y :: m a
y | Int
n' forall a. Ord a => a -> a -> Bool
< Int
0 = Point m -> m a
i forall a b. (a -> b) -> a -> b
$ Point m
p { pointTime :: Double
pointTime = forall (m :: * -> *). Specs m -> Double
spcStartTime Specs m
sc,
pointIteration :: Int
pointIteration = Int
0,
pointPhase :: Int
pointPhase = Int
0 }
| Int
n' forall a. Ord a => a -> a -> Bool
< Int
n = Point m -> m a
x forall a b. (a -> b) -> a -> b
$ Point m
p { pointTime :: Double
pointTime = Double
t',
pointIteration :: Int
pointIteration = Int
n',
pointPhase :: Int
pointPhase = -Int
1 }
| Int
n' forall a. Ord a => a -> a -> Bool
> Int
n = forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$
[Char]
"Cannot return the future data: delay. " forall a. [a] -> [a] -> [a]
++
[Char]
"The lag time cannot be negative."
| Bool
otherwise = forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$
[Char]
"Cannot return the current data: delay. " forall a. [a] -> [a] -> [a]
++
[Char]
"The lag time is too small."
m a
y
delayByDT :: Monad m
=> Dynamics m a
-> Dynamics m Int
-> Dynamics m a
{-# INLINABLE delayByDT #-}
delayByDT :: forall (m :: * -> *) a.
Monad m =>
Dynamics m a -> Dynamics m Int -> Dynamics m a
delayByDT (Dynamics Point m -> m a
x) (Dynamics Point m -> m Int
d) = forall (m :: * -> *) a. Dynamics m a -> Dynamics m a
discreteDynamics forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics Point m -> m a
r
where
r :: Point m -> m a
r Point m
p = do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
Int
a <- Point m -> m Int
d Point m
p
let p' :: Point m
p' = forall (m :: * -> *). Point m -> Int -> Point m
delayPoint Point m
p Int
a
n' :: Int
n' = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p'
y :: m a
y | Int
n' forall a. Ord a => a -> a -> Bool
< Int
0 = Point m -> m a
x forall a b. (a -> b) -> a -> b
$ Point m
p { pointTime :: Double
pointTime = forall (m :: * -> *). Specs m -> Double
spcStartTime Specs m
sc,
pointIteration :: Int
pointIteration = Int
0,
pointPhase :: Int
pointPhase = Int
0 }
| Int
n' forall a. Ord a => a -> a -> Bool
< Int
n = Point m -> m a
x Point m
p'
| Int
n' forall a. Ord a => a -> a -> Bool
> Int
n = forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$
[Char]
"Cannot return the future data: delayByDT. " forall a. [a] -> [a] -> [a]
++
[Char]
"The lag time cannot be negative."
| Bool
otherwise = forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$
[Char]
"Cannot return the current data: delayByDT. " forall a. [a] -> [a] -> [a]
++
[Char]
"The lag time is too small."
m a
y
delayIByDT :: MonadSD m
=> Dynamics m a
-> Dynamics m Int
-> Dynamics m a
-> Simulation m (Dynamics m a)
{-# INLINABLE delayIByDT #-}
delayIByDT :: forall (m :: * -> *) a.
MonadSD m =>
Dynamics m a
-> Dynamics m Int -> Dynamics m a -> Simulation m (Dynamics m a)
delayIByDT (Dynamics Point m -> m a
x) (Dynamics Point m -> m Int
d) (Dynamics Point m -> m a
i) = forall (m :: * -> *) e.
MonadMemo m =>
Dynamics m e -> Simulation m (Dynamics m e)
M.memoDynamics forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics Point m -> m a
r
where
r :: Point m -> m a
r Point m
p = do
let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
n :: Int
n = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p
Int
a <- Point m -> m Int
d Point m
p
let p' :: Point m
p' = forall (m :: * -> *). Point m -> Int -> Point m
delayPoint Point m
p Int
a
n' :: Int
n' = forall (m :: * -> *). Point m -> Int
pointIteration Point m
p'
y :: m a
y | Int
n' forall a. Ord a => a -> a -> Bool
< Int
0 = Point m -> m a
i forall a b. (a -> b) -> a -> b
$ Point m
p { pointTime :: Double
pointTime = forall (m :: * -> *). Specs m -> Double
spcStartTime Specs m
sc,
pointIteration :: Int
pointIteration = Int
0,
pointPhase :: Int
pointPhase = Int
0 }
| Int
n' forall a. Ord a => a -> a -> Bool
< Int
n = Point m -> m a
x Point m
p'
| Int
n' forall a. Ord a => a -> a -> Bool
> Int
n = forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$
[Char]
"Cannot return the future data: delayIByDT. " forall a. [a] -> [a] -> [a]
++
[Char]
"The lag time cannot be negative."
| Bool
otherwise = forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$
[Char]
"Cannot return the current data: delayIByDT. " forall a. [a] -> [a] -> [a]
++
[Char]
"The lag time is too small."
m a
y
npv :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE npv #-}
npv :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
npv Dynamics m Double
stream Dynamics m Double
rate Dynamics m Double
init Dynamics m Double
factor =
mdo let dt' :: Dynamics m Double
dt' = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter forall (m :: * -> *). Monad m => Parameter m Double
dt
Dynamics m Double
df <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ (- Dynamics m Double
df forall a. Num a => a -> a -> a
* Dynamics m Double
rate) Dynamics m Double
1
Dynamics m Double
accum <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ (Dynamics m Double
stream forall a. Num a => a -> a -> a
* Dynamics m Double
df) Dynamics m Double
init
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (Dynamics m Double
accum forall a. Num a => a -> a -> a
+ Dynamics m Double
dt' forall a. Num a => a -> a -> a
* Dynamics m Double
stream forall a. Num a => a -> a -> a
* Dynamics m Double
df) forall a. Num a => a -> a -> a
* Dynamics m Double
factor
npve :: (MonadSD m, MonadFix m)
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
{-# INLINABLE npve #-}
npve :: forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Simulation m (Dynamics m Double)
npve Dynamics m Double
stream Dynamics m Double
rate Dynamics m Double
init Dynamics m Double
factor =
mdo let dt' :: Dynamics m Double
dt' = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter forall (m :: * -> *). Monad m => Parameter m Double
dt
Dynamics m Double
df <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ (- Dynamics m Double
df forall a. Num a => a -> a -> a
* Dynamics m Double
rate forall a. Fractional a => a -> a -> a
/ (Dynamics m Double
1 forall a. Num a => a -> a -> a
+ Dynamics m Double
rate forall a. Num a => a -> a -> a
* Dynamics m Double
dt')) (Dynamics m Double
1 forall a. Fractional a => a -> a -> a
/ (Dynamics m Double
1 forall a. Num a => a -> a -> a
+ Dynamics m Double
rate forall a. Num a => a -> a -> a
* Dynamics m Double
dt'))
Dynamics m Double
accum <- forall (m :: * -> *).
(MonadSD m, MonadFix m) =>
Dynamics m Double
-> Dynamics m Double -> Simulation m (Dynamics m Double)
integ (Dynamics m Double
stream forall a. Num a => a -> a -> a
* Dynamics m Double
df) Dynamics m Double
init
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (Dynamics m Double
accum forall a. Num a => a -> a -> a
+ Dynamics m Double
dt' forall a. Num a => a -> a -> a
* Dynamics m Double
stream forall a. Num a => a -> a -> a
* Dynamics m Double
df) forall a. Num a => a -> a -> a
* Dynamics m Double
factor
step :: Monad m
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
{-# INLINABLE step #-}
step :: forall (m :: * -> *).
Monad m =>
Dynamics m Double -> Dynamics m Double -> Dynamics m Double
step Dynamics m Double
h Dynamics m Double
st =
forall (m :: * -> *) a. Dynamics m a -> Dynamics m a
discreteDynamics forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
t :: Double
t = forall (m :: * -> *). Point m -> Double
pointTime Point m
p
Double
st' <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m Double
st
let t' :: Double
t' = Double
t forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Fractional a => a -> a -> a
/ Double
2
if Double
st' forall a. Ord a => a -> a -> Bool
< Double
t'
then forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m Double
h
else forall (m :: * -> *) a. Monad m => a -> m a
return Double
0
pulse :: Monad m
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
{-# INLINABLE pulse #-}
pulse :: forall (m :: * -> *).
Monad m =>
Dynamics m Double -> Dynamics m Double -> Dynamics m Double
pulse Dynamics m Double
st Dynamics m Double
w =
forall (m :: * -> *) a. Dynamics m a -> Dynamics m a
discreteDynamics forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
t :: Double
t = forall (m :: * -> *). Point m -> Double
pointTime Point m
p
Double
st' <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m Double
st
let t' :: Double
t' = Double
t forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Fractional a => a -> a -> a
/ Double
2
if Double
st' forall a. Ord a => a -> a -> Bool
< Double
t'
then do Double
w' <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m Double
w
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Double
t' forall a. Ord a => a -> a -> Bool
< Double
st' forall a. Num a => a -> a -> a
+ Double
w' then Double
1 else Double
0
else forall (m :: * -> *) a. Monad m => a -> m a
return Double
0
pulseP :: Monad m
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
{-# INLINABLE pulseP #-}
pulseP :: forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Dynamics m Double -> Dynamics m Double -> Dynamics m Double
pulseP Dynamics m Double
st Dynamics m Double
w Dynamics m Double
period =
forall (m :: * -> *) a. Dynamics m a -> Dynamics m a
discreteDynamics forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
t :: Double
t = forall (m :: * -> *). Point m -> Double
pointTime Point m
p
Double
p' <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m Double
period
Double
st' <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m Double
st
let y' :: Double
y' = if (Double
p' forall a. Ord a => a -> a -> Bool
> Double
0) Bool -> Bool -> Bool
&& (Double
t forall a. Ord a => a -> a -> Bool
> Double
st')
then forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a b. (RealFrac a, Integral b) => a -> b
floor forall a b. (a -> b) -> a -> b
$ (Double
t forall a. Num a => a -> a -> a
- Double
st') forall a. Fractional a => a -> a -> a
/ Double
p') forall a. Num a => a -> a -> a
* Double
p'
else Double
0
let st' :: Double
st' = Double
st' forall a. Num a => a -> a -> a
+ Double
y'
let t' :: Double
t' = Double
t forall a. Num a => a -> a -> a
+ forall (m :: * -> *). Specs m -> Double
spcDT Specs m
sc forall a. Fractional a => a -> a -> a
/ Double
2
if Double
st' forall a. Ord a => a -> a -> Bool
< Double
t'
then do Double
w' <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m Double
w
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Double
t' forall a. Ord a => a -> a -> Bool
< Double
st' forall a. Num a => a -> a -> a
+ Double
w' then Double
1 else Double
0
else forall (m :: * -> *) a. Monad m => a -> m a
return Double
0
ramp :: Monad m
=> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
-> Dynamics m Double
{-# INLINABLE ramp #-}
ramp :: forall (m :: * -> *).
Monad m =>
Dynamics m Double
-> Dynamics m Double -> Dynamics m Double -> Dynamics m Double
ramp Dynamics m Double
slope Dynamics m Double
st Dynamics m Double
e =
forall (m :: * -> *) a. Dynamics m a -> Dynamics m a
discreteDynamics forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do let sc :: Specs m
sc = forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
t :: Double
t = forall (m :: * -> *). Point m -> Double
pointTime Point m
p
Double
st' <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m Double
st
if Double
st' forall a. Ord a => a -> a -> Bool
< Double
t
then do Double
slope' <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m Double
slope
Double
e' <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m Double
e
if Double
t forall a. Ord a => a -> a -> Bool
< Double
e'
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Double
slope' forall a. Num a => a -> a -> a
* (Double
t forall a. Num a => a -> a -> a
- Double
st')
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Double
slope' forall a. Num a => a -> a -> a
* (Double
e' forall a. Num a => a -> a -> a
- Double
st')
else forall (m :: * -> *) a. Monad m => a -> m a
return Double
0