summaryrefslogtreecommitdiff
path: root/src/get_dual_clusters.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/get_dual_clusters.c')
-rw-r--r--src/get_dual_clusters.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/get_dual_clusters.c b/src/get_dual_clusters.c
new file mode 100644
index 0000000..488793f
--- /dev/null
+++ b/src/get_dual_clusters.c
@@ -0,0 +1,36 @@
+
+#include "fracture.h"
+
+unsigned int *get_clusters(finst *instance, cholmod_common *c) {
+ cholmod_sparse *s_dual = gen_adjacency(instance, true, false, 0, c);
+
+ unsigned int *dual_marks = find_components(s_dual, 0);
+ CHOL_F(free_sparse)(&s_dual, c);
+
+ return dual_marks;
+}
+
+unsigned int *get_cluster_dist(finst *instance, cholmod_common *c) {
+ unsigned int *clusters = get_clusters(instance, c);
+ unsigned int *cluster_dist = (unsigned int *)calloc(
+ instance->network->num_dual_verts, sizeof(unsigned int));
+
+ unsigned int cur_mark = 0;
+ while (true) {
+ cur_mark++;
+ unsigned int num_in_cluster = 0;
+ for (unsigned int i = 0; i < instance->network->num_dual_verts; i++) {
+ if (clusters[i] == cur_mark)
+ num_in_cluster++;
+ }
+
+ if (num_in_cluster == 0)
+ break;
+
+ cluster_dist[num_in_cluster - 1]++;
+ }
+
+ free(clusters);
+
+ return cluster_dist;
+}