summaryrefslogtreecommitdiff
path: root/packages/sundials/src/Main.hs
blob: 2a561c4dc9c960186865838c129c770d0da5536a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# OPTIONS_GHC -Wall #-}

import qualified Data.Vector.Storable as V
import           Numeric.Sundials.Arkode.ODE

brusselator :: Double -> V.Vector Double -> V.Vector Double
brusselator _t x = V.fromList [ a - (w + 1) * u + v * u^2
                              , w * u - v * u^2
                              , (b - w) / eps - w * u
                              ]
  where
    a = 1.0
    b = 3.5
    eps = 5.0e-6
    u = x V.! 0
    v = x V.! 1
    w = x V.! 2

stiffish t v = V.fromList [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ]
  where
    lamda = -100.0
    u = v V.! 0

main :: IO ()
main = do
  let res = solveOde brusselator (V.fromList [1.2, 3.1, 3.0]) (V.fromList [0.0, 1.0 .. 10.0])
  putStrLn $ show res
  let res = solveOde stiffish (V.fromList [1.0]) (V.fromList [0.0, 0.1 .. 10.0])
  putStrLn $ show res