summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Steinitz <dominic@steinitz.org>2018-04-23 16:20:33 +0100
committerDominic Steinitz <dominic@steinitz.org>2018-04-23 16:20:33 +0100
commit79962d2141f356b6a8018d767e49db162a146405 (patch)
tree232b774c1b138cc554096007a0a1138b1f327450
parent9f571e009bc46c26334be8b6a635db1e1d5b0341 (diff)
Ancilliary files for the start of CVODE support
-rw-r--r--packages/sundials/hmatrix-sundials.cabal10
-rw-r--r--packages/sundials/src/Arkode.hsc6
-rw-r--r--packages/sundials/src/Main.hs18
3 files changed, 24 insertions, 10 deletions
diff --git a/packages/sundials/hmatrix-sundials.cabal b/packages/sundials/hmatrix-sundials.cabal
index 388f1db..4cc02c6 100644
--- a/packages/sundials/hmatrix-sundials.cabal
+++ b/packages/sundials/hmatrix-sundials.cabal
@@ -25,10 +25,12 @@ library
25 template-haskell >=2.12 && <2.13, 25 template-haskell >=2.12 && <2.13,
26 containers >=0.5 && <0.6, 26 containers >=0.5 && <0.6,
27 hmatrix>=0.18 27 hmatrix>=0.18
28 extra-libraries: sundials_arkode 28 extra-libraries: sundials_arkode,
29 sundials_cvode
29 other-extensions: QuasiQuotes 30 other-extensions: QuasiQuotes
30 hs-source-dirs: src 31 hs-source-dirs: src
31 exposed-modules: Numeric.Sundials.ARKode.ODE 32 exposed-modules: Numeric.Sundials.ARKode.ODE,
33 Numeric.Sundials.CVode.ODE
32 other-modules: Types, 34 other-modules: Types,
33 Arkode 35 Arkode
34 c-sources: src/helpers.c src/helpers.h 36 c-sources: src/helpers.c src/helpers.h
@@ -39,6 +41,7 @@ test-suite hmatrix-sundials-testsuite
39 main-is: Main.hs 41 main-is: Main.hs
40 other-modules: Types, 42 other-modules: Types,
41 Numeric.Sundials.ARKode.ODE, 43 Numeric.Sundials.ARKode.ODE,
44 Numeric.Sundials.CVode.ODE,
42 Arkode 45 Arkode
43 build-depends: base >=4.10 && <4.11, 46 build-depends: base >=4.10 && <4.11,
44 inline-c >=0.6 && <0.7, 47 inline-c >=0.6 && <0.7,
@@ -52,6 +55,7 @@ test-suite hmatrix-sundials-testsuite
52 lens, 55 lens,
53 hspec 56 hspec
54 hs-source-dirs: src 57 hs-source-dirs: src
55 extra-libraries: sundials_arkode 58 extra-libraries: sundials_arkode,
59 sundials_cvode
56 c-sources: src/helpers.c src/helpers.h 60 c-sources: src/helpers.c src/helpers.h
57 default-language: Haskell2010 61 default-language: Haskell2010
diff --git a/packages/sundials/src/Arkode.hsc b/packages/sundials/src/Arkode.hsc
index 9db37b5..558ce9e 100644
--- a/packages/sundials/src/Arkode.hsc
+++ b/packages/sundials/src/Arkode.hsc
@@ -10,6 +10,7 @@ import Foreign.C.Types
10#include <nvector/nvector_serial.h> 10#include <nvector/nvector_serial.h>
11#include <sunmatrix/sunmatrix_dense.h> 11#include <sunmatrix/sunmatrix_dense.h>
12#include <arkode/arkode.h> 12#include <arkode/arkode.h>
13#include <cvode/cvode.h>
13 14
14 15
15#def typedef struct _generic_N_Vector SunVector; 16#def typedef struct _generic_N_Vector SunVector;
@@ -40,6 +41,11 @@ getContentPtr ptr = (#peek SunVector, content) ptr
40getData :: Storable a => Ptr b -> IO a 41getData :: Storable a => Ptr b -> IO a
41getData ptr = (#peek SunContent, data) ptr 42getData ptr = (#peek SunContent, data) ptr
42 43
44cV_ADAMS :: Int
45cV_ADAMS = #const CV_ADAMS
46cV_BDF :: Int
47cV_BDF = #const CV_BDF
48
43arkSMax :: Int 49arkSMax :: Int
44arkSMax = #const ARK_S_MAX 50arkSMax = #const ARK_S_MAX
45 51
diff --git a/packages/sundials/src/Main.hs b/packages/sundials/src/Main.hs
index 729d35a..3904b09 100644
--- a/packages/sundials/src/Main.hs
+++ b/packages/sundials/src/Main.hs
@@ -1,6 +1,7 @@
1{-# OPTIONS_GHC -Wall #-} 1{-# OPTIONS_GHC -Wall #-}
2 2
3import Numeric.Sundials.ARKode.ODE 3import qualified Numeric.Sundials.ARKode.ODE as ARK
4import qualified Numeric.Sundials.CVode.ODE as CV
4import Numeric.LinearAlgebra 5import Numeric.LinearAlgebra
5 6
6import Plots as P 7import Plots as P
@@ -97,24 +98,24 @@ kSaxis xs = P.r2Axis &~ do
97main :: IO () 98main :: IO ()
98main = do 99main = do
99 100
100 let res1 = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0]) 101 let res1 = ARK.odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0])
101 renderRasterific "diagrams/brusselator.png" 102 renderRasterific "diagrams/brusselator.png"
102 (D.dims2D 500.0 500.0) 103 (D.dims2D 500.0 500.0)
103 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res1)) 104 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res1))
104 105
105 let res1a = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0]) 106 let res1a = ARK.odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0])
106 renderRasterific "diagrams/brusselatorA.png" 107 renderRasterific "diagrams/brusselatorA.png"
107 (D.dims2D 500.0 500.0) 108 (D.dims2D 500.0 500.0)
108 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res1a)) 109 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res1a))
109 110
110 let res2 = odeSolve stiffish [0.0] (fromList [0.0, 0.1 .. 10.0]) 111 let res2 = ARK.odeSolve stiffish [0.0] (fromList [0.0, 0.1 .. 10.0])
111 renderRasterific "diagrams/stiffish.png" 112 renderRasterific "diagrams/stiffish.png"
112 (D.dims2D 500.0 500.0) 113 (D.dims2D 500.0 500.0)
113 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res2)) 114 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res2))
114 115
115 let res2a = odeSolveV (SDIRK_5_3_4') Nothing 1e-6 1e-10 stiffishV (fromList [0.0]) (fromList [0.0, 0.1 .. 10.0]) 116 let res2a = ARK.odeSolveV (ARK.SDIRK_5_3_4') Nothing 1e-6 1e-10 stiffishV (fromList [0.0]) (fromList [0.0, 0.1 .. 10.0])
116 117
117 let res2b = odeSolveV (TRBDF2_3_3_2') Nothing 1e-6 1e-10 stiffishV (fromList [0.0]) (fromList [0.0, 0.1 .. 10.0]) 118 let res2b = ARK.odeSolveV (ARK.TRBDF2_3_3_2') Nothing 1e-6 1e-10 stiffishV (fromList [0.0]) (fromList [0.0, 0.1 .. 10.0])
118 119
119 let maxDiff = maximum $ map abs $ 120 let maxDiff = maximum $ map abs $
120 zipWith (-) ((toLists $ tr res2a)!!0) ((toLists $ tr res2b)!!0) 121 zipWith (-) ((toLists $ tr res2a)!!0) ((toLists $ tr res2b)!!0)
@@ -123,7 +124,10 @@ main = do
123 it "for two different RK methods" $ 124 it "for two different RK methods" $
124 maxDiff < 1.0e-6 125 maxDiff < 1.0e-6
125 126
126 let res3 = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0]) 127 let res2c = CV.odeSolveV (CV.BDF) Nothing 1e-6 1e-10 stiffishV (fromList [0.0]) (fromList [0.0, 0.1 .. 10.0])
128 putStrLn $ show res2c
129
130 let res3 = ARK.odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0])
127 131
128 renderRasterific "diagrams/lorenz.png" 132 renderRasterific "diagrams/lorenz.png"
129 (D.dims2D 500.0 500.0) 133 (D.dims2D 500.0 500.0)