Neumann boundary condition FD implementation for instationnary diffusion equation
I am trying to solve this diffusion equation : $\dfrac{\partial D\dfrac{\partial f}{\partial x}}{\partial x}+S = \dfrac{\partial f}{\partial t}$ ($D$ is not constant and varies according to $x$) with the following BC: $f(x,0)=1 , f(0,t)=0, \dfrac{\partial f}{\partial x}(1,t)=0$
I am using a central finite difference scheme (2nd order) for space and Euler explicit for time (1st order). The discretized $[0..1]$ domain contains the $x_{i}$ points, $i \in [0..N]$ ($x_{0}=0 , x_{N}=1$).
The implementation of Dirichlet condition at $x=0$ is simple. For the <PERSON> boundary condition, I saw a lot of references that treated simple cases, adequate for constant diffusion coefficients and stationnary cases, like the ghost point, that I can't consider in my case(Diffusion coefficient can't be evaluated out of the domain, ghost point envolves evaluation the equation on a point that is not inside the interior domain... 935
).
So I am trying something at my own and I want confirmation or correction if I omitted an important aspect in my work:
The discretized equation evaluated at $x_{N-1}$ involves the value of $f_{N}$. If we had Diricihlet condition at $x_{N}$, the problem would have been solved directly. But in our case, $f_{N}$ is unknown.
What I did is that I treated the Neumann BC with a backward scheme (at the 2nd order to preserve the general order of the whole scheme) in order to have an expression of $f^{k}_{N}$:
$\dfrac{\partial f}{\partial x}(x_{N},k\Delta t)=\dfrac{-3f^{k}{N}+4f^{k}{N-1}-f^{k}_{N-2}}{2\Delta x}=0$
$f^{k}{N}=4/3 f^{k}{N-1}-1/3 f^{k}_{N-2}$
then I injected the new expression of $f^{k}{N}$ in the discretized equation at $x{N-1}$. Meaning that I did not add an equation to the problem as I would do for a stationnary problem but I injected the expression of $f^{k}_{N}$ inside the last equation.
So the unknown vector $f^{k}$ in a case of matrix writing would only contain $f^{k}_{i}, i\in [1..N-1]$ (like in a full Dirichlet situation)
Is it correct ?
For information, the matrix form of the discretized problem is : $f^{k+1}=Af^{k}+S+B$, with $B$ the vector containing the B.C , and $S$ the 2nd member vector 935