summaryrefslogtreecommitdiff
path: root/lib/dihedral.h
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-24 15:26:31 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-24 15:26:31 -0400
commit96e878d2f69790dc72bb4b713c1d492fa2b4c587 (patch)
tree9b8dd7d0f2e448646bbeb74b8c943532d3650fe4 /lib/dihedral.h
parentc48fd16fe1554c88c79a1f0d50e81c803da8f61f (diff)
downloadc++-96e878d2f69790dc72bb4b713c1d492fa2b4c587.tar.gz
c++-96e878d2f69790dc72bb4b713c1d492fa2b4c587.tar.bz2
c++-96e878d2f69790dc72bb4b713c1d492fa2b4c587.zip
added preprocessor method for potts, and implemented dihedral for the c++ stuff
Diffstat (limited to 'lib/dihedral.h')
-rw-r--r--lib/dihedral.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/dihedral.h b/lib/dihedral.h
index c95b23a..f67c930 100644
--- a/lib/dihedral.h
+++ b/lib/dihedral.h
@@ -19,3 +19,81 @@ q_t *dihedral_gen_transformations(q_t q);
R_t *dihedral_gen_involutions(q_t q);
R_t factorial(q_t);
+
+#ifdef __cplusplus
+
+template <class T, q_t q>
+struct dihedral2_t { bool is_reflection; T x; };
+
+template <class T, q_t q>
+void init(dihedral2_t<T, q> *ptr) {
+ ptr->is_reflection = false;
+ ptr->x = (T)0;
+}
+
+template <class T, q_t q>
+dihedral2_t<T, q> copy(dihedral2_t<T, q> r) {
+ return r;
+}
+
+template <class T, q_t q>
+void free_spin(dihedral2_t<T, q> r) {
+ // do nothing!
+}
+
+template <q_t q>
+potts_t<q> act(dihedral2_t<q_t, q> r, potts_t<q> s) {
+ potts_t<q> s2;
+ if (r.is_reflection) {
+ s2.x = ((q + r.x) - s.x) % q;
+ } else {
+ s2.x = (r.x + s.x) % q;
+ }
+
+ return s2;
+}
+
+template <q_t q>
+dihedral2_t<q_t,q> act(dihedral2_t<q_t,q> r1, dihedral2_t<q_t,q> r2) {
+ dihedral2_t<q_t,q> r3;
+
+ if (r1.is_reflection) {
+ r3.is_reflection = !(r2.is_reflection);
+ r3.x = ((q + r1.x) - r2.x) % q;
+ } else {
+ r3.is_reflection = r2.is_reflection;
+ r3.x = (r1.x + r2.x) % q;
+ }
+
+ return r3;
+}
+
+template <q_t q>
+potts_t<q> act_inverse(dihedral2_t<q_t,q> r, potts_t<q> s) {
+ potts_t<q> s2;
+ if (r.is_reflection) {
+ s2.x = ((r.x + q) - s.x) % q;
+ } else {
+ s2.x = ((s.x + q) - r.x) % q;
+ }
+
+ return s2;
+}
+
+template <q_t q>
+dihedral2_t<q_t, q> act_inverse(dihedral2_t<q_t,q> r1, dihedral2_t<q_t,q> r2) {
+ dihedral2_t<q_t,q> r3;
+
+ if (r1.is_reflection) {
+ r3.is_reflection = !(r2.is_reflection);
+ r3.x = ((r1.x + q) - r2.x) % q;
+ } else {
+ r3.is_reflection = r2.is_reflection;
+ r3.x = ((r2.x + q) - r1.x) % q;
+ }
+
+ return r3;
+}
+
+#endif
+