summaryrefslogtreecommitdiff
path: root/packages/sundials/src
diff options
context:
space:
mode:
authorDominic Steinitz <dominic@steinitz.org>2018-04-05 12:09:07 +0100
committerDominic Steinitz <dominic@steinitz.org>2018-04-05 12:09:07 +0100
commita918ec611a6a54c1260349591369ec33d8e873c3 (patch)
tree86093942e755b7a587e1de57a535780cbd5034a5 /packages/sundials/src
parentf8fde7399e449c324c39c1c0d209f9ef43f1e618 (diff)
Add new example
Diffstat (limited to 'packages/sundials/src')
-rw-r--r--packages/sundials/src/Main.hs53
1 files changed, 50 insertions, 3 deletions
diff --git a/packages/sundials/src/Main.hs b/packages/sundials/src/Main.hs
index 9bbf5c8..eef8148 100644
--- a/packages/sundials/src/Main.hs
+++ b/packages/sundials/src/Main.hs
@@ -12,6 +12,31 @@ import Data.List (intercalate)
12 12
13import Text.PrettyPrint.HughesPJClass 13import Text.PrettyPrint.HughesPJClass
14 14
15lorenz :: Double -> [Double] -> [Double]
16lorenz _t u = [ sigma * (y - x)
17 , x * (rho - z) - y
18 , x * y - beta * z
19 ]
20 where
21 rho = 28.0
22 sigma = 10.0
23 beta = 8.0 / 3.0
24 x = u !! 0
25 y = u !! 1
26 z = u !! 2
27
28lorenzJac :: Double -> Vector Double -> Matrix Double
29lorenzJac _t u = (3><3) [ (-sigma), rho - z, y
30 , sigma , -1.0 , x
31 , 0.0 , (-x) , (-beta)
32 ]
33 where
34 rho = 28.0
35 sigma = 10.0
36 beta = 8.0 / 3.0
37 x = u ! 0
38 y = u ! 1
39 z = u ! 2
15 40
16brusselator :: Double -> [Double] -> [Double] 41brusselator :: Double -> [Double] -> [Double]
17brusselator _t x = [ a - (w + 1) * u + v * u * u 42brusselator _t x = [ a - (w + 1) * u + v * u * u
@@ -90,18 +115,40 @@ main = do
90 -- \end{array} 115 -- \end{array}
91 -- $$ 116 -- $$
92 117
93 let res = btGet SDIRK_2_1_2 118 let res = btGet (SDIRK_2_1_2 undefined)
119 putStrLn $ show res
120 putStrLn $ butcherTableauTex res
121
122 let res = btGet (KVAERNO_4_2_3 undefined)
123 putStrLn $ show res
124 putStrLn $ butcherTableauTex res
125
126 let res = btGet (SDIRK_5_3_4 undefined)
94 putStrLn $ show res 127 putStrLn $ show res
95 putStrLn $ butcherTableauTex res 128 putStrLn $ butcherTableauTex res
96 129
97 let res1 = odeSolve KVAERNO_4_2_3 brussJac brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0]) 130 let res1 = odeSolve' (KVAERNO_4_2_3 undefined) brussJac brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0])
98 putStrLn $ show res1 131 putStrLn $ show res1
99 renderRasterific "diagrams/brusselator.png" 132 renderRasterific "diagrams/brusselator.png"
100 (D.dims2D 500.0 500.0) 133 (D.dims2D 500.0 500.0)
101 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res1)) 134 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res1))
102 135
103 let res2 = odeSolve KVAERNO_4_2_3 stiffJac stiffish [0.0] (fromList [0.0, 0.1 .. 10.0]) 136
137 let res2 = odeSolve' (KVAERNO_4_2_3 undefined) stiffJac stiffish [0.0] (fromList [0.0, 0.1 .. 10.0])
104 putStrLn $ show res2 138 putStrLn $ show res2
105 renderRasterific "diagrams/stiffish.png" 139 renderRasterific "diagrams/stiffish.png"
106 (D.dims2D 500.0 500.0) 140 (D.dims2D 500.0 500.0)
107 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res2)) 141 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res2))
142
143 let res3 = odeSolve' (KVAERNO_4_2_3 undefined) lorenzJac lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 30.0])
144 renderRasterific "diagrams/lorenz.png"
145 (D.dims2D 500.0 500.0)
146 (renderAxis $ kSaxis $ zip ((toLists $ tr res3)!!0) ((toLists $ tr res3)!!1))
147
148 renderRasterific "diagrams/lorenz1.png"
149 (D.dims2D 500.0 500.0)
150 (renderAxis $ kSaxis $ zip ((toLists $ tr res3)!!0) ((toLists $ tr res3)!!2))
151
152 renderRasterific "diagrams/lorenz2.png"
153 (D.dims2D 500.0 500.0)
154 (renderAxis $ kSaxis $ zip ((toLists $ tr res3)!!1) ((toLists $ tr res3)!!2))