diff options
Diffstat (limited to 'packages/sundials/src/Numeric/Sundials/ODEOpts.hs')
-rw-r--r-- | packages/sundials/src/Numeric/Sundials/ODEOpts.hs | 51 |
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 @@ | |||
1 | module Numeric.Sundials.ODEOpts where | 1 | module Numeric.Sundials.ODEOpts where |
2 | 2 | ||
3 | import Data.Int (Int32) | 3 | import Data.Int (Int32) |
4 | import Foreign.Ptr (Ptr) | ||
5 | import Foreign.Storable as FS | ||
6 | import Foreign.ForeignPtr as FF | ||
7 | import Foreign.C.Types | ||
8 | import qualified Data.Vector.Storable as VS | 4 | import qualified Data.Vector.Storable as VS |
9 | import qualified Data.Vector.Storable.Mutable as VM | ||
10 | 5 | ||
11 | import Numeric.LinearAlgebra.HMatrix (Vector, Matrix) | 6 | import Numeric.LinearAlgebra.HMatrix (Vector, Matrix) |
12 | 7 | ||
13 | import qualified Numeric.Sundials.CLangToHaskellTypes as T | ||
14 | import qualified Numeric.Sundials.Arkode as B | ||
15 | 8 | ||
16 | type Jacobian = Double -> Vector Double -> Matrix Double | 9 | type 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 | |||
36 | putMatrixDataFromContents :: T.SunMatrix -> Ptr T.SunMatrix -> IO () | ||
37 | putMatrixDataFromContents 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 | |||
48 | vectorFromC :: Storable a => Int -> Ptr a -> IO (VS.Vector a) | ||
49 | vectorFromC len ptr = do | ||
50 | ptr' <- newForeignPtr_ ptr | ||
51 | VS.freeze $ VM.unsafeFromForeignPtr0 ptr' len | ||
52 | |||
53 | vectorToC :: Storable a => VS.Vector a -> Int -> Ptr a -> IO () | ||
54 | vectorToC vec len ptr = do | ||
55 | ptr' <- newForeignPtr_ ptr | ||
56 | VS.copy (VM.unsafeFromForeignPtr0 ptr' len) vec | ||
57 | |||
58 | getDataFromContents :: Int -> Ptr T.SunVector -> IO (VS.Vector CDouble) | ||
59 | getDataFromContents len ptr = do | ||
60 | qtr <- B.getContentPtr ptr | ||
61 | rtr <- B.getData qtr | ||
62 | vectorFromC len rtr | ||
63 | |||
64 | putDataInContents :: Storable a => VS.Vector a -> Int -> Ptr b -> IO () | ||
65 | putDataInContents vec len ptr = do | ||
66 | qtr <- B.getContentPtr ptr | ||
67 | rtr <- B.getData qtr | ||
68 | vectorToC vec len rtr | ||
69 | |||
70 | data SundialsDiagnostics = SundialsDiagnostics { | 19 | data SundialsDiagnostics = SundialsDiagnostics { |
71 | aRKodeGetNumSteps :: Int | 20 | aRKodeGetNumSteps :: Int |
72 | , aRKodeGetNumStepAttempts :: Int | 21 | , aRKodeGetNumStepAttempts :: Int |