From 2bb0740b68fdb62d45adc00204b3990ca42ade77 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 22 Aug 2016 10:11:14 -0400 Subject: started repo again without all the data files gunking the works --- src/get_dual_clusters.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/get_dual_clusters.c (limited to 'src/get_dual_clusters.c') 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; +} -- cgit v1.2.3-70-g09d2