Finite Difference Approximation of the Nernst-Planck Equation and von Neumann Stability Analysis Oliver K. Ernst September 14, 2015 1 Nernst-Planck Equation In the presence of an electric field, ions undergoing diffusion give rise to an ionic current J(~r, t) zF J(~r, t) = −D ∇c(~r, t) + c(~r, t)∇φ(~r, t) , RT (1) where c(~r, t) is the ionic concentration at position ~r and time t, D is the diffusion constant (taken here as a constant for a particular ionic species), z is the ion charge, T is the temperature, φ(~r, t) is the potential, and F, R are the Faraday and Universal Gas constants, respectively. Together with the continuity equation ∂c = 0, (2) ∂t the Nernst-Planck equation describing the time evolution of the ionic concentration is obtained [1, 2] ∇J + as ∂c zF 2 2 =D ∇ c+ (∇c∇φ + c∇ φ) . ∂t RT (3) We restrict ourselves to the one dimensional case in x, t, although generalization to higher dimensions is straight forward. For ease of notation, define α = zF/RT , then ∂c ∂φ J = −D + αc , ∂x ∂x 2 ∂c ∂ c ∂c ∂φ ∂2φ =D + α( + c ) . ∂t ∂x2 ∂x ∂x ∂x2 2 (4) (5) Finite Difference Approximation We seek to obtain a finite difference approximation to the differential equation 5. Begin by discretizing space into i = 1, 2, . . . , n compartments of width ∆x = xi+1 − xi with x1 = 0 and xn = L, and time into j = 0, 1, 2, . . . steps of duration ∆t = tj+1 − tj , with t0 = 0. Let cji denote the concentration in compartment i at time step j, and φji the potential. 1 2.1 Interior points Consider the flux of ions into compartment i of volume V from compartments i − 1 and i + 1 across a cross sectional area A. The net change in the number of particles in compartment i during a single time step j → j + 1 using a forward difference scheme is where Ja→b cj+1 − cji i V = Ji−1→i A − Ji→i+1 A, ∆t denotes the flux from compartment a into b. By 4, Ji−1→i = −D Ji→i+1 = −D (6) cji − cji−1 φj − φji−1 + αcji i ∆x ∆x ! cji+1 − cji φj − φji + αcji+1 i+1 ∆x ∆x ! , (7) . (8) Furthermore, note that V = ∆x∆y∆z and A = ∆y∆z. Collecting terms ! !) j j cji − cji−1 cji+1 − cji φji+1 − φji j φi − φi−1 j −D + αci +D + αci+1 ∆x ∆x ∆x ∆x h io D n j j j j j j j j j j j c − 2c + c + α c φ − 2φ + φ + c − c φ − φ = i i−1 i i+1 i i−1 i+1 i i+1 i (∆x)2 i+1 cj+1 − cji A i = ∆t V ( ∴ cj+1 = cji + ∆t i 2.2 (9) (10) h io D n j j j j j j j j j j j c − 2c + c + α c φ − 2φ + φ + c − c φ − φ i i−1 i i+1 i i−1 i+1 i i+1 i (∆x)2 i+1 (11) Endpoints The boundary conditions required depend on the desired application of the Nernst-Planck equation. We consider here the case of no-flux endpoints, i.e. Neumann boundary conditions of the type ∂c1 (t) ∂cn (t) = = 0. ∂t ∂t Starting with boundary conditions for compartment i = 1, analogous to 6, where J1→2 cj+1 − cj1 1 V = −J1→2 A, ∆t is given by 8 for i = 1. Using the finite difference approximation gives cj+1 = cj1 + ∆t 1 o 2D n j j j j j c − c + αc φ − φ . 1 2 2 1 (∆x)2 2 (12) (13) (14) Similar considerations for the i = n endpoint give cj+1 = cjn − ∆t n cj+1 − cjn n V = Jn−1→n A, ∆t (15) o 2D n j j j j j c − c + αc φ − φ . n n n−1 n−1 (∆x)2 n (16) 2 3 von Neumann Stability Analysis Consider the following problem: given an initial concentration distribution c0i for all i on a domain [0, L], a known potential function φji for all i, j, and having set D, ∆x, α - how is the time step ∆t to be chosen such that the finite difference approximation is stable, in the sense that the errors in subsequent time steps decrease? Clearly ∆t must be chosen to be sufficiently small, but this comes at the cost of increased simulation time. An upper bound on ∆t that results in a stable simulation is desirable. The von Neumann stability analysis (sometimes known as Fourier stability analysis) gives such a bound for finite difference approximations using Fourier decomposition of the error. We follow [3] approximately in notation and steps, extending the result to the Nernst-Planck equation. Define the round-off error δij in compartment i at time step j as δij = Cij − cji , cji where is the exact (true) solution to 11 and arithmetic. Then δij also satisfies 11, i.e. Cij (17) is the solution obtained using finite precision h io D n j j j j j j j j j j j δ − 2δ + δ + α δ φ − 2φ + φ + δ − δ φ − φ . i i−1 i i+1 i i−1 i+1 i i+1 i (∆x)2 i+1 (18) The desired quantity to bound is the amplification factor of the error, defined as ∴ δij+1 = δij + ∆t δij+1 (19) |G| ≤ 1. (20) G= , δij such that the desired bound for the error to decrease in subsequent time steps is To evaluate the amplification factor, expand the error in a Fourier series δij = n X Ap (tj )eikp xi , (21) p=1 where Ap (t) are the amplitudes and kp = πp/L for n = L/∆x as before. Assume that the amplitude of the errors grows or decays exponentially in time - each term of the series then has the form δij = eatj eikp xi , (22) for some constant a. Furthermore, the other terms in 18 are δij+1 = ea(tj +∆t) eikp xi , (23) j δi+1 j δi−1 , (24) = eatj eikp (xi −∆x) . (25) =e atj ikp (xi +∆x) e Substituting these terms into 18 (it is sufficient to consider an arbitrary term rather than the whole Fourier series), we obtain h io D n ikp ∆x j j j j j −ikp ∆x ikp ∆x e − 2 + e + α φ − 2φ + φ + e − 1 φ − φ (26) i+1 i i−1 i+1 i (∆x)2 h i D j j j j j 2 kp ∆x ikp ∆x = 1 + ∆t −4 sin + α φi+1 − 2φi + φi−1 + e − 1 φi+1 − φi . (27) (∆x)2 2 ea∆t = 1 + ∆t 3 Since the amplification factor evaluates to G= δij+1 δij = ea(tj +∆t) eikp xi = ea∆t , eatj eikp xi (28) the condition for a stable finite difference analysis becomes h i j j j j j 2 kp ∆x ikp ∆x ≤ 1, 1 + ∆t D −4 sin + α φi+1 − 2φi + φi−1 + e − 1 φi+1 − φi (∆x)2 2 h i 2 kp ∆x ∆t D ≤ 2, + α φji+1 − 2φji + φji−1 + eikp ∆x − 1 φji+1 − φji (∆x)2 −4 sin 2 h i j j j j 2 kp ∆x ikp ∆x ≤ 2. ∆t D −4 sin + α −φ + φ + e φ − φ i i−1 i+1 i (∆x)2 2 (29) (30) (31) To obtain a more precise expression for ∆t, consider proceeding by using the triangle inequality |z1 + z2 | ≤ |z1 | + |z2 | for any z1 , z2 ∈ C, then a more rigorous condition on ∆t is D j ikp ∆x j j j 2 kp ∆x ∆t −4 sin φi+1 − φi ≤ 2. + |α| −φi + φi−1 + e (∆x)2 2 (32) (33) Here, α contains the charge z of the ion and therefore may also be negative, but is always real. All terms on the left are positive, and the condition on ∆t must be satisfied for all kp and φji (if the step ∆t is fixed for the entire simulation; otherwise, it may be adjusted at each time step j). As a result, we need to treat only the maximum terms possible. The maximum of sin2 is one, and the phase term does not contribute to the magnitude, hence D j j j j ∆t ≤ 2, (34) 4 + |α| max φi − φi−1 + φi+1 − φi i,j (∆x)2 2(∆x)2 ∆t ≤ D −1 j j j j 4 + |α| max φi − φi−1 + φi+1 − φi . i,j (35) Note the physical interpretation of the term on the right hand side, φj − φji−1 ∂φi ≈ i , ∂t backward difference ∆x φji+1 − φji ∂φi , ≈ ∆x difference ∂t forward j j j j ∂φi 1 φi − φi−1 φi+1 − φi . ∴ + ≈ average 2 ∆x ∆x ∂t (36) (37) (38) Finally, when no electric field is present, the potential terms vanish and we recover the stability condition for the diffusion equation as expected, ∆t ≤ (∆x)2 . 2D 4 (39) 3.1 Constant Electric Field Consider the case of an electric field which is constant in time and space and has magnitude E0 , such as assumed in the derivation of the Goldman-Hodgkin-Katz (GHK) equation. By definition φi − φi−1 φi+1 − φi , E0 = − = − (40) ∆x ∆x for all i, where we have dropped the superscript j to indicate that the potential time independent. The maximum term in 35 becomes 1 j j j j max φi − φi−1 + φi+1 − φi = 2E0 , ∆x i,j (41) such that the bound is ∆x ∆t ≤ D 4 2 + |α|E0 ∆x −1 . (42) Sample Mathematica Code Mathematica (v.10.2) code is provided here. Consider two example potentials φ: (1) a linear potential, and (2) an exponentially varying one. The condition on ∆t for a linear potential is given by 42. Define the following time steps ∆t0.999 ∆x = 0.999 × D ∆t1.001 ∆x = 1.001 × D 2 + |α|E0 ∆x −1 2 + |α|E0 ∆x −1 , (43) , (44) such that ∆t0.999 is a stable time step and ∆t1.001 is an unstable step (see code example for sample parameter values). For an initial concentration distribution in the shape of a sin function, Figure 1 shows the initial and final concentration distributions for each of the two time steps. Despite only a 0.2% difference in their magnitude, the time step ∆t1.001 clearly leads to an unstable simuatlion. 3.× 10-25 3.× 10-25 2.5 × 10-25 2.5 × 10-25 2.× 10-25 2.× 10-25 -25 �������� 1.5 × 10 1.5 × 10-25 1.× 10-25 1.× 10-25 5.× 10-26 5.× 10-26 0.5 1.0 1.5 2.0 0.5 1.0 1.5 2.0 dt0.999 dt1.001 initial dist. Figure 1: Concentration distributions after 2000 steps with time steps as labeled, for a linear potential. Similarly, consider the case of a potential in the shape of an exponential function, whose bound on ∆t is given by the more general 35. For 5 ∆t0.99 2(∆x)2 = 0.99 × D ∆t1.01 2(∆x)2 = 1.01 × D −1 4 + |α| max (|φi − φi−1 | + |φi+1 − φi |) , (45) −1 4 + |α| max (|φi − φi−1 | + |φi+1 − φi |) , (46) i i ∆t0.99 is a stable time step and ∆t1.01 an unstable step. Figure 2 shows that again above the derived bound, the simulation becomes unstable. Note that the bound is not exact, as the triangle inequality 32 provides a larger bound on ∆t than absolutely sufficient, although slightly smaller time step (e.g. ∆t1.0001 ) may also lead to stable simulations. 3.× 10-25 3.× 10-25 2.5 × 10-25 2.5 × 10-25 2.× 10-25 2.× 10-25 -25 ��������� 1.5 × 10 1.5 × 10-25 1.× 10-25 1.× 10-25 5.× 10-26 5.× 10-26 0.5 1.0 1.5 2.0 0.5 1.0 1.5 2.0 dt0.99 dt1.01 initial dist. Figure 2: Concentration distributions after 2000 steps with time steps as labeled, for an exponential potential. References [1] Bertil Hille, Ion channels of excitable membranes, Sinauer, Sunderland, Mass, 2001. [2] Christof Koch, Biophysics of computation information processing in single neurons, Oxford University Press, New York, 1999. [3] Wikipedia, Von Neumann stability analysis — Wikipedia, The Free Encyclopedia (2015), https://en.wikipedia.org/ w/index.php?title=Von_Neumann_stability_analysis&oldid=674227751. 6