From 643baba78eb15a685d959aae718ee3eeade2f806 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Fri, 19 Oct 2018 01:26:14 -0400 Subject: big library overhual, fixed all examples, added documentation with sphinx --- lib/src/graph.cpp | 79 +++++++++++++++++++++---------------------------------- 1 file changed, 30 insertions(+), 49 deletions(-) (limited to 'lib/src/graph.cpp') 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 -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 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 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 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& adj_i : adj) { +void graph::add_ghost() { + for (std::vector& 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++; +} + } -- cgit v1.2.3-70-g09d2