From 639552a2649139ba14363f30daa20786532b21b0 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 23 Jul 2018 13:51:13 -0400 Subject: implemented the discrete gaussian model for roughening --- lib/dihedral_inf.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/height.h | 75 ++++++++++++++++++++++++++++++++++----------------- lib/ising.h | 1 + lib/orthogonal.h | 14 +++++----- lib/state.h | 1 - lib/wolff.h | 4 +-- 6 files changed, 138 insertions(+), 35 deletions(-) create mode 100644 lib/dihedral_inf.h (limited to 'lib') diff --git a/lib/dihedral_inf.h b/lib/dihedral_inf.h new file mode 100644 index 0000000..f7c4297 --- /dev/null +++ b/lib/dihedral_inf.h @@ -0,0 +1,78 @@ + +#include "types.h" +#include +#include "height.h" + +template +struct dihedral_inf_t { bool is_reflection; T x; }; + +template +void init(dihedral_inf_t *ptr) { + ptr->is_reflection = false; + ptr->x = (T)0; +} + +template +dihedral_inf_t copy(dihedral_inf_t r) { + return r; +} + +template +void free_spin(dihedral_inf_t r) { + // do nothing! +} + +template +height_t act(dihedral_inf_t r, height_t h) { + height_t h2; + if (r.is_reflection) { + h2.x = r.x - h.x; + } else { + h2.x = r.x + h.x; + } + + return h2; +} + +template +dihedral_inf_t act(dihedral_inf_t r1, dihedral_inf_t r2) { + dihedral_inf_t r3; + + if (r1.is_reflection) { + r3.is_reflection = !(r2.is_reflection); + r3.x = r1.x - r2.x; + } else { + r3.is_reflection = r2.is_reflection; + r3.x = r1.x + r2.x; + } + + return r3; +} + +template +height_t act_inverse(dihedral_inf_t r, height_t h) { + height_t h2; + if (r.is_reflection) { + h2.x = r.x - h.x; + } else { + h2.x = h.x - r.x; + } + + return h2; +} + +template +dihedral_inf_t act_inverse(dihedral_inf_t r1, dihedral_inf_t r2) { + dihedral_inf_t r3; + + if (r1.is_reflection) { + r3.is_reflection = !(r2.is_reflection); + r3.x = r1.x - r2.x; + } else { + r3.is_reflection = r2.is_reflection; + r3.x = r2.x - r1.x; + } + + return r3; +} + diff --git a/lib/height.h b/lib/height.h index 16c4dc5..81d3a2d 100644 --- a/lib/height.h +++ b/lib/height.h @@ -2,61 +2,88 @@ #pragma once #include +#include #include "types.h" -// object definition +/* The following is the minimum definition of a spin class. + * + * The class must contain an M_t and an F_t for holding the sum of an + * integer number of spins and a double-weighted number of spins, + * respectively. + * + * void init(X_t *p); + * void free_spin(X_t p); + * void free_spin(M_t p); + * void free_spin(F_t p); + * X_t copy(X_t x); + * void add(M_t *x1, int factor, X_t x2); + * void add(F_t *x1, double factor, X_t x2); + * M_t scalar_multiple(int factor, X_t x); + * F_t scalar_multiple(double factor, X_t x); + * double norm_squared(F_t x); + * void write_magnetization(M_t M, FILE *outfile); + * + */ + template -struct height_t { T x; }; +struct height_t { + T x; + + typedef T M_t; + typedef double F_t; +}; -// init, copy, add, subtract, scalar_multiple, free_spin, and -// write_magnetization are necessary for the operation of wolff.h template -void init(height_t *ptr) { +void init(height_t *ptr) { ptr->x = (T)0; } template -height_t copy (height_t h) { - return h; +void free_spin(height_t h) { + // do nothing! } template -void add (height_t *h1, height_t h2) { - h1->x += h2.x; +void free_spin(T h) { + // do nothing! } -template -void subtract (height_t *h1, height_T h2) { - h1->x -= h2.x; +void free_spin(double h) { + // do nothing! } template -height_t scalar_multiple(v_t a, height_t h) { - height_t hm; - hm.x = a * h.x; +height_t copy(height_t h) { + return h; +} - return hm; +template +void add(T *h1, int a, height_t h2) { + (*h1) += a * h2.x; } template -void free_spin (height_t h) { +void add(double *h1, double a, height_t h2) { + (*h1) += a * h2.x; } template -void write_magnetization(height_t M, FILE *outfile) { - fwrite(&(M.x), sizeof(T), 1, outfile); +T scalar_multiple(int factor, height_t h) { + return factor * h.x; } template -double correlation_component(height_t h) { - return (double)h.x; +double scalar_multiple(double factor, height_t h) { + return factor * h.x; } -// below here are not necessary for operation +double norm_squared(double h) { + return pow(h, 2); +} template -T dot(height_t h1, height_t h2) { - return (h1.x - h2.x) * (h1.x - h2.x); +void write_magnetization(T M, FILE *outfile) { + fwrite(&M, sizeof(T), 1, outfile); } diff --git a/lib/ising.h b/lib/ising.h index b4856c3..d956d88 100644 --- a/lib/ising.h +++ b/lib/ising.h @@ -19,6 +19,7 @@ * void add(M_t *x1, int factor, X_t x2); * void add(F_t *x1, double factor, X_t x2); * M_t scalar_multiple(int factor, X_t x); + * F_t scalar_multiple(double factor, X_t x); * double norm_squared(F_t x); * void write_magnetization(M_t M, FILE *outfile); * diff --git a/lib/orthogonal.h b/lib/orthogonal.h index 340ee2c..523fd54 100644 --- a/lib/orthogonal.h +++ b/lib/orthogonal.h @@ -144,7 +144,7 @@ orthogonal_t act_inverse (orthogonal_t m1, orthogonal_t m2) } template -orthogonal_t generate_rotation_uniform (gsl_rng *r, const state_t , vector_t > *s) { +orthogonal_t generate_rotation_uniform (gsl_rng *r, vector_t v) { orthogonal_t ptr; ptr.is_reflection = true; ptr.x = (double *)calloc(q, sizeof(double)); @@ -166,7 +166,7 @@ orthogonal_t generate_rotation_uniform (gsl_rng *r, const state_t -orthogonal_t generate_rotation_perturbation (gsl_rng *r, const state_t , vector_t > *s, double epsilon) { +orthogonal_t generate_rotation_perturbation (gsl_rng *r, vector_t v, double epsilon) { orthogonal_t m; vector_t tmp_v; m.is_reflection = true; @@ -179,15 +179,15 @@ orthogonal_t generate_rotation_perturbation (gsl_rng *r, const state for (q_t i = 0; i < q; i++) { tmp_v.x[i] = gsl_ran_ugaussian(r); - M2 += pow(s->M.x[i], 2); - tmpM += tmp_v.x[i] * s->M.x[i]; + M2 += pow(v.x[i], 2); + tmpM += tmp_v.x[i] * v.x[i]; } double v2 = 0; double factor = gsl_ran_ugaussian(r); for (q_t i = 0; i < q; i++) { - tmp_v.x[i] = (tmp_v.x[i] - tmpM * s->M.x[i] / M2) + epsilon * factor * s->M.x[i] / sqrt(M2); + tmp_v.x[i] = (tmp_v.x[i] - tmpM * v.x[i] / M2) + epsilon * factor * v.x[i] / sqrt(M2); v2 += tmp_v.x[i] * tmp_v.x[i]; } @@ -197,9 +197,7 @@ orthogonal_t generate_rotation_perturbation (gsl_rng *r, const state tmp_v.x[i] /= mag_v; } - vector_t v = act_inverse(s->R, tmp_v); - free(tmp_v.x); - m.x = v.x; + m.x = tmp_v.x; v2 = 0; diff --git a/lib/state.h b/lib/state.h index 8630810..3c6cafa 100644 --- a/lib/state.h +++ b/lib/state.h @@ -5,7 +5,6 @@ #include "types.h" #include "graph.h" -#include "ising.h" template class state_t { diff --git a/lib/wolff.h b/lib/wolff.h index 4e93d01..8286024 100644 --- a/lib/wolff.h +++ b/lib/wolff.h @@ -3,14 +3,14 @@ #include "state.h" template -void wolff(count_t N, state_t *s, std::function *)> gen_R, std::function *)> measurements, gsl_rng *r, bool silent) { +void wolff(count_t N, state_t *s, std::function gen_R, std::function *)> measurements, gsl_rng *r, bool silent) { 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); v_t v0 = gsl_rng_uniform_int(r, s->nv); - R_t step = gen_R(r, s); + R_t step = gen_R(r, s->spins[v0]); flip_cluster (s, v0, step, r); free_spin(step); -- cgit v1.2.3-70-g09d2