summaryrefslogtreecommitdiff
path: root/lib/src
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 /lib/src
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 'lib/src')
-rw-r--r--lib/src/graph.cpp79
1 files changed, 30 insertions, 49 deletions
diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp
index b42aa78..4f91be4 100644
--- a/lib/src/graph.cpp
+++ b/lib/src/graph.cpp
@@ -1,74 +1,55 @@
#include <wolff/graph.hpp>
-graph_t::graph_t(D_t D, L_t L, lattice_t lat) {
- switch (lat) {
- case SQUARE_LATTICE: {
- nv = pow(L, D);
- ne = D * nv;
+namespace wolff {
- adj.resize(nv);
- coordinate.resize(nv);
-
- for (std::vector<v_t> adj_i : adj) {
- adj_i.reserve(2 * D);
- }
-
- for (v_t i = 0; i < nv; i++) {
- coordinate[i].resize(D);
- for (D_t j = 0; j < D; j++) {
- coordinate[i][j] = (i / (v_t)pow(L, D - j - 1)) % L;
-
- adj[i].push_back(pow(L, j + 1) * (i / ((v_t)pow(L, j + 1))) + fmod(i + pow(L, j), pow(L, j + 1)));
- adj[i].push_back(pow(L, j + 1) * (i / ((v_t)pow(L, j + 1))) + fmod(pow(L, j+1) + i - pow(L, j), pow(L, j + 1)));
- }
- }
- break;
- }
- case DIAGONAL_LATTICE: {
- nv = D * pow(L, D);
- ne = 2 * nv;
+graph::graph() {
+ D = 0;
+ L = 0;
+ nv = 0;
+ ne = 0;
+}
- adj.resize(nv);
- coordinate.resize(nv);
+graph::graph(D_t D, L_t L) : D(D), L(L) {
+ nv = pow(L, D);
+ ne = D * nv;
- for (std::vector<v_t> adj_i : adj) {
- adj_i.reserve(4 * (D - 1));
- }
+ adjacency.resize(nv);
+ coordinate.resize(nv);
- for (D_t i = 0; i < D; i++) {
- v_t sb = i * pow(L, D);
+ for (std::vector<v_t> adj_i : adjacency) {
+ adj_i.reserve(2 * D);
+ }
- for (v_t j = 0; j < pow(L, D); j++) {
- v_t vc = sb + j;
+ for (v_t i = 0; i < nv; i++) {
+ coordinate[i].resize(D);
+ for (D_t j = 0; j < D; j++) {
+ coordinate[i][j] = (i / (v_t)pow(L, D - j - 1)) % L;
- adj[vc].push_back(((i + 1) % D) * pow(L, D) + j);
- adj[vc].push_back(((i + 1) % D) * pow(L, D) + pow(L, D - 1) * (j / (v_t)pow(L, D - 1)) + (j + 1 - 2 * (i % 2)) % L);
- adj[vc].push_back(((i + 1) % D) * pow(L, D) + pow(L, D - 1) * ((L + (j/ (v_t)pow(L, D - 1)) - 1 + 2 * (i % 2)) % L) + (j - i) % L);
- adj[vc].push_back(((i + 1) % D) * pow(L, D) + pow(L, D - 1) * ((L + (j/ (v_t)pow(L, D - 1)) - 1 + 2 * (i % 2)) % L) + (j + 1 - i) % L);
- }
- }
- break;
- }
+ adjacency[i].push_back(pow(L, j + 1) * (i / ((v_t)pow(L, j + 1))) + fmod(i + pow(L, j), pow(L, j + 1)));
+ adjacency[i].push_back(pow(L, j + 1) * (i / ((v_t)pow(L, j + 1))) + fmod(pow(L, j+1) + i - pow(L, j), pow(L, j + 1)));
+ }
}
}
-void graph_t::add_ext() {
- for (std::vector<v_t>& adj_i : adj) {
+void graph::add_ghost() {
+ for (std::vector<v_t>& adj_i : adjacency) {
adj_i.push_back(nv);
}
- adj.resize(nv + 1);
+ adjacency.resize(nv + 1);
coordinate.resize(nv + 1);
- adj[nv].reserve(nv);
+ adjacency[nv].reserve(nv);
for (v_t i = 0; i < nv; i++) {
- adj[nv].push_back(i);
+ adjacency[nv].push_back(i);
}
coordinate[nv].resize(coordinate[0].size());
ne += nv;
- nv += 1;
+ nv++;
+}
+
}