The dolfin-adjoint project automatically derives the discrete adjoint and tangent linear models from a forward model written in the Python interface to DOLFIN.

  • Sensitivity analysis on a Klein bottle.

    # Define variational formulation
    F = inner(grad(u), grad(v))*dx - inner(m, v)*dx
    
    # Solve the variational form
    solve(F == 0, u)
    
    # Compute the sensitivity
    J = Functional(inner(u, u)*dx)
    m = Control(f)
    dJdm = compute_gradient(J, m)
    
    # Plot the results
    plot(dJdm)
  • Growing the optimal heat-sink.

    # Define variational formulation
    F = inner(grad(v), k(a)*grad(T))*dx - f*v*dx
    
    # Specify control and compliance as objective
    J = Functional(f*T*dx)
    m = Control(a)
    Jhat = ReducedFunctional(J, m)
    
    # Run optimization
    constraint = VolumeConstraint(V=0.4)
    nlp = rfn.pyipopt_problem(bounds=(lb, ub),
                     constraints=constraint)
    a_opt = nlp.solve(full=False)