From 07906baa42470bad14d2c40f57967691f6118969 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 1 Nov 2018 12:33:37 -0400 Subject: revamped and simplied fracture code with c++ --- lib/include/graph.hpp | 29 +++++++++++++++++++++++++++++ lib/include/hooks.hpp | 12 ++++++++++++ lib/include/network.hpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 lib/include/graph.hpp create mode 100644 lib/include/hooks.hpp create mode 100644 lib/include/network.hpp (limited to 'lib/include') 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 +#include +#include + +class graph { + public: + typedef struct coordinate { + double x; + double y; + } coordinate; + + typedef struct vertex { + coordinate r; + } vertex; + + typedef std::array edge; + + std::vector vertices; + std::vector edges; + + std::vector dual_vertices; + std::vector 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>&, 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 +#include +#include +#include + +#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 fuses; + std::vector 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> currents(); + void fracture(hooks&, double cutoff = 1e-13); +}; + -- cgit v1.2.3-70-g09d2