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.hs34
1 files changed, 18 insertions, 16 deletions
diff --git a/packages/sundials/src/Main.hs b/packages/sundials/src/Main.hs
index d1f6755..5e51372 100644
--- a/packages/sundials/src/Main.hs
+++ b/packages/sundials/src/Main.hs
@@ -1,5 +1,6 @@
1module Main where 1{-# OPTIONS_GHC -Wall #-}
2 2
3import qualified Data.Vector.Storable as V
3import Numeric.Sundials.Arkode.ODE 4import Numeric.Sundials.Arkode.ODE
4import Numeric.LinearAlgebra 5import Numeric.LinearAlgebra
5 6
@@ -8,10 +9,11 @@ import qualified Diagrams.Prelude as D
8import Diagrams.Backend.Rasterific 9import Diagrams.Backend.Rasterific
9 10
10import Control.Lens 11import Control.Lens
12import Data.List (zip4)
11 13
12brusselator :: a -> [Double] -> [Double] 14
13brusselator _t x = [ a - (w + 1) * u + v * u^(2::Int) 15brusselator _t x = [ a - (w + 1) * u + v * u^2
14 , w * u - v * u^(2::Int) 16 , w * u - v * u^2
15 , (b - w) / eps - w * u 17 , (b - w) / eps - w * u
16 ] 18 ]
17 where 19 where
@@ -22,7 +24,6 @@ brusselator _t x = [ a - (w + 1) * u + v * u^(2::Int)
22 v = x !! 1 24 v = x !! 1
23 w = x !! 2 25 w = x !! 2
24 26
25stiffish :: Double -> [Double] -> [Double]
26stiffish t v = [ 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 ]
27 where 28 where
28 lamda = -100.0 29 lamda = -100.0
@@ -44,14 +45,15 @@ kSaxis xs = P.r2Axis &~ do
44 45
45main :: IO () 46main :: IO ()
46main = do 47main = do
47 do let res = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0]) 48 let res = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0])
48 putStrLn $ show res 49 putStrLn $ show res
49 renderRasterific "diagrams/brusselator.png" 50 renderRasterific "diagrams/brusselator.png"
50 (D.dims2D 500.0 500.0) 51 (D.dims2D 500.0 500.0)
51 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res)) 52 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res))
52 53
53 do let res = odeSolve stiffish [0.0] (fromList [0.0, 0.1 .. 10.0]) 54 let res = odeSolve stiffish [0.0] (fromList [0.0, 0.1 .. 10.0])
54 putStrLn $ show res 55 putStrLn $ show res
55 renderRasterific "diagrams/stiffish.png" 56 renderRasterific "diagrams/stiffish.png"
56 (D.dims2D 500.0 500.0) 57 (D.dims2D 500.0 500.0)
57 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res)) 58 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res))
59