Hello, I am trying to study heat diffusion in a radiator composed of fins.
I began by creating a basic mesh that I can duplicate to create multiple fins, then added a Neumann condition on the bottom and a Robin condition anywhere else.
This is my code
def generateFin(z,lx,ly,lp,e):
support = Box(Point(lx/2-lp/2,ly/2-lp/2,z),Point(lx/2+lp/2,ly/2+lp/2,z+e))
fin = Box(Point(0.0,0.0,z+e),Point(lx,ly,z+2*e))
return fin+support
fin = generateFin(0,lx,ly,lp,e)
fin2 = generateFin(2*e,lx,ly,lp,e)
mesh = generate_mesh(fin, 20)
plt.figure(1)
plot(mesh, title="Mesh")
Hh2 = FunctionSpace(mesh, 'P', 3)
#Boundary conditions
boundary_markers = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
class BoundaryNeumann(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and near(x[2], 0, tol)
S = BoundaryNeumann()
S.mark(boundary_markers, 0)
class BoundaryRobin(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and x[2] > tol
S = BoundaryRobin()
S.mark(boundary_markers, 1)
boundary_conditions = {0: {'Neumann': j_a},
1: {'Robin': (h_a, thetaA)}}
ds = Measure('ds', domain=mesh, subdomain_data=boundary_markers)
u = TrialFunction(Hh2)
v = TestFunction(Hh2)
bcs = []
for i in boundary_conditions:
if 'Dirichlet' in boundary_conditions[i]:
bc = DirichletBC(Hh2, boundary_conditions[i]['Dirichlet'],
boundary_markers, i)
bcs.append(bc)
integrals_N = []
for i in boundary_conditions:
if 'Neumann' in boundary_conditions[i]:
if boundary_conditions[i]['Neumann'] != 0:
g = boundary_conditions[i]['Neumann']
integrals_N.append(g*v*ds(i))
integrals_R_a = []
integrals_R_L = []
for i in boundary_conditions:
if 'Robin' in boundary_conditions[i]:
r, s = boundary_conditions[i]['Robin']
integrals_R_a.append(r*u*v*ds(i))
integrals_R_L.append(r*s*v*ds(i))
A = Expression(((str(k), '0', '0'), ('0', str(k), '0'), ('0','0',str(k))), degree=1)
a = dot(dot(A,grad(u)), grad(v))*dx + sum(integrals_R_a)
l = sum(integrals_N) + sum(integrals_R_L)
u = Function(Hh2)
solve(a == l, u)
It basically works (results below, I can only upload one image)
Then I try to add a second fin, by editing
mesh = generate_mesh(fin, 20)
to
mesh = generate_mesh(fin+fin2, 20)
But now, I get these very strange results, my mesh looks good but I suspect my boundary conditions not to be correctly defined, even though it worked fined with only one fin. What did I do wrong ? Is there another way to achieve what I want to do ?