Finite difference method having a discontinuity

I am trying to understand the FDM which is a widely used method solving differential equations by using approximation below. $$\dfrac{\partial u}{\partial x}=\dfrac{u(i+1)-u(i-1)}{2\Delta x}$$ How can I apply the approximation the equation given below?

$$\dfrac{d}{dx}(z(x)\dfrac{d}{dx}u(x))=0$$ where $$u(0)=a$$ and $$u(1)=b$$

and $$z(x)=1$$ for $$0, $$z(x)=2$$ for $$0.5

So, after some derivation the equation becomes, $$\dfrac{z(i+1)-z(i-1)}{2\Delta x}\dfrac{u(i+1)-u(i-1)}{2\Delta x}+z(i)\dfrac{u(i+1)-2u(i)+u(i-1)}{2\Delta x}=0$$

How can I handle the discontinuity at 0.5?

• seems to me that your intervals need to define a value at .5 and use it. As of now you're not defining z at that point.
– EMP
Jun 25 '20 at 18:55
• If you are interested in other approaches that can handle discontinuities take a look at finite volume method danieljfarrell.github.io/FVM Jun 25 '20 at 21:44
• Or the finite element method, which also doesn't care whether or not $z(x)$ is continuous. Jun 26 '20 at 3:20

You're approaching this the wrong way by using the product rule of differentiation. Rather, making use of the fact that $$\frac{\partial u(x_i)}{\partial x} \approx \frac{u_{i+1/2}-u_{i-1/2}}{\Delta x},$$ the first step in finding what you need to do is to recognize that $$z(x_i)\frac{\partial u(x_i)}{\partial x} \approx z_i \frac{u_{i+1/2}-u_{i-1/2}}{\Delta x} = \frac{z_i u_{i+1/2}-z_i u_{i-1/2}}{\Delta x}.$$

The second step is the applying the finite difference operation one more time: $$\frac{\partial}{\partial x} \left[z(x_i)\frac{\partial u(x_i)}{\partial x} \right] \approx \frac{\frac{z_{i+1/2} u_{i+ 1}-z_{i+1/2} u_{i}}{\Delta x} - \frac{z_{i-1/2} u_{i}-z_{i-1/2} u_{i-1}}{\Delta x}}{\Delta x}.$$ This can be simplified to the following, more familiar form: $$\frac{\partial}{\partial x} \left[z(x_i)\frac{\partial u(x_i)}{\partial x} \right] \approx \frac{z_{i+1/2} u_{i+ 1}-(z_{i+1/2} +z_{i-1/2}) u_{i} + z_{i-1/2} u_{i-1}}{\Delta x^2}.$$

• Why product rule of differentiation gives wrong result? @Wolfgang Bangerth Jun 26 '20 at 7:26
• @AldrichTaylor -- it's not that your approximation is wrong, it's just that you lose certain properties using that approach that are useful in the analysis and solution of the discretized form if you apply the product rule first. Jun 26 '20 at 15:49
• Instead of using $\dfrac{\partial u}{\partial x}=\dfrac{u(i+1/2)-u(i-1/2)}{2\Delta x}$, can I use $\dfrac{\partial u}{\partial x}=\dfrac{u(i+1)-u(i-1)}{2\Delta x}$ approach? In your approch, I assume, you get mid points of the differential points. Am I rgiht? Is there a difference between your and my apporach? @WolfgangBangerth Jun 26 '20 at 17:01
• If you take $\pm 1$, then you end up using only every second point on your mesh to define the finite difference approximation of $u$. If you look at how I wrote this down, you only need the half-mesh points for $z$, but not for $u$. Jun 26 '20 at 22:28

There's a really nice book by Li and Ito on the immersed interface method, which was designed to solve problems like yours. Chapter 2 describes 1D problems. Basically, the finite difference method works well when the coefficients are smooth, but when they're rapidly varying or have discontinuities things can go to hell very quickly. You can make it work by being very careful to put nodes right at the interface and making special choices in your finite difference stencils.

• Seconding this. IIM is also pretty easy to implement yourself for a simple problem like this. However, if you are just learned about FDM, then one thing you have now learned is that FDM is not good at handling problems with discontinuities. FEM and FVM are much better at these types of problems, generally Jun 26 '20 at 0:36
• While IIM involves jump conditions of the solution and its derivative at the interface, there is no such condition here. Jun 26 '20 at 8:01