# Simulating First Order Hyperbolic PDE with Finite Difference Scheme

I am trying to simulate a hyperbolic PDE with some control given by the following:

$$u_t(x, t) = u_x(x, t) + \theta(x) u(0, t)$$

with boundary conditions:

$$u(1, t) = U(t) = \int_0^1 k(1-y) u(y, t)dy$$

We use the finite difference scheme with initial condition $$u(x, 0) = c$$ with $$c > 0$$. $$i$$ is discretization in time and $$j$$ is in space.

$$\frac{u_j^{i+1} - u_j^{i}}{dt} = \frac{u_{j+1}^i - u_{j}^i}{dx} + \theta(x) u_0^i$$

Solving yields:

$$u_j^{i+1} = u_j^i + dt*(\frac{u_{j+1}^i - u_{j}^i}{dx} + \theta(x) u_0^i)$$

I directly implemented this in a Python script and the control seems to work quite well, but I get this very odd-looking distribution at the start due to the finite difference scheme. This occurs when I set the control to 0 as well.  I believe it is due to the fact the way the initial condition interacts with the time-difference scheme. Is this expected behavior? If not, where is the mistake I am making?

# Simulate PDE to show that this kernel works
T = 2
dt = 0.01
nt = int(round(T/dt))
dx = 0.01
nx = 101
X = np.linspace(0, 1, nx)

u = np.zeros((nt, nx))
c = 10

# Solve for control
def solveControl(kappa, u):
result = 0
for i in range(0, nx):
result += (kappa[nx-i-1]*u[i])*dx
return result

# Set intial condition
for i in range(nx):
u[i] = c

for i in range(1, nt):
u[i][-1] = solveControl(kappa, u[i-1])
for j in range(0, nx-1):
u[i][j] = u[i-1][j] + dt*((u[i-1][j+1] - u[i-1][j])/dx + theta[j]*u[i-1])

• Simplify. Consider a case with no control and a known exact solution. Do you converge to the known solution? Jan 12 at 21:35
• I believe I do converge to the known solution. My issue is the initial time steps I get this odd behavior that is like this slanted initial step function and I'm not sure why Jan 15 at 23:49
• If you do converge, then the steps are part of the solution. If the steps are unphysical, then you don't converge. So I'd say you have to improve on your "I believe" part and run some rigorous convergence studies for an early end time. Jan 16 at 5:23

The reason for this line-like phenomenon is due to the finite difference scheme. Since $$dx$$ and $$dt$$ have the same discretization, the control is not able to propagate fast enough. The code is correct and will produce beautiful results with $$dt \ll dx$$ (so dt = 0.001 and dx =0.01) for example.