'bool' object is not iterable

Hi all, I am trying to solve the following problem

\nabla^2 u + (\alpha - \beta dot(u,u)) u = 0

where u is a 2d vector in 2d space and alpha and beta are two real constants. Following examples I tried the following as LHS

(inner(grad(u), grad(v)) + (alpha-beta*inner(u,u))*inner(u,v))*dx

but I get an error 'bool' object is not iterable which goes away when I remove the \beta term. Can anyone point out what’s wrong here?

Hi, please share the minimal code that reproduces the error.

Here it is.

from __future__ import print_function    
from fenics import *    
import matplotlib.pyplot as plt    
plt.rcParams.update({'figure.dpi':256})    
    
mesh = UnitSquareMesh(32, 32)    
V    = VectorFunctionSpace(mesh, 'P', 1)    
uD   = Expression(('-sin(atan2(x[1]-y0,x[0]-x0))','cos(atan2(x[1]-y0,x[0]-x0))'), degree=2, x0=0.5,y0=0.5)    
def boundary(x, on_boundary):    
    return on_boundary    
bc = DirichletBC(V, uD, boundary)    
    
# Define variational problem    
u = TrialFunction(V)    
v = TestFunction(V)    
    
alpha = Constant(1.0)    
beta  = Constant(1.0)    
    
LHS = (inner(grad(u), grad(v)) + (alpha-beta*dot(u,u))*inner(u,v))*dx    
#LHS = inner(grad(u), grad(v))*dx    
f = Constant((0,0))    
RHS = dot(f,v)*dx    
# Compute solution    
u = Function(V)    
solve(LHS == RHS, u, bc)    
plot(u)

Your underlying equations are nonlinear, you need to solve a nonlinear finite element problem. Cf. here.

from __future__ import print_function    
from fenics import *    
import matplotlib.pyplot as plt    
plt.rcParams.update({'figure.dpi':256})    
    
mesh = UnitSquareMesh(32, 32)    
V    = VectorFunctionSpace(mesh, 'P', 1)    
uD   = Expression(('-sin(atan2(x[1]-y0,x[0]-x0))','cos(atan2(x[1]-y0,x[0]-x0))'), degree=2, x0=0.5,y0=0.5)    
def boundary(x, on_boundary):    
    return on_boundary    
bc = DirichletBC(V, uD, boundary)    
    
# Define variational problem    
u = Function(V)    
v = TestFunction(V)    
    
alpha = Constant(1.0)    
beta  = Constant(1.0)    
    
LHS = (inner(grad(u), grad(v)) + (alpha-beta*dot(u,u))*inner(u,v))*dx    
#LHS = inner(grad(u), grad(v))*dx    
f = Constant((0,0))    
RHS = dot(f,v)*dx    
# Compute solution
F = LHS - RHS
solve(F == 0, u, bc)    
plot(u)
plt.show()