#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // 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 { 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; bound_t 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, 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 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, bound_t 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, bound_t boundary, bool use_dual, double *(*genfunc)(unsigned int, bound_t, 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, 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(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);