diff options
author | Dominic Steinitz <dominic@steinitz.org> | 2018-04-23 16:20:33 +0100 |
---|---|---|
committer | Dominic Steinitz <dominic@steinitz.org> | 2018-04-23 16:20:33 +0100 |
commit | 79962d2141f356b6a8018d767e49db162a146405 (patch) | |
tree | 232b774c1b138cc554096007a0a1138b1f327450 /packages/sundials/src | |
parent | 9f571e009bc46c26334be8b6a635db1e1d5b0341 (diff) |
Ancilliary files for the start of CVODE support
Diffstat (limited to 'packages/sundials/src')
-rw-r--r-- | packages/sundials/src/Arkode.hsc | 6 | ||||
-rw-r--r-- | packages/sundials/src/Main.hs | 18 |
2 files changed, 17 insertions, 7 deletions
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 | |||
40 | getData :: Storable a => Ptr b -> IO a | 41 | getData :: Storable a => Ptr b -> IO a |
41 | getData ptr = (#peek SunContent, data) ptr | 42 | getData ptr = (#peek SunContent, data) ptr |
42 | 43 | ||
44 | cV_ADAMS :: Int | ||
45 | cV_ADAMS = #const CV_ADAMS | ||
46 | cV_BDF :: Int | ||
47 | cV_BDF = #const CV_BDF | ||
48 | |||
43 | arkSMax :: Int | 49 | arkSMax :: Int |
44 | arkSMax = #const ARK_S_MAX | 50 | arkSMax = #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 | ||
3 | import Numeric.Sundials.ARKode.ODE | 3 | import qualified Numeric.Sundials.ARKode.ODE as ARK |
4 | import qualified Numeric.Sundials.CVode.ODE as CV | ||
4 | import Numeric.LinearAlgebra | 5 | import Numeric.LinearAlgebra |
5 | 6 | ||
6 | import Plots as P | 7 | import Plots as P |
@@ -97,24 +98,24 @@ kSaxis xs = P.r2Axis &~ do | |||
97 | main :: IO () | 98 | main :: IO () |
98 | main = do | 99 | main = 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) |