From 0af22d23f860d7ab1c0e9355f55cade310afd748 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sat, 21 Jul 2018 14:54:13 -0400 Subject: ising example now has a setting for drawing the state to the screen --- src/wolff_ising.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) (limited to 'src/wolff_ising.cpp') 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 +#include +// include your group and spin space +#include +#include + +// include wolff.h #include 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 *)> measurement; + double average_M = 0; - std::function *)> measurement = [&] (const state_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 *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 *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; } -- cgit v1.2.3-70-g09d2