How can i use NonlinearVariationalProblem?

Hi,

I am trying to solve a nonlinear equation (due to the trace terms), but I have this error…

Do you have an idea in order to fix this problem ?

Thank you


Minimal code:

L = 1.
H = 0.1

E0 = 1.
nu = 0.3
Gc = 1.
ell = .1
mu = E0/(2.*(1.+nu))
K = E0/3*(1.-2.*nu)

cell_size = 0.015
nel = L/cell_size

geom = Rectangle(Point(0., 0.), Point(L, H))
mesh = generate_mesh(geom, nel)

ndim = mesh.topology().dim()


def w(alpha):
  return alpha
def a(alpha):
 return E0*(1-alpha)**2
def g(alpha):
  k_ell = Constant(1.e-6) # residual stiffness
  return (1-alpha)**2+k_ell
def eps(u):
  return sym(grad(u))
def sigma0(u):
  return 2.*mu*eps(u) + lmbda*tr(eps(u))*Identity(ndim)
def sigma(alpha, u):
  return a(alpha)*sigma0(u)
def tr_pos_eps(u):
  return conditional( ge(tr(eps(u)), 0.), tr(eps(u)) ,0)
def tr_neg_eps(u):
  return tr(eps(u)) - tr_pos_eps(u) 


s = sympy.Symbol('s')
cw = sympy.integrate(4*sympy.sqrt(w(s)), (s, 0, 1))
c_1w = sympy.integrate(sympy.sqrt(1/w(s)),(s,0,1))
print("c_1/w = ",c_1w)
tmp = 2*(sympy.diff(w(s),s)/sympy.diff(1/a(s),s)).subs({"s":0})
print("Gc = %2.3f"%((ell*cw)/tmp))
Gc = Constant((ell*cw)/tmp)
sigma_c = sympy.sqrt(tmp*Gc*E0/(cw*ell))
print("sigma_c = %2.3f"%sigma_c)
eps_c = float(sigma_c/E0)
print("eps_c = %2.3f"%eps_c)


V_u, V_alpha = VectorFunctionSpace(mesh, 'Lagrange', 1, dim = 2), FunctionSpace(mesh, 'Lagrange', 1)
u, u_, v      = Function(V_u), TrialFunction(V_u), TestFunction(V_u)
alpha, dalpha, beta = Function(V_alpha), TrialFunction(V_alpha), TestFunction(V_alpha)
elastic_en = (    (K/2.)*((tr_neg_eps(u))**2.)  +  g(alpha)*(   (K/2.)*(  ((tr_pos_eps(u))**2.)  )  +   mu*inner(dev(eps(u)),dev(eps(u)))    )     )*dx 
dissip_en  = float(Gc/cw)*(w(alpha)/ell + ell*inner(grad(alpha), grad(alpha)))*dx
total_en =  elastic_en + dissip_en

dEu = derivative(total_en, u, v)


left  = CompiledSubDomain("near(x[0], 0, DOLFIN_EPS)")
right = CompiledSubDomain("near(x[0], %s, DOLFIN_EPS)"%L)
g = Expression(("t", 0.), t=1., degree=0)
bc_u0 = DirichletBC(V_u, Constant((0., 0.)), left)
bc_u1 = DirichletBC(V_u, g, right)
bc_u = [bc_u0, bc_u1]


problem_u = NonlinearVariationalProblem(total_en, u, bc_u, dEu)
solver_u = NonlinearVariationalSolver(problem_u)
solver_u.solve()

Error message :

You have not used a test-function in your variational formulation.

You do not use dEU in your nonlinear variational problem.

Hi,

I thought I defined a test function with this line:

And that I used dEu by calling it in this line:

Please could you tell me how I can do it properly ?

See for instance: https://fenicsproject.org/docs/dolfin/latest/python/demos/hyperelasticity/demo_hyperelasticity.py.html

Yes. The documentation has moved, and I cant go back and check all previous posts for dead links.

This one works - the above link