From 361ecc06948ccebb5bf4fe38bd9acb5f7531bcfa Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Tue, 24 Jul 2018 19:36:07 -0400 Subject: added clock model --- CMakeLists.txt | 12 +++- lib/dihedral.h | 20 +++---- src/wolff_clock.cpp | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+), 11 deletions(-) create mode 100644 src/wolff_clock.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 50bc708..b391bba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,12 +19,16 @@ add_executable(wolff_dgm src/wolff_dgm.cpp ${CPPSOURCES} ${CSOURCES}) add_executable(wolff_cgm src/wolff_cgm.cpp ${CPPSOURCES} ${CSOURCES}) add_executable(wolff_3potts src/wolff_potts.cpp ${CPPSOURCES} ${CSOURCES}) add_executable(wolff_4potts src/wolff_potts.cpp ${CPPSOURCES} ${CSOURCES}) +add_executable(wolff_3clock src/wolff_clock.cpp ${CPPSOURCES} ${CSOURCES}) +add_executable(wolff_5clock src/wolff_clock.cpp ${CPPSOURCES} ${CSOURCES}) add_executable(wolff_planar src/wolff_On.cpp ${CPPSOURCES} ${CSOURCES}) add_executable(wolff_heisenberg src/wolff_On.cpp ${CPPSOURCES} ${CSOURCES}) add_executable(analyze_correlations src/analyze_correlations.cpp ${CPPSOURCES} ${CSOURCES}) SET_TARGET_PROPERTIES(wolff_3potts PROPERTIES COMPILE_FLAGS "-DPOTTSQ=3") SET_TARGET_PROPERTIES(wolff_4potts PROPERTIES COMPILE_FLAGS "-DPOTTSQ=4") +SET_TARGET_PROPERTIES(wolff_3clock PROPERTIES COMPILE_FLAGS "-DPOTTSQ=3") +SET_TARGET_PROPERTIES(wolff_5clock PROPERTIES COMPILE_FLAGS "-DPOTTSQ=5") SET_TARGET_PROPERTIES(wolff_planar PROPERTIES COMPILE_FLAGS "-DN_COMP=2") SET_TARGET_PROPERTIES(wolff_heisenberg PROPERTIES COMPILE_FLAGS "-DN_COMP=3") @@ -43,6 +47,8 @@ if (${GLUT} MATCHES "GLUT-NOTFOUND") target_link_libraries(wolff_cgm cblas gsl m) target_link_libraries(wolff_3potts cblas gsl m) target_link_libraries(wolff_4potts cblas gsl m) + target_link_libraries(wolff_3clock cblas gsl m) + target_link_libraries(wolff_5clock cblas gsl m) target_link_libraries(wolff_heisenberg cblas gsl m) target_link_libraries(wolff_planar cblas gsl m) else() @@ -51,16 +57,20 @@ else() target_link_libraries(wolff_cgm cblas gsl m glut GL GLU) target_link_libraries(wolff_3potts cblas gsl m glut GL GLU) target_link_libraries(wolff_4potts cblas gsl m glut GL GLU) + target_link_libraries(wolff_3clock cblas gsl m glut GL GLU) + target_link_libraries(wolff_5clock cblas gsl m glut GL GLU) target_link_libraries(wolff_heisenberg cblas gsl m glut GL GLU) target_link_libraries(wolff_planar cblas gsl m glut GL GLU) target_compile_definitions(wolff_ising PUBLIC HAVE_GLUT) target_compile_definitions(wolff_dgm PUBLIC HAVE_GLUT) target_compile_definitions(wolff_cgm PUBLIC HAVE_GLUT) target_compile_definitions(wolff_3potts PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_3clock PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_5clock PUBLIC HAVE_GLUT) target_compile_definitions(wolff_4potts PUBLIC HAVE_GLUT) target_compile_definitions(wolff_planar PUBLIC HAVE_GLUT) target_compile_definitions(wolff_heisenberg PUBLIC HAVE_GLUT) endif() -install(TARGETS wolff_ising wolff_dgm wolff_cgm wolff_3potts wolff_4potts wolff_heisenberg wolff_planar analyze_correlations DESTINATION bin) +install(TARGETS wolff_ising wolff_dgm wolff_cgm wolff_3potts wolff_4potts wolff_3clock wolff_heisenberg wolff_planar analyze_correlations DESTINATION bin) diff --git a/lib/dihedral.h b/lib/dihedral.h index f547497..8238835 100644 --- a/lib/dihedral.h +++ b/lib/dihedral.h @@ -5,26 +5,26 @@ #include "potts.h" template -struct dihedral2_t { bool is_reflection; T x; }; +struct dihedral_t { bool is_reflection; T x; }; template -void init(dihedral2_t *ptr) { +void init(dihedral_t *ptr) { ptr->is_reflection = false; ptr->x = (T)0; } template -dihedral2_t copy(dihedral2_t r) { +dihedral_t copy(dihedral_t r) { return r; } template -void free_spin(dihedral2_t r) { +void free_spin(dihedral_t r) { // do nothing! } template -potts_t act(dihedral2_t r, potts_t s) { +potts_t act(dihedral_t r, potts_t s) { potts_t s2; if (r.is_reflection) { s2.x = ((q + r.x) - s.x) % q; @@ -36,8 +36,8 @@ potts_t act(dihedral2_t r, potts_t s) { } template -dihedral2_t act(dihedral2_t r1, dihedral2_t r2) { - dihedral2_t r3; +dihedral_t act(dihedral_t r1, dihedral_t r2) { + dihedral_t r3; if (r1.is_reflection) { r3.is_reflection = !(r2.is_reflection); @@ -51,7 +51,7 @@ dihedral2_t act(dihedral2_t r1, dihedral2_t r2) { } template -potts_t act_inverse(dihedral2_t r, potts_t s) { +potts_t act_inverse(dihedral_t r, potts_t s) { potts_t s2; if (r.is_reflection) { s2.x = ((r.x + q) - s.x) % q; @@ -63,8 +63,8 @@ potts_t act_inverse(dihedral2_t r, potts_t s) { } template -dihedral2_t act_inverse(dihedral2_t r1, dihedral2_t r2) { - dihedral2_t r3; +dihedral_t act_inverse(dihedral_t r1, dihedral_t r2) { + dihedral_t r3; if (r1.is_reflection) { r3.is_reflection = !(r2.is_reflection); diff --git a/src/wolff_clock.cpp b/src/wolff_clock.cpp new file mode 100644 index 0000000..e186c44 --- /dev/null +++ b/src/wolff_clock.cpp @@ -0,0 +1,154 @@ + +#include + +#ifdef HAVE_GLUT +#include +#endif + +// include your group and spin space +#include +#include +#include + +// hack to speed things up considerably +#define N_STATES POTTSQ +#include + +// include wolff.h +#include +#include + +typedef state_t , potts_t> sim_t; + +int main(int argc, char *argv[]) { + + count_t N = (count_t)1e4; + + D_t D = 2; + L_t L = 128; + double T = 2.26918531421; + double *H_vec = (double *)calloc(MAX_Q, sizeof(double)); + + bool silent = false; + bool draw = false; + unsigned int window_size = 512; + + int opt; + q_t H_ind = 0; + + while ((opt = getopt(argc, argv, "N:D:L:T:H:sdw:")) != -1) { + switch (opt) { + case 'N': // number of steps + N = (count_t)atof(optarg); + break; + case 'D': // dimension + D = atoi(optarg); + break; + case 'L': // linear size + L = atoi(optarg); + break; + case 'T': // temperature + T = atof(optarg); + break; + case 'H': // external field. nth call couples to state n + H_vec[H_ind] = atof(optarg); + H_ind++; + break; + case 's': // don't print anything during simulation. speeds up slightly + silent = true; + break; + case 'd': +#ifdef HAVE_GLUT + draw = true; + break; +#else + printf("You didn't compile this with the glut library installed!\n"); + exit(EXIT_FAILURE); +#endif + case 'w': + window_size = atoi(optarg); + break; + default: + exit(EXIT_FAILURE); + } + } + + // initialize random number generator + gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937); + gsl_rng_set(r, rand_seed()); + + // define spin-spin coupling + std::function , potts_t)> Z = [] (potts_t s1, potts_t s2) -> double { + return cos(2 * M_PI * (double)(s1.x + POTTSQ - s2.x) / (double)POTTSQ); + }; + + // define spin-field coupling + std::function )> B = [=] (potts_t s) -> double { + return H_vec[s.x]; + }; + + // initialize state object + state_t , potts_t> s(D, L, T, Z, B); + + // define function that generates self-inverse rotations + std::function (gsl_rng *, potts_t)> gen_R = [] (gsl_rng *r, potts_t v) -> dihedral_t { + dihedral_t rot; + rot.is_reflection = true; + q_t x = gsl_rng_uniform_int(r, POTTSQ - 1); + rot.x = (2 * v.x + x + 1) % POTTSQ; + + return rot; + }; + + // define function that updates any number of measurements + std::function measurement; + + double average_M = 0; + if (!draw) { + // a very simple example: measure the average magnetization + measurement = [&] (const sim_t *s) { + average_M += (double)s->M[0] / (double)N / (double)s->nv; + }; + } else { + // a more complex example: measure the average magnetization, and draw the spin configuration to the screen + +#ifdef HAVE_GLUT + // initialize glut + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize(window_size, window_size); + glutCreateWindow("wolff"); + glClearColor(0.0,0.0,0.0,0.0); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0.0, L, 0.0, L); + + measurement = [&] (const sim_t *s) { + average_M += (double)s->M[0] / (double)N / (double)s->nv; + glClear(GL_COLOR_BUFFER_BIT); + for (v_t i = 0; i < pow(L, 2); i++) { + potts_t tmp_s = act_inverse(s->R, s->spins[i]); + glColor3f(hue_to_R(tmp_s.x * 2 * M_PI / POTTSQ), hue_to_G(tmp_s.x * 2 * M_PI / POTTSQ), hue_to_B(tmp_s.x * 2 * M_PI / POTTSQ)); + glRecti(i / L, i % L, (i / L) + 1, (i % L) + 1); + } + glFlush(); + }; +#endif + } + + // run wolff for N cluster flips + wolff(N, &s, gen_R, measurement, r, silent); + + // tell us what we found! + printf("%" PRIcount " %d-Potts runs completed. D = %" PRID ", L = %" PRIL ", T = %g, H = %g, = %g\n", N, POTTSQ, D, L, T, H_vec[0], average_M); + + // free the random number generator + gsl_rng_free(r); + + if (draw) { + } + + return 0; + +} + -- cgit v1.2.3-70-g09d2