From 7ff906b9cd27a44472b40e78e5d595ea41df1482 Mon Sep 17 00:00:00 2001 From: pants Date: Wed, 31 Aug 2016 14:04:55 -0400 Subject: can generate voronoi networks with regular boundaries --- src/ini_network.c | 83 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 35 deletions(-) (limited to 'src/ini_network.c') diff --git a/src/ini_network.c b/src/ini_network.c index edf1539..263b1b2 100644 --- a/src/ini_network.c +++ b/src/ini_network.c @@ -23,12 +23,14 @@ double *get_edge_coords(unsigned int num_edges, double *vert_coords, unsigned int *edges_to_verts) { double *output = (double *)malloc(2 * num_edges * sizeof(double)); -#pragma omp parallel for + #pragma omp parallel for for (unsigned int i = 0; i < num_edges; i++) { unsigned int v1, v2; double v1x, v1y, v2x, v2y, dx, dy; v1 = edges_to_verts[2 * i]; v2 = edges_to_verts[2 * i + 1]; + output[2 * i] = 0; + output[2 * i + 1] = 0; v1x = vert_coords[2 * v1]; v1y = vert_coords[2 * v1 + 1]; v2x = vert_coords[2 * v2]; @@ -270,7 +272,8 @@ unsigned int *get_voro_dual_edges(unsigned int num_edges, unsigned int *triangles) { unsigned int *dual_edges = (unsigned int *)malloc(2 * num_edges * sizeof(unsigned int)); -#pragma omp parallel for + unsigned int place = 0; + #pragma omp parallel for for (unsigned int i = 0; i < num_edges; i++) { unsigned int v1, v2; v1 = edges[2 * i]; @@ -285,8 +288,9 @@ unsigned int *get_voro_dual_edges(unsigned int num_edges, t21 = triangles[3 * v2 + k]; t22 = triangles[3 * v2 + ((k + 1) % 3)]; if ((t11 == t21 && t12 == t22) || (t11 == t22 && t12 == t21)) { - dual_edges[2 * i] = t11 < t12 ? t11 : t12; - dual_edges[2 * i + 1] = t11 < t12 ? t12 : t11; + dual_edges[2 * place] = t11 < t12 ? t11 : t12; + dual_edges[2 * place + 1] = t11 < t12 ? t12 : t11; + place++; found_match = true; break; } @@ -361,7 +365,7 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, // prune the edges of the lattice and assign boundary vertices based on the // desired boundary conditions unsigned int num_bounds; - unsigned num_verts; + unsigned int num_verts; double *vert_coords; unsigned int *bound_inds; unsigned int *bound_verts; @@ -379,9 +383,9 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, edges = (unsigned int *)malloc(2 * tmp_num_edges * sizeof(unsigned int)); dual_edges = (unsigned int *)malloc(2 * tmp_num_edges * sizeof(unsigned int)); unsigned int num_t, num_b, num_l, num_r; - bool *bound_t, *bound_b, *bound_l, *bound_r; + bool *bound_top, *bound_b, *bound_l, *bound_r; num_t = 0; num_b = 0; num_l = 0; num_r = 0; - bound_t = (bool *)calloc(num_verts, sizeof(bool)); + bound_top = (bool *)calloc(num_verts, sizeof(bool)); bound_b = (bool *)calloc(num_verts, sizeof(bool)); bound_l = (bool *)calloc(num_verts, sizeof(bool)); bound_r = (bool *)calloc(num_verts, sizeof(bool)); @@ -394,15 +398,15 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, dx = v1x - v2x; dy = v1y - v2y; if (fabs(dy) > 0.5) { if (dy > 0) { - if (!bound_t[v1] && !bound_l[v1] && !bound_r[v1]) { - bound_t[v1] = true; num_t++; + if (!bound_top[v1] && !bound_l[v1] && !bound_r[v1]) { + bound_top[v1] = true; num_t++; } if (!bound_b[v2] && !bound_l[v2] && !bound_r[v2]) { bound_b[v2] = true; num_b++; } } else { - if (!bound_t[v2] && !bound_l[v2] && !bound_r[v2]) { - bound_t[v2] = true; num_t++; + if (!bound_top[v2] && !bound_l[v2] && !bound_r[v2]) { + bound_top[v2] = true; num_t++; } if (!bound_b[v1] && !bound_l[v1] && !bound_r[v1]) { bound_b[v1] = true; num_b++; @@ -410,17 +414,17 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, } } else if (fabs(dx) > 0.5) { if (dx > 0) { - if (!bound_r[v1] && !bound_t[v1] && !bound_b[v1]) { + if (!bound_r[v1] && !bound_top[v1] && !bound_b[v1]) { bound_r[v1] = true; num_r++; } - if (!bound_l[v2] && !bound_t[v2] && !bound_b[v2]) { + if (!bound_l[v2] && !bound_top[v2] && !bound_b[v2]) { bound_l[v2] = true; num_l++; } } else { - if (!bound_r[v2] && !bound_t[v2] && !bound_b[v2]) { + if (!bound_r[v2] && !bound_top[v2] && !bound_b[v2]) { bound_r[v2] = true; num_r++; } - if (!bound_l[v1] && !bound_t[v1] && !bound_b[v1]) { + if (!bound_l[v1] && !bound_top[v1] && !bound_b[v1]) { bound_l[v1] = true; num_l++; } } @@ -441,7 +445,7 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, unsigned int pos_t, pos_b, pos_l, pos_r; pos_t = 0; pos_b = 0; pos_l = 0; pos_r = 0; for (unsigned int i = 0; i < num_verts; i++) { - if (bound_t[i]) { + if (bound_top[i]) { bound_verts[pos_t] = i; pos_t++; } else if (bound_b[i]) { bound_verts[num_t + pos_b] = i; pos_b++; @@ -451,9 +455,10 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, bound_verts[num_t + num_b + num_l + pos_r] = i; pos_r++; } } - free(bound_l); free(bound_r); free(bound_t); free(bound_b); + free(bound_l); free(bound_r); free(bound_top); free(bound_b); 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; @@ -471,9 +476,9 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, edges = (unsigned int *)malloc(2 * tmp_num_edges * sizeof(unsigned int)); dual_edges = (unsigned int *)malloc(2 * tmp_num_edges * sizeof(unsigned int)); unsigned int num_t, num_b; - bool *bound_t, *bound_b; + bool *bound_top, *bound_b; num_t = 0; num_b = 0; - bound_t = (bool *)calloc(num_verts, sizeof(bool)); + bound_top = (bool *)calloc(num_verts, sizeof(bool)); bound_b = (bool *)calloc(num_verts, sizeof(bool)); for (unsigned int i = 0; i < tmp_num_edges; i++) { unsigned int v1, v2; @@ -483,15 +488,15 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, dy = v1y - v2y; if (fabs(dy) > 0.5) { if (dy > 0) { - if (!bound_t[v1]) { - bound_t[v1] = true; num_t++; + if (!bound_top[v1]) { + bound_top[v1] = true; num_t++; } if (!bound_b[v2]) { bound_b[v2] = true; num_b++; } } else { - if (!bound_t[v2]) { - bound_t[v2] = true; num_t++; + if (!bound_top[v2]) { + bound_top[v2] = true; num_t++; } if (!bound_b[v1]) { bound_b[v1] = true; num_b++; @@ -512,13 +517,13 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, unsigned int pos_t, pos_b; pos_t = 0; pos_b = 0; for (unsigned int i = 0; i < num_verts; i++) { - if (bound_t[i]) { + if (bound_top[i]) { bound_verts[pos_t] = i; pos_t++; } else if (bound_b[i]) { bound_verts[num_t + pos_b] = i; pos_b++; } } - free(bound_t); free(bound_b); + free(bound_top); free(bound_b); free(tmp_edges); free(tmp_dual_edges); network->edges_to_verts_break = edges; @@ -539,7 +544,7 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, edges[2*i+1] = tmp_edges[2*i+1]; } dual_edges = tmp_dual_edges; - bool *bound_t = (bool *)calloc(tmp_num_verts, sizeof(bool)); + bool *bound_top = (bool *)calloc(tmp_num_verts, sizeof(bool)); int *edge_change = (int *)calloc(num_edges, sizeof(int)); unsigned int num_t = 0; for (unsigned int i = 0; i < num_edges; i++) { @@ -552,13 +557,13 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, if (fabs(dy) > 0.5) { if (dy > 0) { edge_change[i] = 1; - if (!bound_t[v1]) { - bound_t[v1] = true; num_t++; + if (!bound_top[v1]) { + bound_top[v1] = true; num_t++; } } else { edge_change[i] = 2; - if (!bound_t[v2]) { - bound_t[v2] = true; num_t++; + if (!bound_top[v2]) { + bound_top[v2] = true; num_t++; } } } @@ -571,7 +576,7 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, for (unsigned int i = 0; i < tmp_num_verts; i++) { vert_coords[2*i] = tmp_vert_coords[2*i]; vert_coords[2*i+1] = tmp_vert_coords[2*i+1]; - if (bound_t[i]) { + if (bound_top[i]) { bound_verts[pos_t] = i; vert_coords[2*(tmp_num_verts + pos_t)] = tmp_vert_coords[2*i]; vert_coords[2*(tmp_num_verts + pos_t)+1] = tmp_vert_coords[2*i+1]; @@ -589,7 +594,7 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, } } free(tmp_vert_coords); - free(bound_t); + free(bound_top); free(edge_change); network->num_verts_break = num_verts; network->num_verts = tmp_num_verts; @@ -599,17 +604,25 @@ fnet *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual, break; } case EMBEDDED_BOUND: { - num_bounds = 4; + num_bounds = 2; bound_inds = (unsigned int *)malloc(5 * sizeof(unsigned int)); bound_verts = (unsigned int *)malloc(2 * L * sizeof(unsigned int)); for (unsigned int i = 0; i < 5; i++) bound_inds[i] = i * L / 2; for (unsigned int i = 0; i < 2 * L; i++) bound_verts[i] = i; - num_edges = tmp_num_edges; + unsigned int num_away = 0; + for (unsigned int i = 0; i < tmp_num_edges; i++) { + if (tmp_dual_edges[2*i] > num || tmp_dual_edges[2*i+1] > num) num_away++; + } + num_edges = (int)tmp_num_edges - (int)num_away; num_verts = tmp_num_verts; edges = tmp_edges; dual_edges = tmp_dual_edges; - num_edges = tmp_num_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->break_dim = num_verts + num_bounds; } } -- cgit v1.2.3-70-g09d2