summaryrefslogtreecommitdiff
path: root/lib/net_fracture.c
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2017-02-10 12:19:46 -0500
committerJaron Kent-Dobias <jaron@kent-dobias.com>2017-02-10 12:19:46 -0500
commit0ef0c0ce1d904be2b4e1f4da62dc029d8572c983 (patch)
tree12978013d870186240c08d1fdd6a7ce8781bca93 /lib/net_fracture.c
parent9a93a3b88a604672f557950e6c7f3fe815bcf163 (diff)
parent901b9f16494f37890be17ef4bb66e6efc6873340 (diff)
downloadfuse_networks-0ef0c0ce1d904be2b4e1f4da62dc029d8572c983.tar.gz
fuse_networks-0ef0c0ce1d904be2b4e1f4da62dc029d8572c983.tar.bz2
fuse_networks-0ef0c0ce1d904be2b4e1f4da62dc029d8572c983.zip
Merge branch 'tmp'
Diffstat (limited to 'lib/net_fracture.c')
-rw-r--r--lib/net_fracture.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/net_fracture.c b/lib/net_fracture.c
new file mode 100644
index 0000000..e7f18fc
--- /dev/null
+++ b/lib/net_fracture.c
@@ -0,0 +1,67 @@
+
+#include "fracture.h"
+
+uint_t get_next_broken(net_t *net, double *currents, double cutoff) {
+ uint_t max_pos = UINT_MAX;
+ long double max_val = 0;
+
+ for (uint_t i = 0; i < net->graph->ne; i++) {
+ long double current = fabs(currents[i]);
+ bool broken = net->fuses[i];
+
+ if (!broken && current > cutoff) {
+ long double val = current / net->thres[i];
+
+ if (val > max_val) {
+ max_val = val;
+ max_pos = i;
+ }
+ }
+ }
+
+ if (max_pos == UINT_MAX) {
+ printf("GET_NEXT_BROKEN: currents is zero or NaN, no max_val found\n");
+ exit(EXIT_FAILURE);
+ }
+
+ return max_pos;
+}
+
+data_t *net_fracture(net_t *net, cholmod_common *c, double cutoff) {
+ data_t *data = data_create(net->graph->ne);
+
+ uint_t n = 0;
+ while (true) {
+ n++;
+ double *voltages = net_voltages(net, c);
+ double *currents = net_currents(net, voltages, c);
+
+ double conductivity = net_conductivity(net, voltages);
+
+ if (conductivity < cutoff) {
+ free(voltages);
+ free(currents);
+ break;
+ }
+
+ uint_t last_broke = get_next_broken(net, currents, cutoff);
+
+ long double sim_current;
+
+ if (net->voltage_bound) {
+ sim_current = conductivity;
+ } else {
+ sim_current = 1;
+ }
+
+ data_update(data, last_broke, fabsl(sim_current * (net->thres)[last_broke] / ((long double)currents[last_broke])), conductivity);
+
+ free(voltages);
+ free(currents);
+
+ break_edge(net, last_broke, c);
+ }
+
+ return data;
+}
+