Solution of Burgers' equation Can you help me to solve this problem and explain the method used?
$u\equiv u(x,t)$ with $x\in\mathbb{R}$
$$ u_t+\left( \frac{1}{2}u^2\right)_x=0 $$
with initial data
$$u_0(x)=u(x,0)=
\begin{cases}
1-x^2, &\text{for } x\in [-1,1] \\\\
0,     &\text{else}
\end{cases}
$$
I tried to find $u$ using $u=u_0(x-ut)$ but I don't get the solution. In particular with the boundary conditions.
Thanks for your help.

EDIT:
Solving with the characteristics method I find this solution
$$u(x,t)=1-\left( \frac{1\pm \sqrt{(1-4\chi t (x-\chi t)}}{2\chi t} \right)^2$$
where $\chi\equiv\chi_{[-1,1](x)}$
Solving with Upwind scheme for Burgers's equation the solution does not agree with the numerical one. 

 A: I will be using method of characteristics (which is described in Wikipedia article for Burger's euqation in detail).
Writing down the equation:
$$\frac{\partial u}{\partial t}+u\frac{\partial u}{\partial x}=0$$
This has the form of a full time derivative for some function:
$$\frac{du}{dt}=\frac{\partial u}{\partial t}+\frac{\partial u}{\partial x} \frac{dx}{dt}$$
Which gives us the following system of ODEs:
$$\frac{du}{dt}=0 \\ \frac{dx}{dt}=u$$
The solutions have the form:
$$u=u_0 \\ x=x_0+u_0 t$$
This seems surprising, but actually this means that for any $x$:

$$u \left(x+u(x,0)t,t \right)=u(x,0) \tag{1}$$

Now we want to get an explicit solution using our initial conditions.


*

*First, consider the simple case $|x|>1$, which means $u(x,0)=0$:



$$u(x,t)=u(x,0)=0  \tag{2}$$



*

*Now, the case $|x| \leq 1$, which means $u(x,0)=1-x^2$:


Let's make a substitution:
$$x+(1-x^2)t=y$$
We need to find $x(y,t)$ now to substitute on the right hand side of $(1)$:
$$t x^2-x+y-t=0$$

$$x=\frac{1}{2t} (1 \pm \sqrt{1+4t(t-y)})$$

Which makes our solution in this range to be:
$$u(y,t)=1-\frac{1}{4t^2} (1 \pm \sqrt{1+4t(t-y)})^2$$
Or, simply renaming the variable again, we have:

$$u(x,t)=1-\frac{1}{4t^2} (1 \pm \sqrt{1+4t(t-x)})^2 \tag{3}$$

You can directly check (by taking the derivatives) that the original equation is satisfied by this function.

If we want the limit at $t \to 0$ to exist, we need to choose the "$-$" sign in (3).


One thing we need to account for is the range $|x| \leq 1$ which separates the first solution from the second one. Not sure if we just can set the same condition on $y$ or not.
Let's consider the condition on $x$:
$$\left| \frac{1}{2t} (1 - \sqrt{1+4t(t-y)}) \right| \leq 1$$
Assume $t>0$:
$$\left| 1 - \sqrt{1+4t(t-y)} \right| \leq 2t$$
The solution is quite interesting:
$$-1 \leq y \leq 1, \qquad t \leq \frac12$$
$$-1 \leq y \leq \frac{4t^2+1}{4t}, \qquad t > \frac12$$
The latter case contradicts the initial condition on $x$ which we used to get our first, zero solution.
When plotting the solution in Mathematica for different times we see a 'crashing wave', which initially, doesn't go beyond $x=1$.


However, for larger times, it does go beyond the initial boundary:

A: As you have a right-moving phase left of a stationary phase, you will get a shock front that separates both. At the points $(t,y_s(t))$ of the shock front, the equation $y_s(t)=x+tu_0(x)$ has two solutions, $x_1(t)\in(-1,1)$ and $x_2(t)=y(t)\ge 1$. As 
$$
y=x+t(1-x^2)\iff 4ty=1+4t^2-(2tx-1)^2
$$
the maximum of $y$ for fixed $t$ and $x\in[-1,1]$ is 


*

*at $x=1$ for $t<\frac12$ with $y_{max}=1$ and 

*at $x=\frac1{2t}$ with $y_{max}=\frac1{4t}+t$ after that.


This means that the phases "start colliding" at $t=\frac12$. 
It is known that the shock front moves at the mean of the speeds of the phases, in this case at 
$$
y_s'(t)=\frac12u_0(x_1(t)),~~ y_s(\frac12)=1,
$$ 
as $u_0(x_2(t))=0$. On the other hand we know that
$$
y_s'(t)=x_1'(t)+u_0(x_1(t))+tu_0'(x_1(t))x_1'(t)
$$
which allows to translate the differential equation for $y_s$ into a differential equation for $x_1$,
$$
-\frac12(1-x_1^2)=(1-2tx_1)x_1',~~ x_1(\frac12)=1
\\~\\
(1-x_1^2)\frac{dt}{dx_1}=4x_1t-2,~~ t(1)=\frac12
$$
which can be solved as linear ODE
$$
\frac{d}{dx}\left(t(x)(1-x^2)^2\right)=t'(x)(1-x^2)^2-4t(x)x(1-x^2)=-2(1-x^2)
\\~\\
t(x)=\frac{-2(3x-x^3)+C}{3(1-x^2)^2}.
$$
To get a finite value at $t(1)$ we get necessarily $C=4$ so that 
$$
t(x)=\frac{2(2+x)}{3(1+x)^2}
$$
indeed satisfies the initial condition. Solving the quadratic equation for $x_1(t)\in[-1,1]$ gves
\begin{align}
&&9t^2(1+x)^2&=2(3t(1+x))+6t
\\&
\iff&(3t(1+x)-1)^2&=1+6t
\\&
\implies& x_1(t)&=\frac{1+\sqrt{1+6t}}{3t}-1=\frac{1-3t+\sqrt{1+6t}}{3t}
\\&
\implies& y_s(t)&=\frac{1-3t+\sqrt{1+6t}}{3t}+t\left(1-\frac{2+9t^2+2(1-3t)\sqrt{1+6t}}{9t^2}\right)
\\&&
&=\frac{1-3t+\sqrt{1+6t}}{3t}-\frac{2+2(1-3t)\sqrt{1+6t}}{9t}
\\&&
&=\frac{1-9t+(1+6t)\sqrt{1+6t}}{9t}
\end{align}

python script for the picture
tf = 3.0
for x in np.arange(-1.5,tf,0.05):
    u = 0; ts = tf
    if abs(x)<1: u = 1-x**2; ts = min( tf, 2*(2+x)/(3*(1+x)**2))
    plt.plot([x, x+ts*u], [0, ts], 'b',lw=0.5)
    if ts < tf: ys = x+ts*u; plt.plot( [ys,ys], [0,ts], 'b', lw = 0.5)

t = np.arange(0.5,tf+1e-3,0.05);
ys = (1-9*t+(1+6*t)**1.5)/(9*t)
plt.plot(ys,t,'r',lw=2.5); 
plt.xlabel('x'); plt.ylabel('t'); 
plt.title('method of lines with shock front'); 
plt.grid(); plt.show()

