From 4c4ebb87ead363d6d6e11a8b95b07a0f93af5c88 Mon Sep 17 00:00:00 2001 From: pants Date: Tue, 6 Sep 2016 15:05:27 -0400 Subject: finished implementing embedded systems, refactored a bunch --- src/ini_network.c | 192 +++++++++++++++++++++++++++--------------------------- 1 file changed, 96 insertions(+), 96 deletions(-) (limited to 'src/ini_network.c') diff --git a/src/ini_network.c b/src/ini_network.c index d80f43b..ebfea76 100644 --- a/src/ini_network.c +++ b/src/ini_network.c @@ -98,20 +98,20 @@ unsigned int *get_verts_to_edges(unsigned int num_verts, unsigned int num_edges, return output; } -fnet *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds, +graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds, cholmod_common *c) { - fnet *network = (fnet *)calloc(1, sizeof(fnet)); + graph_t *network = (graph_t *)calloc(1, sizeof(graph_t)); network->boundary = boundary; bool periodic = (boundary == CYLINDER_BOUND) || (boundary == TORUS_BOUND) ? true : false; - network->num_edges = pow(width, 2); + network->ne = pow(width, 2); if (boundary == CYLINDER_BOUND) { assert(width % 2 == 0); assert(!side_bounds); - network->num_verts = (width / 2) * (width + 1); - network->num_verts_break = (width / 2) * (width + 1); - network->num_dual_verts = (width / 2 + 1) * (width / 2) + pow(width / 2, 2); + network->nv = (width / 2) * (width + 1); + network->nv_break = (width / 2) * (width + 1); + network->dnv = (width / 2 + 1) * (width / 2) + pow(width / 2, 2); network->num_bounds = 2; network->bound_inds = (unsigned int *)malloc((network->num_bounds + 1) * sizeof(unsigned int)); @@ -119,11 +119,11 @@ fnet *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds, network->bound_inds[1] = width / 2; network->bound_inds[2] = width; network->bound_verts = (unsigned int *)calloc(width, sizeof(unsigned int)); - network->break_dim = network->num_verts + network->num_bounds; + network->break_dim = network->nv + network->num_bounds; } else if (boundary == FREE_BOUND) { - network->num_verts = 2 * ((width + 1) / 2) * (width / 2 + 1); - network->num_verts_break = 2 * ((width + 1) / 2) * (width / 2 + 1); - network->num_dual_verts = pow(width / 2 + 1, 2) + pow((width + 1) / 2, 2); + network->nv = 2 * ((width + 1) / 2) * (width / 2 + 1); + network->nv_break = 2 * ((width + 1) / 2) * (width / 2 + 1); + network->dnv = pow(width / 2 + 1, 2) + pow((width + 1) / 2, 2); if (side_bounds) network->num_bounds = 4; else @@ -148,44 +148,44 @@ fnet *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds, } } } - network->break_dim = network->num_verts + network->num_bounds; + network->break_dim = network->nv + network->num_bounds; } else if (boundary == TORUS_BOUND) { - network->num_verts = (width / 2) * (width + 1) - (width / 2); - network->num_verts_break = (width / 2) * (width + 1); - network->num_dual_verts = (width / 2 + 1) * (width / 2) + pow(width / 2, 2) - (width / 2); + network->nv = (width / 2) * (width + 1) - (width / 2); + network->nv_break = (width / 2) * (width + 1); + network->dnv = (width / 2 + 1) * (width / 2) + pow(width / 2, 2) - (width / 2); network->num_bounds = 1; network->bound_inds = (unsigned int *)malloc((network->num_bounds + 1) * sizeof(unsigned int)); network->bound_inds[0] = 0; network->bound_inds[1] = width / 2; network->bound_verts = (unsigned int *)calloc(width / 2, sizeof(unsigned int)); - network->break_dim = network->num_verts_break; + network->break_dim = network->nv_break; } if (boundary != TORUS_BOUND) { for (unsigned int i = 0; i < (width + 1) / 2; i++) { network->bound_verts[i] = i; - network->bound_verts[(width + 1) / 2 + i] = network->num_verts - 1 - i; + network->bound_verts[(width + 1) / 2 + i] = network->nv - 1 - i; } } else { for (unsigned int i = 0; i < width / 2; i++) { network->bound_verts[i] = i; } } - network->edges_to_verts_break = - (unsigned int *)calloc(2 * network->num_edges, sizeof(unsigned int)); - network->edges_to_verts = - (unsigned int *)calloc(2 * network->num_edges, sizeof(unsigned int)); - for (unsigned int i = 0; i < network->num_edges; i++) { - network->edges_to_verts_break[2 * i] = edge_to_verts(width, periodic, i, 1); - network->edges_to_verts_break[2 * i + 1] = edge_to_verts(width, periodic, i, 0); - network->edges_to_verts[2 * i] = network->edges_to_verts_break[2 * i] % network->num_verts; - network->edges_to_verts[2 * i + 1] = network->edges_to_verts_break[2 * i + 1] % network->num_verts; + network->ev_break = + (unsigned int *)calloc(2 * network->ne, sizeof(unsigned int)); + network->ev = + (unsigned int *)calloc(2 * network->ne, sizeof(unsigned int)); + for (unsigned int i = 0; i < network->ne; i++) { + network->ev_break[2 * i] = edge_to_verts(width, periodic, i, 1); + network->ev_break[2 * i + 1] = edge_to_verts(width, periodic, i, 0); + network->ev[2 * i] = network->ev_break[2 * i] % network->nv; + network->ev[2 * i + 1] = network->ev_break[2 * i + 1] % network->nv; } - network->verts_to_edges_ind = - (unsigned int *)calloc(network->num_verts + 1, sizeof(unsigned int)); - network->verts_to_edges_ind[0] = 0; + network->vei = + (unsigned int *)calloc(network->nv + 1, sizeof(unsigned int)); + network->vei[0] = 0; unsigned int pos1 = 0; - for (unsigned int i = 0; i < network->num_verts; i++) { + for (unsigned int i = 0; i < network->nv; i++) { bool in_bound = false; for (unsigned int j = 0; j < network->num_bounds; j++) { for (unsigned int k = 0; @@ -201,18 +201,18 @@ fnet *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds, else pos1 += 4; - network->verts_to_edges_ind[i + 1] = pos1; + network->vei[i + 1] = pos1; } - network->verts_to_edges = (unsigned int *)calloc( - network->verts_to_edges_ind[network->num_verts], sizeof(unsigned int)); + network->ve = (unsigned int *)calloc( + network->vei[network->nv], sizeof(unsigned int)); unsigned int *vert_counts = - (unsigned int *)calloc(network->num_verts, sizeof(unsigned int)); - for (unsigned int i = 0; i < network->num_edges; i++) { - unsigned int v0 = network->edges_to_verts[2 * i]; - unsigned int v1 = network->edges_to_verts[2 * i + 1]; - network->verts_to_edges[network->verts_to_edges_ind[v0] + vert_counts[v0]] = + (unsigned int *)calloc(network->nv, sizeof(unsigned int)); + for (unsigned int i = 0; i < network->ne; i++) { + unsigned int v0 = network->ev[2 * i]; + unsigned int v1 = network->ev[2 * i + 1]; + network->ve[network->vei[v0] + vert_counts[v0]] = i; - network->verts_to_edges[network->verts_to_edges_ind[v1] + vert_counts[v1]] = + network->ve[network->vei[v1] + vert_counts[v1]] = i; vert_counts[v0]++; vert_counts[v1]++; @@ -220,8 +220,8 @@ fnet *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds, free(vert_counts); network->vert_coords = - (double *)malloc(2 * network->num_verts * sizeof(double)); - for (unsigned int i = 0; i < network->num_verts; i++) { + (double *)malloc(2 * network->nv * sizeof(double)); + for (unsigned int i = 0; i < network->nv; i++) { if (!periodic) { network->vert_coords[2 * i] = ((double)((2 * i + 1) / (width + 1)))/width; network->vert_coords[2 * i + 1] = ((double)((2 * i + 1) % (width + 1)))/width; @@ -233,36 +233,36 @@ fnet *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds, network->L = width; network->edge_coords = get_edge_coords( - network->num_edges, network->vert_coords, network->edges_to_verts); - - network->dual_edges_to_verts = - (unsigned int *)malloc(2 * network->num_edges * sizeof(unsigned int)); - for (unsigned int i = 0; i < network->num_edges; i++) { - network->dual_edges_to_verts[2 * i] = - dual_edge_to_verts(width, periodic, i, 0) % network->num_dual_verts; - network->dual_edges_to_verts[2 * i + 1] = - dual_edge_to_verts(width, periodic, i, 1) % network->num_dual_verts; + network->ne, network->vert_coords, network->ev); + + network->dev = + (unsigned int *)malloc(2 * network->ne * sizeof(unsigned int)); + for (unsigned int i = 0; i < network->ne; i++) { + network->dev[2 * i] = + dual_edge_to_verts(width, periodic, i, 0) % network->dnv; + network->dev[2 * i + 1] = + dual_edge_to_verts(width, periodic, i, 1) % network->dnv; } network->dual_vert_coords = - (double *)malloc(2 * network->num_dual_verts * sizeof(double)); - for (unsigned int i = 0; i < network->num_dual_verts; i++) { + (double *)malloc(2 * network->dnv * sizeof(double)); + for (unsigned int i = 0; i < network->dnv; i++) { network->dual_vert_coords[2 * i] = 2*dual_vert_to_coord(width, periodic, i, 0); network->dual_vert_coords[2 * i + 1] = 2*dual_vert_to_coord(width, periodic, i, 1); } - network->voltcurmat = gen_voltcurmat(network->num_edges, + network->voltcurmat = gen_voltcurmat(network->ne, network->break_dim, - network->edges_to_verts_break, c); + network->ev_break, c); - network->dual_verts_to_edges_ind = - get_verts_to_edges_ind(network->num_dual_verts, network->num_edges, - network->dual_edges_to_verts); - network->dual_verts_to_edges = get_verts_to_edges( - network->num_dual_verts, network->num_edges, network->dual_edges_to_verts, - network->dual_verts_to_edges_ind); - network->spanning_edges = get_spanning_edges(network->num_edges, network->edges_to_verts_break, network->vert_coords, 0.51, &(network->num_spanning_edges)); + network->dvei = + get_verts_to_edges_ind(network->dnv, network->ne, + network->dev); + network->dve = get_verts_to_edges( + network->dnv, network->ne, network->dev, + network->dvei); + network->spanning_edges = get_spanning_edges(network->ne, network->ev_break, network->vert_coords, 0.51, &(network->num_spanning_edges)); return network; } @@ -304,10 +304,10 @@ unsigned int *get_voro_dual_edges(unsigned int num_edges, return dual_edges; } -fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, +graph_t *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, double *(*genfunc)(unsigned int, bound_t, gsl_rng *, unsigned int *), cholmod_common *c) { - fnet *network = (fnet *)calloc(1, sizeof(fnet)); + graph_t *network = (graph_t *)calloc(1, sizeof(graph_t)); // generate the dual lattice double *lattice; @@ -459,10 +459,10 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, free(tmp_edges); free(tmp_dual_edges); num_bounds = 2; - network->edges_to_verts_break = edges; - network->edges_to_verts = edges; - network->num_verts_break = num_verts; - network->num_verts = num_verts; + network->ev_break = edges; + network->ev = edges; + network->nv_break = num_verts; + network->nv = num_verts; network->break_dim = num_verts + num_bounds; break; } @@ -526,10 +526,10 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, free(bound_top); free(bound_b); free(tmp_edges); free(tmp_dual_edges); - network->edges_to_verts_break = edges; - network->edges_to_verts = edges; - network->num_verts_break = num_verts; - network->num_verts = num_verts; + network->ev_break = edges; + network->ev = edges; + network->nv_break = num_verts; + network->nv = num_verts; network->break_dim = num_verts + num_bounds; break; } @@ -596,10 +596,10 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, free(tmp_vert_coords); free(bound_top); free(edge_change); - network->num_verts_break = num_verts; - network->num_verts = tmp_num_verts; - network->edges_to_verts_break = edges; - network->edges_to_verts = tmp_edges; + network->nv_break = num_verts; + network->nv = tmp_num_verts; + network->ev_break = edges; + network->ev = tmp_edges; network->break_dim = num_verts; break; } @@ -618,10 +618,10 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, edges = tmp_edges; dual_edges = tmp_dual_edges; vert_coords = tmp_vert_coords; - network->num_verts_break = num_verts; - network->num_verts = num_verts; - network->edges_to_verts_break = edges; - network->edges_to_verts = edges; + network->nv_break = num_verts; + network->nv = num_verts; + network->ev_break = edges; + network->ev = edges; network->break_dim = num_verts + 2; } } @@ -630,38 +630,38 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, network->num_bounds = num_bounds; network->bound_inds = bound_inds; network->bound_verts = bound_verts; - network->num_edges = num_edges; - network->dual_edges_to_verts = dual_edges; + network->ne = num_edges; + network->dev = dual_edges; network->vert_coords = vert_coords; - network->verts_to_edges_ind = get_verts_to_edges_ind( - network->num_verts, network->num_edges, network->edges_to_verts); - network->verts_to_edges = - get_verts_to_edges(network->num_verts, network->num_edges, - network->edges_to_verts, network->verts_to_edges_ind); + network->vei = get_verts_to_edges_ind( + network->nv, network->ne, network->ev); + network->ve = + get_verts_to_edges(network->nv, network->ne, + network->ev, network->vei); network->L = 1; network->edge_coords = get_edge_coords( - network->num_edges, network->vert_coords, network->edges_to_verts); + network->ne, network->vert_coords, network->ev); free(tmp_tris); network->dual_vert_coords = lattice; - network->num_dual_verts = num; + network->dnv = num; - network->voltcurmat = gen_voltcurmat(network->num_edges, + network->voltcurmat = gen_voltcurmat(network->ne, network->break_dim, - network->edges_to_verts_break, c); + network->ev_break, c); - network->dual_verts_to_edges_ind = - get_verts_to_edges_ind(network->num_dual_verts, network->num_edges, - network->dual_edges_to_verts); - network->dual_verts_to_edges = get_verts_to_edges( - network->num_dual_verts, network->num_edges, network->dual_edges_to_verts, - network->dual_verts_to_edges_ind); + network->dvei = + get_verts_to_edges_ind(network->dnv, network->ne, + network->dev); + network->dve = get_verts_to_edges( + network->dnv, network->ne, network->dev, + network->dvei); - network->spanning_edges = get_spanning_edges(network->num_edges, network->edges_to_verts_break, network->vert_coords, 0.5, &(network->num_spanning_edges)); + network->spanning_edges = get_spanning_edges(network->ne, network->ev_break, network->vert_coords, 0.5, &(network->num_spanning_edges)); return network; } -- cgit v1.2.3-70-g09d2