Hello every body
I have just started to learn FEniCS and I am an amateur. I'm trying to implement the Flow past a cylinder (2D) problem with the Stokes equations. I encountered this error for tentative velocity and computing velocity update:
warning: found no facet matching domain for boundary
and the velocity plot disappear after a while. could you please guide me how to solve it?
here is my code:
from dolfin import*
Set parameter values
dt = 0.01
T = 1
nu = 0.001
tol= 1e-10
mesh domain
mesh = Mesh("cylinder.xml")
## boundary condition
class Left(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0.0,tol)
class Right(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 2.4,tol)
class Bottom(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 0.0,tol)
class Top(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 0.4,tol)
class Cylinder(SubDomain):
def inside(self,x,on_boundary):
r = sqrt((x[0] - 0.2)**2 + (x[1] -0.2)**2)
return on_boundary and near(r, 0.05,tol)
left = Left()
top = Top()
right = Right()
bottom = Bottom()
cylindr = Cylinder()
Define function spaces (P2-P1)
V = VectorFunctionSpace(mesh, "CG", 2)
Q = FunctionSpace(mesh, "CG", 1)
Define trial and test functions
u = TrialFunction(V)
p = TrialFunction(Q)
v = TestFunction(V)
q = TestFunction(Q)
Define time-dependent pressure and velocity boundary condition
v_in = Expression(('(6*(x[1]*(0.41-x[1]))*sin(pi*t/8.0))/0.0283','0'), t=0.0)
Define boundary conditions
inflowv= DirichletBC(V,v_in, left, method='pointwise')
noslip1=DirichletBC(V,(0,0), top, method='pointwise')
noslip2=DirichletBC(V,(0,0), bottom, method='pointwise')
noslip3=DirichletBC(V,(0,0), right, method='pointwise')
noslip4=DirichletBC(V,(0,0), cylindr, method='pointwise')
outflowp = DirichletBC(Q, 0, right, method='pointwise')
bcu = [inflowv,noslip1,noslip2,noslip3,noslip4]
bcp = [outflowp]
Create functions
u0 = Function(V)
u1 = Function(V)
p1 = Function(Q)
Define coefficients
k = Constant(dt)
f = Constant((0, 0))
Tentative velocity step
F1 = (1/k)*inner(u - u0, v)*dx + inner(grad(u0)*u0, v)*dx + \
nu*inner(grad(u), grad(v))*dx - inner(f, v)*dx
a1 = lhs(F1)
L1 = rhs(F1)
Pressure update
a2 = inner(grad(p), grad(q))*dx
L2 = -(1/k)*div(u1)*q*dx
Velocity update
a3 = inner(u, v)*dx
L3 = inner(u1, v)*dx - k*inner(grad(p1), v)*dx
Assemble matrices
A1 = assemble(a1)
A2 = assemble(a2)
A3 = assemble(a3)
Create files for storing solution
ufile = File("results/velocity.pvd")
pfile = File("results/pressure.pvd")
Time-stepping
t = dt
while t < T + DOLFIN_EPS:
# Update pressure boundary condition
v_in.t = t
# Compute tentative velocity step
begin("Computing tentative velocity")
b1 = assemble(L1)
[bc.apply(A1, b1) for bc in bcu]
solve(A1, u1.vector(), b1, "gmres", "default")
end()
# Pressure correction
begin("Computing pressure correction")
b2 = assemble(L2)
[bc.apply(A2, b2) for bc in bcp]
solve(A2, p1.vector(), b2, "gmres", "default")
end()
# Velocity correction
begin("Computing velocity correction")
b3 = assemble(L3)
[bc.apply(A3, b3) for bc in bcu]
solve(A3, u1.vector(), b3, "gmres", "default")
end()
# Plot solution
plot(p1, title="Pressure", rescale=True)
plot(u1, title="Velocity", rescale=True)
# Save to file
ufile << u1
pfile << p1
# Move to next time step
u0.assign(u1)
t += dt
print "t =", t
Hold plot
interactive()