This presentation by the Imperial College in London has a nice example in it, on page 8, Burgers Equations. The first part of their code reads like this:
from dolfin import*
n = 30
mesh = UnitInterval(n)
V = FunctionSpace(mesh, "CG",2)
ic = project(Expression("sin(2*pi*x[0])"), V)
u = Function(ic)
u_next = Function(V)
v= TestFunction(V)
nu = Constant(0.0001)
timestep = Constant(1.0/n)
F1 = ((u_next - u)/timestep*v)*dx
F2 = (u_next*grad(u_next)*v)*dx
F3 = (nu*grad(v)*grad(u_next))*dx
On my system, this code fails, giving shape mismatch errors for the sums F2
and F3
. I don't understand why.