derivatives with respect to boundary conditions
Is dolphin_adjoint capable of taking derivatives with respect to the constants that appear in Dirichlet boundary conditions? The code below, which produces the output:
Solving linear variational problem.
Solving linear variational problem.
Solving linear variational problem.
Solving linear variational problem.
-------
f = 0.333333 (exact value is 0.333333)
df/da = None (exact value is 0.5)
df/db = None (exact value is 0.5)
df/dc = -0.0833333333333 (exact value is -0.083333)
-------
is an example problem that illustrates my attempt to calculate such derivatives.
# The solution to the ODE u" = c with u(0) = a, u(1) = b is
# u(x) = (c/2) x(x-1) + b x + a (1-x).
# Integrating u from 0 to 1 gives -c/12 + b/2 + a/2.
# So the partial derivative of this integral with respect to c is -1/12,
# the partial derivative with respect to b is 1/2, and the partial
# derivative with respect to a is 1/2.
# This script uses dolfin-adjoint to try to find these derivatives.
# Written by Glen D. Granzow on September 19, 2012.
from dolfin import *
from dolfin_adjoint import *
if __name__ == '__main__':
a = Constant(0.0)
b = Constant(1.0)
c = Constant(2.0)
mesh = UnitInterval(10)
functionSpace = FunctionSpace(mesh, 'Lagrange', 2)
u = TrialFunction(
v = TestFunction(
solution = Function(
bc = [DirichletBC(
solve(
f = Functional(
dfda = compute_gradient(f, ScalarParameter(a), forget=False)
dfdb = compute_gradient(f, ScalarParameter(b), forget=False)
dfdc = compute_gradient(f, ScalarParameter(c), forget=True)
print '------
print 'f = %f (exact value is %f)' % (assemble(
print 'df/da = %s (exact value is 0.5)' % dfda
print 'df/db = %s (exact value is 0.5)' % dfdb
print 'df/dc = %s (exact value is %f)' % (dfdc, -1.0/12.0)
print '------
The problem is that in the output "df/da = None" and "df/db = None" instead of the anticipated numerical values.
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Glen D. Granzow
- Solved:
- Last query:
- Last reply: