summaryrefslogtreecommitdiff
path: root/src/cracking_ini.c
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jkentdobias@g.hmc.edu>2016-08-22 10:11:14 -0400
committerJaron Kent-Dobias <jkentdobias@g.hmc.edu>2016-08-22 10:11:14 -0400
commit2bb0740b68fdb62d45adc00204b3990ca42ade77 (patch)
treea52975e3460da781467ddb70aaa8d76840d01bb4 /src/cracking_ini.c
downloadfuse_networks-2bb0740b68fdb62d45adc00204b3990ca42ade77.tar.gz
fuse_networks-2bb0740b68fdb62d45adc00204b3990ca42ade77.tar.bz2
fuse_networks-2bb0740b68fdb62d45adc00204b3990ca42ade77.zip
started repo again without all the data files gunking the works
Diffstat (limited to 'src/cracking_ini.c')
-rw-r--r--src/cracking_ini.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/cracking_ini.c b/src/cracking_ini.c
new file mode 100644
index 0000000..9ab4a9d
--- /dev/null
+++ b/src/cracking_ini.c
@@ -0,0 +1,53 @@
+
+#include "fracture.h"
+
+double *gen_fuse_thres(unsigned int num_edges, double *edge_coords, double beta,
+ double (*beta_scale)(double, double, double)) {
+ unsigned int size = num_edges;
+ assert(beta > 0);
+
+ double *fuse_thres = (double *)malloc(size * sizeof(double));
+ assert(fuse_thres != NULL);
+
+ gsl_set_error_handler_off();
+
+ gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937);
+ FILE *rf = fopen("/dev/urandom", "r");
+ unsigned long int seed;
+ fread(&seed, sizeof(unsigned long int), 1, rf);
+ fclose(rf);
+ gsl_rng_set(r, seed);
+
+ for (unsigned int i = 0; i < size; i++) {
+ double x = edge_coords[2 * i];
+ double y = edge_coords[2 * i + 1];
+ while ((fuse_thres[i] = gsl_sf_exp(gsl_sf_log(gsl_ran_flat(r, 0, 1)) /
+ beta_scale(beta, x, y))) == 0.0)
+ ;
+ }
+
+ gsl_rng_free(r);
+
+ return fuse_thres;
+}
+
+bool gen_crack(finst *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;
+ double *edge_coords = network->edge_coords;
+
+ for (unsigned int j = 0; j < num_edges; j++) {
+ if (edge_coords[2 * j + 1] < crack_len &&
+ fabs(edge_coords[2 * j] - network->L / 2) < crack_width) {
+ instance->fuses[j] = true;
+ instance->num_remaining_edges--;
+ } else
+ fuses[j] = false;
+ }
+
+ return true;
+}