diff options
Diffstat (limited to 'packages/sundials/src/Main.hs')
-rw-r--r-- | packages/sundials/src/Main.hs | 21 |
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 | ||
22 | import Foreign.Storable (peekByteOff) | 22 | import Foreign.Storable (peekByteOff) |
23 | 23 | ||
24 | import Numeric.LinearAlgebra.HMatrix (Vector, Matrix) | ||
25 | |||
24 | import qualified Types as T | 26 | import qualified Types as T |
25 | 27 | ||
26 | C.context (C.baseCtx <> C.vecCtx <> C.funCtx <> T.sunCtx) | 28 | C.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 | ||
94 | solveOdeC :: (CDouble -> V.Vector CDouble -> V.Vector CDouble) -> | 96 | |
95 | V.Vector CDouble -> | 97 | odeSolve :: (Double -> [Double] -> [Double]) -- ^ The RHS of the system \(\dot{y} = f(t,y)\) |
96 | Either CInt (V.Vector CDouble) | 98 | -> [Double] -- ^ initial conditions |
97 | solveOdeC fun f0 = unsafePerformIO $ do | 99 | -> Vector Double -- ^ desired solution times |
100 | -> Matrix Double -- ^ solution | ||
101 | odeSolve = undefined | ||
102 | |||
103 | solveOdeC :: | ||
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 | ||
108 | solveOdeC 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 | ||
249 | main :: IO () | 260 | main :: IO () |
250 | main = do | 261 | main = 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 |