summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-21 14:54:13 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-21 14:54:13 -0400
commit0af22d23f860d7ab1c0e9355f55cade310afd748 (patch)
tree3a3e06e26466f87f0e4239c6db52907b2f36b102
parent6b8448e5f80a7fa623678c532d1cceba0d19ac11 (diff)
downloadc++-0af22d23f860d7ab1c0e9355f55cade310afd748.tar.gz
c++-0af22d23f860d7ab1c0e9355f55cade310afd748.tar.bz2
c++-0af22d23f860d7ab1c0e9355f55cade310afd748.zip
ising example now has a setting for drawing the state to the screen
-rw-r--r--CMakeLists.txt2
-rw-r--r--lib/cluster.h2
-rw-r--r--lib/ising.h1
-rw-r--r--src/wolff_ising.cpp52
4 files changed, 50 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f9ee423..b225d39 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,7 +29,7 @@ if (OPENMP_FOUND)
endif()
target_link_libraries(wolff_finite gsl cblas fftw3 m)
-target_link_libraries(wolff_ising gsl cblas fftw3 m)
+target_link_libraries(wolff_ising gsl cblas fftw3 m glut GL GLU)
target_link_libraries(wolff_heisenberg gsl cblas fftw3 m)
target_link_libraries(wolff_planar gsl cblas fftw3 m)
target_link_libraries(analyze_correlations gsl cblas fftw3 m)
diff --git a/lib/cluster.h b/lib/cluster.h
index d90dc64..cc2dc70 100644
--- a/lib/cluster.h
+++ b/lib/cluster.h
@@ -23,8 +23,6 @@
#include "measurement.h"
#include "vector.h"
#include "orthogonal.h"
-#include "ising.h"
-#include "z2.h"
#include "dihedral.h"
#include "dihinf.h"
#include "yule_walker.h"
diff --git a/lib/ising.h b/lib/ising.h
index e09b39e..4ad88f4 100644
--- a/lib/ising.h
+++ b/lib/ising.h
@@ -1,6 +1,7 @@
#pragma once
#include <cmath>
+#include <stdio.h>
#include "types.h"
diff --git a/src/wolff_ising.cpp b/src/wolff_ising.cpp
index e9d0185..f4073da 100644
--- a/src/wolff_ising.cpp
+++ b/src/wolff_ising.cpp
@@ -1,6 +1,12 @@
#include <getopt.h>
+#include <GL/glut.h>
+// include your group and spin space
+#include <z2.h>
+#include <ising.h>
+
+// include wolff.h
#include <wolff.h>
int main(int argc, char *argv[]) {
@@ -13,10 +19,11 @@ int main(int argc, char *argv[]) {
double H = 0.0;
bool silent = false;
+ bool draw = false;
int opt;
- while ((opt = getopt(argc, argv, "N:q:D:L:T:J:H:s")) != -1) {
+ while ((opt = getopt(argc, argv, "N:D:L:T:H:sd")) != -1) {
switch (opt) {
case 'N': // number of steps
N = (count_t)atof(optarg);
@@ -36,6 +43,9 @@ int main(int argc, char *argv[]) {
case 's': // don't print anything during simulation. speeds up slightly
silent = true;
break;
+ case 'd':
+ draw = true;
+ break;
default:
exit(EXIT_FAILURE);
}
@@ -74,10 +84,41 @@ int main(int argc, char *argv[]) {
};
// define function that updates any number of measurements
+ std::function <void(const state_t <z2_t, ising_t> *)> measurement;
+
double average_M = 0;
- std::function <void(const state_t <z2_t, ising_t> *)> measurement = [&] (const state_t <z2_t, ising_t> *s) {
- average_M += (double)s->M / (double)N / (double)s->nv;
- };
+ if (!draw) {
+ // a very simple example: measure the average magnetization
+ measurement = [&] (const state_t <z2_t, ising_t> *s) {
+ average_M += (double)s->M / (double)N / (double)s->nv;
+ };
+ } else {
+ // a more complex example: measure the average magnetization, and draw the spin configuration to the screen
+
+ // initialize glut
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
+ glutInitWindowSize(L,L);
+ glutCreateWindow("null");
+ glClearColor(0.0,0.0,0.0,0.0);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluOrtho2D(0.0, L, 0.0, L);
+
+ measurement = [&] (const state_t <z2_t, ising_t> *s) {
+ average_M += (double)s->M / (double)N / (double)s->nv;
+ glClear(GL_COLOR_BUFFER_BIT);
+ for (v_t i = 0; i < pow(L, 2); i++) {
+ if (s->spins[i].x == s->R.x) {
+ glColor3f(0.0, 0.0, 0.0);
+ } else {
+ glColor3f(1.0, 1.0, 1.0);
+ }
+ glRecti(i / L, i % L, (i / L) + 1, (i % L) + 1);
+ }
+ glFlush();
+ };
+ }
// run wolff for N cluster flips
wolff(N, &s, gen_R, measurement, r, silent);
@@ -88,6 +129,9 @@ int main(int argc, char *argv[]) {
// free the random number generator
gsl_rng_free(r);
+ if (draw) {
+ }
+
return 0;
}