diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2024-12-11 11:36:39 +0100 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2024-12-11 11:36:39 +0100 |
commit | bd4f181a67aec822d1e420db2b12a10812b371ae (patch) | |
tree | b3c16f80ed2664d8eb8e7192ab833305e549f9dc | |
parent | 2f3979fbca10725eb120a21a51afab6ffda2b0d4 (diff) | |
download | code-bd4f181a67aec822d1e420db2b12a10812b371ae.tar.gz code-bd4f181a67aec822d1e420db2b12a10812b371ae.tar.bz2 code-bd4f181a67aec822d1e420db2b12a10812b371ae.zip |
Moved coordinate calculation to construction
-rw-r--r-- | percolation.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/percolation.cpp b/percolation.cpp index a5c2a36..f012b07 100644 --- a/percolation.cpp +++ b/percolation.cpp @@ -26,6 +26,7 @@ class Vertex { public: std::vector<HalfEdge> bonds; unsigned index; + std::vector<unsigned> coordinates; }; class Cluster : public std::list<std::reference_wrapper<const Vertex>> {}; @@ -60,8 +61,8 @@ public: unsigned squaredDistance(unsigned vi, unsigned vj) const { unsigned sd = 0; for (unsigned i = 0; i < D; i++) { - int x1 = (vi / uPow(L, i)) % uPow(L, i + 1); - int x2 = (vj / uPow(L, i)) % uPow(L, i + 1); + int x1 = vertices[vi].coordinates[i]; + int x2 = vertices[vj].coordinates[i]; unsigned Δx = abs(x1 - x2); if (Δx > L / 2) { Δx = L - Δx; @@ -72,11 +73,14 @@ public: } /* Initialize a square lattice */ - Graph(unsigned D, unsigned L) : D(D), L(L), vertices(uPow(L, D)), multiplicities(D * L * L / 4) { + Graph(unsigned D, unsigned L) : D(D), L(L), vertices(uPow(L, D)), multiplicities((D * L * L) / 4) { for (unsigned i = 0; i < Nv(); i++) { + vertices[i].coordinates.resize(D); vertices[i].index = i; vertices[i].bonds.reserve(2 * D); for (unsigned j = 0; j < D; j++) { + vertices[i].coordinates[j] = (i / uPow(L, j)) % L; + unsigned n1 = uPow(L, j + 1) * (i / uPow(L, j + 1)) + (i + uPow(L, j)) % uPow(L, j + 1); unsigned n2 = uPow(L, j + 1) * (i / uPow(L, j + 1)) + (uPow(L, j + 1) + i - uPow(L, j)) % uPow(L, j + 1); |