Solving a non-linear equation with bisection method

Hi all,

I have a question regarding solving a simple non-linear equation within the framework of fenics.

Say I have a non-linear function

f = u - ln(u) - a

and I would like to solve for f = 0.

If a is a float number, I can use a simple bisection method with scipy like scipy.optimize.bisect(f, f(a), f(b)) to solve for u.

Now, I would like to solve the function on a 2-d mesh. u = u(x, y) and a = a(x,y) (a is known, like defined in different subdomains representing different mateirals.)

How should I solve for u within the framework of fenics? the simple scipy bisection function does not work as f has to be a number, instead here f is a finite element function defined on a mesh.

Thanks.

Isn’t this just a nonlinear projection? Or am I missing something?

from dolfin import *

mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
v = TestFunction(V)

u.interpolate(Constant(2.0))
a = Expression("1.0 + x[0]*x[1]", degree=2)
F = (u - ln(u) - a)*v*dx

solve(F == 0, u)

print(u(0.5, 0.5))

plot(u)
import matplotlib.pyplot as plt
plt.show()

image