Question #123984 on DOLFIN changed: https://answers.launchpad.net/dolfin/+question/123984
Status: Open => Answered Johan Hake proposed the following answer: Dominique! Take a look in the hyperelastisity demo, where the energy is differentiated wrt the displacement twice: http://www.fenics.org/doc/demos/pde/hyperelasticity/python/documentation.html Johan On Friday September 3 2010 09:28:17 Dominique wrote: > New question #123984 on DOLFIN: > https://answers.launchpad.net/dolfin/+question/123984 > > Hello, > > I am trying to use derivative() twice to compute the second-derivatives of > a variational form with respect to the unknown. Here is an example > program: > > --- > from dolfin import * > import numpy as np > > mesh = UnitSquare(5,5) > V = FunctionSpace(mesh, 'CG', 1) > u = Function(V) > v = TestFunction(V) > a = dot(grad(v), (1+u**2) * grad(u))*dx # Nonlinear variational form > > # First derivative of a. > du = TrialFunction(V) > da = derivative(a, u, du) > > # Second derivative of a. > d2u = TrialFunction(V) > d2a = derivative(da, u, d2u) > > # Evaluate a somewhere. > u.vector()[:] = np.random.random(V.dim()) > a_val = assemble(a, mesh=mesh) ; print 'a(u) = ', a_val > > # Evaluate da somewhere. > da_val = assemble(da, mesh=mesh) ; print 'da(u) = ', da_val > > # Evaluate d2a somewhere. > d2a_val = assemble(d2a, mesh=mesh) ; print 'd2a(u) = ', d2a_val > --- > > The first two 'print' commands output: > > a(u) = <PETScVector of size 36> > da(u) = <PETScMatrix of size 36 x 36> > > but the last assemble() command raises an exception: > > "ufl.log.UFLException: Found product of basis functions, forms must be > linear in each basis function argument" > > What am I doing wrong here? Shouldn't I obtain a tensor of order 3 by > differentiating da? > > Thanks in advance! > Dominique -- You received this question notification because you are a member of DOLFIN Team, which is an answer contact for DOLFIN. _______________________________________________ Mailing list: https://launchpad.net/~dolfin Post to : dolfin@lists.launchpad.net Unsubscribe : https://launchpad.net/~dolfin More help : https://help.launchpad.net/ListHelp