Hi all,
Taking inspiration from the flow past a cylinder tutorial, I’m trying to allow another cylinder initialised at a different place in the domain to move through the fluid. I saw Jorgen’s answer for how to accomplish with constant Dirichlet boundary conditions, although I’m a bit stuck on how to implement this with the inflow profile as specified in the ‘Flow past a cylinder tutorial’. This is the code so far:
# Create mesh
channel = Rectangle(Point(0, 0), Point(2.2, 0.41))
cylinder = Circle(Point(0.2, 0.2), 0.05)
domain = channel - cylinder - following_fish_circle
original_mesh = generate_mesh(domain, 64)
# Define function spaces
V = VectorFunctionSpace(original_mesh, 'CG', 2)
Q = FunctionSpace(original_mesh, 'CG', 1)
# Define boundary and set the boundaries number.
class inflow(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0) and on_boundary
class outflow(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 2.2) and on_boundary
class walls(SubDomain):
def inside(self, x, on_boundary):
return (near(x[1], 0) or near(x[1], 0.41)) and on_boundary
class cylinder(SubDomain):
def inside(self, x, on_boundary):
return x[0] >= 0.1 and x[0] <= 0.3 and x[1] >= 0.1 and x[1] <= 0.3 and on_boundary
class following_fish(SubDomain):
def inside(self, x, on_boundary):
return x[0] >= 1.1 and x[0] <= 1.6 and x[1] >= 0.2 and x[1] <= 0.4 and on_boundary
boundaries = MeshFunction('size_t', original_mesh, 1, original_mesh.domains())
boundaries.set_all(0)
inflow().mark(boundaries, 1)
walls().mark(boundaries, 2)
cylinder().mark(boundaries, 3)
following_fish().mark(boundaries, 4)
outflow().mark(boundaries, 5)
# Define inflow profile
inflow_profile = ('4.0*1.5*x[1]*(0.41 - x[1]) / pow(0.41, 2)', '0')
bcu_inflow = DirichletBC(V, Expression(inflow_profile, degree=2), boundaries, 1)
def boundary_condition_changes(displacement, mesh, bcu_inflow):
# Define boundary conditions
bcu_walls = DirichletBC(V, Constant((0, 0)), boundaries, 2)
bcu_cylinder = DirichletBC(V, Constant((0, 0)), boundaries, 3)
bcu_following_fish = DirichletBC(V, Constant((-displacement, 0)), boundaries, 4)
bcp_outflow = DirichletBC(Q, Constant(0), boundaries, 5)
bcu = [bcu_inflow, bcu_walls, bcu_cylinder, bcu_following_fish]
bcp = [bcp_outflow]
if displacement != 0:
#disp_bc1 = bcu[0]
disp_bc2 = bcu[1]
disp_bc3 = bcu[2]
disp_bc4 = bcu[3]
#disp_bc5 = bcp[0]
b_disp = Function(V)
#disp_bc1.apply(b_disp.vector())
disp_bc2.apply(b_disp.vector())
disp_bc3.apply(b_disp.vector())
disp_bc4.apply(b_disp.vector())
#disp_bc5.apply(b_disp.vector())
# Define new mesh
new_mesh = Mesh(mesh)
new_boundaries = MeshFunction("size_t", new_mesh, 1)
new_boundaries.set_values(boundaries.array())
ALE.move(mesh, b_disp)
for j in range(700):
mesh.smooth()
return bcu, bcp, mesh
This function works without an error when called later in the for loop
for n in range(num_steps):
if n!=0:
bcu, bcp, changed_mesh = boundary_condition_changes(displacement=0.01, mesh=changed_mesh, bcu_inflow=bcu_inflow)
L1, L2, L3, a1, a2, a3, u_, p_, u_n, p_n = initialise_solver(MU=mu, RHO=rho, MESH=changed_mesh)
A1, A2, A3 = flow_solver(BCU=bcu, BCP=bcp, a1=a1, a2=a2, a3=a3)
Here, initialise_solver and flow_solver are inspired from the ‘flow behind the cylinder’ tutorial. At each time step, the circle at the far end, gets displaced by 0.01 in the negative x direction. The code works but outputs the fluid going through the circle as shown below, instead of around the circle boundary.
I’m a beginner at Fenics and DOLFIN. Could I have some help please?
Thanks!