FinalFunctional fails in tutorial2.py

Asked by Glen D. Granzow

When running the example program tutorial2.py from http://dolfin-adjoint.org/documentation/tutorial.html

from dolfin import *
from dolfin_adjoint 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)

F = ((u_next - u)/timestep*v
    + u_next*grad(u_next)*v
    + nu*grad(u_next)*grad(v))*dx
bc = DirichletBC(V, 0.0, "on_boundary")

t = 0.0
end = 0.2
while (t <= end):
  solve(F == 0, u_next, bc)
  u.assign(u_next)
  t += float(timestep)

J = FinalFunctional(inner(u, u)*dx)
dJdic = compute_gradient(J, InitialConditionParameter(u), forget=False)
dJdnu = compute_gradient(J, ScalarParameter(nu))

I get the error message

NameError: name 'FinalFunctional' is not defined

Question information

Language:
English Edit question
Status:
Solved
For:
dolfin-adjoint Edit question
Assignee:
No assignee Edit question
Solved by:
Glen D. Granzow
Solved:
Last query:
Last reply:
Revision history for this message
Glen D. Granzow (ggranzow) said :
#1

I see now that someone had reported this as a bug (https://bugs.launchpad.net/dolfin-adjoint/+bug/1027046) and there is some useful information posted in response.

Revision history for this message
Glen D. Granzow (ggranzow) said :
#2

I made the change described at https://bugs.launchpad.net/dolfin-adjoint/+bug/1027046 and tutorial2.py now runs without any error messages.