summaryrefslogtreecommitdiff
path: root/hard_spheres.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'hard_spheres.cpp')
-rw-r--r--hard_spheres.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/hard_spheres.cpp b/hard_spheres.cpp
new file mode 100644
index 0000000..b53f7cf
--- /dev/null
+++ b/hard_spheres.cpp
@@ -0,0 +1,41 @@
+#include "animation.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned N = 1200;
+ double R = 0.021;
+ double ε = 0.01;
+ unsigned steps = 1e6;
+
+ initializeAnimation(argc, argv);
+
+ Rng r;
+
+ Model<2, HardSphere<2>> m(N, 2 * R);
+
+ 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(HardSphere<2>(x, rad));
+ }
+
+ for (unsigned i = 0; i < steps * N; i++) {
+ HardSphere<2>& s = r.pick(m.particles);
+ Vector<2> Δx;
+ for (double& Δxi : Δx) {
+ Δxi = r.variate<double, std::normal_distribution>(0, ε);
+ }
+
+ m.metropolis(1, s, Δx, r);
+
+ HardSphere<2>& s1 = r.pick(m.particles);
+ HardSphere<2>& s2 = r.pick(m.particles);
+
+ m.swap(1, s1, s2, r);
+
+ if (i % (N * 3) == 0) {
+ draw(m);
+ }
+ }
+
+ return 0;
+}