diff options
Diffstat (limited to 'packages/sundials/src/Main.hs')
-rw-r--r-- | packages/sundials/src/Main.hs | 54 |
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 | ||
3 | import qualified Data.Vector.Storable as V | 3 | import qualified Data.Vector.Storable as V |
4 | import Numeric.Sundials.Arkode.ODE | 4 | import Numeric.Sundials.Arkode.ODE |
5 | import Numeric.LinearAlgebra | ||
5 | 6 | ||
6 | brusselator :: Double -> V.Vector Double -> V.Vector Double | 7 | import Plots as P |
7 | brusselator _t x = V.fromList [ a - (w + 1) * u + v * u^2 | 8 | import qualified Diagrams.Prelude as D |
8 | , w * u - v * u^2 | 9 | import Diagrams.Backend.Rasterific |
9 | , (b - w) / eps - w * u | 10 | |
10 | ] | 11 | import Control.Lens |
12 | import Data.List (zip4) | ||
13 | |||
14 | |||
15 | brusselator _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 | ||
19 | stiffish t v = V.fromList [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ] | 27 | stiffish 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 | |||
32 | lSaxis :: [[Double]] -> P.Axis B D.V2 Double | ||
33 | lSaxis 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 | |||
42 | kSaxis :: [(Double, Double)] -> P.Axis B D.V2 Double | ||
43 | kSaxis xs = P.r2Axis &~ do | ||
44 | P.linePlot' xs | ||
23 | 45 | ||
24 | main :: IO () | 46 | main :: IO () |
25 | main = do | 47 | main = 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 | |||