1 /* copyright 2016 Apache 2 sddekit authors */
7 #include "tract_lengths.c"
11 typedef struct { sd_out
*out
; } outd
;
13 static sd_stat
out_igc(void *data
, double t
,
14 uint32_t nx
, double * restrict x
,
15 uint32_t nc
, double * restrict c
)
19 return (d
->out
)->apply(d
->out
, t
, nx
, x
, 0, NULL
);
23 uint32_t i
, n
=76, nnz
, *Or
, *Ic
;
24 double *w
=weights
, *d
=tract_lengths
, *sw
, *sd
, *x0
;
28 * sol -> igc -> tee -> tavg -> out file
31 sd_out_file
*of
= sd_out_file_new_from_name("bench_net_exc.dat");
32 sd_out_tavg
*tavg
= sd_out_tavg_new(20, SD_AS(of
, out
));
33 sd_out
*until
= sd_out_new_until(1e3
);
34 sd_out_tee
*tee
= sd_out_tee_new(2);
35 tee
->set_out(tee
, 0, until
);
36 tee
->set_out(tee
, 1, SD_AS(tavg
, out
));
37 outd igcd
= { .out
= SD_AS(tee
, out
) };
38 sd_out
*out
= sd_out_new_cb(&igcd
, &out_igc
);
40 /* connectivity, assuming conduction velocity of 1.0 */
42 sd_util_read_square_matrix("bench/conn76/weights.txt", &n, &w);
43 sd_util_read_square_matrix("bench/conn76/tract_lengths.txt", &n, &d);
45 sd_sparse_from_dense(n
, n
, weights
, tract_lengths
, 0.0, &nnz
, &Or
, &Ic
, &sw
, &sd
);
46 fprintf(stdout
, "[bench_net_exc] nnz=%d\n", nnz
);
49 sd_sys_exc
*exc
= sd_sys_exc_new();
50 exc
->set_a(exc
, 1.01);
51 exc
->set_tau(exc
, 3.0);
52 exc
->set_D(exc
, 0.01);
53 exc
->set_k(exc
, 0.001);
54 sd_net
*net
= sd_net_new_hom(n
, SD_AS(exc
, sys
), 2, 1, 1, nnz
, Or
, Ic
, w
, d
);
56 /* setup scheme & solver */
57 x0
= sd_malloc(sizeof(double)*2*n
);
58 for (i
=0; i
<(2*n
); i
++)
60 sd_sch
*heun
= sd_sch_new_heun(2*n
);
61 sd_hfill
*hf
= sd_hfill_new_val(0.0);
62 sd_sol
*sol
= sd_sol_new_default(SD_AS(net
, sys
), heun
, out
, hf
,
63 42, 2*n
, x0
, n
, nnz
, Ic
, sd
, 0.0, 0.01);
70 double reft
= (double) (toc
- tic
) / CLOCKS_PER_SEC
;
71 sd_log_info("continuation required %.3f s\n", reft
);