Dear all, I am new to FENICS and want to get some help from you. I tried to use FENICS to model airflows around airfoil at Re=20. After computation, I want to get the pressure distribution on the airfoil surface, but have no idea how to do that, could you give me some clues
def build_space(airfoil, Rect, N_bulk, u_in):
"""Prepare data for DGF benchmark. Return function
space, list of boundary conditions and surface measure
on the airfoil."""
Xmin, Xmax, Ymin, Ymax = Rect[0], Rect[1], Rect[2], Rect[3]
bc_pt = [Point(x,y) for x,y in airfoil]
airfoil = Polygon(bc_pt)
rect = Rectangle(Point(Xmin, Ymin), Point(Xmax, Ymax))
geometry = rect - airfoil
mesh = generate_mesh(geometry, N_bulk)
#plot(mesh, title='Mesh of the total domain')
#plt.show()
EPS = 1e-4
# Construct facet markers
class Airfoil(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and x[0] > -EPS and x[0] < 1.0+EPS and x[1] > -0.1+EPS and x[1] < 0.15-EPS
class Inlet(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], Xmin) and on_boundary
class Outlet(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], Xmax) and on_boundary
class Wall(SubDomain):
def inside(self, x, on_boundary):
return (near(x[1], Ymin) or near(x[1], Ymax) ) and on_boundary
sub_domains = MeshFunction("size_t", mesh, mesh.topology().dim()-1)
sub_domains.set_all(0) # label all facets as 0
inlet = Inlet()
inlet.mark(sub_domains, 1)
outlet = Outlet()
outlet.mark(sub_domains, 2)
wall = Wall()
wall.mark(sub_domains, 3)
air_foil = Airfoil()
air_foil.mark(sub_domains, 4)
# Build function spaces (Taylor-Hood)
P2 = VectorElement("P", mesh.ufl_cell(), 2)
P1 = FiniteElement("P", mesh.ufl_cell(), 1)
TH = MixedElement([P2, P1])
# P2 = VectorElement("Lagrange", triangle, 2)
# P1 = FiniteElement("Lagrange", triangle, 1)
# TH = P2 * P1
W = FunctionSpace(mesh, TH)
# Prepare Dirichlet boundary conditions
bc_walls = DirichletBC(W.sub(0), (0, 0), sub_domains, 3)
bc_airfoil = DirichletBC(W.sub(0), (0, 0), sub_domains, 4)
bc_in = DirichletBC(W.sub(0), u_in, sub_domains, 1)
bc_out = DirichletBC(W.sub(1), 0, sub_domains, 1)
bcs = [bc_airfoil, bc_walls, bc_in]
# Prepare surface measure on airfoil
ds_airfoil= Measure("ds", subdomain_data=sub_domains, subdomain_id=4)
return W, bcs, ds_airfoil
def solve_navier_stokes(W, nu, bcs):
"""Solve steady Navier-Stokes and return the solution"""
# Define variational forms
v, q = TestFunctions(W)
w = Function(W)
u, p = split(w)
F = nu*inner(grad(u), grad(v))*dx + dot(dot(grad(u), u), v)*dx - p*div(v)*dx - q*div(u)*dx
# Solve the problem
solve(F == 0, w, bcs, solver_parameters = {'newton_solver': {'linear_solver': 'mumps'}})
# update parameters
return w