summaryrefslogtreecommitdiff
path: root/packages/sundials/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sundials/src/Main.hs')
-rw-r--r--packages/sundials/src/Main.hs21
1 files changed, 16 insertions, 5 deletions
diff --git a/packages/sundials/src/Main.hs b/packages/sundials/src/Main.hs
index fc48710..d1f35bd 100644
--- a/packages/sundials/src/Main.hs
+++ b/packages/sundials/src/Main.hs
@@ -21,6 +21,8 @@ import System.IO.Unsafe (unsafePerformIO)
21 21
22import Foreign.Storable (peekByteOff) 22import Foreign.Storable (peekByteOff)
23 23
24import Numeric.LinearAlgebra.HMatrix (Vector, Matrix)
25
24import qualified Types as T 26import qualified Types as T
25 27
26C.context (C.baseCtx <> C.vecCtx <> C.funCtx <> T.sunCtx) 28C.context (C.baseCtx <> C.vecCtx <> C.funCtx <> T.sunCtx)
@@ -91,10 +93,19 @@ brusselator _t x = V.fromList [ a - (w + 1) * u + v * u^2
91 v = x V.! 1 93 v = x V.! 1
92 w = x V.! 2 94 w = x V.! 2
93 95
94solveOdeC :: (CDouble -> V.Vector CDouble -> V.Vector CDouble) -> 96
95 V.Vector CDouble -> 97odeSolve :: (Double -> [Double] -> [Double]) -- ^ The RHS of the system \(\dot{y} = f(t,y)\)
96 Either CInt (V.Vector CDouble) 98 -> [Double] -- ^ initial conditions
97solveOdeC fun f0 = unsafePerformIO $ do 99 -> Vector Double -- ^ desired solution times
100 -> Matrix Double -- ^ solution
101odeSolve = undefined
102
103solveOdeC ::
104 (CDouble -> V.Vector CDouble -> V.Vector CDouble) -- ^ The RHS of the system \(\dot{y} = f(t,y)\)
105 -> V.Vector CDouble -- ^ Initial conditions
106 -> V.Vector CDouble -- ^ Desired solution times
107 -> Either CInt (V.Vector CDouble) -- ^ Error code or solution
108solveOdeC fun f0 ts = unsafePerformIO $ do
98 let dim = V.length f0 109 let dim = V.length f0
99 nEq :: CLong 110 nEq :: CLong
100 nEq = fromIntegral dim 111 nEq = fromIntegral dim
@@ -248,5 +259,5 @@ solveOdeC fun f0 = unsafePerformIO $ do
248 259
249main :: IO () 260main :: IO ()
250main = do 261main = do
251 let res = solveOdeC (coerce brusselator) (V.fromList [1.2, 3.1, 3.0]) 262 let res = solveOdeC (coerce brusselator) (V.fromList [1.2, 3.1, 3.0]) undefined
252 putStrLn $ show res 263 putStrLn $ show res