#include "fracture.h" double *net_voltages(const net_t *net, cholmod_common *c) { cholmod_dense *b = net->boundary_cond; cholmod_factor *factor = net->factor; cholmod_dense *x = CHOL_F(solve)(CHOLMOD_A, factor, b, c); if (((double *)x->x)[0] != ((double *)x->x)[0]) { printf("GET_VOLTAGE: value is NaN\n"); exit(EXIT_FAILURE); } double *t_voltages = (double *)x->x; x->x = NULL; CHOL_F(free_dense)(&x, c); const graph_t *g = net->graph; if (g->boundary == TORUS_BOUND) { return t_voltages; } else if (net->voltage_bound) { double *voltages = (double *)malloc(g->nv * sizeof(double)); for (uint_t i = 0; i < g->nv - g->bi[g->nb]; i++) { voltages[g->nbi[i]] = t_voltages[i]; } for (uint_t i = 0; i < 2; i++) { for (uint_t j = 0; j < g->bi[i + 1] - g->bi[i]; j++) { voltages[g->b[g->bi[i] + j]] = 1 - i; } } free(t_voltages); return voltages; } else { return t_voltages; } }