summaryrefslogtreecommitdiff
path: root/src/sample.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sample.cpp')
-rw-r--r--src/sample.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/sample.cpp b/src/sample.cpp
new file mode 100644
index 0000000..b8af937
--- /dev/null
+++ b/src/sample.cpp
@@ -0,0 +1,69 @@
+
+#include "sample.hpp"
+#include <iostream>
+#include <cstdio>
+
+sample::sample(double Lx, double Ly, double beta) {
+ std::string filename = "fracture_" + std::to_string(Lx) + "_" + std::to_string(Ly) + "_" + std::to_string(beta) + "_sample.dat";
+ sample_file.open(filename, std::ifstream::app);
+}
+
+sample::~sample() {
+ sample_file.close();
+}
+
+void sample::pre_fracture(const network& n) {
+ sample_file << "<|";
+ sample_file << "\"vr\"->{";
+ for (const graph::vertex &v : n.G.vertices) {
+ sample_file << "{" << v.r.x << "," << v.r.y << "},";
+ }
+ sample_file << "},\"vp\"->{";
+ for (const graph::vertex &v : n.G.vertices) {
+ sample_file << "{";
+ for (const graph::coordinate &r : v.polygon) {
+ sample_file << "{" << r.x << "," << r.y << "},";
+ }
+ sample_file << "},";
+ }
+ sample_file << "},\"ur\"->{";
+ for (const graph::vertex &v : n.G.dual_vertices) {
+ sample_file << "{" << v.r.x << "," << v.r.y << "},";
+ }
+ sample_file << "},\"up\"->{";
+ for (const graph::vertex &v : n.G.dual_vertices) {
+ sample_file << "{";
+ for (const graph::coordinate &r : v.polygon) {
+ sample_file << "{" << r.x << "," << r.y << "},";
+ }
+ sample_file << "},";
+ }
+ sample_file << "},\"e\"->{";
+ for (const graph::edge &e : n.G.edges) {
+ sample_file << "{" << e.v[0] << "," << e.v[1] << "},";
+ }
+ sample_file << "},\"ec\"->{";
+ for (const graph::edge &e : n.G.edges) {
+ sample_file << "{" << e.crossings[0] << "," << e.crossings[1] << "},";
+ }
+ sample_file << "},\"d\"->{";
+ for (const graph::edge &e : n.G.dual_edges) {
+ sample_file << "{" << e.v[0] << "," << e.v[1] << "},";
+ }
+ sample_file << "},\"dc\"->{";
+ for (const graph::edge &e : n.G.dual_edges) {
+ sample_file << "{" << e.crossings[0] << "," << e.crossings[1] << "},";
+ }
+ sample_file << "},\"data\"->{";
+}
+
+void sample::bond_broken(const network& net, const current_info& cur, unsigned i) {
+ long double c = logl(cur.conductivity / fabs(cur.currents[i])) + net.thresholds[i];
+ sample_file << "{" << i << "," << c << "," << cur.conductivity << "},";
+}
+
+void sample::post_fracture(network &n) {
+ sample_file << "}";
+ sample_file << "|>\n";
+}
+