summaryrefslogtreecommitdiff
path: root/src/measurements.cpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2019-10-02 10:46:17 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2019-10-02 10:46:17 -0400
commit47a7c96d1848e3a3edbcfb17e645790d31c01a67 (patch)
treee45bf1cc6c57338cdd064acf0aa8e7a210d306fb /src/measurements.cpp
parent172d281943371a3aaa04a1a4d564731178e782e7 (diff)
downloadfuse_networks-47a7c96d1848e3a3edbcfb17e645790d31c01a67.tar.gz
fuse_networks-47a7c96d1848e3a3edbcfb17e645790d31c01a67.tar.bz2
fuse_networks-47a7c96d1848e3a3edbcfb17e645790d31c01a67.zip
cleaned up libraries and reduced number of binaries
Diffstat (limited to 'src/measurements.cpp')
-rw-r--r--src/measurements.cpp162
1 files changed, 79 insertions, 83 deletions
diff --git a/src/measurements.cpp b/src/measurements.cpp
index fd9c8a0..1a937be 100644
--- a/src/measurements.cpp
+++ b/src/measurements.cpp
@@ -1,18 +1,16 @@
#include "measurements.hpp"
-#include <iostream>
#include <cstdio>
+#include <iostream>
-class badcycleException: public std::exception
-{
- virtual const char* what() const throw()
- {
+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<uint64_t>& data, std::string model_string) {
+void update_distribution_file(std::string id, const std::vector<uint64_t>& data,
+ std::string model_string) {
std::string filename = model_string + id + ".dat";
std::ifstream file(filename);
@@ -31,7 +29,7 @@ void update_distribution_file(std::string id, const std::vector<uint64_t>& data,
std::ofstream file_out(filename);
for (unsigned i = 0; i < data.size(); i++) {
- file_out <<std::fixed<< data_old[i] + data[i] << " ";
+ file_out << std::fixed << data_old[i] + data[i] << " ";
}
file_out.close();
@@ -59,11 +57,13 @@ void update_field_file(std::string id, const std::vector<T>& data, std::string m
file_out.close();
}
-
-fftw_complex* data_transform(unsigned Mx, unsigned My, fftw_plan forward_plan, double *fftw_forward_in, fftw_complex *fftw_forward_out) {
+/*
+fftw_complex* data_transform(unsigned Mx, unsigned My, fftw_plan forward_plan,
+double *fftw_forward_in, fftw_complex *fftw_forward_out) {
fftw_execute(forward_plan);
- fftw_complex* output = (fftw_complex*)malloc(Mx * (My / 2 + 1) * sizeof(fftw_complex));
+ fftw_complex* output = (fftw_complex*)malloc(Mx * (My / 2 + 1) *
+sizeof(fftw_complex));
for (unsigned i = 0; i < Mx * (My / 2 + 1); i++) {
output[i][0] = fftw_forward_out[i][0];
@@ -72,24 +72,31 @@ fftw_complex* data_transform(unsigned Mx, unsigned My, fftw_plan forward_plan, d
return output;
}
+*/
+/*
template <class T>
-void correlation(unsigned Mx, unsigned My, std::vector<std::vector<T>>& data, const fftw_complex* tx1, const fftw_complex* tx2, fftw_plan reverse_plan, fftw_complex *fftw_reverse_in, double *fftw_reverse_out) {
- for (unsigned i = 0; i < Mx * (My / 2 + 1); i++) {
- fftw_reverse_in[i][0] = tx1[i][0] * tx2[i][0] + tx1[i][1] * tx2[i][1];
- fftw_reverse_in[i][1] = tx1[i][0] * tx2[i][1] - tx1[i][1] * tx2[i][0];
+void correlation(unsigned Mx, unsigned My, std::vector<std::vector<T>>& data,
+const fftw_complex* tx1, const fftw_complex* tx2, fftw_plan reverse_plan,
+fftw_complex *fftw_reverse_in, double *fftw_reverse_out) { for (unsigned i = 0;
+i < Mx * (My / 2 + 1); i++) { fftw_reverse_in[i][0] = tx1[i][0] * tx2[i][0] +
+tx1[i][1] * tx2[i][1]; fftw_reverse_in[i][1] = tx1[i][0] * tx2[i][1] - tx1[i][1]
+* tx2[i][0];
}
fftw_execute(reverse_plan);
for (unsigned j = 0; j < data.size(); j++) {
for (unsigned i = 0; i < (Mx / 2 + 1) * (My / 2 + 1); i++) {
- data[j][i] += (T)pow(fftw_reverse_out[Mx * (i / (Mx / 2 + 1)) + i % (Mx / 2 + 1)] / (Mx * My), j + 1);
+ data[j][i] += (T)pow(fftw_reverse_out[Mx * (i / (Mx / 2 + 1)) + i % (Mx /
+2 + 1)] / (Mx * My), j + 1);
}
}
}
+*/
-void autocorrelation2(double Lx, double Ly, unsigned Mx, unsigned My, std::vector<uint64_t>& data, const std::list<graph::coordinate>& pos, std::array<unsigned, 2> count) {
+void autocorrelation2(double Lx, double Ly, unsigned Mx, unsigned My, std::vector<uint64_t>& data,
+ const std::list<graph::coordinate>& pos, std::array<unsigned, 2> count) {
for (std::list<graph::coordinate>::const_iterator it1 = pos.begin(); it1 != pos.end(); it1++) {
for (std::list<graph::coordinate>::const_iterator it2 = it1; it2 != pos.end(); it2++) {
double Δx_tmp = fabs(it1->x - it2->x);
@@ -107,9 +114,12 @@ void autocorrelation2(double Lx, double Ly, unsigned Mx, unsigned My, std::vecto
}
}
-void correlation2(double Lx, double Ly, unsigned Mx, unsigned My, std::vector<uint64_t>& data, const std::list<graph::coordinate>& pos1, const std::list<graph::coordinate>& pos2) {
+void correlation2(double Lx, double Ly, unsigned Mx, unsigned My, std::vector<uint64_t>& data,
+ const std::list<graph::coordinate>& pos1,
+ const std::list<graph::coordinate>& pos2) {
for (std::list<graph::coordinate>::const_iterator it1 = pos1.begin(); it1 != pos1.end(); it1++) {
- for (std::list<graph::coordinate>::const_iterator it2 = pos2.begin(); it2 != pos2.end(); it2++) {
+ for (std::list<graph::coordinate>::const_iterator it2 = pos2.begin(); it2 != pos2.end();
+ it2++) {
double Δx_tmp = fabs(it1->x - it2->x);
double Δx = Δx_tmp < Lx / 2 ? Δx_tmp : Lx - Δx_tmp;
@@ -120,82 +130,58 @@ void correlation2(double Lx, double Ly, unsigned Mx, unsigned My, std::vector<ui
}
}
}
-
+/*
template <class T>
-void autocorrelation(unsigned Mx, unsigned My, std::vector<std::vector<T>>& out_data, fftw_plan forward_plan, double *fftw_forward_in, fftw_complex *fftw_forward_out, fftw_plan reverse_plan, fftw_complex *fftw_reverse_in, double *fftw_reverse_out) {
- fftw_execute(forward_plan);
+void autocorrelation(unsigned Mx, unsigned My, std::vector<std::vector<T>>&
+out_data, fftw_plan forward_plan, double *fftw_forward_in, fftw_complex
+*fftw_forward_out, fftw_plan reverse_plan, fftw_complex *fftw_reverse_in, double
+*fftw_reverse_out) { fftw_execute(forward_plan);
for (unsigned i = 0; i < My * (Mx / 2 + 1); i++) {
- fftw_reverse_in[i][0] = pow(fftw_forward_out[i][0], 2) + pow(fftw_forward_out[i][1], 2);
- fftw_reverse_in[i][1] = 0.0;
+ fftw_reverse_in[i][0] = pow(fftw_forward_out[i][0], 2) +
+pow(fftw_forward_out[i][1], 2); fftw_reverse_in[i][1] = 0.0;
}
fftw_execute(reverse_plan);
for (unsigned j = 0; j < out_data.size(); j++) {
for (unsigned i = 0; i < (Mx / 2 + 1) * (My / 2 + 1); i++) {
- out_data[j][i] += (T)pow(fftw_reverse_out[Mx * (i / (Mx / 2 + 1)) + i % (Mx / 2 + 1)] / (Mx * My), j + 1);
+ out_data[j][i] += (T)pow(fftw_reverse_out[Mx * (i / (Mx / 2 + 1)) + i %
+(Mx / 2 + 1)] / (Mx * My), j + 1);
}
}
}
+*/
unsigned edge_r_to_ind(graph::coordinate r, double Lx, double Ly, unsigned Mx, unsigned My) {
return floor((Mx * r.x) / Lx) + Mx * floor((My * r.y) / Ly);
}
-ma::ma(unsigned n, double a, double beta, double weight) :
- sn(2 * n),
- ss(2 * n),
- sm(2 * n),
- sl(2 * n),
- sb(n + 1),
- sd(3 * n),
- sa(3 * n),
- sA(3 * n),
- si(10000),
- sI(10000),
- cn(pow((unsigned)sqrt(n), 2)),
- cs(pow((unsigned)sqrt(n), 2)),
- cm(pow((unsigned)sqrt(n), 2)),
- cl(pow((unsigned)sqrt(n), 2)),
- cb(pow((unsigned)sqrt(n), 2)),
- ca(pow((unsigned)sqrt(n), 2)),
- cA(pow((unsigned)sqrt(n), 2)),
- cp(pow((unsigned)sqrt(n), 2)),
- cq(pow((unsigned)sqrt(n), 2))
-{
+ma::ma(unsigned n, double a, double beta, double weight)
+ : sn(2 * n), ss(2 * n), sm(2 * n), sl(2 * n), sb(n + 1), sd(3 * n), sa(3 * n), sA(3 * n),
+ si(10000), sI(10000), cn(pow((unsigned)sqrt(n), 2)), cs(pow((unsigned)sqrt(n), 2)),
+ cm(pow((unsigned)sqrt(n), 2)), cl(pow((unsigned)sqrt(n), 2)), cb(pow((unsigned)sqrt(n), 2)),
+ ca(pow((unsigned)sqrt(n), 2)), cA(pow((unsigned)sqrt(n), 2)), cp(pow((unsigned)sqrt(n), 2)),
+ cq(pow((unsigned)sqrt(n), 2)) {
if (beta != 0.0) {
- model_string = "fracture_" + std::to_string(n) + "_" + std::to_string(a) + "_" + std::to_string(beta) + "_" + std::to_string(weight) + "_";
+ model_string = "fracture_" + std::to_string(n) + "_" + std::to_string(a) + "_" +
+ std::to_string(beta) + "_" + std::to_string(weight) + "_";
} else {
- model_string = "fracture_" + std::to_string(n) + "_" + std::to_string(a) + "_INF_" + std::to_string(weight) + "_";
+ model_string = "fracture_" + std::to_string(n) + "_" + std::to_string(a) + "_INF_" +
+ std::to_string(weight) + "_";
}
}
-ma::ma(unsigned Lx, unsigned Ly, double beta, double weight) :
- sn(Lx * Ly / 2),
- ss(Lx * Ly / 2),
- sm(Lx * Ly / 2),
- sl(Lx * Ly / 2),
- sb(Lx * Ly / 2 + 1),
- sd(Lx * Ly),
- sa(Lx * Ly),
- sA(Lx * Ly),
- si(10000),
- sI(10000),
- cn(Lx * Ly),
- cs(Lx * Ly),
- cm(Lx * Ly),
- cl(Lx * Ly),
- cb(Lx * Ly),
- ca(Lx * Ly),
- cA(Lx * Ly),
- cp(Lx * Ly),
- cq(Lx * Ly)
-{
+ma::ma(unsigned Lx, unsigned Ly, double beta, double weight)
+ : sn(Lx * Ly / 2), ss(Lx * Ly / 2), sm(Lx * Ly / 2), sl(Lx * Ly / 2), sb(Lx * Ly / 2 + 1),
+ sd(Lx * Ly), sa(Lx * Ly), sA(Lx * Ly), si(10000), sI(10000), cn(Lx * Ly), cs(Lx * Ly),
+ cm(Lx * Ly), cl(Lx * Ly), cb(Lx * Ly), ca(Lx * Ly), cA(Lx * Ly), cp(Lx * Ly), cq(Lx * Ly) {
if (beta != 0.0) {
- model_string = "fracture_" + std::to_string(Lx) + "_" + std::to_string(Ly) + "_" + std::to_string(beta) + "_" + std::to_string(weight) + "_";
+ model_string = "fracture_" + std::to_string(Lx) + "_" + std::to_string(Ly) + "_" +
+ std::to_string(beta) + "_" + std::to_string(weight) + "_";
} else {
- model_string = "fracture_" + std::to_string(Lx) + "_" + std::to_string(Ly) + "_INF_" + std::to_string(weight) + "_";
+ model_string = "fracture_" + std::to_string(Lx) + "_" + std::to_string(Ly) + "_INF_" +
+ std::to_string(weight) + "_";
}
}
@@ -237,9 +223,11 @@ void ma::bond_broken(const network& net, const current_info& cur, unsigned i) {
}
for (unsigned j = 0; j < cur.currents.size(); j++) {
- if (logl(cur.currents[j]) >= -100 && logl(cur.currents[j]) < 0 && (!net.backbone[j] || j == i)) {
+ if (logl(cur.currents[j]) >= -100 && logl(cur.currents[j]) < 0 &&
+ (!net.backbone[j] || j == i)) {
si[(unsigned)(10000 * (logl(cur.currents[j]) + 100) / 100)]++;
- } else if (logl(cur.currents[j]) >= -100 && logl(cur.currents[j]) < 0 && net.backbone[j] && j != i) {
+ } else if (logl(cur.currents[j]) >= -100 && logl(cur.currents[j]) < 0 && net.backbone[j] &&
+ j != i) {
sI[(unsigned)(10000 * (logl(cur.currents[j]) + 100) / 100)]++;
}
}
@@ -247,7 +235,7 @@ void ma::bond_broken(const network& net, const current_info& cur, unsigned i) {
num++;
}
-void ma::post_fracture(network &n) {
+void ma::post_fracture(network& n) {
auto crack = find_minimal_crack(n, avalanches.back().back());
std::list<graph::coordinate> cl_cs;
@@ -255,7 +243,8 @@ void ma::post_fracture(network &n) {
for (unsigned e : crack.second) {
cl_cs.push_back(n.G.dual_edges[e].r);
}
- autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cl.size()), 2 * sqrt(cl.size()), cl, cl_cs, crack.first);
+ autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cl.size()), 2 * sqrt(cl.size()), cl, cl_cs,
+ crack.first);
std::vector<std::list<graph::coordinate>> components(n.G.dual_vertices.size());
@@ -269,14 +258,18 @@ void ma::post_fracture(network &n) {
if (components[i].size() > 0) {
if (i != crack_component) {
sm[components[i].size() - 1]++;
- autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cm.size()), 2 * sqrt(cm.size()), cm, components[i], crack.first);
- autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cp.size()), 2 * sqrt(cp.size()), cp, components[i], {0, 1});
+ autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cm.size()), 2 * sqrt(cm.size()), cm,
+ components[i], crack.first);
+ autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cp.size()), 2 * sqrt(cp.size()), cp,
+ components[i], {0, 1});
} else {
ss[components[i].size() - 1]++;
- autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cs.size()), 2 * sqrt(cs.size()), cs, components[i], crack.first);
+ autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cs.size()), 2 * sqrt(cs.size()), cs,
+ components[i], crack.first);
}
sn[components[i].size() - 1]++;
- autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cn.size()), 2 * sqrt(cn.size()), cn, components[i], crack.first);
+ autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cn.size()), 2 * sqrt(cn.size()), cn,
+ components[i], crack.first);
}
}
@@ -301,7 +294,8 @@ void ma::post_fracture(network &n) {
}
sb[bb_size]++;
- autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cb.size()), 2 * sqrt(cb.size()), cb, cb_co, crack.first);
+ autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cb.size()), 2 * sqrt(cb.size()), cb, cb_co,
+ crack.first);
auto av_it = avalanches.rbegin();
av_it++;
@@ -312,8 +306,9 @@ void ma::post_fracture(network &n) {
for (unsigned e : (*av_it)) {
ca_co.push_back(n.G.edges[e].r);
}
- autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(ca.size()), 2 * sqrt(ca.size()), ca, ca_co, crack.first);
- autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cq.size()), 2 * sqrt(cq.size()), cq, ca_co, {0,1});
+ autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(ca.size()), 2 * sqrt(ca.size()), ca, ca_co,
+ crack.first);
+ autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cq.size()), 2 * sqrt(cq.size()), cq, ca_co, {0, 1});
av_it++;
}
@@ -322,7 +317,8 @@ void ma::post_fracture(network &n) {
for (unsigned e : avalanches.back()) {
cA_co.push_back(n.G.edges[e].r);
}
- autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cA.size()), 2 * sqrt(cA.size()), cA, cA_co, crack.first);
+ autocorrelation2(n.G.L.x, n.G.L.y, 2 * sqrt(cA.size()), 2 * sqrt(cA.size()), cA, cA_co,
+ crack.first);
sd[num - 1]++;
}