diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-10-10 21:45:32 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-10-10 21:45:32 -0400 |
commit | a43ff1f98e9b9814f858bccb11c174b418458491 (patch) | |
tree | ae7e094d914eddb8a1ae9548420ba8c2f329ffae /src | |
parent | 6e264d243f0b29d90e90b605b6cdeab8227129c9 (diff) | |
download | c++-a43ff1f98e9b9814f858bccb11c174b418458491.tar.gz c++-a43ff1f98e9b9814f858bccb11c174b418458491.tar.bz2 c++-a43ff1f98e9b9814f858bccb11c174b418458491.zip |
big rearrangement of files to make libraries and example (research) files clearer, and changed to c++ std lib random numbers
Diffstat (limited to 'src')
-rw-r--r-- | src/analyze_correlations.cpp | 486 | ||||
-rw-r--r-- | src/wolff_On.cpp | 269 | ||||
-rw-r--r-- | src/wolff_cgm.cpp | 166 | ||||
-rw-r--r-- | src/wolff_clock.cpp | 154 | ||||
-rw-r--r-- | src/wolff_dgm.cpp | 171 | ||||
-rw-r--r-- | src/wolff_ising.cpp | 201 | ||||
-rw-r--r-- | src/wolff_potts.cpp | 213 |
7 files changed, 0 insertions, 1660 deletions
diff --git a/src/analyze_correlations.cpp b/src/analyze_correlations.cpp deleted file mode 100644 index 48ee426..0000000 --- a/src/analyze_correlations.cpp +++ /dev/null @@ -1,486 +0,0 @@ - -#include <types.h> -#include <cmath> -#include <cstring> -#include <stdio.h> -#include <stdlib.h> -#include <getopt.h> -#include <fftw3.h> - -template <class T> -double mean(int N, T *data) { - double total = 0; - for (int i = 0; i < N; i++) { - total += (double)data[i]; - } - - return total / N; -} - -double squared_mean(int N, double *data) { - double total = 0; - for (int i = 0; i < N; i++) { - total += pow(data[i], 2); - } - - return total / N; -} - -double central_moment(int N, double *data, double mean, int m) { - double total = 0; - for (int i = 0; i < N; i++) { - total += pow(data[i] - mean, m); - } - - return total / N; -} - -void compute_OO(int N, fftw_plan forward_plan, double *forward_data, fftw_plan reverse_plan, double *reverse_data) { - - fftw_execute(forward_plan); - - reverse_data[0] = forward_data[0] * forward_data[0]; - reverse_data[N / 2] = forward_data[N/2] * forward_data[N/2]; - - for (count_t i = 1; i < N / 2; i++) { - reverse_data[i] = pow(forward_data[i], 2) + pow(forward_data[N - i], 2); - reverse_data[N - i] = 0; - } - - fftw_execute(reverse_plan); - -} - -double finite_energy(q_t nb, double *J, q_t q, double *H, v_t nv, v_t ne, uint32_t *bo, uint32_t *so) { - double energy = 0; - - v_t tot = 0; - for (q_t i = 0; i < nb - 1; i++) { - energy -= J[i] * bo[i]; - tot += bo[i]; - } - - energy -= J[nb - 1] * (ne - tot); - - tot = 0; - for (q_t i = 0; i < q - 1; i++) { - energy -= H[i] * so[i]; - tot += so[i]; - } - - energy -= H[q - 1] * (nv - tot); - - return energy; -} - -int main (int argc, char *argv[]) { - count_t drop = (count_t)1e4; - count_t length = (count_t)1e4; - bool speedy_drop = false; - bool from_stdin = false; - bool oldstyle = false; - - int opt; - - while ((opt = getopt(argc, argv, "d:l:spo")) != -1) { - switch (opt) { - case 'd': - drop = (count_t)atof(optarg); - break; - case 'l': - length = (count_t)atof(optarg); - break; - case 's': - speedy_drop = true; - break; - case 'p': - from_stdin = true; - break; - case 'o': - oldstyle = true; - break; - default: - exit(EXIT_FAILURE); - } - } - FILE *metadata; - - fftw_set_timelimit(1); - - if (from_stdin) { - metadata = stdin; - } else { - metadata = fopen("wolff_metadata.txt", "r"); - } - - if (metadata == NULL) { - printf("Metadata file not found. Make sure you are in the correct directory!\n"); - exit(EXIT_FAILURE); - } - - unsigned long id; - char *model = (char *)malloc(32 * sizeof(char)); - - if (model == NULL) { - printf("Malloc failed.\n"); - exit(EXIT_FAILURE); - } - - q_t q; - D_t D; - L_t L; - v_t nv, ne; - - while (EOF != fscanf(metadata, "<| \"ID\" -> %lu, \"MODEL\" -> \"%[^\"]\", \"q\" -> %" SCNq ", \"D\" -> %" SCND ", \"L\" -> %" SCNL ", \"NV\" -> %" SCNv ", \"NE\" -> %" SCNv ", ", &id, model, &q, &D, &L, &nv, &ne)) { - - printf("%lu: Processing...\n", id); - -// bool is_finite = 0 == strcmp(model, "ISING") || 0 == strcmp(model, "POTTS") || 0 == strcmp(model, "CLOCK"); - - if (oldstyle) { - q_t nb; - double T; - fscanf(metadata, "\"NB\" -> %" SCNq ", \"T\" -> %lf, \"J\" -> {", &nb, &T); - double *J = (double *)malloc(nb * sizeof(double)); - double *H = (double *)malloc(q * sizeof(double)); - - if (J == NULL || H == NULL) { - printf("%lu: Malloc failed.\n", id); - break; - } - - for (q_t i = 0; i < nb - 1; i++) { - fscanf(metadata, "%lf, ", &(J[i])); - } - fscanf(metadata, "%lf}, \"H\" -> {", &(J[nb - 1])); - for (q_t i = 0; i < q - 1; i++) { - fscanf(metadata, "%lf, ", &(H[i])); - } - fscanf(metadata, "%lf} |>\n", &(H[q - 1])); - - char *filename_M = (char *)malloc(128 * sizeof(char)); - char *filename_B = (char *)malloc(128 * sizeof(char)); - char *filename_S = (char *)malloc(128 * sizeof(char)); - - if (filename_M == NULL || filename_B == NULL || filename_S == NULL) { - printf("%lu: Malloc failed.\n", id); - break; - } - - sprintf(filename_M, "wolff_%lu_M.dat", id); - sprintf(filename_B, "wolff_%lu_B.dat", id); - sprintf(filename_S, "wolff_%lu_S.dat", id); - - FILE *file_M = fopen(filename_M, "rb"); - FILE *file_B = fopen(filename_B, "rb"); - FILE *file_S = fopen(filename_S, "rb"); - - if (file_M == NULL || file_B == NULL || file_S == NULL) { - printf("%lu: Opening data file failed.\n", id); - break; - } - - fseek(file_S, 0, SEEK_END); - unsigned long N = ftell(file_S) / sizeof(uint32_t); - fseek(file_S, 0, SEEK_SET); - - if (speedy_drop) { - drop = N - pow(2, floor(log(N) / log(2))); - } else { - if (N % 2 == 1 && drop % 2 == 0) { - drop++; // make sure M is even - } - } - - if (N <= drop) { - printf("\033[F%lu: Number of steps %lu is less than %" PRIcount ", nothing done.\n", id, N, drop); - } else { - int M = N - drop; - - double M_f = (double)M; - - if (length > M) { - length = M; - } - - double *forward_data = (double *)fftw_malloc(M * sizeof(double)); - fftw_plan forward_plan = fftw_plan_r2r_1d(M, forward_data, forward_data, FFTW_R2HC, 0); - double *reverse_data = (double *)fftw_malloc(M * sizeof(double)); - fftw_plan reverse_plan = fftw_plan_r2r_1d(M, reverse_data, reverse_data, FFTW_HC2R, 0); - - - uint32_t *data_S = (uint32_t *)malloc(N * sizeof(uint32_t)); - fread(data_S, N, sizeof(uint32_t), file_S); - for (count_t i = 0; i < M; i++) { - forward_data[i] = (double)data_S[drop + i]; - } - free(data_S); - double mean_S = mean(M, forward_data); - double squaredMean_S = squared_mean(M, forward_data); - double moment2_S = central_moment(M, forward_data, mean_S, 2); - double moment4_S = central_moment(M, forward_data, mean_S, 4); - - compute_OO(M, forward_plan, forward_data, reverse_plan, reverse_data); - - sprintf(filename_S, "wolff_%lu_S_OO.dat", id); - - FILE *file_S = fopen(filename_S, "wb"); - fwrite(&M_f, sizeof(double), 1, file_S); - fwrite(&mean_S, sizeof(double), 1, file_S); - fwrite(&squaredMean_S, sizeof(double), 1, file_S); - fwrite(&moment2_S, sizeof(double), 1, file_S); - fwrite(&moment4_S, sizeof(double), 1, file_S); - fwrite(reverse_data, sizeof(double), length, file_S); - fclose(file_S); - - uint32_t *data_B = (uint32_t *)malloc((nb - 1) * N * sizeof(uint32_t)); - uint32_t *data_M = (uint32_t *)malloc((q - 1) * N * sizeof(uint32_t)); - fread(data_B, N * (nb - 1), sizeof(uint32_t), file_B); - fread(data_M, N * (q - 1), sizeof(uint32_t), file_M); - - for (count_t i = 0; i < M; i++) { - forward_data[i] = finite_energy(nb, J, q, H, nv, ne, data_B + (nb - 1) * (drop + i), data_M + (q - 1) * (drop + i)); - } - - double mean_E = mean(M, forward_data); - double squaredMean_E = squared_mean(M, forward_data); - double moment2_E = central_moment(M, forward_data, mean_E, 2); - double moment4_E = central_moment(M, forward_data, mean_E, 4); - - free(data_B); - free(data_M); - - compute_OO(M, forward_plan, forward_data, reverse_plan, reverse_data); - - sprintf(filename_B, "wolff_%lu_E_OO.dat", id); - - FILE *file_E = fopen(filename_B, "wb"); - fwrite(&M_f, sizeof(double), 1, file_E); - fwrite(&mean_E, sizeof(double), 1, file_E); - fwrite(&squaredMean_E, sizeof(double), 1, file_E); - fwrite(&moment2_E, sizeof(double), 1, file_E); - fwrite(&moment4_E, sizeof(double), 1, file_E); - fwrite(reverse_data, sizeof(double), length, file_E); - fclose(file_E); - - printf("\033[F%lu: Correlation functions for %d steps written.\n", id, M); - - fftw_destroy_plan(forward_plan); - fftw_destroy_plan(reverse_plan); - fftw_free(forward_data); - fftw_free(reverse_data); - - } - - fclose(file_M); - fclose(file_B); - fclose(file_S); - - free(J); - free(H); - - free(filename_S); - free(filename_B); - free(filename_M); - - } else { - char *junk = (char *)malloc(1024 * sizeof(char)); - fscanf(metadata, "%[^\n]\n", junk); // throw away the rest of the line, we don't need it - free(junk); - - char *filename_E = (char *)malloc(128 * sizeof(char)); - char *filename_F = (char *)malloc(128 * sizeof(char)); - char *filename_M = (char *)malloc(128 * sizeof(char)); - char *filename_S = (char *)malloc(128 * sizeof(char)); - - sprintf(filename_E, "wolff_%lu_E.dat", id); - sprintf(filename_F, "wolff_%lu_F.dat", id); - sprintf(filename_M, "wolff_%lu_M.dat", id); - sprintf(filename_S, "wolff_%lu_S.dat", id); - - FILE *file_E = fopen(filename_E, "rb"); - FILE *file_F = fopen(filename_F, "rb"); - FILE *file_M = fopen(filename_M, "rb"); - FILE *file_S = fopen(filename_S, "rb"); - - fseek(file_S, 0, SEEK_END); - unsigned long N = ftell(file_S) / sizeof(uint32_t); - fseek(file_S, 0, SEEK_SET); - - if (speedy_drop) { - drop = N - pow(2, floor(log(N) / log(2))); - } else { - if (N % 2 == 1 && drop % 2 == 0) { - drop++; // make sure M is even - } - } - - if (N <= drop) { - printf("\033[F%lu: Number of steps %lu is less than %" PRIcount ", nothing done.\n", id, N, drop); - } else { - int M = N - drop; - double M_f = (double)M; - - if (length > M) { - length = M; - } - - double *forward_data = (double *)fftw_malloc(M * sizeof(double)); - fftw_plan forward_plan = fftw_plan_r2r_1d(M, forward_data, forward_data, FFTW_R2HC, 0); - - double *reverse_data = (double *)fftw_malloc(M * sizeof(double)); - fftw_plan reverse_plan = fftw_plan_r2r_1d(M, reverse_data, reverse_data, FFTW_HC2R, 0); - - if (file_S != NULL) { - uint32_t *data_S = (uint32_t *)malloc(N * sizeof(uint32_t)); - - fread(data_S, sizeof(uint32_t), N, file_S); - fclose(file_S); - - for (int i = 0; i < M; i++) { - forward_data[i] = (double)data_S[drop + i]; - } - free(data_S); - - double mean_S = mean(M, forward_data); - double squaredMean_S = squared_mean(M, forward_data); - double moment2_S = central_moment(M, forward_data, mean_S, 2); - double moment4_S = central_moment(M, forward_data, mean_S, 4); - - compute_OO(M, forward_plan, forward_data, reverse_plan, reverse_data); - - sprintf(filename_S, "wolff_%lu_S_OO.dat", id); - FILE *file_S_new = fopen(filename_S, "wb"); - fwrite(&M_f, sizeof(double), 1, file_S_new); - fwrite(&mean_S, sizeof(double), 1, file_S_new); - fwrite(&squaredMean_S, sizeof(double), 1, file_S_new); - fwrite(&moment2_S, sizeof(double), 1, file_S_new); - fwrite(&moment4_S, sizeof(double), 1, file_S_new); - fwrite(reverse_data, sizeof(double), length, file_S_new); - fclose(file_S_new); - } - if (file_F != NULL) { - float *data_F = (float *)malloc(N * sizeof(float)); - - fread(data_F, sizeof(float), N, file_F); - fclose(file_F); - - for (int i = 0; i < M; i++) { - forward_data[i] = (double)data_F[drop + i]; - } - free(data_F); - - double mean_F = mean(M, forward_data); - double squaredMean_F = squared_mean(M, forward_data); - double moment2_F = central_moment(M, forward_data, mean_F, 2); - double moment4_F = central_moment(M, forward_data, mean_F, 4); - - compute_OO(M, forward_plan, forward_data, reverse_plan, reverse_data); - - sprintf(filename_F, "wolff_%lu_F_OO.dat", id); - FILE *file_F_new = fopen(filename_F, "wb"); - fwrite(&M_f, sizeof(double), 1, file_F_new); - fwrite(&mean_F, sizeof(double), 1, file_F_new); - fwrite(&squaredMean_F, sizeof(double), 1, file_F_new); - fwrite(&moment2_F, sizeof(double), 1, file_F_new); - fwrite(&moment4_F, sizeof(double), 1, file_F_new); - fwrite(reverse_data, sizeof(double), length, file_F_new); - fclose(file_F_new); - } - if (file_E != NULL) { - float *data_E = (float *)malloc(N * sizeof(float)); - - fread(data_E, sizeof(float), N, file_E); - fclose(file_E); - - for (int i = 0; i < M; i++) { - forward_data[i] = (double)data_E[drop + i]; - } - free(data_E); - - double mean_E = mean(M, forward_data); - double squaredMean_E = squared_mean(M, forward_data); - double moment2_E = central_moment(M, forward_data, mean_E, 2); - double moment4_E = central_moment(M, forward_data, mean_E, 4); - - compute_OO(M, forward_plan, forward_data, reverse_plan, reverse_data); - - sprintf(filename_E, "wolff_%lu_E_OO.dat", id); - FILE *file_E_new = fopen(filename_E, "wb"); - fwrite(&M_f, sizeof(double), 1, file_E_new); - fwrite(&mean_E, sizeof(double), 1, file_E_new); - fwrite(&squaredMean_E, sizeof(double), 1, file_E_new); - fwrite(&moment2_E, sizeof(double), 1, file_E_new); - fwrite(&moment4_E, sizeof(double), 1, file_E_new); - fwrite(reverse_data, sizeof(double), length, file_E_new); - fclose(file_E_new); - } - if (file_M != NULL) { - if (0 == strcmp(model, "PLANAR")) { - float *data_M = (float *)malloc(2 * N * sizeof(float)); - fread(data_M, sizeof(float), 2 * N, file_M); - fclose(file_M); - for (int i = 0; i < M; i++) { - forward_data[i] = (double)sqrt(pow(data_M[2 * drop + 2 * i], 2) + pow(data_M[2 * drop + 2 * i + 1], 2)); - } - free(data_M); - } else if (0 == strcmp(model, "HEISENBERG")) { - float *data_M = (float *)malloc(3 * N * sizeof(float)); - fread(data_M, sizeof(float), 3 * N, file_M); - fclose(file_M); - for (int i = 0; i < M; i++) { - forward_data[i] = sqrt(pow(data_M[3 * drop + 3 * i], 2) + pow(data_M[3 * drop + 3 * i + 1], 2) + pow(data_M[3 * drop + 3 * i + 2], 2)); - } - free(data_M); - } else if (0 == strcmp(model, "ISING")) { - int *data_M = (int *)malloc(N * sizeof(float)); - fread(data_M, sizeof(int), N, file_M); - fclose(file_M); - for (int i = 0; i < M; i++) { - forward_data[i] = (double)data_M[i]; - } - free(data_M); - } else { - printf("UNKNOWN MODEL\n"); - exit(EXIT_FAILURE); - } - - double mean_M = mean(M, forward_data); - double squaredMean_M = squared_mean(M, forward_data); - double moment2_M = central_moment(M, forward_data, mean_M, 2); - double moment4_M = central_moment(M, forward_data, mean_M, 4); - - compute_OO(M, forward_plan, forward_data, reverse_plan, reverse_data); - - sprintf(filename_M, "wolff_%lu_M_OO.dat", id); - FILE *file_M_new = fopen(filename_M, "wb"); - fwrite(&M_f, sizeof(double), 1, file_M_new); - fwrite(&mean_M, sizeof(double), 1, file_M_new); - fwrite(&squaredMean_M, sizeof(double), 1, file_M_new); - fwrite(&moment2_M, sizeof(double), 1, file_M_new); - fwrite(&moment4_M, sizeof(double), 1, file_M_new); - fwrite(reverse_data, sizeof(double), length, file_M_new); - fclose(file_M_new); - } - - printf("\033[F%lu: Correlation functions for %d steps written.\n", id, M); - fftw_destroy_plan(forward_plan); - fftw_destroy_plan(reverse_plan); - fftw_free(forward_data); - fftw_free(reverse_data); - - } - free(filename_E); - free(filename_S); - free(filename_F); - free(filename_M); - } - } - - free(model); - fclose(metadata); - fftw_cleanup(); - - return 0; -} - diff --git a/src/wolff_On.cpp b/src/wolff_On.cpp deleted file mode 100644 index f6661af..0000000 --- a/src/wolff_On.cpp +++ /dev/null @@ -1,269 +0,0 @@ - -#include <getopt.h> -#include <stdio.h> - -#ifdef HAVE_GLUT -#include <GL/glut.h> -#endif - -#include <orthogonal.h> -#include <vector.h> - -#include <wolff.h> -#include <measure.h> -#include <colors.h> -#include <rand.h> - -typedef orthogonal_t <N_COMP, double> orthogonal_R_t; -typedef vector_t <N_COMP, double> vector_R_t; -typedef state_t <orthogonal_R_t, vector_R_t> On_t; - -// angle from the x-axis of a two-vector -double theta(vector_R_t v) { - double x = v[0]; - double y = v[1]; - - 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; - } -} - -double H_modulated(vector_R_t v, int order, double mag) { - return mag * cos(order * theta(v)); -} - -int main(int argc, char *argv[]) { - - count_t N = (count_t)1e7; - -#ifdef DIMENSION - D_t D = DIMENSION; -#else - D_t D = 2; -#endif - 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; -#ifdef DIMENSION - case 'D': // dimension - printf("Dimension was specified at compile time, you can't change it now!\n"); - exit(EXIT_FAILURE); -#else - case 'D': // dimension - D = atoi(optarg); - break; -#endif - 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) { - double Hish; - if (modulated_field) { - Hish = fabs(H_vec[0]); - } else { - double H2 = 0; - for (q_t i = 0; i < N_COMP; i++) { - H2 += pow(H_vec[i], 2); - } - Hish = sqrt(H2); - } - - epsilon = sqrt((N_COMP - 1) * T / (D + Hish / 2)) / 2; - - gen_R = std::bind(generate_rotation_perturbation <N_COMP>, std::placeholders::_1, std::placeholders::_2, epsilon, order); - pert_type = "PERTURB5"; - } else { - gen_R = generate_rotation_uniform <N_COMP>; - 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[N_COMP], N_COMP, 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 < N_COMP; i++) { - fprintf(outfile_info, "%.15f", H_vec[i]); - if (i < N_COMP - 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 thetai = fmod(2 * M_PI + theta(v_tmp), 2 * M_PI); - double saturation = 0.7; - double value = 0.9; - double chroma = saturation * value; - glColor3f(chroma * hue_to_R(thetai) + (value - chroma), chroma * hue_to_G(thetai) + (value - chroma), chroma * hue_to_B(thetai) + (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 vector_R_t&)> H; - - if (modulated_field) { - H = std::bind(H_modulated, std::placeholders::_1, order, H_vec[0]); - } else { - H = std::bind(H_vector <N_COMP, double>, std::placeholders::_1, H_vec); - } - - // initialize random number generator - gsl_rng *r = gsl_rng_alloc(gsl_rng_taus2); - gsl_rng_set(r, rand_seed()); - -#ifndef NOFIELD - state_t <orthogonal_R_t, vector_R_t> s(D, L, T, dot <N_COMP, double>, H); -#else - state_t <orthogonal_R_t, vector_R_t> s(D, L, T, dot <N_COMP, double>); -#endif - - 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_cgm.cpp b/src/wolff_cgm.cpp deleted file mode 100644 index ce91bf2..0000000 --- a/src/wolff_cgm.cpp +++ /dev/null @@ -1,166 +0,0 @@ - -#include <getopt.h> - -#ifdef HAVE_GLUT -#include <GL/glut.h> -#endif - -// include your group and spin space -#include <dihedral_inf.h> -#include <height.h> - -// include wolff.h -#include <rand.h> -#include <wolff.h> - -typedef state_t <dihedral_inf_t<double>, height_t<double>> 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 = 0; - - bool silent = false; - bool draw = false; - unsigned int window_size = 512; - double epsilon = 1; - - int opt; - - while ((opt = getopt(argc, argv, "N:D:L:T:H:sdw:e:")) != -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 = atof(optarg); - break; - case 'e': // external field. nth call couples to state n - epsilon = atof(optarg); - 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(const height_t<double>&, const height_t<double>&)> Z = [] (const height_t<double>& h1, const height_t<double>& h2) -> double { - return -pow(h1.x - h2.x, 2); - }; - - // define spin-field coupling - std::function <double(height_t<double>)> B = [=] (height_t<double> h) -> double { - return -H * pow(h.x, 2);; - }; - - // initialize state object - sim_t s(D, L, T, Z, B); - - // define function that generates self-inverse rotations - std::function <dihedral_inf_t<double>(gsl_rng *, height_t<double>)> gen_R = [=] (gsl_rng *r, height_t<double> h) -> dihedral_inf_t<double> { - dihedral_inf_t<double> rot; - rot.is_reflection = true; - - double amount = epsilon * gsl_ran_ugaussian(r); - - rot.x = 2 * h.x + amount; - - 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 / (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 / (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; - if (cur_h < min_h) { - min_h = cur_h; - } - if (cur_h > max_h) { - max_h = cur_h; - } - } - - for (v_t i = 0; i < pow(L, 2); i++) { - 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); - } - glFlush(); - }; -#endif - } - - // run wolff for N cluster flips - 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); - - // free the random number generator - gsl_rng_free(r); - - if (draw) { - } - - return 0; - -} - diff --git a/src/wolff_clock.cpp b/src/wolff_clock.cpp deleted file mode 100644 index 3dec284..0000000 --- a/src/wolff_clock.cpp +++ /dev/null @@ -1,154 +0,0 @@ - -#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<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(const potts_t<POTTSQ>&, const potts_t<POTTSQ>&)> Z = [] (const potts_t<POTTSQ>& s1, const 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(const potts_t<POTTSQ>&)> B = [=] (const potts_t<POTTSQ>& s) -> double { - return H_vec[s.x]; - }; - - // initialize state object - state_t <dihedral_t<POTTSQ>, potts_t<POTTSQ>> s(D, L, T, Z, B); - - // define function that generates self-inverse rotations - std::function <dihedral_t<POTTSQ>(gsl_rng *, potts_t<POTTSQ>)> gen_R = [] (gsl_rng *r, potts_t<POTTSQ> v) -> dihedral_t<POTTSQ> { - dihedral_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 = 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); - } - 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; - -} - diff --git a/src/wolff_dgm.cpp b/src/wolff_dgm.cpp deleted file mode 100644 index 8667fb5..0000000 --- a/src/wolff_dgm.cpp +++ /dev/null @@ -1,171 +0,0 @@ - -#include <getopt.h> - -#ifdef HAVE_GLUT -#include <GL/glut.h> -#endif - -// include your group and spin space -#include <dihedral_inf.h> -#include <height.h> - -// include wolff.h -#include <rand.h> -#include <wolff.h> - -typedef state_t <dihedral_inf_t<int64_t>, height_t<int64_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 = 0; - - bool silent = false; - bool draw = false; - unsigned int window_size = 512; - uint64_t epsilon = 1; - - int opt; - - while ((opt = getopt(argc, argv, "N:D:L:T:H:sdw:e:")) != -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 = atof(optarg); - break; - case 'e': // external field. nth call couples to state n - epsilon = atof(optarg); - 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(const height_t<int64_t>&, const height_t<int64_t>&)> Z = [] (const height_t<int64_t>& h1, const height_t<int64_t>& h2) -> double { - return -pow(h1.x - h2.x, 2); - }; - - // define spin-field coupling - std::function <double(const height_t<int64_t> &)> B = [=] (const height_t<int64_t>& h) -> double { - return -H * pow(h.x, 2);; - }; - - // initialize state object - sim_t s(D, L, T, Z, B); - - // define function that generates self-inverse rotations - std::function <dihedral_inf_t<int64_t>(gsl_rng *, height_t<int64_t>)> gen_R = [=] (gsl_rng *r, height_t<int64_t> h) -> dihedral_inf_t<int64_t> { - dihedral_inf_t<int64_t> rot; - rot.is_reflection = true; - - int direction = gsl_rng_uniform_int(r, 2); - int64_t amount = gsl_rng_uniform_int(r, epsilon); - - if (direction == 0) { - rot.x = 2 * h.x + (1 + amount); - } else { - rot.x = 2 * h.x - (1 + amount); - } - - 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 / (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 / (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; - if (cur_h < min_h) { - min_h = cur_h; - } - if (cur_h > max_h) { - max_h = cur_h; - } - } - - for (v_t i = 0; i < pow(L, 2); i++) { - 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); - } - glFlush(); - }; -#endif - } - - // run wolff for N cluster flips - 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); - - // free the random number generator - gsl_rng_free(r); - - if (draw) { - } - - return 0; - -} - diff --git a/src/wolff_ising.cpp b/src/wolff_ising.cpp deleted file mode 100644 index a6f43b1..0000000 --- a/src/wolff_ising.cpp +++ /dev/null @@ -1,201 +0,0 @@ - -#include <getopt.h> -#include <stdio.h> - -// if you have GLUT installed, you can see graphics! -#ifdef HAVE_GLUT -#include <GL/glut.h> -#endif - -// include your group and spin space -#include <z2.h> -#include <ising.h> - -// finite_states.h can be included for spin types that have special variables -// defined, and it causes wolff execution to use precomputed bond probabilities -#include <finite_states.h> - -// rand.h uses a unix-specific way to seed the random number generator -#include <rand.h> - -// measure.h contains useful functions for saving timeseries to files -#include <measure.h> - -// include wolff.h -#include <wolff.h> - -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 = 0.0; - - bool silent = false; - bool draw = false; - bool N_is_sweeps = false; - unsigned int window_size = 512; - - // don't measure anything by default - unsigned char measurement_flags = 0; - - int opt; - - while ((opt = getopt(argc, argv, "N:D:L:T:H:sdw:M:S")) != -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 - H = atof(optarg); - break; - case 's': // don't print anything during simulation. speeds up slightly - silent = true; - 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; - case 'M': - measurement_flags ^= 1 << atoi(optarg); - break; - default: - exit(EXIT_FAILURE); - } - } - - // get nanosecond timestamp for unique run id - unsigned long timestamp; - - { - struct timespec spec; - clock_gettime(CLOCK_REALTIME, &spec); - timestamp = spec.tv_sec*1000000000LL + spec.tv_nsec; - } - - // initialize random number generator - gsl_rng *r = gsl_rng_alloc(gsl_rng_taus2); - gsl_rng_set(r, rand_seed()); - - // define spin-spin coupling - std::function <double(const ising_t&, const ising_t&)> Z = [] (const ising_t& s1, const ising_t& s2) -> double { - if (s1.x == s2.x) { - return 1.0; - } else { - return -1.0; - } - }; - - // define spin-field coupling - std::function <double(const ising_t&)> B = [=] (const ising_t& s) -> double { - if (s.x) { - return -H; - } else { - return H; - } - }; - - // initialize state object -#ifndef NOFIELD - state_t <z2_t, ising_t> s(D, L, T, Z, B); -#else - state_t <z2_t, ising_t> s(D, L, T, Z); -#endif - - // define function that generates self-inverse rotations - std::function <z2_t(gsl_rng *, ising_t)> gen_R = [] (gsl_rng *, const ising_t& s) -> z2_t { - return z2_t(true); - }; - - FILE **outfiles = measure_setup_files(measurement_flags, timestamp); - - 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; - }; - } 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 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) { - 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); - } - glFlush(); - }; -#endif - } else { - 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); - - // add line to metadata file with run info - { - FILE *outfile_info = fopen("wolff_metadata.txt", "a"); - - fprintf(outfile_info, "<| \"ID\" -> %lu, \"MODEL\" -> \"ISING\", \"q\" -> 2, \"D\" -> %" PRID ", \"L\" -> %" PRIL ", \"NV\" -> %" PRIv ", \"NE\" -> %" PRIv ", \"T\" -> %.15f, \"H\" -> %.15f |>\n", timestamp, s.D, s.L, s.nv, s.ne, T, H); - - fclose(outfile_info); - } - - // run wolff for N cluster flips - 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(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); - } - - // free the random number generator - gsl_rng_free(r); - measure_free_files(measurement_flags, outfiles); - - return 0; - -} - diff --git a/src/wolff_potts.cpp b/src/wolff_potts.cpp deleted file mode 100644 index 9fe3ffe..0000000 --- a/src/wolff_potts.cpp +++ /dev/null @@ -1,213 +0,0 @@ - -#include <getopt.h> -#include <stdio.h> - -#ifdef HAVE_GLUT -#include <GL/glut.h> -#endif - -// include your group and spin space -#include <symmetric.h> -#include <potts.h> - -// hack to speed things up considerably -#define N_STATES POTTSQ -#include <finite_states.h> - -// include wolff.h -#include <measure.h> -#include <colors.h> -#include <rand.h> -#include <wolff.h> - -typedef state_t <symmetric_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; - bool N_is_sweeps = false; - unsigned int window_size = 512; - - // don't measure anything by default - unsigned char measurement_flags = 0; - - int opt; - q_t H_ind = 0; - - while ((opt = getopt(argc, argv, "N:D:L:T:H:sdw:M:S")) != -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 '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; - case 'M': - measurement_flags ^= 1 << atoi(optarg); - break; - default: - exit(EXIT_FAILURE); - } - } - - // get nanosecond timestamp for unique run id - unsigned long timestamp; - - { - struct timespec spec; - clock_gettime(CLOCK_REALTIME, &spec); - timestamp = spec.tv_sec*1000000000LL + spec.tv_nsec; - } - - // 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(const potts_t<POTTSQ>&, const potts_t<POTTSQ>&)> Z = [] (const potts_t<POTTSQ>& s1, const potts_t<POTTSQ>& s2) -> double { - if (s1.x == s2.x) { - return 1.0; - } else { - return 0.0; - } - }; - - // define spin-field coupling - std::function <double(const potts_t<POTTSQ> &)> B = [=] (const potts_t<POTTSQ>& s) -> double { - return H_vec[s.x]; - }; - - // initialize state object - state_t <symmetric_t<POTTSQ>, potts_t<POTTSQ>> s(D, L, T, Z, B); - - // define function that generates self-inverse rotations - std::function <symmetric_t<POTTSQ>(gsl_rng *, potts_t<POTTSQ>)> gen_R = [] (gsl_rng *r, potts_t<POTTSQ> v) -> symmetric_t<POTTSQ> { - symmetric_t<POTTSQ> rot; - - q_t j = gsl_rng_uniform_int(r, POTTSQ - 1); - q_t swap_v; - if (j < v.x) { - swap_v = j; - } else { - swap_v = j + 1; - } - - rot[v.x] = swap_v; - rot[swap_v] = v.x; - - return rot; - }; - - FILE **outfiles = measure_setup_files(measurement_flags, timestamp); - - 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; - }; - } 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 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]); - 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); - } - glFlush(); - }; -#endif - } else { - other_f = [] (const sim_t& s) {}; - } - - std::function <void(const sim_t&)> measurements = measure_function_write_files(measurement_flags, outfiles, other_f); - - // add line to metadata file with run info - { - FILE *outfile_info = fopen("wolff_metadata.txt", "a"); - - fprintf(outfile_info, "<| \"ID\" -> %lu, \"MODEL\" -> \"POTTS\", \"q\" -> %d, \"D\" -> %" PRID ", \"L\" -> %" PRIL ", \"NV\" -> %" PRIv ", \"NE\" -> %" PRIv ", \"T\" -> %.15f, \"H\" -> {", timestamp, POTTSQ, s.D, s.L, s.nv, s.ne, T); - - for (q_t i = 0; i < POTTSQ; i++) { - fprintf(outfile_info, "%.15f", H_vec[i]); - if (i < POTTSQ - 1) { - fprintf(outfile_info, ", "); - } - } - - fprintf(outfile_info, "} |>\n"); - - fclose(outfile_info); - } - - // run wolff for N cluster flips - 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(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); - } - - // free the random number generator - gsl_rng_free(r); - free(H_vec); - measure_free_files(measurement_flags, outfiles); - - return 0; - -} - |