summaryrefslogtreecommitdiff
path: root/lib/include/network.hpp
blob: 15cb8eae594c7595ac287e754be15fb607606616 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

#pragma once

#include <vector>
#include <functional>
#include <utility>
#include <random>
#include <limits>

#include <cholmod.h>

#include "graph.hpp"
#include "hooks.hpp"
#include "current_info.hpp"
#include "array_hash.hpp"

#ifdef FRACTURE_LONGINT

#define CHOL_F(x) cholmod_l_##x
#define CHOL_INT long int

#else

#define CHOL_F(x) cholmod_##x
#define CHOL_INT int

#endif

class problem {
  private:
    const graph& G;
    cholmod_dense* b;
    cholmod_factor* factor;
    cholmod_sparse* voltcurmat;
    cholmod_common* c;
    unsigned axis;

  public:
    problem(const graph&, unsigned axis, cholmod_common*);
    problem(const graph&, unsigned axis, cholmod_sparse*, cholmod_common*);
    problem(const problem&);
    ~problem();
    current_info solve(std::vector<bool>& fuses);
    void break_edge(unsigned, bool unbreak = false);
};

class network {
  public:
    const graph& G;
    std::vector<bool> fuses;
    std::vector<long double> thresholds;

    network(const graph&);
    network(const network&);

    void set_thresholds(double, std::mt19937&);
    virtual void break_edge(unsigned e, bool unbreak = false) {fuses[e] = !unbreak;};
    virtual current_info get_current_info() {current_info empty; return empty;};
};

class fuse_network : public network {
  public:
    problem ohm;

    fuse_network(const graph&, cholmod_common*);

    void fracture(hooks&, double cutoff = 1e-13);
};

class elastic_network : public network {
  private:
    double weight;
  public:
    problem hook_x;
    problem hook_y;

    elastic_network(const graph&, cholmod_common*);
    elastic_network(const elastic_network&);

    void fracture(hooks&, double weight = 0.5, double cutoff = 1e-10);
    void break_edge(unsigned, bool unbreak = false) override;
    current_info get_current_info() override;
};

class percolation_network : public network {
  private:
    double weight;
  public:
    problem hook_x;
    problem hook_y;

    percolation_network(const graph&, cholmod_common*);
    percolation_network(const percolation_network&);

    void fracture(hooks&, double weight = 0.5, double cutoff = 1e-10);
    void break_edge(unsigned, bool unbreak = false) override;
    current_info get_current_info() override;
};