summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpants <jaron@kent-dobias.com>2016-09-06 15:05:27 -0400
committerpants <jaron@kent-dobias.com>2016-09-06 15:05:27 -0400
commit4c4ebb87ead363d6d6e11a8b95b07a0f93af5c88 (patch)
tree9cdaaf27917c2b1562740dec501d013e47a25dd1 /src
parentfd14c5e39d962be94a1f68b0d4cacb7a4aa9c3e7 (diff)
downloadfuse_networks-4c4ebb87ead363d6d6e11a8b95b07a0f93af5c88.tar.gz
fuse_networks-4c4ebb87ead363d6d6e11a8b95b07a0f93af5c88.tar.bz2
fuse_networks-4c4ebb87ead363d6d6e11a8b95b07a0f93af5c88.zip
finished implementing embedded systems, refactored a bunch
Diffstat (limited to 'src')
-rw-r--r--src/bin_values.c4
-rw-r--r--src/break_data.c8
-rw-r--r--src/break_edge.c34
-rw-r--r--src/compare_voronoi_fracture.c34
-rw-r--r--src/corr_test.c8
-rw-r--r--src/correlations.c34
-rw-r--r--src/course_grain_square.c28
-rw-r--r--src/coursegrain.c8
-rw-r--r--src/cracked_voronoi_fracture.c163
-rw-r--r--src/cracking_ini.c22
-rw-r--r--src/current_scaling.c48
-rw-r--r--src/fracture.c46
-rw-r--r--src/fracture.h102
-rw-r--r--src/fracture_network.c16
-rw-r--r--src/free_network.c18
-rw-r--r--src/gen_laplacian.c48
-rw-r--r--src/get_conductivity.c16
-rw-r--r--src/get_current.c26
-rw-r--r--src/get_dual_clusters.c8
-rw-r--r--src/homo_square_fracture.c50
-rw-r--r--src/homo_voronoi_fracture.c42
-rw-r--r--src/ini_network.c192
-rw-r--r--src/instance.c42
-rw-r--r--src/update_boundary.c6
-rw-r--r--src/voronoi_bound_ini.c2
25 files changed, 541 insertions, 464 deletions
diff --git a/src/bin_values.c b/src/bin_values.c
index 2cb9cf6..8cde548 100644
--- a/src/bin_values.c
+++ b/src/bin_values.c
@@ -1,10 +1,10 @@
#include "fracture.h"
-double *bin_values(fnet *network, unsigned int width, double *values) {
+double *bin_values(graph_t *network, unsigned int width, double *values) {
double *binned = calloc(pow(width, 2), sizeof(double));
unsigned int *num_binned = calloc(pow(width, 2), sizeof(unsigned int));
- for (unsigned int i = 0; i < network->num_edges; i++) {
+ for (unsigned int i = 0; i < network->ne; i++) {
if (values[i] != 0) {
unsigned int x = ((int)(network->edge_coords[2 * i] * width)) % width;
unsigned int y = ((int)(network->edge_coords[2 * i + 1] * width)) % width;
diff --git a/src/break_data.c b/src/break_data.c
index 0ce6730..5c922f3 100644
--- a/src/break_data.c
+++ b/src/break_data.c
@@ -1,8 +1,8 @@
#include "fracture.h"
-break_data *alloc_break_data(unsigned int num_edges) {
- break_data *data = malloc(1 * sizeof(break_data)); assert(data != NULL);
+data_t *alloc_break_data(unsigned int num_edges) {
+ data_t *data = malloc(1 * sizeof(data_t)); assert(data != NULL);
data->num_broken = 0;
@@ -18,14 +18,14 @@ break_data *alloc_break_data(unsigned int num_edges) {
return data;
}
-void free_break_data(break_data *data) {
+void free_break_data(data_t *data) {
free(data->break_list);
free(data->extern_field);
free(data->conductivity);
free(data);
}
-void update_break_data(break_data *data, unsigned int last_broke, double strength, double conductivity) {
+void update_break_data(data_t *data, unsigned int last_broke, double strength, double conductivity) {
data->break_list[data->num_broken] = last_broke;
data->extern_field[data->num_broken] = strength;
data->conductivity[data->num_broken] = conductivity;
diff --git a/src/break_edge.c b/src/break_edge.c
index 72ccf3e..7b94160 100644
--- a/src/break_edge.c
+++ b/src/break_edge.c
@@ -1,18 +1,18 @@
#include "fracture.h"
-bool break_edge(finst *instance, unsigned int edge, cholmod_common *c) {
+bool break_edge(net_t *instance, unsigned int edge, cholmod_common *c) {
instance->fuses[edge] = true;
instance->num_remaining_edges--;
- unsigned int v1 = instance->network->edges_to_verts_break[2 * edge];
- unsigned int v2 = instance->network->edges_to_verts_break[2 * edge + 1];
+ unsigned int v1 = instance->graph->ev_break[2 * edge];
+ unsigned int v2 = instance->graph->ev_break[2 * edge + 1];
if (instance->factor != NULL) update_factor(instance->factor, v1, v2, c);
- if (instance->network->boundary != TORUS_BOUND) {
- unsigned int w1 = instance->network->edges_to_verts[2 * edge];
- unsigned int w2 = instance->network->edges_to_verts[2 * edge + 1];
+ if (instance->graph->boundary != TORUS_BOUND) {
+ unsigned int w1 = instance->graph->ev[2 * edge];
+ unsigned int w2 = instance->graph->ev[2 * edge + 1];
unsigned int tw1 = w1 > w2 ? w1 : w2;
unsigned int tw2 = w1 > w2 ? w2 : w1;
@@ -37,13 +37,13 @@ bool break_edge(finst *instance, unsigned int edge, cholmod_common *c) {
(int)tw2, 0);
}
- if (instance->network->boundary == TORUS_BOUND) {
- unsigned int dw1 = instance->network->dual_edges_to_verts[2 * edge];
- unsigned int dw2 = instance->network->dual_edges_to_verts[2 * edge + 1];
+ if (instance->graph->boundary == TORUS_BOUND) {
+ unsigned int dw1 = instance->graph->dev[2 * edge];
+ unsigned int dw2 = instance->graph->dev[2 * edge + 1];
if (instance->dual_marks[dw1] == instance->dual_marks[dw2]) {
- int **cycles = (int **)malloc(2*instance->network->num_edges * sizeof(int *));
- unsigned int num_cycles = find_cycles(instance->network->num_edges, instance->fuses, instance->network->dual_edges_to_verts, instance->network->dual_verts_to_edges_ind, instance->network->dual_verts_to_edges, cycles);
+ int **cycles = (int **)malloc(2*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++) {
int x_num_crossings = 0;
@@ -54,12 +54,12 @@ bool break_edge(finst *instance, unsigned int edge, cholmod_common *c) {
j++;
unsigned int v1, v2;
double v1x, v1y, v2x, v2y;
- v1 = instance->network->dual_edges_to_verts[2 * ee + !side];
- v2 = instance->network->dual_edges_to_verts[2 * ee + side];
- v1x = instance->network->dual_vert_coords[2 * v1];
- v1y = instance->network->dual_vert_coords[2 * v1 + 1];
- v2x = instance->network->dual_vert_coords[2 * v2];
- v2y = instance->network->dual_vert_coords[2 * v2 + 1];
+ v1 = instance->graph->dev[2 * ee + !side];
+ v2 = instance->graph->dev[2 * ee + side];
+ v1x = instance->graph->dual_vert_coords[2 * v1];
+ v1y = instance->graph->dual_vert_coords[2 * v1 + 1];
+ v2x = instance->graph->dual_vert_coords[2 * v2];
+ v2y = instance->graph->dual_vert_coords[2 * v2 + 1];
double dx = v1x - v2x;
double dy = v1y - v2y;
if (((v1x > 0.5 && v2x < 0.5) || (v1x < 0.5 && v2x > 0.5)) && fabs(dx) < 0.5) {
diff --git a/src/compare_voronoi_fracture.c b/src/compare_voronoi_fracture.c
index bdb9423..2edcae2 100644
--- a/src/compare_voronoi_fracture.c
+++ b/src/compare_voronoi_fracture.c
@@ -66,14 +66,14 @@ int main(int argc, char *argv[]) {
(&c)->supernodal = CHOLMOD_SIMPLICIAL;
- fnet *network = ini_voronoi_network(L, false, boundary, genfunc_hyperuniform, &c);
- finst *perm_voltage_instance = create_instance(network, inf, true, true, &c);
- finst *perm_current_instance = create_instance(network, inf, false, true, &c);
- double *fuse_thres = gen_fuse_thres(network->num_edges, network->edge_coords, beta, beta_scaling_flat);
- finst *voltage_instance = copy_instance(perm_voltage_instance, &c);
- finst *current_instance = copy_instance(perm_current_instance, &c);
- break_data *breaking_data_voltage = fracture_network(voltage_instance, fuse_thres, &c, cutoff);
- break_data *breaking_data_current = fracture_network(current_instance, fuse_thres, &c, cutoff);
+ graph_t *network = ini_voronoi_network(L, false, boundary, genfunc_hyperuniform, &c);
+ net_t *perm_voltage_instance = create_instance(network, inf, true, true, &c);
+ net_t *perm_current_instance = create_instance(network, inf, false, true, &c);
+ double *fuse_thres = gen_fuse_thres(network->ne, network->edge_coords, beta, beta_scaling_flat);
+ net_t *voltage_instance = copy_instance(perm_voltage_instance, &c);
+ net_t *current_instance = copy_instance(perm_current_instance, &c);
+ data_t *breaking_data_voltage = fracture_network(voltage_instance, fuse_thres, &c, cutoff);
+ data_t *breaking_data_current = fracture_network(current_instance, fuse_thres, &c, cutoff);
free_instance(voltage_instance, &c);
free_instance(current_instance, &c);
free_instance(perm_voltage_instance, &c);
@@ -81,27 +81,27 @@ int main(int argc, char *argv[]) {
free(fuse_thres);
FILE *net_out = fopen("network.txt", "w");
- for (unsigned int j = 0; j < network->num_verts; j++) {
+ for (unsigned int j = 0; j < network->nv; j++) {
fprintf(net_out, "%f %f ", network->vert_coords[2 * j],
network->vert_coords[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < network->num_edges; j++) {
- fprintf(net_out, "%u %u ", network->edges_to_verts[2 * j],
- network->edges_to_verts[2 * j + 1]);
+ for (unsigned int j = 0; j < network->ne; j++) {
+ fprintf(net_out, "%u %u ", network->ev[2 * j],
+ network->ev[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < network->num_dual_verts; j++) {
+ for (unsigned int j = 0; j < network->dnv; j++) {
fprintf(net_out, "%f %f ", network->dual_vert_coords[2 * j],
network->dual_vert_coords[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < network->num_edges; j++) {
- fprintf(net_out, "%u %u ", network->dual_edges_to_verts[2 * j],
- network->dual_edges_to_verts[2 * j + 1]);
+ for (unsigned int j = 0; j < network->ne; j++) {
+ fprintf(net_out, "%u %u ", network->dev[2 * j],
+ network->dev[2 * j + 1]);
}
- free_fnet(network, &c);
+ free_net(network, &c);
for (unsigned int j = 0; j < breaking_data_voltage->num_broken; j++) {
fprintf(break_out, "%u %g %g ", breaking_data_voltage->break_list[j],
diff --git a/src/corr_test.c b/src/corr_test.c
index 2c93b8e..e0de2d8 100644
--- a/src/corr_test.c
+++ b/src/corr_test.c
@@ -8,9 +8,9 @@ int main() {
unsigned int width = 64;
unsigned int n = pow(width / 2 + 1, 2) + pow((width + 1) / 2, 2);
- fnet *network = ini_square_network(width, true, false, &c);
- finst *instance = create_instance(network, 1e-14, true, true, &c);
- double *fuse_thres = gen_fuse_thres(network->num_edges, network->edge_coords,
+ graph_t *network = ini_square_network(width, true, false, &c);
+ net_t *instance = create_instance(network, 1e-14, true, true, &c);
+ double *fuse_thres = gen_fuse_thres(network->ne, network->edge_coords,
0.001, beta_scaling_flat);
fracture_network(instance, fuse_thres, &c, 1e-10);
@@ -22,7 +22,7 @@ int main() {
printf("\n");
free_instance(instance, &c);
- free_fnet(network, &c);
+ free_net(network, &c);
CHOL_F(finish)(&c);
diff --git a/src/correlations.c b/src/correlations.c
index bd05daf..4fc44ac 100644
--- a/src/correlations.c
+++ b/src/correlations.c
@@ -197,11 +197,11 @@ void fib_decreasekey(fibh *heap, unsigned int value,
}
}
-unsigned int *dijkstra(fnet *network, unsigned int source) {
- unsigned int nv = network->num_dual_verts;
- unsigned int *vei = network->dual_verts_to_edges_ind;
- unsigned int *ve = network->dual_verts_to_edges;
- unsigned int *ev = network->dual_edges_to_verts;
+unsigned int *dijkstra(graph_t *network, unsigned int source) {
+ unsigned int nv = network->dnv;
+ unsigned int *vei = network->dvei;
+ unsigned int *ve = network->dve;
+ unsigned int *ev = network->dev;
unsigned int *dist = (unsigned int *)calloc(nv, sizeof(unsigned int));
fibh *Q = (fibh *)calloc(1, sizeof(fibh));
@@ -236,8 +236,8 @@ unsigned int *dijkstra(fnet *network, unsigned int source) {
return dist;
}
-unsigned int **get_dists(fnet *network) {
- unsigned int nv = network->num_dual_verts;
+unsigned int **get_dists(graph_t *network) {
+ unsigned int nv = network->dnv;
unsigned int **dists = (unsigned int **)malloc(nv * sizeof(unsigned int *));
#pragma omp parallel for
@@ -248,13 +248,13 @@ unsigned int **get_dists(fnet *network) {
return dists;
}
-double *get_corr(finst *instance, unsigned int **dists, cholmod_common *c) {
- unsigned int nv = instance->network->num_dual_verts;
- unsigned int ne = instance->network->num_edges;
- unsigned int *ev = instance->network->dual_edges_to_verts;
+double *get_corr(net_t *instance, unsigned int **dists, cholmod_common *c) {
+ unsigned int nv = instance->graph->dnv;
+ unsigned int ne = instance->graph->ne;
+ unsigned int *ev = instance->graph->dev;
bool nulldists = false;
if (dists == NULL) {
- dists = get_dists(instance->network);
+ dists = get_dists(instance->graph);
nulldists = true;
}
double *corr = calloc(nv, sizeof(double));
@@ -296,11 +296,11 @@ double *get_corr(finst *instance, unsigned int **dists, cholmod_common *c) {
}
/*
-double *get_space_corr(finst *instance, cholmod_common *c) {
- unsigned int nv = instance->network->num_dual_verts;
- double *vc = instance->network->dual_vert_coords;
- unsigned int ne = instance->network->num_edges;
- unsigned int *ev = instance->network->dual_edges_to_verts;
+double *get_space_corr(net_t *instance, cholmod_common *c) {
+ unsigned int nv = instance->graph->dnv;
+ double *vc = instance->graph->dual_vert_coords;
+ unsigned int ne = instance->graph->ne;
+ unsigned int *ev = instance->graph->dev;
double *corr = calloc(nv, sizeof(unsigned int));
unsigned int *numat = calloc(nv, sizeof(unsigned int));
diff --git a/src/course_grain_square.c b/src/course_grain_square.c
index 9035cf7..9c9ca6e 100644
--- a/src/course_grain_square.c
+++ b/src/course_grain_square.c
@@ -63,11 +63,11 @@ int main(int argc, char *argv[]) {
(&c)->supernodal = CHOLMOD_SIMPLICIAL;
}
- fnet *network = ini_square_network(width, periodic, false, &c);
- fnet *network_p = ini_square_network(width / 2, periodic, false, &c);
- finst *perm_instance = create_instance(network, inf, voltage_bound, true, &c);
- unsigned int c_dist_size = network->num_dual_verts;
- unsigned int c_p_dist_size = network_p->num_dual_verts;
+ graph_t *network = ini_square_network(width, periodic, false, &c);
+ graph_t *network_p = ini_square_network(width / 2, periodic, false, &c);
+ net_t *perm_instance = create_instance(network, inf, voltage_bound, true, &c);
+ unsigned int c_dist_size = network->dnv;
+ unsigned int c_p_dist_size = network_p->dnv;
// define arrays for saving cluster and avalanche distributions
unsigned int *cluster_size_dist =
@@ -80,11 +80,11 @@ int main(int argc, char *argv[]) {
printf("\033[F\033[JCOURSEGRAIN_SQUARE: %0*d / %d\n", (int)log10(num) + 1,
DUMB + 1, num);
- break_data *breaking_data = NULL;
- finst *instance = NULL;
+ data_t *breaking_data = NULL;
+ net_t *instance = NULL;
while (breaking_data == NULL) {
double *fuse_thres = gen_fuse_thres(
- network->num_edges, network->edge_coords, beta, beta_scaling_flat);
+ network->ne, network->edge_coords, beta, beta_scaling_flat);
instance = copy_instance(perm_instance, &c);
breaking_data = fracture_network(instance, fuse_thres, &c, cutoff);
free_instance(instance, &c);
@@ -104,22 +104,22 @@ int main(int argc, char *argv[]) {
break;
}
- finst *tmp_instance = copy_instance(perm_instance, &c);
+ net_t *tmp_instance = copy_instance(perm_instance, &c);
for (unsigned int i = 0; i < breaking_data->num_broken; i++) {
break_edge(tmp_instance, breaking_data->break_list[i], &c);
}
unsigned int *tmp_cluster_dist = get_cluster_dist(tmp_instance, &c);
- for (unsigned int i = 0; i < network->num_dual_verts; i++) {
+ for (unsigned int i = 0; i < network->dnv; i++) {
cluster_size_dist[i] += tmp_cluster_dist[i];
}
free(tmp_cluster_dist);
- finst *instance_p = coursegrain_square(tmp_instance, network_p, &c);
+ net_t *instance_p = coursegrain_square(tmp_instance, network_p, &c);
unsigned int *tmp_cluster_p_dist = get_cluster_dist(instance_p, &c);
- for (unsigned int i = 0; i < network_p->num_dual_verts; i++) {
+ for (unsigned int i = 0; i < network_p->dnv; i++) {
cluster_p_size_dist[i] += tmp_cluster_p_dist[i];
}
free(tmp_cluster_p_dist);
@@ -159,8 +159,8 @@ int main(int argc, char *argv[]) {
free(cluster_size_dist);
free(cluster_p_size_dist);
free_instance(perm_instance, &c);
- free_fnet(network, &c);
- free_fnet(network_p, &c);
+ free_net(network, &c);
+ free_net(network_p, &c);
CHOL_F(finish)(&c);
diff --git a/src/coursegrain.c b/src/coursegrain.c
index bd84e1c..1e0d5a7 100644
--- a/src/coursegrain.c
+++ b/src/coursegrain.c
@@ -1,17 +1,17 @@
#include "fracture.h"
-finst *coursegrain_square(finst *instance, fnet *network_p, cholmod_common *c) {
- unsigned int width = sqrt(instance->network->num_edges);
+net_t *coursegrain_square(net_t *instance, graph_t *network_p, cholmod_common *c) {
+ unsigned int width = sqrt(instance->graph->ne);
assert(width % 4 == 0);
- finst *instance_p = create_instance(network_p, instance->inf,
+ net_t *instance_p = create_instance(network_p, instance->inf,
instance->voltage_bound, true, c);
unsigned int width_p = width / 2;
bool *fuses = instance->fuses;
- for (unsigned int i = 0; i < network_p->num_edges; i++) {
+ for (unsigned int i = 0; i < network_p->ne; i++) {
int xp = i / width_p;
int yp = i % width_p;
unsigned int x1 = 2 * xp;
diff --git a/src/cracked_voronoi_fracture.c b/src/cracked_voronoi_fracture.c
index 532c3c3..93eb112 100644
--- a/src/cracked_voronoi_fracture.c
+++ b/src/cracked_voronoi_fracture.c
@@ -15,8 +15,14 @@ int main(int argc, char *argv[]) {
save_damage, save_damage_field;
bound_t boundary;
+
+ // assume filenames will be less than 100 characters
+
filename_len = 100;
+
+ // set default values
+
N = 100;
L = 16;
crack_len = 0.;
@@ -37,9 +43,13 @@ int main(int argc, char *argv[]) {
save_conductivity = false;
save_toughness = false;
+
uint8_t bound_i;
char boundc2 = 'f';
+
+ // get commandline options
+
while ((opt = getopt(argc, argv, "n:L:b:B:dVcoNsCrtDSvel:")) != -1) {
switch (opt) {
case 'n':
@@ -123,6 +133,7 @@ int main(int argc, char *argv[]) {
}
}
+
char boundc;
if (use_voltage_boundaries) boundc = 'v';
else boundc = 'c';
@@ -130,7 +141,7 @@ int main(int argc, char *argv[]) {
FILE *break_out;
if (include_breaking) {
char *break_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(break_filename, filename_len, "breaks_v_%c_%c_%u_%g.txt", boundc, boundc2, L, beta);
+ snprintf(break_filename, filename_len, "breaks_v_%c_%c_%u_%g_%g.txt", boundc, boundc2, L, beta, crack_len);
break_out = fopen(break_filename, "a");
free(break_filename);
}
@@ -158,8 +169,8 @@ int main(int argc, char *argv[]) {
c_filename = (char *)malloc(filename_len * sizeof(char));
a_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(c_filename, filename_len, "cstr_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
- snprintf(a_filename, filename_len, "avln_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
+ snprintf(c_filename, filename_len, "cstr_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len);
+ snprintf(a_filename, filename_len, "avln_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len);
FILE *cluster_out = fopen(c_filename, "rb");
FILE *avalanche_out = fopen(a_filename, "rb");
@@ -179,6 +190,24 @@ int main(int argc, char *argv[]) {
crit_stress = (double *)malloc(N * sizeof(double));
}
+ double *stress_field;
+ unsigned int stress_pos = 0;
+ if (save_stress_field) {
+ stress_field = (double *)malloc(3 * N * voronoi_max_verts * sizeof(double));
+ }
+
+ double *voltage_field;
+ unsigned int voltage_pos = 0;
+ if (save_voltage_field) {
+ voltage_field = (double *)malloc(3 * N * voronoi_max_verts * sizeof(double));
+ }
+
+ double *damage_field;
+ unsigned int damage_pos = 0;
+ if (save_damage_field) {
+ damage_field = (double *)malloc(2 * N * voronoi_max_verts * sizeof(double));
+ }
+
double *conductivity;
if (save_conductivity) {
conductivity = (double *)malloc(N * sizeof(double));
@@ -192,7 +221,7 @@ int main(int argc, char *argv[]) {
(uint32_t *)malloc(a_dist_size * sizeof(uint32_t));
d_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(d_filename, filename_len, "damg_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
+ snprintf(d_filename, filename_len, "damg_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len);
FILE *damage_out = fopen(d_filename, "rb");
@@ -228,16 +257,16 @@ int main(int argc, char *argv[]) {
for (uint32_t i = 0; i < N; i++) {
printf("\033[F\033[JFRACTURE: %0*d / %d\n", (uint8_t)log10(N) + 1, i + 1, N);
- fnet *network = ini_voronoi_network(L, boundary, use_dual, genfunc_hyperuniform, &c);
- finst *perm_instance = create_instance(network, inf, use_voltage_boundaries, false, &c);
+ graph_t *graph = ini_voronoi_network(L, boundary, use_dual, genfunc_hyperuniform, &c);
+ net_t *perm_instance = create_instance(graph, inf, use_voltage_boundaries, false, &c);
if (boundary == EMBEDDED_BOUND) {
voronoi_bound_ini(perm_instance, L, crack_len);
}
gen_voro_crack(perm_instance, crack_len, &c);
finish_instance(perm_instance, &c);
- double *fuse_thres = gen_fuse_thres(network->num_edges, network->edge_coords, beta, beta_scaling_flat);
- finst *instance = copy_instance(perm_instance, &c);
- break_data *breaking_data = fracture_network(instance, fuse_thres, &c, cutoff);
+ double *fuse_thres = gen_fuse_thres(graph->ne, graph->edge_coords, beta, beta_scaling_flat);
+ net_t *instance = copy_instance(perm_instance, &c);
+ data_t *breaking_data = fracture_network(instance, fuse_thres, &c, cutoff);
free_instance(instance, &c);
free(fuse_thres);
@@ -253,12 +282,13 @@ int main(int argc, char *argv[]) {
}
}
- if (save_crit_stress) {
- crit_stress[i] =
- breaking_data->extern_field[max_pos];
- }
+ if (save_crit_stress) crit_stress[i] = breaking_data->extern_field[max_pos];
+
+ if (save_conductivity) conductivity[i] = breaking_data->conductivity[max_pos];
- finst *tmp_instance = copy_instance(perm_instance, &c);
+ if (save_damage) damage[max_pos]++;
+
+ net_t *tmp_instance = copy_instance(perm_instance, &c);
uint_t av_size = 0;
double cur_val = 0;
@@ -279,13 +309,34 @@ int main(int argc, char *argv[]) {
}
}
- if (save_conductivity) {
- if (!use_voltage_boundaries) {
- double *tmp_voltage = get_voltage(tmp_instance, &c);
- conductivity[i] = 1/fabs(tmp_voltage[tmp_instance->network->num_verts + 1] - tmp_voltage[tmp_instance->network->num_verts]);
- free(tmp_voltage);
- } else {
- conductivity[i] = breaking_data->conductivity[max_pos];
+ if (save_stress_field || save_voltage_field) {
+ double *tmp_voltages = get_voltage(tmp_instance, &c);
+ if (save_voltage_field) {
+ for (uint_t j = 0; j < tmp_instance->graph->nv; j++) {
+ voltage_field[3 * voltage_pos] = tmp_instance->graph->vert_coords[2 * j];
+ voltage_field[3 * voltage_pos + 1] = tmp_instance->graph->vert_coords[2 * j + 1];
+ voltage_field[3 * voltage_pos + 2] = tmp_voltages[j];
+ voltage_pos++;
+ }
+ }
+ if (save_stress_field) {
+ double *tmp_currents = get_current_v(tmp_instance, tmp_voltages, &c);
+ for (uint_t j = 0; j < tmp_instance->graph->ne; j++) {
+ stress_field[3 * stress_pos] = tmp_instance->graph->edge_coords[2 * j];
+ stress_field[3 * stress_pos + 1] = tmp_instance->graph->edge_coords[2 * j + 1];
+ stress_field[3 * stress_pos + 2] = tmp_currents[j];
+ stress_pos++;
+ }
+ free(tmp_currents);
+ }
+ free(tmp_voltages);
+ }
+
+ if (save_damage_field) {
+ for (uint_t j = 0; j < max_pos; j++) {
+ damage_field[2 * damage_pos] = tmp_instance->graph->edge_coords[2 * breaking_data->break_list[j]];
+ damage_field[2 * damage_pos + 1] = tmp_instance->graph->edge_coords[2 * breaking_data->break_list[j] + 1];
+ damage_pos++;
}
}
@@ -306,13 +357,9 @@ int main(int argc, char *argv[]) {
toughness[i] = tmp_toughness;
}
- if (save_damage) {
- damage[max_pos]++;
- }
-
if (save_cluster_dist) {
uint_t *tmp_cluster_dist = get_cluster_dist(tmp_instance, &c);
- for (uint_t j = 0; j < tmp_instance->network->num_dual_verts; j++) {
+ for (uint_t j = 0; j < tmp_instance->graph->dnv; j++) {
cluster_size_dist[j] += tmp_cluster_dist[j];
}
free(tmp_cluster_dist);
@@ -320,27 +367,27 @@ int main(int argc, char *argv[]) {
if (save_network) {
FILE *net_out = fopen("network.txt", "w");
- for (uint_t j = 0; j < network->num_verts; j++) {
- fprintf(net_out, "%f %f ", network->vert_coords[2 * j],
- tmp_instance->network->vert_coords[2 * j + 1]);
+ for (uint_t j = 0; j < graph->nv; j++) {
+ fprintf(net_out, "%f %f ", graph->vert_coords[2 * j],
+ tmp_instance->graph->vert_coords[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (uint_t j = 0; j < tmp_instance->network->num_edges; j++) {
- fprintf(net_out, "%u %u ", tmp_instance->network->edges_to_verts[2 * j],
- tmp_instance->network->edges_to_verts[2 * j + 1]);
+ for (uint_t j = 0; j < tmp_instance->graph->ne; j++) {
+ fprintf(net_out, "%u %u ", tmp_instance->graph->ev[2 * j],
+ tmp_instance->graph->ev[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (uint_t j = 0; j < tmp_instance->network->num_dual_verts; j++) {
- fprintf(net_out, "%f %f ", tmp_instance->network->dual_vert_coords[2 * j],
- tmp_instance->network->dual_vert_coords[2 * j + 1]);
+ for (uint_t j = 0; j < tmp_instance->graph->dnv; j++) {
+ fprintf(net_out, "%f %f ", tmp_instance->graph->dual_vert_coords[2 * j],
+ tmp_instance->graph->dual_vert_coords[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (uint_t j = 0; j < tmp_instance->network->num_edges; j++) {
- fprintf(net_out, "%u %u ", tmp_instance->network->dual_edges_to_verts[2 * j],
- tmp_instance->network->dual_edges_to_verts[2 * j + 1]);
+ for (uint_t j = 0; j < tmp_instance->graph->ne; j++) {
+ fprintf(net_out, "%u %u ", tmp_instance->graph->dev[2 * j],
+ tmp_instance->graph->dev[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (uint_t j = 0; j < tmp_instance->network->num_edges; j++) {
+ for (uint_t j = 0; j < tmp_instance->graph->ne; j++) {
fprintf(net_out, "%d ", tmp_instance->fuses[j]);
}
fclose(net_out);
@@ -348,7 +395,7 @@ int main(int argc, char *argv[]) {
free_instance(tmp_instance, &c);
free_instance(perm_instance, &c);
- free_fnet(network, &c);
+ free_net(graph, &c);
if (include_breaking) {
for (uint_t j = 0; j < breaking_data->num_broken; j++) {
@@ -379,9 +426,39 @@ int main(int argc, char *argv[]) {
free(avalanche_size_dist);
}
+ if (save_voltage_field) {
+ char *vfld_filename = (char *)malloc(filename_len * sizeof(char));
+ snprintf(vfld_filename, filename_len, "vfld_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len);
+ FILE *vfld_file = fopen(vfld_filename, "ab");
+ fwrite(voltage_field, sizeof(double), 3 * voltage_pos, vfld_file);
+ fclose(vfld_file);
+ free(vfld_filename);
+ free(voltage_field);
+ }
+
+ if (save_stress_field) {
+ char *cfld_filename = (char *)malloc(filename_len * sizeof(char));
+ snprintf(cfld_filename, filename_len, "cfld_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len);
+ FILE *cfld_file = fopen(cfld_filename, "ab");
+ fwrite(stress_field, sizeof(double), 3 * stress_pos, cfld_file);
+ fclose(cfld_file);
+ free(cfld_filename);
+ free(stress_field);
+ }
+
+ if (save_damage_field) {
+ char *dfld_filename = (char *)malloc(filename_len * sizeof(char));
+ snprintf(dfld_filename, filename_len, "dfld_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len);
+ FILE *dfld_file = fopen(dfld_filename, "ab");
+ fwrite(damage_field, sizeof(double), 2 * damage_pos, dfld_file);
+ fclose(dfld_file);
+ free(dfld_filename);
+ free(damage_field);
+ }
+
if (save_conductivity) {
char *cond_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(cond_filename, filename_len, "cond_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
+ snprintf(cond_filename, filename_len, "cond_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len);
FILE *cond_file = fopen(cond_filename, "ab");
fwrite(conductivity, sizeof(double), N, cond_file);
fclose(cond_file);
@@ -391,7 +468,7 @@ int main(int argc, char *argv[]) {
if (save_toughness) {
char *tough_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(tough_filename, filename_len, "tuff_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
+ snprintf(tough_filename, filename_len, "tuff_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len);
FILE *tough_file = fopen(tough_filename, "ab");
fwrite(toughness, sizeof(double), N, tough_file);
fclose(tough_file);
@@ -413,7 +490,7 @@ int main(int argc, char *argv[]) {
if (save_crit_stress) {
char *str_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(str_filename, filename_len, "strs_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
+ snprintf(str_filename, filename_len, "strs_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len);
FILE *str_file = fopen(str_filename, "ab");
fwrite(crit_stress, sizeof(double), N, str_file);
fclose(str_file);
diff --git a/src/cracking_ini.c b/src/cracking_ini.c
index 988af5b..93e5765 100644
--- a/src/cracking_ini.c
+++ b/src/cracking_ini.c
@@ -31,18 +31,18 @@ double *gen_fuse_thres(unsigned int num_edges, double *edge_coords, double beta,
return fuse_thres;
}
-void gen_voro_crack(finst *instance, double crack_len, cholmod_common *c) {
- for (uint_t i = 0; i < instance->network->num_edges; i++) {
+void gen_voro_crack(net_t *instance, double crack_len, cholmod_common *c) {
+ for (uint_t i = 0; i < instance->graph->ne; i++) {
uint_t v1, v2;
double v1x, v1y, v2x, v2y, dx, dy;
- v1 = instance->network->edges_to_verts[2 * i];
- v2 = instance->network->edges_to_verts[2 * i + 1];
+ v1 = instance->graph->ev[2 * i];
+ v2 = instance->graph->ev[2 * i + 1];
- v1x = instance->network->vert_coords[2 * v1];
- v1y = instance->network->vert_coords[2 * v1 + 1];
- v2x = instance->network->vert_coords[2 * v2];
- v2y = instance->network->vert_coords[2 * v2 + 1];
+ v1x = instance->graph->vert_coords[2 * v1];
+ v1y = instance->graph->vert_coords[2 * v1 + 1];
+ v2x = instance->graph->vert_coords[2 * v2];
+ v2y = instance->graph->vert_coords[2 * v2 + 1];
dx = v1x - v2x;
dy = v1y - v2y;
@@ -55,13 +55,13 @@ void gen_voro_crack(finst *instance, double crack_len, cholmod_common *c) {
}
}
-bool gen_crack(finst *instance, double crack_len, double crack_width,
+bool gen_crack(net_t *instance, double crack_len, double crack_width,
cholmod_common *c) {
assert(instance != NULL);
bool *fuses = instance->fuses;
assert(fuses != NULL);
- const fnet *network = instance->network;
- unsigned int num_edges = network->num_edges;
+ const graph_t *network = instance->graph;
+ unsigned int num_edges = network->ne;
double *edge_coords = network->edge_coords;
for (unsigned int j = 0; j < num_edges; j++) {
diff --git a/src/current_scaling.c b/src/current_scaling.c
index 6837f6b..f750cb1 100644
--- a/src/current_scaling.c
+++ b/src/current_scaling.c
@@ -87,15 +87,15 @@ int main(int argc, char *argv[]) {
(&c)->supernodal = CHOLMOD_SIMPLICIAL;
}
- fnet *network = ini_square_network(width, false, true, &c);
- finst *perm_instance =
+ graph_t *network = ini_square_network(width, false, true, &c);
+ net_t *perm_instance =
create_instance(network, inf, voltage_bound, false, &c);
gen_crack(perm_instance, crack_len, 1, &c);
finish_instance(perm_instance, &c);
if (voltage_bound) {
(&c)->supernodal = CHOLMOD_SIMPLICIAL;
- finst *tmp_instance = create_instance(network, inf, false, false, &c);
+ net_t *tmp_instance = create_instance(network, inf, false, false, &c);
gen_crack(tmp_instance, crack_len, 1, &c);
finish_instance(tmp_instance, &c);
double *voltage = get_voltage(tmp_instance, &c);
@@ -113,14 +113,14 @@ int main(int argc, char *argv[]) {
if (supplied_bound) {
FILE *bound_f = fopen(bound_file, "r");
- for (int i = 0; i < network->num_verts; i++) {
+ for (int i = 0; i < network->nv; i++) {
double tmp;
fscanf(bound_f, "%lg ", &tmp);
((double *)perm_instance->boundary_cond->x)[i] = tmp;
}
- ((double *)perm_instance->boundary_cond->x)[network->num_verts] = 0;
- ((double *)perm_instance->boundary_cond->x)[network->num_verts + 1] = 0;
+ ((double *)perm_instance->boundary_cond->x)[network->nv] = 0;
+ ((double *)perm_instance->boundary_cond->x)[network->nv + 1] = 0;
fclose(bound_f);
}
@@ -134,25 +134,25 @@ int main(int argc, char *argv[]) {
double *damage;
if (save_damage) {
- damage = (double *)calloc(network->num_edges, sizeof(double));
+ damage = (double *)calloc(network->ne, sizeof(double));
}
- double *avg_current = (double *)calloc(network->num_edges, sizeof(double));
+ double *avg_current = (double *)calloc(network->ne, sizeof(double));
unsigned int *num_current_skipped =
- (unsigned int *)calloc(network->num_edges, sizeof(unsigned int));
- double *avg_voltage = (double *)calloc(network->num_verts, sizeof(double));
+ (unsigned int *)calloc(network->ne, sizeof(unsigned int));
+ double *avg_voltage = (double *)calloc(network->nv, sizeof(double));
unsigned int *num_voltage_skipped =
- (unsigned int *)calloc(network->num_verts, sizeof(unsigned int));
+ (unsigned int *)calloc(network->nv, sizeof(unsigned int));
for (int DUMB = 0; DUMB < num; DUMB++) {
printf("\033[F\033[JCURRENT_SCALING: ITERATION %0*d: %0*d / %d\n",
(int)log10(iter) + 1, DUMB2 + 1, (int)log10(num) + 1, DUMB + 1,
num);
- break_data *breaking_data = NULL;
+ data_t *breaking_data = NULL;
while (breaking_data == NULL) {
double *fuse_thres = gen_fuse_thres(
- network->num_edges, network->edge_coords, beta, beta_scaling_flat);
- finst *instance = copy_instance(perm_instance, &c);
+ network->ne, network->edge_coords, beta, beta_scaling_flat);
+ net_t *instance = copy_instance(perm_instance, &c);
breaking_data = fracture_network(instance, fuse_thres, &c, cutoff);
free_instance(instance, &c);
free(fuse_thres);
@@ -173,7 +173,7 @@ int main(int argc, char *argv[]) {
strength[DUMB] = fabs(breaking_data->extern_field[min_pos]);
}
- finst *tmp_instance = copy_instance(perm_instance, &c);
+ net_t *tmp_instance = copy_instance(perm_instance, &c);
unsigned int until = min_pos;
if (use_first)
@@ -188,14 +188,14 @@ int main(int argc, char *argv[]) {
double *voltage = get_voltage(tmp_instance, &c);
double *current = get_current(tmp_instance, &c);
- for (unsigned int i = 0; i < network->num_edges; i++) {
+ for (unsigned int i = 0; i < network->ne; i++) {
avg_current[i] += current[i];
if (current[i] == 0)
num_current_skipped[i]++;
}
- for (unsigned int i = 0; i < network->num_verts; i++) {
- if (tmp_instance->marks[i] == tmp_instance->marks[network->num_verts]) {
+ for (unsigned int i = 0; i < network->nv; i++) {
+ if (tmp_instance->marks[i] == tmp_instance->marks[network->nv]) {
avg_voltage[i] += voltage[i];
} else {
num_voltage_skipped[i]++;
@@ -210,13 +210,13 @@ int main(int argc, char *argv[]) {
free(breaking_data);
}
- for (int i = 0; i < network->num_edges; i++) {
+ for (int i = 0; i < network->ne; i++) {
if (num_current_skipped[i] < num) {
avg_current[i] /= num - num_current_skipped[i];
}
}
- for (int i = 0; i < network->num_verts; i++) {
+ for (int i = 0; i < network->nv; i++) {
if (num_voltage_skipped[i] < num) {
avg_voltage[i] /= num - num_voltage_skipped[i];
}
@@ -235,7 +235,7 @@ int main(int argc, char *argv[]) {
snprintf(c_filename, 100, "current_%d_%g_%d_%g.txt", width, crack_len,
iter, beta);
FILE *outfile = fopen(c_filename, "w");
- for (int i = 0; i < network->num_edges; i++) {
+ for (int i = 0; i < network->ne; i++) {
fprintf(outfile, "%g ", avg_current[i]);
}
fclose(outfile);
@@ -247,7 +247,7 @@ int main(int argc, char *argv[]) {
snprintf(c_filename, 100, "damage_%d_%g_%d_%g.txt", width, crack_len,
iter, beta);
FILE *outfile = fopen(c_filename, "w");
- for (int i = 0; i < network->num_edges; i++) {
+ for (int i = 0; i < network->ne; i++) {
fprintf(outfile, "%g ", damage[i]);
}
fclose(outfile);
@@ -270,7 +270,7 @@ int main(int argc, char *argv[]) {
snprintf(b_filename, 100, "bounds_%d_%g_%d_%g.txt", width, crack_len,
iter, beta);
FILE *outfile = fopen(b_filename, "w");
- for (int i = 0; i < network->num_verts; i++) {
+ for (int i = 0; i < network->nv; i++) {
fprintf(outfile, "%g ", ((double *)perm_instance->boundary_cond->x)[i]);
}
fclose(outfile);
@@ -292,7 +292,7 @@ int main(int argc, char *argv[]) {
}
free_instance(perm_instance, &c);
- free_fnet(network, &c);
+ free_net(network, &c);
CHOL_F(finish)(&c);
diff --git a/src/fracture.c b/src/fracture.c
index 6798231..23bce03 100644
--- a/src/fracture.c
+++ b/src/fracture.c
@@ -151,7 +151,7 @@ int main(int argc, char *argv[]) {
(&c)->supernodal = CHOLMOD_SIMPLICIAL;
}
- fnet *network;
+ graph_t *network;
finst *perm_instance;
unsigned int c_dist_size;
unsigned int a_dist_size;
@@ -175,8 +175,8 @@ int main(int argc, char *argv[]) {
perm_instance = create_instance(network, inf, voltage_bound, false, &c);
gen_crack(perm_instance, crack_len, crack_width, &c);
finish_instance(perm_instance, &c);
- c_dist_size = network->num_dual_verts;
- a_dist_size = network->num_verts;
+ c_dist_size = network->dnv;
+ a_dist_size = network->nv;
}
// define arrays for saving cluster and avalanche distributions
@@ -279,7 +279,7 @@ int main(int argc, char *argv[]) {
printf("\033[F\033[JFRACTURE: %0*d / %d\n", (int)log10(num) + 1, DUMB + 1,
num);
- break_data *breaking_data = NULL;
+ data_t *breaking_data = NULL;
while (breaking_data == NULL) {
if (voronoi && !repeat_voronoi) {
while ((network = ini_voronoi_network(width, periodic,
@@ -293,7 +293,7 @@ int main(int argc, char *argv[]) {
}
}
double *fuse_thres = gen_fuse_thres(
- network->num_edges, network->edge_coords, beta, beta_scaling_flat);
+ network->ne, network->edge_coords, beta, beta_scaling_flat);
finst *instance = copy_instance(perm_instance, &c);
breaking_data = fracture_network(instance, fuse_thres, &c, cutoff);
free_instance(instance, &c);
@@ -350,19 +350,19 @@ int main(int argc, char *argv[]) {
if (save_cond) {
double *tmp_voltage = get_voltage(tmp_instance, &c);
- conductivity[DUMB] = fabs(tmp_voltage[tmp_instance->network->num_verts + 1] - tmp_voltage[tmp_instance->network->num_verts]);
+ conductivity[DUMB] = fabs(tmp_voltage[tmp_instance->graph->nv + 1] - tmp_voltage[tmp_instance->graph->nv]);
free(tmp_voltage);
}
if (save_homo_damage) {
- homo_damage[DUMB] = ((double)min_pos) / tmp_instance->network->num_edges;
+ homo_damage[DUMB] = ((double)min_pos) / tmp_instance->graph->ne;
}
if (save_avg_stress || save_avg_ztress) {
double *tmp_stress = get_current(tmp_instance, &c);
if (voronoi) {
double *tmp_stress_2 =
- bin_values(tmp_instance->network, width, tmp_stress);
+ bin_values(tmp_instance->graph, width, tmp_stress);
free(tmp_stress);
tmp_stress = tmp_stress_2;
}
@@ -380,12 +380,12 @@ int main(int argc, char *argv[]) {
}
if (save_damage) {
- double *tmp_damage = (double *)calloc(tmp_instance->network->num_edges, sizeof(double));
+ double *tmp_damage = (double *)calloc(tmp_instance->graph->ne, sizeof(double));
for (unsigned int i = 0; i < stop_at; i++) {
tmp_damage[breaking_data->break_list[i]] += 1;
}
if (voronoi) {
- double *tmp_damage_2 = bin_values(tmp_instance->network, width, tmp_damage);
+ double *tmp_damage_2 = bin_values(tmp_instance->graph, width, tmp_damage);
free(tmp_damage);
tmp_damage = tmp_damage_2;
}
@@ -397,7 +397,7 @@ int main(int argc, char *argv[]) {
if (save_clusters) {
unsigned int *tmp_cluster_dist = get_cluster_dist(tmp_instance, &c);
- for (unsigned int i = 0; i < network->num_dual_verts; i++) {
+ for (unsigned int i = 0; i < network->dnv; i++) {
cluster_size_dist[i] += tmp_cluster_dist[i];
}
free(tmp_cluster_dist);
@@ -405,7 +405,7 @@ int main(int argc, char *argv[]) {
if (save_corr) {
double *tmp_corr = get_corr(tmp_instance, dists, &c);
- for (unsigned int i = 0; i < tmp_instance->network->num_dual_verts; i++) {
+ for (unsigned int i = 0; i < tmp_instance->graph->dnv; i++) {
avg_corr[i] += tmp_corr[i] / num;
}
free(tmp_corr);
@@ -413,27 +413,27 @@ int main(int argc, char *argv[]) {
if (network_out) {
FILE *net_out = fopen("network.txt", "w");
- for (unsigned int i = 0; i < network->num_verts; i++) {
+ for (unsigned int i = 0; i < network->nv; i++) {
fprintf(net_out, "%f %f ", network->vert_coords[2 * i],
network->vert_coords[2 * i + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int i = 0; i < network->num_edges; i++) {
- fprintf(net_out, "%u %u ", network->edges_to_verts[2 * i],
- network->edges_to_verts[2 * i + 1]);
+ for (unsigned int i = 0; i < network->ne; i++) {
+ fprintf(net_out, "%u %u ", network->ev[2 * i],
+ network->ev[2 * i + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int i = 0; i < network->num_dual_verts; i++) {
+ for (unsigned int i = 0; i < network->dnv; i++) {
fprintf(net_out, "%f %f ", network->dual_vert_coords[2 * i],
network->dual_vert_coords[2 * i + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int i = 0; i < network->num_edges; i++) {
- fprintf(net_out, "%u %u ", network->dual_edges_to_verts[2 * i],
- network->dual_edges_to_verts[2 * i + 1]);
+ for (unsigned int i = 0; i < network->ne; i++) {
+ fprintf(net_out, "%u %u ", network->dev[2 * i],
+ network->dev[2 * i + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int i = 0; i < network->num_edges; i++) {
+ for (unsigned int i = 0; i < network->ne; i++) {
fprintf(net_out, "%d ", tmp_instance->fuses[i]);
}
fclose(net_out);
@@ -441,7 +441,7 @@ int main(int argc, char *argv[]) {
free_instance(tmp_instance, &c);
if (voronoi && !repeat_voronoi) {
- free_fnet(network, &c);
+ free_net(network, &c);
free_instance(perm_instance, &c);
}
if (include_breaking) {
@@ -510,7 +510,7 @@ int main(int argc, char *argv[]) {
if (!voronoi || repeat_voronoi) {
free_instance(perm_instance, &c);
- //free_fnet(network, &c);
+ //free_net(network, &c);
}
if (include_breaking) {
diff --git a/src/fracture.h b/src/fracture.h
index 93e2ed1..349e59e 100644
--- a/src/fracture.h
+++ b/src/fracture.h
@@ -37,33 +37,33 @@ typedef enum bound_t {
} bound_t;
typedef struct {
- unsigned int num_edges;
- unsigned int num_verts;
- unsigned int num_verts_break;
- unsigned int num_bounds;
- unsigned int *edges_to_verts;
- unsigned int *edges_to_verts_break;
- unsigned int *verts_to_edges_ind;
- unsigned int *verts_to_edges;
- unsigned int *bound_inds;
- unsigned int *bound_verts;
+ uint_t ne;
+ uint_t nv;
+ uint_t dnv;
+ uint_t nv_break;
+ uint_t num_bounds;
+ uint_t *ev;
+ uint_t *ev_break;
+ uint_t *vei;
+ uint_t *ve;
+ uint_t *bound_inds;
+ uint_t *bound_verts;
double *vert_coords;
double *edge_coords;
- unsigned int *dual_edges_to_verts;
- unsigned int *dual_verts_to_edges_ind;
- unsigned int *dual_verts_to_edges;
+ uint_t *dev;
+ uint_t *dvei;
+ uint_t *dve;
double *dual_vert_coords;
- unsigned int num_spanning_edges;
- unsigned int *spanning_edges;
+ uint_t num_spanning_edges;
+ uint_t *spanning_edges;
double L;
- unsigned int num_dual_verts;
- unsigned int break_dim;
+ uint_t break_dim;
cholmod_sparse *voltcurmat;
bound_t boundary;
-} fnet;
+} graph_t;
typedef struct {
- fnet *network;
+ graph_t *graph;
unsigned int num_remaining_edges;
bool *fuses;
double inf;
@@ -75,14 +75,14 @@ typedef struct {
unsigned int num_components;
cholmod_sparse *adjacency;
bool debug_stop;
-} finst;
+} net_t;
typedef struct {
unsigned int num_broken;
unsigned int *break_list;
double *conductivity;
double *extern_field;
-} break_data;
+} data_t;
intptr_t *run_voronoi(unsigned int num_coords, double *coords, bool periodic, double xmin, double xmax, double ymin, double ymax);
@@ -91,10 +91,10 @@ int update_components(const cholmod_sparse *laplacian, unsigned int *marks,
unsigned int *find_components(const cholmod_sparse *laplacian, unsigned int skip);
-cholmod_sparse *gen_adjacency(const finst *instance, bool dual, bool breakv,
+cholmod_sparse *gen_adjacency(const net_t *instance, bool dual, bool breakv,
unsigned int pad, cholmod_common *c);
-cholmod_sparse *gen_laplacian(const finst *instance, cholmod_common *c,
+cholmod_sparse *gen_laplacian(const net_t *instance, cholmod_common *c,
bool symmetric);
int edge_to_verts(unsigned int width, bool periodic, unsigned int edge,
@@ -109,20 +109,20 @@ double dual_vert_to_coord(unsigned int width, bool periodic, unsigned int vert,
bool update_factor(cholmod_factor *factor, unsigned int v1, unsigned int v2,
cholmod_common *c);
-break_data *fracture_network(finst *instance, double *fuse_thres,
+data_t *fracture_network(net_t *instance, double *fuse_thres,
cholmod_common *c, double cutoff);
-double *get_current(const finst *instance, cholmod_common *c);
-double *get_current_v(const finst *instance, double *voltages, cholmod_common *c);
-double *get_voltage(const finst *instance, cholmod_common *c);
+double *get_current(const net_t *instance, cholmod_common *c);
+double *get_current_v(const net_t *instance, double *voltages, cholmod_common *c);
+double *get_voltage(const net_t *instance, cholmod_common *c);
double *gen_fuse_thres(unsigned int num_edges, double *edge_coords, double beta,
double (*beta_scale)(double, double, double));
-bool gen_crack(finst *instance, double crack_len, double crack_width,
+bool gen_crack(net_t *instance, double crack_len, double crack_width,
cholmod_common *c);
-void update_boundary(finst *instance, const double *avg_field);
+void update_boundary(net_t *instance, const double *avg_field);
FILE *get_file(const char *prefix, unsigned int width, unsigned int crack,
double beta, unsigned int iter, unsigned int num_iter,
@@ -134,32 +134,32 @@ double update_beta(double beta, unsigned int width, const double *stress,
cholmod_sparse *gen_voltcurmat(unsigned int num_edges, unsigned int num_verts,
unsigned int *edges_to_verts, cholmod_common *c);
-finst *copy_instance(const finst *instance, cholmod_common *c);
+net_t *copy_instance(const net_t *instance, cholmod_common *c);
-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);
-void free_fnet(fnet *network, cholmod_common *c);
-void free_instance(finst *instance, cholmod_common *c);
+void free_net(graph_t *network, cholmod_common *c);
+void free_instance(net_t *instance, cholmod_common *c);
-finst *create_instance(fnet *network, double inf, bool voltage_bound,
+net_t *create_instance(graph_t *network, double inf, bool voltage_bound,
bool startnow, cholmod_common *c);
-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);
-bool check_instance(const finst *instance, cholmod_common *c);
+bool check_instance(const net_t *instance, cholmod_common *c);
-bool break_edge(finst *instance, unsigned int edge, cholmod_common *c);
+bool break_edge(net_t *instance, unsigned int edge, cholmod_common *c);
-void finish_instance(finst *instance, cholmod_common *c);
+void finish_instance(net_t *instance, cholmod_common *c);
-finst *coursegrain_square(finst *instance, fnet *network_p, cholmod_common *c);
+net_t *coursegrain_square(net_t *instance, graph_t *network_p, cholmod_common *c);
-unsigned int *get_clusters(finst *instance, cholmod_common *c);
+unsigned int *get_clusters(net_t *instance, cholmod_common *c);
-unsigned int *get_cluster_dist(finst *instance, cholmod_common *c);
+unsigned int *get_cluster_dist(net_t *instance, cholmod_common *c);
double *genfunc_uniform(unsigned int L, bound_t boundary, gsl_rng *r, unsigned int *num);
double *genfunc_hyperuniform(unsigned int L, bound_t boundary, gsl_rng *r, unsigned int *num);
@@ -169,18 +169,18 @@ double beta_scaling_flat(double beta, double x, double y);
double beta_scaling_gaus(double beta, double x, double y);
double beta_mag(double beta);
-unsigned int *dijkstra(fnet *network, unsigned int source);
-unsigned int **get_dists(fnet *network);
-double *get_corr(finst *instance, unsigned int **dists, cholmod_common *c);
+unsigned int *dijkstra(graph_t *network, unsigned int source);
+unsigned int **get_dists(graph_t *network);
+double *get_corr(net_t *instance, unsigned int **dists, cholmod_common *c);
-double *bin_values(fnet *network, unsigned int width, double *values);
+double *bin_values(graph_t *network, unsigned int width, double *values);
-void voronoi_bound_ini(finst *instance, uint_t L, double crack_len);
+void voronoi_bound_ini(net_t *instance, uint_t L, double crack_len);
-break_data *alloc_break_data(unsigned int num_edges);
-void free_break_data(break_data *data);
-void update_break_data(break_data *data, unsigned int last_broke, double strength, double conductivity);
+data_t *alloc_break_data(unsigned int num_edges);
+void free_break_data(data_t *data);
+void update_break_data(data_t *data, unsigned int last_broke, double strength, double conductivity);
-double get_conductivity(finst *inst, double *current, cholmod_common *c);
+double get_conductivity(net_t *inst, double *current, cholmod_common *c);
-void gen_voro_crack(finst *instance, double crack_len, cholmod_common *c);
+void gen_voro_crack(net_t *instance, double crack_len, cholmod_common *c);
diff --git a/src/fracture_network.c b/src/fracture_network.c
index 3f06104..428b092 100644
--- a/src/fracture_network.c
+++ b/src/fracture_network.c
@@ -1,9 +1,9 @@
#include "fracture.h"
-int inc_break_fuses(finst *instance, double *thres, double *field,
+int inc_break_fuses(net_t *instance, double *thres, double *field,
double cutoff) {
- unsigned int size = (instance->network)->num_edges;
+ unsigned int size = (instance->graph)->ne;
int min_pos = -1;
long double min_val = -1;
@@ -20,12 +20,12 @@ int inc_break_fuses(finst *instance, double *thres, double *field,
return min_pos;
}
-break_data *fracture_network(finst *instance, double *fuse_thres,
+data_t *fracture_network(net_t *instance, double *fuse_thres,
cholmod_common *c, double cutoff) {
- unsigned int num_edges = instance->network->num_edges;
- unsigned int num_verts = instance->network->num_verts;
+ unsigned int num_edges = instance->graph->ne;
+ unsigned int num_verts = instance->graph->nv;
- break_data *breaking_data = alloc_break_data(num_edges);
+ data_t *breaking_data = alloc_break_data(num_edges);
while (true) {
double *voltages = get_voltage(instance, c);
@@ -53,11 +53,11 @@ break_data *fracture_network(finst *instance, double *fuse_thres,
break_edge(instance, last_broke, c);
- if (instance->num_components > 1 && instance->network->boundary == TORUS_BOUND) {
+ if (instance->num_components > 1 && instance->graph->boundary == TORUS_BOUND) {
break;
}
- if (instance->marks[num_verts] != instance->marks[num_verts + 1] && instance->network->boundary != TORUS_BOUND) {
+ if (instance->marks[num_verts] != instance->marks[num_verts + 1] && instance->graph->boundary != TORUS_BOUND) {
break;
}
}
diff --git a/src/free_network.c b/src/free_network.c
index 651d3ae..5fd3290 100644
--- a/src/free_network.c
+++ b/src/free_network.c
@@ -1,21 +1,21 @@
#include "fracture.h"
-void free_fnet(fnet *network, cholmod_common *c) {
- free(network->edges_to_verts);
- if (network->edges_to_verts_break != network->edges_to_verts) {
- free(network->edges_to_verts_break);
+void free_net(graph_t *network, cholmod_common *c) {
+ free(network->ev);
+ if (network->ev_break != network->ev) {
+ free(network->ev_break);
}
- free(network->verts_to_edges_ind);
- free(network->verts_to_edges);
+ free(network->vei);
+ free(network->ve);
free(network->bound_inds);
free(network->bound_verts);
free(network->vert_coords);
free(network->edge_coords);
- free(network->dual_edges_to_verts);
+ free(network->dev);
free(network->dual_vert_coords);
- free(network->dual_verts_to_edges_ind);
- free(network->dual_verts_to_edges);
+ free(network->dvei);
+ free(network->dve);
free(network->spanning_edges);
CHOL_F(free_sparse)(&(network->voltcurmat), c);
free(network);
diff --git a/src/gen_laplacian.c b/src/gen_laplacian.c
index 97a2c9d..6034a82 100644
--- a/src/gen_laplacian.c
+++ b/src/gen_laplacian.c
@@ -1,15 +1,15 @@
#include "fracture.h"
-cholmod_sparse *gen_adjacency(const finst *instance, bool dual, bool breakv,
+cholmod_sparse *gen_adjacency(const net_t *instance, bool dual, bool breakv,
unsigned int pad, cholmod_common *c) {
unsigned int ne;
if (dual)
- ne = ((int)instance->network->num_edges);
+ ne = ((int)instance->graph->ne);
else {
ne = instance->num_remaining_edges;
- if (!breakv && instance->network->boundary != TORUS_BOUND) {
- ne += instance->network->bound_inds[2];
+ if (!breakv && instance->graph->boundary != TORUS_BOUND) {
+ ne += instance->graph->bound_inds[2];
}
}
@@ -17,11 +17,11 @@ cholmod_sparse *gen_adjacency(const finst *instance, bool dual, bool breakv,
unsigned int nv;
if (dual)
- nv = instance->network->num_dual_verts;
+ nv = instance->graph->dnv;
else {
- if (breakv) nv = instance->network->num_verts_break;
- else nv = instance->network->num_verts;
- if (instance->network->boundary != TORUS_BOUND && !breakv) {
+ if (breakv) nv = instance->graph->nv_break;
+ else nv = instance->graph->nv;
+ if (instance->graph->boundary != TORUS_BOUND && !breakv) {
nv += 2;
}
}
@@ -36,15 +36,15 @@ cholmod_sparse *gen_adjacency(const finst *instance, bool dual, bool breakv,
unsigned int *etv;
if (dual)
- etv = instance->network->dual_edges_to_verts;
+ etv = instance->graph->dev;
else {
- if (breakv) etv = instance->network->edges_to_verts_break;
- else etv = instance->network->edges_to_verts;
+ if (breakv) etv = instance->graph->ev_break;
+ else etv = instance->graph->ev;
}
unsigned int count = 0;
- for (unsigned int i = 0; i < instance->network->num_edges; i++) {
+ for (unsigned int i = 0; i < instance->graph->ne; i++) {
if ((instance->fuses[i] && dual) || (!instance->fuses[i] && !dual)) {
unsigned int v1 = etv[2 * i];
unsigned int v2 = etv[2 * i + 1];
@@ -74,14 +74,14 @@ cholmod_sparse *gen_adjacency(const finst *instance, bool dual, bool breakv,
}
}
- if (!breakv && instance->network->boundary != TORUS_BOUND && !dual) {
+ if (!breakv && instance->graph->boundary != TORUS_BOUND && !dual) {
for (unsigned int i = 0; i < 2; i++) {
- for (unsigned int j = 0; j < instance->network->bound_inds[i+1] - instance->network->bound_inds[i]; j++) {
- ri[2*count] = instance->network->num_verts + i;
- ci[2*count] = instance->network->bound_verts[instance->network->bound_inds[i] + j];
+ for (unsigned int j = 0; j < instance->graph->bound_inds[i+1] - instance->graph->bound_inds[i]; j++) {
+ ri[2*count] = instance->graph->nv + i;
+ ci[2*count] = instance->graph->bound_verts[instance->graph->bound_inds[i] + j];
ai[2*count] = 1;
- ri[2*count+1] = instance->network->bound_verts[instance->network->bound_inds[i] + j];
- ci[2*count+1] = instance->network->num_verts + i;
+ ri[2*count+1] = instance->graph->bound_verts[instance->graph->bound_inds[i] + j];
+ ci[2*count+1] = instance->graph->nv + i;
ai[2*count+1] = 1;
count++;
}
@@ -95,10 +95,10 @@ cholmod_sparse *gen_adjacency(const finst *instance, bool dual, bool breakv,
return s;
}
-cholmod_sparse *gen_laplacian(const finst *instance, cholmod_common *c,
+cholmod_sparse *gen_laplacian(const net_t *instance, cholmod_common *c,
bool symmetric) {
- const fnet *network = instance->network;
- unsigned int num_verts = network->num_verts_break;
+ const graph_t *network = instance->graph;
+ unsigned int num_verts = network->nv_break;
double *vert_coords = network->vert_coords;
unsigned int num_bounds = network->num_bounds;
double inf = instance->inf;
@@ -147,13 +147,13 @@ cholmod_sparse *gen_laplacian(const finst *instance, cholmod_common *c,
for (unsigned int i = 0; i < network->bound_inds[1]; i++) {
unsigned int vv = network->bound_verts[i];
rowind[num_gverts + 2*i] = vv;
- colind[num_gverts + 2*i] = network->num_verts + i;
+ colind[num_gverts + 2*i] = network->nv + i;
acoo[num_gverts + 2*i] = -1;
- rowind[num_gverts + 2*i+1] = network->num_verts + i;
+ rowind[num_gverts + 2*i+1] = network->nv + i;
colind[num_gverts + 2*i+1] = vv;
acoo[num_gverts + 2*i+1] = -1;
acoo[vv]++;
- acoo[network->num_verts + i]++;
+ acoo[network->nv + i]++;
}
acoo[bound_verts[0]]++;
}
diff --git a/src/get_conductivity.c b/src/get_conductivity.c
index 7ef08a8..793987e 100644
--- a/src/get_conductivity.c
+++ b/src/get_conductivity.c
@@ -1,16 +1,16 @@
#include "fracture.h"
-double get_conductivity(finst *inst, double *voltage, cholmod_common *c) {
+double get_conductivity(net_t *inst, double *voltage, cholmod_common *c) {
if (inst->voltage_bound) {
double tot_cur = 0;
- for (unsigned int i = 0; i < inst->network->num_spanning_edges; i++) {
- unsigned int e = inst->network->spanning_edges[i];
+ for (unsigned int i = 0; i < inst->graph->num_spanning_edges; i++) {
+ unsigned int e = inst->graph->spanning_edges[i];
if (!inst->fuses[e]) {
- unsigned int v1 = inst->network->edges_to_verts[2*e];
- unsigned int v2 = inst->network->edges_to_verts[2*e+1];
- double v1y = inst->network->vert_coords[2 * v1 + 1];
- double v2y = inst->network->vert_coords[2 * v2 + 1];
+ unsigned int v1 = inst->graph->ev[2*e];
+ unsigned int v2 = inst->graph->ev[2*e+1];
+ double v1y = inst->graph->vert_coords[2 * v1 + 1];
+ double v2y = inst->graph->vert_coords[2 * v2 + 1];
unsigned int s1 = v1y < v2y ? v1 : v2;
unsigned int s2 = v1y < v2y ? v2 : v1;
tot_cur += voltage[s1] - voltage[s2];
@@ -19,6 +19,6 @@ double get_conductivity(finst *inst, double *voltage, cholmod_common *c) {
return fabs(tot_cur);
} else {
- return 1 / fabs(voltage[inst->network->num_verts] - voltage[inst->network->num_verts + 1]);
+ return 1 / fabs(voltage[inst->graph->nv] - voltage[inst->graph->nv + 1]);
}
}
diff --git a/src/get_current.c b/src/get_current.c
index 5360054..bc786f9 100644
--- a/src/get_current.c
+++ b/src/get_current.c
@@ -1,7 +1,7 @@
#include "fracture.h"
-double *get_voltage(const finst *instance, cholmod_common *c) {
+double *get_voltage(const net_t *instance, cholmod_common *c) {
cholmod_dense *b = instance->boundary_cond;
cholmod_factor *factor = instance->factor;
@@ -22,12 +22,12 @@ double *get_voltage(const finst *instance, cholmod_common *c) {
return field;
}
-double *get_current(const finst *instance, cholmod_common *c) {
- unsigned int num_edges = instance->network->num_edges;
- unsigned int num_verts = instance->network->num_verts_break;
- unsigned int num_gverts = instance->network->break_dim;
- unsigned int num_bounds = instance->network->num_bounds;
- cholmod_sparse *voltcurmat = instance->network->voltcurmat;
+double *get_current(const net_t *instance, cholmod_common *c) {
+ unsigned int num_edges = instance->graph->ne;
+ unsigned int num_verts = instance->graph->nv_break;
+ unsigned int num_gverts = instance->graph->break_dim;
+ unsigned int num_bounds = instance->graph->num_bounds;
+ cholmod_sparse *voltcurmat = instance->graph->voltcurmat;
double *voltages = get_voltage(instance, c);
if (voltages == NULL) {
@@ -63,12 +63,12 @@ double *get_current(const finst *instance, cholmod_common *c) {
}
-double *get_current_v(const finst *instance, double *voltages, cholmod_common *c) {
- unsigned int num_edges = instance->network->num_edges;
- unsigned int num_verts = instance->network->num_verts_break;
- unsigned int num_gverts = instance->network->break_dim;
- unsigned int num_bounds = instance->network->num_bounds;
- cholmod_sparse *voltcurmat = instance->network->voltcurmat;
+double *get_current_v(const net_t *instance, double *voltages, cholmod_common *c) {
+ unsigned int num_edges = instance->graph->ne;
+ unsigned int num_verts = instance->graph->nv_break;
+ unsigned int num_gverts = instance->graph->break_dim;
+ unsigned int num_bounds = instance->graph->num_bounds;
+ cholmod_sparse *voltcurmat = instance->graph->voltcurmat;
cholmod_dense *x = CHOL_F(allocate_dense)(
num_gverts, 1, num_gverts, CHOLMOD_REAL, c);
diff --git a/src/get_dual_clusters.c b/src/get_dual_clusters.c
index 488793f..3a51c38 100644
--- a/src/get_dual_clusters.c
+++ b/src/get_dual_clusters.c
@@ -1,7 +1,7 @@
#include "fracture.h"
-unsigned int *get_clusters(finst *instance, cholmod_common *c) {
+unsigned int *get_clusters(net_t *instance, cholmod_common *c) {
cholmod_sparse *s_dual = gen_adjacency(instance, true, false, 0, c);
unsigned int *dual_marks = find_components(s_dual, 0);
@@ -10,16 +10,16 @@ unsigned int *get_clusters(finst *instance, cholmod_common *c) {
return dual_marks;
}
-unsigned int *get_cluster_dist(finst *instance, cholmod_common *c) {
+unsigned int *get_cluster_dist(net_t *instance, cholmod_common *c) {
unsigned int *clusters = get_clusters(instance, c);
unsigned int *cluster_dist = (unsigned int *)calloc(
- instance->network->num_dual_verts, sizeof(unsigned int));
+ instance->graph->dnv, sizeof(unsigned int));
unsigned int cur_mark = 0;
while (true) {
cur_mark++;
unsigned int num_in_cluster = 0;
- for (unsigned int i = 0; i < instance->network->num_dual_verts; i++) {
+ for (unsigned int i = 0; i < instance->graph->dnv; i++) {
if (clusters[i] == cur_mark)
num_in_cluster++;
}
diff --git a/src/homo_square_fracture.c b/src/homo_square_fracture.c
index 9103317..e3e8ad3 100644
--- a/src/homo_square_fracture.c
+++ b/src/homo_square_fracture.c
@@ -126,10 +126,10 @@ int main(int argc, char *argv[]) {
}
- fnet *network = ini_square_network(L, boundary, false, &c);
- finst *perm_instance = create_instance(network, inf, use_voltage_boundaries, true, &c);
- unsigned int c_dist_size = network->num_dual_verts;
- unsigned int a_dist_size = network->num_verts;
+ graph_t *network = ini_square_network(L, boundary, false, &c);
+ net_t *perm_instance = create_instance(network, inf, use_voltage_boundaries, true, &c);
+ unsigned int c_dist_size = network->dnv;
+ unsigned int a_dist_size = network->nv;
// define arrays for saving cluster and avalanche distributions
unsigned int *cluster_size_dist;
@@ -193,9 +193,9 @@ int main(int argc, char *argv[]) {
for (unsigned int i = 0; i < N; i++) {
printf("\033[F\033[JFRACTURE: %0*d / %d\n", (int)log10(N) + 1, i + 1, N);
- double *fuse_thres = gen_fuse_thres(network->num_edges, network->edge_coords, beta, beta_scaling_flat);
- finst *instance = copy_instance(perm_instance, &c);
- break_data *breaking_data = fracture_network(instance, fuse_thres, &c, cutoff);
+ double *fuse_thres = gen_fuse_thres(network->ne, network->edge_coords, beta, beta_scaling_flat);
+ net_t *instance = copy_instance(perm_instance, &c);
+ data_t *breaking_data = fracture_network(instance, fuse_thres, &c, cutoff);
free_instance(instance, &c);
free(fuse_thres);
@@ -216,7 +216,7 @@ int main(int argc, char *argv[]) {
breaking_data->extern_field[max_pos];
}
- finst *tmp_instance = copy_instance(perm_instance, &c);
+ net_t *tmp_instance = copy_instance(perm_instance, &c);
unsigned int av_size = 0;
double cur_val = DBL_MAX;
@@ -240,7 +240,7 @@ int main(int argc, char *argv[]) {
if (save_conductivity) {
if (!use_voltage_boundaries) {
double *tmp_voltage = get_voltage(tmp_instance, &c);
- conductivity[i] = 1/fabs(tmp_voltage[tmp_instance->network->num_verts + 1] - tmp_voltage[tmp_instance->network->num_verts]);
+ conductivity[i] = 1/fabs(tmp_voltage[tmp_instance->graph->nv + 1] - tmp_voltage[tmp_instance->graph->nv]);
free(tmp_voltage);
} else {
conductivity[i] = breaking_data->conductivity[max_pos];
@@ -265,12 +265,12 @@ int main(int argc, char *argv[]) {
}
if (save_damage) {
- damage[i] = ((double)max_pos) / tmp_instance->network->num_edges;
+ damage[i] = ((double)max_pos) / tmp_instance->graph->ne;
}
if (save_cluster_dist) {
unsigned int *tmp_cluster_dist = get_cluster_dist(tmp_instance, &c);
- for (unsigned int j = 0; j < tmp_instance->network->num_dual_verts; j++) {
+ for (unsigned int j = 0; j < tmp_instance->graph->dnv; j++) {
cluster_size_dist[j] += tmp_cluster_dist[j];
}
free(tmp_cluster_dist);
@@ -278,7 +278,7 @@ int main(int argc, char *argv[]) {
if (save_corr) {
double *tmp_corr = get_corr(tmp_instance, dists, &c);
- for (unsigned int j = 0; j < tmp_instance->network->num_dual_verts; j++) {
+ for (unsigned int j = 0; j < tmp_instance->graph->dnv; j++) {
avg_corr[i] += tmp_corr[j] / N;
}
free(tmp_corr);
@@ -286,27 +286,27 @@ int main(int argc, char *argv[]) {
if (save_network) {
FILE *net_out = fopen("network.txt", "w");
- for (unsigned int j = 0; j < network->num_verts; j++) {
+ for (unsigned int j = 0; j < network->nv; j++) {
fprintf(net_out, "%f %f ", network->vert_coords[2 * j],
- tmp_instance->network->vert_coords[2 * j + 1]);
+ tmp_instance->graph->vert_coords[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < tmp_instance->network->num_edges; j++) {
- fprintf(net_out, "%u %u ", tmp_instance->network->edges_to_verts[2 * j],
- tmp_instance->network->edges_to_verts[2 * j + 1]);
+ for (unsigned int j = 0; j < tmp_instance->graph->ne; j++) {
+ fprintf(net_out, "%u %u ", tmp_instance->graph->ev[2 * j],
+ tmp_instance->graph->ev[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < tmp_instance->network->num_dual_verts; j++) {
- fprintf(net_out, "%f %f ", tmp_instance->network->dual_vert_coords[2 * j],
- tmp_instance->network->dual_vert_coords[2 * j + 1]);
+ for (unsigned int j = 0; j < tmp_instance->graph->dnv; j++) {
+ fprintf(net_out, "%f %f ", tmp_instance->graph->dual_vert_coords[2 * j],
+ tmp_instance->graph->dual_vert_coords[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < tmp_instance->network->num_edges; j++) {
- fprintf(net_out, "%u %u ", tmp_instance->network->dual_edges_to_verts[2 * j],
- tmp_instance->network->dual_edges_to_verts[2 * j + 1]);
+ for (unsigned int j = 0; j < tmp_instance->graph->ne; j++) {
+ fprintf(net_out, "%u %u ", tmp_instance->graph->dev[2 * j],
+ tmp_instance->graph->dev[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < tmp_instance->network->num_edges; j++) {
+ for (unsigned int j = 0; j < tmp_instance->graph->ne; j++) {
fprintf(net_out, "%d ", tmp_instance->fuses[j]);
}
fclose(net_out);
@@ -328,7 +328,7 @@ int main(int argc, char *argv[]) {
printf("\033[F\033[JFRACTURE: COMPLETE\n");
free_instance(perm_instance, &c);
- free_fnet(network, &c);
+ free_net(network, &c);
if (save_cluster_dist) {
FILE *cluster_out = fopen(c_filename, "w");
diff --git a/src/homo_voronoi_fracture.c b/src/homo_voronoi_fracture.c
index 26ceed4..6171480 100644
--- a/src/homo_voronoi_fracture.c
+++ b/src/homo_voronoi_fracture.c
@@ -211,11 +211,11 @@ int main(int argc, char *argv[]) {
for (uint32_t i = 0; i < N; i++) {
printf("\033[F\033[JFRACTURE: %0*d / %d\n", (uint8_t)log10(N) + 1, i + 1, N);
- fnet *network = ini_voronoi_network(L, boundary, use_dual, genfunc_hyperuniform, &c);
- finst *perm_instance = create_instance(network, inf, use_voltage_boundaries, true, &c);
- double *fuse_thres = gen_fuse_thres(network->num_edges, network->edge_coords, beta, beta_scaling_flat);
- finst *instance = copy_instance(perm_instance, &c);
- break_data *breaking_data = fracture_network(instance, fuse_thres, &c, cutoff);
+ graph_t *network = ini_voronoi_network(L, boundary, use_dual, genfunc_hyperuniform, &c);
+ net_t *perm_instance = create_instance(network, inf, use_voltage_boundaries, true, &c);
+ double *fuse_thres = gen_fuse_thres(network->ne, network->edge_coords, beta, beta_scaling_flat);
+ net_t *instance = copy_instance(perm_instance, &c);
+ data_t *breaking_data = fracture_network(instance, fuse_thres, &c, cutoff);
free_instance(instance, &c);
free(fuse_thres);
@@ -236,7 +236,7 @@ int main(int argc, char *argv[]) {
breaking_data->extern_field[max_pos];
}
- finst *tmp_instance = copy_instance(perm_instance, &c);
+ net_t *tmp_instance = copy_instance(perm_instance, &c);
uint_t av_size = 0;
double cur_val = 0;
@@ -260,7 +260,7 @@ int main(int argc, char *argv[]) {
if (save_conductivity) {
if (!use_voltage_boundaries) {
double *tmp_voltage = get_voltage(tmp_instance, &c);
- conductivity[i] = 1/fabs(tmp_voltage[tmp_instance->network->num_verts + 1] - tmp_voltage[tmp_instance->network->num_verts]);
+ conductivity[i] = 1/fabs(tmp_voltage[tmp_instance->graph->nv + 1] - tmp_voltage[tmp_instance->graph->nv]);
free(tmp_voltage);
} else {
conductivity[i] = breaking_data->conductivity[max_pos];
@@ -290,7 +290,7 @@ int main(int argc, char *argv[]) {
if (save_cluster_dist) {
uint_t *tmp_cluster_dist = get_cluster_dist(tmp_instance, &c);
- for (uint_t j = 0; j < tmp_instance->network->num_dual_verts; j++) {
+ for (uint_t j = 0; j < tmp_instance->graph->dnv; j++) {
cluster_size_dist[j] += tmp_cluster_dist[j];
}
free(tmp_cluster_dist);
@@ -298,27 +298,27 @@ int main(int argc, char *argv[]) {
if (save_network) {
FILE *net_out = fopen("network.txt", "w");
- for (uint_t j = 0; j < network->num_verts; j++) {
+ for (uint_t j = 0; j < network->nv; j++) {
fprintf(net_out, "%f %f ", network->vert_coords[2 * j],
- tmp_instance->network->vert_coords[2 * j + 1]);
+ tmp_instance->graph->vert_coords[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (uint_t j = 0; j < tmp_instance->network->num_edges; j++) {
- fprintf(net_out, "%u %u ", tmp_instance->network->edges_to_verts[2 * j],
- tmp_instance->network->edges_to_verts[2 * j + 1]);
+ for (uint_t j = 0; j < tmp_instance->graph->ne; j++) {
+ fprintf(net_out, "%u %u ", tmp_instance->graph->ev[2 * j],
+ tmp_instance->graph->ev[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (uint_t j = 0; j < tmp_instance->network->num_dual_verts; j++) {
- fprintf(net_out, "%f %f ", tmp_instance->network->dual_vert_coords[2 * j],
- tmp_instance->network->dual_vert_coords[2 * j + 1]);
+ for (uint_t j = 0; j < tmp_instance->graph->dnv; j++) {
+ fprintf(net_out, "%f %f ", tmp_instance->graph->dual_vert_coords[2 * j],
+ tmp_instance->graph->dual_vert_coords[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (uint_t j = 0; j < tmp_instance->network->num_edges; j++) {
- fprintf(net_out, "%u %u ", tmp_instance->network->dual_edges_to_verts[2 * j],
- tmp_instance->network->dual_edges_to_verts[2 * j + 1]);
+ for (uint_t j = 0; j < tmp_instance->graph->ne; j++) {
+ fprintf(net_out, "%u %u ", tmp_instance->graph->dev[2 * j],
+ tmp_instance->graph->dev[2 * j + 1]);
}
fprintf(net_out, "\n");
- for (uint_t j = 0; j < tmp_instance->network->num_edges; j++) {
+ for (uint_t j = 0; j < tmp_instance->graph->ne; j++) {
fprintf(net_out, "%d ", tmp_instance->fuses[j]);
}
fclose(net_out);
@@ -326,7 +326,7 @@ int main(int argc, char *argv[]) {
free_instance(tmp_instance, &c);
free_instance(perm_instance, &c);
- free_fnet(network, &c);
+ free_net(network, &c);
if (include_breaking) {
for (uint_t j = 0; j < breaking_data->num_broken; j++) {
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;
}
diff --git a/src/instance.c b/src/instance.c
index cc33591..bb1ac8c 100644
--- a/src/instance.c
+++ b/src/instance.c
@@ -1,14 +1,14 @@
#include "fracture.h"
-finst *create_instance(fnet *network, double inf, bool voltage_bound,
+net_t *create_instance(graph_t *network, double inf, bool voltage_bound,
bool startnow, cholmod_common *c) {
- finst *instance = (finst *)calloc(1, sizeof(finst));
+ net_t *instance = (net_t *)calloc(1, sizeof(net_t));
assert(instance != NULL);
- instance->network = network;
- instance->num_remaining_edges = network->num_edges;
- instance->fuses = (bool *)calloc(network->num_edges, sizeof(bool));
+ instance->graph = network;
+ instance->num_remaining_edges = network->ne;
+ instance->fuses = (bool *)calloc(network->ne, sizeof(bool));
assert(instance->fuses != NULL);
instance->inf = inf;
instance->voltage_bound = voltage_bound;
@@ -17,7 +17,7 @@ finst *create_instance(fnet *network, double inf, bool voltage_bound,
if (network->boundary == TORUS_BOUND) {
for (unsigned int i = 0; i < network->bound_inds[1]; i++) {
((double *)instance->boundary_cond->x)[network->bound_verts[i]] = 1;
- ((double *)instance->boundary_cond->x)[network->num_verts + i] = -1;
+ ((double *)instance->boundary_cond->x)[network->nv + i] = -1;
}
((double *)instance->boundary_cond->x)[network->bound_verts[0]] = 1;
} else if (network->boundary == EMBEDDED_BOUND) {
@@ -32,8 +32,8 @@ finst *create_instance(fnet *network, double inf, bool voltage_bound,
}
} else {
((double *)instance->boundary_cond->x)[0] = 1;
- ((double *)instance->boundary_cond->x)[network->num_verts] = 1;
- ((double *)instance->boundary_cond->x)[network->num_verts + 1] = -1;
+ ((double *)instance->boundary_cond->x)[network->nv] = 1;
+ ((double *)instance->boundary_cond->x)[network->nv + 1] = -1;
}
}
@@ -48,20 +48,20 @@ finst *create_instance(fnet *network, double inf, bool voltage_bound,
}
instance->marks = (unsigned int *)malloc(
- (instance->network->break_dim) *
+ (instance->graph->break_dim) *
sizeof(unsigned int));
instance->dual_marks = (unsigned int *)malloc(
- (instance->network->num_dual_verts) *
+ (instance->graph->dnv) *
sizeof(unsigned int));
assert(instance->marks != NULL);
for (unsigned int i = 0;
- i < (instance->network->break_dim);
+ i < (instance->graph->break_dim);
i++) {
instance->marks[i] = 1;
}
for (unsigned int i = 0;
- i < (instance->network->num_dual_verts);
+ i < (instance->graph->dnv);
i++) {
instance->dual_marks[i] = i+1;
}
@@ -70,29 +70,29 @@ finst *create_instance(fnet *network, double inf, bool voltage_bound,
return instance;
}
-void finish_instance(finst *instance, cholmod_common *c) {
+void finish_instance(net_t *instance, cholmod_common *c) {
cholmod_sparse *laplacian = gen_laplacian(instance, c, true);
instance->factor = CHOL_F(analyze)(laplacian, c);
CHOL_F(factorize)(laplacian, instance->factor, c);
CHOL_F(free_sparse)(&laplacian, c);
}
-finst *copy_instance(const finst *instance, cholmod_common *c) {
- finst *instance_copy = (finst *)calloc(1, sizeof(finst));
- memcpy(instance_copy, instance, sizeof(finst));
+net_t *copy_instance(const net_t *instance, cholmod_common *c) {
+ net_t *instance_copy = (net_t *)calloc(1, sizeof(net_t));
+ memcpy(instance_copy, instance, sizeof(net_t));
- size_t fuses_size = (instance->network)->num_edges * sizeof(bool);
+ size_t fuses_size = (instance->graph)->ne * sizeof(bool);
instance_copy->fuses = (bool *)malloc(fuses_size);
memcpy(instance_copy->fuses, instance->fuses, fuses_size);
size_t marks_size =
- (instance->network->break_dim) *
+ (instance->graph->break_dim) *
sizeof(unsigned int);
instance_copy->marks = (unsigned int *)malloc(marks_size);
memcpy(instance_copy->marks, instance->marks, marks_size);
size_t dual_marks_size =
- (instance->network->num_dual_verts) *
+ (instance->graph->dnv) *
sizeof(unsigned int);
instance_copy->dual_marks = (unsigned int *)malloc(dual_marks_size);
memcpy(instance_copy->dual_marks, instance->dual_marks, dual_marks_size);
@@ -104,7 +104,7 @@ finst *copy_instance(const finst *instance, cholmod_common *c) {
return instance_copy;
}
-void free_instance(finst *instance, cholmod_common *c) {
+void free_instance(net_t *instance, cholmod_common *c) {
free(instance->fuses);
CHOL_F(free_dense)(&(instance->boundary_cond), c);
CHOL_F(free_sparse)(&(instance->adjacency), c);
@@ -114,7 +114,7 @@ void free_instance(finst *instance, cholmod_common *c) {
free(instance);
}
-bool check_instance(const finst *instance, cholmod_common *c) {
+bool check_instance(const net_t *instance, cholmod_common *c) {
assert(instance != NULL);
assert(instance->fuses != NULL);
assert(CHOL_F(check_dense)(instance->boundary_cond, c));
diff --git a/src/update_boundary.c b/src/update_boundary.c
index 3d2a086..6bc4fca 100644
--- a/src/update_boundary.c
+++ b/src/update_boundary.c
@@ -1,10 +1,10 @@
#include "fracture.h"
-void update_boundary(finst *instance, const double *avg_field) {
- int size = instance->network->num_edges;
+void update_boundary(net_t *instance, const double *avg_field) {
+ int size = instance->graph->ne;
int width = sqrt(size);
- int num_verts = instance->network->num_verts;
+ int num_verts = instance->graph->nv;
double *boundary = (double *)instance->boundary_cond->x;
boundary[num_verts] = 0;
diff --git a/src/voronoi_bound_ini.c b/src/voronoi_bound_ini.c
index d201093..0b65ef5 100644
--- a/src/voronoi_bound_ini.c
+++ b/src/voronoi_bound_ini.c
@@ -15,7 +15,7 @@ double u_y(double x, double y) {
return sqrt(r) * sin(th / 2);
}
-void voronoi_bound_ini(finst *instance, uint_t L, double crack_len) {
+void voronoi_bound_ini(net_t *instance, uint_t L, double crack_len) {
double *bound = (double *)instance->boundary_cond->x;
for (uint_t i = 0; i < L / 2; i++) {
double x1, y1, x2, y2, x3, y3, x4, y4;