From 6538dcb08e7a303bc1378d29c60812489089fd0f Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Tue, 10 Apr 2018 13:22:43 +0100 Subject: Another change of tack --- packages/sundials/src/Main.hs | 26 ++++++------- shell.nix | 86 ++++++++++++------------------------------- stack.yaml | 6 +-- 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) y = u !! 1 z = u !! 2 -lorenzJac :: Double -> Vector Double -> Matrix Double -lorenzJac _t u = (3><3) [ (-sigma), rho - z, y +_lorenzJac :: Double -> Vector Double -> Matrix Double +_lorenzJac _t u = (3><3) [ (-sigma), rho - z, y , sigma , -1.0 , x , 0.0 , (-x) , (-beta) ] @@ -51,8 +51,8 @@ brusselator _t x = [ a - (w + 1) * u + v * u * u v = x !! 1 w = x !! 2 -brussJac :: Double -> Vector Double -> Matrix Double -brussJac _t x = (3><3) [ (-(w + 1.0)) + 2.0 * u * v, w - 2.0 * u * v, (-w) +_brussJac :: Double -> Vector Double -> Matrix Double +_brussJac _t x = (3><3) [ (-(w + 1.0)) + 2.0 * u * v, w - 2.0 * u * v, (-w) , u * u , (-(u * u)) , 0.0 , (-u) , u , (-1.0) / eps - u ] @@ -120,13 +120,13 @@ main = do putStrLn $ show res putStrLn $ butcherTableauTex res - let res = butcherTable (KVAERNO_4_2_3 undefined) - putStrLn $ show res - putStrLn $ butcherTableauTex res + let resA = butcherTable (KVAERNO_4_2_3 undefined) + putStrLn $ show resA + putStrLn $ butcherTableauTex resA - let res = butcherTable (SDIRK_5_3_4 undefined) - putStrLn $ show res - putStrLn $ butcherTableauTex res + let resB = butcherTable (SDIRK_5_3_4 undefined) + putStrLn $ show resB + putStrLn $ butcherTableauTex resB let res1 = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0]) renderRasterific "diagrams/brusselator.png" @@ -151,12 +151,12 @@ main = do let res3 = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0]) putStrLn $ show $ last ((toLists $ tr res3)!!0) - let res3 = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0]) - putStrLn $ show $ last ((toLists $ tr res3)!!0) + let res3A = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0]) + putStrLn $ show $ last ((toLists $ tr res3A)!!0) renderRasterific "diagrams/lorenz.png" (D.dims2D 500.0 500.0) - (renderAxis $ kSaxis $ zip ((toLists $ tr res3)!!0) ((toLists $ tr res3)!!1)) + (renderAxis $ kSaxis $ zip ((toLists $ tr res3)!!0) ((toLists $ tr res3A)!!1)) let res3a = odeSolve lorenz [-5.0, -5.0, 1.0] (fromList [0.0, 0.01 .. 10.0]) 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 @@ -{ nixpkgs ? import {} -, compiler ? "ghc822", doBenchmark ? false }: - -let - - inherit (nixpkgs) pkgs; - -f = { mkDerivation, base, containers, diagrams-lib, diagrams-rasterific, gcc - , hmatrix, hmatrix-gsl, HUnit, inline-c, plots, stdenv - , template-haskell, temporary, vector }: - -mkDerivation { - pname = "hmatrix-sundials"; - version = "0.1.0.0"; - src = ./.; - isLibrary = true; - isExecutable = true; - libraryHaskellDepends = [ - base - containers - hmatrix - inline-c - template-haskell - vector - ]; - executableHaskellDepends = [ - base - diagrams-lib - diagrams-rasterific - gcc - hmatrix - hmatrix-gsl - HUnit - inline-c - template-haskell - temporary - vector - ] ++ (if pkgs.stdenv.isDarwin then [pkgs.darwin.apple_sdk.frameworks.Cocoa] else []); - executableSystemDepends = [ - pkgs.blas - pkgs.gfortran.cc - pkgs.liblapack - pkgs.gsl - pkgs.glpk - pkgs.pkgconfig - pkgs.stack - pkgs.sundials - pkgs.zlib - ] ++ (if pkgs.stdenv.isDarwin then [pkgs.darwin.apple_sdk.frameworks.Accelerate] else []); - license = stdenv.lib.licenses.bsd3; -}; - - haskellPackages = if compiler == "default" - then pkgs.haskellPackages - else pkgs.haskell.packages.${compiler}; - - variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id; - - drv = variant (haskellPackages.callPackage f {}); +{ nixpkgs ? import {} }: +let p = nixpkgs; in + let + myStack = p.writeShellScriptBin "stack" '' + exec ${p.stack}/bin/stack --no-nix --no-docker --system-ghc $STACK_IN_NIX_EXTRA_ARGS "$@" + ''; in - - if pkgs.lib.inNixShell then drv.env else drv - +p.haskell.lib.buildStackProject { + name = "hmatrix"; + + buildInputs = [ + p.zlib + p.sundials + p.blas + p.gfortran.cc + p.liblapack + p.gsl + p.glpk + p.pkgconfig + p.stack + p.sundials + myStack + ] ++ (if p.stdenv.isDarwin then [p.darwin.apple_sdk.frameworks.Accelerate] else []) + ++ (if p.stdenv.isDarwin then [p.darwin.apple_sdk.frameworks.Cocoa] else []); +} diff --git a/stack.yaml b/stack.yaml index 8e9e5c2..04bbfb6 100644 --- a/stack.yaml +++ b/stack.yaml @@ -18,6 +18,6 @@ extra-deps: - diagrams-rasterific-1.4 - plots-0.1.0.2 resolver: lts-10.9 -# nix: -# path: [nixpkgs=./nixpkgs.nix] -# shell-file: shell.nix +nix: + path: [nixpkgs=./nixpkgs.nix] + shell-file: shell.nix -- cgit v1.2.3