From 948f90b6493da83d10e18f30b0fbb8e937e29c0b Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 24 Jun 2019 21:41:34 -0400 Subject: mostly implemented the ability to find dead bonds using topological properties --- lib/src/problem.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'lib/src/problem.cpp') diff --git a/lib/src/problem.cpp b/lib/src/problem.cpp index f66a35c..0645244 100644 --- a/lib/src/problem.cpp +++ b/lib/src/problem.cpp @@ -75,6 +75,8 @@ problem::problem(const graph& G, unsigned axis, cholmod_sparse *vcmat, cholmod_c factor = CHOL_F(analyze)(laplacian, c); CHOL_F(factorize)(laplacian, factor, c); CHOL_F(free_sparse)(&laplacian, c); + + sol.currents.resize(G.edges.size()); } problem::problem(const graph& G, unsigned axis, cholmod_common *c) : problem(G, axis, NULL, c) { @@ -97,7 +99,7 @@ problem::problem(const graph& G, unsigned axis, cholmod_common *c) : problem(G, CHOL_F(free_triplet)(&t, c); } -problem::problem(const problem& other) : G(other.G), axis(other.axis), c(other.c) { +problem::problem(const problem& other) : G(other.G), axis(other.axis), c(other.c), sol(other.sol) { b = CHOL_F(copy_dense)(other.b, c); factor = CHOL_F(copy_factor)(other.factor, c); voltcurmat = CHOL_F(copy_sparse)(other.voltcurmat, c); @@ -109,7 +111,7 @@ problem::~problem() { CHOL_F(free_sparse)(&voltcurmat, c); } -current_info problem::solve(std::vector& fuses) { +void problem::solve(std::vector& fuses) { cholmod_dense *x = CHOL_F(solve)(CHOLMOD_A, factor, b, c); if (((double *)x->x)[0] != ((double *)x->x)[0]) { @@ -122,15 +124,13 @@ current_info problem::solve(std::vector& fuses) { double beta[2] = {0, 0}; CHOL_F(sdmult)(voltcurmat, 0, alpha, beta, x, y, c); - std::vector currents(G.edges.size()); - - std::array total_current = {0, 0}; + sol.conductivity = {0, 0}; for (int i = 0; i < G.edges.size(); i++) { if (fuses[i]) { - currents[i] = 0; + sol.currents[i] = 0; } else { - currents[i] = ((double *)y->x)[i]; + sol.currents[i] = ((double *)y->x)[i]; graph::coordinate v0 = G.vertices[G.edges[i].v[0]].r; graph::coordinate v1 = G.vertices[G.edges[i].v[1]].r; @@ -144,22 +144,20 @@ current_info problem::solve(std::vector& fuses) { } if (comp) { - currents[i] += 1.0; - total_current[axis] += currents[i]; + sol.currents[i] += 1.0; + sol.conductivity[axis] += sol.currents[i]; } else { - currents[i] -= 1.0; - total_current[axis] -= currents[i]; + sol.currents[i] -= 1.0; + sol.conductivity[axis] -= sol.currents[i]; } } } } - total_current[!axis] = 0.0; + sol.conductivity[!axis] = 0.0; CHOL_F(free_dense)(&x, c); CHOL_F(free_dense)(&y, c); - - return {total_current, currents}; } void problem::break_edge(unsigned e, bool unbreak) { -- cgit v1.2.3-70-g09d2