Week solution of the equation $u_t + u^2u_x = f(x,t)$

Derive the weak formulation of the partial differential equation
\[u_t + u^2u_x = f(x,t)\]
with the initial value $u(x,0)=u_0(x)$.

Please provide a detailed ans easy to follow solution. 

Answer

First note that by the chain rule $$\frac{\partial}{\partial x} \Bigg(\frac{1}{3} u(x,t)^3 \Bigg) = \frac{\partial u}{\partial x}\frac{\partial}{\partial u}\Bigg(\frac{1}{3} u(x,t)^3 \Bigg) = u_x u^2.$$

Multiply the PDE $$ u_t + \frac{1}{3} \big(u^3\big)_x = f(x,t)$$ with a testfunction $\phi(x, t) \in C_c^1\big(\mathbb{R} \times \mathbb{R}_+ \big) $ to obtain

$$ \Bigg(u_t + \frac{1}{3} \big(u^3\big)_x \Bigg) \phi(x, t) = f(x,t) \phi(x, t).$$
Integrate to get
$$ \int_\mathbb{R} \int_{\mathbb{R}_+} \Bigg(u_t + \frac{1}{3} \big(u^3\big)_x \Bigg) \phi(x, t) \:\mathrm dt \:\mathrm dx = \int_\mathbb{R} \int_{\mathbb{R}_+} f(x,t) \phi(x, t) \:\mathrm dt \:\mathrm dx$$
Integrate by parts and use the product rule to obtain

$$ \int_\mathbb{R} \int_{\mathbb{R}_+} u_t \phi(x, t) + \Bigg(\frac{1}{3} \big(u^3\big)_x \Bigg) \phi(x, t) \:\mathrm dt \:\mathrm dx = \int_\mathbb{R} \int_{\mathbb{R}_+} -u \phi_t + \Bigg(\frac{1}{3} \big(u^3\big)_x \Bigg) \phi \:\mathrm dt + u \phi \Big \vert^\infty_0 \:\mathrm dx$$

Since the support of $\phi$  is compact, for bounded $u(x,t)$ we have
$$\lim_{t\to \infty} u(x, t) \phi(x, t) = 0$$
and thus
$$\int_\mathbb{R} \int_{\mathbb{R}_+} \Bigg(u_t + \frac{1}{3} \big(u^3\big)_x \Bigg) \phi(x, t) \:\mathrm dt \:\mathrm dx = \int_\mathbb{R} \int_{\mathbb{R}_+} -u \phi_t + \Bigg(\frac{1}{3} \big(u^3\big)_x \Bigg) \phi \:\mathrm dt - u(x, 0) \phi(x, 0) \:\mathrm dx$$

Similarly

$$\int_\mathbb{R} \Bigg(\frac{1}{3} \big(u^3\big)_x \Bigg) \phi(x, t) \:\mathrm dx = \int_\mathbb{R} -\Bigg(\frac{1}{3} \big(u^3\big) \Bigg) \phi_x \:\mathrm dx + u\phi \Big \vert^\infty_{-\infty}$$ and again $u\phi \Big \vert^\infty_{-\infty}$ vanishes due to the fact that $\phi$ has compact support. The weak formulation is given by $$\int_\mathbb{R} \int_{\mathbb{R}_+} -u \phi_t -\Bigg(\frac{1}{3} u^3 \Bigg) \phi_x \:\mathrm dt \:\mathrm dx - \int_\mathbb{R} \underbrace{u(x, 0)}_{u_0(x)} \phi(x, 0) \:\mathrm dx = \int_\mathbb{R} \int_{\mathbb{R}_+} f(x,t) \phi(x, t) \:\mathrm dt \:\mathrm dx.$$

The answer is accepted.