From 386856afbb6ca347221c13cd606e25b204317929 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 14 Nov 2018 14:25:21 -0500 Subject: a lot of cleaning and simplification --- src/fracture.cpp | 23 ++++++++++++++++++++--- src/measurements.cpp | 15 +++++++++------ src/measurements.hpp | 10 +++++----- 3 files changed, 34 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/fracture.cpp b/src/fracture.cpp index 77af253..0aad56e 100644 --- a/src/fracture.cpp +++ b/src/fracture.cpp @@ -11,7 +11,23 @@ #include #include "measurements.hpp" +#include +#include +#include + +std::atomic quit(false); // signal flag + +void got_signal(int) { + quit.store(true); +} + int main(int argc, char* argv[]) { + struct sigaction sa; + memset( &sa, 0, sizeof(sa) ); + sa.sa_handler = got_signal; + sigfillset(&sa.sa_mask); + sigaction(SIGINT, &sa, NULL); + int opt; unsigned int N = 1; @@ -36,12 +52,10 @@ int main(int argc, char* argv[]) { cholmod_common c; CHOL_F(start)(&c); - c.supernodal = CHOLMOD_SUPERNODAL; - graph G(L); network base_network(G, &c); - ma meas(N, L, beta); + ma meas(L, beta); randutils::auto_seed_128 seeds; std::mt19937 rng{seeds}; @@ -50,6 +64,9 @@ int main(int argc, char* argv[]) { network tmp_network(base_network); tmp_network.set_thresholds(beta, rng); tmp_network.fracture(meas); + + if (quit.load()) + break; } CHOL_F(finish)(&c); diff --git a/src/measurements.cpp b/src/measurements.cpp index 0bd72c4..ed96855 100644 --- a/src/measurements.cpp +++ b/src/measurements.cpp @@ -38,8 +38,8 @@ std::list find_minimal_crack(const Graph& G, const network& n) { class find_cycle : public boost::default_dfs_visitor { public: - unsigned int end; std::list& E; + unsigned int end; struct done{}; find_cycle(std::list& E, unsigned int end) : E(E), end(end) {} @@ -226,7 +226,7 @@ void autocorrelation(unsigned int L, std::vector& out_data, fftw_plan forward } } -ma::ma(unsigned int N, unsigned int L, double beta) : L(L), G(2 * pow(L / 2, 2)), N(N), beta(beta), +ma::ma(unsigned int L, double beta) : L(L), beta(beta), G(2 * pow(L / 2, 2)), sc(pow(L, 2), 0), sa(pow(L, 2), 0), sd(pow(L, 2), 0), @@ -239,6 +239,7 @@ ma::ma(unsigned int N, unsigned int L, double beta) : L(L), G(2 * pow(L / 2, 2)) Cll(pow(L / 2 + 1, 2), 0), Cee(pow(L / 2 + 1, 2), 0) { + N = 0; Nc = 0; Na = 0; @@ -284,8 +285,9 @@ void ma::pre_fracture(const network &) { boost::remove_edge_if(trivial, G); } -void ma::bond_broken(const network& net, const std::pair>& cur, unsigned int i) { - if (cur.first / fabs(cur.second[i]) * net.thresholds[i] > lv) { +void ma::bond_broken(const network& net, const current_info& cur, unsigned int i) { + double c = cur.conductivity / fabs(cur.currents[i]) * net.thresholds[i]; + if (c > lv) { sa[avalanches.back().size()]++; Na++; @@ -297,7 +299,7 @@ void ma::bond_broken(const network& net, const std::pair> avalanches; - ma(unsigned int N, unsigned int L, double beta); + ma(unsigned int L, double beta); ~ma(); void pre_fracture(const network &) override; - void bond_broken(const network& net, const std::pair>& cur, unsigned int i) override; + void bond_broken(const network& net, const current_info& cur, unsigned int i) override; void post_fracture(network &n) override; }; -- cgit v1.2.3-70-g09d2