# Finite difference method help (bvp)

1. Jan 23, 2010

### beedle

Hi, I'm currently writing a code to solve a steady-state boundary problem across multiple layers of a system. The system involves diffusion-reaction of various species in a porous medium. I am simply using central finite differences to model this setup, which says that essentially -div*J+Q = 0. (I take J to be mole flux of a species and Q to be the rate of creation of that species per volume). It is one dimensional, so basically, my equations typically look something like this:

$$J = vC - D_i\frac{dc}{dx}$$

$$-\frac{dJ}{dx} + Q_i = 0$$

$$-v\frac{dC}{dx}+D_i\frac{d^2C}{dx^2}+Q_i=0$$

or, in terms of central differences

$$-v\frac{C_{j+1}-C_{j-1}}{h_i}+D_i\frac{C_{j+1}-2C_{j}+C_{j-1}}{h_i ^2} +Q_i = 0$$

where the i's designate which phase/region I am in. So I have written this set of equations in various regions of my problem. At the interfaces of these regions, I know I am supposed to say that the fluxes and concentrations of the species are continuous. Take the interface in the following example to be located at some point j, and let phase 1 lie to the left and phase 2 lie to the right. I want to write something like this at point j:

$$A(J_{j-1/2} - J_{j+1/2}) + Q_{overall}dV = 0$$

So here is what I am thinking for the centered finite differences:

$$(v\frac{C_j+C_{j-1}}{2}-D_{i=1}\frac{C_j-C_{j-1}}{h_{i=1}}) -(v\frac{C_{j+1}+C_{j}}{2}-D_{i=2}\frac{C_{j+1}-C_{j}}{h_{i=2}})+Q_{i=1}\frac{h_{i=1}}{2}+Q_{i=2}\frac{h_{i=2}}{2}=0$$

Again, Q is rate of rxn per unit volume, so I am weighing according to the step size h between phases. I'd just like to check if this is the correct way of imposing the continuity of fluxes between phases. I bring this up because a code I am looking at from a former grad student in my research group has somewhat different looking fd's. He neglected the terms involving the v's, but his other terms still look different:

$$(D_{i=1}\frac{C_j-C_{j-1}}{h_{i=1} ^2}) -(D_{i=2}\frac{C_{j+1}-C_{j}}{h_{i=2} ^2})+\frac{Q_{i=1}+Q_{i=2}}{2}=0$$

the two h's are not necessarily equal, so I am not clear about this way of doing it and how it makes sense. If the two h's -are- equal, then my way reduces to his way. If my way is wrong, could someone please explain why? Thanks. I will be on for a while so if anything in my post needs clarification just ask.

Last edited: Jan 23, 2010