src/ include/ test/ fig/ objs/
[sddekit.git] / test / test_exc.c
blob94e0f7d68443b7d37732f5fb55550496b4a6ec8a
1 /* Apache 2.0 INS-AMU 2015 */
3 #include <stdio.h>
5 #include "sk_test.h"
6 #include "sk_solv.h"
7 #include "sk_sys.h"
8 #include "sk_scheme.h"
10 typedef struct {
11 int crossed;
12 double tf;
13 FILE *fd;
14 } out_data;
16 static SK_DEFOUT(test_out)
18 out_data *d = data;
19 (void) nx; /* unused */
20 fprintf(d->fd, "%f\t%f\t%f\n", t, x[0], x[1]);
21 if (x[0] < 0.0)
22 d->crossed = 1;
23 return t < d->tf;
26 static void test_hist_filler()
30 static double x0[2] = {1.010403, 0.030870};
32 static int for_scheme(sk_sch sch, void *schd, char *name)
34 sk_sys_exc_dat sysd;
35 out_data outd;
36 sk_solv solv;
37 char dat_name[100];
39 /* init solver */
40 sk_solv_init(&solv, &sk_sys_exc, &sysd,
41 sch, schd, &test_out, &outd,
42 &test_hist_filler, NULL,
43 42, 2, x0, 0, NULL, NULL,
44 0.0, 0.05);
46 /* fill in data */
47 outd.tf = 20.0;
48 sprintf(dat_name, "test_exc_%s.dat", name);
49 outd.fd = fopen(dat_name, "w");
50 sysd.a = 1.01;
51 sysd.tau = 3.0;
53 /* deterministic sub-thresh, no crossing */
54 outd.crossed = 0;
55 sysd.D = 0.0;
56 sk_solv_cont(&solv);
57 sk_test_true(!outd.crossed);
59 /* stochastic sub-thresh, crossing */
60 outd.crossed = 0;
61 outd.tf = 40.0;
62 sysd.D = 0.05;
63 sk_solv_cont(&solv);
64 sk_test_true(outd.crossed);
66 /* clean up */
67 fclose(outd.fd);
68 sk_solv_free(&solv);
70 return 0;
74 int test_exc()
76 sk_sch_em_data emd;
77 sk_sch_heun_data heund;
78 sk_sch_emcolor_data emcolord;
80 sk_sch_em_init(&emd, 2);
81 for_scheme(sk_sch_em, &emd, "em");
82 sk_sch_em_free(&emd);
84 sk_sch_heun_init(&heund, 2);
85 for_scheme(sk_sch_heun, &heund, "heun");
86 sk_sch_heun_free(&heund);
88 sk_sch_emcolor_init(&emcolord, 2, 1.0);
89 for_scheme(sk_sch_emcolor, &emcolord, "emcolor");
90 sk_sch_emcolor_free(&emcolord);
92 return 0;