Energy conservation for semidiscrete Galerkin advection (source code)

= Energy conservation for semidiscrete Galerkin advection

For periodic $u_t=u_x$, the conforming <Galerkin method> has $M\dot U=CU$, with <mass matrix> $M_{ij}=\int\phi_i\phi_j$ and $C_{ij}=\int\phi_i\phi_j'$. <Integration by parts> and periodicity give $C^T=-C$. Therefore
$$
\frac{d}{dt}(U^TMU)=2U^TCU=0.
$$
The conserved quantity is the squared <L2 norm> of the <finite element> function. On a uniform one-dimensional mesh of spacing $h$, the <piecewise-linear hat functions> give $M_{ii}=2h/3$, $M_{i,i\pm1}=h/6$, $C_{i,i+1}=1/2$ and $C_{i,i-1}=-1/2$.