From 1343a3fe6bd17a2487f12a0d61be8dc83cd722a0 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 15 Oct 2018 22:57:17 -0400 Subject: many changes, including reworking the measurements system --- examples/src/models/ising/ising.hpp | 33 +++++++++++++++++++++++++++---- examples/src/models/ising/wolff_ising.cpp | 25 ++++++++++------------- 2 files changed, 39 insertions(+), 19 deletions(-) (limited to 'examples/src/models/ising') diff --git a/examples/src/models/ising/ising.hpp b/examples/src/models/ising/ising.hpp index ae20840..73b06ed 100644 --- a/examples/src/models/ising/ising.hpp +++ b/examples/src/models/ising/ising.hpp @@ -5,17 +5,31 @@ #include +// all that is required to use wolff.hpp is a default constructor class ising_t { public: bool x; - typedef int M_t; - typedef double F_t; - ising_t() : x(false) {} - ising_t(bool x) : x(x) {} + + // optional constructors for syntactic sugar + ising_t(bool x) : x(x) {} ising_t(int x) : x((bool)x) {} + /* below this comment is code required only for using measure.hpp in the + * examples folder, which provides an interface for measuring several + * generic features of models. these require + * + * - an M_t, representing the magnetization or sum of all spins + * - an F_t, representing a double-weighted version of the magnetization + * - the overloaded operator *, which takes a v_t (unsigned int) and returns an M_t + * - the overloaded operator *, which takes a double and returns an F_t + * - the overloaded operator -, which takes another X_t and returns an M_t + */ + + typedef int M_t; + typedef double F_t; + inline int operator*(v_t a) const { if (x) { return -(int)a; @@ -45,6 +59,12 @@ class ising_t { } }; +/* using measure.hpp additionally requires a norm_squared function which takes + * an F_t to a double, and a write_magnetization function, which takes an M_t + * and a FILE pointer and appropriately records the contents of the former to + * the latter. + */ + double norm_squared(double s) { return pow(s, 2); } @@ -53,6 +73,11 @@ void write_magnetization(int M, FILE *outfile) { fwrite(&M, sizeof(int), 1, outfile); } +/* these definitions allow wolff/finite_states.hpp to be invoked and provide + * much faster performance for models whose number of possible spin + * configurations is finite. + */ + #define N_STATES 2 const ising_t states[2] = {ising_t(0), ising_t(1)}; q_t state_to_ind(ising_t state) { return (q_t)state.x; } diff --git a/examples/src/models/ising/wolff_ising.cpp b/examples/src/models/ising/wolff_ising.cpp index f7a3ada..de04f32 100644 --- a/examples/src/models/ising/wolff_ising.cpp +++ b/examples/src/models/ising/wolff_ising.cpp @@ -127,14 +127,12 @@ int main(int argc, char *argv[]) { return z2_t(true); }; - FILE **outfiles = measure_setup_files(measurement_flags, timestamp); - - std::function &)> other_f; + std::function &, const wolff_research_measurements&)> other_f; uint64_t sum_of_clusterSize = 0; if (N_is_sweeps) { - other_f = [&] (const state_t& s) { - sum_of_clusterSize += s.last_cluster_size; + other_f = [&] (const state_t& s, const wolff_research_measurements& meas) { + sum_of_clusterSize += meas.last_cluster_size; }; } else if (draw) { #ifdef HAVE_GLUT @@ -148,7 +146,7 @@ int main(int argc, char *argv[]) { glLoadIdentity(); gluOrtho2D(0.0, L, 0.0, L); - other_f = [] (const state_t & s) { + other_f = [] (const state_t & s, const wolff_research_measurements& meas) { glClear(GL_COLOR_BUFFER_BIT); for (v_t i = 0; i < pow(s.L, 2); i++) { #ifdef NOFIELD @@ -166,10 +164,10 @@ int main(int argc, char *argv[]) { }; #endif } else { - other_f = [] (const state_t& s) {}; + other_f = [] (const state_t& s, const wolff_research_measurements& meas) {}; } - std::function &)> measurements = measure_function_write_files(measurement_flags, outfiles, other_f); + wolff_research_measurements m(measurement_flags, timestamp, other_f, s, silent); // add line to metadata file with run info { @@ -185,18 +183,15 @@ int main(int argc, char *argv[]) { count_t N_rounds = 0; printf("\n"); while (sum_of_clusterSize < N * s.nv) { - printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, s.E, s.last_cluster_size); - wolff(N, s, gen_R, measurements, rng, silent); + printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, m.E, m.last_cluster_size); + wolff(N, s, gen_R, m, rng); N_rounds++; } - printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, s.E, s.last_cluster_size); + printf("\033[F\033[J\033[F\033[JWOLFF: sweep %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n\n", (count_t)((double)sum_of_clusterSize / (double)s.nv), N, m.E, m.last_cluster_size); } else { - wolff(N, s, gen_R, measurements, rng, silent); + wolff(N, s, gen_R, m, rng); } - measure_free_files(measurement_flags, outfiles); - return 0; - } -- cgit v1.2.3-70-g09d2