Continuing with Classical Mechanics

In the previous post I discussed Professor Susskind’s Theoretical Minimum course. I’ve been continuing with the Classical Mechanics lectures and delving into alternative formulations of classical mechanics.

It has been absolutely fascinating, from the position of an undergraduate mathematician who went directly into engineering research, to study formulations of the laws other than the traditional “F=ma” approach of Newton. Progressing from the Newtonian method, through to the Principle of Least Action, then onto the Hamiltonian approach and finally through to Poisson Brackets has really filled in a substantial part of the missing pieces in my knowledge of this part of theoretical physics.

For instance, I was always confused about the importance given to commutating angular momentum operators in Quantum Mechanics. It felt extremely abstract and I was struggling to find a rationale when I studied it before. In addition, I picked up a Quantum Field Theory textbook (by Ryder) recently and tried to work my through. I was very rapidly thrust into the world of generators and continuous rotational symmetry. While I was happy working through these in a mathematical sense, I just did not have the physical insight.

Now that Poisson Brackets have provided such an insight, I feel very confident that I’ll be able to work through the Theoretical Minimum Quantum Mechanics (and ultimately QFT!) courses without too much difficulty.

Another benefit of learning these alternative approaches is that I feel like I can really attack a completely different set of (classical mechanical) problems now, that I otherwise considered extremely difficult to achieve under the Newtonian force-based approach. In that vein I have ordered some new books, which provide a large amount of interesting solved problems to work through.

One aspect that I want to clear up (and I will likely ask this in the Physics Stack Overflow portal) is whether or not the equations of motion for fluid dynamics are ever derived from an Lagrangian/Hamiltonian approach. From what I could briefly gather from the Theoretical Minimum lectures, since viscous fluids have velocity dependent forces associated with them, they cannot be derived from a Lagrangian or Hamiltonian.

I now only have two more lectures on the Classical Mechanics course to complete. These are both on applying all of the techniques learned to date to electromagnetism. No doubt the talks will as fascinating as the previous lectures have been.

The Theoretical Minimum with Leonard Susskind

I’m extremely fortunate to have come across a set of courses run by Stanford University and the renowned physicist Leonard Susskind, called The Theoretical Minimum. The core courses are a set of theoretical physics modules at an approachable undergraduate level that (eventually) help a mathematically-inclined viewer gain an understanding of the current frontiers of theoretical physics.

The courses follow a logical order of introducing Classical Mechanics (particularly the Lagrangian and Hamiltonian formations), followed by Quantum Mechanics, Special Relativity and Electrodynamics. General Relativity and Cosmology are then treated leading to a final course on Statistical Mechanics.

I can’t recommend these courses enough. Leonard Susskind is an exceptional lecturer. In equal parts humble and but also highly experienced and intuitive with the material. He doesn’t waste precious lecture time with extensive derivation, but provides resources to do so elsewhere (or encourages you to have a go!).

However, the courses are not full accounts of each topic. After all, they have been designed as the “theoretical minimum” needed to be studied prior to gaining an understanding of modern physics. Each course will require significant study outside of the lectures themselves. This is by design – it allows the student to get to grips with the main themes, even at a reasonable degree of mathematical sophistication, without being confused by extensive details.

I’m currently working through the modules on Classical Mechanics. To date I have made notes on lectures 3-6, which begin with the Principle of Least Action (really it should be Stationary Action!), then the Langrangian and Euler-Lagrange equations, symmetry and conservation laws (including Noether’s Theorem) and finally Hamiltonian Mechanics and conservation of energy.

I decided to skip lectures 1 and 2, since I was relatively familiar with the material from undergraduate mathematics. Mathematicians spend a good deal of time considering ordinary differential equations, which form a big component in Newtonian mechanics. That being said, it has been some time since I considered complex phase-space dynamics so after lecture 7 I think I will go back and watch the first two for completeness.

If you wish to gain an insight into the current state of theoretical physics then you should really consider working through the courses.

