diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-10-10 21:45:32 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-10-10 21:45:32 -0400 |
commit | a43ff1f98e9b9814f858bccb11c174b418458491 (patch) | |
tree | ae7e094d914eddb8a1ae9548420ba8c2f329ffae | |
parent | 6e264d243f0b29d90e90b605b6cdeab8227129c9 (diff) | |
download | c++-a43ff1f98e9b9814f858bccb11c174b418458491.tar.gz c++-a43ff1f98e9b9814f858bccb11c174b418458491.tar.bz2 c++-a43ff1f98e9b9814f858bccb11c174b418458491.zip |
big rearrangement of files to make libraries and example (research) files clearer, and changed to c++ std lib random numbers
-rw-r--r-- | .gitmodules | 3 | ||||
-rw-r--r-- | CMakeLists.txt | 91 | ||||
-rw-r--r-- | examples/CMakeLists.txt | 7 | ||||
-rw-r--r-- | examples/include/colors.h (renamed from lib/colors.h) | 2 | ||||
-rw-r--r-- | examples/include/correlation.hpp (renamed from lib/correlation.h) | 4 | ||||
-rw-r--r-- | examples/include/measure.hpp (renamed from lib/measure.h) | 4 | ||||
m--------- | examples/include/randutils | 0 | ||||
-rw-r--r-- | examples/src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | examples/src/models/CMakeLists.txt | 6 | ||||
-rw-r--r-- | examples/src/models/On/CMakeLists.txt | 29 | ||||
-rw-r--r-- | examples/src/models/On/orthogonal.hpp (renamed from lib/orthogonal.h) | 24 | ||||
-rw-r--r-- | examples/src/models/On/vector.hpp (renamed from lib/vector.h) | 2 | ||||
-rw-r--r-- | examples/src/models/On/wolff_On.cpp (renamed from src/wolff_On.cpp) | 21 | ||||
-rw-r--r-- | examples/src/models/ising/CMakeLists.txt | 28 | ||||
-rw-r--r-- | examples/src/models/ising/ising.hpp (renamed from lib/ising.h) | 2 | ||||
-rw-r--r-- | examples/src/models/ising/wolff_ising.cpp (renamed from src/wolff_ising.cpp) | 29 | ||||
-rw-r--r-- | examples/src/models/ising/z2.hpp (renamed from lib/z2.h) | 4 | ||||
-rw-r--r-- | examples/src/models/potts/CMakeLists.txt | 39 | ||||
-rw-r--r-- | examples/src/models/potts/dihedral.hpp (renamed from lib/dihedral.h) | 4 | ||||
-rw-r--r-- | examples/src/models/potts/potts.hpp (renamed from lib/potts.h) | 4 | ||||
-rw-r--r-- | examples/src/models/potts/symmetric.hpp (renamed from lib/symmetric.h) | 4 | ||||
-rw-r--r-- | examples/src/models/potts/wolff_clock.cpp (renamed from src/wolff_clock.cpp) | 25 | ||||
-rw-r--r-- | examples/src/models/potts/wolff_potts.cpp (renamed from src/wolff_potts.cpp) | 26 | ||||
-rw-r--r-- | examples/src/models/roughening/CMakeLists.txt | 21 | ||||
-rw-r--r-- | examples/src/models/roughening/dihedral_inf.hpp (renamed from lib/dihedral_inf.h) | 4 | ||||
-rw-r--r-- | examples/src/models/roughening/height.hpp (renamed from lib/height.h) | 2 | ||||
-rw-r--r-- | examples/src/models/roughening/wolff_cgm.cpp (renamed from src/wolff_cgm.cpp) | 21 | ||||
-rw-r--r-- | examples/src/models/roughening/wolff_dgm.cpp (renamed from src/wolff_dgm.cpp) | 29 | ||||
-rw-r--r-- | examples/src/tools/CMakeLists.txt | 7 | ||||
-rw-r--r-- | examples/src/tools/analyze_correlations.cpp (renamed from src/analyze_correlations.cpp) | 2 | ||||
-rw-r--r-- | lib/CMakeLists.txt | 17 | ||||
-rw-r--r-- | lib/angle.h | 48 | ||||
-rw-r--r-- | lib/circle_group.h | 46 | ||||
-rw-r--r-- | lib/convex.c | 102 | ||||
-rw-r--r-- | lib/convex.h | 23 | ||||
-rw-r--r-- | lib/include/wolff.hpp (renamed from lib/wolff.h) | 10 | ||||
-rw-r--r-- | lib/include/wolff/cluster.hpp (renamed from lib/cluster.h) | 12 | ||||
-rw-r--r-- | lib/include/wolff/finite_states.hpp (renamed from lib/finite_states.h) | 0 | ||||
-rw-r--r-- | lib/include/wolff/graph.hpp (renamed from lib/graph.h) | 1 | ||||
-rw-r--r-- | lib/include/wolff/state.hpp (renamed from lib/state.h) | 2 | ||||
-rw-r--r-- | lib/include/wolff/types.h (renamed from lib/types.h) | 0 | ||||
-rw-r--r-- | lib/rand.c | 20 | ||||
-rw-r--r-- | lib/rand.h | 16 | ||||
-rw-r--r-- | lib/src/graph.cpp (renamed from lib/graph.cpp) | 2 | ||||
-rw-r--r-- | lib/torus.h | 64 | ||||
-rw-r--r-- | wolfram_link/Makefile | 13 | ||||
-rw-r--r-- | wolfram_link/convexminorant.tm | 34 |
47 files changed, 283 insertions, 575 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..66f0577 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "examples/include/randutils"] + path = examples/include/randutils + url = https://gist.github.com/imneme/540829265469e673d045 diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bf604c..073ae14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ -cmake_minimum_required(VERSION 3.0) -project(wolff) +cmake_minimum_required(VERSION 3.9) +project(wolff DESCRIPTION "a library for preforming the wolff algorithm") set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall") set(CMAKE_CXX_FLAGS_RELEASE "-O3") @@ -8,89 +8,8 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3") set (CMAKE_CXX_STANDARD 17) set (CMAKE_C_STANDARD 11) -include_directories(lib ~/.local/include) -link_directories(~/.local/lib) +include(GNUInstallDirs) -file(GLOB CSOURCES lib/*.c) -file(GLOB CPPSOURCES lib/*.cpp) - -add_executable(wolff_ising src/wolff_ising.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_ising_2D_0 src/wolff_ising.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_dgm src/wolff_dgm.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_cgm src/wolff_cgm.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_3potts src/wolff_potts.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_4potts src/wolff_potts.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_7potts src/wolff_potts.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_3clock src/wolff_clock.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_5clock src/wolff_clock.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_planar src/wolff_On.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_planar_2D src/wolff_On.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_planar_2D_0 src/wolff_On.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(wolff_heisenberg src/wolff_On.cpp ${CPPSOURCES} ${CSOURCES}) -add_executable(analyze_correlations src/analyze_correlations.cpp ${CPPSOURCES} ${CSOURCES}) - -SET_TARGET_PROPERTIES(wolff_ising_2D_0 PROPERTIES COMPILE_FLAGS "-DDIMENSION=2 -DNOFIELD") -SET_TARGET_PROPERTIES(wolff_3potts PROPERTIES COMPILE_FLAGS "-DPOTTSQ=3") -SET_TARGET_PROPERTIES(wolff_4potts PROPERTIES COMPILE_FLAGS "-DPOTTSQ=4") -SET_TARGET_PROPERTIES(wolff_7potts PROPERTIES COMPILE_FLAGS "-DPOTTSQ=7") -SET_TARGET_PROPERTIES(wolff_3clock PROPERTIES COMPILE_FLAGS "-DPOTTSQ=3") -SET_TARGET_PROPERTIES(wolff_5clock PROPERTIES COMPILE_FLAGS "-DPOTTSQ=5") -SET_TARGET_PROPERTIES(wolff_planar PROPERTIES COMPILE_FLAGS "-DN_COMP=2") -SET_TARGET_PROPERTIES(wolff_planar_2D PROPERTIES COMPILE_FLAGS "-DN_COMP=2 -DDIMENSION=2") -SET_TARGET_PROPERTIES(wolff_planar_2D_0 PROPERTIES COMPILE_FLAGS "-DN_COMP=2 -DDIMENSION=2 -DNOFIELD") -SET_TARGET_PROPERTIES(wolff_heisenberg PROPERTIES COMPILE_FLAGS "-DN_COMP=3") - -find_library(GSL REQUIRED NAMES gsl) -find_library(FFTW REQUIRED NAMES fftw3) -find_library(M REQUIRED NAMES m) -FIND_LIBRARY(GL NAMES GL) -FIND_LIBRARY(GLU NAMES GLU) -FIND_LIBRARY(GLUT NAMES glut) - -target_link_libraries(analyze_correlations cblas gsl fftw3 m) - -if (${GLUT} MATCHES "GLUT-NOTFOUND") - target_link_libraries(wolff_ising cblas gsl m) - target_link_libraries(wolff_ising_2D_0 cblas gsl m) - target_link_libraries(wolff_dgm cblas gsl m) - target_link_libraries(wolff_cgm cblas gsl m) - target_link_libraries(wolff_3potts cblas gsl m) - target_link_libraries(wolff_4potts cblas gsl m) - target_link_libraries(wolff_7potts cblas gsl m) - target_link_libraries(wolff_3clock cblas gsl m) - target_link_libraries(wolff_5clock cblas gsl m) - target_link_libraries(wolff_heisenberg cblas gsl m) - target_link_libraries(wolff_planar cblas gsl m) - target_link_libraries(wolff_planar_2D cblas gsl m) - target_link_libraries(wolff_planar_2D_0 cblas gsl m) -else() - target_link_libraries(wolff_ising cblas gsl m glut GL GLU) - target_link_libraries(wolff_ising_2D_0 cblas gsl m glut GL GLU) - target_link_libraries(wolff_dgm cblas gsl m glut GL GLU) - target_link_libraries(wolff_cgm cblas gsl m glut GL GLU) - target_link_libraries(wolff_3potts cblas gsl m glut GL GLU) - target_link_libraries(wolff_4potts cblas gsl m glut GL GLU) - target_link_libraries(wolff_7potts cblas gsl m glut GL GLU) - target_link_libraries(wolff_3clock cblas gsl m glut GL GLU) - target_link_libraries(wolff_5clock cblas gsl m glut GL GLU) - target_link_libraries(wolff_heisenberg cblas gsl m glut GL GLU) - target_link_libraries(wolff_planar cblas gsl m glut GL GLU) - target_link_libraries(wolff_planar_2D cblas gsl m glut GL GLU) - target_link_libraries(wolff_planar_2D_0 cblas gsl m glut GL GLU) - target_compile_definitions(wolff_ising PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_ising_2D_0 PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_dgm PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_cgm PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_3potts PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_4potts PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_7potts PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_3clock PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_5clock PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_planar PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_planar_2D PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_planar_2D_0 PUBLIC HAVE_GLUT) - target_compile_definitions(wolff_heisenberg PUBLIC HAVE_GLUT) -endif() - -install(TARGETS wolff_ising wolff_dgm wolff_cgm wolff_3potts wolff_4potts wolff_3clock wolff_heisenberg wolff_planar analyze_correlations DESTINATION bin) +add_subdirectory(lib) +add_subdirectory(examples) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..baf0a10 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,7 @@ + +add_library(wolff_examples INTERFACE) + +target_include_directories(wolff_examples INTERFACE include) + +add_subdirectory(src) + diff --git a/lib/colors.h b/examples/include/colors.h index 04d39a8..abf137c 100644 --- a/lib/colors.h +++ b/examples/include/colors.h @@ -1,6 +1,6 @@ #pragma once -#include "types.h" +#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))) { diff --git a/lib/correlation.h b/examples/include/correlation.hpp index 29357a5..042cff3 100644 --- a/lib/correlation.h +++ b/examples/include/correlation.hpp @@ -1,8 +1,8 @@ #pragma once -#include "types.h" -#include "state.h" +#include <wolff/types.h> +#include <wolff/state.hpp> #include <fftw3.h> diff --git a/lib/measure.h b/examples/include/measure.hpp index 2c5ffb7..e20353c 100644 --- a/lib/measure.h +++ b/examples/include/measure.hpp @@ -1,8 +1,8 @@ #pragma once -#include "state.h" -#include "correlation.h" +#include <wolff/state.hpp> +#include "correlation.hpp" #include <functional> #define POSSIBLE_MEASUREMENTS 4 diff --git a/examples/include/randutils b/examples/include/randutils new file mode 160000 +Subproject 8486a610a954a8248c12485fb4cfc390a5f5f85 diff --git a/examples/src/CMakeLists.txt b/examples/src/CMakeLists.txt new file mode 100644 index 0000000..3397426 --- /dev/null +++ b/examples/src/CMakeLists.txt @@ -0,0 +1,4 @@ + +add_subdirectory(models) +add_subdirectory(tools) + diff --git a/examples/src/models/CMakeLists.txt b/examples/src/models/CMakeLists.txt new file mode 100644 index 0000000..0b0c111 --- /dev/null +++ b/examples/src/models/CMakeLists.txt @@ -0,0 +1,6 @@ + +add_subdirectory(ising) +add_subdirectory(On) +add_subdirectory(potts) +add_subdirectory(roughening) + diff --git a/examples/src/models/On/CMakeLists.txt b/examples/src/models/On/CMakeLists.txt new file mode 100644 index 0000000..26985b9 --- /dev/null +++ b/examples/src/models/On/CMakeLists.txt @@ -0,0 +1,29 @@ + +add_executable(wolff_planar wolff_On.cpp) +add_executable(wolff_planar_2d_no-field wolff_On.cpp) +add_executable(wolff_heisenberg wolff_On.cpp) + +set_target_properties(wolff_planar PROPERTIES COMPILE_FLAGS "-DN_COMP=2") +set_target_properties(wolff_planar_2d_no-field PROPERTIES COMPILE_FLAGS "-DN_COMP=2 -DDIMENSION=2 -DNOFIELD") +set_target_properties(wolff_heisenberg PROPERTIES COMPILE_FLAGS "-DN_COMP=3") + +find_library(GL NAMES GL) +find_library(GLU NAMES GLU) +find_library(GLUT NAMES glut) + +if (${GLUT} MATCHES "GLUT-NOTFOUND") + target_link_libraries(wolff_planar wolff wolff_examples) + target_link_libraries(wolff_planar_2d_no-field wolff wolff_examples) + target_link_libraries(wolff_heisenberg wolff wolff_examples) +else() + target_compile_definitions(wolff_planar PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_planar_2d_no-field PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_heisenberg PUBLIC HAVE_GLUT) + + target_link_libraries(wolff_planar wolff wolff_examples glut GL GLU) + target_link_libraries(wolff_planar_2d_no-field wolff wolff_examples glut GL GLU) + target_link_libraries(wolff_heisenberg wolff wolff_examples glut GL GLU) +endif() + +install(TARGETS wolff_planar wolff_planar_2d_no-field wolff_heisenberg DESTINATION ${CMAKE_INSTALL_BINDIR}) + diff --git a/lib/orthogonal.h b/examples/src/models/On/orthogonal.hpp index e1bf33a..f13357f 100644 --- a/lib/orthogonal.h +++ b/examples/src/models/On/orthogonal.hpp @@ -2,13 +2,12 @@ #pragma once #include <stdlib.h> -#include <gsl/gsl_rng.h> -#include <gsl/gsl_randist.h> +#include <random> #include <cmath> -#include "state.h" -#include "types.h" -#include "vector.h" +#include <wolff/state.hpp> +#include <wolff/types.h> +#include "vector.hpp" template <q_t q, class T> class orthogonal_t : public std::array<std::array<T, q>, q> { @@ -117,14 +116,15 @@ class orthogonal_t : public std::array<std::array<T, q>, q> { template <q_t q> -orthogonal_t <q, double> generate_rotation_uniform (gsl_rng *r, const vector_t <q, double>& v) { +orthogonal_t <q, double> generate_rotation_uniform (std::mt19937& r, const vector_t <q, double>& v) { + std::normal_distribution<double> dist(0.0,1.0); orthogonal_t <q, double> ptr; ptr.is_reflection = true; double v2 = 0; for (q_t i = 0; i < q; i++) { - ptr[0][i] = gsl_ran_ugaussian(r); + ptr[0][i] = dist(r); v2 += ptr[0][i] * ptr[0][i]; } @@ -138,14 +138,16 @@ orthogonal_t <q, double> generate_rotation_uniform (gsl_rng *r, const vector_t < } template <q_t q> -orthogonal_t <q, double> generate_rotation_perturbation (gsl_rng *r, const vector_t <q, double>& v0, double epsilon, unsigned int n) { +orthogonal_t <q, double> generate_rotation_perturbation (std::mt19937& r, const vector_t <q, double>& v0, double epsilon, unsigned int n) { + std::normal_distribution<double> dist(0.0,1.0); orthogonal_t <q, double> m; m.is_reflection = true; vector_t <q, double> v; if (n > 1) { - unsigned int rotation = gsl_rng_uniform_int(r, n); + std::uniform_int_distribution<unsigned int> udist(0, n); + unsigned int rotation = udist(r); double cosr = cos(2 * M_PI * rotation / (double)n / 2.0); double sinr = sin(2 * M_PI * rotation / (double)n / 2.0); @@ -163,7 +165,7 @@ orthogonal_t <q, double> generate_rotation_perturbation (gsl_rng *r, const vecto double m_dot_v = 0; for (q_t i = 0; i < q; i++) { - m[0][i] = gsl_ran_ugaussian(r); // create a random vector + m[0][i] = dist(r); // create a random vector m_dot_v += m[0][i] * v[i]; } @@ -182,7 +184,7 @@ orthogonal_t <q, double> generate_rotation_perturbation (gsl_rng *r, const vecto v2 = 0; - double factor = gsl_ran_gaussian(r, epsilon); + double factor = epsilon * dist(r); for (q_t i = 0; i < q; i++) { m[0][i] += factor * v[i]; // perturb orthogonal vector in original direction diff --git a/lib/vector.h b/examples/src/models/On/vector.hpp index 7d0ee36..1cdb60a 100644 --- a/lib/vector.h +++ b/examples/src/models/On/vector.hpp @@ -5,7 +5,7 @@ #include <cmath> #include <array> -#include "types.h" +#include <wolff/types.h> template <q_t q, class T> class vector_t : public std::array<T, q> { diff --git a/src/wolff_On.cpp b/examples/src/models/On/wolff_On.cpp index f6661af..e3568c7 100644 --- a/src/wolff_On.cpp +++ b/examples/src/models/On/wolff_On.cpp @@ -6,13 +6,13 @@ #include <GL/glut.h> #endif -#include <orthogonal.h> -#include <vector.h> +#include "orthogonal.hpp" +#include "vector.hpp" -#include <wolff.h> -#include <measure.h> +#include <wolff.hpp> +#include <measure.hpp> #include <colors.h> -#include <rand.h> +#include <randutils/randutils.hpp> typedef orthogonal_t <N_COMP, double> orthogonal_R_t; typedef vector_t <N_COMP, double> vector_R_t; @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) { const char *pert_type; - std::function <orthogonal_R_t(gsl_rng *, vector_R_t)> gen_R; + std::function <orthogonal_R_t(std::mt19937&, vector_R_t)> gen_R; if (use_pert) { double Hish; @@ -238,8 +238,8 @@ int main(int argc, char *argv[]) { } // initialize random number generator - gsl_rng *r = gsl_rng_alloc(gsl_rng_taus2); - gsl_rng_set(r, rand_seed()); + randutils::auto_seed_128 seeds; + std::mt19937 rng{seeds}; #ifndef NOFIELD state_t <orthogonal_R_t, vector_R_t> s(D, L, T, dot <N_COMP, double>, H); @@ -252,17 +252,16 @@ int main(int argc, char *argv[]) { 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 <orthogonal_R_t, vector_R_t> (N, s, gen_R, measurements, r, silent); + wolff <orthogonal_R_t, vector_R_t> (N, s, gen_R, measurements, rng, silent); 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); } else { - wolff <orthogonal_R_t, vector_R_t> (N, s, gen_R, measurements, r, silent); + wolff <orthogonal_R_t, vector_R_t> (N, s, gen_R, measurements, rng, silent); } measure_free_files(measurement_flags, outfiles); free(H_vec); - gsl_rng_free(r); return 0; } diff --git a/examples/src/models/ising/CMakeLists.txt b/examples/src/models/ising/CMakeLists.txt new file mode 100644 index 0000000..e8fbc9a --- /dev/null +++ b/examples/src/models/ising/CMakeLists.txt @@ -0,0 +1,28 @@ + +add_executable(wolff_ising wolff_ising.cpp) +add_executable(wolff_ising_2d wolff_ising.cpp) +add_executable(wolff_ising_2d_no-field wolff_ising.cpp) + +set_target_properties(wolff_ising_2d PROPERTIES COMPILE_FLAGS "-DDIMENSION=2") +set_target_properties(wolff_ising_2d_no-field PROPERTIES COMPILE_FLAGS "-DDIMENSION=2 -DNOFIELD") + +find_library(GL NAMES GL) +find_library(GLU NAMES GLU) +find_library(GLUT NAMES glut) + +if (${GLUT} MATCHES "GLUT-NOTFOUND") + target_link_libraries(wolff_ising wolff wolff_examples) + target_link_libraries(wolff_ising_2d wolff wolff_examples) + target_link_libraries(wolff_ising_2d_no-field wolff wolff_examples) +else() + target_compile_definitions(wolff_ising PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_ising_2d PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_ising_2d_no-field PUBLIC HAVE_GLUT) + + target_link_libraries(wolff_ising wolff wolff_examples glut GL GLU) + target_link_libraries(wolff_ising_2d wolff wolff_examples glut GL GLU) + target_link_libraries(wolff_ising_2d_no-field wolff wolff_examples glut GL GLU) +endif() + +install(TARGETS wolff_ising wolff_ising_2d wolff_ising_2d_no-field DESTINATION ${CMAKE_INSTALL_BINDIR}) + diff --git a/lib/ising.h b/examples/src/models/ising/ising.hpp index 45058fb..ae20840 100644 --- a/lib/ising.h +++ b/examples/src/models/ising/ising.hpp @@ -3,7 +3,7 @@ #include <cmath> #include <stdio.h> -#include "types.h" +#include <wolff/types.h> class ising_t { public: diff --git a/src/wolff_ising.cpp b/examples/src/models/ising/wolff_ising.cpp index a6f43b1..5bdaa82 100644 --- a/src/wolff_ising.cpp +++ b/examples/src/models/ising/wolff_ising.cpp @@ -8,21 +8,20 @@ #endif // include your group and spin space -#include <z2.h> -#include <ising.h> +#include "z2.hpp" +#include "ising.hpp" // finite_states.h can be included for spin types that have special variables // defined, and it causes wolff execution to use precomputed bond probabilities -#include <finite_states.h> +#include <wolff/finite_states.hpp> -// rand.h uses a unix-specific way to seed the random number generator -#include <rand.h> +#include <randutils/randutils.hpp> -// measure.h contains useful functions for saving timeseries to files -#include <measure.h> +// measure.hpp contains useful functions for saving timeseries to files +#include <measure.hpp> -// include wolff.h -#include <wolff.h> +// include wolff.hpp +#include <wolff.hpp> int main(int argc, char *argv[]) { @@ -95,8 +94,8 @@ int main(int argc, char *argv[]) { } // initialize random number generator - gsl_rng *r = gsl_rng_alloc(gsl_rng_taus2); - gsl_rng_set(r, rand_seed()); + randutils::auto_seed_128 seeds; + std::mt19937 rng{seeds}; // define spin-spin coupling std::function <double(const ising_t&, const ising_t&)> Z = [] (const ising_t& s1, const ising_t& s2) -> double { @@ -124,7 +123,7 @@ int main(int argc, char *argv[]) { #endif // define function that generates self-inverse rotations - std::function <z2_t(gsl_rng *, ising_t)> gen_R = [] (gsl_rng *, const ising_t& s) -> z2_t { + std::function <z2_t(std::mt19937&, ising_t)> gen_R = [] (std::mt19937&, const ising_t& s) -> z2_t { return z2_t(true); }; @@ -183,16 +182,14 @@ int main(int argc, char *argv[]) { 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, r, silent); + wolff(N, s, gen_R, measurements, rng, silent); 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); } else { - wolff(N, s, gen_R, measurements, r, silent); + wolff(N, s, gen_R, measurements, rng, silent); } - // free the random number generator - gsl_rng_free(r); measure_free_files(measurement_flags, outfiles); return 0; diff --git a/lib/z2.h b/examples/src/models/ising/z2.hpp index a18d740..19b6c05 100644 --- a/lib/z2.h +++ b/examples/src/models/ising/z2.hpp @@ -1,8 +1,8 @@ #pragma once -#include "types.h" -#include "ising.h" +#include <wolff/types.h> +#include "ising.hpp" /* The minimum definition for a group type R_t to act on a spin type X_t is * given by the following. diff --git a/examples/src/models/potts/CMakeLists.txt b/examples/src/models/potts/CMakeLists.txt new file mode 100644 index 0000000..53133b9 --- /dev/null +++ b/examples/src/models/potts/CMakeLists.txt @@ -0,0 +1,39 @@ + +add_executable(wolff_3potts wolff_potts.cpp) +add_executable(wolff_4potts wolff_potts.cpp) +add_executable(wolff_7potts wolff_potts.cpp) +add_executable(wolff_3clock wolff_clock.cpp) +add_executable(wolff_5clock wolff_clock.cpp) + +set_target_properties(wolff_3potts PROPERTIES COMPILE_FLAGS "-DPOTTSQ=3") +set_target_properties(wolff_4potts PROPERTIES COMPILE_FLAGS "-DPOTTSQ=4") +set_target_properties(wolff_7potts PROPERTIES COMPILE_FLAGS "-DPOTTSQ=7") +set_target_properties(wolff_3clock PROPERTIES COMPILE_FLAGS "-DPOTTSQ=3") +set_target_properties(wolff_5clock PROPERTIES COMPILE_FLAGS "-DPOTTSQ=5") + +find_library(GL NAMES GL) +find_library(GLU NAMES GLU) +find_library(GLUT NAMES glut) + +if (${GLUT} MATCHES "GLUT-NOTFOUND") + target_link_libraries(wolff_3potts wolff wolff_examples) + target_link_libraries(wolff_4potts wolff wolff_examples) + target_link_libraries(wolff_7potts wolff wolff_examples) + target_link_libraries(wolff_3clock wolff wolff_examples) + target_link_libraries(wolff_5clock wolff wolff_examples) +else() + target_compile_definitions(wolff_3potts PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_4potts PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_7potts PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_3clock PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_5clock PUBLIC HAVE_GLUT) + + target_link_libraries(wolff_3potts wolff wolff_examples glut GL GLU) + target_link_libraries(wolff_4potts wolff wolff_examples glut GL GLU) + target_link_libraries(wolff_7potts wolff wolff_examples glut GL GLU) + target_link_libraries(wolff_3clock wolff wolff_examples glut GL GLU) + target_link_libraries(wolff_5clock wolff wolff_examples glut GL GLU) +endif() + +install(TARGETS wolff_3potts wolff_4potts wolff_7potts wolff_3clock wolff_5clock DESTINATION ${CMAKE_INSTALL_BINDIR}) + diff --git a/lib/dihedral.h b/examples/src/models/potts/dihedral.hpp index 8d0472b..cbc5687 100644 --- a/lib/dihedral.h +++ b/examples/src/models/potts/dihedral.hpp @@ -1,8 +1,8 @@ #pragma once -#include "types.h" -#include "potts.h" +#include <wolff/types.h> +#include "potts.hpp" template <q_t q> class dihedral_t { diff --git a/lib/potts.h b/examples/src/models/potts/potts.hpp index 1764e53..f4765e2 100644 --- a/lib/potts.h +++ b/examples/src/models/potts/potts.hpp @@ -3,8 +3,8 @@ #include <cmath> #include <stdio.h> -#include "types.h" -#include "vector.h" +#include <wolff/types.h> +#include "../On/vector.hpp" template <q_t q> class potts_t { diff --git a/lib/symmetric.h b/examples/src/models/potts/symmetric.hpp index 9e9b6e4..8636f15 100644 --- a/lib/symmetric.h +++ b/examples/src/models/potts/symmetric.hpp @@ -3,8 +3,8 @@ #include <stdlib.h> #include <array> -#include "types.h" -#include "potts.h" +#include <wolff/types.h> +#include "potts.hpp" template <q_t q> class symmetric_t : public std::array<q_t, q> { diff --git a/src/wolff_clock.cpp b/examples/src/models/potts/wolff_clock.cpp index 3dec284..020415d 100644 --- a/src/wolff_clock.cpp +++ b/examples/src/models/potts/wolff_clock.cpp @@ -6,17 +6,18 @@ #endif // include your group and spin space -#include <dihedral.h> -#include <potts.h> +#include "dihedral.hpp" +#include "potts.hpp" #include <colors.h> // hack to speed things up considerably #define N_STATES POTTSQ -#include <finite_states.h> +#include <wolff/finite_states.hpp> -// include wolff.h -#include <rand.h> -#include <wolff.h> +#include <randutils/randutils.hpp> + +// include wolff.hpp +#include <wolff.hpp> typedef state_t <dihedral_t<POTTSQ>, potts_t<POTTSQ>> sim_t; @@ -74,8 +75,8 @@ int main(int argc, char *argv[]) { } // initialize random number generator - gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937); - gsl_rng_set(r, rand_seed()); + randutils::auto_seed_128 seeds; + std::mt19937 rng{seeds}; // define spin-spin coupling std::function <double(const potts_t<POTTSQ>&, const potts_t<POTTSQ>&)> Z = [] (const potts_t<POTTSQ>& s1, const potts_t<POTTSQ>& s2) -> double { @@ -91,10 +92,11 @@ int main(int argc, char *argv[]) { state_t <dihedral_t<POTTSQ>, potts_t<POTTSQ>> s(D, L, T, Z, B); // define function that generates self-inverse rotations - std::function <dihedral_t<POTTSQ>(gsl_rng *, potts_t<POTTSQ>)> gen_R = [] (gsl_rng *r, potts_t<POTTSQ> v) -> dihedral_t<POTTSQ> { + std::function <dihedral_t<POTTSQ>(std::mt19937&, potts_t<POTTSQ>)> gen_R = [] (std::mt19937& r, potts_t<POTTSQ> v) -> dihedral_t<POTTSQ> { dihedral_t<POTTSQ> rot; rot.is_reflection = true; - q_t x = gsl_rng_uniform_int(r, POTTSQ - 1); + std::uniform_int_distribution<q_t> dist(0, POTTSQ - 1); + q_t x = dist(r); rot.x = (2 * v.x + x + 1) % POTTSQ; return rot; @@ -137,13 +139,12 @@ int main(int argc, char *argv[]) { } // run wolff for N cluster flips - wolff(N, s, gen_R, measurement, r, silent); + wolff(N, s, gen_R, measurement, rng, silent); // tell us what we found! printf("%" PRIcount " %d-Potts runs completed. D = %" PRID ", L = %" PRIL ", T = %g, H = %g, <M> = %g\n", N, POTTSQ, D, L, T, H_vec[0], average_M); // free the random number generator - gsl_rng_free(r); if (draw) { } diff --git a/src/wolff_potts.cpp b/examples/src/models/potts/wolff_potts.cpp index 9fe3ffe..a1e9284 100644 --- a/src/wolff_potts.cpp +++ b/examples/src/models/potts/wolff_potts.cpp @@ -7,18 +7,18 @@ #endif // include your group and spin space -#include <symmetric.h> -#include <potts.h> +#include "symmetric.hpp" +#include "potts.hpp" // hack to speed things up considerably #define N_STATES POTTSQ -#include <finite_states.h> +#include <wolff/finite_states.hpp> // include wolff.h -#include <measure.h> +#include <measure.hpp> #include <colors.h> -#include <rand.h> -#include <wolff.h> +#include <randutils/randutils.hpp> +#include <wolff.hpp> typedef state_t <symmetric_t<POTTSQ>, potts_t<POTTSQ>> sim_t; @@ -95,8 +95,8 @@ int main(int argc, char *argv[]) { } // initialize random number generator - gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937); - gsl_rng_set(r, rand_seed()); + randutils::auto_seed_128 seeds; + std::mt19937 rng{seeds}; // define spin-spin coupling std::function <double(const potts_t<POTTSQ>&, const potts_t<POTTSQ>&)> Z = [] (const potts_t<POTTSQ>& s1, const potts_t<POTTSQ>& s2) -> double { @@ -116,10 +116,11 @@ int main(int argc, char *argv[]) { state_t <symmetric_t<POTTSQ>, potts_t<POTTSQ>> s(D, L, T, Z, B); // define function that generates self-inverse rotations - std::function <symmetric_t<POTTSQ>(gsl_rng *, potts_t<POTTSQ>)> gen_R = [] (gsl_rng *r, potts_t<POTTSQ> v) -> symmetric_t<POTTSQ> { + std::function <symmetric_t<POTTSQ>(std::mt19937&, potts_t<POTTSQ>)> gen_R = [] (std::mt19937& r, potts_t<POTTSQ> v) -> symmetric_t<POTTSQ> { symmetric_t<POTTSQ> rot; - q_t j = gsl_rng_uniform_int(r, POTTSQ - 1); + std::uniform_int_distribution<q_t> dist(0, POTTSQ - 1); + q_t j = dist(r); q_t swap_v; if (j < v.x) { swap_v = j; @@ -194,16 +195,15 @@ int main(int argc, char *argv[]) { 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, r, silent); + wolff(N, s, gen_R, measurements, rng, silent); 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); } else { - wolff(N, s, gen_R, measurements, r, silent); + wolff(N, s, gen_R, measurements, rng, silent); } // free the random number generator - gsl_rng_free(r); free(H_vec); measure_free_files(measurement_flags, outfiles); diff --git a/examples/src/models/roughening/CMakeLists.txt b/examples/src/models/roughening/CMakeLists.txt new file mode 100644 index 0000000..51a8644 --- /dev/null +++ b/examples/src/models/roughening/CMakeLists.txt @@ -0,0 +1,21 @@ + +add_executable(wolff_dgm wolff_dgm.cpp) +add_executable(wolff_cgm wolff_cgm.cpp) + +find_library(GL NAMES GL) +find_library(GLU NAMES GLU) +find_library(GLUT NAMES glut) + +if (${GLUT} MATCHES "GLUT-NOTFOUND") + target_link_libraries(wolff_dgm wolff wolff_examples) + target_link_libraries(wolff_cgm wolff wolff_examples) +else() + target_compile_definitions(wolff_dgm PUBLIC HAVE_GLUT) + target_compile_definitions(wolff_cgm PUBLIC HAVE_GLUT) + + target_link_libraries(wolff_dgm wolff wolff_examples glut GL GLU) + target_link_libraries(wolff_cgm wolff wolff_examples glut GL GLU) +endif() + +install(TARGETS wolff_dgm wolff_cgm DESTINATION ${CMAKE_INSTALL_BINDIR}) + diff --git a/lib/dihedral_inf.h b/examples/src/models/roughening/dihedral_inf.hpp index a064b48..19fa195 100644 --- a/lib/dihedral_inf.h +++ b/examples/src/models/roughening/dihedral_inf.hpp @@ -1,7 +1,7 @@ -#include "types.h" +#include <wolff/types.h> #include <cmath> -#include "height.h" +#include "height.hpp" template <class T> class dihedral_inf_t { diff --git a/lib/height.h b/examples/src/models/roughening/height.hpp index d2173fe..4023063 100644 --- a/lib/height.h +++ b/examples/src/models/roughening/height.hpp @@ -4,7 +4,7 @@ #include <cmath> #include <stdio.h> -#include "types.h" +#include <wolff/types.h> /* The following is the minimum definition of a spin class. * diff --git a/src/wolff_cgm.cpp b/examples/src/models/roughening/wolff_cgm.cpp index ce91bf2..65f8d66 100644 --- a/src/wolff_cgm.cpp +++ b/examples/src/models/roughening/wolff_cgm.cpp @@ -6,12 +6,13 @@ #endif // include your group and spin space -#include <dihedral_inf.h> -#include <height.h> +#include "dihedral_inf.hpp" +#include "height.hpp" + +#include <randutils/randutils.hpp> // include wolff.h -#include <rand.h> -#include <wolff.h> +#include <wolff.hpp> typedef state_t <dihedral_inf_t<double>, height_t<double>> sim_t; @@ -71,8 +72,8 @@ int main(int argc, char *argv[]) { } // initialize random number generator - gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937); - gsl_rng_set(r, rand_seed()); + randutils::auto_seed_128 seeds; + std::mt19937 rng{seeds}; // define spin-spin coupling std::function <double(const height_t<double>&, const height_t<double>&)> Z = [] (const height_t<double>& h1, const height_t<double>& h2) -> double { @@ -88,11 +89,12 @@ int main(int argc, char *argv[]) { sim_t s(D, L, T, Z, B); // define function that generates self-inverse rotations - std::function <dihedral_inf_t<double>(gsl_rng *, height_t<double>)> gen_R = [=] (gsl_rng *r, height_t<double> h) -> dihedral_inf_t<double> { + std::function <dihedral_inf_t<double>(std::mt19937&, height_t<double>)> gen_R = [=] (std::mt19937& r, height_t<double> h) -> dihedral_inf_t<double> { dihedral_inf_t<double> rot; rot.is_reflection = true; + std::normal_distribution<double> dist(0.0,1.0); - double amount = epsilon * gsl_ran_ugaussian(r); + double amount = epsilon * dist(r); rot.x = 2 * h.x + amount; @@ -149,13 +151,12 @@ int main(int argc, char *argv[]) { } // run wolff for N cluster flips - wolff(N, s, gen_R, measurement, r, silent); + wolff(N, s, gen_R, measurement, rng, silent); // tell us what we found! printf("%" PRIcount " DGM runs completed. D = %" PRID ", L = %" PRIL ", T = %g, H = %g, <M> = %g\n", N, D, L, T, H, average_M); // free the random number generator - gsl_rng_free(r); if (draw) { } diff --git a/src/wolff_dgm.cpp b/examples/src/models/roughening/wolff_dgm.cpp index 8667fb5..8395382 100644 --- a/src/wolff_dgm.cpp +++ b/examples/src/models/roughening/wolff_dgm.cpp @@ -6,12 +6,13 @@ #endif // include your group and spin space -#include <dihedral_inf.h> -#include <height.h> +#include "dihedral_inf.hpp" +#include "height.hpp" + +#include <randutils/randutils.hpp> // include wolff.h -#include <rand.h> -#include <wolff.h> +#include <wolff.hpp> typedef state_t <dihedral_inf_t<int64_t>, height_t<int64_t>> sim_t; @@ -71,8 +72,8 @@ int main(int argc, char *argv[]) { } // initialize random number generator - gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937); - gsl_rng_set(r, rand_seed()); + randutils::auto_seed_128 seeds; + std::mt19937 rng{seeds}; // define spin-spin coupling std::function <double(const height_t<int64_t>&, const height_t<int64_t>&)> Z = [] (const height_t<int64_t>& h1, const height_t<int64_t>& h2) -> double { @@ -88,18 +89,13 @@ int main(int argc, char *argv[]) { sim_t s(D, L, T, Z, B); // define function that generates self-inverse rotations - std::function <dihedral_inf_t<int64_t>(gsl_rng *, height_t<int64_t>)> gen_R = [=] (gsl_rng *r, height_t<int64_t> h) -> dihedral_inf_t<int64_t> { + std::function <dihedral_inf_t<int64_t>(std::mt19937&, height_t<int64_t>)> gen_R = [=] (std::mt19937& r, height_t<int64_t> h) -> dihedral_inf_t<int64_t> { dihedral_inf_t<int64_t> rot; rot.is_reflection = true; - int direction = gsl_rng_uniform_int(r, 2); - int64_t amount = gsl_rng_uniform_int(r, epsilon); + std::uniform_int_distribution<int64_t> dist(-epsilon,epsilon); - if (direction == 0) { - rot.x = 2 * h.x + (1 + amount); - } else { - rot.x = 2 * h.x - (1 + amount); - } + rot.x = 2 * h.x + dist(r); return rot; }; @@ -154,14 +150,11 @@ int main(int argc, char *argv[]) { } // run wolff for N cluster flips - wolff(N, s, gen_R, measurement, r, silent); + wolff(N, s, gen_R, measurement, rng, silent); // tell us what we found! printf("%" PRIcount " DGM runs completed. D = %" PRID ", L = %" PRIL ", T = %g, H = %g, <M> = %g\n", N, D, L, T, H, average_M); - // free the random number generator - gsl_rng_free(r); - if (draw) { } diff --git a/examples/src/tools/CMakeLists.txt b/examples/src/tools/CMakeLists.txt new file mode 100644 index 0000000..1c73c2d --- /dev/null +++ b/examples/src/tools/CMakeLists.txt @@ -0,0 +1,7 @@ + +find_library(fftw REQUIRED NAMES fftw3) + +add_executable(analyze_correlations analyze_correlations.cpp) + +target_link_libraries(analyze_correlations fftw3 wolff) + diff --git a/src/analyze_correlations.cpp b/examples/src/tools/analyze_correlations.cpp index 48ee426..abeaff3 100644 --- a/src/analyze_correlations.cpp +++ b/examples/src/tools/analyze_correlations.cpp @@ -1,5 +1,5 @@ -#include <types.h> +#include <wolff/types.h> #include <cmath> #include <cstring> #include <stdio.h> diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..a31500e --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,17 @@ + +project(libwolff LANGUAGES C CXX) + +add_library(wolff SHARED src/graph.cpp) + +target_include_directories(wolff PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + $<INSTALL_INTERFACE:include>) + +install(TARGETS wolff EXPORT wolffConfig + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +install(EXPORT wolffConfig DESTINATION share/wolff/cmake) + +export(TARGETS wolff FILE wolffConfig.cmake) diff --git a/lib/angle.h b/lib/angle.h deleted file mode 100644 index c3f128e..0000000 --- a/lib/angle.h +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "types.h" - -#include <cmath> -#include "vector.h" - -class angle_t { - public: - double x; - - typedef vector_t<2, double> M_t; - typedef vector_t<2, double> F_t; - - angle_t() : x(0) {} - angle_t(double x) : x(x) {} - - inline vector_t<2, double> operator*(v_t a) const { - vector_t<2, double>M; - M[0] = a * cos(x); - M[1] = a * sin(x); - - return M; - } - - inline vector_t<2, double> operator*(double a) const { - vector_t<2, double>M; - M[0] = a * cos(x); - M[1] = a * sin(x); - - return M; - } -}; - -inline vector_t<2,double>& operator+=(vector_t<2,double>& M, const angle_t& theta) { - M[0] += cos(theta.x); - M[1] += sin(theta.x); - - return M; -} - -inline vector_t<2,double>& operator-=(vector_t<2,double>& M, const angle_t& theta) { - M[0] -= cos(theta.x); - M[1] -= sin(theta.x); - - return M; -} - diff --git a/lib/circle_group.h b/lib/circle_group.h deleted file mode 100644 index cb7cadd..0000000 --- a/lib/circle_group.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include "angle.h" - -class circle_group_t { - public: - bool is_reflection; - double x; - - circle_group_t() : is_reflection(false), x(0) {} - circle_group_t(bool x, double y) : is_reflection(x), x(y) {} - - angle_t act(const angle_t& theta) const { - if (is_reflection) { - return angle_t(fmod(2 * M_PI + x - theta.x, 2 * M_PI)); - } else { - return angle_t(fmod(x + theta.x, 2 * M_PI)); - } - } - - circle_group_t act(const circle_group_t& r) const { - if (is_reflection) { - return circle_group_t(!r.is_reflection, fmod(2 * M_PI + x - r.x, 2 * M_PI)); - } else { - return circle_group_t(r.is_reflection, fmod(x + r.x, 2 * M_PI)); - } - } - - angle_t act_inverse(const angle_t& theta) const { - if (is_reflection) { - return act(theta); - } else { - return angle_t(fmod(2 * M_PI + theta.x - x, 2 * M_PI)); - } - } - - circle_group_t act_inverse(const circle_group_t& r) const { - if (is_reflection) { - return act(r); - } else { - return circle_group_t(r.is_reflection, fmod(2 * M_PI + r.x - x, 2 * M_PI)); - } - } -}; - - diff --git a/lib/convex.c b/lib/convex.c deleted file mode 100644 index 7255ad4..0000000 --- a/lib/convex.c +++ /dev/null @@ -1,102 +0,0 @@ - -#include "convex.h" - -double slope(point_t *P, point_t *Q) { - return (Q->y - P->y) / ((double)(Q->x) - (double)(P->x)); -} - -double *get_convex_minorant(count_t n, double *Gammas) { - if (n < 2) { - return Gammas; - } - - list_t *L = (list_t *)calloc(1, sizeof(list_t)); - L->p = (point_t *)calloc(1, sizeof(point_t)); - L->p->x = 0; - L->p->y = Gammas[0]; - - list_t *pos = L; - - for (count_t i = 1; i < n; i++) { - pos->next = (list_t *)calloc(1, sizeof(list_t)); - pos->next->p = (point_t *)calloc(1, sizeof(point_t)); - pos->next->p->x = i; - pos->next->p->y = Gammas[i]; - pos->next->prev = pos; - pos = pos->next; - } - - pos->next = (list_t *)calloc(1, sizeof(list_t)); - pos->next->p = (point_t *)calloc(1, sizeof(point_t)); - pos->next->p->x = n; - pos->next->p->y = 0; - pos->next->prev = pos; - - list_t *X = L; - list_t *Y = L->next; - list_t *Z = Y->next; - - while (true) { - if (slope(X->p, Y->p) <= slope(Y->p, Z->p)) { - X = Y; - Y = Z; - if (Z->next == NULL) { - break; - } else { - Z = Z->next; - } - } else { - Y->prev->next = Y->next; - Y->next->prev = Y->prev; - free(Y->p); - free(Y); - if (X->prev != NULL) { - Y = X; - X = X->prev; - } else { - if (Z->next != NULL) { - Y = Z; - Z = Z->next; - } else { - break; - } - } - } - } - - pos = L; - - double *g = (double *)calloc(n + 1, sizeof(double)); - double rho = 0; - - for (count_t i = 0; i < n + 1; i++) { - if (i > pos->next->p->x) { - pos = pos->next; - } - - g[i] = pos->p->y + ((double)i - (double)(pos->p->x)) * (pos->next->p->y - pos->p->y) / ((double)(pos->next->p->x) - (double)(pos->p->x)); - - if (i <n) { - if (Gammas[i] - g[i] > rho) { - rho = Gammas[i] - g[i]; - } - } else { - if (0 - g[i] > rho) { - rho = 0 - g[i]; - } - } - } - - for (count_t i = 0; i < n + 1; i++) { - g[i] += rho / 2; - } - - while (L != NULL) { - free(L->p); - L = L->next; - free(L); - } - - return g; -} - diff --git a/lib/convex.h b/lib/convex.h deleted file mode 100644 index 5a405d4..0000000 --- a/lib/convex.h +++ /dev/null @@ -1,23 +0,0 @@ - -#pragma once - -#include <inttypes.h> -#include <stdbool.h> -#include <stdlib.h> -#include <string.h> - -#include "types.h" - -typedef struct { - count_t x; - double y; -} point_t; - -typedef struct list_tag { - struct list_tag *prev; - struct list_tag *next; - point_t *p; -} list_t; - -double *get_convex_minorant(count_t n, double *Gammas); - diff --git a/lib/wolff.h b/lib/include/wolff.hpp index 141a5b2..c10a211 100644 --- a/lib/wolff.h +++ b/lib/include/wolff.hpp @@ -1,9 +1,9 @@ -#include "cluster.h" -#include "state.h" +#include "wolff/cluster.hpp" +#include "wolff/state.hpp" 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 *, X_t s0)> gen_R, 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(std::mt19937&, X_t)> gen_R, std::function <void(const state_t <R_t, X_t>&)> measurements, std::mt19937& r, bool silent) { #ifdef FINITE_STATES #ifdef NOFIELD @@ -13,11 +13,13 @@ void wolff(count_t N, state_t <R_t, X_t>& s, std::function <R_t(gsl_rng *, X_t s #endif #endif + std::uniform_int_distribution<v_t> dist(0, s.nv); + if (!silent) printf("\n"); for (count_t steps = 0; steps < N; steps++) { if (!silent) printf("\033[F\033[JWOLFF: step %" PRIu64 " / %" PRIu64 ": E = %.2f, S = %" PRIv "\n", steps, N, s.E, s.last_cluster_size); - v_t v0 = gsl_rng_uniform_int(r, s.nv); + v_t v0 = dist(r); R_t step = gen_R(r, s.spins[v0]); flip_cluster <R_t, X_t> (s, v0, step, r); diff --git a/lib/cluster.h b/lib/include/wolff/cluster.hpp index f57bb68..104f3c2 100644 --- a/lib/cluster.h +++ b/lib/include/wolff/cluster.hpp @@ -1,18 +1,18 @@ #pragma once -#include <gsl/gsl_randist.h> -#include <gsl/gsl_rng.h> +#include <random> #include <cmath> #include <vector> #include <stack> #include "types.h" -#include "state.h" -#include "graph.h" +#include "state.hpp" +#include "graph.hpp" template <class R_t, class X_t> -void flip_cluster(state_t<R_t, X_t>& s, v_t v0, const R_t& r, gsl_rng *rand) { +void flip_cluster(state_t<R_t, X_t>& s, v_t v0, const R_t& r, std::mt19937& rand) { + std::uniform_real_distribution<double> dist(0.0,1.0); v_t nv = 0; std::stack<v_t> stack; @@ -89,7 +89,7 @@ void flip_cluster(state_t<R_t, X_t>& s, v_t v0, const R_t& r, gsl_rng *rand) { prob = 1.0 - exp(-dE / s.T); #endif - if (gsl_rng_uniform(rand) < prob) { + if (dist(rand) < prob) { stack.push(vn); // push the neighboring vertex to the stack } } diff --git a/lib/finite_states.h b/lib/include/wolff/finite_states.hpp index 426edad..426edad 100644 --- a/lib/finite_states.h +++ b/lib/include/wolff/finite_states.hpp diff --git a/lib/graph.h b/lib/include/wolff/graph.hpp index de06924..165544a 100644 --- a/lib/graph.h +++ b/lib/include/wolff/graph.hpp @@ -17,6 +17,5 @@ class graph_t { graph_t(D_t D, L_t L); void add_ext(); - }; diff --git a/lib/state.h b/lib/include/wolff/state.hpp index cad453c..1f5e359 100644 --- a/lib/state.h +++ b/lib/include/wolff/state.hpp @@ -5,7 +5,7 @@ #include <vector> #include "types.h" -#include "graph.h" +#include "graph.hpp" template <class R_t, class X_t> class state_t { diff --git a/lib/types.h b/lib/include/wolff/types.h index ec9efaf..ec9efaf 100644 --- a/lib/types.h +++ b/lib/include/wolff/types.h diff --git a/lib/rand.c b/lib/rand.c deleted file mode 100644 index 76f537d..0000000 --- a/lib/rand.c +++ /dev/null @@ -1,20 +0,0 @@ - -#include <assert.h> -#include <stdio.h> - -unsigned long int rand_seed() { - /* - returns a random unsigned long integer read from the standard unix - pseudorandom device /dev/urandom - */ - - FILE *f = fopen("/dev/urandom", "r"); - assert(f != NULL); - - unsigned long int seed; - fread(&seed, sizeof(unsigned long int), 1, f); - - fclose(f); - - return seed; -} diff --git a/lib/rand.h b/lib/rand.h deleted file mode 100644 index 7bb5354..0000000 --- a/lib/rand.h +++ /dev/null @@ -1,16 +0,0 @@ - -#pragma once - -#include <assert.h> -#include <stdio.h> - -#ifdef __cplusplus -extern "C" { -#endif - -unsigned long int rand_seed(); - -#ifdef __cplusplus -} -#endif - diff --git a/lib/graph.cpp b/lib/src/graph.cpp index ca251f3..4043413 100644 --- a/lib/graph.cpp +++ b/lib/src/graph.cpp @@ -1,5 +1,5 @@ -#include "graph.h" +#include <wolff/graph.hpp> graph_t::graph_t(D_t D, L_t L) { nv = pow(L, D); diff --git a/lib/torus.h b/lib/torus.h deleted file mode 100644 index 2aead52..0000000 --- a/lib/torus.h +++ /dev/null @@ -1,64 +0,0 @@ - -#pragma once - -#include <cmath> -#include <array> -#include "types.h" - -template <q_t n> -class torus_t : public std::array<double, n> { - public: - typedef std::array<double, n> M_t; - typedef std::array<double, n> F_t; - - torus_t() { - this->fill(0); - } - - inline torus_t<n> operator*(v_t a) const { - torus_t<n> x; - for (q_t i = 0; i < n; i++) { - x[i] = a * (*this)[i]; - } - - return x; - } - - inline torus_t<n> operator*(double a) const { - torus_t<n> x; - for (q_t i = 0; i < n; i++) { - x[i] = a * (*this)[i]; - } - - return x; - } - - inline torus_t<n>& operator+=(const torus_t<n>& x) { - for (q_t i = 0; i < n; i++) { - (*this)[i] += x[i]; - } - } - - inline torus_t<n>& operator-=(const torus_t<n>& x) { - for (q_t i = 0; i < n; i++) { - (*this)[i] -= x[i]; - } - } -}; - -template <q_t n> -double norm_squared(const torus_t<n>& x) { - double tmp = 0; - for (const double& xi : x) { - tmp += pow(xi, 2); - } - return tmp; -} - -void write_magnetization(const torus_t<n>& x, FILE *outfile) { - for (const double& xi : x) { - float tmp_xi = (float)xi; - fwrite(&tmp_xi, sizeof(float), 1, outfile); - } -} - diff --git a/wolfram_link/Makefile b/wolfram_link/Makefile deleted file mode 100644 index 9d65623..0000000 --- a/wolfram_link/Makefile +++ /dev/null @@ -1,13 +0,0 @@ - -CC = clang -WSPREP = /opt/Mathematica/SystemFiles/Links/WSTP/DeveloperKit/Linux-x86-64/CompilerAdditions/wsprep -CFLAGS = -g -Os -O3 -Wall -fno-strict-aliasing -Wstrict-overflow -Wno-missing-field-initializers -flto -fopenmp=libiomp5 -I/usr/lib/gcc/x86_64-linux-gnu/4.8/include/ -march=native -I/opt/Mathematica/SystemFiles/Links/WSTP/DeveloperKit/Linux-x86-64/CompilerAdditions/ -I../lib/ -LDFLAGS = -L/opt/Mathematica/SystemFiles/Links/WSTP/DeveloperKit/Linux-x86-64/CompilerAdditions -lm -lpthread -lrt -lstdc++ -ldl -luuid -l WSTP64i4 - -convex.o: ../lib/convex.c - @${CC} -c -o $@ $< ${CFLAGS} - -convexminorant: convexminorant.tm convex.o - @${WSPREP} $< -o $@.c - @${CC} -o $@ convex.o $@.c ${CFLAGS} ${LDFLAGS} - diff --git a/wolfram_link/convexminorant.tm b/wolfram_link/convexminorant.tm deleted file mode 100644 index edca6f4..0000000 --- a/wolfram_link/convexminorant.tm +++ /dev/null @@ -1,34 +0,0 @@ - -#include <convex.h> -#include <wstp.h> - -extern int WSMain(int, char **); - -void convexminorant(double *, int); - -:Begin: -:Function: convexminorant -:Pattern: GetConvexMinorant[ list:{___Real} ] -:Arguments: { list } -:ArgumentTypes: { Real64List } -:ReturnType: Manual -:End: - -:Evaluate: GetConvexMinorant[ sequence___Float]:= GetConvexMinorant[ {sequence} ] - -void convexminorant(double * Gammas, int len) { - int i; - for (i = 0; i < len; i++) { - if (Gammas[i] <= 0) { - break; - } - } - double *m = get_convex_minorant(i, Gammas); - WSPutReal64List(stdlink, m, i); - free(m); -} - -int main(int argc, char **argv) { - return WSMain(argc, argv); -} - |