This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Derivative with respect to a tensor

0 votes

I cannot use the diff function to obtain the second order Kirchoff-Piola tensor, as shown in the following snippet:

# Large displacements kinematics
def largeKinematics(u):
    """Return the strain tensor, and the significant invariants."""
    d = u.geometric_dimension()
    I = fe.Identity(d)
    Fgrad = I + fe.grad(u)
    C = Fgrad.T*Fgrad
    E = 0.5*(C - I)
    return E

E = largeKinematics(u)


# Stored strain energy density for a generic model
def strainDensityFunction(E):
    return lambda_/2.*(fe.tr(E))**2. + mu*fe.tr(E*E)


psi = strainDensityFunction(E)


debugStress = False
if debugStress:
    # Computation of the stresses
    S = fe.diff(psi, E)
    S_project = fe.project(S, Z)
    sigmaViewer = fe.File('paraview/stress.pvd')
    sigmaViewer << S_project

I have understood that I need to define a Variable object, but I cannot work out how to call the constructor and then apply the differentiation.

Thank you in advance for your help, if you need any additional code, please let me know.

Ale N.

asked Jun 16, 2017 by alen12345 FEniCS Novice (160 points)

1 Answer

+1 vote
 
Best answer

You're right that diff requires E to be a 'variable':

E = variable(E)

try putting that after the command

E = largeKinematics(u)
E = variable(E)

and see if that fixes it. Otherwise, if you provide a complete MWE I can try to help more.

answered Jun 16, 2017 by mwelland FEniCS User (8,410 points)
selected Jun 17, 2017 by alen12345

Dear mwelland,

I had already tried your solution but the constructor for Variable fails executing.

Could please elaborate what to edit? Here is the complete code: Nonlinear Elasticity Fenics Gist

Thank you for your help.

Ale N.

'variable' is a ufl (fenics) function, so you need to prepend 'fe' as per your style:

E = largeKinematics(u)
E = fe.variable(E)

works for me with your code (with debugStress = True)

OUTPUT:
Min/Max displacement: -1.75059590546e-06 0.400478255456
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Maximum equivalent stress: 810703009.292
Max. displacement according to the linear beam theory: 0.285714285714
Maximum displacement along Y: 0.399058504966

Mike

I was attempting to use the Variable class from dolphin, not variable from ufl... the code works perfectly now.

Thank you so much for your help!

Ale N.

...