summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--lib/cluster_finite.c112
-rw-r--r--lib/cluster_finite.h55
-rw-r--r--lib/dihedral.c55
-rw-r--r--lib/dihedral.h24
-rw-r--r--lib/dihinf.c28
-rw-r--r--lib/dihinf.h17
-rw-r--r--lib/initial_finite.c372
-rw-r--r--lib/initial_finite.h27
-rw-r--r--lib/symmetric.c70
-rw-r--r--lib/symmetric.h19
-rw-r--r--src/wolff_finite.c188
12 files changed, 3 insertions, 968 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b5a47d6..50bc708 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,7 +14,6 @@ link_directories(~/.local/lib)
file(GLOB CSOURCES lib/*.c)
file(GLOB CPPSOURCES lib/*.cpp)
-add_executable(wolff_finite src/wolff_finite.c ${CSOURCES})
add_executable(wolff_ising src/wolff_ising.cpp ${CPPSOURCES} ${CSOURCES})
add_executable(wolff_dgm src/wolff_dgm.cpp ${CPPSOURCES} ${CSOURCES})
add_executable(wolff_cgm src/wolff_cgm.cpp ${CPPSOURCES} ${CSOURCES})
@@ -37,7 +36,6 @@ FIND_LIBRARY(GLU NAMES GLU)
FIND_LIBRARY(GLUT NAMES glut)
FIND_LIBRARY(TESTING NAMES Idontexist)
-target_link_libraries(wolff_finite cblas gsl m)
target_link_libraries(analyze_correlations cblas gsl fftw3 m)
if (${GLUT} MATCHES "GLUT-NOTFOUND")
target_link_libraries(wolff_ising cblas gsl m)
@@ -64,5 +62,5 @@ else()
target_compile_definitions(wolff_heisenberg PUBLIC HAVE_GLUT)
endif()
-install(TARGETS wolff_finite 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_heisenberg wolff_planar analyze_correlations DESTINATION bin)
diff --git a/lib/cluster_finite.c b/lib/cluster_finite.c
deleted file mode 100644
index 2041df0..0000000
--- a/lib/cluster_finite.c
+++ /dev/null
@@ -1,112 +0,0 @@
-
-#include "cluster_finite.h"
-
-v_t flip_cluster_finite(state_finite_t *s, v_t v0, R_t rot_ind, gsl_rng *r) {
- q_t *rot = s->transformations + s->q * s->involutions[rot_ind];
- q_t *R_inv = symmetric_invert(s->q, s->R);
- v_t nv = 0;
-
- ll_t *stack = NULL; // create a new stack
- stack_push(&stack, v0); // push the initial vertex to the stack
-
- bool *marks = (bool *)calloc(s->g->nv, sizeof(bool));
-
- while (stack != NULL) {
- v_t v = stack_pop(&stack);
-
- if (!marks[v]) {
- q_t s_old, s_new;
- q_t *R_new, *R_inv_new;
- bool external_flipped;
-
- marks[v] = true;
-
- if (v == s->g->nv - 1) {
- R_new = symmetric_compose(s->q, rot, s->R);
- R_inv_new = symmetric_invert(s->q, R_new);
- external_flipped = true;
- } else {
- s_old = s->spins[v];
- s_new = symmetric_act(rot, s_old);
- external_flipped = false;
- }
-
- v_t nn = s->g->v_i[v + 1] - s->g->v_i[v];
-
- for (v_t i = 0; i < nn; i++) {
- q_t sn, non_ghost;
- double prob;
- bool external_neighbor = false;
-
- v_t vn = s->g->v_adj[s->g->v_i[v] + i];
-
- if (vn == s->g->nv - 1) {
- external_neighbor = true;
- non_ghost = v;
- } else {
- sn = s->spins[vn];
- non_ghost = vn;
- }
-
- if (external_flipped || external_neighbor) {
- q_t rot_s_old, rot_s_new;
-
- if (external_neighbor) {
- rot_s_old = symmetric_act(R_inv, s_old);
- rot_s_new = symmetric_act(R_inv, s_new);
- } else {
- rot_s_old = symmetric_act(R_inv, sn);
- rot_s_new = symmetric_act(R_inv_new, sn);
- }
-
- prob = s->H_probs[rot_s_new * s->q + rot_s_old];
-
- s->M[rot_s_old]--;
- s->M[rot_s_new]++;
-
- 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;
-
- s->ReF[s->D * i + rot_s_old] -= s->precomputed_cos[i];
- s->ReF[s->D * i + rot_s_new] += s->precomputed_cos[i];
-
- s->ImF[s->D * i + rot_s_old] -= s->precomputed_sin[i];
- s->ImF[s->D * i + rot_s_new] += s->precomputed_sin[i];
- }
-
- } else {
- q_t diff_old = s->bond_with_zero_type[s->transformations[s->q * s->transform_site_to_zero[sn] + s_old]];
- q_t diff_new = s->bond_with_zero_type[s->transformations[s->q * s->transform_site_to_zero[sn] + s_new]];
-
- prob = s->J_probs[diff_new * s->n_bond_types + diff_old];
-
- s->B[diff_old]--;
- s->B[diff_new]++;
- }
-
- if (gsl_rng_uniform(r) < prob) { // and with probability ps[e]...
- stack_push(&stack, vn); // push the neighboring vertex to the stack
- }
- }
-
- if (external_flipped) {
- free(s->R);
- free(R_inv);
- s->R = R_new;
- R_inv = R_inv_new;
- } else {
- s->spins[v] = s_new;
- }
-
- if (v != s->g->nv - 1) { // count the number of non-external sites that flip
- nv++;
- }
- }
- }
-
- free(marks);
- free(R_inv);
-
- return nv;
-}
-
diff --git a/lib/cluster_finite.h b/lib/cluster_finite.h
deleted file mode 100644
index 117087e..0000000
--- a/lib/cluster_finite.h
+++ /dev/null
@@ -1,55 +0,0 @@
-
-#pragma once
-
-#include <assert.h>
-#include <fftw3.h>
-#include <float.h>
-#include <gsl/gsl_randist.h>
-#include <gsl/gsl_rng.h>
-#include <inttypes.h>
-#include <math.h>
-#include <stdbool.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "types.h"
-#include "rand.h"
-#include "stack.h"
-#include "convex.h"
-#include "graph.h"
-#include "tree.h"
-#include "measurement.h"
-#include "symmetric.h"
-#include "yule_walker.h"
-
-typedef struct {
- D_t D;
- L_t L;
- v_t nv;
- v_t ne;
- graph_t *g;
- q_t q;
- R_t n_transformations;
- q_t *transformations;
- R_t n_involutions;
- R_t *involutions;
- R_t *transform_site_to_zero;
- q_t n_bond_types;
- q_t *bond_with_zero_type;
- double T;
- double *J;
- double *H;
- double *J_probs;
- double *H_probs;
- q_t *spins;
- q_t *R;
- v_t *B;
- v_t *M;
- double *ReF;
- double *ImF;
- double *precomputed_cos;
- double *precomputed_sin;
-} state_finite_t;
-
-v_t flip_cluster_finite(state_finite_t *s, v_t v0, R_t rot, gsl_rng *r);
-
diff --git a/lib/dihedral.c b/lib/dihedral.c
deleted file mode 100644
index 8158b43..0000000
--- a/lib/dihedral.c
+++ /dev/null
@@ -1,55 +0,0 @@
-
-#include "dihedral.h"
-
-dihedral_t *dihedral_compose(q_t q, q_t g1i, const dihedral_t *g2) {
- // we only need to consider the action of reflections
- dihedral_t *g3 = (dihedral_t *)malloc(1 * sizeof(dihedral_t));
-
- g3->r = !g2->r;
- g3->i = (g1i + q - g2->i) % q;
-
- return g3;
-}
-
-q_t dihedral_act(q_t q, q_t gi, bool r, q_t s) {
- // we only need to consider the action of reflections
-
- if (r) {
- return (gi + q - s) % q;
- } else {
- return (gi + s) % q;
- }
-}
-
-q_t dihedral_inverse_act(q_t q, const dihedral_t *g, q_t s) {
- if (g->r) {
- return (q - ((q + s - g->i) % q)) % q;
- } else {
- return (q + s - g->i) % q;
- }
-}
-
-q_t *dihedral_gen_transformations(q_t q) {
- q_t *transformations = (q_t *)malloc(2 * q * q * sizeof(q_t));
-
- for (q_t i = 0; i < q; i++) {
- for (q_t j = 0; j < q; j++) {
- transformations[q * i + j] = dihedral_act(q, i, false, j);
- transformations[q * q + q * i + j] = dihedral_act(q, i, true, j);
- }
- }
-
- return transformations;
-}
-
-R_t *dihedral_gen_involutions(q_t q) {
- R_t *transformations = (R_t *)malloc(q * sizeof(R_t));
-
- for (q_t i = 0; i < q; i++) {
- transformations[i] = q + i;
- }
-
- return transformations;
-}
-
-
diff --git a/lib/dihedral.h b/lib/dihedral.h
index f67c930..f547497 100644
--- a/lib/dihedral.h
+++ b/lib/dihedral.h
@@ -1,26 +1,8 @@
-#include <stdbool.h>
-#include <stdlib.h>
+#pragma once
#include "types.h"
-
-typedef struct {
- q_t i;
- bool r;
-} dihedral_t;
-
-dihedral_t *dihedral_compose(q_t q, q_t gti, const dihedral_t *g2);
-
-q_t dihedral_act(q_t q, q_t gi, bool r, q_t s);
-
-q_t dihedral_inverse_act(q_t q, const dihedral_t *g, q_t s);
-
-q_t *dihedral_gen_transformations(q_t q);
-R_t *dihedral_gen_involutions(q_t q);
-
-R_t factorial(q_t);
-
-#ifdef __cplusplus
+#include "potts.h"
template <class T, q_t q>
struct dihedral2_t { bool is_reflection; T x; };
@@ -95,5 +77,3 @@ dihedral2_t<q_t, q> act_inverse(dihedral2_t<q_t,q> r1, dihedral2_t<q_t,q> r2) {
return r3;
}
-#endif
-
diff --git a/lib/dihinf.c b/lib/dihinf.c
deleted file mode 100644
index 4f88a7a..0000000
--- a/lib/dihinf.c
+++ /dev/null
@@ -1,28 +0,0 @@
-
-#include "dihinf.h"
-
-dihinf_t *dihinf_compose(h_t g1i, const dihinf_t *g2) {
- // we only need to consider the action of reflections
- dihinf_t *g3 = (dihinf_t *)malloc(1 * sizeof(dihinf_t));
-
- g3->r = !g2->r;
- g3->i = g1i - g2->i;
-
- return g3;
-}
-
-h_t dihinf_act(h_t gi, h_t s) {
- // we only need to consider the action of reflections
-
- return gi - s;
-}
-
-h_t dihinf_inverse_act(const dihinf_t *g, h_t s) {
- if (g->r) {
- return g->i - s;
- } else {
- return s - g->i;
- }
-}
-
-
diff --git a/lib/dihinf.h b/lib/dihinf.h
deleted file mode 100644
index 2bc7dc2..0000000
--- a/lib/dihinf.h
+++ /dev/null
@@ -1,17 +0,0 @@
-
-#include <stdbool.h>
-#include <stdlib.h>
-
-#include "types.h"
-
-typedef struct {
- h_t i;
- bool r;
-} dihinf_t;
-
-dihinf_t *dihinf_compose(h_t gti, const dihinf_t *g2);
-
-h_t dihinf_act(h_t gi, h_t s);
-
-h_t dihinf_inverse_act(const dihinf_t *g, h_t s);
-
diff --git a/lib/initial_finite.c b/lib/initial_finite.c
deleted file mode 100644
index 59e7ec4..0000000
--- a/lib/initial_finite.c
+++ /dev/null
@@ -1,372 +0,0 @@
-
-#include "initial_finite.h"
-
-double *precompute_cos(L_t L) {
- double *x = (double *)malloc(L * sizeof(double));
- for (L_t i = 0; i < L; i++) {
- x[i] = cos(2 * M_PI * (double)i / (double)L);
- }
-
- return x;
-}
-
-double *precompute_sin(L_t L) {
- double *x = (double *)malloc(L * sizeof(double));
- for (L_t i = 0; i < L; i++) {
- x[i] = sin(2 * M_PI * (double)i / (double)L);
- }
-
- return x;
-}
-
-double *Jprobs_from_J(q_t q, double T, double *J) {
- double *J_probs = (double *)calloc(pow(q, 2), sizeof(double));
-
- for (q_t i = 0; i < q; i++) {
- for (q_t j = 0; j < q; j++) {
- J_probs[q * i + j] = 1.0 - exp((J[i] - J[j]) / T);
- }
- }
-
- return J_probs;
-}
-
-q_t *initialize_R(q_t q) {
- q_t *R = (q_t *)malloc(q * sizeof(q_t));
-
- for (q_t i = 0; i < q; i++) {
- R[i] = i;
- }
-
- return R;
-}
-
-R_t *transformation_bringing_to_zero(q_t q, R_t n_transformations, q_t *transformations) {
- R_t *destination = (R_t *)malloc(q * sizeof(R_t));
-
- for (q_t i = 0; i < q; i++) {
- for (R_t j = 0; j < n_transformations; j++) {
- if (transformations[q * j + i] == 0) {
- destination[i] = j;
- }
- }
- }
-
- return destination;
-}
-
-R_t find_involutions(R_t *destination, q_t q, R_t n_transformations, q_t *transformations) {
- R_t n_involutions = 0;
-
- for (R_t i = 1; i < n_transformations; i++) {
- bool is_involution = true;
- for (q_t j = 0; j < q; j++) {
- if (j != transformations[q * i + transformations[q * i + j]]) {
- is_involution = false;
- break;
- }
- }
- if (is_involution) {
- destination[n_involutions] = i;
- n_involutions++;
- }
- }
-
- return n_involutions;
-}
-
-state_finite_t *initial_finite_prepare_ising(D_t D, L_t L, double T, double *H) {
- state_finite_t *s = (state_finite_t *)calloc(1, sizeof(state_finite_t));
-
- s->D = D;
- s->L = L;
-
- {
- graph_t *g = graph_create_square(D, L);
- s->nv = g->nv;
- s->ne = g->ne;
- s->g = graph_add_ext(g);
- graph_free(g);
- }
-
- s->q = 2;
-
- s->n_transformations = 2;
- s->transformations = (q_t *)malloc(2 * 2 * sizeof(q_t));
- s->transformations[0] = 0;
- s->transformations[1] = 1;
- s->transformations[2] = 1;
- s->transformations[3] = 0;
-
- s->n_involutions = 1;
- s->involutions = (R_t *)malloc(1 * sizeof(R_t));
- s->involutions[0] = 1;
-
- s->transform_site_to_zero = (R_t *)malloc(2 * sizeof(R_t));
- s->transform_site_to_zero[0] = 0;
- s->transform_site_to_zero[1] = 1;
-
- s->n_bond_types = 2;
- s->bond_with_zero_type = (q_t *)malloc(2 * sizeof(q_t));
- s->bond_with_zero_type[0] = 0;
- s->bond_with_zero_type[1] = 1;
-
- s->T = T;
- s->J = (double *)malloc(2 * sizeof(double));
- s->J[0] = 1.0;
- s->J[1] = -1.0;
- s->H = (double *)malloc(2 * sizeof(double));
- s->H[0] = H[0];
- s->H[1] = -H[0];
-
- s->J_probs = Jprobs_from_J(2, T, s->J);
- s->H_probs = Jprobs_from_J(2, T, s->H);
-
- s->spins = (q_t *)calloc(s->nv, sizeof(q_t));
- s->R = initialize_R(2);
-
- s->M = (v_t *)calloc(2, sizeof(v_t));
- s->M[0] = s->nv; // everyone starts in state 0, remember?
- s->B = (v_t *)calloc(2, sizeof(v_t));
- s->B[0] = s->ne;
-
- s->ReF = (double *)calloc(D * 2, sizeof(double));
- s->ImF = (double *)calloc(D * 2, sizeof(double));
-
-
- s->precomputed_cos = precompute_cos(L);
- s->precomputed_sin = precompute_sin(L);
-
- return s;
-}
-
-state_finite_t *initial_finite_prepare_potts(D_t D, L_t L, q_t q, double T, double *H) {
- state_finite_t *s = (state_finite_t *)calloc(1, sizeof(state_finite_t));
-
- s->D = D;
- s->L = L;
-
- {
- graph_t *g = graph_create_square(D, L);
- s->nv = g->nv;
- s->ne = g->ne;
- s->g = graph_add_ext(g);
- graph_free(g);
- }
-
- s->q = q;
- s->n_transformations = factorial(q);
- s->transformations = symmetric_gen_transformations(q);
- s->involutions = (R_t *)malloc(s->n_transformations * sizeof(R_t));
- s->n_involutions = find_involutions(s->involutions, q, s->n_transformations, s->transformations);
-
- s->transform_site_to_zero = transformation_bringing_to_zero(q, s->n_transformations, s->transformations);
-
- s->n_bond_types = 2;
-
- s->bond_with_zero_type = (q_t *)malloc(q * sizeof(q_t));
-
- s->bond_with_zero_type[0] = 0;
-
- for (q_t i = 1; i < q; i++) {
- s->bond_with_zero_type[i] = 1;
- }
-
- s->T = T;
- s->J = (double *)calloc(2, sizeof(double));
- s->J[0] = 1.0;
- s->J[1] = 0.0;
-
- s->H = (double *)malloc(q * sizeof(double));
- for (q_t i = 0; i < q; i++) {
- s->H[i] = H[i];
- }
-
- s->J_probs = Jprobs_from_J(s->n_bond_types, T, s->J);
- s->H_probs = Jprobs_from_J(q, T, s->H);
-
- s->spins = (q_t *)calloc(s->nv, sizeof(q_t));
- s->R = initialize_R(q);
-
- s->M = (v_t *)calloc(q, sizeof(v_t));
- s->M[0] = s->nv; // everyone starts in state 0, remember?
- s->B = (v_t *)calloc(s->n_bond_types, sizeof(v_t));
- s->B[0] = s->ne; // everyone starts in state 0, remember?
-
- s->ReF = (double *)calloc(D * q, sizeof(double));
- s->ImF = (double *)calloc(D * q, sizeof(double));
-
- s->precomputed_cos = precompute_cos(L);
- s->precomputed_sin = precompute_sin(L);
-
- return s;
-}
-
-state_finite_t *initial_finite_prepare_clock(D_t D, L_t L, q_t q, double T, double *H) {
- state_finite_t *s = (state_finite_t *)calloc(1, sizeof(state_finite_t));
-
- s->D = D;
- s->L = L;
-
- {
- graph_t *g = graph_create_square(D, L);
- s->nv = g->nv;
- s->ne = g->ne;
- s->g = graph_add_ext(g);
- graph_free(g);
- }
-
- s->q = q;
-
- s->n_transformations = 2 * q;
- s->transformations = dihedral_gen_transformations(q);
- s->n_involutions = q;
- s->involutions = dihedral_gen_involutions(q);
-
- s->transform_site_to_zero = transformation_bringing_to_zero(q, s->n_transformations, s->transformations);
- s->bond_with_zero_type = malloc(q * sizeof(q_t));
-
- s->n_bond_types = q / 2 + 1;
-
- for (q_t i = 0; i < q / 2 + 1; i++) {
- s->bond_with_zero_type[i] = i;
- }
-
- for (q_t i = 1; i < (q + 1) / 2; i++) {
- s->bond_with_zero_type[q - i] = i;
- }
-
-
- s->T = T;
- s->J = (double *)malloc(s->n_bond_types * sizeof(double));
-
- for (q_t i = 0; i < s->n_bond_types; i++) {
- s->J[i] = cos(2 * M_PI * i / ((double)q));
- }
-
-
- s->H = (double *)malloc(q * sizeof(double));
- for (q_t i = 0; i < q; i++) {
- s->H[i] = H[i];
- }
-
- s->J_probs = Jprobs_from_J(s->n_bond_types, T, s->J);
- s->H_probs = Jprobs_from_J(q, T, s->H);
-
- s->spins = (q_t *)calloc(s->nv, sizeof(q_t));
- s->R = initialize_R(q);
-
- s->M = (v_t *)calloc(q, sizeof(v_t));
- s->M[0] = s->nv; // everyone starts in state 0, remember?
- s->B = (v_t *)calloc(s->n_bond_types, sizeof(v_t));
- s->B[0] = s->ne; // everyone starts in state 0, remember?
-
- s->ReF = (double *)calloc(D * q, sizeof(double));
- s->ImF = (double *)calloc(D * q, sizeof(double));
-
- s->precomputed_cos = precompute_cos(L);
- s->precomputed_sin = precompute_sin(L);
-
- return s;
-}
-
-state_finite_t *initial_finite_prepare_dgm(D_t D, L_t L, q_t q, double T, double *H) {
- state_finite_t *s = (state_finite_t *)calloc(1, sizeof(state_finite_t));
-
- s->D = D;
- s->L = L;
-
- {
- graph_t *g = graph_create_square(D, L);
- s->nv = g->nv;
- s->ne = g->ne;
- s->g = graph_add_ext(g);
- graph_free(g);
- }
-
- s->q = q;
-
- s->n_transformations = 2 * q;
- s->transformations = dihedral_gen_transformations(q);
- s->n_involutions = q;
- s->involutions = dihedral_gen_involutions(q);
-
- s->transform_site_to_zero = transformation_bringing_to_zero(q, s->n_transformations, s->transformations);
- s->bond_with_zero_type = malloc(q * sizeof(q_t));
-
- s->n_bond_types = q / 2 + 1;
-
- for (q_t i = 0; i < q / 2 + 1; i++) {
- s->bond_with_zero_type[i] = i;
- }
-
- for (q_t i = 1; i < (q + 1) / 2; i++) {
- s->bond_with_zero_type[(int)q - (int)i] = i;
- }
-
- s->T = T;
- s->J = (double *)malloc(s->n_bond_types * sizeof(double));
-
- for (q_t i = 0; i < s->n_bond_types; i++) {
- s->J[i] = -pow(i, 2);
- }
-
- s->H = (double *)malloc(q * sizeof(double));
- for (q_t i = 0; i < q; i++) {
- s->H[i] = H[i];
- }
-
- s->J_probs = Jprobs_from_J(s->n_bond_types, T, s->J);
- s->H_probs = Jprobs_from_J(q, T, s->H);
-
- s->spins = (q_t *)calloc(s->nv, sizeof(q_t));
- s->R = initialize_R(q);
-
- s->M = (v_t *)calloc(q, sizeof(v_t));
- s->M[0] = s->nv; // everyone starts in state 0, remember?
- s->B = (v_t *)calloc(s->n_bond_types, sizeof(v_t));
- s->B[0] = s->nv; // everyone starts in state 0, remember?
-
- s->ReF = (double *)calloc(D * q, sizeof(double));
- s->ImF = (double *)calloc(D * q, sizeof(double));
-
- s->precomputed_cos = precompute_cos(L);
- s->precomputed_sin = precompute_sin(L);
-
- return s;
-}
-
-double state_finite_energy(state_finite_t *s) {
- double E = 0;
-
- for (q_t i = 0; i < s->n_bond_types; i++) {
- E += s->J[i] * s->B[i];
- }
- for (q_t i = 0; i < s->q; i++) {
- E += s->H[i] * s->M[i];
- }
-
- return -E;
-}
-
-void state_finite_free(state_finite_t *s) {
- graph_free(s->g);
- free(s->J);
- free(s->H);
- free(s->J_probs);
- free(s->H_probs);
- free(s->spins);
- free(s->R);
- free(s->M);
- free(s->B);
- free(s->transformations);
- free(s->involutions);
- free(s->transform_site_to_zero);
- free(s->bond_with_zero_type);
- free(s->ReF);
- free(s->ImF);
- free(s->precomputed_cos);
- free(s->precomputed_sin);
- free(s);
-}
-
diff --git a/lib/initial_finite.h b/lib/initial_finite.h
deleted file mode 100644
index 542f923..0000000
--- a/lib/initial_finite.h
+++ /dev/null
@@ -1,27 +0,0 @@
-
-#pragma once
-
-#include <stdbool.h>
-
-#include "types.h"
-#include "dihedral.h"
-#include "cluster_finite.h"
-
-static char *finite_model_t_strings[] = {"ISING", "POTTS", "CLOCK", "DGM"};
-
-typedef enum {
- ISING,
- POTTS,
- CLOCK,
- DGM
-} finite_model_t;
-
-state_finite_t *initial_finite_prepare_ising(D_t D, L_t L, double T, double *H);
-state_finite_t *initial_finite_prepare_potts(D_t D, L_t L, q_t q, double T, double *H);
-state_finite_t *initial_finite_prepare_clock(D_t D, L_t L, q_t q, double T, double *H);
-state_finite_t *initial_finite_prepare_dgm(D_t D, L_t L, q_t q, double T, double *H);
-
-void state_finite_free(state_finite_t *s);
-
-double state_finite_energy(state_finite_t *s);
-
diff --git a/lib/symmetric.c b/lib/symmetric.c
deleted file mode 100644
index 4487538..0000000
--- a/lib/symmetric.c
+++ /dev/null
@@ -1,70 +0,0 @@
-
-#include "symmetric.h"
-
-q_t *symmetric_compose(q_t q, const q_t *g1, const q_t *g2) {
- q_t *g3 = (q_t *)malloc(q * sizeof(q_t));
-
- for (q_t i = 0; i < q; i++) {
- g3[i] = g1[g2[i]];
- }
-
- return g3;
-}
-
-q_t symmetric_act(const q_t *g, q_t s) {
- return g[s];
-}
-
-q_t *symmetric_invert(q_t q, const q_t *g) {
- q_t *g_inv = (q_t *)malloc(q * sizeof(q_t));
-
- for (q_t i = 0; i < q; i++) {
- g_inv[g[i]] = i;
- }
-
- return g_inv;
-}
-
-void swap(q_t *q1, q_t *q2) {
- q_t temp = *q1;
- *q1 = *q2;
- *q2 = temp;
-}
-
-R_t factorial(q_t q) {
- if (q == 0) {
- return 1;
- } else {
- return q * factorial(q - 1);
- }
-}
-
-void permute(q_t *a, q_t l, q_t r, R_t pos, q_t *transformations) {
- if (l == r - 1) {
- for (q_t i = 0; i < r; i++) {
- transformations[r * pos + i] = a[i];
- }
- } else {
- for (q_t i = l; i < r; i++) {
- swap((a+l), (a+i));
- permute(a, l+1, r, pos + (i - l) * factorial(r - l - 1), transformations);
- swap((a+l), (a+i));
- }
- }
-}
-
-q_t *symmetric_gen_transformations(q_t q) {
- q_t *transformations = (q_t *)malloc(q * factorial(q) * sizeof(q_t));
- q_t *tmp = (q_t *)malloc(q * sizeof(q_t));
-
- for (q_t i = 0; i < q; i++) {
- tmp[i] = i;
- }
-
- permute(tmp, 0, q, 0, transformations);
-
- free(tmp);
-
- return transformations;
-}
-
diff --git a/lib/symmetric.h b/lib/symmetric.h
index a73b403..41c8fb6 100644
--- a/lib/symmetric.h
+++ b/lib/symmetric.h
@@ -2,27 +2,9 @@
#pragma once
#include <stdlib.h>
-
#include "types.h"
-
-#ifdef __cplusplus
#include "potts.h"
-extern "C" {
-#endif
-
-q_t *symmetric_compose(q_t q, const q_t *g1, const q_t *g2);
-
-q_t symmetric_act(const q_t *g, q_t s);
-
-q_t *symmetric_invert(q_t q, const q_t *g);
-
-q_t *symmetric_gen_transformations(q_t q);
-
-#ifdef __cplusplus
-}
-#endif
-#ifdef __cplusplus
template <q_t q>
class symmetric_t {
public:
@@ -100,5 +82,4 @@ symmetric_t<q> act_inverse(symmetric_t<q> r1, symmetric_t<q> r2) {
return r3;
}
-#endif
diff --git a/src/wolff_finite.c b/src/wolff_finite.c
deleted file mode 100644
index 9b3e21e..0000000
--- a/src/wolff_finite.c
+++ /dev/null
@@ -1,188 +0,0 @@
-
-#include <time.h>
-#include <getopt.h>
-
-#include <initial_finite.h>
-
-int main(int argc, char *argv[]) {
-
- count_t N = (count_t)1e7;
-
- finite_model_t model = ISING;
-
- q_t q = 2;
- D_t D = 2;
- L_t L = 128;
- double T = 2.26918531421;
- double *J = (double *)calloc(MAX_Q, sizeof(double));
- J[0] = 1.0;
- double *H = (double *)calloc(MAX_Q, sizeof(double));
-
- bool silent = false;
-
- int opt;
- q_t J_ind = 0;
- q_t H_ind = 0;
-
- while ((opt = getopt(argc, argv, "N:t:q:D:L:T:J:H:s")) != -1) {
- switch (opt) {
- case 'N': // number of steps
- N = (count_t)atof(optarg);
- break;
- case 't': // type of simulation
- model = (finite_model_t)atoi(optarg);
- break;
- case 'q': // number of states, if relevant
- q = atoi(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 'J': // couplings, if relevant. nth call couples states i and i + n
- J[J_ind] = atof(optarg);
- J_ind++;
- break;
- case 'H': // external field. nth call couples to state n
- H[H_ind] = atof(optarg);
- H_ind++;
- break;
- case 's': // don't print anything during simulation. speeds up slightly
- silent = true;
- break;
- default:
- exit(EXIT_FAILURE);
- }
- }
-
- state_finite_t *s;
-
- switch (model) {
- case ISING:
- s = initial_finite_prepare_ising(D, L, T, H);
- break;
- case POTTS:
- s = initial_finite_prepare_potts(D, L, q, T, H);
- break;
- case CLOCK:
- s = initial_finite_prepare_clock(D, L, q, T, H);
- break;
- case DGM:
- s = initial_finite_prepare_dgm(D, L, q, T, H);
- break;
- default:
- printf("Not a valid model!\n");
- free(J);
- free(H);
- exit(EXIT_FAILURE);
- }
-
- free(J);
- free(H);
-
- // initialize random number generator
- gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937);
- gsl_rng_set(r, rand_seed());
-
- unsigned long timestamp;
-
- {
- struct timespec spec;
- clock_gettime(CLOCK_REALTIME, &spec);
- timestamp = spec.tv_sec*1000000000LL + spec.tv_nsec;
- }
-
- FILE *outfile_info = fopen("wolff_metadata.txt", "a");
-
- fprintf(outfile_info, "<| \"ID\" -> %lu, \"MODEL\" -> \"%s\", \"q\" -> %" PRIq ", \"D\" -> %" PRID ", \"L\" -> %" PRIL ", \"NV\" -> %" PRIv ", \"NE\" -> %" PRIv ", \"NB\" -> %" PRIq ", \"T\" -> %.15f, \"J\" -> {", timestamp, finite_model_t_strings[model], s->q, D, L, s->nv, s->ne, s->n_bond_types, T);
-
- for (q_t i = 0; i < s->n_bond_types; i++) {
- fprintf(outfile_info, "%.15f", s->J[i]);
- if (i < s->n_bond_types - 1) {
- fprintf(outfile_info, ", ");
- }
- }
-
- fprintf(outfile_info, "}, \"H\" -> {");
-
- for (q_t i = 0; i < s->q; i++) {
- fprintf(outfile_info, "%.15f", s->H[i]);
- if (i < s->q - 1) {
- fprintf(outfile_info, ", ");
- }
- }
-
- fprintf(outfile_info, "} |>\n");
-
- fclose(outfile_info);
-
- char *filename_M = (char *)malloc(255 * sizeof(char));
- char *filename_B = (char *)malloc(255 * sizeof(char));
- char *filename_S = (char *)malloc(255 * sizeof(char));
-
- sprintf(filename_M, "wolff_%lu_M.dat", timestamp);
- sprintf(filename_B, "wolff_%lu_B.dat", timestamp);
- sprintf(filename_S, "wolff_%lu_S.dat", timestamp);
-
- FILE *outfile_M = fopen(filename_M, "wb");
- FILE *outfile_B = fopen(filename_B, "wb");
- FILE *outfile_S = fopen(filename_S, "wb");
-
- free(filename_M);
- free(filename_B);
- free(filename_S);
-
- v_t cluster_size = 0;
-
- if (!silent) printf("\n");
- for (count_t steps = 0; steps < N; steps++) {
- if (!silent) printf("\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, B_0 = %" PRIv ", M_0 = %" PRIv ", S = %" PRIv "\n", steps, N, state_finite_energy(s), s->B[0], s->M[0], cluster_size);
-
- v_t v0 = gsl_rng_uniform_int(r, s->nv);
- R_t step;
-
- bool changed = false;
- while (!changed) {
- step = gsl_rng_uniform_int(r, s->n_involutions);
- if (symmetric_act(s->transformations + s->q * s->involutions[step], s->spins[v0]) != s->spins[v0]) {
- changed = true;
- }
- }
-
- cluster_size = flip_cluster_finite(s, v0, step, r);
-
- // v_t is never going to be bigger than 32 bits, but since it's specified
- // as a fast time many machines will actually have it be 64 bits. we cast
- // it down here to halve space.
-
- for (q_t i = 0; i < s->n_bond_types - 1; i++) { // if we know the occupation of all but one state we know the occupation of the last
- fwrite(&(s->B[i]), sizeof(uint32_t), 1, outfile_B);
- }
-
- for (q_t i = 0; i < s->q - 1; i++) { // if we know the occupation of all but one state we know the occupation of the last
- fwrite(&(s->M[i]), sizeof(uint32_t), 1, outfile_M);
- }
-
- fwrite(&cluster_size, sizeof(uint32_t), 1, outfile_S);
-
- }
- if (!silent) {
- printf("\033[F\033[J");
- }
- printf("WOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, B_0 = %" PRIv ", M_0 = %" PRIv ", S = %" PRIv "\n", N, N, state_finite_energy(s), s->B[0], s->M[0], cluster_size);
-
- fclose(outfile_M);
- fclose(outfile_B);
- fclose(outfile_S);
-
- state_finite_free(s);
- gsl_rng_free(r);
-
- return 0;
-}
-