diff options
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | lib/cluster.h | 65 | ||||
-rw-r--r-- | lib/correlation.h | 8 | ||||
-rw-r--r-- | lib/measure.h | 10 | ||||
-rw-r--r-- | lib/wolff.h | 12 | ||||
-rw-r--r-- | lib/z2.h | 8 | ||||
-rw-r--r-- | src/wolff_O2.cpp | 278 | ||||
-rw-r--r-- | src/wolff_On.cpp | 18 | ||||
-rw-r--r-- | src/wolff_cgm.cpp | 16 | ||||
-rw-r--r-- | src/wolff_clock.cpp | 14 | ||||
-rw-r--r-- | src/wolff_dgm.cpp | 16 | ||||
-rw-r--r-- | src/wolff_ising.cpp | 22 | ||||
-rw-r--r-- | src/wolff_potts.cpp | 22 |
13 files changed, 107 insertions, 386 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 12fe087..fe564f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,6 @@ add_executable(wolff_4potts src/wolff_potts.cpp ${CPPSOURCES} ${CSOURCES}) add_executable(wolff_7potts 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_planar2 src/wolff_O2.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}) @@ -55,7 +54,6 @@ if (${GLUT} MATCHES "GLUT-NOTFOUND") target_link_libraries(wolff_5clock cblas gsl m) target_link_libraries(wolff_heisenberg cblas gsl m) target_link_libraries(wolff_planar cblas gsl m) - target_link_libraries(wolff_planar2 cblas gsl m) else() target_link_libraries(wolff_ising cblas gsl m glut GL GLU) target_link_libraries(wolff_dgm cblas gsl m glut GL GLU) @@ -67,7 +65,6 @@ else() 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_link_libraries(wolff_planar2 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) @@ -77,7 +74,6 @@ else() target_compile_definitions(wolff_3clock PUBLIC HAVE_GLUT) target_compile_definitions(wolff_5clock PUBLIC HAVE_GLUT) target_compile_definitions(wolff_planar PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_planar2 PUBLIC HAVE_GLUT) target_compile_definitions(wolff_heisenberg PUBLIC HAVE_GLUT) endif() diff --git a/lib/cluster.h b/lib/cluster.h index f948586..f3271b0 100644 --- a/lib/cluster.h +++ b/lib/cluster.h @@ -12,45 +12,45 @@ #include "graph.h" template <class R_t, class X_t> -void flip_cluster(state_t <R_t, X_t> *state, v_t v0, R_t r, gsl_rng *rand) { +void flip_cluster(state_t<R_t, X_t>& s, v_t v0, const R_t& r, gsl_rng *rand) { v_t nv = 0; std::stack<v_t> stack; stack.push(v0); - std::vector<bool> marks(state->g.nv, false); + std::vector<bool> marks(s.g.nv, false); while (!stack.empty()) { v_t v = stack.top(); stack.pop(); - if (!marks[v]) { + if (!marks[v]) { // don't reprocess anyone we've already visited! X_t si_old, si_new; R_t R_old, R_new; - R_old = state->R; + R_old = s.R; marks[v] = true; - bool v_is_ghost = (v == state->nv); + bool v_is_ghost = (v == s.nv); // ghost site has the last index if (v_is_ghost) { - R_new = r.act(R_old); + R_new = r.act(R_old); // if we are, then we're moving the transformation } else { - si_old = state->spins[v]; - si_new = r.act(si_old); + si_old = s.spins[v]; + si_new = r.act(si_old); // otherwise, we're moving the spin at our site } - for (const v_t &vn : state->g.v_adj[v]) { + for (const v_t &vn : s.g.v_adj[v]) { X_t sj; - bool vn_is_ghost = (vn == state->nv); + bool vn_is_ghost = (vn == s.nv); // any of our neighbors could be the ghost if (!vn_is_ghost) { - sj = state->spins[vn]; + sj = s.spins[vn]; } double prob; - if (v_is_ghost || vn_is_ghost) { + if (v_is_ghost || vn_is_ghost) { // if this is a ghost-involved bond... X_t rs_old, rs_new; v_t non_ghost; if (vn_is_ghost) { @@ -63,51 +63,54 @@ void flip_cluster(state_t <R_t, X_t> *state, v_t v0, R_t r, gsl_rng *rand) { non_ghost = vn; } - double dE = state->H(rs_old) - state->H(rs_new); + double dE = s.H(rs_old) - s.H(rs_new); + #ifdef FINITE_STATES prob = H_probs[state_to_ind(rs_old)][state_to_ind(rs_new)]; #else - prob = 1.0 - exp(-dE / state->T); + prob = 1.0 - exp(-dE / s.T); #endif - state->M -= rs_old; - state->M += rs_new; + s.M -= rs_old; + s.M += rs_new; - state->E += dE; + s.E += dE; - for (D_t i = 0; i < state->D; i++) { - L_t x = (non_ghost / (v_t)pow(state->L, state->D - i - 1)) % state->L; + for (D_t i = 0; i < s.D; i++) { + L_t x = (non_ghost / (v_t)pow(s.L, s.D - i - 1)) % s.L; - state->ReF[i] -= rs_old * state->precomputed_cos[x]; - state->ReF[i] += rs_new * state->precomputed_cos[x]; + s.ReF[i] -= rs_old * s.precomputed_cos[x]; + s.ReF[i] += rs_new * s.precomputed_cos[x]; - state->ImF[i] -= rs_old * state->precomputed_sin[x]; - state->ImF[i] += rs_new * state->precomputed_sin[x]; + s.ImF[i] -= rs_old * s.precomputed_sin[x]; + s.ImF[i] += rs_new * s.precomputed_sin[x]; } - } else { - double dE = state->J(si_old, sj) - state->J(si_new, sj); + } else { // otherwise, we're at a perfectly normal bond! + double dE = s.J(si_old, sj) - s.J(si_new, sj); + #ifdef FINITE_STATES prob = J_probs[state_to_ind(si_old)][state_to_ind(si_new)][state_to_ind(sj)]; #else - prob = 1.0 - exp(-dE / state->T); + prob = 1.0 - exp(-dE / s.T); #endif - state->E += dE; + + s.E += dE; } - if (gsl_rng_uniform(rand) < prob) { // and with probability... + if (gsl_rng_uniform(rand) < prob) { stack.push(vn); // push the neighboring vertex to the stack } } if (v_is_ghost) { - state->R = R_new; + s.R = R_new; } else { - state->spins[v] = si_new; + s.spins[v] = si_new; nv++; } } } - state->last_cluster_size = nv; + s.last_cluster_size = nv; } diff --git a/lib/correlation.h b/lib/correlation.h index 49c6ff2..23b1bd9 100644 --- a/lib/correlation.h +++ b/lib/correlation.h @@ -7,13 +7,13 @@ #include <fftw3.h> template <class R_t, class X_t> -double correlation_length(const state_t <R_t, X_t> *s) { +double correlation_length(const state_t <R_t, X_t>& s) { double total = 0; - for (D_t j = 0; j < s->D; j++) { - total += norm_squared(s->ReF[j]) + norm_squared(s->ReF[j]); + for (D_t j = 0; j < s.D; j++) { + total += norm_squared(s.ReF[j]) + norm_squared(s.ReF[j]); } - return total / s->D; + return total / s.D; } diff --git a/lib/measure.h b/lib/measure.h index 8082dd2..2c5ffb7 100644 --- a/lib/measure.h +++ b/lib/measure.h @@ -29,17 +29,17 @@ FILE **measure_setup_files(unsigned char flags, unsigned long timestamp) { } template <class R_t, class X_t> -std::function <void(const state_t <R_t, X_t> *)> measure_function_write_files(unsigned char flags, FILE **files, std::function <void(const state_t <R_t, X_t> *)> other_f) { - return [=] (const state_t <R_t, X_t> *s) { +std::function <void(const state_t <R_t, X_t>&)> measure_function_write_files(unsigned char flags, FILE **files, std::function <void(const state_t <R_t, X_t>&)> other_f) { + return [=] (const state_t <R_t, X_t>& s) { if (flags & measurement_energy) { - float smaller_E = (float)s->E; + float smaller_E = (float)s.E; fwrite(&smaller_E, sizeof(float), 1, files[0]); } if (flags & measurement_clusterSize) { - fwrite(&(s->last_cluster_size), sizeof(uint32_t), 1, files[1]); + fwrite(&(s.last_cluster_size), sizeof(uint32_t), 1, files[1]); } if (flags & measurement_magnetization) { - write_magnetization(s->M, files[2]); + write_magnetization(s.M, files[2]); } if (flags & measurement_fourierZero) { float smaller_X = (float)correlation_length(s); diff --git a/lib/wolff.h b/lib/wolff.h index a4a663c..498f7f3 100644 --- a/lib/wolff.h +++ b/lib/wolff.h @@ -3,18 +3,18 @@ #include "state.h" template <class R_t, class X_t> -void wolff(count_t N, state_t <R_t, X_t> *s, std::function <R_t(gsl_rng *, X_t s0)> gen_R, std::function <void(const state_t <R_t, X_t> *)> measurements, gsl_rng *r, bool silent) { +void wolff(count_t N, state_t <R_t, X_t>& s, std::function <R_t(gsl_rng *, X_t s0)> gen_R, std::function <void(const state_t <R_t, X_t>&)> measurements, gsl_rng *r, bool silent) { #ifdef FINITE_STATES - initialize_probs(s->J, s->H, s->T); + initialize_probs(s.J, s.H, s.T); #endif if (!silent) printf("\n"); for (count_t steps = 0; steps < N; steps++) { - if (!silent) printf("\033[F\033[JWOLFF: step %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", steps, N, s->E, s->last_cluster_size); + if (!silent) printf("\033[F\033[JWOLFF: step %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", steps, N, s.E, s.last_cluster_size); - v_t v0 = gsl_rng_uniform_int(r, s->nv); - R_t step = gen_R(r, s->spins[v0]); + v_t v0 = gsl_rng_uniform_int(r, s.nv); + R_t step = gen_R(r, s.spins[v0]); flip_cluster <R_t, X_t> (s, v0, step, r); measurements(s); @@ -23,7 +23,7 @@ void wolff(count_t N, state_t <R_t, X_t> *s, std::function <R_t(gsl_rng *, X_t s if (!silent) { printf("\033[F\033[J"); } - printf("WOLFF: step %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", N, N, s->E, s->last_cluster_size); + printf("WOLFF: step %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", N, N, s.E, s.last_cluster_size); } @@ -25,7 +25,7 @@ class z2_t { z2_t(bool x) : x(x) {} - ising_t act(const ising_t& s) { + ising_t act(const ising_t& s) const { if (x) { return ising_t(!s.x); } else { @@ -33,7 +33,7 @@ class z2_t { } } - z2_t act(const z2_t& r) { + z2_t act(const z2_t& r) const { if (x) { return z2_t(!r.x); } else { @@ -41,11 +41,11 @@ class z2_t { } } - ising_t act_inverse(const ising_t& s) { + ising_t act_inverse(const ising_t& s) const { return this->act(s); } - z2_t act_inverse(const z2_t& r) { + z2_t act_inverse(const z2_t& r) const { return this->act(r); } }; diff --git a/src/wolff_O2.cpp b/src/wolff_O2.cpp deleted file mode 100644 index 63ca0a7..0000000 --- a/src/wolff_O2.cpp +++ /dev/null @@ -1,278 +0,0 @@ - -#include <getopt.h> -#include <stdio.h> - -#ifdef HAVE_GLUT -#include <GL/glut.h> -#endif - -#include <circle_group.h> -#include <angle.h> - -#include <wolff.h> -#include <measure.h> -#include <colors.h> -#include <rand.h> - -typedef circle_group_t orthogonal_R_t; -typedef angle_t vector_R_t; -typedef state_t <orthogonal_R_t, vector_R_t> On_t; - -double H_modulated(vector_R_t v, int order, double mag) { - return mag * cos(order * v.x); -} - -double theta(double *v) { - double x = v[0]; - double y = v[1]; - - if (x == 0) { - if (y >= 0) { - return M_PI / 2; - } else { - return - M_PI / 2; - } - } else { - double val = atan(y / x); - - if (x < 0.0 && y > 0.0) { - return M_PI + val; - } else if ( x < 0.0 && y < 0.0 ) { - return - M_PI + val; - } else { - return val; - } - } -} - -int main(int argc, char *argv[]) { - - count_t N = (count_t)1e7; - - 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 use_pert = false; - bool N_is_sweeps = false; - bool draw = false; - unsigned int window_size = 512; - - bool modulated_field = false; - unsigned int order = 1; - - int opt; - q_t H_ind = 0; - double epsilon = 1; - -// unsigned char measurement_flags = measurement_energy | measurement_clusterSize; - - unsigned char measurement_flags = 0; - - while ((opt = getopt(argc, argv, "N:D:L:T:H:spe:mo:M: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 'p': - use_pert = true; - break; - case 'e': - epsilon = atof(optarg); - break; - case 'm': - modulated_field = true; - break; - case 'M': - measurement_flags ^= 1 << atoi(optarg); - break; - case 'o': - order = atoi(optarg); - break; - case 'S': - N_is_sweeps = 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); - } - } - - unsigned long timestamp; - - { - struct timespec spec; - clock_gettime(CLOCK_REALTIME, &spec); - timestamp = spec.tv_sec*1000000000LL + spec.tv_nsec; - } - - const char *pert_type; - - std::function <orthogonal_R_t(gsl_rng *, vector_R_t)> gen_R; - - if (use_pert) { - gen_R = [=] (gsl_rng *r, const angle_t& t) -> circle_group_t { - circle_group_t rot; - rot.is_reflection = true; - - unsigned int x = gsl_rng_uniform_int(r, order); - double amount = epsilon * gsl_ran_ugaussian(r); - - rot.x = fmod(2 * M_PI * (1.0 + (double)x / (double)order + amount), 2 * M_PI); - - return rot; - }; - pert_type = "PERTURB"; - } else { - gen_R = [=] (gsl_rng *r, const angle_t& t) -> circle_group_t { - circle_group_t rot; - rot.is_reflection = true; - rot.x = 2 * M_PI * gsl_rng_uniform(r); - - return rot; - }; - pert_type = "UNIFORM"; - } - - FILE *outfile_info = fopen("wolff_metadata.txt", "a"); - - fprintf(outfile_info, "<| \"ID\" -> %lu, \"MODEL\" -> \"%s\", \"q\" -> %d, \"D\" -> %" PRID ", \"L\" -> %" PRIL ", \"NV\" -> %" PRIv ", \"NE\" -> %" PRIv ", \"T\" -> %.15f, \"FIELD_TYPE\" -> ", timestamp, ON_strings[2], 2, D, L, (v_t)pow(L, D), D * (v_t)pow(L, D), T); - if (modulated_field) { - fprintf(outfile_info, "\"MODULATED\", \"ORDER\" -> %d, \"H\" -> %.15f, ", order, H_vec[0]); - } else { - fprintf(outfile_info, "\"VECTOR\", \"H\" -> {"); - for (q_t i = 0; i < 2; i++) { - fprintf(outfile_info, "%.15f", H_vec[i]); - if (i < 2 - 1) { - fprintf(outfile_info, ", "); - } - } - fprintf(outfile_info, "}, "); - } - - fprintf(outfile_info, "\"GENERATOR\" -> \"%s\"", pert_type); - - if (use_pert) { - fprintf(outfile_info, ", \"EPS\" -> %g", epsilon); - } - - fprintf(outfile_info, " |>\n"); - - fclose(outfile_info); - - FILE **outfiles = measure_setup_files(measurement_flags, timestamp); - - std::function <void(const On_t *)> other_f; - uint64_t sum_of_clusterSize = 0; - - if (N_is_sweeps) { - other_f = [&] (const On_t *s) { - sum_of_clusterSize += s->last_cluster_size; - }; - } else if (draw) { -#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); - - other_f = [&] (const On_t *s) { - glClear(GL_COLOR_BUFFER_BIT); - for (v_t i = 0; i < pow(L, 2); i++) { - vector_R_t v_tmp = s->R.act_inverse(s->spins[i]); - double saturation = 0.7; - double value = 0.9; - double chroma = saturation * value; - glColor3f(chroma * hue_to_R(v_tmp.x) + (value - chroma), chroma * hue_to_G(v_tmp.x) + (value - chroma), chroma * hue_to_B(v_tmp.x) + (value - chroma)); - glRecti(i / L, i % L, (i / L) + 1, (i % L) + 1); - } - glFlush(); - }; -#endif - } else { - other_f = [] (const On_t *s) {}; - } - - std::function <void(const On_t *)> measurements = measure_function_write_files(measurement_flags, outfiles, other_f); - - std::function <double(const angle_t&, const angle_t&)> J = [] (const angle_t& t1, const angle_t& t2) -> double { - return cos(t1.x - t2.x); - }; - - std::function <double(const angle_t &)> H; - - if (modulated_field) { - H = [=] (const angle_t& t) -> double { - return H_vec[0] * cos(order * t.x); - }; - } else { - double mag = 0; - for (q_t i = 0; i < 2; i++) { - mag += pow(H_vec[i], 2); - } - mag = sqrt(mag); - double t0 = theta(H_vec); - H = [=] (const angle_t& t) -> double { - return mag * cos(t0 + t.x); - }; - } - - // initialize random number generator - gsl_rng *r = gsl_rng_alloc(gsl_rng_taus2); - gsl_rng_set(r, rand_seed()); - - state_t <orthogonal_R_t, vector_R_t> s(D, L, T, J, H); - - if (N_is_sweeps) { - count_t N_rounds = 0; - printf("\n"); - while (sum_of_clusterSize < N * s.nv) { - printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, s.E, s.last_cluster_size); - wolff <orthogonal_R_t, vector_R_t> (N, &s, gen_R, measurements, r, silent); - N_rounds++; - } - printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, s.E, s.last_cluster_size); - } else { - wolff <orthogonal_R_t, vector_R_t> (N, &s, gen_R, measurements, r, silent); - } - - measure_free_files(measurement_flags, outfiles); - free(H_vec); - gsl_rng_free(r); - - return 0; -} - diff --git a/src/wolff_On.cpp b/src/wolff_On.cpp index cbde498..3fa5840 100644 --- a/src/wolff_On.cpp +++ b/src/wolff_On.cpp @@ -167,12 +167,12 @@ int main(int argc, char *argv[]) { FILE **outfiles = measure_setup_files(measurement_flags, timestamp); - std::function <void(const On_t *)> other_f; + std::function <void(const On_t&)> other_f; uint64_t sum_of_clusterSize = 0; if (N_is_sweeps) { - other_f = [&] (const On_t *s) { - sum_of_clusterSize += s->last_cluster_size; + other_f = [&] (const On_t& s) { + sum_of_clusterSize += s.last_cluster_size; }; } else if (draw) { #ifdef HAVE_GLUT @@ -186,10 +186,10 @@ int main(int argc, char *argv[]) { glLoadIdentity(); gluOrtho2D(0.0, L, 0.0, L); - other_f = [&] (const On_t *s) { + other_f = [&] (const On_t& s) { glClear(GL_COLOR_BUFFER_BIT); for (v_t i = 0; i < pow(L, 2); i++) { - vector_R_t v_tmp = s->R.act_inverse(s->spins[i]); + vector_R_t v_tmp = s.R.act_inverse(s.spins[i]); double thetai = fmod(2 * M_PI + theta(v_tmp), 2 * M_PI); double saturation = 0.7; double value = 0.9; @@ -201,10 +201,10 @@ int main(int argc, char *argv[]) { }; #endif } else { - other_f = [] (const On_t *s) {}; + other_f = [] (const On_t& s) {}; } - std::function <void(const On_t *)> measurements = measure_function_write_files(measurement_flags, outfiles, other_f); + std::function <void(const On_t&)> measurements = measure_function_write_files(measurement_flags, outfiles, other_f); std::function <double(const vector_R_t&)> H; @@ -225,12 +225,12 @@ int main(int argc, char *argv[]) { printf("\n"); while (sum_of_clusterSize < N * s.nv) { printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, s.E, s.last_cluster_size); - wolff <orthogonal_R_t, vector_R_t> (N, &s, gen_R, measurements, r, silent); + wolff <orthogonal_R_t, vector_R_t> (N, s, gen_R, measurements, r, silent); N_rounds++; } printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, s.E, s.last_cluster_size); } else { - wolff <orthogonal_R_t, vector_R_t> (N, &s, gen_R, measurements, r, silent); + wolff <orthogonal_R_t, vector_R_t> (N, s, gen_R, measurements, r, silent); } measure_free_files(measurement_flags, outfiles); diff --git a/src/wolff_cgm.cpp b/src/wolff_cgm.cpp index ec3ae36..ce91bf2 100644 --- a/src/wolff_cgm.cpp +++ b/src/wolff_cgm.cpp @@ -100,13 +100,13 @@ int main(int argc, char *argv[]) { }; // define function that updates any number of measurements - std::function <void(const sim_t *)> measurement; + 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 / (double)N / (double)s->nv; + measurement = [&] (const sim_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 @@ -122,13 +122,13 @@ int main(int argc, char *argv[]) { glLoadIdentity(); gluOrtho2D(0.0, L, 0.0, L); - measurement = [&] (const sim_t *s) { - average_M += (double)s->M / (double)N / (double)s->nv; + measurement = [&] (const sim_t& s) { + average_M += (double)s.M / (double)N / (double)s.nv; glClear(GL_COLOR_BUFFER_BIT); double max_h = INT64_MIN; double min_h = INT64_MAX; for (v_t i = 0; i < pow(L, 2); i++) { - double cur_h = (s->R.act_inverse(s->spins[i])).x; + double cur_h = (s.R.act_inverse(s.spins[i])).x; if (cur_h < min_h) { min_h = cur_h; } @@ -138,7 +138,7 @@ int main(int argc, char *argv[]) { } for (v_t i = 0; i < pow(L, 2); i++) { - double cur_h = (s->R.act_inverse(s->spins[i])).x; + double cur_h = (s.R.act_inverse(s.spins[i])).x; double mag = ((double)(cur_h - min_h)) / ((double)(max_h - min_h)); glColor3f(mag, mag, mag); glRecti(i / L, i % L, (i / L) + 1, (i % L) + 1); @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) { } // run wolff for N cluster flips - wolff(N, &s, gen_R, measurement, r, silent); + wolff(N, s, gen_R, measurement, r, silent); // tell us what we found! printf("%" PRIcount " DGM runs completed. D = %" PRID ", L = %" PRIL ", T = %g, H = %g, <M> = %g\n", N, D, L, T, H, average_M); diff --git a/src/wolff_clock.cpp b/src/wolff_clock.cpp index 376eaec..3dec284 100644 --- a/src/wolff_clock.cpp +++ b/src/wolff_clock.cpp @@ -101,13 +101,13 @@ int main(int argc, char *argv[]) { }; // define function that updates any number of measurements - std::function <void(const sim_t *)> measurement; + 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; + 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 @@ -123,11 +123,11 @@ int main(int argc, char *argv[]) { glLoadIdentity(); gluOrtho2D(0.0, L, 0.0, L); - measurement = [&] (const sim_t *s) { - average_M += (double)s->M[0] / (double)N / (double)s->nv; + 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 = s->R.act_inverse(s->spins[i]); + potts_t<POTTSQ> tmp_s = s.R.act_inverse(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); } @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) { } // run wolff for N cluster flips - wolff(N, &s, gen_R, measurement, r, silent); + 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); diff --git a/src/wolff_dgm.cpp b/src/wolff_dgm.cpp index d00cae5..8667fb5 100644 --- a/src/wolff_dgm.cpp +++ b/src/wolff_dgm.cpp @@ -105,13 +105,13 @@ int main(int argc, char *argv[]) { }; // define function that updates any number of measurements - std::function <void(const sim_t *)> measurement; + 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 / (double)N / (double)s->nv; + measurement = [&] (const sim_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 @@ -127,13 +127,13 @@ int main(int argc, char *argv[]) { glLoadIdentity(); gluOrtho2D(0.0, L, 0.0, L); - measurement = [&] (const sim_t *s) { - average_M += (double)s->M / (double)N / (double)s->nv; + measurement = [&] (const sim_t& s) { + average_M += (double)s.M / (double)N / (double)s.nv; glClear(GL_COLOR_BUFFER_BIT); int64_t max_h = INT64_MIN; int64_t min_h = INT64_MAX; for (v_t i = 0; i < pow(L, 2); i++) { - int64_t cur_h = (s->R.act_inverse(s->spins[i])).x; + int64_t cur_h = (s.R.act_inverse(s.spins[i])).x; if (cur_h < min_h) { min_h = cur_h; } @@ -143,7 +143,7 @@ int main(int argc, char *argv[]) { } for (v_t i = 0; i < pow(L, 2); i++) { - int64_t cur_h = (s->R.act_inverse(s->spins[i])).x; + int64_t cur_h = (s.R.act_inverse(s.spins[i])).x; double mag = ((double)(cur_h - min_h)) / ((double)(max_h - min_h)); glColor3f(mag, mag, mag); glRecti(i / L, i % L, (i / L) + 1, (i % L) + 1); @@ -154,7 +154,7 @@ int main(int argc, char *argv[]) { } // run wolff for N cluster flips - wolff(N, &s, gen_R, measurement, r, silent); + wolff(N, s, gen_R, measurement, r, silent); // tell us what we found! printf("%" PRIcount " DGM runs completed. D = %" PRID ", L = %" PRIL ", T = %g, H = %g, <M> = %g\n", N, D, L, T, H, average_M); diff --git a/src/wolff_ising.cpp b/src/wolff_ising.cpp index 0c9485d..24bf74c 100644 --- a/src/wolff_ising.cpp +++ b/src/wolff_ising.cpp @@ -126,12 +126,12 @@ int main(int argc, char *argv[]) { FILE **outfiles = measure_setup_files(measurement_flags, timestamp); - std::function <void(const state_t<z2_t, ising_t> *)> other_f; + std::function <void(const state_t<z2_t, ising_t>&)> other_f; uint64_t sum_of_clusterSize = 0; if (N_is_sweeps) { - other_f = [&] (const state_t<z2_t, ising_t> *s) { - sum_of_clusterSize += s->last_cluster_size; + other_f = [&] (const state_t<z2_t, ising_t>& s) { + sum_of_clusterSize += s.last_cluster_size; }; } else if (draw) { #ifdef HAVE_GLUT @@ -145,24 +145,24 @@ int main(int argc, char *argv[]) { glLoadIdentity(); gluOrtho2D(0.0, L, 0.0, L); - other_f = [] (const state_t <z2_t, ising_t> *s) { + other_f = [] (const state_t <z2_t, ising_t>& s) { glClear(GL_COLOR_BUFFER_BIT); - for (v_t i = 0; i < pow(s->L, 2); i++) { - if (s->spins[i].x == s->R.x) { + for (v_t i = 0; i < pow(s.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 / s->L, i % s->L, (i / s->L) + 1, (i % s->L) + 1); + glRecti(i / s.L, i % s.L, (i / s.L) + 1, (i % s.L) + 1); } glFlush(); }; #endif } else { - other_f = [] (const state_t<z2_t, ising_t> *s) {}; + other_f = [] (const state_t<z2_t, ising_t>& s) {}; } - std::function <void(const state_t<z2_t, ising_t> *)> measurements = measure_function_write_files(measurement_flags, outfiles, other_f); + std::function <void(const state_t<z2_t, ising_t>&)> measurements = measure_function_write_files(measurement_flags, outfiles, other_f); // add line to metadata file with run info { @@ -179,12 +179,12 @@ int main(int argc, char *argv[]) { printf("\n"); while (sum_of_clusterSize < N * s.nv) { printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, s.E, s.last_cluster_size); - wolff(N, &s, gen_R, measurements, r, silent); + wolff(N, s, gen_R, measurements, r, silent); N_rounds++; } printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, s.E, s.last_cluster_size); } else { - wolff(N, &s, gen_R, measurements, r, silent); + wolff(N, s, gen_R, measurements, r, silent); } // free the random number generator diff --git a/src/wolff_potts.cpp b/src/wolff_potts.cpp index 2bc306b..9fe3ffe 100644 --- a/src/wolff_potts.cpp +++ b/src/wolff_potts.cpp @@ -135,12 +135,12 @@ int main(int argc, char *argv[]) { FILE **outfiles = measure_setup_files(measurement_flags, timestamp); - std::function <void(const sim_t *)> other_f; + std::function <void(const sim_t&)> other_f; uint64_t sum_of_clusterSize = 0; if (N_is_sweeps) { - other_f = [&] (const sim_t *s) { - sum_of_clusterSize += s->last_cluster_size; + other_f = [&] (const sim_t& s) { + sum_of_clusterSize += s.last_cluster_size; }; } else if (draw) { #ifdef HAVE_GLUT @@ -154,21 +154,21 @@ int main(int argc, char *argv[]) { glLoadIdentity(); gluOrtho2D(0.0, L, 0.0, L); - other_f = [] (const sim_t *s) { + other_f = [] (const sim_t& s) { glClear(GL_COLOR_BUFFER_BIT); - for (v_t i = 0; i < pow(s->L, 2); i++) { - potts_t<POTTSQ> tmp_s = s->R.act_inverse(s->spins[i]); + for (v_t i = 0; i < pow(s.L, 2); i++) { + potts_t<POTTSQ> tmp_s = s.R.act_inverse(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 / s->L, i % s->L, (i / s->L) + 1, (i % s->L) + 1); + glRecti(i / s.L, i % s.L, (i / s.L) + 1, (i % s.L) + 1); } glFlush(); }; #endif } else { - other_f = [] (const sim_t *s) {}; + other_f = [] (const sim_t& s) {}; } - std::function <void(const sim_t *)> measurements = measure_function_write_files(measurement_flags, outfiles, other_f); + std::function <void(const sim_t&)> measurements = measure_function_write_files(measurement_flags, outfiles, other_f); // add line to metadata file with run info { @@ -194,12 +194,12 @@ int main(int argc, char *argv[]) { printf("\n"); while (sum_of_clusterSize < N * s.nv) { printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, s.E, s.last_cluster_size); - wolff(N, &s, gen_R, measurements, r, silent); + wolff(N, s, gen_R, measurements, r, silent); N_rounds++; } printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, s.E, s.last_cluster_size); } else { - wolff(N, &s, gen_R, measurements, r, silent); + wolff(N, s, gen_R, measurements, r, silent); } // free the random number generator |