summaryrefslogtreecommitdiff
path: root/src/sample.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sample.cpp')
-rw-r--r--src/sample.cpp58
1 files changed, 13 insertions, 45 deletions
diff --git a/src/sample.cpp b/src/sample.cpp
index febff19..e7ca09b 100644
--- a/src/sample.cpp
+++ b/src/sample.cpp
@@ -3,8 +3,13 @@
#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::sample(unsigned n, double a, double beta) {
+ std::string filename = "sample_" + std::to_string(n) + "_" + std::to_string(a) + "_" + std::to_string(beta) + ".dat";
+ sample_file.open(filename, std::ifstream::app);
+}
+
+sample::sample(unsigned Lx, unsigned Ly, double beta) {
+ std::string filename = "sample_" + std::to_string(Lx) + "_" + std::to_string(Ly) + "_" + std::to_string(beta) + ".dat";
sample_file.open(filename, std::ifstream::app);
}
@@ -14,56 +19,19 @@ sample::~sample() {
void sample::pre_fracture(const network& n) {
sample_file << "<|";
- sample_file << "\"vr\"->{";
- for (const graph::vertex &v : n.G.vertices) {
- sample_file <<std::fixed<< "{" << 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 <<std::fixed<< "{" << r.x << "," << r.y << "},";
- }
- sample_file << "},";
- }
- sample_file << "},\"ur\"->{";
- for (const graph::vertex &v : n.G.dual_vertices) {
- sample_file <<std::fixed<< "{" << 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 <<std::fixed<< "{" << 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\"->{";
+ sample_file << n.G.write();
+ sample_file << ",\"data\"->{";
}
void sample::bond_broken(const network& net, const current_info& cur, unsigned i) {
long double c = logl(cur.conductivity[0] / fabs(cur.currents[i])) + net.thresholds[i];
- sample_file << "{" << i << "," << c << "," << cur.conductivity[0] << "},";
+ sample_string += "{" + std::to_string(i) + "," + std::to_string(c) + "," + std::to_string(cur.conductivity[0]) + "},";
}
void sample::post_fracture(network &n) {
- sample_file << "}";
+ sample_string.pop_back();
+ sample_file << sample_string + "}";
sample_file << "|>\n";
+ sample_string.clear();
}