summaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c74
1 files changed, 41 insertions, 33 deletions
diff --git a/src/net.c b/src/net.c
index b61c9ea..a1047e2 100644
--- a/src/net.c
+++ b/src/net.c
@@ -50,35 +50,53 @@ net_t *net_create(const graph_t *g, double inf, double beta, double notch_len, b
net->graph = g;
net->num_broken = 0;
+
net->fuses = (bool *)calloc(g->ne, sizeof(bool));
assert(net->fuses != NULL);
+
net->thres = get_thres(g->ne, beta);
net->inf = inf;
+ net->dim = g->nv;
+
+ if (g->boundary == TORUS_BOUND) {
+ net->nep = g->ne;
+ net->evp = (uint_t *)malloc(2 * g->ne * sizeof(uint_t));
+ memcpy(net->evp, g->ev, 2 * g->ne * sizeof(uint_t));
+ } else {
+ if (vb) {
+ net->dim -= g->bi[g->nb];
+ net->evp = (uint_t *)malloc(2 * g->ne * sizeof(uint_t));
+ net->nep = 0;
+ for (uint_t i = 0; i < g->ne; i++) {
+ if (!(g->bq[g->ev[2*i]] || g->bq[g->ev[2*i+1]])) {
+ net->evp[2*net->nep] = g->bni[g->ev[2*i]];
+ net->evp[2*net->nep + 1] = g->bni[g->ev[2*i + 1]];
+ net->nep++;
+ }
+ }
+ } else {
+ net->dim += 2;
+ net->evp = (uint_t *)malloc(2 * (g->ne + g->bi[2]) * sizeof(uint_t));
+ memcpy(net->evp, g->ev, 2 * g->ne * sizeof(uint_t));
+ net->nep = g->ne + g->bi[2];
+
+ for (uint_t i = 0; i < 2; i++) {
+ for (uint_t j = 0; j < g->bi[i+1] - g->bi[i]; j++){
+ net->evp[2 * (g->ne + g->bi[i] + j)] = g->b[g->bi[i] + j];
+ net->evp[2 * (g->ne + g->bi[i] + j) + 1] = g->nv + i;
+ }
+ }
+ }
+ }
+
net->voltage_bound = vb;
net->boundary_cond = bound_set(g, vb, notch_len, c);
- net->adjacency = gen_adjacency(net, false, false, 0, c);
- net->dual_adjacency = gen_adjacency(net, true, false, 0, c);
-
- net->marks = (uint_t *)malloc((net->graph->break_dim) * sizeof(uint_t));
- assert(net->marks != NULL);
-
- net->dual_marks = (uint_t *)malloc((net->graph->dnv) * sizeof(uint_t));
- assert(net->dual_marks != NULL);
-
- for (uint_t i = 0; i < (net->graph->break_dim); i++) {
- net->marks[i] = 1;
- }
- for (uint_t i = 0; i < (net->graph->dnv); i++) {
- net->dual_marks[i] = i+1;
- }
- net->num_components = 1;
-
net_notch(net, notch_len, c);
{
- cholmod_sparse *laplacian = gen_laplacian(net, c, true);
+ cholmod_sparse *laplacian = gen_laplacian(net, c);
net->factor = CHOL_F(analyze)(laplacian, c);
CHOL_F(factorize)(laplacian, net->factor, c);
CHOL_F(free_sparse)(&laplacian, c);
@@ -102,18 +120,11 @@ net_t *net_copy(const net_t *net, cholmod_common *c) {
assert(net_copy->thres != NULL);
memcpy(net_copy->thres, net->thres, thres_size);
- size_t marks_size = (net->graph->break_dim) * sizeof(uint_t);
- net_copy->marks = (uint_t *)malloc(marks_size);
- assert(net_copy->marks != NULL);
- memcpy(net_copy->marks, net->marks, marks_size);
-
- size_t dual_marks_size = (net->graph->dnv) * sizeof(uint_t);
- net_copy->dual_marks = (uint_t *)malloc(dual_marks_size);
- assert(net_copy->dual_marks != NULL);
- memcpy(net_copy->dual_marks, net->dual_marks, dual_marks_size);
+ size_t evp_size = 2 * net->nep * sizeof(uint_t);
+ net_copy->evp = (uint_t *)malloc(thres_size);
+ assert(net_copy->evp != NULL);
+ memcpy(net_copy->evp, net->evp, evp_size);
- net_copy->adjacency = CHOL_F(copy_sparse)(net->adjacency, c);
- net_copy->dual_adjacency = CHOL_F(copy_sparse)(net->dual_adjacency, c);
net_copy->boundary_cond = CHOL_F(copy_dense)(net->boundary_cond, c);
net_copy->factor = CHOL_F(copy_factor)(net->factor, c);
@@ -124,10 +135,7 @@ void net_free(net_t *net, cholmod_common *c) {
free(net->fuses);
free(net->thres);
CHOL_F(free_dense)(&(net->boundary_cond), c);
- CHOL_F(free_sparse)(&(net->adjacency), c);
- CHOL_F(free_sparse)(&(net->dual_adjacency), c);
CHOL_F(free_factor)(&(net->factor), c);
- free(net->marks);
- free(net->dual_marks);
+ free(net->evp);
free(net);
}