Restarting Compressible CFD with Fortran

As part of my “hobbyist” foray into Numerical Relativity (NR) I wanted to refamiliarise myself with the research I carried out at the Hypersonics Group of Imperial College as part of my doctorate. I was investigating ramjet intakes in a high supersonic/low hypersonic inviscid regime using a Generalised Riemann Problem (GRP) based Godunov Scheme Riemann Solver numerical code written in Fortran.

It didn’t take me long to realise that there was a significant hydrodynamic component to Numerical Relativity, which involved some very sophisticated computational fluid dynamics (CFD). In particular the field is known as relativistic hydrodynamics and encompasses modelling of not only compressible fluids but also those subject to magnetic field interactions at relativistic velocities. Hence we are in a relativistic compressible magnetohydrodynamic (MHD) regime with dynamically varying spacetime geometry. As you can imagine this makes the simulations rather complex.

If I am to be usefully contributing to this field in the future it is absolutely essential that I “continue where I left off” in regards to aerodynamic modelling and bridge the gap with NR. Thus I have set myself an additional goal of creating a complex CFD solver, for the particular field I was looking at, as well as gaining additional insight into the MHD regime.

In particular I have been working towards constructing a two-dimensional axisymmetric simulation of an isentropic ramjet intake with external cowl using Fortran as the implementation language and Python as the visualisation tool. The finite-volume method simulation will ultimately have the following features:

  • Utilises the latest approximate Riemann solvers in the literature, which include the aforementioned GRP and the Rotated-RHLL[1] due to Nishikawa and Kitamura.
  • Flexible triangular-element unstructured grid, useful for more general geometries.
  • Second-order accuracy via slope limiters.
  • Will be an explicit Euler simulator, rather than Navier-Stokes (i.e. viscosity) at this stage. Later implementations will introduce laminar, and ultimately turbulent, viscosity.

To this end I have been researching around the internet to see what open source code and tutorials are already available in order to save time. I actually managed to find an exceptional CFD teaching resource called CFD Books by Katate Masatsuka (which is actually a pen name!). The site has many extremely well commented Fortran 90 codes for various compressible CFD implementations using Riemann solvers.

In particular there is an example of a 2D unstructured explicit Euler solver using Roe/Rotated-RHLL approximate Riemann solvers, a Van Albada slope limiter and a two-step Runge-Kutta timestepper. The example uses a classic supersonic compressible flow test known as a shock-diffraction problem. It is a great way to learn how such CFD codes work as all of the Fortran code is clearly commented and very well written.

There is also a one-dimensional example of Sod’s test (a classic Riemann solver test case, which has an exact solution) using a Roe approximate solver, a Minmod slope limiter and a two-step Runge-Kutta timestepper. I actually spent yesterday coding up this example myself, trying to follow along the whole way in order to see if I can replicate the results. It was a very beneficial experience, since I had previously not looked at some Fortran code in earnest in approximately 5 years!

Installing a Python Scientific Stack

I thought it would also be instructive to show you how I managed to install a Python and Fortran scientific stack on my Ubuntu 14.04 Desktop machine so that you could also replicate the results.

Firstly we update and upgrade Ubuntu:

sudo apt-get update && sudo apt-get upgrade

Then we install the necessary packages for working with Python and Fortran:

sudo apt-get install build-essential git-core python2.7-dev python-dev python-pip liblapack-dev libblas-dev libatlas-base-dev gfortran libpng-dev libjpeg8-dev libfreetype6-dev libqt4-core libqt4-gui libqt4-dev libzmq-dev

This is my approach to creating a set of directories with a git repository:

mkdir -p ~/science/aerocfd/projroot
mkdir ~/science/aerocfd/data
mkdir ~/science/aerocfd/tmp
mkdir ~/science/aerocfd/test
cd ~/science/aerocfd/projroot
git init .

Then a space to store the 2D Unstructured Euler Shock Diffraction problem from CFDBooks:

