summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wolff_potts.c (renamed from src/wolff.c)13
-rw-r--r--src/wolff_vector.c202
2 files changed, 213 insertions, 2 deletions
diff --git a/src/wolff.c b/src/wolff_potts.c
index 7b6b56f..7d9beb3 100644
--- a/src/wolff.c
+++ b/src/wolff_potts.c
@@ -92,11 +92,12 @@ int main(int argc, char *argv[]) {
s->q = q;
- s->spins = (q_t *)calloc(h->nv + 1, sizeof(q_t));
+ s->spins = (q_t *)calloc(h->nv, sizeof(q_t));
s->T = T;
s->H = H;
s->J = J;
+ s->R = (dihedral_t *)calloc(1, sizeof(dihedral_t));
s->J_probs = (double *)calloc(pow(q, 2), sizeof(double));
for (q_t i = 0; i < q; i++) {
@@ -159,7 +160,13 @@ int main(int argc, char *argv[]) {
while (n_flips / h->nv < n) {
v_t v0 = gsl_rng_uniform_int(r, h->nv);
- q_t step = 1 + gsl_rng_uniform_int(r, q - 1);
+ q_t step;
+
+ if (q == 2) {
+ step = 1;
+ } else {
+ step = gsl_rng_uniform_int(r, q);
+ }
v_t tmp_flips = flip_cluster(s, v0, step, r);
n_flips += tmp_flips;
@@ -322,12 +329,14 @@ int main(int argc, char *argv[]) {
free(sE[i]);
free(lifetimes[i]);
}
+ free(lifetimes);
free(freqs);
free(sE);
free(s->H_probs);
free(s->J_probs);
free(s->M);
free(s->spins);
+ free(s->R);
graph_free(s->g);
free(s);
free(H);
diff --git a/src/wolff_vector.c b/src/wolff_vector.c
new file mode 100644
index 0000000..c6ab695
--- /dev/null
+++ b/src/wolff_vector.c
@@ -0,0 +1,202 @@
+
+#include <wolff.h>
+
+double identity(double x) {
+ return x;
+}
+
+double zero(double *x) {
+ return 0.0;
+}
+
+double test(double *x) {
+ return -x[1];
+}
+
+int main(int argc, char *argv[]) {
+
+ L_t L = 128;
+ count_t N = (count_t)1e7;
+ count_t min_runs = 10;
+ count_t n = 3;
+ q_t q = 2;
+ D_t D = 2;
+ double T = 2.26918531421;
+ double *H = (double *)calloc(MAX_Q, sizeof(double));
+ double eps = 0;
+ bool silent = false;
+
+ int opt;
+ q_t H_ind = 0;
+
+ while ((opt = getopt(argc, argv, "N:n:D:L:q:T:H:m:e:s")) != -1) {
+ switch (opt) {
+ case 'N':
+ N = (count_t)atof(optarg);
+ break;
+ case 'n':
+ n = (count_t)atof(optarg);
+ break;
+ case 'D':
+ D = atoi(optarg);
+ break;
+ case 'L':
+ L = atoi(optarg);
+ break;
+ case 'q':
+ q = atoi(optarg);
+ break;
+ case 'T':
+ T = atof(optarg);
+ break;
+ case 'H':
+ H[H_ind] = atof(optarg);
+ H_ind++;
+ break;
+ case 'm':
+ min_runs = atoi(optarg);
+ break;
+ case 'e':
+ eps = atof(optarg);
+ break;
+ case 's':
+ silent = true;
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937);
+ gsl_rng_set(r, rand_seed());
+
+ vector_state_t *s = (vector_state_t *)calloc(1, sizeof(vector_state_t));
+
+ graph_t *h = graph_create_square(D, L);
+ s->g = graph_add_ext(h);
+
+ s->n = q;
+
+ s->spins = (double *)calloc(n * h->nv, sizeof(double));
+
+ for (v_t i = 0; i < h->nv; i++) {
+ s->spins[q * i] = 1.0;
+ }
+
+ s->T = T;
+ s->H = test;
+ s->J = identity;
+
+ s->R = (double *)calloc(q * q, sizeof(double));
+
+ for (q_t i = 0; i < q; i++) {
+ s->R[q * i + i] = 1.0;
+ }
+
+ s->M = (double *)calloc(q, sizeof(double));
+ s->M[0] = 1.0 * (double)h->nv;
+ s->E = - ((double)h->ne) * s->J(1.0) - s->H(s->M);
+
+ printf("%g %g\n", s->E, s->M[0]);
+
+ double diff = 1e31;
+ count_t n_runs = 0;
+
+ meas_t *E, *clust, **M;
+
+ M = (meas_t **)malloc(q * sizeof(meas_t *));
+ for (q_t i = 0; i < q; i++) {
+ M[i] = (meas_t *)calloc(1, sizeof(meas_t));
+ }
+
+ E = calloc(1, sizeof(meas_t));
+ clust = calloc(1, sizeof(meas_t));
+
+ if (!silent) printf("\n");
+ while (((diff > eps || diff != diff) && n_runs < N) || n_runs < min_runs) {
+ if (!silent) printf("\033[F\033[JWOLFF: sweep %" PRIu64
+ ", dH/H = %.4f, dM/M = %.4f, dC/C = %.4f, dX/X = %.4f, cps: %.1f\n",
+ n_runs, fabs(E->dx / E->x), M[0]->dx / M[0]->x, E->dc / E->c, M[0]->dc / M[0]->c, h->nv / clust->x);
+
+ count_t n_flips = 0;
+
+ while (n_flips / h->nv < n) {
+ v_t v0 = gsl_rng_uniform_int(r, h->nv);
+ double *step = gen_rot(r, q);
+
+ v_t tmp_flips = flip_cluster_vector(s, v0, step, r);
+ free(step);
+ n_flips += tmp_flips;
+
+ update_meas(clust, tmp_flips);
+ }
+
+ for (q_t i = 0; i < q; i++) {
+ update_meas(M[i], s->M[i]);
+ }
+ update_meas(E, s->E);
+
+ diff = fabs(E->dc / E->c);
+
+ n_runs++;
+ }
+ if (!silent) {
+ printf("\033[F\033[J");
+ }
+ printf("WOLFF: sweep %" PRIu64
+ ", dH/H = %.4f, dM/M = %.4f, dC/C = %.4f, dX/X = %.4f, cps: %.1f\n",
+ n_runs, fabs(E->dx / E->x), M[0]->dx / M[0]->x, E->dc / E->c, M[0]->dc / M[0]->c, h->nv / clust->x);
+
+ FILE *outfile = fopen("out.m", "a");
+
+ fprintf(outfile, "<|D->%" PRID ",L->%" PRIL ",q->%" PRIq ",T->%.15f", D, L, q, T);
+ fprintf(outfile, "},E->%.15f,\\[Delta]E->%.15f,C->%.15f,\\[Delta]C->%.15f,M->{", E->x / h->nv, E->dx / h->nv, E->c / h->nv, E->dc / h->nv);
+ for (q_t i = 0; i < q; i++) {
+ fprintf(outfile, "%.15f", M[i]->x / h->nv);
+ if (i != q-1) {
+ fprintf(outfile, ",");
+ }
+ }
+ fprintf(outfile, "},\\[Delta]M->{");
+ for (q_t i = 0; i < q; i++) {
+ fprintf(outfile, "%.15f", M[i]->dx / h->nv);
+ if (i != q-1) {
+ fprintf(outfile, ",");
+ }
+ }
+ fprintf(outfile, "},\\[Chi]->{");
+ for (q_t i = 0; i < q; i++) {
+ fprintf(outfile, "%.15f", M[i]->c / h->nv);
+ if (i != q-1) {
+ fprintf(outfile, ",");
+ }
+ }
+ fprintf(outfile, "},\\[Delta]\\[Chi]->{");
+ for (q_t i = 0; i < q; i++) {
+ fprintf(outfile, "%.15f", M[i]->dc / h->nv);
+ if (i != q-1) {
+ fprintf(outfile, ",");
+ }
+ }
+ fprintf(outfile, "}|>\n");
+
+ fclose(outfile);
+
+ free(E);
+ free(clust);
+ for (q_t i = 0; i < q; i++) {
+ free(M[i]);
+ }
+ free(M);
+ free(H);
+ free(s->M);
+ free(s->R);
+ free(s->spins);
+ graph_free(s->g);
+ free(s);
+ graph_free(h);
+ gsl_rng_free(r);
+
+ return 0;
+}
+