summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-10-19 01:26:14 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-10-19 01:26:14 -0400
commit643baba78eb15a685d959aae718ee3eeade2f806 (patch)
tree35c35e5e383f7ae1937574f3c764a0f60a448e6e /examples
parentf2f7a072216dfafab89851e4ff3e0b2c3eb16663 (diff)
downloadc++-643baba78eb15a685d959aae718ee3eeade2f806.tar.gz
c++-643baba78eb15a685d959aae718ee3eeade2f806.tar.bz2
c++-643baba78eb15a685d959aae718ee3eeade2f806.zip
big library overhual, fixed all examples, added documentation with sphinx
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt4
-rw-r--r--examples/On.cpp10
-rw-r--r--examples/ising.cpp14
-rw-r--r--examples/ising_animation.cpp (renamed from examples/animate_ising.cpp)36
-rw-r--r--examples/simple_measurement.hpp18
5 files changed, 49 insertions, 33 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 73922c6..a4a4a5c 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,11 +1,11 @@
add_executable(ising ising.cpp)
-add_executable(animate_ising animate_ising.cpp)
+add_executable(ising_animation ising_animation.cpp)
add_executable(xy On.cpp)
add_compile_definitions(xy WOLFF_N=2)
target_link_libraries(ising wolff)
-target_link_libraries(animate_ising wolff GL GLU glut)
+target_link_libraries(ising_animation wolff GL GLU glut)
target_link_libraries(xy wolff)
diff --git a/examples/On.cpp b/examples/On.cpp
index e045f52..6c3f0fd 100644
--- a/examples/On.cpp
+++ b/examples/On.cpp
@@ -7,6 +7,7 @@
#include <wolff/models/vector.hpp>
#include <wolff/models/orthogonal.hpp>
+
#include <wolff.hpp>
int main(int argc, char *argv[]) {
@@ -56,10 +57,13 @@ int main(int argc, char *argv[]) {
return H * s;
};
+ // initialize the lattice
+ graph G(D, L);
+
// initialize the system
- wolff_system<orthogonal_t<WOLFF_N, double>, vector_t<WOLFF_N, double>> S(D, L, T, Z, B);
+ system<orthogonal_t<WOLFF_N, double>, vector_t<WOLFF_N, double>> S(G, T, Z, B);
- std::function <orthogonal_t<WOLFF_N, double>(std::mt19937&, const vector_t<WOLFF_N, double>&)> gen_R = generate_rotation_uniform<WOLFF_N>;
+ std::function <orthogonal_t<WOLFF_N, double>(std::mt19937&, const system<orthogonal_t<WOLFF_N, double>, vector_t<WOLFF_N, double>>&, v_t)> gen_R = generate_rotation_uniform<WOLFF_N>;
// initailze the measurement object
simple_measurement A(S);
@@ -69,7 +73,7 @@ int main(int argc, char *argv[]) {
std::mt19937 rng{seed};
// run wolff N times
- wolff<orthogonal_t<WOLFF_N, double>, vector_t<WOLFF_N, double>>(N, S, gen_R, A, rng);
+ S.run_wolff(N, gen_R, A, rng);
// print the result of our measurements
std::cout << "Wolff complete!\nThe average energy per site was " << A.avgE() / S.nv
diff --git a/examples/ising.cpp b/examples/ising.cpp
index ffcb7e4..fe21279 100644
--- a/examples/ising.cpp
+++ b/examples/ising.cpp
@@ -7,8 +7,11 @@
#include <wolff/models/ising.hpp>
#include <wolff/finite_states.hpp>
+
#include <wolff.hpp>
+using namespace wolff;
+
int main(int argc, char *argv[]) {
// set defaults
@@ -53,23 +56,24 @@ int main(int argc, char *argv[]) {
return H * s;
};
+ // initialize the lattice
+ graph G(D, L);
+
// initialize the system
- wolff_system<ising_t, ising_t> S(D, L, T, Z, B);
+ system<ising_t, ising_t> S(G, T, Z, B);
// initialize the random number generator
auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng{seed};
// define function that generates self-inverse rotations
- std::function <ising_t(std::mt19937&, const ising_t&)> gen_R = [] (std::mt19937&, const ising_t& s) -> ising_t {
- return ising_t(true);
- };
+ std::function <ising_t(std::mt19937&, const system<ising_t, ising_t>&, v_t)> gen_r = gen_ising;
// initailze the measurement object
simple_measurement A(S);
// run wolff N times
- wolff<ising_t, ising_t>(N, S, gen_R, A, rng);
+ S.run_wolff(N, gen_r, A, rng);
// print the result of our measurements
std::cout << "Wolff complete!\nThe average energy per site was " << A.avgE() / S.nv
diff --git a/examples/animate_ising.cpp b/examples/ising_animation.cpp
index e33736e..2104e91 100644
--- a/examples/animate_ising.cpp
+++ b/examples/ising_animation.cpp
@@ -7,14 +7,17 @@
#include <wolff/models/ising.hpp>
#include <wolff/finite_states.hpp>
+
#include <wolff.hpp>
-class draw_ising : public wolff_measurement<ising_t, ising_t> {
+using namespace wolff;
+
+class draw_ising : public measurement<ising_t, ising_t> {
private:
unsigned int frame_skip;
v_t C;
public:
- draw_ising(const wolff_system<ising_t, ising_t>& S, unsigned int window_size, unsigned int frame_skip, int argc, char *argv[]) : frame_skip(frame_skip){
+ draw_ising(const system<ising_t, ising_t>& S, unsigned int window_size, unsigned int frame_skip, int argc, char *argv[]) : frame_skip(frame_skip){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(window_size, window_size);
@@ -22,39 +25,39 @@ class draw_ising : public wolff_measurement<ising_t, ising_t> {
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- gluOrtho2D(0.0, S.L, 0.0, S.L);
+ gluOrtho2D(0.0, S.G.L, 0.0, S.G.L);
}
- void pre_cluster(N_t, N_t, const wolff_system<ising_t, ising_t>& S, v_t, const ising_t&) {
+ void pre_cluster(N_t, N_t, const system<ising_t, ising_t>& S, v_t, const ising_t&) {
glClear(GL_COLOR_BUFFER_BIT);
- for (v_t i = 0; i < pow(S.L, 2); i++) {
+ for (v_t i = 0; i < pow(S.G.L, 2); i++) {
if (S.s[i].x == S.s0.x) {
glColor3f(0.0, 0.0, 0.0);
} else {
glColor3f(1.0, 1.0, 1.0);
}
- glRecti(i / S.L, i % S.L, (i / S.L) + 1, (i % S.L) + 1);
+ glRecti(i / S.G.L, i % S.G.L, (i / S.G.L) + 1, (i % S.G.L) + 1);
}
glFlush();
C = 0;
}
- void plain_bond_visited(const wolff_system<ising_t, ising_t>&, v_t, const ising_t&, v_t, double dE) {}
+ void plain_bond_visited(const system<ising_t, ising_t>&, v_t, const ising_t&, v_t, double dE) {}
- void ghost_bond_visited(const wolff_system<ising_t, ising_t>&, v_t, const ising_t& s_old, const ising_t& s_new, double dE) {}
+ void ghost_bond_visited(const system<ising_t, ising_t>&, v_t, const ising_t& s_old, const ising_t& s_new, double dE) {}
- void plain_site_transformed(const wolff_system<ising_t, ising_t>& S, v_t i, const ising_t&) {
+ void plain_site_transformed(const system<ising_t, ising_t>& S, v_t i, const ising_t&) {
glColor3f(1.0, 0.0, 0.0);
- glRecti(i / S.L, i % S.L, (i / S.L) + 1, (i % S.L) + 1);
+ glRecti(i / S.G.L, i % S.G.L, (i / S.G.L) + 1, (i % S.G.L) + 1);
C++;
if (C % frame_skip == 0) {
glFlush();
}
}
- void ghost_site_transformed(const wolff_system<ising_t, ising_t>&, const ising_t&) {}
+ void ghost_site_transformed(const system<ising_t, ising_t>&, const ising_t&) {}
- void post_cluster(N_t, N_t, const wolff_system<ising_t, ising_t>&) {}
+ void post_cluster(N_t, N_t, const system<ising_t, ising_t>&) {}
};
int main(int argc, char *argv[]) {
@@ -109,11 +112,14 @@ int main(int argc, char *argv[]) {
return H * s;
};
+ // initialize the lattice
+ graph G(D, L);
+
// initialize the system
- wolff_system<ising_t, ising_t> S(D, L, T, Z, B);
+ system<ising_t, ising_t> S(G, T, Z, B);
// define function that generates self-inverse rotations
- std::function <ising_t(std::mt19937&, const ising_t&)> gen_R = [] (std::mt19937&, const ising_t& s) -> ising_t {
+ std::function <ising_t(std::mt19937&, const system<ising_t, ising_t>&, v_t)> gen_R = [] (std::mt19937&, const system<ising_t, ising_t>&, v_t) -> ising_t {
return ising_t(true);
};
@@ -125,7 +131,7 @@ int main(int argc, char *argv[]) {
std::mt19937 rng{seed};
// run wolff N times
- wolff<ising_t, ising_t>(N, S, gen_R, A, rng);
+ S.run_wolff(N, gen_R, A, rng);
// exit
return 0;
diff --git a/examples/simple_measurement.hpp b/examples/simple_measurement.hpp
index 2287c58..518631c 100644
--- a/examples/simple_measurement.hpp
+++ b/examples/simple_measurement.hpp
@@ -1,8 +1,10 @@
#include <wolff/measurement.hpp>
+using namespace wolff;
+
template <class R_t, class X_t>
-class simple_measurement : public wolff_measurement<R_t, X_t> {
+class simple_measurement : public measurement<R_t, X_t> {
private:
N_t n;
@@ -15,7 +17,7 @@ class simple_measurement : public wolff_measurement<R_t, X_t> {
double totalC;
public:
- simple_measurement(const wolff_system<R_t, X_t>& S) {
+ simple_measurement(const system<R_t, X_t>& S) {
n = 0;
M = S.nv * S.s[0];
E = - (S.ne * S.Z(S.s[0], S.s[0]) + S.nv * S.B(S.s[0]));
@@ -25,26 +27,26 @@ class simple_measurement : public wolff_measurement<R_t, X_t> {
totalC = 0;
}
- void pre_cluster(N_t, N_t, const wolff_system<R_t, X_t>&, v_t, const R_t&) {
+ void pre_cluster(N_t, N_t, const system<R_t, X_t>&, v_t, const R_t&) {
C = 0;
}
- void plain_bond_visited(const wolff_system<R_t, X_t>&, v_t, const X_t&, v_t, double dE) {
+ void plain_bond_visited(const system<R_t, X_t>&, v_t, const X_t&, v_t, double dE) {
E += dE;
}
- void ghost_bond_visited(const wolff_system<R_t, X_t>&, v_t, const X_t& s_old, const X_t& s_new, double dE) {
+ void ghost_bond_visited(const system<R_t, X_t>&, v_t, const X_t& s_old, const X_t& s_new, double dE) {
E += dE;
M += s_new - s_old;
}
- void plain_site_transformed(const wolff_system<R_t, X_t>&, v_t, const X_t&) {
+ void plain_site_transformed(const system<R_t, X_t>&, v_t, const X_t&) {
C++;
}
- void ghost_site_transformed(const wolff_system<R_t, X_t>&, const R_t&) {}
+ void ghost_site_transformed(const system<R_t, X_t>&, const R_t&) {}
- void post_cluster(N_t, N_t, const wolff_system<R_t, X_t>&) {
+ void post_cluster(N_t, N_t, const system<R_t, X_t>&) {
totalE += E;
totalM += M;
totalC += C;