# Difference between revisions of "A Symplectic Integrator"

## Introduction

On Orbiter Forum, orbinaut Keithth G has described some of his results comparing the Orbiter Space Flight Simulator numerical integrator with one of his own. In response to a user question, he provided the following description of the principles underlying a symplectic numeric integrator.

## A second-order symplectic integrator

First, let's focus on a basic second-order symplectic integrator. It is worthwhile spending a little time on this because, so long as the time-step of the integration is small enough, it actually works pretty well. It is also an integrator from which it is possible to build higher-order syplectic integrators.

### A couple of introductory points:

• The integrator is called 'symplectic' because (up to second order at least) it preserves the symplectic character of the physical system. This means that the long-run properties of the integrator tend to be much more stable than other kinds of integrators and, largely because of this, they have become very popular amongst physicists in the last couple of decades.
• The integrator is second-order because it has been constructed so as to 'kill' error terms up to the second-order only.

So, what is this integrator? If we just focus on a one-dimensional system for a moment, then the integrator maps a pair of points ${\displaystyle \left\{Q_{0},P_{0}\right\}}$ to a new pair of points ${\displaystyle \left\{Q_{2},P_{2}\right\}}$ at a time ${\displaystyle \delta t}$ later. We can think of this as taking a pair of numbers, ${\displaystyle \left\{Q_{0},P_{0}\right\}}$, that describe the state of some object at some start time ${\displaystyle t=t_{0}}$ and updating this to a new pair of numbers, ${\displaystyle \left\{Q_{2},P_{2}\right\}}$, that describes the new state of the same object at time ${\displaystyle t=t_{0}+\delta t}$.

There are three steps to this updating rule:

${\displaystyle Q_{1}\leftarrow Q_{0}+{\frac {1}{2}}\,\delta t\,P_{0}}$

${\displaystyle P_{2}\leftarrow P_{0}+\delta t\,F\left(Q_{1}\right)}$

${\displaystyle Q_{2}\leftarrow Q_{1}+{\frac {1}{2}}\,\delta t\,P_{2}}$

