# discretizing advection equation with variable wave speed + stability

I currently have a code that solves $$u_t+ cu_x=0$$ with periodic boundary conditions, and constant $$c$$ (using an upwind method). I'm wondering how I would alter this code to solve something of the form $$u_t +c(x) u_x=0.$$ I'm thinking it will look of like

$$u_i^{j+1}=u_i^j-c_i \Delta t \left(\frac{u_i^j-u_{i-1}^j}{\Delta x} \right),$$ where $$c_i=c(x_i)$$?

I know that generally, the upwind scheme is stable for $$c \frac{\Delta t}{\Delta x} \leq 1$$. How would this change with a variable $$c$$? Am I better off using another method?

• Your thinking is right, for variable C you can encounter CFL violation at a specific location, and that would set the time step limit for the whole thing. This situation often happens for non-uniform grids, if one cell is small then the CFL condition there would constrain the time step for the whole calculation. – Maxim Umansky Oct 22 '20 at 19:04
• hm okay thank you! that's a bit concerning since I will be using a non-uniform grid, I'll look into the CFL condition. – lrs417 Oct 23 '20 at 0:10
• make sure that your advection field $c(x)$ is solenoidal, i.e. $\nabla \cdot c(x) = 0$, otherwise you will find that the advective effects will transport mass into or out of a region! In the absence of diffusion this would produce blowup. – MPIchael Oct 23 '20 at 8:10