summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-11-14 14:25:21 -0500
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-11-14 14:25:21 -0500
commit386856afbb6ca347221c13cd606e25b204317929 (patch)
tree601f24b5537330781fba01941488378fcae614e9 /src
parent7984b8dbde1d44fc18b6026693c387d2d433872d (diff)
downloadfuse_networks-386856afbb6ca347221c13cd606e25b204317929.tar.gz
fuse_networks-386856afbb6ca347221c13cd606e25b204317929.tar.bz2
fuse_networks-386856afbb6ca347221c13cd606e25b204317929.zip
a lot of cleaning and simplification
Diffstat (limited to 'src')
-rw-r--r--src/fracture.cpp23
-rw-r--r--src/measurements.cpp15
-rw-r--r--src/measurements.hpp10
3 files changed, 34 insertions, 14 deletions
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 <hooks.hpp>
#include "measurements.hpp"
+#include <csignal>
+#include <cstring>
+#include <atomic>
+
+std::atomic<bool> 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<unsigned int> find_minimal_crack(const Graph& G, const network& n) {
class find_cycle : public boost::default_dfs_visitor {
public:
- unsigned int end;
std::list<unsigned int>& E;
+ unsigned int end;
struct done{};
find_cycle(std::list<unsigned int>& E, unsigned int end) : E(E), end(end) {}
@@ -226,7 +226,7 @@ void autocorrelation(unsigned int L, std::vector<T>& 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<double, std::vector<double>>& 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<double, std::vector<dou
autocorrelation(L, Caa, forward_plan, fftw_forward_in, fftw_forward_out, reverse_plan, fftw_reverse_in, fftw_reverse_out);
- lv = cur.first / fabs(cur.second[i]) * net.thresholds[i];
+ lv = c;
avalanches.push_back({i});
} else {
avalanches.back().push_back(i);
@@ -373,7 +375,7 @@ void ma::post_fracture(network &n) {
// rewind the last avalanche
for (auto e : avalanches.back()) {
boost::remove_edge(n.G.dual_edges[e][0], n.G.dual_edges[e][1], G);
- n.add_edge(e);
+ n.break_edge(e, true);
fftw_forward_in[e] = 1;
}
@@ -417,5 +419,6 @@ void ma::post_fracture(network &n) {
sd[total_broken]++;
+ N++;
}
diff --git a/src/measurements.hpp b/src/measurements.hpp
index 621c425..ab31ccd 100644
--- a/src/measurements.hpp
+++ b/src/measurements.hpp
@@ -41,6 +41,9 @@ class ma : public hooks {
double *fftw_reverse_out;
fftw_plan forward_plan;
fftw_plan reverse_plan;
+ unsigned int N;
+ unsigned int L;
+ double beta;
Graph G;
// measurement storage
@@ -59,19 +62,16 @@ class ma : public hooks {
uint64_t Na;
public:
- unsigned int N;
- unsigned int L;
double lv;
- double beta;
std::list<std::list<unsigned int>> 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<double, std::vector<double>>& 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;
};