1 /* copyright 2016 Apache 2 sddekit authors */
8 typedef struct out_data
{
14 static sd_stat
test_out_apply(sd_out
*out
, double t
,
15 uint32_t nx
, double * restrict x
,
16 uint32_t nc
, double * restrict c
)
18 out_data
*d
= out
->ptr
;
19 (void) nx
; (void) nc
; (void) c
;
20 fprintf(d
->fd
, "%f\t%f\t%f\n", t
, x
[0], x
[1]);
23 return t
< d
->tf
? SD_CONT
: SD_STOP
;
26 static void test_out_free(sd_out
*out
) { sd_free(out
->ptr
); sd_free(out
); }
28 sd_out test_out_defaults
= {.free
=&test_out_free
,
29 .apply
=&test_out_apply
,
32 sd_out
* test_out_new()
34 sd_out
*out
= sd_malloc(sizeof(sd_out
));;
35 *out
= test_out_defaults
;
36 out
->ptr
= sd_malloc(sizeof(out_data
));
40 static double x0
[2] = {1.010403, 0.030870};
42 static int for_scheme(sd_sch
*sch
, char *name
)
44 sd_sys_exc
*sys
= sd_sys_exc_new();
46 sd_out
*out
= test_out_new();
47 sd_hfill
*hf
= sd_hfill_new_val(0.0);
48 out_data
*outd
= out
->ptr
;
56 sol
= sd_sol_new_default(sys
->sys(sys
), sch
, out
, hf
, 42, 2, x0
,
57 1, 1, vi
, vd
, 0.0, 0.05);
61 sprintf(dat_name
, "test_exc_%s.dat", name
);
62 outd
->fd
= fopen(dat_name
, "w");
63 sys
->set_a(sys
, 1.01);
64 sys
->set_tau(sys
, 3.0);
65 sys
->set_k(sys
, -1e-3);
67 /* deterministic sub-thresh, no crossing */
71 EXPECT_TRUE(!outd
->crossed
);
73 /* stochastic sub-thresh, crossing */
76 sys
->set_D(sys
, 0.05);
78 EXPECT_TRUE(outd
->crossed
);
83 sd_sys
*exc_sys_if
= sys
->sys(sys
);
84 exc_sys_if
->free(exc_sys_if
);
93 sd_sch
*sch
= sd_sch_new_em(2);
94 for_scheme(sch
, "em");
99 sd_sch
*sch
= sd_sch_new_heun(2);
100 for_scheme(sch
, "heun");
105 sd_sch
*sch
= sd_sch_new_emc(2, 1.0);
106 for_scheme(sch
, "emc");