This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Moving Dirichlet BC...ALE?

+1 vote

I have Stoke flow problem where I have a rectangular domain with a circle cut out. I need to have the circle moving up and down at a sinusoidal manner. I have the following code for BC's that I have to change to achieve this but I'm new to fenics and I'm not sure what to change.

EDIT:
So I figured out that the vc below is just the velocity going through the cylinder and not the boundary's movement. I've been told that fenics has built in functions that can easily do what I'm looking for. Any help would be much appreciated.

# Build function spaces (Taylor-Hood)

V = VectorFunctionSpace(mesh, "CG", 2)
P = FunctionSpace(mesh, "CG", 1)
E = FunctionSpace(mesh, "CG", 1)
W = MixedFunctionSpace([V, P, E])

No-slip boundary condition for velocity on walls and cylinder - boundary id 3

noslip = Constant((0, 0))
bcv_walls = DirichletBC(W.sub(0), noslip, bndry, 3)

vc= Expression(("-0.5tcos(atan2(x[0]-0.2,x[1]-0.2))","0.5tsin(atan2(x[0]-0.2,x[1]-0.2))"),t=0)
bcv_cylinder = DirichletBC(W.sub(0), vc, bndry, 5)

bce_cylinder = DirichletBC(W.sub(2), Constant(1.0), bndry, 5)

Inflow boundary condition for velocity - boundary id 1

v_in = Expression(("1.5 * 4.0 * x[1] * (0.41 - x[1]) / ( 0.41 * 0.41 )", "0.0"))
bcv_in = DirichletBC(W.sub(0), v_in, bndry, 1)

Collect boundary conditions

bcs = [bcv_cylinder, bcv_walls, bcv_in, bce_cylinder]

asked Dec 5, 2016 by Nabby FEniCS Novice (180 points)
edited Dec 6, 2016 by Nabby

1 Answer

+1 vote

You can use a FacetFunction to mark facets on the cylinder boundary in order to apply Dirichlet boundary conditions and then move the mesh using functions of the ALE class. If you move your mesh, the dofs and entities ordering will be preserved, and in consequence, the FacetFunctions, FunctionSpaces or any definition over your mesh will be automatically updated. Try something like:

from dolfin import *

class left(SubDomain):
  def inside(self, x, on_boundary):
    return x[0] > 1.0 - DOLFIN_EPS

mesh   = UnitSquareMesh(10, 10)
left = left()

# Subdomain marker
mf = MeshFunction("size_t", mesh, 2)
mf.set_all(1)
left.mark(mf, 0)

# Define facet function over the new mesh
ff = FacetFunction("size_t", mesh)
ff.set_all(0)
left.mark(ff, 1)
plot(ff, interactive=True)

# Extract boundary mesh
bmesh = BoundaryMesh(mesh, "exterior", True)
plot(bmesh, interactive=True)

t = 0.0
for i in range(10):
  t += 0.1
  for x in bmesh.coordinates():
    if left.inside(x, True):
      x[0] += 0.0
      x[1] *= 1.0 + 0.1*sin(0.1*t*x[1])

  ALE.move(mesh, bmesh)
  plot(ff, interactive=True)

Something similar can be done just moving the boundary coordinates of the cylinder.

answered Dec 6, 2016 by hernan_mella FEniCS Expert (19,460 points)
edited Dec 6, 2016 by hernan_mella
...