summaryrefslogtreecommitdiff
path: root/lib/src/problem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/problem.cpp')
-rw-r--r--lib/src/problem.cpp26
1 files changed, 12 insertions, 14 deletions
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<bool>& fuses) {
+void problem::solve(std::vector<bool>& 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<bool>& fuses) {
double beta[2] = {0, 0};
CHOL_F(sdmult)(voltcurmat, 0, alpha, beta, x, y, c);
- std::vector<double> currents(G.edges.size());
-
- std::array<double, 2> 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<bool>& 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) {