cd ~/science/aerocfd/test
mkdir -p idolikecfd/2d_unstructured_euler_shock_diffraction
cd idolikecfd/2d_unstructured_euler_shock_diffraction

Then we download all of the Fortran files from CFDBooks:


This compiles the software and executes it to produce the TecPlot output files:

source readme

The following is only necessary if you want to visualise the output using a Python (open source) stack, rather than using the commercial TecPlot product. This creates a Python virtual environment (“virtualenv”):

mkdir -p ~/science/venv/aerocfd
source ~/science/venv/aerocfd/bin/activate

This installs all of the necessary scientific packages for Python:

pip install numpy
pip install scipy
pip install matplotlib
pip install ipython
pip install pandas

I then wrote the following script to plot the output of the 2D Euler shock diffraction problem:

import matplotlib
from matplotlib.mlab import griddata
import matplotlib.pyplot as plt

import numpy as np
import pandas as pd
import as ma
from numpy.random import uniform

if __name__ == "__main__":
    filename = "idolikecfd/2d_unstructured_euler_shock_diffraction/test_results.dat"    
    data =, delimiter="\t", 
                                  header=None, names=["x","y","rho","u","v","p","M"], 

    x = np.array(data["x"])
    y = np.array(data["y"])
    z = np.array(data["rho"])
    xi = np.linspace(0.0,1.0,500)
    yi = np.linspace(0.0,1.0,500)
    zi = griddata(x,y,z,xi,yi)
    CS = plt.contour(xi,yi,zi,50,linewidths=0.5,colors='k')
    plt.title('Density Plot')

This is the output from the Python plotter, which I think compares relatively favourably to TecPlot:

2D Euler shock diffraction

You can clearly see the expansion fan forming at the “corner” of the shock diffraction input tube (middle left on the image) and the associated circular shock wave forming into the region.

In the next set of articles I hope to try and construct a 1D relativistic Riemann solver problem, although I’ll have to brush up on my references first!


  • [1] – Nishikawa, H.; Kitamura, K. (2008), “Very simple, carbuncle-free, boundary-layer-resolving, rotated-hybrid Riemann solvers”, J. Comput. Phys. 227 (4): 2560–2581

Restarting General Relativity

In order to fully clarify exactly which topics I would need in order to get started in Numerical Relativity I decided to try and work through the second chapter of Numerical Relativity again. It became clear that I was rather rusty on my Riemannian manifold vector and tensor calculus.

In particular the derivation of the ADM formalism relies on a solid grasp of the Riemann curvature tensor $R^{a}_{bcd}$ and associated contractions to the Ricci tensor $R_{ab}$ and scalar curvature $R$. This of course requires a deep understanding of the affine connection $\Gamma^{b}_{ac}$ and properties of the metric tensor $g_{ab}$.

Vector and Tensor Calculus on Riemannian Manifolds

In order to make any progress I was going to have to re-learn vector and tensor calculus on Riemannian manifolds. Thankfully the text General Relativity by Hobson et al has the necessary background in Chapters 3 and 4.

Hence I have spent the entirety of today working through Chapter 3. I have to admit it has been an extremely enjoyable experience! The book really does explain things well. There are occasional sections where I feel a derivation has jumped a step or two ahead, but “mathematics is not a spectator sport”, and I derived things myself as I needed to.

So what topics were actually studied? Here’s a list of the concepts I looked at today:

  • Tangent spaces on (pseudo)-Riemannian manifolds
  • Contravariant and covariant representations of tangent space basis vectors
  • Dual bases of tangent space bases
  • Relationships between the metric tensor and tangent space basis
  • Using the metric tensor for raising and lowering of indices
  • Coordinate transformations for tangent space bases and general vectors
  • Derivatives of basis vectors, the affine connection and transformation properties
  • Torsion of a manifold as defined in terms of affine connections
  • Metric connection formula: $\Gamma^{a}_{bc} = \frac{1}{2}g^{ad}\left(\partial_b g_{dc} + \partial_c g_{bd} – \partial_d g_{bc}\right)$
  • Raising and lowering indices of affine connections (“Christoffel symbols of the first kind”)
  • Covariant derivative of vectors
  • Gradient, Divergence, Curl and Laplacian in (pseudo-)Riemannian manifolds
  • Intrinsic derivative of a vector along a curve
  • Parallel transport
  • Null curves, non-null curves and geodesics

