summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-21 19:43:16 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-21 19:43:16 -0400
commite3fbb92e68f0410f106285c9a49ecf8cd0a488a9 (patch)
tree7b7412af76032746e3b5c4281a7c7ba076302791 /src
parent0af22d23f860d7ab1c0e9355f55cade310afd748 (diff)
downloadc++-e3fbb92e68f0410f106285c9a49ecf8cd0a488a9.tar.gz
c++-e3fbb92e68f0410f106285c9a49ecf8cd0a488a9.tar.bz2
c++-e3fbb92e68f0410f106285c9a49ecf8cd0a488a9.zip
added visualization, and started potts
Diffstat (limited to 'src')
-rw-r--r--src/wolff_On.cpp75
-rw-r--r--src/wolff_ising.cpp21
-rw-r--r--src/wolff_potts.cpp138
3 files changed, 229 insertions, 5 deletions
diff --git a/src/wolff_On.cpp b/src/wolff_On.cpp
index 491fb27..32a6fc4 100644
--- a/src/wolff_On.cpp
+++ b/src/wolff_On.cpp
@@ -1,5 +1,8 @@
#include <getopt.h>
+#ifdef HAVE_GLUT
+#include <GL/glut.h>
+#endif
#include <wolff.h>
#include <correlation.h>
@@ -29,6 +32,36 @@ double H_modulated(vector_R_t v, int order, double mag) {
return mag * cos(order * theta(v));
}
+double hue_to_R(double theta) {
+ if (((M_PI / 3 <= theta) && (theta < 2 * M_PI / 3)) || ((4 * M_PI / 3 <= theta) && (theta < 5 * M_PI / 3))) {
+ return 1.0 - fabs(fmod(theta / (2 * M_PI / 6), 2) - 1.0);
+ } else if (((0 <= theta) && (theta < M_PI / 3)) || ((5 * M_PI / 3 <= theta) && (theta <= 2 * M_PI))) {
+ return 1.0;
+ } else {
+ return 0.0;
+ }
+}
+
+double hue_to_G(double theta) {
+ if (((0 <= theta) && (theta < M_PI / 3)) || ((M_PI <= theta) && (theta < 4 * M_PI / 3))) {
+ return 1.0 - fabs(fmod(theta / (2 * M_PI / 6), 2) - 1.0);
+ } else if (((M_PI / 3 <= theta) && (theta < 2 * M_PI / 3)) || ((2 * M_PI / 3 <= theta) && (theta < M_PI))) {
+ return 1.0;
+ } else {
+ return 0.0;
+ }
+}
+
+double hue_to_B(double theta) {
+ if (((2 * M_PI / 3 <= theta) && (theta < M_PI)) || ((5 * M_PI / 3 <= theta) && (theta <= 2 * M_PI))) {
+ return 1.0 - fabs(fmod(theta / (2 * M_PI / 6), 2) - 1.0);
+ } else if (((M_PI <= theta) && (theta < 4 * M_PI / 3)) || ((4 * M_PI / 3 <= theta) && (theta < 5 * M_PI / 3))) {
+ return 1.0;
+ } else {
+ return 0.0;
+ }
+}
+
int main(int argc, char *argv[]) {
count_t N = (count_t)1e7;
@@ -41,6 +74,8 @@ int main(int argc, char *argv[]) {
bool silent = false;
bool use_pert = false;
bool N_is_sweeps = false;
+ bool draw = false;
+ unsigned int window_size = 512;
bool modulated_field = false;
int order = 2;
@@ -54,7 +89,7 @@ int main(int argc, char *argv[]) {
unsigned char measurement_flags = 0;
- while ((opt = getopt(argc, argv, "N:q:D:L:T:J:H:spe:mo:M:S")) != -1) {
+ 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);
@@ -93,6 +128,17 @@ int main(int argc, char *argv[]) {
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);
}
@@ -153,6 +199,33 @@ int main(int argc, char *argv[]) {
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 = act_inverse(s->R, s->spins[i]);
+ double thetai = fmod(2 * M_PI + theta(v_tmp), 2 * M_PI);
+ free_spin(v_tmp);
+ 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) {};
}
diff --git a/src/wolff_ising.cpp b/src/wolff_ising.cpp
index f4073da..83b6448 100644
--- a/src/wolff_ising.cpp
+++ b/src/wolff_ising.cpp
@@ -1,6 +1,8 @@
#include <getopt.h>
+#ifdef HAVE_GLUT
#include <GL/glut.h>
+#endif
// include your group and spin space
#include <z2.h>
@@ -11,7 +13,7 @@
int main(int argc, char *argv[]) {
- count_t N = (count_t)1e7;
+ count_t N = (count_t)1e4;
D_t D = 2;
L_t L = 128;
@@ -20,10 +22,11 @@ int main(int argc, char *argv[]) {
bool silent = false;
bool draw = false;
+ unsigned int window_size = 512;
int opt;
- while ((opt = getopt(argc, argv, "N:D:L:T:H:sd")) != -1) {
+ while ((opt = getopt(argc, argv, "N:D:L:T:H:sdw:")) != -1) {
switch (opt) {
case 'N': // number of steps
N = (count_t)atof(optarg);
@@ -44,8 +47,16 @@ int main(int argc, char *argv[]) {
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);
}
@@ -95,11 +106,12 @@ int main(int argc, char *argv[]) {
} 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(L,L);
- glutCreateWindow("null");
+ glutInitWindowSize(window_size, window_size);
+ glutCreateWindow("wolff");
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@@ -118,6 +130,7 @@ int main(int argc, char *argv[]) {
}
glFlush();
};
+#endif
}
// run wolff for N cluster flips
diff --git a/src/wolff_potts.cpp b/src/wolff_potts.cpp
new file mode 100644
index 0000000..9d22ea4
--- /dev/null
+++ b/src/wolff_potts.cpp
@@ -0,0 +1,138 @@
+
+#include <getopt.h>
+#include <GL/glut.h>
+
+// include your group and spin space
+#include <symmetric.h>
+#include <potts.h>
+
+// include wolff.h
+#include <wolff.h>
+
+int main(int argc, char *argv[]) {
+
+ count_t N = (count_t)1e7;
+
+ D_t D = 2;
+ L_t L = 128;
+ double T = 2.26918531421;
+ double H = 0.0;
+
+ bool silent = false;
+ bool draw = false;
+
+ int opt;
+
+ while ((opt = getopt(argc, argv, "N:D:L:T:H:sd")) != -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 'd':
+ draw = true;
+ 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(potts_t, ising_t)> Z = [] (ising_t s1, ising_t s2) -> double {
+ if (s1.x == s2.x) {
+ return 1.0;
+ } else {
+ return -1.0;
+ }
+ };
+
+ // define spin-field coupling
+ std::function <double(ising_t)> B = [=] (ising_t s) -> double {
+ if (s.x) {
+ return -H;
+ } else {
+ return H;
+ }
+ };
+
+ // initialize state object
+ state_t <z2_t, ising_t> s(D, L, T, Z, B);
+
+ // define function that generates self-inverse rotations
+ std::function <z2_t(gsl_rng *, const state_t <z2_t, ising_t> *)> gen_R = [] (gsl_rng *, const state_t <z2_t, ising_t> *) -> z2_t {
+ z2_t rot;
+ rot.x = true;
+ return rot;
+ };
+
+ // define function that updates any number of measurements
+ std::function <void(const state_t <z2_t, ising_t> *)> measurement;
+
+ double average_M = 0;
+ if (!draw) {
+ // a very simple example: measure the average magnetization
+ measurement = [&] (const state_t <z2_t, ising_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
+
+ // initialize glut
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
+ glutInitWindowSize(L,L);
+ glutCreateWindow("null");
+ glClearColor(0.0,0.0,0.0,0.0);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluOrtho2D(0.0, L, 0.0, L);
+
+ measurement = [&] (const state_t <z2_t, ising_t> *s) {
+ average_M += (double)s->M / (double)N / (double)s->nv;
+ glClear(GL_COLOR_BUFFER_BIT);
+ for (v_t i = 0; i < pow(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 / L, i % L, (i / L) + 1, (i % L) + 1);
+ }
+ glFlush();
+ };
+ }
+
+ // run wolff for N cluster flips
+ wolff(N, &s, gen_R, measurement, r, silent);
+
+ // tell us what we found!
+ printf("%" PRIcount " Ising 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;
+
+}
+