summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Steinitz <dominic@steinitz.org>2018-04-10 13:22:43 +0100
committerDominic Steinitz <dominic@steinitz.org>2018-04-10 13:22:43 +0100
commit6538dcb08e7a303bc1378d29c60812489089fd0f (patch)
treec35547ba3f72c475ae576afdfd40db34be34f699
parent3f28b18d880f055c445f19ab3a982112a51c09d9 (diff)
Another change of tack
-rw-r--r--packages/sundials/src/Main.hs26
-rw-r--r--shell.nix86
-rw-r--r--stack.yaml6
3 files changed, 40 insertions, 78 deletions
diff --git a/packages/sundials/src/Main.hs b/packages/sundials/src/Main.hs
index b65d668..14b1f8a 100644
--- a/packages/sundials/src/Main.hs
+++ b/packages/sundials/src/Main.hs
@@ -25,8 +25,8 @@ lorenz _t u = [ sigma * (y - x)
25 y = u !! 1 25 y = u !! 1
26 z = u !! 2 26 z = u !! 2
27 27
28lorenzJac :: Double -> Vector Double -> Matrix Double 28_lorenzJac :: Double -> Vector Double -> Matrix Double
29lorenzJac _t u = (3><3) [ (-sigma), rho - z, y 29_lorenzJac _t u = (3><3) [ (-sigma), rho - z, y
30 , sigma , -1.0 , x 30 , sigma , -1.0 , x
31 , 0.0 , (-x) , (-beta) 31 , 0.0 , (-x) , (-beta)
32 ] 32 ]
@@ -51,8 +51,8 @@ brusselator _t x = [ a - (w + 1) * u + v * u * u
51 v = x !! 1 51 v = x !! 1
52 w = x !! 2 52 w = x !! 2
53 53
54brussJac :: Double -> Vector Double -> Matrix Double 54_brussJac :: Double -> Vector Double -> Matrix Double
55brussJac _t x = (3><3) [ (-(w + 1.0)) + 2.0 * u * v, w - 2.0 * u * v, (-w) 55_brussJac _t x = (3><3) [ (-(w + 1.0)) + 2.0 * u * v, w - 2.0 * u * v, (-w)
56 , u * u , (-(u * u)) , 0.0 56 , u * u , (-(u * u)) , 0.0
57 , (-u) , u , (-1.0) / eps - u 57 , (-u) , u , (-1.0) / eps - u
58 ] 58 ]
@@ -120,13 +120,13 @@ main = do
120 putStrLn $ show res 120 putStrLn $ show res
121 putStrLn $ butcherTableauTex res 121 putStrLn $ butcherTableauTex res
122 122
123 let res = butcherTable (KVAERNO_4_2_3 undefined) 123 let resA = butcherTable (KVAERNO_4_2_3 undefined)
124 putStrLn $ show res 124 putStrLn $ show resA
125 putStrLn $ butcherTableauTex res 125 putStrLn $ butcherTableauTex resA
126 126
127 let res = butcherTable (SDIRK_5_3_4 undefined) 127 let resB = butcherTable (SDIRK_5_3_4 undefined)
128 putStrLn $ show res 128 putStrLn $ show resB
129 putStrLn $ butcherTableauTex res 129 putStrLn $ butcherTableauTex resB
130 130
131 let res1 = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0]) 131 let res1 = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0])
132 renderRasterific "diagrams/brusselator.png" 132 renderRasterific "diagrams/brusselator.png"
@@ -151,12 +151,12 @@ main = do
151 let res3 = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0]) 151 let res3 = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0])
152 putStrLn $ show $ last ((toLists $ tr res3)!!0) 152 putStrLn $ show $ last ((toLists $ tr res3)!!0)
153 153
154 let res3 = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0]) 154 let res3A = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0])
155 putStrLn $ show $ last ((toLists $ tr res3)!!0) 155 putStrLn $ show $ last ((toLists $ tr res3A)!!0)
156 156
157 renderRasterific "diagrams/lorenz.png" 157 renderRasterific "diagrams/lorenz.png"
158 (D.dims2D 500.0 500.0) 158 (D.dims2D 500.0 500.0)
159 (renderAxis $ kSaxis $ zip ((toLists $ tr res3)!!0) ((toLists $ tr res3)!!1)) 159 (renderAxis $ kSaxis $ zip ((toLists $ tr res3)!!0) ((toLists $ tr res3A)!!1))
160 160
161 let res3a = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0]) 161 let res3a = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0])
162 renderRasterific "diagrams/lorenzA.png" 162 renderRasterific "diagrams/lorenzA.png"
diff --git a/shell.nix b/shell.nix
index d22f886..42bbe08 100644
--- a/shell.nix
+++ b/shell.nix
@@ -1,64 +1,26 @@
1{ nixpkgs ? import <nixpkgs> {} 1{ nixpkgs ? import <nixpkgs> {} }:
2, compiler ? "ghc822", doBenchmark ? false }: 2let p = nixpkgs; in
3
4let
5
6 inherit (nixpkgs) pkgs;
7
8f = { mkDerivation, base, containers, diagrams-lib, diagrams-rasterific, gcc
9 , hmatrix, hmatrix-gsl, HUnit, inline-c, plots, stdenv
10 , template-haskell, temporary, vector }:
11
12mkDerivation {
13 pname = "hmatrix-sundials";
14 version = "0.1.0.0";
15 src = ./.;
16 isLibrary = true;
17 isExecutable = true;
18 libraryHaskellDepends = [
19 base
20 containers
21 hmatrix
22 inline-c
23 template-haskell
24 vector
25 ];
26 executableHaskellDepends = [
27 base
28 diagrams-lib
29 diagrams-rasterific
30 gcc
31 hmatrix
32 hmatrix-gsl
33 HUnit
34 inline-c
35 template-haskell
36 temporary
37 vector
38 ] ++ (if pkgs.stdenv.isDarwin then [pkgs.darwin.apple_sdk.frameworks.Cocoa] else []);
39 executableSystemDepends = [
40 pkgs.blas
41 pkgs.gfortran.cc
42 pkgs.liblapack
43 pkgs.gsl
44 pkgs.glpk
45 pkgs.pkgconfig
46 pkgs.stack
47 pkgs.sundials
48 pkgs.zlib
49 ] ++ (if pkgs.stdenv.isDarwin then [pkgs.darwin.apple_sdk.frameworks.Accelerate] else []);
50 license = stdenv.lib.licenses.bsd3;
51};
52
53 haskellPackages = if compiler == "default"
54 then pkgs.haskellPackages
55 else pkgs.haskell.packages.${compiler};
56
57 variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
58
59 drv = variant (haskellPackages.callPackage f {});
60 3
4 let
5 myStack = p.writeShellScriptBin "stack" ''
6 exec ${p.stack}/bin/stack --no-nix --no-docker --system-ghc $STACK_IN_NIX_EXTRA_ARGS "$@"
7 '';
61in 8in
62 9p.haskell.lib.buildStackProject {
63 if pkgs.lib.inNixShell then drv.env else drv 10 name = "hmatrix";
64 11
12 buildInputs = [
13 p.zlib
14 p.sundials
15 p.blas
16 p.gfortran.cc
17 p.liblapack
18 p.gsl
19 p.glpk
20 p.pkgconfig
21 p.stack
22 p.sundials
23 myStack
24 ] ++ (if p.stdenv.isDarwin then [p.darwin.apple_sdk.frameworks.Accelerate] else [])
25 ++ (if p.stdenv.isDarwin then [p.darwin.apple_sdk.frameworks.Cocoa] else []);
26}
diff --git a/stack.yaml b/stack.yaml
index 8e9e5c2..04bbfb6 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -18,6 +18,6 @@ extra-deps:
18- diagrams-rasterific-1.4 18- diagrams-rasterific-1.4
19- plots-0.1.0.2 19- plots-0.1.0.2
20resolver: lts-10.9 20resolver: lts-10.9
21# nix: 21nix:
22# path: [nixpkgs=./nixpkgs.nix] 22 path: [nixpkgs=./nixpkgs.nix]
23# shell-file: shell.nix 23 shell-file: shell.nix