summaryrefslogtreecommitdiff
path: root/lib/src/graph.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/graph.cpp')
-rw-r--r--lib/src/graph.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp
new file mode 100644
index 0000000..e76947b
--- /dev/null
+++ b/lib/src/graph.cpp
@@ -0,0 +1,38 @@
+
+#include "graph.hpp"
+
+graph::graph(unsigned int L) {
+ double dx = 1.0 / L;
+ unsigned int nv = 2 * pow(L / 2, 2);
+ unsigned int ne = pow(L, 2);
+
+ vertices.resize(nv);
+ edges.resize(ne);
+
+ dual_vertices.resize(nv);
+ dual_edges.resize(ne);
+
+ for (unsigned int i = 0; i < nv; i++) {
+ vertices[i].r.x = dx * ((1 + i / (L / 2)) % 2 + 2 * (i % (L / 2)));
+ vertices[i].r.y = dx * (i / (L / 2));
+
+ dual_vertices[i].r.x = dx * ((i / (L / 2)) % 2 + 2 * (i % (L / 2)));
+ dual_vertices[i].r.y = dx * (i / (L / 2));
+ }
+
+ for (unsigned int i = 0; i < ne; i++) {
+ unsigned int x = i / L;
+ unsigned int y = i % L;
+
+ unsigned int v1 = (L * x) / 2 + ((y + x % 2) / 2) % (L / 2);
+ unsigned int v2 = ((L * (x + 1)) / 2 + ((y + (x + 1) % 2) / 2) % (L / 2)) % nv;
+
+ edges[i] = {v1, v2};
+
+ unsigned int dv1 = (L * x) / 2 + ((y + (x + 1) % 2) / 2) % (L / 2);
+ unsigned int dv2 = ((L * (x + 1)) / 2 + ((y + x % 2) / 2) % (L / 2)) % nv;
+
+ dual_edges[i] = {dv1, dv2};
+ }
+}
+