summaryrefslogtreecommitdiff
path: root/src/fracture.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/fracture.h')
-rw-r--r--src/fracture.h182
1 files changed, 182 insertions, 0 deletions
diff --git a/src/fracture.h b/src/fracture.h
new file mode 100644
index 0000000..4ee7050
--- /dev/null
+++ b/src/fracture.h
@@ -0,0 +1,182 @@
+
+#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 two defs allow me to switch to long int cholmod in a sitch
+#define CHOL_INT long int
+#define CHOL_F(x) cholmod_l_##x
+
+typedef enum boundary_type {
+ FREE_BOUND,
+ CYLINDER_BOUND,
+ TORUS_BOUND
+} boundary_type;
+
+typedef struct {
+ unsigned int num_edges;
+ unsigned int num_verts;
+ unsigned int num_verts_break;
+ unsigned int num_bounds;
+ unsigned int *edges_to_verts;
+ unsigned int *edges_to_verts_break;
+ unsigned int *verts_to_edges_ind;
+ unsigned int *verts_to_edges;
+ unsigned int *bound_inds;
+ unsigned int *bound_verts;
+ double *vert_coords;
+ double *edge_coords;
+ unsigned int *dual_edges_to_verts;
+ unsigned int *dual_verts_to_edges_ind;
+ unsigned int *dual_verts_to_edges;
+ double *dual_vert_coords;
+ unsigned int num_spanning_edges;
+ unsigned int *spanning_edges;
+ double L;
+ unsigned int num_dual_verts;
+ unsigned int break_dim;
+ cholmod_sparse *voltcurmat;
+ boundary_type boundary;
+} fnet;
+
+typedef struct {
+ fnet *network;
+ 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;
+} finst;
+
+typedef struct {
+ unsigned int num_broken;
+ unsigned int *break_list;
+ double *conductivity;
+ double *extern_field;
+} break_data;
+
+intptr_t *run_voronoi(unsigned int num_coords, double *coords, 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 finst *instance, bool dual, bool breakv,
+ unsigned int pad, cholmod_common *c);
+
+cholmod_sparse *gen_laplacian(const finst *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);
+
+break_data *fracture_network(finst *instance, double *fuse_thres,
+ cholmod_common *c, double cutoff);
+
+double *get_current(const finst *instance, cholmod_common *c);
+double *get_current_v(const finst *instance, double *voltages, cholmod_common *c);
+double *get_voltage(const finst *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(finst *instance, double crack_len, double crack_width,
+ cholmod_common *c);
+
+void update_boundary(finst *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);
+
+finst *copy_instance(const finst *instance, cholmod_common *c);
+
+fnet *ini_square_network(unsigned int width, boundary_type boundary, bool side_bounds,
+ cholmod_common *c);
+
+void free_fnet(fnet *network, cholmod_common *c);
+void free_instance(finst *instance, cholmod_common *c);
+
+finst *create_instance(fnet *network, double inf, bool voltage_bound,
+ bool startnow, cholmod_common *c);
+
+fnet *ini_voronoi_network(unsigned int L, boundary_type boundary,
+ double *(*genfunc)(unsigned int, gsl_rng *, unsigned int *),
+ cholmod_common *c);
+
+bool check_instance(const finst *instance, cholmod_common *c);
+
+bool break_edge(finst *instance, unsigned int edge, cholmod_common *c);
+
+void finish_instance(finst *instance, cholmod_common *c);
+
+finst *coursegrain_square(finst *instance, fnet *network_p, cholmod_common *c);
+
+unsigned int *get_clusters(finst *instance, cholmod_common *c);
+
+unsigned int *get_cluster_dist(finst *instance, cholmod_common *c);
+
+double *genfunc_uniform(unsigned int L, gsl_rng *r, unsigned int *num);
+double *genfunc_hyperuniform(unsigned int L, 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(fnet *network, unsigned int source);
+unsigned int **get_dists(fnet *network);
+double *get_corr(finst *instance, unsigned int **dists, cholmod_common *c);
+
+double *bin_values(fnet *network, unsigned int width, double *values);
+
+void voronoi_bound_ini(finst *instance, double *square_bound,
+ unsigned int width);
+
+break_data *alloc_break_data(unsigned int num_edges);
+void free_break_data(break_data *data);
+void update_break_data(break_data *data, unsigned int last_broke, double strength, double conductivity);
+
+double get_conductivity(finst *inst, double *current, cholmod_common *c);