<jupyter_start><jupyter_text>Advection We start our study with the scalar, linear hyperbolic PDE: the advection equation.  In this chapter we consider one of the most simple hyperbolic conservation laws, the scalar constant-coefficient advection equation. The solution to this equation simply consists of the initial condition propagating with constant velocity. This equation is extremely important to understand before tackling linear hyerbolic systems, which can be solved by decoupling the system into a set of advection equations. We first describe the physical origin of this equation and then investigate the solution to its Riemann problem. This equation is studied in more detail in Chapter 2 of (LeVeque, 2002).  Conservation of massImagine a fluid flowing in a long, narrow tube.  We'll use $q$ to indicate the density of the fluid and $u$ to indicate its velocity.  Both of these are functions of space and time: $q = q(x,t)$; $u=u(x,t)$.  The total mass in the section of tube $[x_1,x_2]$ is  \begin{equation*}\int_{x_1}^{x_2} q(x,t) dx.\end{equation*}  This total mass can change in time due to fluid flowing in or out of this section of the tube.  We call the rate of flow the *flux*, and represent it with the function $f(q)$.  Thus the net rate of flow of mass into (or out of) the interval $[x_1,x_2]$ at time $t$ is  $$f(q(x_1,t)) - f(q(x_2,t)).$$  We just said that this rate of flow must equal the time rate of change of total mass; i.e.  $$\frac{d}{dt} \int_{x_1}^{x_2} q(x,t) dx = f(q(x_1,t)) - f(q(x_2,t)).$$  Now since $\int_{x_1}^{x_2} \frac{\partial}{\partial x} f(q) dx = f(q(x_2,t)) - f(q(x_1,t))$, we can rewrite this as  $$\frac{d}{dt} \int_{x_1}^{x_2} q(x,t) dx = -\int_{x_1}^{x_2} \frac{\partial}{\partial x} f(q) dx.$$  Under certain smoothness assumptions on $q$, we can move the time derivative inside the integral.  We'll also put everything on the left side, to obtain  $$\int_{x_1}^{x_2} \left(\frac{\partial}{\partial t}q(x,t) + \frac{\partial}{\partial x} f(q)\right) dx = 0.$$  Since this integral is zero for *any* choice of $x_1,x_2$, it must be that the integrand (the expression in parentheses) is actually zero *everywhere*!  Therefore we can write the **differential conservation law**  $$q_t + f(q)_x = 0.$$  This equation expresses the fact that the total mass is conserved, since locally the mass can change only due to a net inflow or outflow.  AdvectionIn order to solve the conservation law above, we need an expression for the flux, $f$.  The rate of flow is just mass times velocity: $f=u q$.  Thus we obtain the **continuity equation**  $$q_t + (uq)_x = 0.$$  In general, we need another equation to determine the velocity $u(x,t)$.  In later chapters we'll examine models in which the velocity depends on the density (or other properties), but for now let's consider the simplest case, in which all of the fluid flows at a single, constant velocity $u(x,t)=a$.  Then the continuity equation becomes the **advection equation**  \begin{align} \label{adv:advection}    q_t + a q_x = 0.\end{align}  This equation has a very simple solution.  If we are given the density $q(x,0)=q_0(x)$ at time zero, then the solution is just  \begin{align} \label{adv:solution}    q(x,t) = q_0(x-at).\end{align}<jupyter_code>%matplotlib inline
%config InlineBackend.figure_format = 'svg'
from ipywidgets import interact
from exact_solvers import advection<jupyter_output><empty_output><jupyter_text>To examine the Python code for this chapter, see: - [exact_solvers/advection.py](exact_solvers/advection.py)  CharacteristicsNotice that the solution is constant along the line $x-at=C$, for each value of $C$.  These are parallel, straight lines in the $x-t$ plane, with slope $1/a$, as shown in the figure below.<jupyter_code>interact(advection.characteristics);<jupyter_output><empty_output><jupyter_text>We can think of the initial values $q_0(x)$ being transmitted along these lines; we sometimes say that *information* is transmitted along characteristics. The next figure shows how an initial hump propagates to the right along characteristics.<jupyter_code>interact(advection.solution);<jupyter_output><empty_output><jupyter_text>For more complicated hyperbolic problems, we may have multiple sets of characteristics, they may not be parallel, and the solution may not be constant along them.  But it will still be the case that information is propagated along characteristics.  The idea that information propagates at finite speed is an essential property of hyperbolic PDEs.  The Riemann problemThe Riemann problem consists of a hyperbolic PDE, such as (\ref{adv:advection}), together with piecewise constant initial data consisting of two states.  For convenience, we place the interface (or jump) at $x=0$ and refer to the left state (for $x0$) as $q_r$.  We thus have  \begin{align*}    q_0(x) & = \begin{cases} q_l & x0. \end{cases}\end{align*}  For the advection equation, the solution to the Riemann problem is immediately obvious; it is simply a special case of (\ref{adv:solution}).  The discontinuity initially at $x=0$ moves at speed $a$.  We have  \begin{align*}    q(x,t) & = \begin{cases} q_l & x-at0. \end{cases}\end{align*}<jupyter_code>interact(advection.riemann_demo);<jupyter_output><empty_output><jupyter_text>Notice how the initial discontinuity follows the characteristic coming from $x=0$ at $t=0$.Here's another way to look at the Riemann solution that will be very useful for more complicated equations.<jupyter_code>q_l = 1.
q_r = 0.
advection.plot_riemann_solution(q_l, q_r, a=1.);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09940891993551854, 'fraction_numerical': 0.00877664338169443, 'mean_word_length': 4.9785867237687365, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '347108', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1648, 'n_words': 745, 'path': 'Advection.ipynb', 'repo_name': 'haraldschilly/riemann_book', 'size': '5583'}