summaryrefslogtreecommitdiff
path: root/src/fracture.h
blob: a9973ea7562dc4db1dc4625ced3bad958ac07522 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

#pragma once

#include <assert.h>
#include <cholmod.h>
#include <float.h>
#include <getopt.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_sf_erf.h>
#include <gsl/gsl_sf_exp.h>
#include <gsl/gsl_sf_log.h>
#include <inttypes.h>
#include <math.h>
#include <omp.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

// these defs allow me to switch to long int cholmod in a sitch
#define int_t int
#define uint_t unsigned int
#define CINT_MAX INT_MAX
#define CHOL_F(x) cholmod_##x

typedef enum bound_t {
	FREE_BOUND,
	CYLINDER_BOUND,
	TORUS_BOUND,
	EMBEDDED_BOUND
} bound_t;

typedef struct {
	uint_t ne;          // number of edges
	uint_t nv;          // number of vertices
	uint_t dnv;         // number of dual vertices
	uint_t nv_break;
	uint_t num_bounds;
	// 2*ne length array.  edge i connects vertices ev[2*i], ev[2*i+1] < nv
	uint_t *ev; 
	uint_t *ev_break;
	// nv+1 length array.  vertex i has degree vei[i+1]-vei[i], vei[0] = 0
	uint_t *vei;
	// vei[nv] length array.  vertex i is connected to edges ve[vei[i]+j], 0 <= j < vei[i+1]-vei[i]
	uint_t *ve;
	uint_t *bound_inds;
	uint_t *bound_verts;
	double *vert_coords;
	double *edge_coords;
	uint_t *dev;
	uint_t *dvei;
	uint_t *dve;
	double *dual_vert_coords;
	uint_t num_spanning_edges;
	uint_t *spanning_edges;
	double L;
	uint_t break_dim;
	cholmod_sparse *voltcurmat;
	bound_t boundary;
} graph_t;

typedef struct {
	graph_t *graph;
	unsigned int num_remaining_edges;
	bool *fuses;
	double inf;
	cholmod_dense *boundary_cond;
	cholmod_factor *factor;
	unsigned int *marks;
	unsigned int *dual_marks;
	bool voltage_bound;
	unsigned int num_components;
	cholmod_sparse *adjacency;
	bool debug_stop;
} net_t;

typedef struct {
	unsigned int num_broken;
	unsigned int *break_list;
	double *conductivity;
	double *extern_field;
} data_t;

intptr_t *run_voronoi(unsigned int num_coords, double *coords, bool periodic, double xmin, double xmax, double ymin, double ymax);

int update_components(const cholmod_sparse *laplacian, unsigned int *marks,
											int old_num_components, int v1, int v2, int exclude);

unsigned int *find_components(const cholmod_sparse *laplacian, unsigned int skip);

cholmod_sparse *gen_adjacency(const net_t *instance, bool dual, bool breakv,
															unsigned int pad, cholmod_common *c);

cholmod_sparse *gen_laplacian(const net_t *instance, cholmod_common *c,
															bool symmetric);

int edge_to_verts(unsigned int width, bool periodic, unsigned int edge,
									bool index);

int dual_edge_to_verts(unsigned int width, bool periodic, unsigned int edge,
											 bool index);

double dual_vert_to_coord(unsigned int width, bool periodic, unsigned int vert,
													bool index);

bool update_factor(cholmod_factor *factor, unsigned int v1, unsigned int v2,
									 cholmod_common *c);

data_t *fracture_network(net_t *instance, double *fuse_thres,
														 cholmod_common *c, double cutoff);

double *get_current(const net_t *instance, cholmod_common *c);
double *get_current_v(const net_t *instance, double *voltages, cholmod_common *c);
double *get_voltage(const net_t *instance, cholmod_common *c);

double *gen_fuse_thres(unsigned int num_edges, double *edge_coords, double beta,
											 double (*beta_scale)(double, double, double));

bool gen_crack(net_t *instance, double crack_len, double crack_width,
							 cholmod_common *c);

void update_boundary(net_t *instance, const double *avg_field);

FILE *get_file(const char *prefix, unsigned int width, unsigned int crack,
							 double beta, unsigned int iter, unsigned int num_iter,
							 unsigned int num, bool read);

double update_beta(double beta, unsigned int width, const double *stress,
									 const double *damage, double bound_total);

cholmod_sparse *gen_voltcurmat(unsigned int num_edges, unsigned int num_verts,
															 unsigned int *edges_to_verts, cholmod_common *c);

net_t *copy_instance(const net_t *instance, cholmod_common *c);

graph_t *ini_square_network(unsigned int width, bound_t boundary, bool side_bounds,
												 cholmod_common *c);

void free_net(graph_t *network, cholmod_common *c);
void free_instance(net_t *instance, cholmod_common *c);

net_t *create_instance(graph_t *network, double inf, bool voltage_bound,
											 bool startnow, cholmod_common *c);

graph_t *ini_voronoi_network(unsigned int L, bound_t boundary, bool use_dual,
													double *(*genfunc)(unsigned int, bound_t, gsl_rng *, unsigned int *),
													cholmod_common *c);

bool check_instance(const net_t *instance, cholmod_common *c);

bool break_edge(net_t *instance, unsigned int edge, cholmod_common *c);

void finish_instance(net_t *instance, cholmod_common *c);

net_t *coursegrain_square(net_t *instance, graph_t *network_p, cholmod_common *c);

unsigned int *get_clusters(net_t *instance, cholmod_common *c);

unsigned int *get_cluster_dist(net_t *instance, cholmod_common *c);

double *genfunc_uniform(unsigned int L, bound_t boundary, gsl_rng *r, unsigned int *num);
double *genfunc_hyperuniform(unsigned int L, bound_t boundary, gsl_rng *r, unsigned int *num);
void randfunc_flat(gsl_rng *r, double *x, double *y);
void randfunc_gaus(gsl_rng *r, double *x, double *y);
double beta_scaling_flat(double beta, double x, double y);
double beta_scaling_gaus(double beta, double x, double y);
double beta_mag(double beta);

unsigned int *dijkstra(graph_t *network, unsigned int source);
unsigned int **get_dists(graph_t *network);
double *get_corr(net_t *instance, unsigned int **dists, cholmod_common *c);

double *bin_values(graph_t *network, unsigned int width, double *values);

void voronoi_bound_ini(net_t *instance, uint_t L, double crack_len);

data_t *alloc_break_data(unsigned int num_edges);
void free_break_data(data_t *data);
void update_break_data(data_t *data, unsigned int last_broke, double strength, double conductivity);

double get_conductivity(net_t *inst, double *current, cholmod_common *c);

void gen_voro_crack(net_t *instance, double crack_len, cholmod_common *c);