summaryrefslogtreecommitdiff
path: root/src/get_conductivity.c
blob: 7ef08a85448d7b2688c705296f19c7cd1cf6c211 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

#include "fracture.h"

double get_conductivity(finst *inst, double *voltage, cholmod_common *c) {
	if (inst->voltage_bound) {
		double tot_cur = 0;
		for (unsigned int i = 0; i < inst->network->num_spanning_edges; i++) {
			unsigned int e = inst->network->spanning_edges[i];
			if (!inst->fuses[e]) {
				unsigned int v1 = inst->network->edges_to_verts[2*e];
				unsigned int v2 = inst->network->edges_to_verts[2*e+1];
				double v1y = inst->network->vert_coords[2 * v1 + 1];
				double v2y = inst->network->vert_coords[2 * v2 + 1];
				unsigned int s1 = v1y < v2y ? v1 : v2;
				unsigned int s2 = v1y < v2y ? v2 : v1;
				tot_cur += voltage[s1] - voltage[s2];
			}
		}

		return fabs(tot_cur);
	} else {
		return 1 / fabs(voltage[inst->network->num_verts] - voltage[inst->network->num_verts + 1]);
	}
}