# Finite difference method not working for advection PDE with negative coefficient

I'm trying to solve a very simple advection PDE

$\frac{\partial u}{\partial t}+c\frac{\partial u}{\partial x}=0$

where $c<0$.

I have been able to implement a simple Modelica code to solve the equation and it works just fine for $c>0$ with the exact same boundary conditions, though. So my question is why my code is not able to finish the simulation:

1. Is it a mathematical issue? Like such PDE never has a solution for $c<0$?
2. is it a finite difference limitation and maybe I should use other numerical methods?
3. or there is some issue with the code or Modelica compiler?

I would appreciate if you could help me figure this issue out.

P.S. the goal for me is to learn how to solve PDEs in Modelica and this is just one example.

and it works just fine for c>0 with the exact same boundary conditions, though.

That's your issue. Look up the method of characteristics:

https://web.stanford.edu/class/math220a/handouts/firstorder.pdf

The characteristics for a 1D advection problem flow in one direction. So there are two things involved. One is that the BCs on one side of the interval matter since the characteristics are only flowing in one direction. Secondly,

https://en.wikipedia.org/wiki/Upwind_scheme

the upwind scheme has to change directions depending on the direction of the characteristics. So you need to change your implementation to match the direction as given by sign(c). When c<0, you need to use u[i+1] instead of u[i-1].

• I'm not sure if I understand this correctly. would you be so kind to implement in Modelica? you may edit my post in SO?