simple question on mesh_snap_boundary

Asked by Xiaoxian Liu on 2013-01-25

Hi all,

I explored the usage of "mesh_snap_boundary" with the following simple code:

### Beginning of code
mesh=UnitSquare(2,2)
print mesh.coordinates()

class LeftRegion(SubDomain):
def inside(self, x, on_boundary):
return True if x[0]<=0.5 else False
def snap(self, x):
if x[0]<=0.5+DOLFIN_EPS: x[0]=0.5*(x[0]-0); x[1]=x[1]

left = LeftRegion()
mesh.snap_boundary(left)
print mesh.coordinates()
### End of code

I simply want to push the vertices on the left side of the unit square towards y-axis by a factor of 0.5, so [0.5, y] should become [0.25, y]. However, the output of the code above is, after "snapping",
"""

[[ 0. 0. ]
[ 0.25 0. ]
[ 1. 0. ]
[ 0. 0.5 ]
[ 0.375 0.5 ]
[ 1. 0.5 ]
[ 0. 1. ]
[ 0.25 1. ]
[ 1. 1. ]]
"""

Could anyone tell me why the center vertex became [0.375, 0.5], rather than [0.25, 0.5]?

Thanks a lot!

Question information

Language:
English Edit question
Status:
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
2013-01-25
2013-01-25
 Jan Blechta (blechta) said on 2013-01-25: #1

Mesh.snap_boundary() method snaps only boundary vertices of mesh and interior vertices are subjet to harmonic smoothing unless you turn it off by calling
mesh.snap_boundary(left, False)

So if you want to move interior vertices either you can do it by writting into mesh.coordinates().

You could also do
submesh = SubMesh(mesh, left)
submesh.move(displacement)
where displacement is instance of Function with appropriate shape. But I'm not sure whether harmonic smoothing can be turned on/off in Mesh.move() method.