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

Problem with moving mesh (ALE.move)

0 votes

Hello
I have a rectangular domain with a rectangular hole inside. I want to move the nodes located on the boundaries of the rectangular hole in the y-direction at every time step and subsequently I expect the boundaries of the hole to move in the y-direction.
I have followed the example provided in this topic:
https://fenicsproject.org/qa/11852/moving-dirichlet-bc-ale

Here is the geometry and mesh:

enter image description here
And this is my implementation:

from dolfin import *
import mshr

# Domain
domain = mshr.Rectangle(Point(0,0), Point(4,4))\
          - mshr.Rectangle(Point(1,1), Point(3,3))

# Mesh
mesh = mshr.generate_mesh(domain, 20)

class lower_edge(SubDomain):
  def inside(self, x, on_boundary):
    return True if x[0]<= 3.0 and x[0]>= 1.0 and x[1] == 1.0 else False

class top_edge(SubDomain):
  def inside(self, x, on_boundary):
    return True if x[0]<= 3.0 and x[0]>= 1.0 and x[1] == 3.0 else False

class left_edge(SubDomain):
  def inside(self, x, on_boundary):
    return True if x[0]==1.0 and x[1]<= 3.0 and x[1]>= 1.0 else False

class right_edge(SubDomain):
  def inside(self, x, on_boundary):
    return True if x[0]==3.0 and x[1]<= 3.0 and x[1]>= 1.0 else False

lower_edge = lower_edge()
top_edge = top_edge()
left_edge = left_edge()
right_edge = right_edge()

# Subdomain marker
mf = MeshFunction("size_t", mesh, 2)
mf.set_all(0)
lower_edge.mark(mf, 1)
top_edge.mark(mf, 2)
left_edge.mark(mf, 3)
right_edge.mark(mf, 4)

# Define facet function over the new mesh
ff = FacetFunction("size_t", mesh)
ff.set_all(0)
lower_edge.mark(ff, 1)
top_edge.mark(ff, 2)
left_edge.mark(ff, 3)
right_edge.mark(ff, 4)
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 lower_edge.inside(x, True):
      x[0] += 0.0
      x[1] += 0.05

    if top_edge.inside(x, True):
      x[0] += 0.0
      x[1] += 0.05

    if left_edge.inside(x, True):
      x[0] += 0.0
      x[1] += 0.05

    if right_edge.inside(x, True):
      x[0] += 0.0
      x[1] += 0.05

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

As mentioned in the code, I have added displacement (equal to 0.05) only in the y-direction to the nodes located at the boundaries of the hole at every time-step but this is what I get at the last time step:
enter image description here
It seems like the bottom and top boundaries of the internal hole, do not even move!! As I said I expect all 4 boundaries to move upward during the time as the nodes attached to these boundaries are moving upward.
Could you please help me fix this issue?
Best

asked Jun 8, 2017 by Leo FEniCS Novice (840 points)

1 Answer

+1 vote

The issue might be that you're using a statement like:

x[1] == k

instead of :

near(x[1], k)

which is:

abs(x[1] - k) < DOLFIN_EPS

The top statement might not always work due to floating point accuracy

answered Jun 9, 2017 by alexmm FEniCS User (4,240 points)
edited Jun 12, 2017 by alexmm

Hi
I changed this part of code according to your suggestion:

class lower_edge(SubDomain):
  def inside(self, x, on_boundary):
    return True if x[0]<= 3.0 and x[0]>= 1.0 \
and abs(x[1] - 1.0) < DOLFIN_EPS else False

class top_edge(SubDomain):
  def inside(self, x, on_boundary):
    return True if x[0]<= 3.0 and x[0]>= 1.0 \
and abs(x[1] - 3.0) < DOLFIN_EPS else False

class left_edge(SubDomain):
  def inside(self, x, on_boundary):
    return True if abs(x[0] - 1.0) < DOLFIN_EPS \
and x[1]<= 3.0 and x[1]>= 1.0 else False

class right_edge(SubDomain):
  def inside(self, x, on_boundary):
    return True if abs(x[0] - 3.0) < DOLFIN_EPS \
and x[1]<= 3.0 and x[1]>= 1.0 else False

Unfortunately it was not helpful! The same problem still exists.

Are you changing your definition of the inside edges every time you move them?

No I did not. I just changed the part of the original code that I provided in the beginning of my question. How can I change my definition of the inside edges every time ?
Thanks.

To check if this is the problem you can run it for one iteration and see if the boundaries move correctly.

What you can do is have array of numbers with the extents of the inside square, change this numbers at every iteration, and then pass them to the inside edge classes, so you will be checking against the new moved inside extent and not the initial one

As I have shown in my figures, the meshes on the left and the right boundaries of the internal square move at every time step but the nodes on the top and the bottom boundaries are completely fixed!
Regarding to what you suggested, it looks a bit confusing to me. I was hoping if you could provide a working example to resolve the issue I am having in this code.
Thanks again.

...