summaryrefslogtreecommitdiff
path: root/lib/ising.h
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-20 22:57:39 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-20 22:57:39 -0400
commit5ffaf0a1bb0f0b47d57d0f24ee1134659775dacb (patch)
tree230c9562222b7858316ac1bb59bb3e8570746df4 /lib/ising.h
parent72301b3d5c3a91ff2e7fc6eedcad7bce8e647efa (diff)
downloadc++-5ffaf0a1bb0f0b47d57d0f24ee1134659775dacb.tar.gz
c++-5ffaf0a1bb0f0b47d57d0f24ee1134659775dacb.tar.bz2
c++-5ffaf0a1bb0f0b47d57d0f24ee1134659775dacb.zip
added ising example to cpp collection
Diffstat (limited to 'lib/ising.h')
-rw-r--r--lib/ising.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/ising.h b/lib/ising.h
new file mode 100644
index 0000000..4e5164b
--- /dev/null
+++ b/lib/ising.h
@@ -0,0 +1,80 @@
+#pragma once
+
+#include <cmath>
+#include <stdlib.h>
+
+#include "types.h"
+
+class ising_t {
+ public:
+ bool x;
+
+ typedef int M_t;
+ typedef double F_t;
+};
+
+void init(ising_t *p) {
+ p->x = false;
+}
+
+void free_spin(ising_t s) {
+ // do nothing!
+}
+
+void free_spin(int s) {
+ // do nothing
+}
+
+void free_spin(double s) {
+ // do nothing
+}
+
+ising_t copy(ising_t s) {
+ return s;
+}
+
+template <class T>
+void add(T *s1, T a, ising_t s2) {
+ if (s2.x) {
+ *s1 -= a;
+ } else {
+ *s1 += a;
+ }
+}
+
+int scalar_multiple(int factor, ising_t s) {
+ if (s.x) {
+ return -factor;
+ } else {
+ return factor;
+ }
+}
+
+
+double norm_squared(double s) {
+ return pow(s, 2);
+}
+
+template <class T>
+void write_magnetization(T M, FILE *outfile) {
+ fwrite(&M, sizeof(T), 1, outfile);
+}
+
+// below this line is unnecessary, but convenient
+
+double ising_dot(ising_t s1, ising_t s2) {
+ if (s1.x == s2.x) {
+ return 1.0;
+ } else {
+ return -1.0;
+ }
+}
+
+double scalar_field(ising_t s, double H) {
+ if (s.x) {
+ return -H;
+ } else {
+ return H;
+ }
+}
+