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 --- CMakeLists.txt | 2 +- lib/cluster.h | 2 -- lib/ising.h | 1 + src/wolff_ising.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 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 +#include #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 +#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