From fb4c5ffab6a3648ef7d9d3558cd4f9edc1fe2254 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 2 Aug 2021 18:09:53 +0200 Subject: Remaved self inverse scattering in favor of overlap, worked on camparisons for Ciamarra. --- ciamarra.cpp | 75 +++++++++++++++++++---------------------------------- distinguishable.cpp | 20 +++++++++----- glass.hpp | 73 ++++++++++++++++++++------------------------------- 3 files changed, 69 insertions(+), 99 deletions(-) diff --git a/ciamarra.cpp b/ciamarra.cpp index d3acc38..1d4538f 100644 --- a/ciamarra.cpp +++ b/ciamarra.cpp @@ -84,38 +84,6 @@ class CiamarraSystem : public HardSystem> { } } } - - /* For the Ciamarra system, position within sites must be specially acconted - * for in the scattering function. We therefore expand the lattice and add - * the state when setting positions, so as later to be able to take particle - * sublattice positions into account. - * */ - void setInitialPosition() override { - CiamarraSystem::orientation = Transformation(CiamarraSystem::L); - for (Vertex>& v : CiamarraSystem::vertices) { - v.initialPosition = 4 * v.position + v.state; - } - } - - double selfIntermediateScattering(const std::vector>& ms) const override { - double F = 0; - - std::array, D> ks; - for (unsigned i = 0; i < D; i++) { - ks[i].setZero(); - ks[i](i) = 1; - } - for (const Vertex>& v : CiamarraSystem::vertices) { - if (!v.empty()) { - Vector Δx = ((4 * CiamarraSystem::orientation.inverse().apply(v.position)) + CiamarraSystem::orientation.inverse().apply(v.state)) - v.initialPosition; - for (const Vector& k : ks) { - F += cos((M_PI / 4) * k.dot(Δx)); - } - } - } - - return F / (D * CiamarraSystem::N); - } }; void print(const CiamarraSystem<2>& s) { @@ -161,27 +129,38 @@ int main() { while (s.density() < ρ) { s.sweepGrandCanonical(z, r); } - std::cout << s.density() << " "; - s.setInitialPosition(); + + std::cout << s.N << std::endl; + + CiamarraSystem s0 = s; + double last_overlap = 1; auto start = std::chrono::high_resolution_clock::now(); - for (unsigned i = 0; i < 1e4; i++) { - /* + + while (last_overlap > 0.1) { for (unsigned j = 0; j < s.vertices.size(); j++) { - s.tryRandomNonlocalMove(r); + s.tryRandomMove(r); } - */ + + auto stop = std::chrono::high_resolution_clock::now(); + auto duration = duration_cast(stop - start); + last_overlap = ((double)s.overlap(s0) / s.N - s.density() / 6) / (1 - s.density() / 6); + std::cout << duration.count() << " " << last_overlap << " "; + } + std::cout << std::endl; + + CiamarraSystem s1 = s; + last_overlap = 1; + auto start1 = std::chrono::high_resolution_clock::now(); + + while (last_overlap > 0.1) { Matrix m = r.pick(ms); Vertex>& v = r.pick(s.vertices); - unsigned n = s.wolff(Transformation(L, m, v.position - m * v.position), r); - if (i % 1 == 0) { - auto stop = std::chrono::high_resolution_clock::now(); - auto duration = duration_cast(stop - start); - std::cout << duration.count() << " " << s.selfIntermediateScattering(ms) << " " << n << " "; - } - } - if (!s.compatible()) { - std::cerr << "Bad configuration" << std::endl; - return 1; + s.wolff(Transformation(L, m, v.position - m * v.position), r.pick(s.vertices)); + + auto stop = std::chrono::high_resolution_clock::now(); + auto duration = duration_cast(stop - start1); + last_overlap = ((double)s.overlap(s1) / s.N - s.density() / 6) / (1 - s.density() / 6); + std::cout << duration.count() << " " << last_overlap << " "; } std::cout << std::endl; } diff --git a/distinguishable.cpp b/distinguishable.cpp index 0aae0c1..de71c47 100644 --- a/distinguishable.cpp +++ b/distinguishable.cpp @@ -53,7 +53,7 @@ int main() { unsigned N = 1560; double Tmin = 0; double Tmax = 0.4; - double δT = 0.02; + double δT = 0.05; Rng r; @@ -86,23 +86,29 @@ int main() { /* */ std::cout << T << " "; + for (unsigned i = 0; i < 1e3; i++) { + for (unsigned j = 0; j < s.vertices.size(); j++) { + s.tryRandomSwap(T, r); + } + } s.setInitialPosition(); + DistinguishableSystem s0 = s; auto start = std::chrono::high_resolution_clock::now(); - Quantity energy(1e3); +// Quantity energy(1e3); for (unsigned i = 0; i < 1e5; i++) { + /* for (unsigned j = 0; j < s.vertices.size(); j++) { s.tryRandomSwap(T, r); } - /* + */ Matrix m = r.pick(ms); Vertex& v = r.pick(s.vertices); s.wolff(Transformation(L, m, v.position - m * v.position), T, r); - */ if (i % 10 == 0) { - energy.add(s.energy()); +// energy.add(s.energy()); auto stop = std::chrono::high_resolution_clock::now(); auto duration = duration_cast(stop - start); - std::cout /*<< duration.count() << " "*/ << s.selfIntermediateScattering(ms) << " "; + std::cout << duration.count() << " " << s.overlap(s0) << " "; } } /* @@ -114,12 +120,14 @@ int main() { } */ std::cout << std::endl; + /* std::vector rho = energy.ρ(); for (const double& x : rho) { std::cout << x << " "; } std::cout << std::endl; std::cerr << T << " " << s.energy() / N << std::endl; + */ // s.sweepLocal(r); // s.sweepSwap(r); // s.swendsenWang(Transformation(L, ms, r), r); diff --git a/glass.hpp b/glass.hpp index 8ad0b52..1b1beb7 100644 --- a/glass.hpp +++ b/glass.hpp @@ -153,6 +153,10 @@ public: CiamarraState s2(m * s); return s2; } + + template A apply(const A& s) const { + return s; + }; }; template concept State = requires(T v, const T& v2) { @@ -166,7 +170,6 @@ template class HalfEdge; template class Vertex { public: Vector position; - Vector initialPosition; S state; std::vector> adjacentEdges; bool marked; @@ -208,7 +211,6 @@ public: System(unsigned L) : L(L), N(0), vertices(iPow(L, D)), orientation(L) { for (unsigned i = 0; i < iPow(L, D); i++) { vertices[i].position = indexToVector(i); - vertices[i].initialPosition = vertices[i].position; vertices[i].adjacentEdges.reserve(2 * D); vertices[i].marked = false; } @@ -232,31 +234,22 @@ public: return iPow(L, D); } - virtual void setInitialPosition() { - orientation = Transformation(L); - for (Vertex& v : vertices) { - v.initialPosition = v.position; - } - } + int overlap(const System& s) const { + unsigned o = 0; + Transformation oRel = orientation.apply(s.orientation.inverse()); - virtual double selfIntermediateScattering(const std::vector>& ms) const { - double F = 0; + for (unsigned i = 0; i < vertices.size(); i++) { + if (!vertices[i].empty()) { + S s1 = vertices[i].state; + S s2 = oRel.apply(s.vertices[vectorToIndex(oRel.inverse().apply(indexToVector(i)))].state); - std::array, D> ks; - for (unsigned i = 0; i < D; i++) { - ks[i].setZero(); - ks[i](i) = 1; - } - for (const Vertex& v : vertices) { - if (!v.empty()) { - Vector Δx = v.position - orientation.apply(v.initialPosition); - for (const Vector& k : ks) { - F += cos(M_PI * k.dot(Δx)); + if (s1 == s2) { + o += 1; } } } - return F / (D * System::N); + return o; } }; @@ -294,7 +287,6 @@ public: if (exp(-ΔE / T) > r.uniform(0.0, 1.0)) { /* Accept the swap. */ - std::swap(v1.initialPosition, v2.initialPosition); return true; } else { /* Revert the swap. */ @@ -381,7 +373,6 @@ public: if (!dry) { std::swap(v.state, vNew.state); - std::swap(v.initialPosition, vNew.initialPosition); } if (!v.empty()) { @@ -453,7 +444,6 @@ public: bool tryRandomMove(Rng& r) { Vertex& v = r.pick(HardSystem::vertices); S oldState = v.state; - Vector oldPos = v.initialPosition; if (!tryDeletion(v)) { return false; @@ -463,7 +453,6 @@ public: for (HalfEdge& e : v.adjacentEdges) { if (1 == e.Δx.dot(oldState)) { if (insert(e.neighbor, oldState.flip())) { - e.neighbor.initialPosition = oldPos; return true; } break; @@ -475,11 +464,9 @@ public: newState = S(r); } if (insert(v, newState)) { - v.initialPosition = oldPos; return true; } } - v.initialPosition = oldPos; v.state = oldState; HardSystem::N++; return false; @@ -488,7 +475,6 @@ public: bool tryRandomNonlocalMove(Rng& r) { Vertex& v = r.pick(HardSystem::vertices); S oldState = v.state; - Vector oldPos = v.initialPosition; if (!tryDeletion(v)) { return false; @@ -498,11 +484,9 @@ public: S newState(r); if (insert(vNew, newState)) { - vNew.initialPosition = oldPos; return true; } - v.initialPosition = oldPos; v.state = oldState; HardSystem::N++; return false; @@ -514,7 +498,6 @@ public: } if (overlaps(v1, v2.state, true).size() == 0 && overlaps(v2, v1.state, true).size() == 0) { std::swap(v1.state, v2.state); - std::swap(v1.initialPosition, v2.initialPosition); return true; } else { return false; @@ -578,7 +561,7 @@ public: } } - unsigned flipCluster(const Transformation& R, Vertex& v0, Rng& r, bool dry = false) { + unsigned flipCluster(const Transformation& R, Vertex& v0, bool dry = false) { std::queue>> q; q.push(v0); @@ -612,7 +595,6 @@ public: if (!dry) { v.state = sNew; vNew.state = s; - std::swap(v.initialPosition, vNew.initialPosition); } if (!v.empty()) { @@ -629,8 +611,19 @@ public: return n; } + unsigned wolff(const Transformation& R, Vertex& v0) { + unsigned n = flipCluster(R, v0); + if (n > HardSystem::N / 2) { + HardSystem::orientation = R.apply(HardSystem::orientation); + } + for (Vertex& v : this->vertices) { + v.marked = false; + } + return n; + } + unsigned wolff(const Transformation& R, Rng& r) { - unsigned n = flipCluster(R, r.pick(this->vertices), r); + unsigned n = flipCluster(R, r.pick(this->vertices)); if (n > HardSystem::N / 2) { HardSystem::orientation = R.apply(HardSystem::orientation); } @@ -644,7 +637,7 @@ public: for (Vertex& v : HardSystem::vertices) { if (!v.marked) { bool dry = 0.5 < r.uniform(0.0, 1.0); - unsigned n = flipCluster(R, v, r, dry); + unsigned n = flipCluster(R, v, dry); if (n > pow(HardSystem::L, D) / 4 && !dry) { HardSystem::orientation = R.apply(HardSystem::orientation); } @@ -656,14 +649,4 @@ public: } } - int overlap(const System& s) const { - int o = 0; - - for (unsigned i = 0; i < HardSystem::vertices.size(); i++) { - S s2 = HardSystem::orientation.apply(s.vertices[HardSystem::vectorToIndex(HardSystem::orientation.inverse().apply(HardSystem::indexToVector(i)))].state); - o += HardSystem::vertices[i].state.dot(s2); - } - - return o; - } }; -- cgit v1.2.3-70-g09d2