summaryrefslogtreecommitdiff
path: root/lib/gen_voltcurmat.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/gen_voltcurmat.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/gen_voltcurmat.c')
-rw-r--r--lib/gen_voltcurmat.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/gen_voltcurmat.c b/lib/gen_voltcurmat.c
new file mode 100644
index 0000000..e870140
--- /dev/null
+++ b/lib/gen_voltcurmat.c
@@ -0,0 +1,36 @@
+
+#include "fracture.h"
+
+cholmod_sparse *gen_voltcurmat(unsigned int num_edges, unsigned int num_verts,
+ unsigned int *edges_to_verts,
+ cholmod_common *c) {
+
+ cholmod_triplet *t_m = CHOL_F(allocate_triplet)(
+ num_edges, num_verts, num_edges * 2, 0, CHOLMOD_REAL, c);
+ assert(t_m != NULL);
+
+ int_t *rowind = (int_t *)t_m->i;
+ int_t *colind = (int_t *)t_m->j;
+ double *acoo = (double *)t_m->x;
+
+ for (unsigned int i = 0; i < num_edges; i++) {
+ unsigned int v1 = edges_to_verts[2 * i];
+ unsigned int v2 = edges_to_verts[2 * i + 1];
+ rowind[2 * i] = i;
+ rowind[2 * i + 1] = i;
+ colind[2 * i] = v1;
+ colind[2 * i + 1] = v2;
+ acoo[2 * i] = 1;
+ acoo[2 * i + 1] = -1;
+ }
+
+ t_m->nnz = num_edges * 2;
+
+ assert(CHOL_F(check_triplet)(t_m, c));
+
+ cholmod_sparse *m = CHOL_F(triplet_to_sparse)(t_m, num_edges * 2, c);
+
+ CHOL_F(free_triplet)(&t_m, c);
+
+ return m;
+}