1 /* copyright 2016 Apache 2 sddekit authors */
9 struct pars pars_default
= {.a
=1.1, .tau
=3.0, .D
=1e-3, .k
=0.01};
17 static void exc_free(sd_sys
*s
) { sd_free(s
->ptr
); }
20 #define GETSET(field) \
21 static double get_ ## field(sd_sys_exc *s) { \
22 struct data *d = (struct data *) (*s->sys)(s)->ptr; \
23 return d->pars.field; \
25 static void set_ ## field(sd_sys_exc *s, double val) { \
26 struct data *d = (struct data *) (*s->sys)(s)->ptr; \
27 d->pars.field = val; \
37 static sd_stat
apply(sd_sys
*s
, sd_sys_in
*in
, sd_sys_out
*out
)
39 struct pars
*d
= &(((struct data
*) s
->ptr
)->pars
);
40 double *x
= in
->x
, *c
= in
->i
, *f
= out
->f
, *g
= out
->g
, *o
= out
->o
;
41 f
[0] = (x
[0] - x
[0]*x
[0]*x
[0]/3.0 + x
[1]) * d
->tau
;
42 f
[1] = (d
->a
- x
[0] + d
->k
*c
[0]) / d
->tau
;
49 uint32_t ndim(sd_sys
*s
) { (void) s
; return 2; }
50 uint32_t ndc(sd_sys
*s
) { (void) s
; return 1; }
51 uint32_t nobs(sd_sys
*s
) { (void) s
; return 1; }
52 uint32_t nrpar(sd_sys
*s
) { (void) s
; return 4; }
53 uint32_t nipar(sd_sys
*s
) { (void) s
; return 0; }
55 sd_sys sys_default
= {
66 sd_sys
* get_sys(sd_sys_exc
*e
) { return &(((struct data
*) e
->ptr
)->sys_if
); }
68 sd_sys_exc exc_default
= {
81 sd_sys_exc
*sd_sys_exc_new() {
82 struct data
*d
, zero
= {0};
83 if ((d
= sd_malloc (sizeof(struct data
))) == NULL
)
85 sd_err("alloc exc sys failed.");
89 d
->pars
= pars_default
;
90 d
->sys_if
= sys_default
;
91 d
->exc_if
= exc_default
;
92 d
->sys_if
.ptr
= d
->exc_if
.ptr
= d
;