I'm solving a mixed problem and I define the energy function and using derivative() to obtain the weak form according the hyperelasticity example(https://fenics.readthedocs.io/projects/dolfin/en/latest/demos/demo_hyperelasticity.py.html#demo-hyperelasticity). But I'm not able to get it right somehow. Below is the minimal working code snippet. Any help is greatly appreciated!
from dolfin import *
import numpy as np
mesh = UnitSquareMesh(32,32)
U = VectorElement("Lagrange",mesh.ufl_cell(), 1, dim=2) # displacement
M = FiniteElement("Lagrange",mesh.ufl_cell(), 1) # mu
W = VectorElement("Lagrange",mesh.ufl_cell(), 1, dim=2) # Lagrangian multipliers
S = FunctionSpace(mesh, MixedElement([U,M,W]))
v, q, w = TestFunctions(S)
u, mu, lamd = TrialFunctions(S)
L = inner(u,u)*dx + inner(grad(mu),grad(mu))*dx + \
inner(mu*(grad(lamd)+grad(lamd).T), grad(u)+grad(u).T)*dx + inner(div(lamd),div(u))*dx
ds = TestFunction(S)
du = TrialFunction(S)
s = Function(S)
F = derivative(L, s, ds)
JF = derivative(F, s, du)
bc = DirichletBC(S.sub(0), Constant([0.0,0.0]), "on_boundary")
problem = NonlinearVariationalProblem(F,s,bc,JF)
solver = NonlinearVariationalSolver(problem)
solver.solve()
u_s, mu_s, lamd_s = s.split()
The error message is
*** Error: Unable to define nonlinear variational problem F(u;v)=0 for all v.
*** Reason: Expecting the residual F to be a linear form (not rank 2).
By the way, I tried this on both fenics 2016.1.0 and 2016.2.0 and got the same error.