Or
$$\frac{\partial\phi}{\partial t} + u\frac{\partial\phi}{\partial x} = \Gamma \frac{\partial^2\phi}{\partial x^2},$$where $u$ is a velocity, $\phi$ is our scalar variable, and $\Gamma$ is a diffusion coefficient (like $\alpha$).
* Unsteady species transport equation.
Or, $$c^2\le2d\le 1.$$
Divide through by $\frac{\Gamma}{\Delta x}$:
$$\phi_W\left(-\frac{Pe}{2} -1 \right) + \phi_P(2) + \phi_E\left(\frac{Pe}{2} - 1\right) = 0.$$Solve the above equation for $\phi_P$ in terms of its neighbors:
$$\phi_P = \frac{1}{2}\left[\phi_W\left(\frac{Pe}{2} + 1\right) - \phi_E\left(\frac{Pe}{2}-1\right)\right].$$import ipywidgets as wgt
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def f(Pe):
ϕw = 2
ϕe = 1
ϕp = 1/2*(ϕw*(Pe/2 + 1) - ϕe*(Pe/2 - 1))
ϕ = np.array([ϕw,ϕp,ϕe])
x = np.array([0, 1, 2])
plt.rc("font", size=14)
plt.plot(x,ϕ,'o-', markersize=10, lw=3)
plt.ylim([0,3])
plt.xlabel('x')
plt.ylabel('ϕ')
plt.grid()
plt.show()
wgt.interact(f, Pe=(-5,5,0.1)); # try adding string and list arguments...
interactive(children=(FloatSlider(value=0.0, description='Pe', max=5.0, min=-5.0), Output()), _dom_classes=('w…
Following Patankar, we can write our above equation as
$$C_p \phi_P = C_E\phi_E + C_W\phi_W,$$where $C$'s are coefficients of the $\phi$'s.
The problem above is that we applied a central difference approximation when evaluating the convective term.
These approaches effectively give equal weighting to the neighbors when computing a property.
There is no change to the diffusion term. Diffusion has no directionality. Use central differences.
Solve for $\phi_P$:
$$\phi_P = \phi_E\left[\frac{\frac{\Gamma}{\Delta x}}{u + 2\frac{\Gamma}{\Delta x}}\right] + \phi_W\left[\frac{u+\frac{\Gamma}{\Delta x}}{u + 2\frac{\Gamma}{\Delta x}}\right], $$Or,
$$\phi_P = \phi_E\left[\frac{1}{Pe+2}\right] + \phi_W\left[\frac{Pe+1}{Pe+2}\right]. $$Here, the coefficients are always positive for any value of $Pe$.
Note, this method is $\mathcal{O}(\Delta t)$, but only $\mathcal{O}(\Delta x)$. The upwinding is first order spatially.