summaryrefslogtreecommitdiff
path: root/examples/include
diff options
context:
space:
mode:
Diffstat (limited to 'examples/include')
-rw-r--r--examples/include/colors.h34
-rw-r--r--examples/include/correlation.hpp23
-rw-r--r--examples/include/measure.hpp63
m---------examples/include/randutils0
4 files changed, 120 insertions, 0 deletions
diff --git a/examples/include/colors.h b/examples/include/colors.h
new file mode 100644
index 0000000..abf137c
--- /dev/null
+++ b/examples/include/colors.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include <wolff/types.h>
+
+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;
+ }
+}
+
diff --git a/examples/include/correlation.hpp b/examples/include/correlation.hpp
new file mode 100644
index 0000000..042cff3
--- /dev/null
+++ b/examples/include/correlation.hpp
@@ -0,0 +1,23 @@
+
+#pragma once
+
+#include <wolff/types.h>
+#include <wolff/state.hpp>
+
+#include <fftw3.h>
+
+template <class R_t, class X_t>
+double correlation_length(const state_t <R_t, X_t>& s) {
+ double total = 0;
+
+#ifdef DIMENSION
+ for (D_t j = 0; j < DIMENSION; j++) {
+#else
+ for (D_t j = 0; j < s.D; j++) {
+#endif
+ total += norm_squared(s.ReF[j]) + norm_squared(s.ImF[j]);
+ }
+
+ return total / s.D;
+}
+
diff --git a/examples/include/measure.hpp b/examples/include/measure.hpp
new file mode 100644
index 0000000..e20353c
--- /dev/null
+++ b/examples/include/measure.hpp
@@ -0,0 +1,63 @@
+
+#pragma once
+
+#include <wolff/state.hpp>
+#include "correlation.hpp"
+#include <functional>
+
+#define POSSIBLE_MEASUREMENTS 4
+const unsigned char measurement_energy = 1 << 0;
+const unsigned char measurement_clusterSize = 1 << 1;
+const unsigned char measurement_magnetization = 1 << 2;
+const unsigned char measurement_fourierZero = 1 << 3;
+
+char const *measurement_labels[] = {"E", "S", "M", "F"};
+
+FILE **measure_setup_files(unsigned char flags, unsigned long timestamp) {
+ FILE **files = (FILE **)calloc(POSSIBLE_MEASUREMENTS, sizeof(FILE *));
+
+ for (uint8_t i = 0; i < POSSIBLE_MEASUREMENTS; i++) {
+ if (flags & (1 << i)) {
+ char *filename = (char *)malloc(255 * sizeof(char));
+ sprintf(filename, "wolff_%lu_%s.dat", timestamp, measurement_labels[i]);
+ files[i] = fopen(filename, "wb");
+ free(filename);
+ }
+ }
+
+ return files;
+}
+
+template <class R_t, class X_t>
+std::function <void(const state_t <R_t, X_t>&)> measure_function_write_files(unsigned char flags, FILE **files, std::function <void(const state_t <R_t, X_t>&)> other_f) {
+ return [=] (const state_t <R_t, X_t>& s) {
+ if (flags & measurement_energy) {
+ float smaller_E = (float)s.E;
+ fwrite(&smaller_E, sizeof(float), 1, files[0]);
+ }
+ if (flags & measurement_clusterSize) {
+ fwrite(&(s.last_cluster_size), sizeof(uint32_t), 1, files[1]);
+ }
+ if (flags & measurement_magnetization) {
+ write_magnetization(s.M, files[2]);
+ }
+ if (flags & measurement_fourierZero) {
+ float smaller_X = (float)correlation_length(s);
+ fwrite(&smaller_X, sizeof(float), 1, files[3]);
+ }
+
+ other_f(s);
+ };
+}
+
+void measure_free_files(unsigned char flags, FILE **files) {
+ for (uint8_t i = 0; i < POSSIBLE_MEASUREMENTS; i++) {
+ if (flags & (1 << i)) {
+ fclose(files[i]);
+ }
+ }
+
+ free(files);
+}
+
+
diff --git a/examples/include/randutils b/examples/include/randutils
new file mode 160000
+Subproject 8486a610a954a8248c12485fb4cfc390a5f5f85