Error: Unable to successfully call PETSc function 'MatSetValuesLocal'. Reason: PETSc error code is: 63 (Argument out of range)

Hello,

I am trying to solve a non-linear variational problem, but I get:

*** Error: Unable to successfully call PETSc function ‘MatSetValuesLocal’.
*** Reason: PETSc error code is: 63 (Argument out of range).
*** Where: This error was encountered inside /build/dolfin-cZGj9S/dolfin-2019.2.0~git20200629.946dbd3/dolfin/la/PETScMatrix.cpp.
*** Process: 0

Here is my code:

from dolfin import *
mesh = UnitSquareMesh(4,4)
W = VectorFunctionSpace(mesh, 'CG', 1)
u, v, du = Function(W), TestFunction(W), TrialFunction(W)

top = CompiledSubDomain("near(x[1], 1) && on_boundary")
bot = CompiledSubDomain("near(x[1], -1) && on_boundary") 
bcbot= DirichletBC(W, Constant((0.0,0.0)), bot)
bctop = DirichletBC(W.sub(1), Constant(0.1), top)
bc_u = [bcbot, bctop]
lmbda, mu = 120, 80

# Constituive functions
def epsilon(u):
    return sym(grad(u))

def sigma(u):
    E = psi(u)
    F = Identity(len(u)) + sym(grad(u))
    F = variable(F) 
    return diff(E, F)

def psi(u):
    return 0.5*lmbda*(tr(epsilon(u)))**2 + mu*inner(epsilon(u), epsilon(u))	
           
E_du = inner(grad(v), sigma(u))*dx
J  = derivative(E_du, u, du)
p_disp = NonlinearVariationalProblem(E_du, u, bc_u, J)
solver_disp = NonlinearVariationalSolver(p_disp)
solver_disp.solve()

Any help is much appreciated!

THe issue is that the operation diff(E, F) returns 0, as psi is not a function of F. Have you considered the hyperelasticity demo: Hyperelasticity — DOLFIN documentation ?

2 Likes

Thank you so much!
Yes, that demo resolved the issue!