Hi. I need a favor in pointing the problem in my coding. I don’t know whats wrong with my boundary conditions. Now I am working on convective flow in a sinusoidal cavity. I’m working for weeks but could not run it successfully. The error appear:
*** Warning: Found no facets matching domain for boundary condition.
Please help me. Here I attach the code:
from __future__ import print_function
from fenics import *
from dolfin import *
from mshr import *
import matplotlib.pyplot as plt
# Define dimensionless parameter
Ra = 10000
Pr = 6.26
n = 1
M = 0
Nr = 0.1
Nb = 0.1
Nt = 0.1
Le = 10
o = 0
k = 0
# Create mesh
domain_n_points = 128
domain_points = list()
for n in range(domain_n_points + 1):
y = n*1./domain_n_points
domain_points.append( Point(0.2-0.2*cos(6.*pi*y), y) )
domain_points.append( Point(1., 1.) )
domain_points.append( Point(1., 0.) )
domain_points = domain_points[::-1] # Polygon vertices must be given in counter clockwise order.
domain = Polygon(domain_points)
mesh = generate_mesh(domain, 16)
plot(mesh)
# Create boundaries
class Noslip(SubDomain):
def inside(self, x, on_boundary):
return on_boundary
class Bottom(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[1]) < DOLFIN_EPS
class Right(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[0] - 1) < DOLFIN_EPS
class Left(SubDomain):
def inside(self, x, on_boundary):
return on_boundary #and abs(x[0]) < DOLFIN_EPS
class Top(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[1] - 1) < DOLFIN_EPS
boundaries = MeshFunction("size_t", mesh, mesh.topology().dim()-1)
boundaries.set_all(0)
noslip = Noslip()
noslip.mark(boundaries,1)
top = Top()
top.mark(boundaries,2)
bottom = Bottom()
bottom.mark(boundaries, 3)
right = Right()
right.mark(boundaries, 4)
left = Left()
left.mark(boundaries, 5)
plot(boundaries)
# Define function space
V = VectorElement("CG", mesh.ufl_cell(), 2)
Q = FiniteElement("CG", mesh.ufl_cell(), 1)
L = FiniteElement("CG", mesh.ufl_cell(), 2)
X = FiniteElement("CG", mesh.ufl_cell(), 2)
element = MixedElement([V, Q, L, X])
W = FunctionSpace(mesh, element)
# Define boundary condition
no_slip = DirichletBC(W.sub(0), (0,0), boundaries,1)
#lid = DirichletBC(W.sub(0), (1,0), "x[1] > 1.0 - DOLFIN_EPS")
cold = DirichletBC(W.sub(2), 0,boundaries, 4)
hot = DirichletBC(W.sub(2), 1,boundaries, 5)
notconc = DirichletBC(W.sub(3), 0,boundaries, 4)
conc = DirichletBC(W.sub(3), 1,boundaries, 5)
bc = [no_slip, hot, cold, notconc, conc]
# Define test functions
(v,q,s,r) = TestFunctions(W)
# Define trial functions
w = Function(W)
(u,p,T,c) = (as_vector((w[0], w[1])), w[2], w[3], w[4])
# Define expression used in variational forms
miu = 1.0/Pr
theta = 1.0/Le
e = Constant ((0,1))
M = Constant(M)
Nr = Constant(Nr)
Nb = Constant(Nb)
Nt = Constant(Nt)
phi = Nt/Nb
o = Constant(o)
k = Constant(k)
def epsilon(w):
return (grad(w)+(grad(w).T))
def secondinvariant(w):
return 0.5*inner(epsilon(w),epsilon(w))+ DOLFIN_EPS
def powerlaw(w):
return pow(secondinvariant(w),0.5*(n-1))
# Define variational problem
F1 = div(u)*q*dx
F2 = inner(dot(u,grad(u)), v)*dx - div(v)*p*dx + Pr*powerlaw(u)*inner(epsilon(u),grad(v))*dx \
+ M*dot(u,v)*dx - T*Pr*Ra*dot(e,v)*dx + c*Nr*Pr*Ra*dot(e,v)*dx
F3 = dot(u,grad(T))*s*dx + dot(grad(T),grad(s))*dx \
- Nb*inner(grad(c),grad(T))*s*dx - Nt*inner(grad(T),grad(T))*s*dx- o*T*s*dx
F4 = dot(u,grad(c))*r*dx + theta*dot(grad(c),grad(r))*dx \
+ theta*phi*dot(grad(T),grad(r))*dx - k*c*r*dx
F = F1 + F2 + F3 + F4
# Solve
J = derivative(F, w)
problem = NonlinearVariationalProblem(F, w, bc, J)
solver = NonlinearVariationalSolver(problem)
solver.solve
# Create VTK files for visualization output
vtkfile_u = File('test/u.pvd')
vtkfile_p = File('test//p.pvd')
vtkfile_T = File('test//T.pvd')
vtkfile_c = File('test//c.pvd')
# Save solution to file (VTK)
(u, p, T, c) = w.split()
vtkfile_u << u
vtkfile_p << p
vtkfile_T << T
vtkfile_c << c
# Plot solution
plot(u)
plot(T)
plot(c)
# Hold plot
plt.show()