Hi,
I am pretty new about fenics, just started two days before, I have some struggle with the code I wrote below. The problem I want to solve with fenics is a coupled thermo-electric problem. When I ran the following code, the gives the following error:
TypeError: ‘bool’ object is not iterable when run the line solve(a == L, u, bc)
.
I know this error is self-explained in terms of python, but I do not really know what this bool is referring to, the only bool I can see is on_boundary, which I can not think of how it can cause the problem. Could some experienced user run the code and gives me some hint, what is the problem of the code? Thanks very much for your help.
from fenics import *
import matplotlib.pyplot as plt
import numpy as np
from dolfin import *
from mshr import *
box = Box(Point(-0.3,-0.15,-0.014),Point(0.3,0.15,0.014))
## sample dimensions in cm
mesh = generate_mesh(box,30)
P1 = FiniteElement('P',tetrahedron,1)
element = MixedElement([P1,P1])
V = FunctionSpace(mesh, element)
##############################some parameters
T = 1.0
num_steps = 5
dt = T/num_steps
a = 0.6
## sample length in cm
b = 0.3
## sample width in cm
c = 0.028
## sample thickness in cm
L = 100.0e-4
## wire lenght in cm
r = 5.0e-4
## wire radius in cm
R = (L/(r*r*np.pi))*(2.65e-4)
## wire resistance in ohm
I = 200e-6
## current in A
contact = 4e6
## contact resistance in ohm
W = I*I*(R+contact)
## heat injected via the wire
T_ext = 30.0
##environment temperature in K
J_ext = I/(r*r*np.pi)
## current density in wire in A/cm2
tol = 0.05
#################################################
Define boundary condition
u_D_heat = Expression('T_ext', degree=2,T_ext=T_ext)
u_D_potential = Constant(0)
def boundary_D_heat(x, on_boundary):
return False
def boundary_D_potential(x, on_boundary):
return False
bc_heat = DirichletBC(V.sub(0), u_D_heat, boundary_D_heat)
bc_potential = DirichletBC(V.sub(1), u_D_potential, boundary_D_potential)
bc = [bc_heat, bc_potential]
Define initial condition
u_0 = Expression(('30.0','0.0'),degree=2)
u_n = interpolate(u_0,V)
u_n1, u_n2 = u_n.split()
Define parameter functions
K = Constant(0.13)
# w/cm/K
cp = Constant(0.2)
#J/g/K
rou = Constant(2.329)
#g/cm3
sigma = Expression('temp < 37.0 ? exp(0.4258*temp-23.313):exp(0.0105*temp-7.6668)',degree=2,temp=u_n)
#conductivity
h = 0.002
# w/cm2/K
Define variational problem
u = TrialFunction(V)
u_1, u_2 = split(u)
v_1, v_2 = TestFunctions(V)
g_heat = Expression('(near(x[0],-0.25*a,tol) and near(x[1],0.0,tol) and near(x[2],c/2.0,tol/5.0)) or (near(x[0],0.25*a,tol) and near(x[1],0.0,tol) and near(x[2],c/2.0,tol/5.0)) ? W : h*(T_ext-temp)',degree=2, tol=tol,a=a,c=c,W=W, h=h,T_ext=T_ext,temp=u_n1)
g_potential = Expression('near(x[0],-0.25*a,tol) and near(x[1],0.0,tol) and near(x[2],c/2.0,tol/5.0) ? J_ext : near(x[0],0.25*a,tol) and near(x[1],0.0,tol) and near(x[2],c/2.0,tol/5.0) ? -1.0*J_ext : 0',degree=2,tol=tol,a=a,c=c,J_ext=J_ext)
f_heat = sigma*dot(grad(u_2),grad(u_2))
a = dt*K*dot(grad(u_1), grad(v_1))*dx + rou*cp*u_1*v_1*dx + **sigma*dot(grad(u_2),grad(v_2))*dx**
L = dt*f_heat*v_1*dx + rou*cp*u_n1*v_1*dx + dt*g_heat*v_1*ds + **g_potential*v_2*ds**
u = Function(V)
Time-stepping
t = 0.0
vtkfile_u_1 = File('heat_test/solution_u_1.pvd')
vtkfile_u_2 = File('heat_test/solution_u_2.pvd')
for n in range(num_steps):
t = t + dt
solve(a == L, u, bc)
u_n.assign(u)
_u_1, _u_2 = u.split()
vtkfile_u_1 << (_u_1,t)
vtkfile_u_2 << (_u_2,t)