Numerical solutions are wrong until proven to be correct
The best way to prove that numerical results are correct is by reproducing problems for which there is an analytical solution - demonstrating that the method matches the exact solution
Interpolation
Filling in the gaps between discrete data points
Allows integration and differentiation of data
Lagrange polynomials
Curves of arbitrary order that pass through all data points
Splines
Curves that meet at the same value and have the same first and second derivatives at the joining points
Least squares
Fitting a lower order polynomial to noisy data by minimising the mean square error
Numerical integration
1. Fit a curve to the data
2. Integrate the area under the curve
Trapezoidal rule
Numerical integration using straight lines between data points
Simpson's rule
Numerical integration using quadratic Lagrangian polynomials fit to groups of 3 points
Different computational operations take different amounts of time, with additions/subtractions/multiplications being very fast, divisions being slower, and more complex functions being even slower
Order of accuracy
Tells you how quickly the numerical solution approaches the exact solution as the sample spacing ∆x decreases
The order of accuracy of a numerical method does not change with the order of the derivative
Second order accurate scheme
Error is proportional to ∆x^2
First order accurate scheme
Error is proportional to ∆x^1
As the grid spacing is halved, the error in a second order scheme decreases by a factor of 4, while in a first order scheme it decreases by a factor of 2
Stability
A numerical scheme must be stable, otherwise errors will grow exponentially and the simulation will crash
Consistency
As the grid spacing tends to zero, the approximation will become exact
Verification
Ensuring the numerical method is derived and implemented correctly
Validation
Checking if the governing equation is the correct choice to model the actual physics of the problem
Error norms (L1, L2, L∞)
Used to quantify the errors between the numerical solution and the exact solution
Computing the observed order of accuracy
1. Calculate the error norms for multiple grid sizes
2. Plot the error norms against the grid spacing on a log-log plot
3. The slope of the line is the observed order of accuracy
For problems with two spatial dimensions, the error norm definition must be modified to account for the additional dimension
Error norms
Denoted Lp where p is an integer ranging from 1,2...∞, the most common choices are the L1, L2 and L∞ norms
L1 error
Mean absolute error
L2 error
Root mean square error
L∞ error
Maximum error
For problems with two spatial dimensions, the error norm definition must be changed
Observed order of accuracy
The actual order of accuracy of the implementation of the algorithm, tests for bugs in the algorithm derivation or coding errors
The real error consists of many terms with many different derivatives, so the model of the error only gives the exact convergence rate as the number of points becomes very high
Grid resolutions should vary by a factor of 2 from one calculation to the next when estimating the error
At low grid resolutions, the observed value of n can differ dramatically from the expected due to the solution not being well resolved
At high grid resolutions, the error asymptotes towards the expected order of accuracy for the numerical scheme used
The heat equation is an exception where first order accuracy in time is acceptable because the time step size is constrained by stability to be proportional to the square of the grid spacing
Forward in Time, Central in Space (FTCS) discretisation of the heat equation
1. Approximate uxx using central differences
2. Approximate ut using forward Euler
3. Rearrange to get un+1_i = un_i + c^2*Δt/Δx^2 * (un_i+1 - 2un_i + un_i-1)
Stability criterion for FTCS heat equation
Δt ≤ Δx^2/(2c^2)
Backward in Time, Central in Space (BTCS) discretisation of the heat equation
1. Approximate uxx using central differences at the next time level
2. Rearrange to get un+1_i = un_i + c^2*Δt/Δx^2 * (un+1_i+1 - 2un+1_i + un+1_i-1)
Stability of BTCS heat equation
Unconditionally stable, no restriction on Δt
The linear advection equation describes the advection (transport/flow) of a quantity at a constant velocity
Explicit discretisation of linear advection equation
1. Approximate Yt using forward Euler
2. Approximate Yx using first-order upwind
such a straightforward analytical solution, yet has a similar behaviour to fluid dynamics, makes it an ideal starting point to understand the numerical discretisation of more complicated systems of equations like the Navier-Stokes equation