diff options
Diffstat (limited to 'packages/sundials/src/Numeric/Sundials/ODEOpts.hs')
-rw-r--r-- | packages/sundials/src/Numeric/Sundials/ODEOpts.hs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/packages/sundials/src/Numeric/Sundials/ODEOpts.hs b/packages/sundials/src/Numeric/Sundials/ODEOpts.hs new file mode 100644 index 0000000..e924292 --- /dev/null +++ b/packages/sundials/src/Numeric/Sundials/ODEOpts.hs | |||
@@ -0,0 +1,78 @@ | |||
1 | module Numeric.Sundials.ODEOpts where | ||
2 | |||
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 | ||
9 | import qualified Data.Vector.Storable.Mutable as VM | ||
10 | |||
11 | import qualified Types as T | ||
12 | import qualified Arkode as B | ||
13 | |||
14 | data ODEOpts = ODEOpts { | ||
15 | maxNumSteps :: Int32 | ||
16 | , minStep :: Double | ||
17 | , relTol :: Double | ||
18 | , absTols :: VS.Vector Double | ||
19 | , initStep :: Double | ||
20 | } deriving (Read, Show, Eq, Ord) | ||
21 | |||
22 | -- FIXME: Potentially an instance of Storable | ||
23 | _getMatrixDataFromContents :: Ptr T.SunMatrix -> IO T.SunMatrix | ||
24 | _getMatrixDataFromContents ptr = do | ||
25 | qtr <- B.getContentMatrixPtr ptr | ||
26 | rs <- B.getNRows qtr | ||
27 | cs <- B.getNCols qtr | ||
28 | rtr <- B.getMatrixData qtr | ||
29 | vs <- vectorFromC (fromIntegral $ rs * cs) rtr | ||
30 | return $ T.SunMatrix { T.rows = rs, T.cols = cs, T.vals = vs } | ||
31 | |||
32 | putMatrixDataFromContents :: T.SunMatrix -> Ptr T.SunMatrix -> IO () | ||
33 | putMatrixDataFromContents mat ptr = do | ||
34 | let rs = T.rows mat | ||
35 | cs = T.cols mat | ||
36 | vs = T.vals mat | ||
37 | qtr <- B.getContentMatrixPtr ptr | ||
38 | B.putNRows rs qtr | ||
39 | B.putNCols cs qtr | ||
40 | rtr <- B.getMatrixData qtr | ||
41 | vectorToC vs (fromIntegral $ rs * cs) rtr | ||
42 | -- FIXME: END | ||
43 | |||
44 | vectorFromC :: Storable a => Int -> Ptr a -> IO (VS.Vector a) | ||
45 | vectorFromC len ptr = do | ||
46 | ptr' <- newForeignPtr_ ptr | ||
47 | VS.freeze $ VM.unsafeFromForeignPtr0 ptr' len | ||
48 | |||
49 | vectorToC :: Storable a => VS.Vector a -> Int -> Ptr a -> IO () | ||
50 | vectorToC vec len ptr = do | ||
51 | ptr' <- newForeignPtr_ ptr | ||
52 | VS.copy (VM.unsafeFromForeignPtr0 ptr' len) vec | ||
53 | |||
54 | getDataFromContents :: Int -> Ptr T.SunVector -> IO (VS.Vector CDouble) | ||
55 | getDataFromContents len ptr = do | ||
56 | qtr <- B.getContentPtr ptr | ||
57 | rtr <- B.getData qtr | ||
58 | vectorFromC len rtr | ||
59 | |||
60 | putDataInContents :: Storable a => VS.Vector a -> Int -> Ptr b -> IO () | ||
61 | putDataInContents vec len ptr = do | ||
62 | qtr <- B.getContentPtr ptr | ||
63 | rtr <- B.getData qtr | ||
64 | vectorToC vec len rtr | ||
65 | |||
66 | data SundialsDiagnostics = SundialsDiagnostics { | ||
67 | aRKodeGetNumSteps :: Int | ||
68 | , aRKodeGetNumStepAttempts :: Int | ||
69 | , aRKodeGetNumRhsEvals_fe :: Int | ||
70 | , aRKodeGetNumRhsEvals_fi :: Int | ||
71 | , aRKodeGetNumLinSolvSetups :: Int | ||
72 | , aRKodeGetNumErrTestFails :: Int | ||
73 | , aRKodeGetNumNonlinSolvIters :: Int | ||
74 | , aRKodeGetNumNonlinSolvConvFails :: Int | ||
75 | , aRKDlsGetNumJacEvals :: Int | ||
76 | , aRKDlsGetNumRhsEvals :: Int | ||
77 | } deriving Show | ||
78 | |||