summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-21 13:21:49 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-21 13:21:49 -0400
commit0c69763278ed102d0e37aa1fb4feda5827c26c62 (patch)
tree0227d36b272c1243cde6827dcde6f2b3014abb95 /lib
parentf14e6eb0e8cb01ee29f98db9797ac37f3e690cb8 (diff)
downloadc++-0c69763278ed102d0e37aa1fb4feda5827c26c62.tar.gz
c++-0c69763278ed102d0e37aa1fb4feda5827c26c62.tar.bz2
c++-0c69763278ed102d0e37aa1fb4feda5827c26c62.zip
simplified the way that measurements work
Diffstat (limited to 'lib')
-rw-r--r--lib/measure.h70
-rw-r--r--lib/wolff.h6
2 files changed, 44 insertions, 32 deletions
diff --git a/lib/measure.h b/lib/measure.h
index 52e43af..0b86309 100644
--- a/lib/measure.h
+++ b/lib/measure.h
@@ -3,53 +3,67 @@
#include "measurement.h"
-#define POSSIBLE_MEASUREMENTS 5
+#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"};
+
#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);
- };
+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> *)> 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);
+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);
};
}
-template <class R_t, class X_t>
-std::function <void(const state_t <R_t, X_t> *)> measurement_average_cluster(meas_t *x) {
- return [=](const state_t <R_t, X_t> *s) {
- meas_update(x, s->last_cluster_size);
- };
+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);
}
#endif
diff --git a/lib/wolff.h b/lib/wolff.h
index 21e88d9..4e93d01 100644
--- a/lib/wolff.h
+++ b/lib/wolff.h
@@ -3,7 +3,7 @@
#include "state.h"
template <class R_t, class X_t>
-void wolff(count_t N, state_t <R_t, X_t> *s, std::function <R_t(gsl_rng *, const state_t <R_t, X_t> *)> gen_R, unsigned int n_measurements, std::function <void(const state_t <R_t, X_t> *)> *measurements, gsl_rng *r, bool silent) {
+void wolff(count_t N, state_t <R_t, X_t> *s, std::function <R_t(gsl_rng *, const state_t <R_t, X_t> *)> gen_R, std::function <void(const state_t <R_t, X_t> *)> measurements, gsl_rng *r, bool silent) {
if (!silent) printf("\n");
for (count_t steps = 0; steps < N; steps++) {
@@ -14,9 +14,7 @@ void wolff(count_t N, state_t <R_t, X_t> *s, std::function <R_t(gsl_rng *, const
flip_cluster <R_t, X_t> (s, v0, step, r);
free_spin(step);
- for (unsigned int i = 0; i < n_measurements; i++) {
- measurements[i](s);
- }
+ measurements(s);
}
if (!silent) {