summaryrefslogtreecommitdiff
path: root/src/sample.cpp
blob: febff19b487326387ecb672f47d616e5ef4f19cc (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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 <<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\"->{";
}

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] << "},";
}

void sample::post_fracture(network &n) {
  sample_file << "}";
  sample_file << "|>\n";
}