I'm trying to simulate the growth of a brain tumor using a 3d reaction-diffusion model $ \partial_{t}u = \nabla.{(D\nabla{u}) } + ku.(1-u)$ , knowing the initial distribution of tumor $u^0$, the non-homogeneous diffusion coefficient $D$ and the non-homogeneous net-proliferation map $k$.
So I first tried to proceed to simulation simply by dividing it into small time steps and directly simulate the process by simply replacing the derivatives what is appearing to me now as forward Euler finite difference. I got serious instability problems which, if I understand well, are due to the difference scheme I'm using.
So I'm trying to learn how to correctly code finite difference algorithms. At this point there's something I don't understand and I hope someone will be able to explain me where I'm wrong.
Let forget the proliferation term and do simply a 1D diffusion ( $ \partial_{t}u = \partial_{x}(D\partial_{x}u) $ ) using a Crank-Nicolson scheme for the time difference and a central difference for the spatial derivatives.
So, if $D$ depends on $x$, we have $ u^{n+1}_{i} = u^{n}_{i} + \frac{\Delta{t}}{2} \{ \partial_{x}(D\partial_{x}u^{n}) + \partial_{x}(D\partial_{x}u^{n+1}) \} $
which develop to
$ \Rightarrow ( 1 - \frac{\Delta t}{2}\partial_{x}(D\partial_{x}\cdot) ) u^{n+1}_{i} = ( 1 + \frac{\Delta t}{2}\partial_{x}(D\partial_{x}\cdot) ) u^{n}_{i}$
and using $ \partial_{x}(D\partial_{x}V) = \partial_{x}D.\partial_{x}V + D.\partial_{xx}V $,
$\partial_{x}V = \frac{V_{i+1}-V_{i-1}}{2\Delta x}$
and $\partial_{xx}V = \frac{V_{i+1}+V_{i-1}-2V_{i}}{{\Delta x}^2}$
one get
$ \partial_{x}(D\partial_{x}u_{i}) = \frac{(D_{i+1}-D_{i-1}).(u_{i+1}-u_{i-1})}{4{\Delta x}^2} + \frac{D_{i}.(u_{i+1}+u_{i-1}-2u_{i})}{{\Delta x}^2}$
ordering it according to the spatial indice of $u$ , one get
$ \partial_{x}(D\partial_{x}u_{i}) = \frac{1}{4{\Delta x}^2}.\{ (D_{i+1}-D_{i-1}+4D_{i})u_{i+1} + 8D_{i}u_{i} - (D_{i+1}-D_{i-1}-4D_{i})u_{i-1} \} $
In matrix form, this can be written
$ \partial_{x}(D\partial_{x}u) = \tilde{D}u $
with $ \tilde{D} \equiv \frac{1}{4{\Delta x}^2}\begin{bmatrix} -8D_1 & (D_2+4D_1) & 0 & \cdots \\ -(D_3 - D_1 -4D_2) & -8D_2 & (D_3-D_1+4D_2) & \cdots \\ \vdots & \vdots & \vdots & \vdots \\ 0 & \cdots & -(- D_N -4D_{N-1}) & -8D_N \end{bmatrix} $
Therefore, one have to solve, at each time step, the equation $ (1 - \frac{\Delta t}{2}\tilde{D})u^{n+1} = (1 + \frac{\Delta t}{2}\tilde{D})u^{n} $
my problem is that on every course/paper I read on this subject, the authors are explaining that one have to solve the equation at each time step which is the time consuming step. However, as it is written here at least, the matrix $\tilde{D}$ is completely determined from the (fixed in time) $D$ distribution and it looks to me that one can just simply generate it, then calculate the total matrix $ M = (1 - \frac{\Delta t}{2}\tilde{D})^{-1} \cdot (1 + \frac{\Delta t}{2}\tilde{D})$ and then simply calculate $u^n = M^nu^0 $ which is very fast.
I tried to code it in MATLAB, and indeed, doing it step by step, or just at once gives me the same results ( and which are coherent with a simple Gaussian blurring with $\sigma = \sqrt{2D.T} $ in the case of an homogeneous D, just to check the validity of the simulation).
So i must have missed something but what ? Maybe finite difference is not the tool to use in case of diffusion-only and are actually used because of the reaction term, but still, if I understand well, one can separate the simulation into smaller sub-time steps to perform only diffusion or only proliferation (solved analytically for the later) with Douglas-Gunn or equivalent approaches. In such a case, the diffusion step can still be solved using a simple matrix multiplication at each step which do not require a long processing ? So I would be very happy if someone can tell me if I'm going on the right track or if (as I suspect) I missed any fundamental issue...
Many thanks !
D. Guez