diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-07-24 19:36:07 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-07-24 19:36:07 -0400 |
commit | 361ecc06948ccebb5bf4fe38bd9acb5f7531bcfa (patch) | |
tree | fd646d3ccf6361c4acfaadab660b42b91bf72d48 | |
parent | dbae5cf4f9b80edc8d089475d5de4c13478c4f40 (diff) | |
download | c++-361ecc06948ccebb5bf4fe38bd9acb5f7531bcfa.tar.gz c++-361ecc06948ccebb5bf4fe38bd9acb5f7531bcfa.tar.bz2 c++-361ecc06948ccebb5bf4fe38bd9acb5f7531bcfa.zip |
added clock model
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | lib/dihedral.h | 20 | ||||
-rw-r--r-- | src/wolff_clock.cpp | 154 |
3 files changed, 175 insertions, 11 deletions
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 <class T, q_t q> -struct dihedral2_t { bool is_reflection; T x; }; +struct dihedral_t { bool is_reflection; T x; }; template <class T, q_t q> -void init(dihedral2_t<T, q> *ptr) { +void init(dihedral_t<T, q> *ptr) { ptr->is_reflection = false; ptr->x = (T)0; } template <class T, q_t q> -dihedral2_t<T, q> copy(dihedral2_t<T, q> r) { +dihedral_t<T, q> copy(dihedral_t<T, q> r) { return r; } template <class T, q_t q> -void free_spin(dihedral2_t<T, q> r) { +void free_spin(dihedral_t<T, q> r) { // do nothing! } template <q_t q> -potts_t<q> act(dihedral2_t<q_t, q> r, potts_t<q> s) { +potts_t<q> act(dihedral_t<q_t, q> r, potts_t<q> s) { potts_t<q> s2; if (r.is_reflection) { s2.x = ((q + r.x) - s.x) % q; @@ -36,8 +36,8 @@ potts_t<q> act(dihedral2_t<q_t, q> r, potts_t<q> s) { } template <q_t q> -dihedral2_t<q_t,q> act(dihedral2_t<q_t,q> r1, dihedral2_t<q_t,q> r2) { - dihedral2_t<q_t,q> r3; +dihedral_t<q_t,q> act(dihedral_t<q_t,q> r1, dihedral_t<q_t,q> r2) { + dihedral_t<q_t,q> r3; if (r1.is_reflection) { r3.is_reflection = !(r2.is_reflection); @@ -51,7 +51,7 @@ dihedral2_t<q_t,q> act(dihedral2_t<q_t,q> r1, dihedral2_t<q_t,q> r2) { } template <q_t q> -potts_t<q> act_inverse(dihedral2_t<q_t,q> r, potts_t<q> s) { +potts_t<q> act_inverse(dihedral_t<q_t,q> r, potts_t<q> s) { potts_t<q> s2; if (r.is_reflection) { s2.x = ((r.x + q) - s.x) % q; @@ -63,8 +63,8 @@ potts_t<q> act_inverse(dihedral2_t<q_t,q> r, potts_t<q> s) { } template <q_t q> -dihedral2_t<q_t, q> act_inverse(dihedral2_t<q_t,q> r1, dihedral2_t<q_t,q> r2) { - dihedral2_t<q_t,q> r3; +dihedral_t<q_t, q> act_inverse(dihedral_t<q_t,q> r1, dihedral_t<q_t,q> r2) { + dihedral_t<q_t,q> 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 <getopt.h> + +#ifdef HAVE_GLUT +#include <GL/glut.h> +#endif + +// include your group and spin space +#include <dihedral.h> +#include <potts.h> +#include <colors.h> + +// hack to speed things up considerably +#define N_STATES POTTSQ +#include <finite_states.h> + +// include wolff.h +#include <rand.h> +#include <wolff.h> + +typedef state_t <dihedral_t<q_t,POTTSQ>, potts_t<POTTSQ>> 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 <double(potts_t<POTTSQ>, potts_t<POTTSQ>)> Z = [] (potts_t<POTTSQ> s1, potts_t<POTTSQ> s2) -> double { + return cos(2 * M_PI * (double)(s1.x + POTTSQ - s2.x) / (double)POTTSQ); + }; + + // define spin-field coupling + std::function <double(potts_t<POTTSQ>)> B = [=] (potts_t<POTTSQ> s) -> double { + return H_vec[s.x]; + }; + + // initialize state object + state_t <dihedral_t<q_t,POTTSQ>, potts_t<POTTSQ>> s(D, L, T, Z, B); + + // define function that generates self-inverse rotations + std::function <dihedral_t<q_t,POTTSQ>(gsl_rng *, potts_t<POTTSQ>)> gen_R = [] (gsl_rng *r, potts_t<POTTSQ> v) -> dihedral_t<q_t,POTTSQ> { + dihedral_t<q_t,POTTSQ> 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 <void(const sim_t *)> 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<POTTSQ> 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, <M> = %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; + +} + |