# Derivation of a parabolic PDE using Alternating Direction Implicit method

I have a very simple question concerning Alternating Direction Implicit (ADI) Scheme.

If I have an equation of the form:

$$\begin{equation*} \frac{df(x,y,t)}{dt} = \nabla^2 f(x,y,t) + f(x,y,t) \end{equation*}$$

with f, my unknown function.

I know how to use it for the diffusion term, but how should I handle the term $$f(x,y,t)$$?

Starting from Crank-Nicolson, I can write:

$$\begin{equation*} \frac{f^{t+1}_{i,j} - f^{t}_{i,j}}{\Delta t} = \frac{1}{2}(\frac{f_{i+1,j}^{t} - 2 f_{i,j}^{t} + f_{i-1,j}^{t}}{dx^2} + \frac{f_{i+1,j}^{t+1} - 2 f_{i,j}^{t+1} + f_{i-1,j}^{t+1}}{dx^2} \\ + \frac{f_{i,j+1}^{t} - 2 f_{i,j}^{t} + f_{i,j-1}^{t}}{dy^2} + \frac{f_{i,j+1}^{t+1} - 2 f_{i,j}^{t+1} + f_{i,j-1}^{t+1}}{dy^2}) + \frac{1}{2}(f_{i,j}^{t} + f_{i,j}^{t+1}) \end{equation*}$$

Then, solving implicitly in x and explicitly in y, using ADI, with * beeing the intermediate timestep:

$$\begin{equation*} \frac{f^{*}_{i,j} - f^{t}_{i,j}}{\frac{\Delta t}{2}} = \frac{f_{i+1,j}^{*} - 2 f_{i,j}^{*} + f_{i-1,j}^{*}}{dx^2} + \frac{f_{i,j+1}^{t} - 2 f_{i,j}^{t} + f_{i,j-1}^{t}}{dy^2} \\ + \frac{1}{2}(f_{i,j}^{t} + f_{i,j}^{*}) \end{equation*}$$

And after, solving explicitly in x and implicitly in y, using ADI, taking the previous result:

$$\begin{equation*} \frac{f^{t+1}_{i,j} - f^{*}_{i,j}}{\frac{\Delta t}{2}} = \frac{f_{i+1,j}^{*} - 2 f_{i,j}^{*} + f_{i-1,j}^{*}}{dx^2} + \frac{f_{i,j+1}^{t+1} - 2 f_{i,j}^{t+1} + f_{i,j-1}^{t+1}}{dy^2} \\ + \frac{1}{2}(f_{i,j}^{*} + f_{i,j}^{t+1}) \end{equation*}$$

I know how to solve everything, my question concerns the term $$f(x,y,t)$$: is that correct to take the mean between the value at t and * for the first step and the mean of time * and t+1 on the second step?

Thank you very much!

Yes, this is correct in the sense that it is second order in both time and space. It is not the only way to handle the $$f(x, y, t)$$ term, however.
From the equations you wrote, it appears that the PDE has been partitioned in the following way \begin{align*} \frac{\partial f(x,y,t)}{\partial t} &= \nabla^2 f(x, y, t) + f(x, y, t) \\ &= \underbrace{\frac{\partial^2 f(x,y,t)}{\partial x^2} + \frac{1}{2} f(x,y,t)}_\text{x-direction} + \underbrace{\frac{\partial^2 f(x,y,t)}{\partial y^2} + \frac{1}{2} f(x,y,t)}_\text{y-direction}. \end{align*} Alternatively, you could move the $$f(x,y,t)$$ entirely in the x-direction or entirely in the y-direction. It is somewhat arbitrary how the term is distributed as long as it sums to $$f(x,y,t)$$. Let's stick with this half-in-each approach, though.
Here is another way to check that this is correct. For simplicity, let's ignore the diffusion term since that wasn't your concern, and we can focus on the treatment of the $$f(x,y,t)$$. So consider the ODE $$\frac{\partial f(x,y,t)}{\partial t} = f(x,y,t).$$ From the first part of the ADI method, we have that $$\frac{f^*_{i,j} - f^t_{i,j}}{\frac{\Delta t}{2}} = \frac{f^t_{i,j} + f^*_{i,j}}{2} \quad \Rightarrow \quad f^*_{i,j} = \frac{1+\frac{\Delta t}{4}}{1-\frac{\Delta t}{4}} f^t_{i,j}.$$ Similarly, the second part give \begin{align*} f^{t+1}_{i,j} &= \frac{1+\frac{\Delta t}{4}}{1-\frac{\Delta t}{4}} f^*_{i,j} \\ &= \left(\frac{1+\frac{\Delta t}{4}}{1-\frac{\Delta t}{4}}\right)^2 f^t_{i,j} \\ &= \left( 1 + \Delta t + \frac{\Delta t^2}{2} + \frac{3 \Delta t^3}{16} + \cdots \right) f^t_{i,j}. \end{align*} This is the linear stability function for two half-steps of CN. It matches the exact solution of $$e^{\Delta t} f^t_{i,j}$$ up to $$\mathcal{O}(\Delta t^3)$$, and thus, it is order two.