From ae8014ad662e485f54ea578be67daa477b3936f0 Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Nov 2016 18:53:58 -0500 Subject: added support for controlling disorder by random initial bond breaking --- src/net.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/net.c') diff --git a/src/net.c b/src/net.c index 444e76c..1be5613 100644 --- a/src/net.c +++ b/src/net.c @@ -1,7 +1,7 @@ #include "fracture.h" -long double *get_thres(uint_t ne, double beta) { +long double *get_thres(uint_t ne, double beta, bool perc) { long double *thres = (long double *)malloc(ne * sizeof(long double)); assert(thres != NULL); @@ -9,7 +9,8 @@ long double *get_thres(uint_t ne, double beta) { gsl_rng_set(r, rand_seed()); for (uint_t i = 0; i < ne; i++) { - thres[i] = rand_dist_pow(r, beta); + if (perc) thres[i] = 1; + else thres[i] = rand_dist_pow(r, beta); } gsl_rng_free(r); @@ -44,14 +45,27 @@ void net_notch(net_t *net, double notch_len, cholmod_common *c) { } } -net_t *net_create(const graph_t *g, double inf, double beta, double notch_len, bool vb, cholmod_common *c) { +void net_perc(net_t *net, double p, cholmod_common *c) { + gsl_rng *r = gsl_rng_alloc(GSL_RAND_GEN); + gsl_rng_set(r, rand_seed()); + + for (uint_t i = 0; i < net->graph->ne; i++) { + double x = gsl_rng_uniform_pos(r); + if (!net->fuses[i] && p > x) break_edge(net, i, c, false); + } + + gsl_rng_free(r); +} + +net_t *net_create(const graph_t *g, double inf, double beta, double notch_len, bool vb, bool perc, cholmod_common *c) { net_t *net = (net_t *)calloc(1, sizeof(net_t)); assert(net != NULL); net->graph = g; + net->num_broken = 0; net->fuses = (bool *)calloc(g->ne, sizeof(bool)); assert(net->fuses != NULL); - net->thres = get_thres(g->ne, beta); + net->thres = get_thres(g->ne, beta, perc); net->inf = inf; net->voltage_bound = vb; @@ -76,6 +90,8 @@ net_t *net_create(const graph_t *g, double inf, double beta, double notch_len, b net_notch(net, notch_len, c); + if (perc) net_perc(net, beta, c); + { cholmod_sparse *laplacian = gen_laplacian(net, c, true); net->factor = CHOL_F(analyze)(laplacian, c); -- cgit v1.2.3-70-g09d2