summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/break_edge.c8
-rw-r--r--src/compare_voronoi_fracture.c4
-rw-r--r--src/fortune/main.c69
-rw-r--r--src/fracture.h29
-rw-r--r--src/gen_laplacian.c12
-rw-r--r--src/gen_voltcurmat.c4
-rw-r--r--src/graph_components.c6
-rw-r--r--src/homo_square_fracture.c2
-rw-r--r--src/homo_voronoi_fracture.c113
-rw-r--r--src/ini_network.c26
-rw-r--r--src/randfuncs.c26
-rw-r--r--src/update_factor.c10
12 files changed, 165 insertions, 144 deletions
diff --git a/src/break_edge.c b/src/break_edge.c
index 7082b76..0ba1ad7 100644
--- a/src/break_edge.c
+++ b/src/break_edge.c
@@ -17,8 +17,8 @@ bool break_edge(finst *instance, unsigned int edge, cholmod_common *c) {
unsigned int tw1 = w1 > w2 ? w1 : w2;
unsigned int tw2 = w1 > w2 ? w2 : w1;
- CHOL_INT *lap_p = (CHOL_INT *)instance->adjacency->p;
- CHOL_INT *lap_i = (CHOL_INT *)instance->adjacency->i;
+ int_t *lap_p = (int_t *)instance->adjacency->p;
+ int_t *lap_i = (int_t *)instance->adjacency->i;
double *lap_x = (double *)instance->adjacency->x;
for (int i = 0; i < lap_p[tw1 + 1] - lap_p[tw1]; i++) {
@@ -81,8 +81,8 @@ bool break_edge(finst *instance, unsigned int edge, cholmod_common *c) {
unsigned int tw1 = dw1 > dw2 ? dw1 : dw2;
unsigned int tw2 = dw1 > dw2 ? dw2 : dw1;
- CHOL_INT *lap_p = (CHOL_INT *)instance->adjacency->p;
- CHOL_INT *lap_i = (CHOL_INT *)instance->adjacency->i;
+ int_t *lap_p = (int_t *)instance->adjacency->p;
+ int_t *lap_i = (int_t *)instance->adjacency->i;
double *lap_x = (double *)instance->adjacency->x;
for (int i = 0; i < lap_p[tw1 + 1] - lap_p[tw1]; i++) {
diff --git a/src/compare_voronoi_fracture.c b/src/compare_voronoi_fracture.c
index 5578987..bdb9423 100644
--- a/src/compare_voronoi_fracture.c
+++ b/src/compare_voronoi_fracture.c
@@ -8,7 +8,7 @@ int main(int argc, char *argv[]) {
// defining variables to be (potentially) set by command line flags
unsigned int N, L, filename_len;
double beta, inf, cutoff;
- boundary_type boundary;
+ bound_t boundary;
filename_len = 100;
@@ -66,7 +66,7 @@ int main(int argc, char *argv[]) {
(&c)->supernodal = CHOLMOD_SIMPLICIAL;
- fnet *network = ini_voronoi_network(L, boundary, genfunc_hyperuniform, &c);
+ 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);
diff --git a/src/fortune/main.c b/src/fortune/main.c
index 7571945..543f6e4 100644
--- a/src/fortune/main.c
+++ b/src/fortune/main.c
@@ -77,7 +77,7 @@ unsigned int delete_duplicates(unsigned int ne, unsigned int *etv) {
return newsize;
}
-intptr_t *run_voronoi(unsigned int num, double *lattice, double xmin, double xmax, double ymin, double ymax)
+intptr_t *run_voronoi(unsigned int num, double *lattice, bool periodic, double xmin, double xmax, double ymin, double ymax)
{
struct Site *(*next)();
@@ -91,45 +91,50 @@ intptr_t *run_voronoi(unsigned int num, double *lattice, double xmin, double xma
freeinit(&sfl, sizeof *sites);
- unsigned int eff_num = 9 * num;
- double *eff_lattice = (double *)malloc(2 * eff_num * sizeof(double));
+ unsigned int eff_num = num;
+ double *eff_lattice = lattice;
- for (unsigned int i = 0; i < num; i++) {
- // original sites - our baby boys
- eff_lattice[2*i] = lattice[2*i];
- eff_lattice[2*i+1] = lattice[2*i+1];
+ if (periodic) {
+ unsigned int eff_num = 9 * num;
+ double *eff_lattice = (double *)malloc(2 * eff_num * sizeof(double));
- // sites to the right
- eff_lattice[2*(num+i)+1] = lattice[2*i+1] - xmin + xmax;
- eff_lattice[2*(num+i)] = lattice[2*i];
+ for (unsigned int i = 0; i < num; i++) {
+ // original sites - our baby boys
+ eff_lattice[2*i] = lattice[2*i];
+ eff_lattice[2*i+1] = lattice[2*i+1];
- // sites to the left
- eff_lattice[2*(2*num+i)+1] = lattice[2*i+1] - xmax + xmin;
- eff_lattice[2*(2*num+i)] = lattice[2*i];
+ // sites to the right
+ eff_lattice[2*(num+i)+1] = lattice[2*i+1] - xmin + xmax;
+ eff_lattice[2*(num+i)] = lattice[2*i];
- // sites to the top
- eff_lattice[2*(3*num+i)+1] = lattice[2*i+1];
- eff_lattice[2*(3*num+i)] = lattice[2*i] - ymin + ymax;
+ // sites to the left
+ eff_lattice[2*(2*num+i)+1] = lattice[2*i+1] - xmax + xmin;
+ eff_lattice[2*(2*num+i)] = lattice[2*i];
- // sites to the bottom
- eff_lattice[2*(4*num+i)+1] = lattice[2*i+1];
- eff_lattice[2*(4*num+i)] = lattice[2*i] - ymax + ymin;
+ // sites to the top
+ eff_lattice[2*(3*num+i)+1] = lattice[2*i+1];
+ eff_lattice[2*(3*num+i)] = lattice[2*i] - ymin + ymax;
- // sites to the upper right
- eff_lattice[2*(5*num+i)+1] = lattice[2*i+1] - xmin + xmax;
- eff_lattice[2*(5*num+i)] = lattice[2*i] - ymin + ymax;
+ // sites to the bottom
+ eff_lattice[2*(4*num+i)+1] = lattice[2*i+1];
+ eff_lattice[2*(4*num+i)] = lattice[2*i] - ymax + ymin;
- // sites to the upper left
- eff_lattice[2*(6*num+i)+1] = lattice[2*i+1] - xmax + xmin;
- eff_lattice[2*(6*num+i)] = lattice[2*i] - ymin + ymax;
+ // sites to the upper right
+ eff_lattice[2*(5*num+i)+1] = lattice[2*i+1] - xmin + xmax;
+ eff_lattice[2*(5*num+i)] = lattice[2*i] - ymin + ymax;
- // sites to the lower left
- eff_lattice[2*(7*num+i)+1] = lattice[2*i+1] - xmax + xmin;
- eff_lattice[2*(7*num+i)] = lattice[2*i] + ymin - ymax;
+ // sites to the upper left
+ eff_lattice[2*(6*num+i)+1] = lattice[2*i+1] - xmax + xmin;
+ eff_lattice[2*(6*num+i)] = lattice[2*i] - ymin + ymax;
- // sites to the lower right
- eff_lattice[2*(8*num+i)+1] = lattice[2*i+1] + xmax - xmin;
- eff_lattice[2*(8*num+i)] = lattice[2*i] + ymin - ymax;
+ // sites to the lower left
+ eff_lattice[2*(7*num+i)+1] = lattice[2*i+1] - xmax + xmin;
+ eff_lattice[2*(7*num+i)] = lattice[2*i] + ymin - ymax;
+
+ // sites to the lower right
+ eff_lattice[2*(8*num+i)+1] = lattice[2*i+1] + xmax - xmin;
+ eff_lattice[2*(8*num+i)] = lattice[2*i] + ymin - ymax;
+ }
}
nsites = eff_num;
@@ -160,7 +165,7 @@ intptr_t *run_voronoi(unsigned int num, double *lattice, double xmin, double xma
unsigned int *real_edge_list = edge_list;
unsigned int *real_dual_list = dual_list;
- {
+ if (periodic) {
real_vert_count = 0;
real_edge_count = 0;
real_dual_count = 0;
diff --git a/src/fracture.h b/src/fracture.h
index fea0caf..91b2bfc 100644
--- a/src/fracture.h
+++ b/src/fracture.h
@@ -23,15 +23,18 @@
#include <sys/types.h>
#include <unistd.h>
-// these two defs allow me to switch to long int cholmod in a sitch
-#define CHOL_INT long int
-#define CHOL_F(x) cholmod_l_##x
+// these defs allow me to switch to long int cholmod in a sitch
+#define int_t int
+#define uint_t unsigned int
+#define CINT_MAX INT_MAX
+#define CHOL_F(x) cholmod_##x
-typedef enum boundary_type {
+typedef enum bound_t {
FREE_BOUND,
CYLINDER_BOUND,
- TORUS_BOUND
-} boundary_type;
+ TORUS_BOUND,
+ EMBEDDED_BOUND
+} bound_t;
typedef struct {
unsigned int num_edges;
@@ -56,7 +59,7 @@ typedef struct {
unsigned int num_dual_verts;
unsigned int break_dim;
cholmod_sparse *voltcurmat;
- boundary_type boundary;
+ bound_t boundary;
} fnet;
typedef struct {
@@ -81,7 +84,7 @@ typedef struct {
double *extern_field;
} break_data;
-intptr_t *run_voronoi(unsigned int num_coords, double *coords, double xmin, double xmax, double ymin, double ymax);
+intptr_t *run_voronoi(unsigned int num_coords, double *coords, bool periodic, double xmin, double xmax, double ymin, double ymax);
int update_components(const cholmod_sparse *laplacian, unsigned int *marks,
int old_num_components, int v1, int v2, int exclude);
@@ -133,7 +136,7 @@ cholmod_sparse *gen_voltcurmat(unsigned int num_edges, unsigned int num_verts,
finst *copy_instance(const finst *instance, cholmod_common *c);
-fnet *ini_square_network(unsigned int width, boundary_type boundary, bool side_bounds,
+fnet *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds,
cholmod_common *c);
void free_fnet(fnet *network, cholmod_common *c);
@@ -142,8 +145,8 @@ void free_instance(finst *instance, cholmod_common *c);
finst *create_instance(fnet *network, double inf, bool voltage_bound,
bool startnow, cholmod_common *c);
-fnet *ini_voronoi_network(unsigned int L, boundary_type boundary, bool use_dual,
- double *(*genfunc)(unsigned int, gsl_rng *, unsigned int *),
+fnet *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);
@@ -158,8 +161,8 @@ unsigned int *get_clusters(finst *instance, cholmod_common *c);
unsigned int *get_cluster_dist(finst *instance, cholmod_common *c);
-double *genfunc_uniform(unsigned int L, gsl_rng *r, unsigned int *num);
-double *genfunc_hyperuniform(unsigned int L, gsl_rng *r, unsigned int *num);
+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);
void randfunc_flat(gsl_rng *r, double *x, double *y);
void randfunc_gaus(gsl_rng *r, double *x, double *y);
double beta_scaling_flat(double beta, double x, double y);
diff --git a/src/gen_laplacian.c b/src/gen_laplacian.c
index a282564..d8f0c6d 100644
--- a/src/gen_laplacian.c
+++ b/src/gen_laplacian.c
@@ -28,8 +28,8 @@ cholmod_sparse *gen_adjacency(const finst *instance, bool dual, bool breakv,
cholmod_triplet *t =
CHOL_F(allocate_triplet)(nv + pad, nv + pad, nnz, 0, CHOLMOD_REAL, c);
- CHOL_INT *ri = (CHOL_INT *)t->i;
- CHOL_INT *ci = (CHOL_INT *)t->j;
+ int_t *ri = (int_t *)t->i;
+ int_t *ci = (int_t *)t->j;
double *ai = (double *)t->x;
t->nnz = nnz;
@@ -120,8 +120,8 @@ cholmod_sparse *gen_laplacian(const finst *instance, cholmod_common *c,
cholmod_triplet *temp_m =
CHOL_F(allocate_triplet)(num_gverts, num_gverts, nnz, 0, CHOLMOD_REAL, c);
- CHOL_INT *rowind = (CHOL_INT *)temp_m->i;
- CHOL_INT *colind = (CHOL_INT *)temp_m->j;
+ int_t *rowind = (int_t *)temp_m->i;
+ int_t *colind = (int_t *)temp_m->j;
double *acoo = (double *)temp_m->x;
temp_m->nnz = nnz;
@@ -133,8 +133,8 @@ cholmod_sparse *gen_laplacian(const finst *instance, cholmod_common *c,
}
cholmod_sparse *adjacency = gen_adjacency(instance, false, true, (int)num_gverts - (int)num_verts, c);
- CHOL_INT *ia = (CHOL_INT *)adjacency->p;
- CHOL_INT *ja = (CHOL_INT *)adjacency->i;
+ int_t *ia = (int_t *)adjacency->p;
+ int_t *ja = (int_t *)adjacency->i;
double *aa = (double *)adjacency->x;
for (unsigned int i = 0; i < num_verts; i++) {
diff --git a/src/gen_voltcurmat.c b/src/gen_voltcurmat.c
index ab16150..e870140 100644
--- a/src/gen_voltcurmat.c
+++ b/src/gen_voltcurmat.c
@@ -9,8 +9,8 @@ cholmod_sparse *gen_voltcurmat(unsigned int num_edges, unsigned int num_verts,
num_edges, num_verts, num_edges * 2, 0, CHOLMOD_REAL, c);
assert(t_m != NULL);
- CHOL_INT *rowind = (CHOL_INT *)t_m->i;
- CHOL_INT *colind = (CHOL_INT *)t_m->j;
+ int_t *rowind = (int_t *)t_m->i;
+ int_t *colind = (int_t *)t_m->j;
double *acoo = (double *)t_m->x;
for (unsigned int i = 0; i < num_edges; i++) {
diff --git a/src/graph_components.c b/src/graph_components.c
index 036f2fe..c4e894d 100644
--- a/src/graph_components.c
+++ b/src/graph_components.c
@@ -3,10 +3,10 @@
bool set_connected(const cholmod_sparse *laplacian, unsigned int *marks,
int vertex, int label, int stop_at, int exclude) {
- unsigned int num_verts = (CHOL_INT)laplacian->nrow;
+ unsigned int num_verts = (int_t)laplacian->nrow;
- CHOL_INT *ia = (CHOL_INT *)laplacian->p;
- CHOL_INT *ja = (CHOL_INT *)laplacian->i;
+ int_t *ia = (int_t *)laplacian->p;
+ int_t *ja = (int_t *)laplacian->i;
double *a = (double *)laplacian->x;
bool stopped = false;
diff --git a/src/homo_square_fracture.c b/src/homo_square_fracture.c
index a0dd305..9103317 100644
--- a/src/homo_square_fracture.c
+++ b/src/homo_square_fracture.c
@@ -8,7 +8,7 @@ int main(int argc, char *argv[]) {
// defining variables to be (potentially) set by command line flags
unsigned int N, L, filename_len;
double beta, inf, cutoff;
- boundary_type boundary;
+ bound_t boundary;
bool include_breaking, save_cluster_dist, use_voltage_boundaries, save_network,
save_crit_stress, save_toughness, save_corr, save_conductivity,
save_damage;
diff --git a/src/homo_voronoi_fracture.c b/src/homo_voronoi_fracture.c
index 4e2d67a..65a25f8 100644
--- a/src/homo_voronoi_fracture.c
+++ b/src/homo_voronoi_fracture.c
@@ -6,12 +6,14 @@ int main(int argc, char *argv[]) {
int opt;
// defining variables to be (potentially) set by command line flags
- unsigned int N, L, filename_len;
+ uint8_t filename_len;
+ uint64_t N;
+ uint_t L;
double beta, inf, cutoff;
- boundary_type boundary;
bool include_breaking, save_cluster_dist, use_voltage_boundaries, use_dual, save_network,
- save_crit_stress, save_toughness, save_corr, save_conductivity,
+ save_crit_stress, save_toughness, save_conductivity,
save_damage;
+ bound_t boundary;
filename_len = 100;
@@ -28,11 +30,10 @@ int main(int argc, char *argv[]) {
save_network = false;
save_crit_stress = false;
save_damage = false;
- save_corr = false;
save_conductivity = false;
save_toughness = false;
- int boundary_int;
+ uint8_t bound_i;
char boundc2 = 'f';
while ((opt = getopt(argc, argv, "n:L:b:B:dVcoNsCrtD")) != -1) {
@@ -47,8 +48,8 @@ int main(int argc, char *argv[]) {
beta = atof(optarg);
break;
case 'B':
- boundary_int = atoi(optarg);
- switch (boundary_int) {
+ bound_i = atoi(optarg);
+ switch (bound_i) {
case 0:
boundary = FREE_BOUND;
boundc2 = 'f';
@@ -64,6 +65,7 @@ int main(int argc, char *argv[]) {
break;
default:
printf("boundary specifier must be 0 (FREE_BOUND), 1 (CYLINDER_BOUND), or 2 (TORUS_BOUND).\n");
+ exit(EXIT_FAILURE);
}
break;
case 'd':
@@ -87,9 +89,6 @@ int main(int argc, char *argv[]) {
case 's':
save_crit_stress = true;
break;
- case 'C':
- save_corr = true;
- break;
case 'r':
save_conductivity = true;
//inf = 1;
@@ -114,20 +113,26 @@ int main(int argc, char *argv[]) {
free(break_filename);
}
- unsigned int voronoi_max_verts = 4 * pow(L, 2);
- unsigned int c_dist_size = voronoi_max_verts;
- unsigned int a_dist_size = voronoi_max_verts;
+ uint_t voronoi_max_verts, c_dist_size, a_dist_size;
+
+ voronoi_max_verts = 4 * pow(L, 2);
+ c_dist_size = voronoi_max_verts;
+ a_dist_size = voronoi_max_verts;
+
+ if (voronoi_max_verts > CINT_MAX) {
+ exit(EXIT_FAILURE);
+ }
// define arrays for saving cluster and avalanche distributions
- unsigned int *cluster_size_dist;
- unsigned int *avalanche_size_dist;
+ uint64_t *cluster_size_dist;
+ uint64_t *avalanche_size_dist;
char *c_filename;
char *a_filename;
if (save_cluster_dist) {
cluster_size_dist =
- (unsigned int *)malloc(c_dist_size * sizeof(unsigned int));
+ (uint64_t *)malloc(c_dist_size * sizeof(uint64_t));
avalanche_size_dist =
- (unsigned int *)malloc(a_dist_size * sizeof(unsigned int));
+ (uint64_t *)malloc(a_dist_size * sizeof(uint64_t));
c_filename = (char *)malloc(filename_len * sizeof(char));
a_filename = (char *)malloc(filename_len * sizeof(char));
@@ -138,11 +143,11 @@ int main(int argc, char *argv[]) {
FILE *avalanche_out = fopen(a_filename, "rb");
if (cluster_out != NULL) {
- fread(cluster_size_dist, sizeof(unsigned int), c_dist_size, cluster_out);
+ fread(cluster_size_dist, sizeof(uint64_t), c_dist_size, cluster_out);
fclose(cluster_out);
}
if (avalanche_out != NULL) {
- fread(avalanche_size_dist, sizeof(unsigned int), a_dist_size, avalanche_out);
+ fread(avalanche_size_dist, sizeof(uint64_t), a_dist_size, avalanche_out);
fclose(avalanche_out);
}
}
@@ -152,23 +157,17 @@ int main(int argc, char *argv[]) {
crit_stress = (double *)malloc(N * sizeof(double));
}
- double *avg_corr;
- unsigned int **dists = NULL;
- if (save_corr) {
- avg_corr = (double *)calloc(voronoi_max_verts, sizeof(double));
- }
-
double *conductivity;
if (save_conductivity) {
conductivity = (double *)malloc(N * sizeof(double));
}
// define arrays for saving damage distributions
- unsigned int *damage;
+ uint64_t *damage;
char *d_filename;
if (save_damage) {
damage =
- (unsigned int *)malloc(a_dist_size * sizeof(unsigned int));
+ (uint64_t *)malloc(a_dist_size * sizeof(uint64_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);
@@ -176,7 +175,7 @@ int main(int argc, char *argv[]) {
FILE *damage_out = fopen(d_filename, "rb");
if (damage_out != NULL) {
- fread(damage, sizeof(unsigned int), a_dist_size, damage_out);
+ fread(damage, sizeof(uint64_t), a_dist_size, damage_out);
fclose(damage_out);
}
}
@@ -204,22 +203,21 @@ int main(int argc, char *argv[]) {
printf("\n");
- for (unsigned int i = 0; i < N; i++) {
- printf("\033[F\033[JFRACTURE: %0*d / %d\n", (int)log10(N) + 1, i + 1, N);
+ for (uint64_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);
- bool debug_stop = instance->debug_stop;
free_instance(instance, &c);
free(fuse_thres);
- unsigned int max_pos = 0;
+ uint_t max_pos = 0;
double max_val = 0;
- for (unsigned int j = 0; j < breaking_data->num_broken; j++) {
+ for (uint_t j = 0; j < breaking_data->num_broken; j++) {
double val = breaking_data->extern_field[j];
if (val > max_val) {
@@ -235,9 +233,9 @@ int main(int argc, char *argv[]) {
finst *tmp_instance = copy_instance(perm_instance, &c);
- unsigned int av_size = 0;
+ uint_t av_size = 0;
double cur_val = 0;
- for (unsigned int j = 0; j < max_pos; j++) {
+ for (uint_t j = 0; j < max_pos; j++) {
break_edge(tmp_instance, breaking_data->break_list[j], &c);
double val = breaking_data->extern_field[j];
@@ -269,7 +267,7 @@ int main(int argc, char *argv[]) {
if (max_pos > 0) {
double sigma1 = breaking_data->extern_field[0];
double epsilon1 = sigma1 / breaking_data->conductivity[0];
- for (unsigned int j = 0; j < max_pos - 1; j++) {
+ for (uint_t j = 0; j < max_pos - 1; j++) {
double sigma2 = breaking_data->extern_field[j+1];
double epsilon2 = sigma2 / breaking_data->conductivity[j+1];
if (epsilon2 > epsilon1) {
@@ -286,44 +284,36 @@ int main(int argc, char *argv[]) {
}
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++) {
+ uint_t *tmp_cluster_dist = get_cluster_dist(tmp_instance, &c);
+ for (uint_t j = 0; j < tmp_instance->network->num_dual_verts; j++) {
cluster_size_dist[j] += tmp_cluster_dist[j];
}
free(tmp_cluster_dist);
}
- 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++) {
- avg_corr[i] += tmp_corr[j] / N;
- }
- free(tmp_corr);
- }
-
if (save_network) {
FILE *net_out = fopen("network.txt", "w");
- for (unsigned int j = 0; j < network->num_verts; j++) {
+ 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]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < tmp_instance->network->num_edges; j++) {
+ 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]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < tmp_instance->network->num_dual_verts; j++) {
+ 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]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < tmp_instance->network->num_edges; j++) {
+ 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]);
}
fprintf(net_out, "\n");
- for (unsigned int j = 0; j < tmp_instance->network->num_edges; j++) {
+ for (uint_t j = 0; j < tmp_instance->network->num_edges; j++) {
fprintf(net_out, "%d ", tmp_instance->fuses[j]);
}
fclose(net_out);
@@ -334,7 +324,7 @@ int main(int argc, char *argv[]) {
free_fnet(network, &c);
if (include_breaking) {
- for (unsigned int j = 0; j < breaking_data->num_broken; j++) {
+ for (uint_t j = 0; j < breaking_data->num_broken; j++) {
fprintf(break_out, "%u %g %g ", breaking_data->break_list[j],
breaking_data->extern_field[j], breaking_data->conductivity[j]);
}
@@ -350,8 +340,8 @@ int main(int argc, char *argv[]) {
FILE *cluster_out = fopen(c_filename, "wb");
FILE *avalanche_out = fopen(a_filename, "wb");
- fwrite(cluster_size_dist, sizeof(unsigned int), c_dist_size, cluster_out);
- fwrite(avalanche_size_dist, sizeof(unsigned int), a_dist_size, avalanche_out);
+ fwrite(cluster_size_dist, sizeof(uint64_t), c_dist_size, cluster_out);
+ fwrite(avalanche_size_dist, sizeof(uint64_t), a_dist_size, avalanche_out);
fclose(cluster_out);
fclose(avalanche_out);
@@ -362,19 +352,6 @@ int main(int argc, char *argv[]) {
free(avalanche_size_dist);
}
- if (save_corr) {
- char *corr_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(corr_filename, filename_len, "corr_v_%c_%c_%d_%g.txt", boundc, boundc2, L,
- beta);
- FILE *corr_file = fopen(corr_filename, "w");
- for (unsigned int i = 0; i < voronoi_max_verts; i++) {
- fprintf(corr_file, "%g ", avg_corr[i]);
- }
- fclose(corr_file);
- free(corr_filename);
- free(avg_corr);
- }
-
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);
@@ -397,7 +374,7 @@ int main(int argc, char *argv[]) {
if (save_damage) {
FILE *hdam_file = fopen(d_filename, "wb");
- fwrite(damage, sizeof(unsigned int), a_dist_size, hdam_file);
+ fwrite(damage, sizeof(uint64_t), a_dist_size, hdam_file);
fclose(hdam_file);
free(d_filename);
free(damage);
diff --git a/src/ini_network.c b/src/ini_network.c
index f1dbe70..edf1539 100644
--- a/src/ini_network.c
+++ b/src/ini_network.c
@@ -96,7 +96,7 @@ unsigned int *get_verts_to_edges(unsigned int num_verts, unsigned int num_edges,
return output;
}
-fnet *ini_square_network(unsigned int width, boundary_type boundary, bool side_bounds,
+fnet *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds,
cholmod_common *c) {
fnet *network = (fnet *)calloc(1, sizeof(fnet));
@@ -300,8 +300,8 @@ unsigned int *get_voro_dual_edges(unsigned int num_edges,
return dual_edges;
}
-fnet *ini_voronoi_network(unsigned int L, boundary_type boundary, bool use_dual,
- double *(*genfunc)(unsigned int, gsl_rng *, unsigned int *),
+fnet *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));
@@ -315,12 +315,15 @@ fnet *ini_voronoi_network(unsigned int L, boundary_type boundary, bool use_dual,
fread(&seed, sizeof(unsigned long int), 1, rf);
fclose(rf);
gsl_rng_set(r, seed);
- lattice = genfunc(L, r, &num);
+ lattice = genfunc(L, boundary, r, &num);
gsl_rng_free(r);
}
// retrieve a periodic voronoi tesselation of the lattice
- intptr_t *vout = run_voronoi(num, lattice, 0, 1, 0, 1);
+ bool run_periodic;
+ if (boundary == EMBEDDED_BOUND) run_periodic = false;
+ 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];
@@ -595,6 +598,19 @@ fnet *ini_voronoi_network(unsigned int L, boundary_type boundary, bool use_dual,
network->break_dim = num_verts;
break;
}
+ 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;
+ num_edges = tmp_num_edges;
+ num_verts = tmp_num_verts;
+ edges = tmp_edges;
+ dual_edges = tmp_dual_edges;
+ num_edges = tmp_num_edges;
+ vert_coords = tmp_vert_coords;
+ }
}
network->boundary = boundary;
diff --git a/src/randfuncs.c b/src/randfuncs.c
index 260c047..35b9f56 100644
--- a/src/randfuncs.c
+++ b/src/randfuncs.c
@@ -1,7 +1,7 @@
#include "fracture.h"
-double *genfunc_uniform(unsigned int L, gsl_rng *r, unsigned int *num) {
+double *genfunc_uniform(unsigned int L, bound_t boundary, gsl_rng *r, unsigned int *num) {
*num = pow(L / 2 + 1, 2) + pow((L + 1) / 2, 2);
double *lattice = (double *)malloc(2 * (*num) * sizeof(double));
@@ -13,7 +13,7 @@ double *genfunc_uniform(unsigned int L, gsl_rng *r, unsigned int *num) {
return lattice;
}
-double *genfunc_hyperuniform(unsigned int L, gsl_rng *r, unsigned int *num) {
+double *genfunc_hyperuniform(unsigned int L, bound_t boundary, gsl_rng *r, unsigned int *num) {
*num = pow(L / 2 + 1, 2) + pow((L + 1) / 2, 2);
// necessary to prevent crashing when underflow occurs
@@ -21,7 +21,27 @@ double *genfunc_hyperuniform(unsigned int L, gsl_rng *r, unsigned int *num) {
double *lattice = (double *)malloc(2 * (*num) * sizeof(double));
double rho = *num;
- for (unsigned int i = 0; i < (*num); i++) {
+ unsigned int to_gen = *num;
+
+ if (boundary == EMBEDDED_BOUND) {
+ for (unsigned int i = 0; i < L / 2; i++) {
+ lattice[2 * i] = 0;
+ lattice[2 * i + 1] = (2. * i + 1.) / L;
+
+ lattice[L / 2 + 2 * i] = 1;
+ lattice[L / 2 + 2 * i + 1] = (2. * i + 1.) / L;
+
+ lattice[L + 2 * i] = (2. * i + 1.) / L;
+ lattice[L + 2 * i + 1] = 0;
+
+ lattice[3 * L / 2 + 2 * i] = (2. * i + 1.) / L;
+ lattice[3 * L / 2 + 2 * i + 1] = 1;
+ }
+
+ to_gen -= 2 * L;
+ }
+
+ for (unsigned int i = 0; i < to_gen; i++) {
bool reject = true;
double x, y;
while(reject) {
diff --git a/src/update_factor.c b/src/update_factor.c
index 6b8e05e..debfe7b 100644
--- a/src/update_factor.c
+++ b/src/update_factor.c
@@ -16,13 +16,13 @@ bool update_factor(cholmod_factor *factor, unsigned int v1, unsigned int v2,
for (int i = 0; i < n; i++) {
if (i <= v3)
- ((CHOL_INT *)update_mat->p)[i] = 0;
+ ((int_t *)update_mat->p)[i] = 0;
else
- ((CHOL_INT *)update_mat->p)[i] = 2;
+ ((int_t *)update_mat->p)[i] = 2;
}
- ((CHOL_INT *)update_mat->p)[n] = 2;
- ((CHOL_INT *)update_mat->i)[0] = v3;
- ((CHOL_INT *)update_mat->i)[1] = v4;
+ ((int_t *)update_mat->p)[n] = 2;
+ ((int_t *)update_mat->i)[0] = v3;
+ ((int_t *)update_mat->i)[1] = v4;
((double *)update_mat->x)[0] = 1;
((double *)update_mat->x)[1] = -1;