## Working with percolation clusters in Python

We’re working on a new project in FYS4460 about percolation. In the introduction of this project, we are given a few commands to help us demonstrate a few properties of percolation clusters using MATLAB.

As the Python-fan I am, I of course had to see if I could find equivalent commands in Python, and thankfully that was quite easy. Below I will summarize the commands that will generate a random matrix of filled and unfilled areas, label each cluster in this matrix and calculate the area of each such cluster. Finally, we’ll draw a bounding box around the largest cluster.

## Optimizing your C++ code for molecular dynamics

While working with the molecular dynamics project in FYS4460 I decided to learn more about how to optimize my C++ code for performance. As always, I follow Donald Knuth’s famous quote as a guideline to optimization:

“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil”[2]

And this has proved to be as true as ever in my efforts to optimize my code. There are a bunch of things that I have tried that didn’t turn out to be as effective as I had thought, and some other that I would never think could be so important. I’ve listed most of these in this post so you too may learn from my experience. They are all listed in the order from most useful to most wasteful:

Ovito is a great tool to visualize atoms from molecular dynamics simulations and to perform some statistical analysis on the data. The tool is an alternative to other similar tools such as VMD and ParaView.

The current version of Ovito in the Ubuntu repositories (version 0.9.2) is sadly very outdated. Even though you of course may download the latest version from Ovito’s webpages and install it locally in your home folder, I often find it better to get a newer package version.

At the Computational Physics group’s PPA I have now uploaded the latest build of Ovito for Ubuntu in a package that will automatically replace the current Ovito version. Note that this is not a release version of Ovito, but the latest version fetched from Ovito’s sources (currently nicknamed 1.1.1.90). The reason is that Ovito’s creator, Alexander Stukowski, was kind enough to implement a suggestion we proposed to change the default input handler for the viewports to be the orbit input handler. This behavior feels so much more natural and makes the already great Ovito application even better.

To install the latest version of Ovito, all you need to do is to open up a terminal and type these lines:

sudo apt-add-repository ppa:comp-phys/stable
sudo apt-get install ovito

Note that the Computational Physics repository also contains newer versions of the Armadillo package, which will automatically be updated if you do not remove the repository after installing Ovito.

## Classical mechanics in HTML5 and Javascript

Ok, so we’re working on the home exam in classical mechanics and I decided to spend some time simulating the solution of the first exercise. Probably not the wisest way to spend time during an home exam, but what the heck. I’m learning some Javascript and HTML5, plus the fact that it’s always fun to verify results by looking at something moving!

So here you go. A pendulum on a cart.

I won’t go into details about deriving and solving the Lagrange equation for this system now, but I might get back to that at a later time. And of course there will be some added controls to this so you could set the initial positions, velocities and stuff. Sometime later, I hope.