I am trying to learn about basics of computational fluid dynamics, at the moment on the simple example of linear advection in 1D. I am am currently testing the theoretical predictions of the order of accuracy of different methods, and the results that I am finding are not what I would expect them to be, and I don't understand why.
First point would be testing how the order of accuracy behaves with decreasing cell width dx
. For piecewise constant upwind differencing advection in 1D, i.e. advecting a quantity $q$ with constant positive velocity $u$, the equation is
$$ q^{n+1}_i = q^n_i + \frac{u \Delta t}{\Delta x} \left( q_{i-1} - q_i \right) $$
This method is, on paper, of order $\mathcal{O}(\Delta x)$. (e.g. section 3.6 of these lecture notes).
However, going from a piecewise constant to a piecewise linear reconstruction should give us a second order accurate method in space. On a smooth initial condition, this should hold even when slope limiters are employed, which reduce the order of accuracy in regions of non-monotone states to first order.
So I tested the accuracy on a smooth Gaussian profile in a periodic "box" of size 1:
dx = 1./nx
for i in range(nx):
x = (i+0.5)*dx
rho[i] = 1 + 2 * np.exp(-((x-0.5)**2/0.05))
and then run the simulation up to $t = 1$ with $u = 1$, such that the analytical solution should be exactly the initial conditions again.
To remove any time dependence, I enforced a small constant time step for all choices of dx
, such that every choice of dx
needs to do exactly the same number of steps to get to $t = 1$.
Then I plotted the $L1$ norm of the results compared to the initial conditions vs dx
, and fitted a line to compute the slope of the plot.
About this plot, I have two things that I don't understand fully:
Question 1: for piecewise constant advection, I expect a slope of $1$, but get $\approx 1.5$. Why is that? My understanding is that the order of accuracy estimation gives you the minimal order of accuracy, but in certain cases, it can be higher. Is that correct?
Question 2: for piecewise linear advection, specifically when using no slope limiter, the monotonized centered limiter (MC), and the van Leer limiter, the curve isn't linear any more, but plateaus for small dx
. Why is that?
Secondly, I wanted to measure the order of accuracy of the time variable. I expect all the methods mentioned earlier to be $\mathcal{O}(\Delta t)$.
Also, following this answer, I expect the introduced error $$ Err = \frac{c\Delta x}{2}\frac{\partial^2 u}{\partial x^2}(1-C_{cfl}) \propto -C_{cfl} $$
i.e. to be $\mathcal{O}(C_{cfl})$, where $C_{cfl} \leq 1$ is the user-set Courant number.
So I ran the same initial conditions for a fixed dx
up to $t = 1$ again with different Courant numbers, expecting to get a slope $\approx 1$. However, the resulting curves show a line often closer to slope $0$:
In fact, it gets even worse if instead of a Gaussian profile I use a step function as initial conditions:
dx = 1./nx
for i in range(nx):
center = (i+0.5)*dx
if center > 1./3 and center < 2./3:
rho[i] = 2
else:
rho[i] = 1
Then all lines are closer to slope $0$ than $1$:
This leads to another two questions for me:
Question 3: Why aren't the slopes close to $1$?
Question 4: Why does the initial condition change the accuracy of the $C_{cfl}$ dependence so drastically? Compare for example the piecewise linear advection without a slope limiter between the Gaussian profile and the step functoin. The slope drops from $\approx 0.9$ to $\approx 0.15$.
Edit: corrected equation