summaryrefslogtreecommitdiff
path: root/lib/include
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-11-01 12:33:37 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-11-01 12:33:37 -0400
commit07906baa42470bad14d2c40f57967691f6118969 (patch)
tree416ae624829967861c7c799103b3ff795e9e36b4 /lib/include
parent8c4c42d81745ea33c31150fe22e834d97e29ede6 (diff)
downloadfuse_networks-07906baa42470bad14d2c40f57967691f6118969.tar.gz
fuse_networks-07906baa42470bad14d2c40f57967691f6118969.tar.bz2
fuse_networks-07906baa42470bad14d2c40f57967691f6118969.zip
revamped and simplied fracture code with c++
Diffstat (limited to 'lib/include')
-rw-r--r--lib/include/graph.hpp29
-rw-r--r--lib/include/hooks.hpp12
-rw-r--r--lib/include/network.hpp48
3 files changed, 89 insertions, 0 deletions
diff --git a/lib/include/graph.hpp b/lib/include/graph.hpp
new file mode 100644
index 0000000..80cdd66
--- /dev/null
+++ b/lib/include/graph.hpp
@@ -0,0 +1,29 @@
+
+#pragma once
+
+#include <cmath>
+#include <vector>
+#include <array>
+
+class graph {
+ public:
+ typedef struct coordinate {
+ double x;
+ double y;
+ } coordinate;
+
+ typedef struct vertex {
+ coordinate r;
+ } vertex;
+
+ typedef std::array<unsigned int, 2> edge;
+
+ std::vector<vertex> vertices;
+ std::vector<edge> edges;
+
+ std::vector<vertex> dual_vertices;
+ std::vector<edge> dual_edges;
+
+ graph(unsigned int L);
+};
+
diff --git a/lib/include/hooks.hpp b/lib/include/hooks.hpp
new file mode 100644
index 0000000..350f318
--- /dev/null
+++ b/lib/include/hooks.hpp
@@ -0,0 +1,12 @@
+
+#pragma once
+
+class network;
+
+class hooks {
+ public:
+ virtual void pre_fracture(const network&) {};
+ virtual void bond_broken(const network&, const std::pair<double, std::vector<double>>&, unsigned int) {};
+ virtual void post_fracture(network&) {}; // post fracture hook can be destructive
+};
+
diff --git a/lib/include/network.hpp b/lib/include/network.hpp
new file mode 100644
index 0000000..abf88cd
--- /dev/null
+++ b/lib/include/network.hpp
@@ -0,0 +1,48 @@
+
+#pragma once
+
+#include <vector>
+#include <functional>
+#include <utility>
+#include <random>
+
+#include "cholmod.h"
+
+#include "graph.hpp"
+#include "hooks.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 network {
+ private:
+ cholmod_dense *b;
+ cholmod_factor *factor;
+ cholmod_sparse *voltcurmat;
+ cholmod_common *c;
+
+ public:
+ const graph& G;
+ std::vector<bool> fuses;
+ std::vector<long double> thresholds;
+
+ network(const graph&, cholmod_common*);
+ network(const network &other);
+ ~network();
+
+ void set_thresholds(double, std::mt19937&);
+ void break_edge(unsigned int);
+ void add_edge(unsigned int);
+ std::pair<double, std::vector<double>> currents();
+ void fracture(hooks&, double cutoff = 1e-13);
+};
+