diff options
-rw-r--r-- | packages/sundials/src/Numeric/Sundials/ARKode/ODE.hs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/packages/sundials/src/Numeric/Sundials/ARKode/ODE.hs b/packages/sundials/src/Numeric/Sundials/ARKode/ODE.hs index d0c58dc..2ede918 100644 --- a/packages/sundials/src/Numeric/Sundials/ARKode/ODE.hs +++ b/packages/sundials/src/Numeric/Sundials/ARKode/ODE.hs | |||
@@ -151,7 +151,7 @@ odeSolve :: ODEMethod | |||
151 | -> Vector Double -- ^ desired solution times | 151 | -> Vector Double -- ^ desired solution times |
152 | -> Matrix Double -- ^ solution | 152 | -> Matrix Double -- ^ solution |
153 | odeSolve method f y0 ts = | 153 | odeSolve method f y0 ts = |
154 | case solveOde method g (V.fromList y0) (V.fromList $ toList ts) of | 154 | case solveOde method 1.0e-6 1.0e-10 g (V.fromList y0) (V.fromList $ toList ts) of |
155 | Left c -> error $ show c -- FIXME | 155 | Left c -> error $ show c -- FIXME |
156 | Right (v, _) -> (nR >< nC) (V.toList v) | 156 | Right (v, _) -> (nR >< nC) (V.toList v) |
157 | where | 157 | where |
@@ -162,22 +162,27 @@ odeSolve method f y0 ts = | |||
162 | 162 | ||
163 | solveOde :: | 163 | solveOde :: |
164 | ODEMethod | 164 | ODEMethod |
165 | -> Double | ||
166 | -> Double | ||
165 | -> (Double -> V.Vector Double -> V.Vector Double) -- ^ The RHS of the system \(\dot{y} = f(t,y)\) | 167 | -> (Double -> V.Vector Double -> V.Vector Double) -- ^ The RHS of the system \(\dot{y} = f(t,y)\) |
166 | -> V.Vector Double -- ^ Initial conditions | 168 | -> V.Vector Double -- ^ Initial conditions |
167 | -> V.Vector Double -- ^ Desired solution times | 169 | -> V.Vector Double -- ^ Desired solution times |
168 | -> Either Int ((V.Vector Double), SundialsDiagnostics) -- ^ Error code or solution | 170 | -> Either Int ((V.Vector Double), SundialsDiagnostics) -- ^ Error code or solution |
169 | solveOde method f y0 tt = | 171 | solveOde method relTol absTol f y0 tt = |
170 | case solveOdeC (fromIntegral $ fromEnum method) (coerce f) (coerce y0) (coerce tt) of | 172 | case solveOdeC (fromIntegral $ fromEnum method) (CDouble relTol) (CDouble absTol) |
173 | (coerce f) (coerce y0) (coerce tt) of | ||
171 | Left c -> Left $ fromIntegral c | 174 | Left c -> Left $ fromIntegral c |
172 | Right (v, d) -> Right (coerce v, d) | 175 | Right (v, d) -> Right (coerce v, d) |
173 | 176 | ||
174 | solveOdeC :: | 177 | solveOdeC :: |
175 | CInt -> | 178 | CInt -> |
179 | CDouble -> | ||
180 | CDouble -> | ||
176 | (CDouble -> V.Vector CDouble -> V.Vector CDouble) -- ^ The RHS of the system \(\dot{y} = f(t,y)\) | 181 | (CDouble -> V.Vector CDouble -> V.Vector CDouble) -- ^ The RHS of the system \(\dot{y} = f(t,y)\) |
177 | -> V.Vector CDouble -- ^ Initial conditions | 182 | -> V.Vector CDouble -- ^ Initial conditions |
178 | -> V.Vector CDouble -- ^ Desired solution times | 183 | -> V.Vector CDouble -- ^ Desired solution times |
179 | -> Either CInt ((V.Vector CDouble), SundialsDiagnostics) -- ^ Error code or solution | 184 | -> Either CInt ((V.Vector CDouble), SundialsDiagnostics) -- ^ Error code or solution |
180 | solveOdeC method fun f0 ts = unsafePerformIO $ do | 185 | solveOdeC method relTol absTol fun f0 ts = unsafePerformIO $ do |
181 | let dim = V.length f0 | 186 | let dim = V.length f0 |
182 | nEq :: CLong | 187 | nEq :: CLong |
183 | nEq = fromIntegral dim | 188 | nEq = fromIntegral dim |
@@ -216,15 +221,7 @@ solveOdeC method fun f0 ts = unsafePerformIO $ do | |||
216 | 221 | ||
217 | /* general problem parameters */ | 222 | /* general problem parameters */ |
218 | realtype T0 = RCONST(($vec-ptr:(double *tMut))[0]); /* initial time */ | 223 | realtype T0 = RCONST(($vec-ptr:(double *tMut))[0]); /* initial time */ |
219 | |||
220 | sunindextype NEQ = $(sunindextype nEq); /* number of dependent vars. */ | 224 | sunindextype NEQ = $(sunindextype nEq); /* number of dependent vars. */ |
221 | realtype reltol = 1.0e-6; /* tolerances */ | ||
222 | realtype abstol = 1.0e-10; | ||
223 | |||
224 | /* Initial diagnostics output */ | ||
225 | printf("\nAnalytical ODE test problem:\n"); | ||
226 | printf(" reltol = %.1"ESYM"\n", reltol); | ||
227 | printf(" abstol = %.1"ESYM"\n\n",abstol); | ||
228 | 225 | ||
229 | /* Initialize data structures */ | 226 | /* Initialize data structures */ |
230 | y = N_VNew_Serial(NEQ); /* Create serial vector for solution */ | 227 | y = N_VNew_Serial(NEQ); /* Create serial vector for solution */ |
@@ -247,7 +244,7 @@ solveOdeC method fun f0 ts = unsafePerformIO $ do | |||
247 | if (check_flag(&flag, "ARKodeInit", 1)) return 1; | 244 | if (check_flag(&flag, "ARKodeInit", 1)) return 1; |
248 | 245 | ||
249 | /* Set routines */ | 246 | /* Set routines */ |
250 | flag = ARKodeSStolerances(arkode_mem, reltol, abstol); /* Specify tolerances */ | 247 | flag = ARKodeSStolerances(arkode_mem, $(double relTol), $(double absTol)); |
251 | if (check_flag(&flag, "ARKodeSStolerances", 1)) return 1; | 248 | if (check_flag(&flag, "ARKodeSStolerances", 1)) return 1; |
252 | 249 | ||
253 | /* Initialize dense matrix data structure and solver */ | 250 | /* Initialize dense matrix data structure and solver */ |