In principle, I know finite differences. In university, we discussed it and derived consistency and boundary conditions. But I am still left with a big question.How to design a good finite difference scheme?What should I do, that my solution does not oscillate or makes other weird things.When I look at a scheme, how can I decide, whether it's a good or bad one?
How to design good finite difference schemes?
finite difference
The quality of the scheme depends on the type of equation to be solved. You can check for dispersion and dissipation: the dominant error term for odd-order schemes is typically dissipative, while the dominant error term for even-ordered schemes is typically dispersive; it is true that some schemes, such as symmetric centered schemes, have only dispersive error terms (thanks to David Ketcheson for pointing this out). If your solution is smooth, ie. no discontinuities, then central schemes are better than biased schemes. If your solution not smooth, then upwind or upwind-biased schemes are required. A central scheme will generate oscillations. Filtering or artificial dissipation could be used to offset the oscillations though.Downwind biasing is unstable.If you are running a problem that has smooth and non-smooth regions, then you can look at schemes that adjust order and/or bias such as WENO or ENO schemes. One approach to determine stability of a method is the Von Neumann Stability Analysis where you substitute a solution in the form of a Fourier series into your equation and see whether the disturbances are amplified or not. Almost all stability methods only work on linear PDE's, but some insight can be made into non-linear stability from those approaches. The other issue that often arises is grid quality. Some schemes will tolerate a non-uniform grid just fine while others go unstable if used on a non-uniform grid. Typically higher order schemes are more sensitive to grid issues than lower order schemes.The last thing to check is conservation, if that matters. You may come up with a numerical scheme that is consistent but not conservative. If it is conservative then it is a telescoping series and you should be left with only the boundary terms in your series when summed over a grid. Which makes sense intuitively, what comes in goes out. In aerodynamics, the classic example of this is the 1970 Murman-Cole scheme for transonic flow calculations. The scheme is used to solve the transonic potential equations. But the original formulation actually gave answers closer to real life than it should, it showed viscous effects and non-linear effects that it shouldn't have shown. In 1973, Murman found the issue and published a correction to make the scheme conservative. The answer got better in the sense that it showed the solution expected for the equation solved, but that solution was further from the real, physical solution. So practitioners still use the non-conservative form because it happened to give a more physical answer, despite such an answer not being a solution to the equation it is supposed to solve. Sometimes being wrong is lucky.