You can use
u1.assign(ic)
if ic
is a Function
in V
(as the output of interpolate
would be). The argument may also be a constant-coefficient linear combination of Function
s in V
. Setting u0
depends on having another initial condition for the velocity, or knowing u(t_0-\Delta t) directly.
You might also consider re-arranging the time integrator to use a displacement and velocity from the previous time step, as implemented in my answer here:
Another note: If you initialize the wave equation with discontinuous data, you will likely get spurious oscillations in the solution without some form of additional stabilization or shock capturing. (That was one of the demonstrative examples considered in this paper. FEniCS code for the wave equation test is here, but it uses an additional library I wrote to do isogeometric analysis with FEniCS.)