AC274: Finite Differences for Classical Fields Sauro Succi We shall cover three broad classes of PDE’s: Transport: Advection-Diffusion-Reaction equations Porous media, environment, you_name_it Conservation: Continuity equation Ubiquituos! Gas-dynamics: Burgers equation Shock waves, Cosmological fluids, Growth phenomena …
The Four Levels MACRO Continuum Fields Probability distributions MESO Particles (atoms/molecules MICRO Complex Fields QUANTUM Wash out Irrelevant details (tube/baby problem)
Finite Differences for Transport PDE’s
Finite Differences for Classical Fields Transport PDE’s: Outline We introduce the basic criteria of space-time finite-difference Discretization of PDE’s. For the sake of simplicity, we explicitly refer to simple Diffusion –Advection-Reaction equations in d=1 spatial dimensions. In the process of discussing actual examples, we shall also introduce the general (and very important) notion of stability analysis through inspection of the Discrete Dispersion Relation. Generalizations to the broader class of ADR (Advection-Diffusion-Reaction) equations in d>1 are left as an exercise. They are conceptually straightforward but require some extra-coding, hence it is an excellent exercise.
PDE’s for transport phenomena Diffusion Equation Advection-Diffusion Equation Advection-Diffusion-Reaction Equation
Transport: analytic solutions Linear homogeneous: similarity group Translation Dilatation Growth/Decay Inhomogenous, non-linear: broken syms This is where numerics takes over analytics!
Spacetime crystal Uniform (for simplicity)
Finite-Difference Schemes The Discrete Derivative is by no means unique! Higher accuracy is obtained by using larger sets of discrete points = STENCIL
Consistency Continuum limit: The discrete operators must reduce to their continuum form: smoothly. The rate of error decay defines the order of accuracy (first, second ….)
Computational molecules (stencils) Differential operators become SPARSE MATRICES
Discrete Time: Forward Euler
Discrete derivatives = Sparse matrices 1 0=N N N+1=1
2D stencils
Non uniform lattices The coefficients a,b,c, pick-up a dependence on the position {a_j,c_j,b_j}, but the The matrix structure stays the same because LOCALITY is what matters. Accuracy is affected though, usually one order less and sometimes even stability. Let us see why:
Non uniform lattices Uniform limit a+b+c =0 still, but the diagonal is non-zero. What does this mean?
Accuracy Taylor-expand to second order: Zeroth order accuracy: OK OK First order accuracy: OK Second order accuracy : No, unless UNIFORM! BOTTOMLINE: Even the centered derivative is only first order accurate Serious problem? No, if you don’t insist on point-like convergence…
PDE’s in 1d: Transfer matrix Using local (nearest-neighbor) stencils and fwd Euler in time: Computational Molecule: Compact matrix form: (Tridiagonal) T_ij is appropriately called Transfer Matrix, as it transfers state at time n (Present) to time n+1 (Future).
Now to actual equations Diffusion Equation
Diffusion Equation d=1 Analytical solution: Dispersion Relation: Frequency vs Wavenumber (see later)
Discrete Time: Forward Euler
Discrete space: centered Handier notation In general tridiagonal form:
DE: Centered-Euler This is known as diffusive Courant-Friedrich-Levy (CFL) number. Key to stability. Transfer matrix: Note that a+b+c=1 by mass conservation.
Dispersion Relation The Dispersion Relation tells how different wavelengths propagate in space. It says ALL about linear systems. The solution is expressed as a superposition of plane-waves (exponential). Since the problem is linear we can focus on a single plane wave: The real part tells the propagation speed of the signal: The imaginary part tells the growth/decay rate Stable Unstable
Discrete Fourier space Low k High k
Discrete range and continuum limit In the limit kd ->0 thewave does not “see” discreteness anymore
DE: continuum DR For plane waves the following handy replacement rules hold: One-line algebra delivers: Namely: No propagation All wavelengths decay (absolute stability) the shortest decay quadratically fast Any consistent discretization must reproduce the above relations in the continuum limit:
Discrete vs Continuum DR The Discrete DR necessarily deviates from this, esp at high-k, since short wavelengths see the lattice. We are mostly interested in long wavelengths
Discrete vs Continuum DR Two main sources of discretization error: Real(omega), Phase Errors: Dispersion Imag(omega), Amplitude Errors: Numerical Diffusion Dispersion means that the plane wave propagates at a different speed Than continuum one, thus leading to distorsions in the profile and eventually Unphysical oscillations (Gibbs oscillations) Positive numerical diffusion leads to excessive damping. Negative numerical diffusion leads to artificial growth: Numerical instability
General DDR Useful manipulations: Divide second by first: with By squaring both sides and summing up:
General DDR We can draw some general conclusions: If a=b there cannot be any propagation (this is the case for pure Diffusion) 2) If b-a>0 the scheme cannot be stable for any h (this is the case for pure Advection with centered differences)
From General to DE DDR DE: Exact at any k By squaring both sides and summing up: with
Diffusion DDR: Stability (-2<X<0) The discrete stability condition reads: (Since X<0) (Since |X|<2) This is the diffusive CFL condition
DDR: continuum limit Exact at any k Continuum limit: The continuum limit is recovered: accurate to 2° order. The stability analysis shows that discretization errors canNOT trigger instability at any wavenumber
Stability/Realizability Probabilistic interpretation (a+b+c=1) Probability of moving up in time from left Probability of moving up in time from right Probability of moving up in time from center Much swifter: Realizability (all coeffs must be non-negative):
Let’s add some “wind” Advection-Diffusion Equation
AD Equation For the simple case U=const, the analytical solution reads: The AD dispersion relation: Propagation
Numerical dispersion: Gibbs phenomena
positive = overdamping Numerical Diffusion: positive = overdamping
Centered FD+Euler
ADE: Centered-Euler Two CFL’s
Stability vs Realizability Note that the limit D=0 (pure advection) is always UNSTABLE! Adv/Dif is measured by the cell-Peclet number:
Time-step constraints DIFFUSION is much more constraining than ADVECTION ! Upon refining the grid by a factor 2, advection requires dt/2, diffusion requires dt/4. Other time-discretizations are used for diffusion, So-called implicit methods. See the quantum mechanics lectures
Advection-Diffusion-Reaction A lot of applications in science and engineering (combustion, crystal growth, population bacteria dynamics
Important dim-less groups Peclet = Advection/Diffusion Pe>>1 for macroflows, and Pe<<1 for nanoflows Air: D=10^-6 m2/s. L=1m, U=1 m/s gives Pe=10^5… Water: D=10^-5 m2/s, L=10^-6, U=10^-3, gives Pe=10^-4 Damkohler = Chemistry/Diffusion Da>>1 for flames, and Da<<1 for well-stirred reactors With L=1m, D=10^-6, r<10^-6 react/s is well stirred, but at small scales lower reactivity can still yield high Da.
ADR Equation For the ideal case U=const and linear chemistry: The analytical solution is: In general, chemistry “wants” homogeneous states such that: This may have multiple solutions (fixed points): how do they manage to coexist?
The conflict (frustration) is resolved through INTERFACES Interface width: Infinitely fast chemistry (Da to infinity)
Logistic equation: population growth Capacity:
ADR Equation: analytics For the ideal case U=const and Chemical reactions Select the unstable modes (morphogenesis) Large scales grow: k<sqrt(r/D) Small scale decay: k>sqrt(r/D)
ADR: Centered-Euler Three CFL’s:
Cell dim-less groups Peclet=Advection/Diffusion Large Peclet stand for strong diffusion vs weak advection (microscopic transport) Damkohler=Reaction/Diffusion CFL: At the mesh-size scales the dimensionless number should not exceed O(1)
A nice research project Can yield quite complex behavior: Show movie of bacterial growth Growth up to a/b Decay to zero, extinction Random a(x) with <a> <0 but fluctuations with a(x)>o; Islands of growth (oasis) surrounded by an ocean of decay (desert). Q: Probability of survival? Show movies!
Boundary Conditions They strongly affect the solutions: BC select the bulk solutions compatible with the environmental constraints
Boundary Conditions: Dirichlet With explicit methods (present depends on past only) easy: Dirichlet: Bulk: j=2,N-1 Boundaries: j=1, j=N are taken by the BC specification: The bulk gives a (N-2)x(N-2) matrix:
Boundary Conditions: periodic 1 N
Full stability analysis (incl. Boundary) Find the numerical eigenvalues of the Transfer matrix For tridiagonal systems the eigenvalues are known analytically. For instance Diffusion Matrix {1,-2,1} gives In general, however, they must be found via numerical Eigenvalue solvers.
Assignements 1. Write a computer program to solve the 1d ADR with constant coefficients (periodic boundaries) 2. Same in 2D 3. Same in 3D (for the brave) 4. Include heterogenoeus reactions
End of the lecture