summaryrefslogtreecommitdiff
path: root/packages/sundials/src/Numeric/Sundials/ODEOpts.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sundials/src/Numeric/Sundials/ODEOpts.hs')
-rw-r--r--packages/sundials/src/Numeric/Sundials/ODEOpts.hs51
1 files changed, 0 insertions, 51 deletions
diff --git a/packages/sundials/src/Numeric/Sundials/ODEOpts.hs b/packages/sundials/src/Numeric/Sundials/ODEOpts.hs
index 56dc12c..89f2306 100644
--- a/packages/sundials/src/Numeric/Sundials/ODEOpts.hs
+++ b/packages/sundials/src/Numeric/Sundials/ODEOpts.hs
@@ -1,17 +1,10 @@
1module Numeric.Sundials.ODEOpts where 1module Numeric.Sundials.ODEOpts where
2 2
3import Data.Int (Int32) 3import Data.Int (Int32)
4import Foreign.Ptr (Ptr)
5import Foreign.Storable as FS
6import Foreign.ForeignPtr as FF
7import Foreign.C.Types
8import qualified Data.Vector.Storable as VS 4import qualified Data.Vector.Storable as VS
9import qualified Data.Vector.Storable.Mutable as VM
10 5
11import Numeric.LinearAlgebra.HMatrix (Vector, Matrix) 6import Numeric.LinearAlgebra.HMatrix (Vector, Matrix)
12 7
13import qualified Numeric.Sundials.CLangToHaskellTypes as T
14import qualified Numeric.Sundials.Arkode as B
15 8
16type Jacobian = Double -> Vector Double -> Matrix Double 9type Jacobian = Double -> Vector Double -> Matrix Double
17 10
@@ -23,50 +16,6 @@ data ODEOpts = ODEOpts {
23 , initStep :: Double 16 , initStep :: Double
24 } deriving (Read, Show, Eq, Ord) 17 } deriving (Read, Show, Eq, Ord)
25 18
26-- FIXME: Potentially an instance of Storable
27_getMatrixDataFromContents :: Ptr T.SunMatrix -> IO T.SunMatrix
28_getMatrixDataFromContents ptr = do
29 qtr <- B.getContentMatrixPtr ptr
30 rs <- B.getNRows qtr
31 cs <- B.getNCols qtr
32 rtr <- B.getMatrixData qtr
33 vs <- vectorFromC (fromIntegral $ rs * cs) rtr
34 return $ T.SunMatrix { T.rows = rs, T.cols = cs, T.vals = vs }
35
36putMatrixDataFromContents :: T.SunMatrix -> Ptr T.SunMatrix -> IO ()
37putMatrixDataFromContents mat ptr = do
38 let rs = T.rows mat
39 cs = T.cols mat
40 vs = T.vals mat
41 qtr <- B.getContentMatrixPtr ptr
42 B.putNRows rs qtr
43 B.putNCols cs qtr
44 rtr <- B.getMatrixData qtr
45 vectorToC vs (fromIntegral $ rs * cs) rtr
46-- FIXME: END
47
48vectorFromC :: Storable a => Int -> Ptr a -> IO (VS.Vector a)
49vectorFromC len ptr = do
50 ptr' <- newForeignPtr_ ptr
51 VS.freeze $ VM.unsafeFromForeignPtr0 ptr' len
52
53vectorToC :: Storable a => VS.Vector a -> Int -> Ptr a -> IO ()
54vectorToC vec len ptr = do
55 ptr' <- newForeignPtr_ ptr
56 VS.copy (VM.unsafeFromForeignPtr0 ptr' len) vec
57
58getDataFromContents :: Int -> Ptr T.SunVector -> IO (VS.Vector CDouble)
59getDataFromContents len ptr = do
60 qtr <- B.getContentPtr ptr
61 rtr <- B.getData qtr
62 vectorFromC len rtr
63
64putDataInContents :: Storable a => VS.Vector a -> Int -> Ptr b -> IO ()
65putDataInContents vec len ptr = do
66 qtr <- B.getContentPtr ptr
67 rtr <- B.getData qtr
68 vectorToC vec len rtr
69
70data SundialsDiagnostics = SundialsDiagnostics { 19data SundialsDiagnostics = SundialsDiagnostics {
71 aRKodeGetNumSteps :: Int 20 aRKodeGetNumSteps :: Int
72 , aRKodeGetNumStepAttempts :: Int 21 , aRKodeGetNumStepAttempts :: Int