Let's consider the following 1D diffusion equation:

$\frac{\partial u}{\partial t} = xk \frac{\partial}{\partial x}(\frac{1}{x}\frac{\partial u}{\partial x})$

where we assume that the diffusion coefficient $k$ is constant.

In order to discretize this equation, let us define the following:

$x_i = 1 + i\Delta x, \forall i=0,1,...,I \\ t_n = n\Delta t, \forall n=0,1,...,N \\ r = \frac{k\Delta t}{2 \Delta x^2} \\ s = \frac{k\Delta t}{4 \Delta x} $

where $\Delta t$ and $\Delta x$ are the time step and the spacing, respectively.

Let's discretize the diffusion equation by means of the Crank-Nicholson method:

$u_i^{n+1}-u_i^n = r x_i [ \frac{u_{i+1}^n - u_i^n}{x_{i+\frac{1}{2}}} - \frac{u_i^n - u_{i-1}^n}{x_{i-\frac{1}{2}}}] + r x_i [ \frac{u_{i+1}^{n+1} - u_i^{n+1}}{x_{i+\frac{1}{2}}} - \frac{u_i^{n+1} - u_{i-1}^{n+1}}{x_{i-\frac{1}{2}}}]$

where upper indexes refer to time, lower indexes refer to space.

So far, so good. Now, using the product rule, the initial diffusion equation can be rewritten as:

$\frac{\partial u}{\partial t} = k \frac{\partial^2 u}{\partial x^2} - \frac{k}{x}\frac{\partial u}{\partial x}$

The latter equation is now a diffusion-advection equation, but should be equivalent to the original diffusion equation.

Let us discretize the latter equation by means of the Crank-Nicholson method:

$u_i^{n+1}-u_i^n = r [ u_{i+1}^n - 2 u_i^n + u_{i-1}^n ] - \frac{s}{x_i} [ u_{i+1}^n - u_{i-1}^n] + r [ u_{i+1}^{n+1} - 2 u_i^{n+1} + u_{i-1}^{n+1}] - \frac{s}{x_i} [u_{i+1}^{n+1} - u_{i-1}^{n+1}]$

Those 2 discretizations are different. So, here is my question:

Which discretization should I choose?

  • $\begingroup$ You really do have a variable coefficient heat equation as written so I am not surprised that you are seeing different discretizations as is common for variable coefficient problems. Looking at the two discretizations I would pick the latter but it may not be consistent with the original equation. $\endgroup$ Nov 28, 2019 at 16:43
  • $\begingroup$ @KyleMandli I'd take the latter as well, as I've seen C-N many times on diffusion-advection equations. The term "Variable coefficient heat equation" comes from the x multiplier in the rhs? $\endgroup$
    – mfnx
    Nov 28, 2019 at 16:49
  • $\begingroup$ @KyleMandli, yes the PDEs are identical, but that doesn't imply that their discrete forms are. $\endgroup$ Nov 29, 2019 at 5:49
  • $\begingroup$ @Dr.LutzLehmann When you say I will reduce the order of the method, do you refer to the first or the second discretization? $\endgroup$
    – mfnx
    Nov 29, 2019 at 12:28
  • $\begingroup$ Yes, that makes more sense. Then the singularity is well away from the integration interval and the midpoint is the appropriate approximation everywhere. $\endgroup$ Nov 29, 2019 at 13:07

1 Answer 1


Take the first expression and start to reduce the $x$ values to $x_i$, \begin{align} \frac{u_{i+1}^n - u_i^n}{x_{i+\frac{1}{2}}} - \frac{u_i^n - u_{i-1}^n}{x_{i-\frac{1}{2}}} &= \frac{(x_i-\frac12Δx)(u_{i+1}^n - u_i^n) - (x_i+\frac12Δx)(u_i^n - u_{i-1}^n)}{x_{i-\frac{1}{2}}x_{i+\frac{1}{2}}} \\ &=\frac{x_i}{x_i^2-\frac14Δx^2}(u_{i+1}^n - 2u_i^n + u_{i-1}^n) \\&\qquad - \frac{Δx}{2(x_i^2-\frac14Δx^2)}(u_{i+1}^n - u_{i-1}^n) \end{align} After multiplying with $rx_i$ you find that the difference to the second formula are only in terms of size $O(Δx^2)$, that is, within the error order of the method.

  • $\begingroup$ So, in terms of order of accuracy, there is no preference? Any other things to account for when choosing one or the other? $\endgroup$
    – mfnx
    Nov 29, 2019 at 13:29
  • $\begingroup$ I do not see anything that could be quantitatively different. The computed numbers will differ of course, but within the bounds of the method error. $\endgroup$ Nov 29, 2019 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.