From 4c4ebb87ead363d6d6e11a8b95b07a0f93af5c88 Mon Sep 17 00:00:00 2001 From: pants Date: Tue, 6 Sep 2016 15:05:27 -0400 Subject: finished implementing embedded systems, refactored a bunch --- src/cracked_voronoi_fracture.c | 163 ++++++++++++++++++++++++++++++----------- 1 file changed, 120 insertions(+), 43 deletions(-) (limited to 'src/cracked_voronoi_fracture.c') diff --git a/src/cracked_voronoi_fracture.c b/src/cracked_voronoi_fracture.c index 532c3c3..93eb112 100644 --- a/src/cracked_voronoi_fracture.c +++ b/src/cracked_voronoi_fracture.c @@ -15,8 +15,14 @@ int main(int argc, char *argv[]) { save_damage, save_damage_field; bound_t boundary; + + // assume filenames will be less than 100 characters + filename_len = 100; + + // set default values + N = 100; L = 16; crack_len = 0.; @@ -37,9 +43,13 @@ int main(int argc, char *argv[]) { save_conductivity = false; save_toughness = false; + uint8_t bound_i; char boundc2 = 'f'; + + // get commandline options + while ((opt = getopt(argc, argv, "n:L:b:B:dVcoNsCrtDSvel:")) != -1) { switch (opt) { case 'n': @@ -123,6 +133,7 @@ int main(int argc, char *argv[]) { } } + char boundc; if (use_voltage_boundaries) boundc = 'v'; else boundc = 'c'; @@ -130,7 +141,7 @@ int main(int argc, char *argv[]) { FILE *break_out; if (include_breaking) { char *break_filename = (char *)malloc(filename_len * sizeof(char)); - snprintf(break_filename, filename_len, "breaks_v_%c_%c_%u_%g.txt", boundc, boundc2, L, beta); + snprintf(break_filename, filename_len, "breaks_v_%c_%c_%u_%g_%g.txt", boundc, boundc2, L, beta, crack_len); break_out = fopen(break_filename, "a"); free(break_filename); } @@ -158,8 +169,8 @@ int main(int argc, char *argv[]) { c_filename = (char *)malloc(filename_len * sizeof(char)); a_filename = (char *)malloc(filename_len * sizeof(char)); - snprintf(c_filename, filename_len, "cstr_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta); - snprintf(a_filename, filename_len, "avln_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta); + snprintf(c_filename, filename_len, "cstr_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len); + snprintf(a_filename, filename_len, "avln_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len); FILE *cluster_out = fopen(c_filename, "rb"); FILE *avalanche_out = fopen(a_filename, "rb"); @@ -179,6 +190,24 @@ int main(int argc, char *argv[]) { crit_stress = (double *)malloc(N * sizeof(double)); } + double *stress_field; + unsigned int stress_pos = 0; + if (save_stress_field) { + stress_field = (double *)malloc(3 * N * voronoi_max_verts * sizeof(double)); + } + + double *voltage_field; + unsigned int voltage_pos = 0; + if (save_voltage_field) { + voltage_field = (double *)malloc(3 * N * voronoi_max_verts * sizeof(double)); + } + + double *damage_field; + unsigned int damage_pos = 0; + if (save_damage_field) { + damage_field = (double *)malloc(2 * N * voronoi_max_verts * sizeof(double)); + } + double *conductivity; if (save_conductivity) { conductivity = (double *)malloc(N * sizeof(double)); @@ -192,7 +221,7 @@ int main(int argc, char *argv[]) { (uint32_t *)malloc(a_dist_size * sizeof(uint32_t)); d_filename = (char *)malloc(filename_len * sizeof(char)); - snprintf(d_filename, filename_len, "damg_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta); + snprintf(d_filename, filename_len, "damg_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len); FILE *damage_out = fopen(d_filename, "rb"); @@ -228,16 +257,16 @@ int main(int argc, char *argv[]) { for (uint32_t i = 0; i < N; i++) { printf("\033[F\033[JFRACTURE: %0*d / %d\n", (uint8_t)log10(N) + 1, i + 1, N); - fnet *network = ini_voronoi_network(L, boundary, use_dual, genfunc_hyperuniform, &c); - finst *perm_instance = create_instance(network, inf, use_voltage_boundaries, false, &c); + graph_t *graph = ini_voronoi_network(L, boundary, use_dual, genfunc_hyperuniform, &c); + net_t *perm_instance = create_instance(graph, inf, use_voltage_boundaries, false, &c); if (boundary == EMBEDDED_BOUND) { voronoi_bound_ini(perm_instance, L, crack_len); } gen_voro_crack(perm_instance, crack_len, &c); finish_instance(perm_instance, &c); - double *fuse_thres = gen_fuse_thres(network->num_edges, network->edge_coords, beta, beta_scaling_flat); - finst *instance = copy_instance(perm_instance, &c); - break_data *breaking_data = fracture_network(instance, fuse_thres, &c, cutoff); + double *fuse_thres = gen_fuse_thres(graph->ne, graph->edge_coords, beta, beta_scaling_flat); + net_t *instance = copy_instance(perm_instance, &c); + data_t *breaking_data = fracture_network(instance, fuse_thres, &c, cutoff); free_instance(instance, &c); free(fuse_thres); @@ -253,12 +282,13 @@ int main(int argc, char *argv[]) { } } - if (save_crit_stress) { - crit_stress[i] = - breaking_data->extern_field[max_pos]; - } + if (save_crit_stress) crit_stress[i] = breaking_data->extern_field[max_pos]; + + if (save_conductivity) conductivity[i] = breaking_data->conductivity[max_pos]; - finst *tmp_instance = copy_instance(perm_instance, &c); + if (save_damage) damage[max_pos]++; + + net_t *tmp_instance = copy_instance(perm_instance, &c); uint_t av_size = 0; double cur_val = 0; @@ -279,13 +309,34 @@ int main(int argc, char *argv[]) { } } - if (save_conductivity) { - if (!use_voltage_boundaries) { - double *tmp_voltage = get_voltage(tmp_instance, &c); - conductivity[i] = 1/fabs(tmp_voltage[tmp_instance->network->num_verts + 1] - tmp_voltage[tmp_instance->network->num_verts]); - free(tmp_voltage); - } else { - conductivity[i] = breaking_data->conductivity[max_pos]; + if (save_stress_field || save_voltage_field) { + double *tmp_voltages = get_voltage(tmp_instance, &c); + if (save_voltage_field) { + for (uint_t j = 0; j < tmp_instance->graph->nv; j++) { + voltage_field[3 * voltage_pos] = tmp_instance->graph->vert_coords[2 * j]; + voltage_field[3 * voltage_pos + 1] = tmp_instance->graph->vert_coords[2 * j + 1]; + voltage_field[3 * voltage_pos + 2] = tmp_voltages[j]; + voltage_pos++; + } + } + if (save_stress_field) { + double *tmp_currents = get_current_v(tmp_instance, tmp_voltages, &c); + for (uint_t j = 0; j < tmp_instance->graph->ne; j++) { + stress_field[3 * stress_pos] = tmp_instance->graph->edge_coords[2 * j]; + stress_field[3 * stress_pos + 1] = tmp_instance->graph->edge_coords[2 * j + 1]; + stress_field[3 * stress_pos + 2] = tmp_currents[j]; + stress_pos++; + } + free(tmp_currents); + } + free(tmp_voltages); + } + + if (save_damage_field) { + for (uint_t j = 0; j < max_pos; j++) { + damage_field[2 * damage_pos] = tmp_instance->graph->edge_coords[2 * breaking_data->break_list[j]]; + damage_field[2 * damage_pos + 1] = tmp_instance->graph->edge_coords[2 * breaking_data->break_list[j] + 1]; + damage_pos++; } } @@ -306,13 +357,9 @@ int main(int argc, char *argv[]) { toughness[i] = tmp_toughness; } - if (save_damage) { - damage[max_pos]++; - } - if (save_cluster_dist) { uint_t *tmp_cluster_dist = get_cluster_dist(tmp_instance, &c); - for (uint_t j = 0; j < tmp_instance->network->num_dual_verts; j++) { + for (uint_t j = 0; j < tmp_instance->graph->dnv; j++) { cluster_size_dist[j] += tmp_cluster_dist[j]; } free(tmp_cluster_dist); @@ -320,27 +367,27 @@ int main(int argc, char *argv[]) { if (save_network) { FILE *net_out = fopen("network.txt", "w"); - for (uint_t j = 0; j < network->num_verts; j++) { - fprintf(net_out, "%f %f ", network->vert_coords[2 * j], - tmp_instance->network->vert_coords[2 * j + 1]); + for (uint_t j = 0; j < graph->nv; j++) { + fprintf(net_out, "%f %f ", graph->vert_coords[2 * j], + tmp_instance->graph->vert_coords[2 * j + 1]); } fprintf(net_out, "\n"); - for (uint_t j = 0; j < tmp_instance->network->num_edges; j++) { - fprintf(net_out, "%u %u ", tmp_instance->network->edges_to_verts[2 * j], - tmp_instance->network->edges_to_verts[2 * j + 1]); + for (uint_t j = 0; j < tmp_instance->graph->ne; j++) { + fprintf(net_out, "%u %u ", tmp_instance->graph->ev[2 * j], + tmp_instance->graph->ev[2 * j + 1]); } fprintf(net_out, "\n"); - for (uint_t j = 0; j < tmp_instance->network->num_dual_verts; j++) { - fprintf(net_out, "%f %f ", tmp_instance->network->dual_vert_coords[2 * j], - tmp_instance->network->dual_vert_coords[2 * j + 1]); + for (uint_t j = 0; j < tmp_instance->graph->dnv; j++) { + fprintf(net_out, "%f %f ", tmp_instance->graph->dual_vert_coords[2 * j], + tmp_instance->graph->dual_vert_coords[2 * j + 1]); } fprintf(net_out, "\n"); - for (uint_t j = 0; j < tmp_instance->network->num_edges; j++) { - fprintf(net_out, "%u %u ", tmp_instance->network->dual_edges_to_verts[2 * j], - tmp_instance->network->dual_edges_to_verts[2 * j + 1]); + for (uint_t j = 0; j < tmp_instance->graph->ne; j++) { + fprintf(net_out, "%u %u ", tmp_instance->graph->dev[2 * j], + tmp_instance->graph->dev[2 * j + 1]); } fprintf(net_out, "\n"); - for (uint_t j = 0; j < tmp_instance->network->num_edges; j++) { + for (uint_t j = 0; j < tmp_instance->graph->ne; j++) { fprintf(net_out, "%d ", tmp_instance->fuses[j]); } fclose(net_out); @@ -348,7 +395,7 @@ int main(int argc, char *argv[]) { free_instance(tmp_instance, &c); free_instance(perm_instance, &c); - free_fnet(network, &c); + free_net(graph, &c); if (include_breaking) { for (uint_t j = 0; j < breaking_data->num_broken; j++) { @@ -379,9 +426,39 @@ int main(int argc, char *argv[]) { free(avalanche_size_dist); } + if (save_voltage_field) { + char *vfld_filename = (char *)malloc(filename_len * sizeof(char)); + snprintf(vfld_filename, filename_len, "vfld_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len); + FILE *vfld_file = fopen(vfld_filename, "ab"); + fwrite(voltage_field, sizeof(double), 3 * voltage_pos, vfld_file); + fclose(vfld_file); + free(vfld_filename); + free(voltage_field); + } + + if (save_stress_field) { + char *cfld_filename = (char *)malloc(filename_len * sizeof(char)); + snprintf(cfld_filename, filename_len, "cfld_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len); + FILE *cfld_file = fopen(cfld_filename, "ab"); + fwrite(stress_field, sizeof(double), 3 * stress_pos, cfld_file); + fclose(cfld_file); + free(cfld_filename); + free(stress_field); + } + + if (save_damage_field) { + char *dfld_filename = (char *)malloc(filename_len * sizeof(char)); + snprintf(dfld_filename, filename_len, "dfld_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len); + FILE *dfld_file = fopen(dfld_filename, "ab"); + fwrite(damage_field, sizeof(double), 2 * damage_pos, dfld_file); + fclose(dfld_file); + free(dfld_filename); + free(damage_field); + } + if (save_conductivity) { char *cond_filename = (char *)malloc(filename_len * sizeof(char)); - snprintf(cond_filename, filename_len, "cond_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta); + snprintf(cond_filename, filename_len, "cond_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len); FILE *cond_file = fopen(cond_filename, "ab"); fwrite(conductivity, sizeof(double), N, cond_file); fclose(cond_file); @@ -391,7 +468,7 @@ int main(int argc, char *argv[]) { if (save_toughness) { char *tough_filename = (char *)malloc(filename_len * sizeof(char)); - snprintf(tough_filename, filename_len, "tuff_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta); + snprintf(tough_filename, filename_len, "tuff_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len); FILE *tough_file = fopen(tough_filename, "ab"); fwrite(toughness, sizeof(double), N, tough_file); fclose(tough_file); @@ -413,7 +490,7 @@ int main(int argc, char *argv[]) { if (save_crit_stress) { char *str_filename = (char *)malloc(filename_len * sizeof(char)); - snprintf(str_filename, filename_len, "strs_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta); + snprintf(str_filename, filename_len, "strs_v_%c_%c_%d_%g_%g.dat", boundc, boundc2, L, beta, crack_len); FILE *str_file = fopen(str_filename, "ab"); fwrite(crit_stress, sizeof(double), N, str_file); fclose(str_file); -- cgit v1.2.3-70-g09d2