A blog of Python-related topics and code.

The harmonic oscillator wavefunctions

The harmonic oscillator is often used as an approximate model for the behaviour of some quantum systems, for example the vibrations of a diatomic molecule. The Schrödinger equation for a particle of mass $m$ moving in one dimension in a potential $V(x) = \frac{1}{2}kx^2$ is $$ -\frac{\hbar^2}{2m}\frac{\mathrm{d}^2\psi}{\mathrm{d}x^2} + \frac{1}{2}kx^2\psi = E\psi. $$ With the change of variable, $q = (mk/\hbar^2)^{1/4}x$, this equation becomes $$ -\frac{1}{2}\frac{\mathrm{d}^2\psi}{\mathrm{d}q^2} + \frac{1}{2}q^2\psi = \frac{E}{\hbar\omega}\psi, $$ where $\omega = \sqrt{k/m}$. This differential equation has an exact solution in terms of a quantum number $v=0,1,2,\cdots$: $$ \psi(q) = N_vH_v(q)\exp(-q^2/2), $$ where $N_v = (\sqrt{\pi}2^vv! )^{-1/2}$ is a normalization constant and $H_v(q)$ is the Hermite polynomial of order $v$, defined by: $$ H_v(q) = (-1)^ve^{q^2}\frac{\mathrm{d}^v}{\mathrm{d}q^v}\left(e^{-q^2}\right). $$ The Hermite polynomials obey a useful recursion formula: $$ H_{n+1}(q) = 2qH_n(q) - 2nH_{n-1}(q), $$ so given the first two: $H_0 = 1$ and $H_1 = 2q$, we can calculate all the others.

Simulating two-dimensional polycrystals

The following code simulates (very approximately) the growth of a polycrystal from a number of seeds. Atoms are added to the crystal lattice of each of the resulting grains until no more will fit, creating realistic-looking boundaries where two grains meet.

Breeding tritium for a fusion reactor

The most feasible nuclear reaction for a "first-generation" fusion reaction is the one involving deuterium (D) and tritium (T): $$ \mathrm{D} + \mathrm{T} \rightarrow \alpha (3.5\;\mathrm{MeV}) + n (14.1\;\mathrm{MeV}) $$ Tritium is not a primary fuel and does not exist in significant quantities naturally since it decays with a half life of 12.3 years. It therefore has to be "bred" from a separate nuclear reaction. Most fusion reactor design concepts employ a lithium "blanket" surrounding the reaction vessel which absorbs the energetic fusion neutrons to produce tritium in such a reaction.

Wa-Tor World on a torus

The population dynamics simulation known as Wa-Tor was described in a previous post. When carried out on a grid with periodic boundary conditions, the Wa-Tor "universe" is topologically equivalent to a torus, as depicted below using the code provided here.

Diffusion on the surface of a torus

An example in Chapter 7 of the scipython book describes the numerical solution of the two-dimensional heat equation for a flat plate with edges held at a fixed temperature.