sg-ode
ode.h
Go to the documentation of this file.
1 #ifndef G_U239L9IU4I9YYJGH4M9CD6ADMGT66
2 #define G_U239L9IU4I9YYJGH4M9CD6ADMGT66
3 
26 #include <stdbool.h>
27 #include <math.h>
28 #include "vector.h"
29 #include "extern.h"
30 #include "restrict_begin.h"
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
36 #define SG_ODE_FSTRICT 0x1
37 
40 #define SG_ODE_FMAXNUM 0x2
41 
48 #define SG_ODE_ETOLER 3
49 
52 #define SG_ODE_ESTEPS 4
53 
56 #define SG_ODE_ESTIFF 5
57 
59 #define SG_ODE_EINVAL 6
60 
61 enum {
62  SG_ODE_TYPE_BOOL,
63  SG_ODE_TYPE_DOUBLE,
64  SG_ODE_TYPE_UNSIGNED,
65  SG_ODE_TYPE_VECTOR,
66 };
67 
68 typedef void SgDerivFn(void *f_ctx,
69  double t,
70  const SgVector *restrict y,
71  SgVector *restrict yp);
72 
73 SG_EXTERN struct SgOde *sg_ode_try_new(struct SgVectorDriver drv);
74 
75 SG_EXTERN void sg_ode_del(struct SgOde *self);
76 
77 SG_EXTERN int sg_ode_traverse(struct SgOde *self,
78  int (*f)(void *ctx,
79  void *data,
80  int type,
81  size_t len),
82  void *ctx);
83 
178 SG_EXTERN int sg_ode_step(struct SgOde *self,
179  SgDerivFn *f,
180  void *restrict f_ctx,
181  double *restrict eps);
182 
205 SG_EXTERN void sg_ode_interpolate(struct SgVectorDriver drv,
206  double x,
207  const SgVector *restrict y,
208  double xout,
209  SgVector *restrict yout,
210  SgVector *restrict ypout,
211  unsigned kold,
212  SgVector *const restrict *phi,
213  const double *restrict psi);
214 
331 SG_EXTERN void sg_ode_de(struct SgOde *self,
332  SgDerivFn *f,
333  void *restrict f_ctx,
334  SgVector *restrict y,
335  double *restrict t,
336  double tout,
337  double *restrict relerr,
338  double *restrict abserr,
339  int *restrict iflag,
340  unsigned maxnum);
341 
407 SG_EXTERN int sg_ode(void *f_ctx,
408  void (*f)(void *, double, const double *, double *),
409  size_t neqn,
410  double *restrict y,
411  double *restrict t,
412  double tout,
413  double relerr,
414  double abserr,
415  int flag,
416  double *restrict work,
417  int *restrict iwork);
418 
419 #ifdef __cplusplus
420 }
421 #endif
422 #include "restrict_end.h"
423 #endif
A vector driver.
Definition: vector.h:132
Definition: ode.c:366
void sg_ode_interpolate(struct SgVectorDriver drv, double x, const SgVector *restrict y, double xout, SgVector *restrict yout, SgVector *restrict ypout, unsigned kold, SgVector *const restrict *phi, const double *restrict psi)
The methods in function step approximate the solution near x by a polynomial.
Definition: ode.c:800
double x
Independent variable.
Definition: ode.c:380
A generic interface for elementwise and aggregate operations on vectors.
int sg_ode_step(struct SgOde *self, SgDerivFn *f, void *restrict f_ctx, double *restrict eps)
Integrates a system of first order ordinary differential equations one step, normally from x to x+h...
Definition: ode.c:443
int sg_ode(void *f_ctx, void(*f)(void *, double, const double *, double *), size_t neqn, double *restrict y, double *restrict t, double tout, double relerr, double abserr, int flag, double *restrict work, int *restrict iwork)
Simple interface to the ODE solver.
void sg_ode_de(struct SgOde *self, SgDerivFn *f, void *restrict f_ctx, SgVector *restrict y, double *restrict t, double tout, double *restrict relerr, double *restrict abserr, int *restrict iflag, unsigned maxnum)
Integrates a system of neqn first order ordinary differential equations.
Definition: ode.c:855
unsigned kold
Order used for last successful step.
Definition: ode.c:391
void SgVector
A vector is an opaque data type containing a finite number of doubles.
Definition: vector.h:15