I’ve not quite reached the end of Chapter 3 but I’m nearly there. There are three rather large appendices (useful, by the look of it) and then a lot of questions, which I’m eager to try. One really must practice using the Einstein summation notation as well as gain extensive familiarity with contra- and co-variant indices before continuing, since the notation is so pervasive in GR.

While I don’t yet feel confident enough to re-try Chapter 2 of Numerical Relativity, I’m certainly getting there. I believe I need to really understand the tensor calculus in Chapter 4 of General Relativity, plus the chapters on the Riemann curvature tensor before having another crack at the ADM formalism.

Numerical Relativity on the GPU

Since I currently possess a workstation with a Nvidia GPU supporting the CUDA GPGPU language I wanted to find out if there had been any research into porting numerical relativity codes onto a GPU. It turns out that there has been some work done in the area.

I found a paper on Arxiv here (PDF), which discussed utilising the OpenCL standard for GPU implementation in a numerical relativity regime. Thus I’m looking forward to trying out an implementation as and when I start to understand the NR material!

What’s Next?

The next main task is to finish Chapter 3 of General Relativity, including the appendices and working through all of the questions. Having looked at some of the questions briefly, I feel I am “getting into the mindset” of GR. Then it will be on to Chapter 4 to extend the vector calculus into the general tensor regime.

This will likely be a lot trickier as there is less geometric intuition to rely on. For instance, a lot of GR concepts can be considered on a two-dimensional curved embedded manifold in a higher dimensional (three-dimensional) space. In the tensor regime it becomes harder to visualise and thus more emphasis on the rules must be considered.

I’m also considering purchasing General Relativity by Wald as it seems to be referenced so frequently within the Numerical Relativity text. However, it is a definite “step up” from Hobson et al, so I’ll only work through it once I’m happy with the majority of the material in the latter text.

Beginning Classical Mechanics

In the previous entry in the NR diary I mentioned that among other topics I wanted to start re-learning classical mechanics. In particular the Lagrangian and Hamiltonian formulation, which forms the basis of the derivation of the ADM formalism required in NR.

Having previously tried this a couple of years ago I was able to obtain Classical Mechanics by Kibble and Berkshire, which seems to be the recommended text for undergraduate classical mechanics courses.

Beginning “Classical Mechanics”

Having spent the last week reading a lot of advice regarding how to study physics (as well as drawing on my experience learning mathematics) I’ve decided that the best way to learn the material is to be constantly deriving and “playing” with the equations, as well as attempting as many exercises as possible. One of my lecturers at Warwick always used to say that “mathematics is not a spectator sport”. I’ll certainly be applying similar sentiment to physics self-study.

The first chapter I considered was Chapter 2 on Linear Motion. The starting point was one dimensional motion and conservative forces. Along the way I considered second order linear ordinary differential equations, which I have a reasonable experience with from undergraduate maths and postgraduate fluid dynamics. In addition the conservation of energy was discussed in the form of $E=T+V$.

Simple Harmonic Motion was then derived in the approximate case ($m \ddot x + kx = 0$) and then a representation using complex numbers was outlined. A particularly interesting example considered the force between two charged particles, as it started introducing coefficients that I recalled from A-Level Physics. More electromagnetism study is clearly needed!

The next set of topics mainly concerns second order ODE effects, such as damping, resonance, general periodic forces and then some linear collisions. Then there is an extensive set of questions, which I plan to carry out.

Additional Resources

There are some worthwhile free resources for (advanced) classical physics available on the web. If you’re interested primarily in the Lagrangian or Hamiltonian formulation of classical physics then you can have a look at the following resources: