summaryrefslogtreecommitdiff
path: root/soft_spheres.cpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2021-09-16 16:47:05 +0200
committerJaron Kent-Dobias <jaron@kent-dobias.com>2021-09-16 16:47:05 +0200
commit496dcbd9960677db246a84bcd3e4b4230ee28e0a (patch)
tree7477598b762a825e7aefae74a6748df7601fca33 /soft_spheres.cpp
downloadspheres-496dcbd9960677db246a84bcd3e4b4230ee28e0a.tar.gz
spheres-496dcbd9960677db246a84bcd3e4b4230ee28e0a.tar.bz2
spheres-496dcbd9960677db246a84bcd3e4b4230ee28e0a.zip
Initial commit.
Diffstat (limited to 'soft_spheres.cpp')
-rw-r--r--soft_spheres.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/soft_spheres.cpp b/soft_spheres.cpp
new file mode 100644
index 0000000..a71a472
--- /dev/null
+++ b/soft_spheres.cpp
@@ -0,0 +1,44 @@
+#include "animation.hpp"
+
+int main(int argc, char* argv[]) {
+ const unsigned n = 12;
+
+ unsigned N = 1200;
+ double R = 0.024;
+ double ε = 0.01;
+ unsigned steps = 1e6;
+ double β = 1;
+
+ initializeAnimation(argc, argv);
+
+ Rng r;
+
+ Model<2, SoftSphere<2, n>> m(N, 2 * R * 1.25);
+
+ for (unsigned i = 0; i < N; i++) {
+ Position<2> x = {r.uniform(0.0, 1.0), r.uniform(0.0, 1.0)};
+ double rad = pow(r.uniform(pow(2.219, -2), 1.0), -0.5) * R / 2.219;
+ m.insert(SoftSphere<2, n>(x, rad));
+ }
+
+ for (unsigned i = 0; i < steps * N; i++) {
+ SoftSphere<2, n>& s = r.pick(m.particles);
+ Vector<2> Δx;
+ for (double& Δxi : Δx) {
+ Δxi = r.variate<double, std::normal_distribution>(0, ε);
+ }
+
+ m.metropolis(β, s, Δx, r);
+
+ SoftSphere<2, n>& s1 = r.pick(m.particles);
+ SoftSphere<2, n>& s2 = r.pick(m.particles);
+
+ m.swap(β, s1, s2, r);
+
+ if (i % (N * 3) == 0) {
+ draw(m);
+ }
+ }
+
+ return 0;
+}