summaryrefslogtreecommitdiff
path: root/src/compare_voronoi_fracture.c
blob: bdb94231aed00d70bea0dc0fc1e9909382fc70f2 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124


#include "fracture.h"

int main(int argc, char *argv[]) {
	int opt;

	// defining variables to be (potentially) set by command line flags
	unsigned int N, L, filename_len;
	double beta, inf, cutoff;
	bound_t boundary;

	filename_len = 100;

	N = 100;
	L = 16;
	beta = .3;
	inf = 1e10;
	cutoff = 1e-10;
	boundary = FREE_BOUND;

	int boundary_int;
	char boundc2 = 'f';

	while ((opt = getopt(argc, argv, "n:L:b:B:dcoNsCrt")) != -1) {
		switch (opt) {
			case 'n':
				N = atoi(optarg);
				break;
			case 'L':
				L = atoi(optarg);
				break;
			case 'b':
				beta = atof(optarg);
				break;
			case 'B':
				boundary_int = atoi(optarg);
				switch (boundary_int) {
					case 0:
						boundary = FREE_BOUND;
						boundc2 = 'f';
						break;
					case 1:
						boundary = CYLINDER_BOUND;
						boundc2 = 'c';
						break;
					default:
						printf("boundary specifier must be 0 (FREE_BOUND) or 1 (CYLINDER_BOUND).\n");
				}
				break;
			default: /* '?' */
				exit(EXIT_FAILURE);
		}
	}

	char *break_filename = (char *)malloc(filename_len * sizeof(char));
	snprintf(break_filename, filename_len, "breaks_v_vc_%c_%u_%g.txt", boundc2, L, beta);
	FILE *break_out = fopen(break_filename, "a");
	free(break_filename);


	// start cholmod
	cholmod_common c;
	CHOL_F(start)(&c);

	(&c)->supernodal = CHOLMOD_SIMPLICIAL;


	fnet *network = ini_voronoi_network(L, false, boundary, genfunc_hyperuniform, &c);
	finst *perm_voltage_instance = create_instance(network, inf, true, true, &c);
	finst *perm_current_instance = create_instance(network, inf, false, true, &c);
	double *fuse_thres = gen_fuse_thres(network->num_edges, network->edge_coords, beta, beta_scaling_flat);
	finst *voltage_instance = copy_instance(perm_voltage_instance, &c);
	finst *current_instance = copy_instance(perm_current_instance, &c);
	break_data *breaking_data_voltage = fracture_network(voltage_instance, fuse_thres, &c, cutoff);
	break_data *breaking_data_current = fracture_network(current_instance, fuse_thres, &c, cutoff);
	free_instance(voltage_instance, &c);
	free_instance(current_instance, &c);
	free_instance(perm_voltage_instance, &c);
	free_instance(perm_current_instance, &c);
	free(fuse_thres);

	FILE *net_out = fopen("network.txt", "w");
	for (unsigned int j = 0; j < network->num_verts; j++) {
		fprintf(net_out, "%f %f ", network->vert_coords[2 * j],
						network->vert_coords[2 * j + 1]);
	}
	fprintf(net_out, "\n");
	for (unsigned int j = 0; j < network->num_edges; j++) {
		fprintf(net_out, "%u %u ", network->edges_to_verts[2 * j],
						network->edges_to_verts[2 * j + 1]);
	}
	fprintf(net_out, "\n");
	for (unsigned int j = 0; j < network->num_dual_verts; j++) {
		fprintf(net_out, "%f %f ", network->dual_vert_coords[2 * j],
						network->dual_vert_coords[2 * j + 1]);
	}
	fprintf(net_out, "\n");
	for (unsigned int j = 0; j < network->num_edges; j++) {
		fprintf(net_out, "%u %u ", network->dual_edges_to_verts[2 * j],
						network->dual_edges_to_verts[2 * j + 1]);
	}

	free_fnet(network, &c);

	for (unsigned int j = 0; j < breaking_data_voltage->num_broken; j++) {
		fprintf(break_out, "%u %g %g ", breaking_data_voltage->break_list[j],
						breaking_data_voltage->extern_field[j], breaking_data_voltage->conductivity[j]);
	}
	fprintf(break_out, "\n");
	for (unsigned int j = 0; j < breaking_data_current->num_broken; j++) {
		fprintf(break_out, "%u %g %g ", breaking_data_current->break_list[j],
						breaking_data_current->extern_field[j], breaking_data_current->conductivity[j]);
	}
	fprintf(break_out, "\n");

	free_break_data(breaking_data_voltage);
	free_break_data(breaking_data_current);
	fclose(break_out);

	CHOL_F(finish)(&c);

	return 0;
}