summaryrefslogtreecommitdiff
path: root/packages/sundials/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sundials/src/Main.hs')
-rw-r--r--packages/sundials/src/Main.hs54
1 files changed, 42 insertions, 12 deletions
diff --git a/packages/sundials/src/Main.hs b/packages/sundials/src/Main.hs
index 2a561c4..5e51372 100644
--- a/packages/sundials/src/Main.hs
+++ b/packages/sundials/src/Main.hs
@@ -2,28 +2,58 @@
2 2
3import qualified Data.Vector.Storable as V 3import qualified Data.Vector.Storable as V
4import Numeric.Sundials.Arkode.ODE 4import Numeric.Sundials.Arkode.ODE
5import Numeric.LinearAlgebra
5 6
6brusselator :: Double -> V.Vector Double -> V.Vector Double 7import Plots as P
7brusselator _t x = V.fromList [ a - (w + 1) * u + v * u^2 8import qualified Diagrams.Prelude as D
8 , w * u - v * u^2 9import Diagrams.Backend.Rasterific
9 , (b - w) / eps - w * u 10
10 ] 11import Control.Lens
12import Data.List (zip4)
13
14
15brusselator _t x = [ a - (w + 1) * u + v * u^2
16 , w * u - v * u^2
17 , (b - w) / eps - w * u
18 ]
11 where 19 where
12 a = 1.0 20 a = 1.0
13 b = 3.5 21 b = 3.5
14 eps = 5.0e-6 22 eps = 5.0e-6
15 u = x V.! 0 23 u = x !! 0
16 v = x V.! 1 24 v = x !! 1
17 w = x V.! 2 25 w = x !! 2
18 26
19stiffish t v = V.fromList [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ] 27stiffish t v = [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ]
20 where 28 where
21 lamda = -100.0 29 lamda = -100.0
22 u = v V.! 0 30 u = v !! 0
31
32lSaxis :: [[Double]] -> P.Axis B D.V2 Double
33lSaxis xs = P.r2Axis &~ do
34 let ts = xs!!0
35 us = xs!!1
36 vs = xs!!2
37 ws = xs!!3
38 P.linePlot' $ zip ts us
39 P.linePlot' $ zip ts vs
40 P.linePlot' $ zip ts ws
41
42kSaxis :: [(Double, Double)] -> P.Axis B D.V2 Double
43kSaxis xs = P.r2Axis &~ do
44 P.linePlot' xs
23 45
24main :: IO () 46main :: IO ()
25main = do 47main = do
26 let res = solveOde brusselator (V.fromList [1.2, 3.1, 3.0]) (V.fromList [0.0, 1.0 .. 10.0]) 48 let res = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0])
27 putStrLn $ show res 49 putStrLn $ show res
28 let res = solveOde stiffish (V.fromList [1.0]) (V.fromList [0.0, 0.1 .. 10.0]) 50 renderRasterific "diagrams/brusselator.png"
51 (D.dims2D 500.0 500.0)
52 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res))
53
54 let res = odeSolve stiffish [0.0] (fromList [0.0, 0.1 .. 10.0])
29 putStrLn $ show res 55 putStrLn $ show res
56 renderRasterific "diagrams/stiffish.png"
57 (D.dims2D 500.0 500.0)
58 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res))
59