summaryrefslogtreecommitdiff
path: root/lib/measure.h
blob: d20c08186166554157e18fdcd3d83a7cfb3e81d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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) {
  return [=](const state_t <R_t, X_t> *s) {
    float smaller_X = (float)correlation_length(s);
    fwrite(&smaller_X, sizeof(float), 1, file);
  };
}

#endif