summaryrefslogtreecommitdiff
path: root/packages/sundials/src/Main.hs
diff options
context:
space:
mode:
authoridontgetoutmuch <dominic@steinitz.org>2018-03-26 00:15:39 -0700
committerGitHub <noreply@github.com>2018-03-26 00:15:39 -0700
commit560f38ab27bcc44c80ce7d9c2e4972342170fe28 (patch)
tree2aef5c26b5d19b6029078f27533515a679c8267e /packages/sundials/src/Main.hs
parentf7ea5ed206af85cafec1e8bef824f0dd5a9f63fb (diff)
parent13fcfabce2edf2a276bb5ba1f47cdf8fdfd9958a (diff)
Merge pull request #1 from mboes/sundials
Cleanups to Sundials PR
Diffstat (limited to 'packages/sundials/src/Main.hs')
-rw-r--r--packages/sundials/src/Main.hs34
1 files changed, 16 insertions, 18 deletions
diff --git a/packages/sundials/src/Main.hs b/packages/sundials/src/Main.hs
index 5e51372..d1f6755 100644
--- a/packages/sundials/src/Main.hs
+++ b/packages/sundials/src/Main.hs
@@ -1,6 +1,5 @@
1{-# OPTIONS_GHC -Wall #-} 1module Main where
2 2
3import qualified Data.Vector.Storable as V
4import Numeric.Sundials.Arkode.ODE 3import Numeric.Sundials.Arkode.ODE
5import Numeric.LinearAlgebra 4import Numeric.LinearAlgebra
6 5
@@ -9,11 +8,10 @@ import qualified Diagrams.Prelude as D
9import Diagrams.Backend.Rasterific 8import Diagrams.Backend.Rasterific
10 9
11import Control.Lens 10import Control.Lens
12import Data.List (zip4)
13 11
14 12brusselator :: a -> [Double] -> [Double]
15brusselator _t x = [ a - (w + 1) * u + v * u^2 13brusselator _t x = [ a - (w + 1) * u + v * u^(2::Int)
16 , w * u - v * u^2 14 , w * u - v * u^(2::Int)
17 , (b - w) / eps - w * u 15 , (b - w) / eps - w * u
18 ] 16 ]
19 where 17 where
@@ -24,6 +22,7 @@ brusselator _t x = [ a - (w + 1) * u + v * u^2
24 v = x !! 1 22 v = x !! 1
25 w = x !! 2 23 w = x !! 2
26 24
25stiffish :: Double -> [Double] -> [Double]
27stiffish t v = [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ] 26stiffish t v = [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ]
28 where 27 where
29 lamda = -100.0 28 lamda = -100.0
@@ -45,15 +44,14 @@ kSaxis xs = P.r2Axis &~ do
45 44
46main :: IO () 45main :: IO ()
47main = do 46main = do
48 let res = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0]) 47 do let res = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0])
49 putStrLn $ show res 48 putStrLn $ show res
50 renderRasterific "diagrams/brusselator.png" 49 renderRasterific "diagrams/brusselator.png"
51 (D.dims2D 500.0 500.0) 50 (D.dims2D 500.0 500.0)
52 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res)) 51 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res))
53 52
54 let res = odeSolve stiffish [0.0] (fromList [0.0, 0.1 .. 10.0]) 53 do let res = odeSolve stiffish [0.0] (fromList [0.0, 0.1 .. 10.0])
55 putStrLn $ show res 54 putStrLn $ show res
56 renderRasterific "diagrams/stiffish.png" 55 renderRasterific "diagrams/stiffish.png"
57 (D.dims2D 500.0 500.0) 56 (D.dims2D 500.0 500.0)
58 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res)) 57 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res))
59