Solving a linear conservation law subject to initial and final conditions