Non linear variational problem with constrained function

Hi
I am a new fenics user
I have to impose the functional below equal to zero:

immagine

where “d” is the goal function, “T0” and “E” are two 2x2 matrix, “w0” and “k” are constants and “e” is the test function. I have to impose 0<d<1. I used the follow code:

Blockquote
################ Solution1,d, s1
d=Function(D)
dd=TestFunction(D)
comp_1=(d-1)inner(T0,E)
comp_3=non_local_coeff
inner((grad(d)),grad(dd))
b=(inner(comp_1+w0,dd))dx+comp_3dx
d0=Function(D)
problem=NonlinearVariationalProblem(b,d0,bcd,toll1)
solver = NonlinearVariationalSolver(problem)
solver.parameters.update(snes_solver_parameters)
a_min = Function(interpolate(Constant(0.0), D))
a_max = Function(interpolate(Constant(1.0), D))
(iter, converged) = solver.solve(a_min.vector(), a_max.vector())
dpre=d0
d=d0
plot(d)

and I obtained the follow error message:

Blockquote
RuntimeError Traceback (most recent call last)
in
6 b=(inner(comp_1+w0,dd))dx+comp_3dx
7 d0=Function(D)
----> 8 problem=NonlinearVariationalProblem(b,d0,bcd,toll1)
9
10 solver = NonlinearVariationalSolver(problem)
~/anaconda3/lib/python3.8/site-packages/dolfin/fem/problem.py in init(self, F, u, bcs, J, form_compiler_parameters)
90 F = Form(F, form_compiler_parameters=form_compiler_parameters)
91 if J is not None:
—> 92 J = Form(J, form_compiler_parameters=form_compiler_parameters)
93
94 # Initialize C++ base class
~/anaconda3/lib/python3.8/site-packages/dolfin/fem/form.py in init(self, form, **kwargs)
18 # Check form argument
19 if not isinstance(form, ufl.Form):
—> 20 raise RuntimeError(“Expected a ufl.Form.”)
21
22 sd = form.subdomain_data()
RuntimeError: Expected a ufl.Form.

How I can solve this?
Thank you for the attention

Hi,
check the following bound-constrained optimization demos:
https://bitbucket.org/fenics-project/dolfin/src/master/python/demo/undocumented/contact-vi-snes/demo_contact-vi-snes.py
or
https://bitbucket.org/fenics-project/dolfin/src/master/python/demo/undocumented/contact-vi-tao/demo_contact-vi-tao.py

1 Like