OK, so what do all of these symbols mean? Let's start with 'Q' and 'P'. In physics, largely because of a longstanding convention in nomenclature, 'Q' is often used to denote a spatial coordinate of something. Here, in our one-dimensional example, you can think of 'Q' as representing the x-coordinate of some object moving in some gravitational field. In the same convention, 'P' is used to denote the momentum of the same object. (Formally, it is the generalised momentum conjugate to 'Q' but that's a nuance that we don't need to worry about here.). Here, we can think of 'P' as representing the x-coordinate of the momentum of a particle. But since momentum is just mass * velocity (in this coordinate system), we can think of 'P' as the x-coordinate of velocity (multiplied by the mass of the object). So, the pair of numbers ${\displaystyle \left\{Q_{0},P_{0}\right\}}$ just represents the position and velocity of the object at some initial time. And this is just the state-vector of the object written in cartesian coordinates. In other words, the symplectic integrator is an updating rule that takes an object's state vector at some initial time, and returns a new state vector at some time ${\displaystyle \delta t}$ later. (Now, you can extend this idea to three dimensions but for the time being we'll just stick with one-dimension.)

Next, let's focus on the 'F' term. Again by convention, 'F' is used to denote the force acting on an object. Specifically, ${\displaystyle F\left(Q_{1}\right)}$ represents the force on the object being modelled when it is at position ${\displaystyle Q_{1}}$. So, to carry out the three steps of the integration updating rule, we need to provide some force function, ${\displaystyle F(Q)}$ which allows us to calculate the force on an object at a point in our one-dimensional space (i.e., at any 'Q'). For object moving subject to a gravitational force from a single body, we know that:

${\displaystyle F(Q)=-{\frac {\mu \,m}{(Q-Q^{*})^{2}}}}$

(provided that ${\displaystyle Q>Q^{*}}$)

where ${\displaystyle \mu }$ is the gravitational constant for the body in question; 'm' is the mass of the object that we are modelling, and ${\displaystyle Q^{*}}$ is the location of the source of the gravitational field (e.g., the centre of the Sun or the Earth). If we work in Gaussian units where we measure distances in AU (Astronomical Units); velocity in AU/day; and mass in units of the mass of the Sun, then for an object moving in the gravitational potential of the Sun, ${\displaystyle \mu =0.00029591220828559115}$ and ${\displaystyle m=1}$. For an object moving in the gravitational field of the Earth, ${\displaystyle m=1/354710}$. To convert from AU and days to metres and seconds, one needs to know that 1 AU = 149597870700 metres; and that 1 day = 86400 seconds. Unless the mass of the object that we are modelling is changing, it is convenient to set ${\displaystyle m=1}$.

In this one-dimensional system, the object moving in a gravitational potential is a bit limited in terms of directional options. It can either go up, or it can go down. Clearly, as the object moves towards the location of the gravitational source, the force acting on the object is going to increase without limit and the integration is going to going hay-wire, but so long as we are a reasonable distance away from ${\displaystyle Q^{*}}$ then the integration scheme given above will provide a reasonable description of the object's motion.

### In three dimensions

In three dimensions, the integration scheme looks much the same. But now we have to apply it to three spatial coordinates and three velocity components - i.e., the integration scheme becomes one that updates one set of 6 numbers ${\displaystyle \left\{Q_{x,0},Q_{y,0},Q_{z,0},P_{x,0},P_{y,0},P_{z,0}\right\}}$ to a new set of six numbers ${\displaystyle \left\{Q_{x,2},Q_{y,2},Q_{z,2},P_{x,2},P_{y,2},P_{z,2}\right\}}$. And the second order integration scheme that does this is as follows:

${\displaystyle Q_{x,1}\leftarrow Q_{x,0}+{\frac {1}{2}}\,\delta t\,P_{x,0}}$

${\displaystyle Q_{y,1}\leftarrow Q_{y,0}+{\frac {1}{2}}\,\delta t\,P_{y,0}}$

${\displaystyle Q_{z,1}\leftarrow Q_{z,0}+{\frac {1}{2}}\,\delta t\,P_{z,0}}$

${\displaystyle P_{x,2}\leftarrow P_{x,0}+\delta t\,F_{x}\left(Q_{x,1},Q_{y,1},Q_{z,1}\right)}$

${\displaystyle P_{y,2}\leftarrow P_{y,0}+\delta t\,F_{y}\left(Q_{x,1},Q_{y,1},Q_{z,1}\right)}$

${\displaystyle P_{z,2}\leftarrow P_{z,0}+\delta t\,F_{z}\left(Q_{x,1},Q_{y,1},Q_{z,1}\right)}$

${\displaystyle Q_{x,2}\leftarrow Q_{x,1}+{\frac {1}{2}}\,\delta t\,P_{x,2}}$

${\displaystyle Q_{y,2}\leftarrow Q_{y,1}+{\frac {1}{2}}\,\delta t\,P_{y,2}}$

${\displaystyle Q_{z,2}\leftarrow Q_{z,1}+{\frac {1}{2}}\,\delta t\,P_{z,2}}$

Each step of the integrator is the same - except now we apply it three times - once for each spatial coordinate.

You should note that we now have three force functions rather than just one. This is because force is really a 'vector' rather than 'scalar' quantity. ${\displaystyle F_{x}\left(Q_{x},Q_{y},Q_{z}\right)}$ is the force acting in the x-direction on the object located at position ${\displaystyle {Q_{x},Q_{y},Q_{z}}}$; ${\displaystyle F_{y}\left(Q_{x},Q_{y},Q_{z}\right)}$ is the force acting in the y-direction on the object located at position ${\displaystyle {Q_{x},Q_{y},Q_{z}}}$; and ${\displaystyle F_{z}\left(Q_{x},Q_{y},Q_{z}\right)}$ is the force in the x-direction acting on the object located at position ${\displaystyle {Q_{x},Q_{y},Q_{z}}}$. And if we are in the gravitational field of a single body, then these functions become:

${\displaystyle F_{x}\left(Q_{x},Q_{y},Q_{z}\right)=-{\frac {\mu \,m\,\left(Q_{x}-Q_{x}^{*}\right)}{\left(\left(Q_{x}-Q_{x}^{*}\right)^{2}+\left(Q_{y}-Q_{y}^{*}\right)^{2}+\left(Q_{z}-Q_{z}^{*}\right)^{2}\right)^{3/2}}}}$

${\displaystyle F_{y}\left(Q_{x},Q_{y},Q_{z}\right)=-{\frac {\mu \,m\,\left(Q_{y}-Q_{y}^{*}\right)}{\left(\left(Q_{x}-Q_{x}^{*}\right)^{2}+\left(Q_{y}-Q_{y}^{*}\right)^{2}+\left(Q_{z}-Q_{z}^{*}\right)^{2}\right)^{3/2}}}}$

${\displaystyle F_{z}\left(Q_{x},Q_{y},Q_{z}\right)=-{\frac {\mu \,m\,\left(Q_{z}-Q_{z}^{*}\right)}{\left(\left(Q_{x}-Q_{x}^{*}\right)^{2}+\left(Q_{y}-Q_{y}^{*}\right)^{2}+\left(Q_{z}-Q_{z}^{*}\right)^{2}\right)^{3/2}}}}$

where ${\displaystyle \left(Q_{x}^{*},Q_{y}^{*},Q_{z}^{*}\right)}$ are the coordinates of the gravitating body (when the object whose motion you are modelling is at ${\displaystyle \left(Q_{x},Q_{y},Q_{z}\right)}$)

And that's about all there is to this this second-order symplectic integrator. To integrate, one chooses a suitable small step-size (so that the overall errors are as small as some tolerance that you require for your calculations); one specifies the initial conditions of the object - its position and velocity - and then one repeatedly applies the integration step for as long as you wish.

Now, for those interested, it is worthwhile setting up this integrator in, say, a spreadsheet and seeing how it performs under various sizes of time-steps. and initial conditions. Of course, if there is more than one gravitating body, then you have additional terms in the force functions, but the basic scheme of the updating rule remains the same.

As a sequel to this post, I will sketch how you can quickly build fourth and sixth order symplectic integrators from this simple second-order integrator.

And as a sequel to that I will talk about the distinction between 'implicit' and 'explicit' integrators.

## Precis

This article has a precis and appears in the Random addon or Random article section on the Main Page. The precis can be found at A Symplectic Integrator/precis and is displayed below.

 A Symplectic Integrator. An explanation of how to set up a certain type of numeric integrator, a key aspect of celestial mechanics calculations, such as those performed by Orbiter Space Flight Simulator. (More...)