Hard-Disk Monte Carlo

2D Monte Carlo Simulation in Javascript

Background Theory

\begin{equation} \langle X\rangle = \dfrac{\int\text{d}q^{N}\exp\big[-\beta\mathcal{V}(q^{N})\big]X(q^{N})}{\int\text{d}q^{N}~\exp\big[-\beta\mathcal{V}(q^{N})\big]} \end{equation}

Metropolis Criterion

This can be alternatively written down as: \begin{equation} \text{acc}(o\rightarrow n)=\min\bigg(1,\exp\bigg[-\beta\big(\mathcal{V}(n)-\mathcal{V}(o)\big)\bigg]\bigg) \end{equation}

The Code

We want to build a Monte Carlo package in javascript using object-oriented programming

Setting up the System

class System {
  // set initial system parameters
  constructor(){
    this.npart     = 100; // number of particles in the system
    this.density   = 0.4; // density of the system
    this.area      = (this.npart*20**2)/this.density; // area of the simulation box
    this.box_x     = Math.sqrt(this.area); // length of the box along the x-axis
    this.box_y     = this.box_x; // length of the box along the y-axis
    this.particles = []; // list of particles in the system
  }
}

Final Result

Andreas Neophytou
Andreas Neophytou
Postdoctoral Researcher

My research interests are generally in the realm of understanding programmable matter. Get in touch if there’s anything you see here that interests you or you want to share something interesting with me.