summaryrefslogtreecommitdiff
path: root/ising_animate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ising_animate.cpp')
-rw-r--r--ising_animate.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/ising_animate.cpp b/ising_animate.cpp
new file mode 100644
index 0000000..e6586d9
--- /dev/null
+++ b/ising_animate.cpp
@@ -0,0 +1,105 @@
+#include "ising.hpp"
+#include <GL/glut.h>
+
+class Animation : public measurement<signed, D, TorusGroup<signed, D>, signed> {
+private:
+ bool color;
+
+public:
+ Animation(double L, unsigned w, bool tcolor, int argc, char* argv[]) {
+ color = tcolor;
+
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
+ glutInitWindowSize(w, w);
+ glutCreateWindow("wolff");
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluOrtho2D(0, L, 0, L);
+ }
+
+ void post_cluster(const isingModel& m) override {
+ glClearColor(1.0, 1.0, 1.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ for (const Spin<signed, 2, signed>* s : m.s) {
+ if (s->s == 1) {
+ if (color)
+ glColor3f(1.0, 0.0, 0.0);
+ else
+ glColor3f(1.0, 1.0, 1.0);
+ } else if (s->s == -1) {
+ if (color)
+ glColor3f(0.0, 0.0, 1.0);
+ else
+ glColor3f(0.0, 0.0, 0.0);
+ }
+ Vector<signed, 2> xx = m.s0.inverse().act(*s).x;
+ glRecti(xx(0), xx(1), xx(0) + 1, xx(1) + 1);
+ }
+ glFlush();
+ }
+};
+
+int main(int argc, char* argv[]) {
+ unsigned L = 32;
+ unsigned N = 1000;
+ unsigned mod = 0;
+ double mag = 0.5;
+ double pop = 1.0;
+ double T = 2.0 / log(1.0 + sqrt(2.0));
+ double H = 1.0;
+ bool color = false;
+
+ int opt;
+
+ while ((opt = getopt(argc, argv, "N:L:T:H:m:r:p:c")) != -1) {
+ switch (opt) {
+ case 'N':
+ N = (unsigned)atof(optarg);
+ break;
+ case 'L':
+ L = atoi(optarg);
+ break;
+ case 'T':
+ T = atof(optarg);
+ break;
+ case 'H':
+ H = atof(optarg);
+ break;
+ case 'm':
+ mod = atoi(optarg);
+ break;
+ case 'r':
+ mag = atof(optarg);
+ break;
+ case 'p':
+ pop = atof(optarg);
+ break;
+ case 'c':
+ color = true;
+ break;
+ default:
+ exit(1);
+ }
+ }
+
+ std::function<double(Spin<signed, D, signed>)> B;
+
+ if (mod == 0) {
+ B = isingBFace(L, H);
+ } else {
+ B = isingBMod(L, mod, H);
+ }
+
+ isingModel ising(L, isingZ(L), B);
+ isingPopulate(ising, L, pop, mag);
+
+ auto g = isingGen(L);
+
+ Animation A(L, 750, color, argc, argv);
+
+ ising.wolff(T, {g}, A, N);
+
+ return 0;
+}