#include "perc_meas.hpp" #include #include class badcycleException: public std::exception { virtual const char* what() const throw() { return "Could not find a valid cycle on the broken system."; } } badcycleex; void update_distribution_file(std::string id, const std::vector& data, std::string model_string) { std::string filename = model_string + id + ".dat"; std::ifstream file(filename); std::vector data_old(data.size(), 0); if (file.is_open()) { for (unsigned i = 0; i < data.size(); i++) { uint64_t num; file >> num; data_old[i] = num; } file.close(); } std::ofstream file_out(filename); for (unsigned i = 0; i < data.size(); i++) { file_out <>& data, std::string model_string) { std::string filename = model_string + id + ".dat"; std::ifstream file(filename); std::vector> data_old(data.size()); for (unsigned i = 0; i < data.size(); i++) { data_old[i].resize(data[0].size()); } if (file.is_open()) { for (unsigned i = 0; i < data.size(); i++) { for (unsigned j = 0; j < data[0].size(); j++) { uint64_t num; file >> num; data_old[i][j] = num; } } file.close(); } std::ofstream file_out(filename); for (unsigned i = 0; i < data.size(); i++) { for (unsigned j = 0; j < data[0].size(); j++) { file_out << std::fixed << data_old[i][j] + data[i][j] << " "; } file_out << "\n"; } file_out.close(); } pm::pm(unsigned n, double a) : sn(3 * n), sN(3 * n), ss(2 * n), sm(2 * n), sl(2 * n), sb(3 * n), sd(3 * n) { model_string = "percolation_" + std::to_string(n) + "_" + std::to_string(a) + "_"; for (std::vector &x : sn) { x.resize(2 * n); } for (std::vector &x : sN) { x.resize(2 * n); } for (std::vector &x : sb) { x.resize(n); } } pm::pm(unsigned Lx, unsigned Ly) : sn(Lx * Ly), sN(Lx * Ly), ss(Lx * Ly / 2), sm(Lx * Ly / 2), sl(Lx * Ly / 2), sb(Lx * Ly), sd(Lx * Ly) { model_string = "percolation_" + std::to_string(Lx) + "_" + std::to_string(Ly) + "_"; for (std::vector &x : sn) { x.resize(Lx * Ly / 2); } for (std::vector &x : sN) { x.resize(Lx * Ly / 2); } for (std::vector &x : sb) { x.resize(Lx * Ly / 2); } } pm::~pm() { update_distribution_file("sn", sn, model_string); update_distribution_file("sN", sN, model_string); update_distribution_file("ss", ss, model_string); update_distribution_file("sm", sm, model_string); update_distribution_file("sl", sl, model_string); update_distribution_file("sb", sb, model_string); update_distribution_file("sd", sd, model_string); } void pm::pre_fracture(const network&) { r = 0; sN_tmp.clear(); } void pm::bond_broken(const network& net, const current_info& cur, unsigned i) { std::vector vertex_in(net.G.vertices.size()); for (unsigned i = 0; i < net.G.edges.size(); i++) { if (cur.currents[i] > CURRENT_CUTOFF) { vertex_in[net.G.edges[i].v[0]] = true; vertex_in[net.G.edges[i].v[1]] = true; } } unsigned bb_size = 0; for (unsigned i = 0; i < net.G.vertices.size(); i++) { if (vertex_in[i]) bb_size++; } sb[r][bb_size - 1]++; r++; last_cur = cur; } void pm::post_fracture(network &n) { sd[r - 1]++; }