summaryrefslogtreecommitdiff
path: root/examples/src/models/ising/ising.hpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-10-10 21:45:32 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-10-10 21:45:32 -0400
commita43ff1f98e9b9814f858bccb11c174b418458491 (patch)
treeae7e094d914eddb8a1ae9548420ba8c2f329ffae /examples/src/models/ising/ising.hpp
parent6e264d243f0b29d90e90b605b6cdeab8227129c9 (diff)
downloadc++-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
Diffstat (limited to 'examples/src/models/ising/ising.hpp')
-rw-r--r--examples/src/models/ising/ising.hpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/examples/src/models/ising/ising.hpp b/examples/src/models/ising/ising.hpp
new file mode 100644
index 0000000..ae20840
--- /dev/null
+++ b/examples/src/models/ising/ising.hpp
@@ -0,0 +1,59 @@
+#pragma once
+
+#include <cmath>
+#include <stdio.h>
+
+#include <wolff/types.h>
+
+class ising_t {
+ public:
+ bool x;
+
+ typedef int M_t;
+ typedef double F_t;
+
+ ising_t() : x(false) {}
+ ising_t(bool x) : x(x) {}
+ ising_t(int x) : x((bool)x) {}
+
+ inline int operator*(v_t a) const {
+ if (x) {
+ return -(int)a;
+ } else {
+ return (int)a;
+ }
+ }
+
+ inline double operator*(double a) const {
+ if (x) {
+ return -a;
+ } else {
+ return a;
+ }
+ }
+
+ inline int operator-(const ising_t &s) const {
+ if (x == s.x) {
+ return 0;
+ } else {
+ if (x) {
+ return -2;
+ } else {
+ return 2;
+ }
+ }
+ }
+};
+
+double norm_squared(double s) {
+ return pow(s, 2);
+}
+
+void write_magnetization(int M, FILE *outfile) {
+ fwrite(&M, sizeof(int), 1, outfile);
+}
+
+#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; }
+