summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-06-28 14:20:25 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-06-28 14:20:25 -0400
commit3eb67e3bca774eb0441db60158e1968ad901273b (patch)
tree5250190f9230b129b4d82a9d23cc5ae6547a6b8d /lib
parent25781a4041fa75a3394949d111be3abbefc97c26 (diff)
downloadc++-3eb67e3bca774eb0441db60158e1968ad901273b.tar.gz
c++-3eb67e3bca774eb0441db60158e1968ad901273b.tar.bz2
c++-3eb67e3bca774eb0441db60158e1968ad901273b.zip
cleaned up the operation of the finite-group wolff code
Diffstat (limited to 'lib')
-rw-r--r--lib/cluster_finite.h4
-rw-r--r--lib/graph.h2
-rw-r--r--lib/initial_finite.c211
-rw-r--r--lib/initial_finite.h24
-rw-r--r--lib/measurement.h5
-rw-r--r--lib/wolff_finite.c70
6 files changed, 241 insertions, 75 deletions
diff --git a/lib/cluster_finite.h b/lib/cluster_finite.h
index abdc8fc..ad45ed3 100644
--- a/lib/cluster_finite.h
+++ b/lib/cluster_finite.h
@@ -23,6 +23,10 @@
#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;
diff --git a/lib/graph.h b/lib/graph.h
index 9c80dd6..cb47faa 100644
--- a/lib/graph.h
+++ b/lib/graph.h
@@ -1,4 +1,6 @@
+#pragma once
+
#include <inttypes.h>
#include <math.h>
#include <stdlib.h>
diff --git a/lib/initial_finite.c b/lib/initial_finite.c
new file mode 100644
index 0000000..f286dcc
--- /dev/null
+++ b/lib/initial_finite.c
@@ -0,0 +1,211 @@
+
+#include "initial_finite.h"
+
+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;
+}
+
+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 = 1;
+
+ s->transformations = (q_t *)malloc(2 * sizeof(q_t));
+ s->transformations[0] = 1;
+ s->transformations[1] = 0;
+
+ 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->E = - ((double)s->ne) * s->J[0] - ((double)s->nv) * s->H[0];
+ s->M = (v_t *)calloc(2, sizeof(v_t));
+ s->M[0] = s->nv; // everyone starts in state 0, remember?
+
+ 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 = q;
+ s->transformations = dihedral_gen_transformations(q);
+
+ s->T = T;
+ s->J = (double *)calloc(q, sizeof(double));
+ s->J[0] = 1.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(q, 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->E = - ((double)s->ne) * s->J[0] - ((double)s->nv) * s->H[0];
+ s->M = (v_t *)calloc(q, sizeof(v_t));
+ s->M[0] = s->nv; // everyone starts in state 0, remember?
+
+ 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 = q;
+ s->transformations = dihedral_gen_transformations(q);
+
+ s->T = T;
+ s->J = (double *)malloc(q * sizeof(double));
+
+ for (q_t i = 0; i < q; 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(q, 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->E = - ((double)s->ne) * s->J[0] - ((double)s->nv) * s->H[0];
+ s->M = (v_t *)calloc(q, sizeof(v_t));
+ s->M[0] = s->nv; // everyone starts in state 0, remember?
+
+ 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 = q;
+ s->transformations = dihedral_gen_transformations(q);
+
+ s->T = T;
+ s->J = (double *)malloc(q * sizeof(double));
+
+ for (q_t i = 0; i < q / 2 + 1; i++) {
+ s->J[i] = -pow(i, 2);
+ }
+ for (q_t i = 1; i < (q + 1) / 2; i++) {
+ s->J[q - 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(q, 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->E = - ((double)s->ne) * s->J[0] - ((double)s->nv) * s->H[0];
+ s->M = (v_t *)calloc(q, sizeof(v_t));
+ s->M[0] = s->nv; // everyone starts in state 0, remember?
+
+ return s;
+}
+
+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->transformations);
+ free(s);
+}
+
diff --git a/lib/initial_finite.h b/lib/initial_finite.h
new file mode 100644
index 0000000..65414cd
--- /dev/null
+++ b/lib/initial_finite.h
@@ -0,0 +1,24 @@
+
+#pragma once
+
+#include <stdbool.h>
+
+#include "types.h"
+#include "dihedral.h"
+#include "cluster_finite.h"
+
+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);
+
+
diff --git a/lib/measurement.h b/lib/measurement.h
index 46c034f..eaa260b 100644
--- a/lib/measurement.h
+++ b/lib/measurement.h
@@ -24,11 +24,6 @@ typedef struct {
double O2;
} autocorr_t;
-typedef struct {
- void (*f)(state_finite_t *, void *);
- void *data;
-} measurement_t;
-
void meas_update(meas_t *m, double x);
double meas_dx(const meas_t *m);
diff --git a/lib/wolff_finite.c b/lib/wolff_finite.c
deleted file mode 100644
index 64de9ba..0000000
--- a/lib/wolff_finite.c
+++ /dev/null
@@ -1,70 +0,0 @@
-
-#include "cluster_finite.h"
-
-void wolff_finite(state_finite_t *s, count_t sweeps, count_t sweeps_per_measurement, count_t n_measurements, measurement_t *measurements) {
- for (count_t i = 0; i < sweeps; i++) {
-
- count_t n_flips = 0;
-
- while (n_flips / h->nv < sweeps_per_measurement) {
- v_t v0 = gsl_rng_uniform_int(r, h->nv);
- R_t step;
-
- bool changed = false;
- while (!changed) {
- step = gsl_rng_uniform_int(r, s->n_transformations);
- if v(symmetric_act(s->transformations + q * step, s->spins[v0]) != s->spins[v0]) {
- changed = true;
- }
- }
-
- v_t tmp_flips = flip_cluster_finite(s, v0, step, r);
- n_flips += tmp_flips;
-
- if (n_runs > 0) {
- n_steps++;
- meas_update(clust, tmp_flips);
-
- if (record_autocorrelation && n_steps % ac_skip == 0) {
- update_autocorr(autocorr, s->E);
- }
-
- }
-
- }
-
- for (q_t i = 0; i < q; i++) {
- meas_update(M[i], s->M[i]);
- }
- meas_update(E, s->E);
-
- q_t n_at_max = 0;
- q_t max_M_i = 0;
- v_t max_M = 0;
-
- for (q_t i = 0; i < q; i++) {
- if (s->M[i] > max_M) {
- n_at_max = 1;
- max_M_i = i;
- max_M = s->M[i];
- } else if (s->M[i] == max_M) {
- n_at_max++;
- }
- }
-
- if (record_distribution) {
- mag_dist[s->M[0]]++;
- }
-
- if (n_at_max == 1) {
- for (q_t i = 0; i < q; i++) {
- meas_update(sM[max_M_i][i], s->M[i]);
- }
- meas_update(sE[max_M_i], s->E);
- freqs[max_M_i]++;
- }
-
- diff = fabs(meas_dx(clust) / clust->x);
- }
-}
-