summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/correlation.h21
-rw-r--r--lib/measure.h48
-rw-r--r--lib/vector.h3
3 files changed, 54 insertions, 18 deletions
diff --git a/lib/correlation.h b/lib/correlation.h
index 5722aab..b3b7d86 100644
--- a/lib/correlation.h
+++ b/lib/correlation.h
@@ -7,29 +7,14 @@
#include <fftw3.h>
template <class R_t, class X_t>
-double correlation_length(const state_t <R_t, X_t> *s) {
- double *data = (double *)fftw_malloc(s->nv * sizeof(double));
- int rank = s->D;
- int *n = (int *)malloc(rank * sizeof(int));
- fftw_r2r_kind *kind = (fftw_r2r_kind *)malloc(rank * sizeof(fftw_r2r_kind));
- for (D_t i = 0; i < rank; i++) {
- n[i] = s->L;
- kind[i] = FFTW_R2HC;
- }
- fftw_plan plan = fftw_plan_r2r(rank, n, data, data, kind, 0);
-
+double correlation_length(const state_t <R_t, X_t> *s, fftw_plan plan, double *in, double *out) {
for (v_t i = 0; i < s->nv; i++) {
- data[i] = correlation_component(s->spins[i]);
+ in[i] = correlation_component(s->spins[i]);
}
fftw_execute(plan);
- double length = pow(data[0], 2);
-
- fftw_destroy_plan(plan);
- fftw_free(data);
- free(n);
- free(kind);
+ double length = pow(out[0], 2);
return length;
}
diff --git a/lib/measure.h b/lib/measure.h
new file mode 100644
index 0000000..3474684
--- /dev/null
+++ b/lib/measure.h
@@ -0,0 +1,48 @@
+
+#pragma once
+
+#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;
+
+#ifdef __cplusplus
+
+#include "state.h"
+#include "correlation.h"
+#include <functional>
+
+template <class R_t, class X_t>
+std::function <void(const state_t <R_t, X_t> *)> measurement_energy_file(FILE *file) {
+ return [=](const state_t <R_t, X_t> *s) {
+ float smaller_E = (float)s->E;
+ fwrite(&smaller_E, sizeof(float), 1, file);
+ };
+}
+
+template <class R_t, class X_t>
+std::function <void(const state_t <R_t, X_t> *)> measurement_cluster_file(FILE *file) {
+ return [=](const state_t <R_t, X_t> *s) {
+ fwrite(&(s->last_cluster_size), sizeof(uint32_t), 1, file);
+ };
+}
+
+template <class R_t, class X_t>
+std::function <void(const state_t <R_t, X_t> *)> measurement_magnetization_file(FILE *file) {
+ return [=](const state_t <R_t, X_t> *s) {
+ write_magnetization(s->M, file);
+ };
+}
+
+template <class R_t, class X_t>
+std::function <void(const state_t <R_t, X_t> *)> measurement_fourier_file(FILE *file, fftw_plan plan, double *fftw_in, double *fftw_out) {
+ return [=](const state_t <R_t, X_t> *s) {
+ float smaller_X = (float)correlation_length(s, plan, fftw_in, fftw_out);
+ fwrite(&smaller_X, sizeof(float), 1, file);
+ };
+}
+
+#endif
+
+
diff --git a/lib/vector.h b/lib/vector.h
index 6c72fd1..2099d28 100644
--- a/lib/vector.h
+++ b/lib/vector.h
@@ -94,3 +94,6 @@ double H_vector(vector_t <q, T> v1, T *H) {
H_vec.x = H;
return (double)(dot <q, T> (v1, H_vec));
}
+
+char const *ON_strings[] = {"TRIVIAL", "ISING", "PLANAR", "HEISENBERG"};
+