summaryrefslogtreecommitdiff
path: root/src/sample.cpp
blob: e7ca09b182759188c841f86f68d00caeb549ecaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

#include "sample.hpp"
#include <iostream>
#include <cstdio>

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);
}

sample::~sample() {
  sample_file.close();
}

void sample::pre_fracture(const network& n) {
  sample_file << "<|";
  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_string += "{" + std::to_string(i) + "," + std::to_string(c) + "," + std::to_string(cur.conductivity[0]) + "},";
}

void sample::post_fracture(network &n) {
  sample_string.pop_back();
  sample_file << sample_string + "}";
  sample_file << "|>\n";
  sample_string.clear();
}