summaryrefslogtreecommitdiff
path: root/src/fracture.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fracture.c')
-rw-r--r--src/fracture.c66
1 files changed, 40 insertions, 26 deletions
diff --git a/src/fracture.c b/src/fracture.c
index 59bd424..6050182 100644
--- a/src/fracture.c
+++ b/src/fracture.c
@@ -10,7 +10,7 @@ int main(int argc, char *argv[]) {
uint32_t N;
uint_t L, refactor_every;
double beta, inf, cutoff, crack_len;
- bool save_data, save_cluster_dist, use_voltage_boundaries, use_dual, save_network,
+ bool save_data, save_cluster_dist, use_voltage_boundaries, use_dual, use_perc, save_network,
save_crit_stress, save_stress_field, save_voltage_field, save_energy, save_conductivity,
save_damage, save_damage_field, save_threshold;
bound_t boundary;
@@ -44,8 +44,9 @@ int main(int argc, char *argv[]) {
save_damage = false;
save_damage_field = false;
save_conductivity = false;
- save_energy = true;
+ save_energy = false;
save_threshold = false;
+ use_perc = false;
uint8_t bound_i;
@@ -53,11 +54,12 @@ int main(int argc, char *argv[]) {
uint8_t lattice_i;
char lattice_c = 'v';
char dual_c = 'o';
+ char perc_c = 't';
// get commandline options
- while ((opt = getopt(argc, argv, "n:L:b:B:q:dVcoNsCrDSvel:TER:")) != -1) {
+ while ((opt = getopt(argc, argv, "n:L:b:B:q:dVcoNsCrDSvel:TER:p")) != -1) {
switch (opt) {
case 'n':
N = atoi(optarg);
@@ -74,6 +76,10 @@ int main(int argc, char *argv[]) {
case 'l':
crack_len = atof(optarg);
break;
+ case 'p':
+ use_perc = true;
+ perc_c = 'b';
+ break;
case 'B':
bound_i = atoi(optarg);
switch (bound_i) {
@@ -170,7 +176,7 @@ int main(int argc, char *argv[]) {
FILE *data_out;
if (save_data) {
char *data_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(data_filename, filename_len, "data_%c_%c_%c_%c_%u_%g_%g.txt", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(data_filename, filename_len, "data_%c_%c_%c_%c_%c_%u_%g_%g.txt", perc_c, lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
data_out = fopen(data_filename, "a");
free(data_filename);
}
@@ -198,8 +204,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_%c_%c_%c_%c_%d_%g_%g.dat", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
- snprintf(a_filename, filename_len, "avln_%c_%c_%c_%c_%d_%g_%g.dat", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(c_filename, filename_len, "cstr_%c_%c_%c_%c_%c_%d_%g_%g.dat", perc_c, lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(a_filename, filename_len, "avln_%c_%c_%c_%c_%c_%d_%g_%g.dat", perc_c, lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
FILE *cluster_out = fopen(c_filename, "rb");
FILE *avalanche_out = fopen(a_filename, "rb");
@@ -250,7 +256,7 @@ int main(int argc, char *argv[]) {
(uint32_t *)calloc(max_edges, sizeof(uint32_t));
d_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(d_filename, filename_len, "damg_%c_%c_%c_%c_%d_%g_%g.dat", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(d_filename, filename_len, "damg_%c_%c_%c_%c_%c_%d_%g_%g.dat", perc_c, lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
FILE *damage_out = fopen(d_filename, "rb");
@@ -292,7 +298,14 @@ int main(int argc, char *argv[]) {
printf("\033[F\033[JFRACTURE: %0*d / %d\n", (uint8_t)log10(N) + 1, i + 1, N);
graph_t *g = graph_create(lattice, boundary, L, use_dual, &c);
- net_t *net = net_create(g, inf, beta, crack_len, use_voltage_boundaries, &c);
+ net_t *net = net_create(g, inf, beta, crack_len, use_voltage_boundaries, use_perc, &c);
+ if (net->marks[g->nv] != net->marks[g->nv+1]) {
+ if (save_crit_stress) crit_stress[i] = 0;
+ if (save_conductivity) conductivity[i] = 0;
+ if (save_damage) damage[net->num_broken]++;
+ if (save_energy) energy[i] = 0;
+ if (save_threshold) thresholds[i] = 0;
+ } else {
net_t *tmp_net = net_copy(net, &c);
data_t *data = net_fracture(tmp_net, &c, cutoff, refactor_every);
net_free(tmp_net, &c);
@@ -349,7 +362,7 @@ int main(int argc, char *argv[]) {
}
}
- if (save_damage) damage[max_pos]++;
+ if (save_damage) damage[net->num_broken]++;
if (save_stress_field || save_voltage_field) {
double *tmp_voltages = net_voltages(net, &c);
@@ -412,6 +425,17 @@ int main(int argc, char *argv[]) {
free(tmp_cluster_dist);
}
+
+ if (save_data) {
+ for (uint_t j = 0; j < data->num_broken; j++) {
+ fprintf(data_out, "%u %Lg %g ", data->break_list[j],
+ data->extern_field[j], data->conductivity[j]);
+ }
+ fprintf(data_out, "\n");
+ }
+
+ data_free(data);
+ }
if (save_network) {
FILE *net_out = fopen("network.txt", "w");
for (uint_t j = 0; j < g->nv; j++) {
@@ -440,16 +464,6 @@ int main(int argc, char *argv[]) {
net_free(net, &c);
graph_free(g, &c);
-
- if (save_data) {
- for (uint_t j = 0; j < data->num_broken; j++) {
- fprintf(data_out, "%u %Lg %g ", data->break_list[j],
- data->extern_field[j], data->conductivity[j]);
- }
- fprintf(data_out, "\n");
- }
-
- data_free(data);
}
printf("\033[F\033[JFRACTURE: COMPLETE\n");
@@ -472,7 +486,7 @@ int main(int argc, char *argv[]) {
if (save_voltage_field) {
char *vfld_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(vfld_filename, filename_len, "vfld_%c_%c_%c_%c_%d_%g_%g.dat", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(vfld_filename, filename_len, "vfld_%c_%c_%c_%c_%c_%d_%g_%g.dat", perc_c, lattice_c, dual_c, 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);
@@ -482,7 +496,7 @@ int main(int argc, char *argv[]) {
if (save_stress_field) {
char *cfld_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(cfld_filename, filename_len, "cfld_%c_%c_%c_%c_%d_%g_%g.dat", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(cfld_filename, filename_len, "cfld_%c_%c_%c_%c_%c_%d_%g_%g.dat", perc_c, lattice_c, dual_c, 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);
@@ -492,7 +506,7 @@ int main(int argc, char *argv[]) {
if (save_damage_field) {
char *dfld_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(dfld_filename, filename_len, "dfld_%c_%c_%c_%c_%d_%g_%g.dat", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(dfld_filename, filename_len, "dfld_%c_%c_%c_%c_%c_%d_%g_%g.dat", perc_c, lattice_c, dual_c, 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);
@@ -502,7 +516,7 @@ int main(int argc, char *argv[]) {
if (save_conductivity) {
char *cond_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(cond_filename, filename_len, "cond_%c_%c_%c_%c_%d_%g_%g.dat", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(cond_filename, filename_len, "cond_%c_%c_%c_%c_%c_%d_%g_%g.dat", perc_c, lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
FILE *cond_file = fopen(cond_filename, "ab");
fwrite(conductivity, sizeof(double), N, cond_file);
fclose(cond_file);
@@ -512,7 +526,7 @@ int main(int argc, char *argv[]) {
if (save_energy) {
char *tough_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(tough_filename, filename_len, "enrg_%c_%c_%c_%c_%d_%g_%g.dat", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(tough_filename, filename_len, "enrg_%c_%c_%c_%c_%c_%d_%g_%g.dat", perc_c, lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
FILE *tough_file = fopen(tough_filename, "ab");
fwrite(energy, sizeof(long double), N, tough_file);
fclose(tough_file);
@@ -522,7 +536,7 @@ int main(int argc, char *argv[]) {
if (save_threshold) {
char *thres_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(thres_filename, filename_len, "thrs_%c_%c_%c_%c_%d_%g_%g.dat", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(thres_filename, filename_len, "thrs_%c_%c_%c_%c_%c_%d_%g_%g.dat", perc_c, lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
FILE *thres_file = fopen(thres_filename, "ab");
fwrite(thresholds, sizeof(long double), N, thres_file);
fclose(thres_file);
@@ -544,7 +558,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_%c_%c_%c_%c_%d_%g_%g.dat", lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
+ snprintf(str_filename, filename_len, "strs_%c_%c_%c_%c_%c_%d_%g_%g.dat", perc_c, lattice_c, dual_c, boundc, boundc2, L, beta, crack_len);
FILE *str_file = fopen(str_filename, "ab");
fwrite(crit_stress, sizeof(long double), N, str_file);
fclose(str_file);