From 6461165f4daea01c5baa1d969ee5c726fb4c559e Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 26 Feb 2020 00:00:16 -0500 Subject: Finished fixes of new features. --- dimers.cpp | 2 +- dimers_torus.cpp | 2 +- spheres.cpp | 2 +- spheres.hpp | 39 ++++++++++++++++++++------------------- vector.hpp | 2 +- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/dimers.cpp b/dimers.cpp index 4416333..d5cfdf4 100644 --- a/dimers.cpp +++ b/dimers.cpp @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) { file.open(filename); Animation, Dimer> A(L, 750, argc, argv, wait); - model sphere(1.0, Z, bCenter>(H)); + model sphere(1, Z, bCenter>(H)); Rng rng; diff --git a/dimers_torus.cpp b/dimers_torus.cpp index 74cf47e..ec7c73a 100644 --- a/dimers_torus.cpp +++ b/dimers_torus.cpp @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) { sphere.s.resize(n); - unsigned nx = floor(sqrt(n)); + unsigned nx = ceil(sqrt(n)); for (unsigned i = 0; i < sphere.s.size(); i++) { Spin>* ss = new Spin>(); ss->x = {(i / nx) * L / nx, (i % nx) * L / nx}; diff --git a/spheres.cpp b/spheres.cpp index 9ca2036..4b2237d 100644 --- a/spheres.cpp +++ b/spheres.cpp @@ -75,7 +75,7 @@ int main(int argc, char* argv[]) { sphere.s.resize(n); - unsigned nx = floor(sqrt(n)); + unsigned nx = ceil(sqrt(n)); for (unsigned i = 0; i < sphere.s.size(); i++) { Spin* ss = new Spin(); ss->x = {(i / nx) * L / nx, (i % nx) * L / nx}; diff --git a/spheres.hpp b/spheres.hpp index 3dc4a5e..60154f6 100644 --- a/spheres.hpp +++ b/spheres.hpp @@ -2,13 +2,8 @@ #include "space_wolff.hpp" template -std::function&, const Spin&)> -zSpheres(double a, double k) { - return [a, k](const Spin& s1, const Spin& s2) -> double { - Vector d = s1.x - s2.x; - - double σ = s1.s + s2.s; - double δ = σ - sqrt(d.transpose() * d); +double softPotential(double a, double k, const Vector& diff, double σ) { + double δ = σ - sqrt(diff.transpose() * diff); if (δ > -a * σ) { return 0.5 * k * (2 * pow(a * σ, 2) - pow(δ, 2)); @@ -17,6 +12,23 @@ zSpheres(double a, double k) { } else { return 0; } +} + +template +double hardPotential(const Vector& diff, double σ) { + if (pow(σ, 2) < diff.transpose() * diff) { + return 0; + } else { + return -std::numeric_limits::infinity(); + } +} + +template +std::function&, const Spin&)> +zSpheres(double a, double k) { + return [a, k](const Spin& s1, const Spin& s2) -> double { + Vector d = s1.x - s2.x; + return softPotential(a, k, d, s1.s + s2.s); }; } @@ -24,18 +36,7 @@ template std::function&, const Spin&)> zSpheresTorus(double L, double a, double k) { return [L, a, k](const Spin& s1, const Spin& s2) -> double { - Vector d = diff(L, s1.x, s2.x); - - double σ = s1.s + s2.s; - double δ = σ - sqrt(d.transpose() * d); - - if (δ > -a * σ) { - return 0.5 * k * (2 * pow(a * σ, 2) - pow(δ, 2)); - } else if (δ > -2 * a * σ) { - return 0.5 * k * pow(δ + 2 * a * σ, 2); - } else { - return 0; - } + return softPotential(a, k, diff(L, s1.x, s2.x), s1.s + s2.s); }; } diff --git a/vector.hpp b/vector.hpp index f642816..04a1a97 100644 --- a/vector.hpp +++ b/vector.hpp @@ -10,7 +10,7 @@ template Vector diff(T L, Vector v1, Vector v Vector v; for (unsigned i = 0; i < D; i++) { - v(i) = std::abs(mod(v1(i), L) - mod(v2(i), L)); + v(i) = mod(std::abs(v1(i) - v2(i)), L); if (v(i) > L / 2) { v(i) = L - v(i); } -- cgit v1.2.3-70-g09d2