# Timestep and Cost Analysis of Pressure- and Density-Based Methods

Jupyter Notebook here: https://git.io/fjRjL

For an explicit compressible algorithm the maximum timestep one can take is dictated by both the advective and acoustic speeds in the flow.
This is given by the famous CFL condition

V \frac{\delta t}{\Delta x} \leq 1

where $V$ is the maximum speed in the flow. In this case,

V = u + c

where $u$ is the advective speed and $c$ is the speed of sound.
One can turn this into useful quantities in terms of the Mach number, $M=\frac{u}{c}$.

### Number of Timesteps

One such useful quantity is the number of timesteps required to advect a fluid front a single grid point, $\Delta x$.
In a single timestep, $\delta t$, the fluid moves (by advection) by a distance $\delta x = u \delta t$.
Assume it takes $n$ timesteps of size $\delta t$ to move a distance equal to the grid spacing $\Delta x$.
In other words, let $\Delta t = n \delta t$ such that $\Delta x = u \Delta t$.
Now

\Delta t = n\delta t = n \frac{\Delta x}{V}

or

n = V \frac{\Delta t}{\Delta x} = (u+c)\frac{\Delta t}{\Delta x}

now divide by the speed of sound, $c$

n = (M+1)\frac{c\Delta t}{\Delta x}

but, recall that the fluid front moves at the advective velocity $u$ such that $\Delta x = u \Delta t$, this means

\label{eq:ndt}
n = (M+1)\frac{c}{u} = \frac{M+1}{M} = 1 + \frac{1}{M}

### Courant Number

Another useful quantity is the (advective) Courant number ($\text{Cr} = u\frac{\delta t}{\Delta x}$) as a function of the Mach number. This one is easy. Starting with

\delta t = \frac{\Delta x}{V} = \frac{\Delta x}{u+c}

multiply both sides by $\frac{u}{\Delta x}$

\frac{u}{\Delta x}\delta t = \frac{u}{\Delta x} \frac{\Delta x}{u+c}

or

\text{Cr} = \frac{u}{u+c} = \frac{M}{M+1}
\label{eq:courant}

### Preconditioning

To alleviate this strict limitation on the timestep size, several techniques have been introduced to manipulate the speed of sound in the governing equations without modifying much of the dynamics. One popular approach is the ASR method. The technique results in effectively scaling the speed of sound by a factor, $\alpha$, such that

c \to \frac{c}{\alpha}; \quad \alpha > 1

This means that the Mach number gets amplified by a factor $\alpha$, i.e. $M\to\alpha M$.
This changes \eqref{ndt} to

\label{eq:nsteps-precon}
n =\frac{\alpha M + 1}{\alpha M}= 1 + \frac{1}{\alpha M}

and \eqref{courant} to

\label{eq:courant-precon}
\text{Cr} = \frac{\alpha M}{\alpha M+1}

### Cost Analysis

The plots in Figure (\ref{fig:test}) compare pressure-based to conditioned and unconditioned density-based methods. But they do not compare cost. The real question is: what if the cost of a single pressure-based timestep is 10 times that of an ASR-100 timestep? Where is the break-even Mach number? Here, the break-even Mach number is defined as the Mach number below which pressure-based methods cost less in terms of time-to-solution and above which density-based methods cost less (in terms of time-to solution).
We can cleverly estimate this cost as follows.
Define the cost ratio, $r$ as the ratio of the cost per timestep of a pressure-based method to that of a density-based method,

r = \frac{\text{cost per timestep of pressure-based}}{\text{cost per timestep of density-based}} = \frac{p\text{-cost}}{\rho\text{-cost}}

Now, for a density based method, it takes $n$ steps to move a fluid front by one grid point. The cost for that operation is

\rho\text{-cost}\times n = \rho\text{-cost}\times\frac{\alpha M + 1}{\alpha M}

For a pressure based method, by definition, it takes a single timestep to move a fluid front by a single grid point. This operation costs $p\text{-cost}$.
The breakeven Mach number is when those two are equal, i.e.

\rho\text{-cost}\times n = p\text{-cost}

or, dividing by $\rho\text{-cost}$ and substituting for the value of $n$, we have

\frac{\alpha M_\text{breakeven} + 1}{\alpha M_\text{breakeven}} = r

or

M_\text{breakeven} = \frac{1}{\alpha (r-1)}