For today’s recreational coding exercise, we simulate **active matter**, i.e., swarming. Such a system may describe a flock of birds or a school of fish. We will look at how very simple rules may lead to the emergence of self-ordered motions.

You may find the accompanying Python code on github.

But first, below is a gif of what running our simulation looks like:

We will describe a famous minimal model for active matter called the Viscek model (1995). Despite its simplicity, the model is able to describe universal properties of swarming behavior.

The model consists of *N* moving particles, indexed by *i=1,…,N*. Each particle has an angle *Θ*** ᵢ **representing the direction in which it moves. All particles move with the same speed

For today’s recreational coding exercise, we simulate fluid flow past a cylinder using the Lattice Boltzmann method. This is a really cool and really simple technique to simulate fluid flow: instead of evolving the fluid (Navier-Stokes) equations directly, microscopic particles on a lattice are simulated with streaming and collision processes. The power of the method comes from reducing the high-dimensionality of the microscopic physics onto the lattice, which has limited degrees of freedom. It is remarkable that this restricted microscopic representation is able to capture macroscopic fluid behavior.

You may find the accompanying Python code on github.

But first, below is a gif of what running our simulation looks…

For today’s recreational coding exercise, we look at a simple way to create volume renderings to visualize 3D simulation datacubes. This technique is incredibly useful when you have space-filling data you would like to visualize. Such data shows up often in astrophysical datasets but also in other areas of computer graphics and medical data (CT scans and MRIs).

You may find the accompanying Python code on github.

Before diving in, below is a gif of what running the rendering algorithm on some data may look like:

We assume that the data is an *Nx* × *Ny* × *Nz* datacube of a density that we would like to visualize. …

For today’s recreational coding exercise, we will look at **quantum mechanical systems**, in particular, the *Schrodinger-Poisson* equations. We will create a simulation for the evolution of a wavefunction under its self-potential. Such a system may describe certain superfluids/Bose-Einstein condensate or exotic dark matter.

You may find the accompanying Python code on github.

Before diving in, below is a gif of what running our simulation looks like:

We will consider the evolution of the wavefunction *ψ(**x**)* under the Schrodinger equation:

For today’s recreational coding exercise, we will simulate the **Kelvin-Helmholtz Instability **with the Finite Volume method. We will consider a compressible fluid with a high density stream moving in opposite direction of the background. The velocity shear induces a famous instability that is seen sometimes in clouds as well as Jupiter’s Great Red Spot.

You may find the accompanying Python code on github.

Before we begin, below is a gif of what running our simulation looks like:

We will describe the finite volume method to simulate an ideal compressible fluid. Extensions of the method exist for the simulation of other types of fluids. An ideal compressible fluid is described by the **Euler fluid equations**. For purposes of this discussion, let us consider the system in 2D (it is not too difficult to extend what is presented here to 3D). …

For today’s recreational coding exercise, we will simulate a **star** with smoothed-particle hydrodynamics (SPH). We will start with some initial condition and relax it into a stable stellar structure and measure the star’s density as a function of radius. The SPH method has many applications in astrophysics and elsewhere, and is in fact a general one to simulate all types of fluids.

You may find the accompanying Python code on github.

Before we begin, below is a gif of what running our simulation looks like:

We will represent the fluid as a collection of *N* point particles, indexed by *i=1,…,N*. …

For today’s recreational coding exercise, we will investigate **plasma physics** with particle-in-cell (PIC) simulations. We will create a simulation of two electron beams passing through each other in opposite directions. An interesting phenomenon occurs, called the Two-Stream Instability.

You may find the accompanying Python code on github.

Before we begin, below is a gif of what running our simulation looks like:

We will consider a one-dimensional system of electrons in an unmagnetized uniform medium of ions. The electrons will be described by N particles, indexed by *i*, each having a

- position
*rᵢ* - velocity
*vᵢ*

The electrons feel an acceleration *aᵢ *which is due to the electric field *E* at the location of the particle*.* The equations of motion for the electrons are given…

For today’s recreational coding exercise, we will look at the **gravitational N-body problem**. We will create a simulation of a dynamical system of particles interacting with each other gravitationally. Such a system may describe the orbits of planets in the Solar System or stars in our Galaxy.

You may find the accompanying Python code on github. (And if you prefer to use Matlab, please see my Matlab version of the article)

But first, below is a gif of what running our simulation looks like:

We will assume a system of *N* point particles, indexed by *i=1,…,N*. Each particle has a:

- mass…

For today’s recreational coding exercise, we will look at the **gravitational N-body problem**. We will create a simulation of a dynamical system of particles interacting with each other gravitationally. Such a system may describe the orbits of planets in the Solar System or stars in our Galaxy.

You may find the accompanying Matlab code on github. (And if you prefer to use Python, please see my Python version of the article)

But first, below is a gif of what running our simulation looks like:

We will assume a system of *N* point particles, indexed by *i=1,…,N*. Each particle has a:

- mass…

About