summaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
authorpants <jaron@kent-dobias.com>2016-11-21 18:53:58 -0500
committerpants <jaron@kent-dobias.com>2016-11-21 18:53:58 -0500
commitae8014ad662e485f54ea578be67daa477b3936f0 (patch)
treeec26cf51262d20b30ce0135ff899307891e07dbf /src/net.c
parent4407982c990594a90db9184e3de8fba394ee096b (diff)
downloadfuse_networks-ae8014ad662e485f54ea578be67daa477b3936f0.tar.gz
fuse_networks-ae8014ad662e485f54ea578be67daa477b3936f0.tar.bz2
fuse_networks-ae8014ad662e485f54ea578be67daa477b3936f0.zip
added support for controlling disorder by random initial bond breaking
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c24
1 files changed, 20 insertions, 4 deletions
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);