summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpants <jaron@kent-dobias.com>2016-09-08 12:46:49 -0400
committerpants <jaron@kent-dobias.com>2016-09-08 12:46:49 -0400
commit9c6505dace488032dc4f5e3bbb8c5a4cb154b429 (patch)
tree7d2323a5bb0d01a1675905dcdf7289bf33d03e4f /src
parent2b7e4f906d8595994c36f9254574caff13c172a4 (diff)
downloadfuse_networks-9c6505dace488032dc4f5e3bbb8c5a4cb154b429.tar.gz
fuse_networks-9c6505dace488032dc4f5e3bbb8c5a4cb154b429.tar.bz2
fuse_networks-9c6505dace488032dc4f5e3bbb8c5a4cb154b429.zip
more refactoring
Diffstat (limited to 'src')
-rw-r--r--src/break_data.c34
-rw-r--r--src/data.c35
-rw-r--r--src/fracture.c2
-rw-r--r--src/fracture.h12
-rw-r--r--src/free_network.c22
-rw-r--r--src/graph_free.c22
-rw-r--r--src/graph_genfunc.c (renamed from src/randfuncs.c)15
-rw-r--r--src/net_copy.c35
-rw-r--r--src/net_create.c (renamed from src/net.c)52
-rw-r--r--src/net_fracture.c5
-rw-r--r--src/net_free.c14
11 files changed, 112 insertions, 136 deletions
diff --git a/src/break_data.c b/src/break_data.c
deleted file mode 100644
index 5c922f3..0000000
--- a/src/break_data.c
+++ /dev/null
@@ -1,34 +0,0 @@
-
-#include "fracture.h"
-
-data_t *alloc_break_data(unsigned int num_edges) {
- data_t *data = malloc(1 * sizeof(data_t)); assert(data != NULL);
-
- data->num_broken = 0;
-
- data->break_list = (unsigned int *)malloc(num_edges * sizeof(unsigned int));
- assert(data->break_list != NULL);
-
- data->extern_field = (double *)malloc(num_edges * sizeof(double));
- assert(data->extern_field != NULL);
-
- data->conductivity = (double *)malloc(num_edges * sizeof(double));
- assert(data->conductivity != NULL);
-
- return 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(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;
- data->num_broken++;
-}
-
diff --git a/src/data.c b/src/data.c
new file mode 100644
index 0000000..b54236d
--- /dev/null
+++ b/src/data.c
@@ -0,0 +1,35 @@
+
+#include "fracture.h"
+
+data_t *data_create(uint_t ne) {
+ data_t *data = malloc(1 * sizeof(data_t));
+ assert(data != NULL);
+
+ data->num_broken = 0;
+
+ data->break_list = (uint_t *)malloc(ne * sizeof(uint_t));
+ assert(data->break_list != NULL);
+
+ data->extern_field = (double *)malloc(ne * sizeof(double));
+ assert(data->extern_field != NULL);
+
+ data->conductivity = (double *)malloc(ne * sizeof(double));
+ assert(data->conductivity != NULL);
+
+ return data;
+}
+
+void data_free(data_t *data) {
+ free(data->break_list);
+ free(data->extern_field);
+ free(data->conductivity);
+ free(data);
+}
+
+void data_update(data_t *data, uint_t 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;
+ data->num_broken++;
+}
+
diff --git a/src/fracture.c b/src/fracture.c
index e7abaec..f36cfdb 100644
--- a/src/fracture.c
+++ b/src/fracture.c
@@ -412,7 +412,7 @@ int main(int argc, char *argv[]) {
fprintf(data_out, "\n");
}
- free_break_data(data);
+ data_free(data);
}
printf("\033[F\033[JFRACTURE: COMPLETE\n");
diff --git a/src/fracture.h b/src/fracture.h
index 19b1e71..2401d25 100644
--- a/src/fracture.h
+++ b/src/fracture.h
@@ -148,8 +148,6 @@ graph_t *ini_voro_graph(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 net_t *instance, cholmod_common *c);
-
bool break_edge(net_t *instance, unsigned int edge, cholmod_common *c);
void finish_instance(net_t *instance, cholmod_common *c);
@@ -164,11 +162,7 @@ double *genfunc_uniform(unsigned int L, bound_t boundary, gsl_rng *r, unsigned i
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);
-double beta_scaling_gaus(double beta, double x, double y);
-double beta_mag(double beta);
-unsigned int *dijkstra(const graph_t *network, unsigned int source);
unsigned int **get_dists(const graph_t *network);
double *get_corr(net_t *instance, unsigned int **dists, cholmod_common *c);
@@ -176,9 +170,9 @@ double *bin_values(graph_t *network, unsigned int width, double *values);
cholmod_dense *bound_set(const graph_t *g, bool vb, double notch_len, cholmod_common *c);
-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);
+data_t *data_create(uint_t num_edges);
+void data_free(data_t *data);
+void data_update(data_t *data, uint_t last_broke, double strength, double conductivity);
double get_conductivity(net_t *inst, double *current, cholmod_common *c);
diff --git a/src/free_network.c b/src/free_network.c
deleted file mode 100644
index 2001479..0000000
--- a/src/free_network.c
+++ /dev/null
@@ -1,22 +0,0 @@
-
-#include "fracture.h"
-
-void graph_free(graph_t *network, cholmod_common *c) {
- free(network->ev);
- if (network->ev_break != network->ev) {
- free(network->ev_break);
- }
- free(network->vei);
- free(network->ve);
- free(network->bound_inds);
- free(network->bound_verts);
- free(network->vx);
- free(network->ex);
- free(network->dev);
- free(network->dvx);
- free(network->dvei);
- free(network->dve);
- free(network->spanning_edges);
- CHOL_F(free_sparse)(&(network->voltcurmat), c);
- free(network);
-}
diff --git a/src/graph_free.c b/src/graph_free.c
new file mode 100644
index 0000000..e9c55d7
--- /dev/null
+++ b/src/graph_free.c
@@ -0,0 +1,22 @@
+
+#include "fracture.h"
+
+void graph_free(graph_t *g, cholmod_common *c) {
+ free(g->ev);
+ if (g->ev_break != g->ev) {
+ free(g->ev_break);
+ }
+ free(g->vei);
+ free(g->ve);
+ free(g->bound_inds);
+ free(g->bound_verts);
+ free(g->vx);
+ free(g->ex);
+ free(g->dev);
+ free(g->dvx);
+ free(g->dvei);
+ free(g->dve);
+ free(g->spanning_edges);
+ CHOL_F(free_sparse)(&(g->voltcurmat), c);
+ free(g);
+}
diff --git a/src/randfuncs.c b/src/graph_genfunc.c
index 137c7ff..991e127 100644
--- a/src/randfuncs.c
+++ b/src/graph_genfunc.c
@@ -76,18 +76,3 @@ double *genfunc_hyperuniform(unsigned int L, bound_t boundary, gsl_rng *r, unsig
return lattice;
}
-void randfunc_flat(gsl_rng *r, double *x, double *y) {
- *x = gsl_ran_flat(r, 0, 1);
- *y = gsl_ran_flat(r, 0, 1);
-}
-
-void randfunc_gaus(gsl_rng *r, double *x, double *y) {
- *x = 100;
- *y = 100;
- double sigma = 0.25;
- while (fabs(*x) > 0.5 || fabs(*y) > 0.5) {
- gsl_ran_bivariate_gaussian(r, sigma, sigma, 0, x, y);
- }
- *x += 0.5;
- *y += 0.5;
-}
diff --git a/src/net_copy.c b/src/net_copy.c
new file mode 100644
index 0000000..dcb4080
--- /dev/null
+++ b/src/net_copy.c
@@ -0,0 +1,35 @@
+
+#include "fracture.h"
+
+net_t *net_copy(const net_t *net, cholmod_common *c) {
+ net_t *net_copy = (net_t *)calloc(1, sizeof(net_t));
+ assert(net_copy != NULL);
+ memcpy(net_copy, net, sizeof(net_t));
+
+ size_t fuses_size = (net->graph)->ne * sizeof(bool);
+ net_copy->fuses = (bool *)malloc(fuses_size);
+ assert(net_copy->fuses != NULL);
+ memcpy(net_copy->fuses, net->fuses, fuses_size);
+
+ size_t thres_size = (net->graph)->ne * sizeof(double);
+ net_copy->thres = (double *)malloc(thres_size);
+ assert(net_copy->thres != NULL);
+ memcpy(net_copy->thres, net->thres, thres_size);
+
+ size_t marks_size = (net->graph->break_dim) * sizeof(uint_t);
+ net_copy->marks = (uint_t *)malloc(marks_size);
+ assert(net_copy->marks != NULL);
+ memcpy(net_copy->marks, net->marks, marks_size);
+
+ size_t dual_marks_size = (net->graph->dnv) * sizeof(uint_t);
+ net_copy->dual_marks = (uint_t *)malloc(dual_marks_size);
+ assert(net_copy->dual_marks != NULL);
+ memcpy(net_copy->dual_marks, net->dual_marks, dual_marks_size);
+
+ net_copy->adjacency = CHOL_F(copy_sparse)(net->adjacency, c);
+ net_copy->boundary_cond = CHOL_F(copy_dense)(net->boundary_cond, c);
+ net_copy->factor = CHOL_F(copy_factor)(net->factor, c);
+
+ return net_copy;
+}
+
diff --git a/src/net.c b/src/net_create.c
index d090a9a..fedcb3a 100644
--- a/src/net.c
+++ b/src/net_create.c
@@ -27,7 +27,6 @@ double *get_thres(uint_t ne, double beta) {
return thres;
}
-
net_t *net_create(const graph_t *g, double inf, double beta, double notch_len, bool vb, cholmod_common *c) {
net_t *net = (net_t *)calloc(1, sizeof(net_t));
assert(net != NULL);
@@ -68,54 +67,3 @@ net_t *net_create(const graph_t *g, double inf, double beta, double notch_len, b
return net;
}
-net_t *net_copy(const net_t *net, cholmod_common *c) {
- net_t *net_copy = (net_t *)calloc(1, sizeof(net_t));
- assert(net_copy != NULL);
- memcpy(net_copy, net, sizeof(net_t));
-
- size_t fuses_size = (net->graph)->ne * sizeof(bool);
- net_copy->fuses = (bool *)malloc(fuses_size);
- assert(net_copy->fuses != NULL);
- memcpy(net_copy->fuses, net->fuses, fuses_size);
-
- size_t thres_size = (net->graph)->ne * sizeof(double);
- net_copy->thres = (double *)malloc(thres_size);
- assert(net_copy->thres != NULL);
- memcpy(net_copy->thres, net->thres, thres_size);
-
- size_t marks_size = (net->graph->break_dim) * sizeof(uint_t);
- net_copy->marks = (uint_t *)malloc(marks_size);
- assert(net_copy->marks != NULL);
- memcpy(net_copy->marks, net->marks, marks_size);
-
- size_t dual_marks_size = (net->graph->dnv) * sizeof(uint_t);
- net_copy->dual_marks = (uint_t *)malloc(dual_marks_size);
- assert(net_copy->dual_marks != NULL);
- memcpy(net_copy->dual_marks, net->dual_marks, dual_marks_size);
-
- net_copy->adjacency = CHOL_F(copy_sparse)(net->adjacency, c);
- net_copy->boundary_cond = CHOL_F(copy_dense)(net->boundary_cond, c);
- net_copy->factor = CHOL_F(copy_factor)(net->factor, c);
-
- return net_copy;
-}
-
-void net_free(net_t *net, cholmod_common *c) {
- free(net->fuses);
- free(net->thres);
- CHOL_F(free_dense)(&(net->boundary_cond), c);
- CHOL_F(free_sparse)(&(net->adjacency), c);
- CHOL_F(free_factor)(&(net->factor), c);
- free(net->marks);
- free(net->dual_marks);
- free(net);
-}
-
-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));
- assert(CHOL_F(check_factor)(instance->factor, c));
-
- return true;
-}
diff --git a/src/net_fracture.c b/src/net_fracture.c
index b7fa61d..48e81f9 100644
--- a/src/net_fracture.c
+++ b/src/net_fracture.c
@@ -27,9 +27,8 @@ uint_t get_next_broken(net_t *net, double *currents, double cutoff) {
return max_pos;
}
-
data_t *net_fracture(net_t *net, cholmod_common *c, double cutoff) {
- data_t *data = alloc_break_data(net->graph->ne);
+ data_t *data = data_create(net->graph->ne);
while (true) {
double *voltages = get_voltage(net, c);
@@ -45,7 +44,7 @@ data_t *net_fracture(net_t *net, cholmod_common *c, double cutoff) {
uint_t last_broke = get_next_broken(net, currents, cutoff);
- update_break_data(data, last_broke, fabs(conductivity * (net->thres)[last_broke] / currents[last_broke]), conductivity);
+ data_update(data, last_broke, fabs(conductivity * (net->thres)[last_broke] / currents[last_broke]), conductivity);
free(voltages);
free(currents);
diff --git a/src/net_free.c b/src/net_free.c
new file mode 100644
index 0000000..8b5af50
--- /dev/null
+++ b/src/net_free.c
@@ -0,0 +1,14 @@
+
+#include "fracture.h"
+
+void net_free(net_t *net, cholmod_common *c) {
+ free(net->fuses);
+ free(net->thres);
+ CHOL_F(free_dense)(&(net->boundary_cond), c);
+ CHOL_F(free_sparse)(&(net->adjacency), c);
+ CHOL_F(free_factor)(&(net->factor), c);
+ free(net->marks);
+ free(net->dual_marks);
+ free(net);
+}
+