1 /* Apache 2.0 INS-AMU 2015 */
8 static void hist_t_fill(void *data
, int n
, double *t
, int *indices
, double *buf
) {
9 /* suppress unused arguments */
10 (void) data
; (void) indices
;
11 /* fill buffer from times */
12 memcpy(buf
, t
, n
*sizeof(double));
19 double dt
, vd
[ND
], x
[ND
];
34 sk_hist_init(h
, ND
, vi
, vd
, 0.0, dt
);
35 EXPECT_EQ(ND
, sk_hist_get_nd(h
));
36 EXPECT_EQ(0.0, sk_hist_get_t(h
));
37 EXPECT_EQ(dt
, sk_hist_get_dt(h
));
38 EXPECT_EQ(2, sk_hist_get_nu(h
));
39 EXPECT_EQ(0,sk_hist_get_lim(h
, 0));
40 EXPECT_EQ(36,sk_hist_get_lim(h
, 1));
41 EXPECT_EQ(8 + 36,sk_hist_get_lim(h
, 2));
42 EXPECT_EQ(36, sk_hist_get_len(h
, 0));
43 EXPECT_EQ(8, sk_hist_get_len(h
, 1));
44 EXPECT_EQ(0, sk_hist_get_pos(h
, 0));
45 EXPECT_EQ(0, sk_hist_get_pos(h
, 1));
46 EXPECT_EQ(0, sk_hist_get_uvi(h
, 0));
47 EXPECT_EQ(1, sk_hist_get_uvi(h
, 1));
48 EXPECT_EQ(1, sk_hist_get_maxvi(h
));
49 EXPECT_EQ(0, sk_hist_get_vi2i(h
, 0));
50 EXPECT_EQ(1, sk_hist_get_vi2i(h
, 1));
51 EXPECT_EQ(vd
[0], sk_hist_get_maxd(h
, 1));
52 EXPECT_EQ(vd
[2], sk_hist_get_maxd(h
, 0));
53 EXPECT_EQ(1, sk_hist_get_vi(h
, 0));
54 EXPECT_EQ(1, sk_hist_get_vi(h
, 1));
55 EXPECT_EQ(0, sk_hist_get_vi(h
, 2));
56 EXPECT_EQ(0, sk_hist_get_vi(h
, 3));
57 EXPECT_EQ(vd
[0], sk_hist_get_vd(h
, 0));
58 EXPECT_EQ(vd
[1], sk_hist_get_vd(h
, 1));
59 EXPECT_EQ(vd
[2], sk_hist_get_vd(h
, 2));
60 EXPECT_EQ(vd
[3], sk_hist_get_vd(h
, 3));
61 EXPECT_TRUE(!sk_hist_buf_is_null(h
));
63 sk_hist_fill(h
, &hist_t_fill
, NULL
);
65 EXPECT_EQ(-i
*dt
, sk_hist_get_buf_lin(h
, i
));
66 EXPECT_EQ(dt
, sk_hist_get_buf_lin(h
, 35));
68 EXPECT_EQ(-i
*dt
, sk_hist_get_buf_lin(h
, 36+i
));
69 EXPECT_EQ(dt
, sk_hist_get_buf_lin(h
, 36+7));
71 sk_hist_get(h
, dt
/3, x
);
72 ASSERT_NEAR(x
[0], -vd
[0]+dt
/3, 1e-15);
73 ASSERT_NEAR(x
[1], -vd
[1]+dt
/3, 1e-15);
74 ASSERT_NEAR(x
[2], -vd
[2]+dt
/3, 1e-15);
75 ASSERT_NEAR(x
[3], -vd
[3]+dt
/3, 1e-15);
79 sk_hist_set(h
, dt
/2.0, x
);
80 ASSERT_NEAR( sk_hist_get_buf_lin(h
, 35), 3.0, 1e-15);
81 ASSERT_NEAR( sk_hist_get_buf_lin(h
, 36 + 7), 2.0, 1e-15);
86 /* port of TVB's history test */
87 static void hist_fill_ones(void *data
, int n
, double *t
, int *indices
, double *buf
) {
89 /* suppress unused arguments */
90 (void) data
; (void) indices
; (void) t
;
91 /* fill buffer from times */
96 static SK_DEFSYS(hist_exact_sys
) {
97 (void) data
; (void) nx
; (void) nc
; (void) t
; (void) Jf
; (void) Jg
;
98 (void) Jce
; (void) hist
; (void) i
;
105 /* The values are obtained by stepping through time according to the
108 * w = [ 0 1 0 0 d = [ . 1 . .
111 * 0 0 0 0 ] . . . . ]
130 static double xexpect
[12][4] = {
145 static SK_DEFOUT(hist_exact_out
) {
147 /* unused */ (void) nc
; (void) c
; (void) data
;
150 EXPECT_EQ(x
[i
], xexpect
[(int) t
][i
]);
155 int i
, n
=4, nnz
, *Or
, *Ic
;
156 double w
[16], d
[16], *nzw
, *nzd
, x0
[4];
159 sk_sch_id_data
*schd
;
161 schd
= sk_sch_id_alloc();
162 sol
= sk_solv_alloc();
167 for (i
=0; i
<16; i
++) {
171 for (i
=0; i
<n
-1; i
++)
174 /* 3 nnz, so hist expects c size 3, but net setups for c size 4 */
177 sk_sparse_from_dense(n
, n
, w
, d
, 0.0, &nnz
, &Or
, &Ic
, &nzw
, &nzd
);
190 EXPECT_EQ(11,nzd
[2]);
192 net
= sk_net_alloc();
193 sk_net_init1(net
, n
, hist_exact_sys
, NULL
, 1, 1, nnz
, Or
, Ic
, nzw
, nzd
);
196 EXPECT_EQ(4,sk_net_get_ne(net
));
198 /* setup scheme & driver */
199 sk_sch_id_init(schd
, n
);
200 sk_solv_init(sol
, sk_net_sys
, net
, sk_sch_id
, schd
,
201 hist_exact_out
, NULL
, hist_fill_ones
, NULL
, 42,
202 n
, x0
, nnz
, Ic
, nzd
, 0.0, 1.0);
204 EXPECT_EQ(3, sk_solv_get_nc(sol
));
205 EXPECT_EQ(3, sk_hist_get_nu(sk_solv_get_hist(sol
)));
210 /* tests performed in out function.. */
214 sk_sch_id_free(schd
);