4
$\begingroup$

I'm trying to express the following in finite differences:

$\frac{d}{dx}\left[ A(x)\frac{d\, u(x)}{dx} \right].$

Let $h$ be the step size and $x_{i-1} = x_i - h$ and $x_{i+ 1} = x_i + h$

If I take centered differences evaluated in $x_i$, I get:

$\begin{align*}\left\{\frac{d}{dx}\left[ A(x)\frac{d\, u(x)}{dx}\right]\right\}_i &= \frac{\left[A(x)\frac{d\, u(x)}{dx}\right]_{i+1/2} - \left[A(x)\frac{d\, u(x)}{dx}\right]_{i-1/2}}{h} \\ &= \frac{A_{i+1/2}\left[\frac{u_{i+1}-u_{i}}{h}\right] - A_{i-1/2}\left[\frac{u_{i}-u_{i-1}}{h}\right]}{h} \end{align*}$

So, if I use centered differences I would have to have values for $A$ at $i + \frac 12$ and $A$ at $i - \frac 12$; however those nodes don't exist (in my stencil I only have $i \pm$ integer nodes); is that correct? If I use forward or backward differences I need A values at $i$, $i + 1$, $i + 2$ and at $i$, $i -1$, $i -2$ respectively.

Am I on the correct path?

I would really appreciate any hint.

Thanks in advance,

Federico

  • 0
    @user1551: may I use the central difference for the outer differential and then a forward and a backward difference for the inner differentials?2011-08-26

2 Answers 2

3

While the approach of robjohn is certainly possible, it is often better to take the approach suggested by the original poster: $ \left\{\frac{d}{dx}\left[ A(x)\frac{d\, u(x)}{dx}\right]\right\}_i = \frac{A_{i+1/2}\left[\frac{u_{i+1}-u_{i}}{h}\right] - A_{i-1/2}\left[\frac{u_{i}-u_{i-1}}{h}\right]}{h} $ As he noted, $A$ is evaluated on half grid point. In many cases, that's not much of a problem. For instance, if you start from the diffusion equation with variable diffusivity, $ \frac{\partial u}{\partial t} = \frac{\partial}{\partial x} \left( A(x) \frac{\partial u}{\partial x} \right), $ with $A(x)$ given, then it does not matter whether you sample $A$ on grid points or half grid points. It is quite okay to use a different grid for $A$ and $u$ (that's sometimes called a staggered grid).

In other cases, you can approximate the values at half grid points by the average: $A_{i+1/2} \approx \frac12 ( A_{i+1} + A_i )$. That gives you almost the same method as the one derived by robjohn.

  • 1
    If we write $A$ in Taylor series\begin{align}A_{i+1}&=A_i+A_i'+\frac{1}{2}A_i''\\A_{i-1}&=A_i-A_i'+\frac{1}{2}A_i''\end{align} and similarly for $u_{i+1}$ and $u_{i-1}$, we get that $A_{i+1/2}[u_{i+1}-u_i]-A_{i-1/2}[u_i-u_{i-1}]=A_i'u_i'+A_iu_i''+\frac{1}{4}A_i''u_i''$Whereas, $\frac{1}{4}(A_{i+1}-A_{i-1})(u_{i+1}-u_{i-1}) + A_i(u_{i+1}-2u_i+u_{i-1})=A_i'u_i'+A_iu_i''$ So it turns out that the formula I cited is exact if both $A$ and $u$ are quadratic. Extending this analysis further yields fewer higher order error terms as well.2011-08-31
2

$ \frac{\mathrm{d}}{\mathrm{d}x}\left[A\frac{\mathrm{d}u}{\mathrm{d}x}\right]=\frac{\mathrm{d}A}{\mathrm{d}x}\frac{\mathrm{d}u}{\mathrm{d}x}+A\frac{\mathrm{d}^2u}{\mathrm{d}x^2} $ So you might try using $\frac{1}{4}(A_{i+1}-A_{i-1})(u_{i+1}-u_{i-1}) + A_i(u_{i+1}-2u_i+u_{i-1})$

  • 0
    I have a similar question to the one stated above. Please see if you can help find a solution http://math.stackexchange.com/questions/491$0$97/finite-difference-for-variable-conductivity2013-09-11