summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpants <jaron@kent-dobias.com>2016-09-07 20:14:05 -0400
committerpants <jaron@kent-dobias.com>2016-09-07 20:14:05 -0400
commit3c5671310bdada56f5e087b951ac2e4d6086dfbf (patch)
tree361c4d0c60cddaf0c286f6d8d4f3e776b990d48a /src
parent6590154ae3e4ee97e5e1a2792f9f2ebf716ed251 (diff)
downloadfuse_networks-3c5671310bdada56f5e087b951ac2e4d6086dfbf.tar.gz
fuse_networks-3c5671310bdada56f5e087b951ac2e4d6086dfbf.tar.bz2
fuse_networks-3c5671310bdada56f5e087b951ac2e4d6086dfbf.zip
got square network embedded working, torus still broken
Diffstat (limited to 'src')
-rw-r--r--src/bound_set.c14
-rw-r--r--src/break_edge.c2
-rw-r--r--src/get_current.c9
-rw-r--r--src/graph_create.c269
-rw-r--r--src/net_notch.c3
5 files changed, 153 insertions, 144 deletions
diff --git a/src/bound_set.c b/src/bound_set.c
index 9c67f82..f513aa1 100644
--- a/src/bound_set.c
+++ b/src/bound_set.c
@@ -16,7 +16,9 @@ double u_y(double x, double y) {
return sqrt(r) * sin(th / 2);
}
-void bound_set_embedded(double *bound, uint_t L, double notch_len) {
+void bound_set_embedded(double *bound, const graph_t *g, double notch_len) {
+ uint_t L = g->L;
+
for (uint_t i = 0; i < L / 2; i++) {
double x1, y1, x2, y2, x3, y3, x4, y4;
x1 = (2. * i + 1.) / L - notch_len; y1 = 0.5 - 1.;
@@ -24,10 +26,10 @@ void bound_set_embedded(double *bound, uint_t L, double notch_len) {
y3 = (2. * i + 1.) / L - 0.5; x3 = 0.5 - 1.;
y4 = (2. * i + 1.) / L - 0.5; x4 = 0.5 - 0.;
- bound[i] = u_y(x1, y1);
- bound[L / 2 + i] = u_y(x2, y2);
- bound[L + i] = u_y(x3, y3);
- bound[3 * L / 2 + i] = u_y(x4, y4);
+ bound[g->bound_verts[g->bound_inds[0] + i]] = u_y(x1, y1);
+ bound[g->bound_verts[g->bound_inds[1] + i]] = u_y(x2, y2);
+ bound[g->bound_verts[g->bound_inds[2] + i]] = u_y(x3, y3);
+ bound[g->bound_verts[g->bound_inds[3] + i]] = u_y(x4, y4);
}
}
@@ -44,7 +46,7 @@ cholmod_dense *bound_set(const graph_t *g, bool vb, double notch_len, cholmod_co
bound[g->bound_verts[0]] = 1;
break;
case EMBEDDED_BOUND:
- bound_set_embedded(bound, g->L, notch_len);
+ bound_set_embedded(bound, g, notch_len);
break;
default:
if (vb) {
diff --git a/src/break_edge.c b/src/break_edge.c
index 4e1559b..daed1c5 100644
--- a/src/break_edge.c
+++ b/src/break_edge.c
@@ -41,7 +41,7 @@ bool break_edge(net_t *instance, unsigned int edge, cholmod_common *c) {
unsigned int dw2 = instance->graph->dev[2 * edge + 1];
if (instance->dual_marks[dw1] == instance->dual_marks[dw2]) {
- int **cycles = (int **)malloc(2*instance->graph->ne * sizeof(int *));
+ int **cycles = (int **)malloc(4*instance->graph->ne * sizeof(int *));
unsigned int num_cycles = find_cycles(instance->graph->ne, instance->fuses, instance->graph->dev, instance->graph->dvei, instance->graph->dve, cycles);
for (unsigned int i = 0; i < num_cycles; i++) {
diff --git a/src/get_current.c b/src/get_current.c
index bc786f9..8493370 100644
--- a/src/get_current.c
+++ b/src/get_current.c
@@ -8,9 +8,12 @@ double *get_voltage(const net_t *instance, cholmod_common *c) {
cholmod_dense *x = CHOL_F(solve)(CHOLMOD_A, factor, b, c);
if (((double *)x->x)[0] != ((double *)x->x)[0]) {
- printf("ERROR: GET_VOLTAGE FAILED\n\n");
- CHOL_F(free_dense)(&x, c);
- return NULL;
+ for (uint_t i = 0; i < instance->graph->ne; i++) {
+ printf("%d ", instance->fuses[i]);
+ }
+ printf("\n");
+ printf("GET_VOLTAGE: value is NaN\n");
+ exit(EXIT_FAILURE);
}
double *field = (double *)x->x;
diff --git a/src/graph_create.c b/src/graph_create.c
index 2746310..5573064 100644
--- a/src/graph_create.c
+++ b/src/graph_create.c
@@ -1,17 +1,17 @@
#include "fracture.h"
-unsigned int *get_spanning_edges(unsigned int num_edges, unsigned int *edges_to_verts, double *vert_coords, double cut, unsigned int *n) {
- unsigned int *spanning_edges = (unsigned int *)malloc(num_edges * sizeof(unsigned int));
+uint_t *get_spanning_edges(uint_t num_edges, uint_t *edges_to_verts, double *vert_coords, double cut, uint_t *n) {
+ uint_t *spanning_edges = (uint_t *)malloc(num_edges * sizeof(uint_t));
(*n) = 0;
- for (unsigned int i = 0; i < num_edges; i++) {
- unsigned int v1, v2;
+ for (uint_t i = 0; i < num_edges; i++) {
+ uint_t v1, v2;
v1 = edges_to_verts[2 * i];
v2 = edges_to_verts[2 * i + 1];
double v1y, v2y;
v1y = vert_coords[2 * v1 + 1];
v2y = vert_coords[2 * v2 + 1];
- if ((fabs(v1y - v2y) < 0.25) && ((v1y < cut && v2y > cut) || (v1y > cut && v2y < cut))) {
+ if ((fabs(v1y - v2y) < 0.5) && ((v1y < cut && v2y > cut) || (v1y > cut && v2y < cut))) {
spanning_edges[*n] = i;
(*n)++;
}
@@ -19,13 +19,13 @@ unsigned int *get_spanning_edges(unsigned int num_edges, unsigned int *edges_to_
return spanning_edges;
}
-double *get_edge_coords(unsigned int num_edges, double *vert_coords,
- unsigned int *edges_to_verts) {
+double *get_edge_coords(uint_t num_edges, double *vert_coords,
+ uint_t *edges_to_verts) {
double *output = (double *)malloc(2 * num_edges * sizeof(double));
#pragma omp parallel for
- for (unsigned int i = 0; i < num_edges; i++) {
- unsigned int v1, v2;
+ for (uint_t i = 0; i < num_edges; i++) {
+ uint_t v1, v2;
double v1x, v1y, v2x, v2y, dx, dy;
v1 = edges_to_verts[2 * i];
v2 = edges_to_verts[2 * i + 1];
@@ -58,33 +58,33 @@ double *get_edge_coords(unsigned int num_edges, double *vert_coords,
return output;
}
-unsigned int *get_verts_to_edges_ind(unsigned int num_verts,
- unsigned int num_edges,
- const unsigned int *edges_to_verts) {
- unsigned int *output =
- (unsigned int *)calloc(num_verts + 1, sizeof(unsigned int));
+uint_t *get_verts_to_edges_ind(uint_t num_verts,
+ uint_t num_edges,
+ const uint_t *edges_to_verts) {
+ uint_t *output =
+ (uint_t *)calloc(num_verts + 1, sizeof(uint_t));
assert(output != NULL);
- for (unsigned int i = 0; i < 2 * num_edges; i++) {
+ for (uint_t i = 0; i < 2 * num_edges; i++) {
if (edges_to_verts[i] < num_verts) {
output[edges_to_verts[i] + 1]++;
}
}
- for (unsigned int i = 0; i < num_verts; i++) {
+ for (uint_t i = 0; i < num_verts; i++) {
output[i + 1] += output[i];
}
return output;
}
-unsigned int *get_verts_to_edges(unsigned int num_verts, unsigned int num_edges,
- const unsigned int *edges_to_verts,
- const unsigned int *verts_to_edges_ind) {
- unsigned int *output = (unsigned int *)calloc(verts_to_edges_ind[num_verts],
- sizeof(unsigned int));
- unsigned int *counts =
- (unsigned int *)calloc(num_verts, sizeof(unsigned int));
+uint_t *get_verts_to_edges(uint_t num_verts, uint_t num_edges,
+ const uint_t *edges_to_verts,
+ const uint_t *verts_to_edges_ind) {
+ uint_t *output = (uint_t *)calloc(verts_to_edges_ind[num_verts],
+ sizeof(uint_t));
+ uint_t *counts =
+ (uint_t *)calloc(num_verts, sizeof(uint_t));
for (int i = 0; i < 2 * num_edges; i++) {
if (edges_to_verts[i] < num_verts) {
output[verts_to_edges_ind[edges_to_verts[i]] +
@@ -98,7 +98,7 @@ unsigned int *get_verts_to_edges(unsigned int num_verts, unsigned int num_edges,
return output;
}
-graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds,
+graph_t *ini_square_network(uint_t width, bound_t boundary, bool side_bounds,
cholmod_common *c) {
graph_t *network = (graph_t *)calloc(1, sizeof(graph_t));
@@ -113,14 +113,14 @@ graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_boun
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));
+ network->bound_inds = (uint_t *)malloc((network->num_bounds + 1) *
+ sizeof(uint_t));
network->bound_inds[0] = 0;
network->bound_inds[1] = width / 2;
network->bound_inds[2] = width;
- network->bound_verts = (unsigned int *)calloc(width, sizeof(unsigned int));
+ network->bound_verts = (uint_t *)calloc(width, sizeof(uint_t));
network->break_dim = network->nv + network->num_bounds;
- } else if (boundary == FREE_BOUND) {
+ } else if (boundary == FREE_BOUND || boundary == EMBEDDED_BOUND) {
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);
@@ -128,15 +128,15 @@ graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_boun
network->num_bounds = 4;
else
network->num_bounds = 2;
- network->bound_inds = (unsigned int *)malloc((network->num_bounds + 1) *
- sizeof(unsigned int));
- for (unsigned int i = 0; i < network->num_bounds + 1; i++) {
+ network->bound_inds = (uint_t *)malloc((network->num_bounds + 1) *
+ sizeof(uint_t));
+ for (uint_t i = 0; i < network->num_bounds + 1; i++) {
network->bound_inds[i] = i * ((width + 1) / 2);
}
- network->bound_verts = (unsigned int *)calloc(
- network->num_bounds * ((width + 1) / 2), sizeof(unsigned int));
+ network->bound_verts = (uint_t *)malloc(
+ network->num_bounds * ((width + 1) / 2) * sizeof(uint_t));
if (side_bounds) {
- for (unsigned int i = 0; i < (width + 1) / 2; i++) {
+ for (uint_t i = 0; i < (width + 1) / 2; i++) {
network->bound_verts[2 * ((width + 1) / 2) + i] =
(width + 1) / 2 + i * (width + 1);
if (width % 2) {
@@ -148,47 +148,47 @@ graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_boun
}
}
}
- network->break_dim = network->nv + network->num_bounds;
+ network->break_dim = network->nv + 2;
} else if (boundary == TORUS_BOUND) {
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 = (uint_t *)malloc((network->num_bounds + 1) *
+ sizeof(uint_t));
network->bound_inds[0] = 0;
network->bound_inds[1] = width / 2;
- network->bound_verts = (unsigned int *)calloc(width / 2, sizeof(unsigned int));
+ network->bound_verts = (uint_t *)calloc(width / 2, sizeof(uint_t));
network->break_dim = network->nv_break;
}
if (boundary != TORUS_BOUND) {
- for (unsigned int i = 0; i < (width + 1) / 2; i++) {
+ for (uint_t i = 0; i < (width + 1) / 2; i++) {
network->bound_verts[i] = i;
- network->bound_verts[(width + 1) / 2 + i] = network->nv - 1 - i;
+ network->bound_verts[(width + 1) / 2 + i] = network->nv - (width + 1) / 2 + i;
}
} else {
- for (unsigned int i = 0; i < width / 2; i++) {
+ for (uint_t i = 0; i < width / 2; i++) {
network->bound_verts[i] = i;
}
}
network->ev_break =
- (unsigned int *)calloc(2 * network->ne, sizeof(unsigned int));
+ (uint_t *)calloc(2 * network->ne, sizeof(uint_t));
network->ev =
- (unsigned int *)calloc(2 * network->ne, sizeof(unsigned int));
- for (unsigned int i = 0; i < network->ne; i++) {
+ (uint_t *)calloc(2 * network->ne, sizeof(uint_t));
+ for (uint_t 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->vei =
- (unsigned int *)calloc(network->nv + 1, sizeof(unsigned int));
+ (uint_t *)calloc(network->nv + 1, sizeof(uint_t));
network->vei[0] = 0;
- unsigned int pos1 = 0;
- for (unsigned int i = 0; i < network->nv; i++) {
+ uint_t pos1 = 0;
+ for (uint_t 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;
+ for (uint_t j = 0; j < network->num_bounds; j++) {
+ for (uint_t k = 0;
k < network->bound_inds[j + 1] - network->bound_inds[j]; k++) {
if (i == network->bound_verts[network->bound_inds[j] + k]) {
in_bound = true;
@@ -203,13 +203,13 @@ graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_boun
network->vei[i + 1] = pos1;
}
- network->ve = (unsigned int *)calloc(
- network->vei[network->nv], sizeof(unsigned int));
- unsigned int *vert_counts =
- (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 = (uint_t *)calloc(
+ network->vei[network->nv], sizeof(uint_t));
+ uint_t *vert_counts =
+ (uint_t *)calloc(network->nv, sizeof(uint_t));
+ for (uint_t i = 0; i < network->ne; i++) {
+ uint_t v0 = network->ev[2 * i];
+ uint_t v1 = network->ev[2 * i + 1];
network->ve[network->vei[v0] + vert_counts[v0]] =
i;
network->ve[network->vei[v1] + vert_counts[v1]] =
@@ -221,13 +221,13 @@ graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_boun
network->vx =
(double *)malloc(2 * network->nv * sizeof(double));
- for (unsigned int i = 0; i < network->nv; i++) {
+ for (uint_t i = 0; i < network->nv; i++) {
if (!periodic) {
- network->vx[2 * i] = ((double)((2 * i + 1) / (width + 1)))/width;
- network->vx[2 * i + 1] = ((double)((2 * i + 1) % (width + 1)))/width;
+ network->vx[2 * i + 1] = ((double)((2 * i + 1) / (width + 1)))/width;
+ network->vx[2 * i] = ((double)((2 * i + 1) % (width + 1)))/width;
} else {
- network->vx[2 * i] = ((double)((2 * i + 1) / (width)))/width;
- network->vx[2 * i + 1] = ((double)((((2 * i + 1) / (width)+1) % 2) + ((2 * i) % (width))))/width;
+ network->vx[2 * i + 1] = ((double)((2 * i + 1) / (width)))/width;
+ network->vx[2 * i] = ((double)((((2 * i + 1) / (width)+1) % 2) + ((2 * i) % (width))))/width;
}
}
@@ -236,8 +236,8 @@ graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_boun
network->ne, network->vx, network->ev);
network->dev =
- (unsigned int *)malloc(2 * network->ne * sizeof(unsigned int));
- for (unsigned int i = 0; i < network->ne; i++) {
+ (uint_t *)malloc(2 * network->ne * sizeof(uint_t));
+ for (uint_t 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] =
@@ -245,7 +245,7 @@ graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_boun
}
network->dvx =
(double *)malloc(2 * network->dnv * sizeof(double));
- for (unsigned int i = 0; i < network->dnv; i++) {
+ for (uint_t i = 0; i < network->dnv; i++) {
network->dvx[2 * i] =
2*dual_vert_to_coord(width, periodic, i, 0);
network->dvx[2 * i + 1] =
@@ -262,27 +262,27 @@ graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_boun
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->vx, 0.51, &(network->num_spanning_edges));
+ network->spanning_edges = get_spanning_edges(network->ne, network->ev, network->vx, 0.51, &(network->num_spanning_edges));
return network;
}
-unsigned int *get_voro_dual_edges(unsigned int num_edges,
- unsigned int num_verts, unsigned int *edges,
- unsigned int *triangles) {
- unsigned int *dual_edges =
- (unsigned int *)malloc(2 * num_edges * sizeof(unsigned int));
- unsigned int place = 0;
+uint_t *get_voro_dual_edges(uint_t num_edges,
+ uint_t num_verts, uint_t *edges,
+ uint_t *triangles) {
+ uint_t *dual_edges =
+ (uint_t *)malloc(2 * num_edges * sizeof(uint_t));
+ uint_t place = 0;
#pragma omp parallel for
- for (unsigned int i = 0; i < num_edges; i++) {
- unsigned int v1, v2;
+ for (uint_t i = 0; i < num_edges; i++) {
+ uint_t v1, v2;
v1 = edges[2 * i];
v2 = edges[2 * i + 1];
if (v1 < num_verts && v2 < num_verts) {
bool found_match = false;
- for (unsigned int j = 0; j < 3; j++) {
- for (unsigned int k = 0; k < 3; k++) {
- unsigned int t11, t12, t21, t22;
+ for (uint_t j = 0; j < 3; j++) {
+ for (uint_t k = 0; k < 3; k++) {
+ uint_t t11, t12, t21, t22;
t11 = triangles[3 * v1 + j];
t12 = triangles[3 * v1 + ((j + 1) % 3)];
t21 = triangles[3 * v2 + k];
@@ -304,14 +304,14 @@ unsigned int *get_voro_dual_edges(unsigned int num_edges,
return dual_edges;
}
-graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
- double *(*genfunc)(unsigned int, bound_t, gsl_rng *, unsigned int *),
+graph_t *ini_voro_graph(uint_t L, bound_t boundary, bool use_dual,
+ double *(*genfunc)(uint_t, bound_t, gsl_rng *, uint_t *),
cholmod_common *c) {
graph_t *g = (graph_t *)calloc(1, sizeof(graph_t));
// generate the dual lattice
double *lattice;
- unsigned int num;
+ uint_t num;
{
gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937);
FILE *rf = fopen("/dev/urandom", "r");
@@ -329,11 +329,11 @@ graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
else run_periodic = true;
intptr_t *vout = run_voronoi(num, lattice, run_periodic, 0, 1, 0, 1);
- unsigned int tmp_num_verts = ((unsigned int *)vout[0])[0];
- unsigned int tmp_num_edges = ((unsigned int *)vout[0])[1];
+ uint_t tmp_num_verts = ((uint_t *)vout[0])[0];
+ uint_t tmp_num_edges = ((uint_t *)vout[0])[1];
double *tmp_vert_coords = (double *)vout[2];
- unsigned int *tmp_edges = (unsigned int *)vout[3];
- unsigned int *tmp_tris = (unsigned int *)vout[5];
+ uint_t *tmp_edges = (uint_t *)vout[3];
+ uint_t *tmp_tris = (uint_t *)vout[5];
free((void *)vout[0]);
free((void *)vout[1]);
@@ -341,16 +341,16 @@ graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
free(vout);
// get dual edges of the fully periodic graph
- unsigned int *tmp_dual_edges =
+ uint_t *tmp_dual_edges =
get_voro_dual_edges(tmp_num_edges, tmp_num_verts, tmp_edges, tmp_tris);
// when use_dual is specificed, the edge and vertex sets are swapped with the
// dual edge and dual vertex sets. once formally relabelled, everything
// works the same way
if (use_dual) {
- unsigned int *tmp_tmp_dual_edges = tmp_edges;
+ uint_t *tmp_tmp_dual_edges = tmp_edges;
double *tmp_lattice = tmp_vert_coords;
- unsigned int tmp_num = tmp_num_verts;
+ uint_t tmp_num = tmp_num_verts;
tmp_edges = tmp_dual_edges;
tmp_dual_edges = tmp_tmp_dual_edges;
@@ -364,33 +364,33 @@ graph_t *ini_voro_graph(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 int num_verts;
+ uint_t num_bounds;
+ uint_t num_verts;
double *vert_coords;
- unsigned int *bound_inds;
- unsigned int *bound_verts;
- unsigned int num_edges;
- unsigned int *edges;
- unsigned int *dual_edges;
+ uint_t *bound_inds;
+ uint_t *bound_verts;
+ uint_t num_edges;
+ uint_t *edges;
+ uint_t *dual_edges;
switch (boundary) {
case FREE_BOUND: {
num_bounds = 4;
- bound_inds = (unsigned int *)malloc((1 + num_bounds) * sizeof(unsigned int));
+ bound_inds = (uint_t *)malloc((1 + num_bounds) * sizeof(uint_t));
bound_inds[0] = 0;
vert_coords = tmp_vert_coords;
num_verts = tmp_num_verts;
num_edges = 0;
- 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;
+ edges = (uint_t *)malloc(2 * tmp_num_edges * sizeof(uint_t));
+ dual_edges = (uint_t *)malloc(2 * tmp_num_edges * sizeof(uint_t));
+ uint_t num_t, num_b, num_l, num_r;
bool *bound_top, *bound_b, *bound_l, *bound_r;
num_t = 0; num_b = 0; num_l = 0; num_r = 0;
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));
- for (unsigned int i = 0; i < tmp_num_edges; i++) {
- unsigned int v1, v2;
+ for (uint_t i = 0; i < tmp_num_edges; i++) {
+ uint_t v1, v2;
double v1x, v1y, v2x, v2y, dx, dy;
v1 = tmp_edges[2 * i]; v2 = tmp_edges[2 * i + 1];
v1x = vert_coords[2 * v1]; v1y = vert_coords[2 * v1 + 1];
@@ -431,20 +431,20 @@ graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
} else {
edges[2 * num_edges] = v1 < v2 ? v1 : v2;
edges[2 * num_edges + 1] = v1 < v2 ? v2 : v1;
- unsigned int d1 = tmp_dual_edges[2 * i];
- unsigned int d2 = tmp_dual_edges[2 * i + 1];
+ uint_t d1 = tmp_dual_edges[2 * i];
+ uint_t d2 = tmp_dual_edges[2 * i + 1];
dual_edges[2 * num_edges] = d1 < d2 ? d1 : d2;
dual_edges[2 * num_edges + 1] = d1 < d2 ? d2 : d1;
num_edges++;
}
}
- bound_verts = malloc((num_t + num_b + num_l + num_r) * sizeof(unsigned int));
+ bound_verts = malloc((num_t + num_b + num_l + num_r) * sizeof(uint_t));
bound_inds[1] = num_t; bound_inds[2] = num_t + num_b;
bound_inds[3] = num_l + num_t + num_b;
bound_inds[4] = num_t + num_b + num_r + num_l;
- unsigned int pos_t, pos_b, pos_l, pos_r;
+ uint_t 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++) {
+ for (uint_t i = 0; i < num_verts; i++) {
if (bound_top[i]) {
bound_verts[pos_t] = i; pos_t++;
} else if (bound_b[i]) {
@@ -468,20 +468,20 @@ graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
}
case CYLINDER_BOUND: {
num_bounds = 2;
- bound_inds = (unsigned int *)malloc((1 + num_bounds) * sizeof(unsigned int));
+ bound_inds = (uint_t *)malloc((1 + num_bounds) * sizeof(uint_t));
bound_inds[0] = 0;
vert_coords = tmp_vert_coords;
num_verts = tmp_num_verts;
num_edges = 0;
- 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;
+ edges = (uint_t *)malloc(2 * tmp_num_edges * sizeof(uint_t));
+ dual_edges = (uint_t *)malloc(2 * tmp_num_edges * sizeof(uint_t));
+ uint_t num_t, num_b;
bool *bound_top, *bound_b;
num_t = 0; num_b = 0;
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;
+ for (uint_t i = 0; i < tmp_num_edges; i++) {
+ uint_t v1, v2;
double v1x, v1y, v2x, v2y, dx, dy;
v1 = tmp_edges[2 * i]; v2 = tmp_edges[2 * i + 1];
v1y = vert_coords[2 * v1 + 1]; v2y = vert_coords[2 * v2 + 1];
@@ -505,18 +505,18 @@ graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
} else {
edges[2 * num_edges] = v1 < v2 ? v1 : v2;
edges[2 * num_edges + 1] = v1 < v2 ? v2 : v1;
- unsigned int d1 = tmp_dual_edges[2 * i];
- unsigned int d2 = tmp_dual_edges[2 * i + 1];
+ uint_t d1 = tmp_dual_edges[2 * i];
+ uint_t d2 = tmp_dual_edges[2 * i + 1];
dual_edges[2 * num_edges] = d1 < d2 ? d1 : d2;
dual_edges[2 * num_edges + 1] = d1 < d2 ? d2 : d1;
num_edges++;
}
}
- bound_verts = malloc((num_t + num_b) * sizeof(unsigned int));
+ bound_verts = malloc((num_t + num_b) * sizeof(uint_t));
bound_inds[1] = num_t; bound_inds[2] = num_t + num_b;
- unsigned int pos_t, pos_b;
+ uint_t pos_t, pos_b;
pos_t = 0; pos_b = 0;
- for (unsigned int i = 0; i < num_verts; i++) {
+ for (uint_t i = 0; i < num_verts; i++) {
if (bound_top[i]) {
bound_verts[pos_t] = i; pos_t++;
} else if (bound_b[i]) {
@@ -535,20 +535,20 @@ graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
}
case TORUS_BOUND: {
num_bounds = 1;
- bound_inds = (unsigned int *)malloc((1 + num_bounds) * sizeof(unsigned int));
+ bound_inds = (uint_t *)malloc((1 + num_bounds) * sizeof(uint_t));
bound_inds[0] = 0;
num_edges = tmp_num_edges;
- edges = (unsigned int *)malloc(2* num_edges*sizeof(unsigned int));
- for (unsigned int i = 0; i < num_edges; i++) {
+ edges = (uint_t *)malloc(2* num_edges*sizeof(uint_t));
+ for (uint_t i = 0; i < num_edges; i++) {
edges[2*i] = tmp_edges[2*i];
edges[2*i+1] = tmp_edges[2*i+1];
}
dual_edges = tmp_dual_edges;
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++) {
- unsigned int v1, v2;
+ uint_t num_t = 0;
+ for (uint_t i = 0; i < num_edges; i++) {
+ uint_t v1, v2;
double v1x, v1y, v2x, v2y, dx, dy;
v1 = edges[2 * i]; v2 = edges[2 * i + 1];
v1x = tmp_vert_coords[2 * v1]; v1y = tmp_vert_coords[2 * v1 + 1];
@@ -570,10 +570,10 @@ graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
}
num_verts = tmp_num_verts + num_t;
vert_coords = (double *)malloc(2 * num_verts * sizeof(double));
- bound_verts = malloc(num_t * sizeof(unsigned int));
+ bound_verts = malloc(num_t * sizeof(uint_t));
bound_inds[1] = num_t;
- unsigned int pos_t = 0;
- for (unsigned int i = 0; i < tmp_num_verts; i++) {
+ uint_t pos_t = 0;
+ for (uint_t 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_top[i]) {
@@ -583,9 +583,9 @@ graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
pos_t++;
}
}
- for (unsigned int i = 0; i < num_edges; i++) {
+ for (uint_t i = 0; i < num_edges; i++) {
if (edge_change[i]) {
- for (unsigned int j = 0; j < num_t; j++) {
+ for (uint_t j = 0; j < num_t; j++) {
if (edges[2*i+(edge_change[i]-1)] == bound_verts[j]) {
edges[2*i+(edge_change[i]-1)] = tmp_num_verts + j;
break;
@@ -605,12 +605,12 @@ graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
}
case EMBEDDED_BOUND: {
num_bounds = 4;
- 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;
- unsigned int num_away = 0;
- for (unsigned int i = 0; i < tmp_num_edges; i++) {
+ bound_inds = (uint_t *)malloc(5 * sizeof(uint_t));
+ bound_verts = (uint_t *)malloc(2 * L * sizeof(uint_t));
+ for (uint_t i = 0; i < 5; i++) bound_inds[i] = i * L / 2;
+ for (uint_t i = 0; i < 2 * L; i++) bound_verts[i] = i;
+ uint_t num_away = 0;
+ for (uint_t 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;
@@ -667,11 +667,14 @@ graph_t *ini_voro_graph(unsigned int L, bound_t boundary, bool use_dual,
graph_t *graph_create(lattice_t lattice, bound_t bound, uint_t L, bool dual, cholmod_common *c) {
+ bool side_bounds;
switch (lattice) {
case (VORONOI_LATTICE):
return ini_voro_graph(L, bound, dual, genfunc_hyperuniform, c);
case (SQUARE_LATTICE):
- return ini_square_network(L, bound, true, c);
+ if (bound == EMBEDDED_BOUND) side_bounds = true;
+ else side_bounds = false;
+ return ini_square_network(L, bound, side_bounds, c);
default:
printf("lattice type unsupported\n");
exit(EXIT_FAILURE);
diff --git a/src/net_notch.c b/src/net_notch.c
index c0ab9d7..48dce1e 100644
--- a/src/net_notch.c
+++ b/src/net_notch.c
@@ -20,7 +20,8 @@ void net_notch(net_t *net, double notch_len, cholmod_common *c) {
crosses_center = (v1y >= 0.5 && v2y <= 0.5) || (v1y <= 0.5 && v2y >= 0.5);
not_wrapping = fabs(dy) < 0.5;
- correct_length = 0 <= v1x + dx / dy * (v1y - 0.5) <= notch_len;
+ //correct_length = v1x + dx / dy * (v1y - 0.5) <= notch_len;
+ correct_length = v1x < notch_len && v2x < notch_len;
if (crosses_center && not_wrapping && correct_length) {
break_edge(net, i, c);