summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2019-01-24 18:55:36 -0500
committerJaron Kent-Dobias <jaron@kent-dobias.com>2019-01-24 18:55:36 -0500
commitc83636a1b56b331cf4ea16450dcf637e6e9fae8a (patch)
tree412fb957e177c667213baee2af44d9a2ed01a81b
parent2b9a37884b27e272c48c3c44e4ddd0d091b7f16d (diff)
downloadfuse_networks-c83636a1b56b331cf4ea16450dcf637e6e9fae8a.tar.gz
fuse_networks-c83636a1b56b331cf4ea16450dcf637e6e9fae8a.tar.bz2
fuse_networks-c83636a1b56b331cf4ea16450dcf637e6e9fae8a.zip
added square lattice animation, and fixed the animation library to handle non-triangle cells
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/animate.cpp49
-rw-r--r--src/animate_fracture_square.cpp81
3 files changed, 109 insertions, 24 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cc93881..4d4099f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -17,3 +17,6 @@ target_link_libraries(fracture_square frac measurements fftw3 cholmod profiler G
add_executable(animate_fracture animate_fracture.cpp)
target_link_libraries(animate_fracture frac animate fftw3 cholmod profiler GL GLU glut)
+add_executable(animate_fracture_square animate_fracture_square.cpp)
+target_link_libraries(animate_fracture_square frac animate fftw3 cholmod profiler GL GLU glut)
+
diff --git a/src/animate.cpp b/src/animate.cpp
index a24f0f2..4f10e0a 100644
--- a/src/animate.cpp
+++ b/src/animate.cpp
@@ -135,22 +135,22 @@ void animate::post_fracture(network &n) {
switch (key) {
case 's' :
for (auto edge : crack) {
- glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
- glVertex2d(n.G.dual_vertices[n.G.dual_edges[edge].v[0]].polygon[0].x, n.G.dual_vertices[n.G.dual_edges[edge].v[0]].polygon[0].y);
- glVertex2d(n.G.dual_vertices[n.G.dual_edges[edge].v[0]].polygon[1].x, n.G.dual_vertices[n.G.dual_edges[edge].v[0]].polygon[1].y);
- glVertex2d(n.G.dual_vertices[n.G.dual_edges[edge].v[0]].polygon[2].x, n.G.dual_vertices[n.G.dual_edges[edge].v[0]].polygon[2].y);
-
- glVertex2d(n.G.dual_vertices[n.G.dual_edges[edge].v[1]].polygon[0].x, n.G.dual_vertices[n.G.dual_edges[edge].v[1]].polygon[0].y);
- glVertex2d(n.G.dual_vertices[n.G.dual_edges[edge].v[1]].polygon[1].x, n.G.dual_vertices[n.G.dual_edges[edge].v[1]].polygon[1].y);
- glVertex2d(n.G.dual_vertices[n.G.dual_edges[edge].v[1]].polygon[2].x, n.G.dual_vertices[n.G.dual_edges[edge].v[1]].polygon[2].y);
+ glBegin(GL_POLYGON);
+ for (const graph::coordinate &r : n.G.dual_vertices[n.G.dual_edges[edge].v[0]].polygon) {
+ glVertex2d(r.x, r.y);
+ }
+ glEnd();
+ glBegin(GL_POLYGON);
+ for (const graph::coordinate &r : n.G.dual_vertices[n.G.dual_edges[edge].v[1]].polygon) {
+ glVertex2d(r.x, r.y);
+ }
glEnd();
}
glFlush();
break;
case 'c' :
- glBegin(GL_TRIANGLES); // Each set of 3 vertices form a triangle
for (unsigned int i = 0; i < num; i++) {
if (i == crack_component) {
glColor3d(1.0, 0.0, 0.0);
@@ -159,17 +159,17 @@ void animate::post_fracture(network &n) {
}
for (auto it = components[i].begin(); it != components[i].end(); it++) {
- glVertex2d(n.G.dual_vertices[*it].polygon[0].x, n.G.dual_vertices[*it].polygon[0].y);
- glVertex2d(n.G.dual_vertices[*it].polygon[1].x, n.G.dual_vertices[*it].polygon[1].y);
- glVertex2d(n.G.dual_vertices[*it].polygon[2].x, n.G.dual_vertices[*it].polygon[2].y);
+ glBegin(GL_POLYGON); // Each set of 3 vertices form a triangle
+ for (const graph::coordinate &r: n.G.dual_vertices[*it].polygon) {
+ glVertex2d(r.x, r.y);
+ }
+ glEnd();
}
}
- glEnd();
glFlush();
break;
case 'C' :
- glBegin(GL_TRIANGLES); // Each set of 3 vertices form a triangle
for (unsigned int i = 0; i < num; i++) {
if (components[i].size() > 1) {
if (i == crack_component) {
@@ -179,25 +179,26 @@ void animate::post_fracture(network &n) {
}
for (auto it = components[i].begin(); it != components[i].end(); it++) {
- glVertex2d(n.G.dual_vertices[*it].polygon[0].x, n.G.dual_vertices[*it].polygon[0].y);
- glVertex2d(n.G.dual_vertices[*it].polygon[1].x, n.G.dual_vertices[*it].polygon[1].y);
- glVertex2d(n.G.dual_vertices[*it].polygon[2].x, n.G.dual_vertices[*it].polygon[2].y);
+ glBegin(GL_POLYGON); // Each set of 3 vertices form a triangle
+ for (const graph::coordinate &r :n.G.dual_vertices[*it].polygon) {
+ glVertex2d(r.x, r.y);
+ }
+ glEnd();
}
}
}
- glEnd();
glFlush();
break;
case 'm' :
- glBegin(GL_TRIANGLES);
- glColor3d(1.0, 0.0, 0.0);
for (auto it = components[crack_component].begin(); it != components[crack_component].end(); it++) {
- glVertex2d(n.G.dual_vertices[*it].polygon[0].x, n.G.dual_vertices[*it].polygon[0].y);
- glVertex2d(n.G.dual_vertices[*it].polygon[1].x, n.G.dual_vertices[*it].polygon[1].y);
- glVertex2d(n.G.dual_vertices[*it].polygon[2].x, n.G.dual_vertices[*it].polygon[2].y);
- }
+ glBegin(GL_POLYGON);
+ glColor3d(1.0, 0.0, 0.0);
+ for (const graph::coordinate &r :n.G.dual_vertices[*it].polygon) {
+ glVertex2d(r.x, r.y);
+ }
glEnd();
+ }
glFlush();
}
}
diff --git a/src/animate_fracture_square.cpp b/src/animate_fracture_square.cpp
new file mode 100644
index 0000000..512486f
--- /dev/null
+++ b/src/animate_fracture_square.cpp
@@ -0,0 +1,81 @@
+
+#include <random>
+#include <iostream>
+
+#include <cholmod.h>
+
+#include "randutils/randutils.hpp"
+
+#include <graph.hpp>
+#include <network.hpp>
+#include <hooks.hpp>
+#include "animate.hpp"
+
+#include <csignal>
+#include <cstring>
+#include <atomic>
+
+std::atomic<bool> quit(false); // signal flag
+
+void got_signal(int) {
+ quit.store(true);
+}
+
+int main(int argc, char* argv[]) {
+ struct sigaction sa;
+ memset( &sa, 0, sizeof(sa) );
+ sa.sa_handler = got_signal;
+ sigfillset(&sa.sa_mask);
+ sigaction(SIGINT, &sa, NULL);
+
+ int opt;
+
+ unsigned int N = 1;
+ unsigned Lx = 16;
+ unsigned Ly = 16;
+ double beta = 0.5;
+
+ while ((opt = getopt(argc, argv, "X:Y:N:b:")) != -1) {
+ switch (opt) {
+ case 'N':
+ N = (unsigned int)atof(optarg);
+ break;
+ case 'X':
+ Lx = atoi(optarg);
+ break;
+ case 'Y':
+ Ly = atoi(optarg);
+ break;
+ case 'b':
+ beta = atof(optarg);
+ break;
+ default:
+ exit(1);
+ }
+ }
+
+ cholmod_common c;
+ CHOL_F(start)(&c);
+
+ animate meas(Lx, Ly, 512, argc, argv);
+
+ randutils::auto_seed_128 seeds;
+ std::mt19937 rng{seeds};
+
+ graph G(Lx, Ly);
+ network perm_network(G, &c);
+
+ for (unsigned int trial = 0; trial < N; trial++) {
+ network tmp_network(perm_network);
+ tmp_network.set_thresholds(beta, rng);
+ tmp_network.fracture(meas);
+
+ if (quit.load())
+ break;
+ }
+
+ CHOL_F(finish)(&c);
+
+ return 0;
+}
+