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

Move mesh after refining

0 votes

Hi,

I am using DOLFIN version: 1.7.0dev. I try to introduce a small and localized perturbation in a 3D mesh near point p which is on the surface of the meshed volume. In a first step I need to refine the mesh in the neighbourhood of point p:

p = Point(x0, y0, z0)
for i in range(1):

   print("marking for refinement")

   # Mark cells for refinement
   cell_markers = CellFunction("bool", mesh)
   for c in cells(mesh):
       if c.midpoint().distance(p) < 0.1:
           cell_markers[c] = True
       else:
           cell_markers[c] = False

   # Refine mesh
   mesh = refine(mesh, cell_markers)

In a second step I define the perturbation and move the mesh :

lpx = 0.01
lpy = 0.01

class MyExpression1(Expression):
    def eval(self, value, x):
        value[0] = lpx*exp(-((x[0]-x0)**2.+(x[1]-y0)**2.+(x[2]-z0)**2.)/lpx**2)
        value[1] = -lpy*exp(-((x[0]-x0)**2.+(x[1]-y0)**2.+(x[2]-z0)**2.)/lpy**2)
        value[2] = 0
    def value_shape(self):
        return (3,)

u3D = interpolate(MyExpression1(),V)
mesh.move(u3D)

But I get the following error :

*** Error:   Unable to interpolate function values at vertices.
*** Reason:  Non-matching mesh.
*** Where:   This error was encountered inside Function.cpp.

Is it possible to combine functions refine and move on a mesh ?

Many thanks in advance for your help !

Claire

asked Mar 25, 2016 by Claire L FEniCS User (2,120 points)
edited Mar 25, 2016 by Claire L

1 Answer

0 votes
 
Best answer

Hi,
using fenics 1.7dev with your code i'm getting the following error:

AttributeError: 'Mesh' object has no attribute 'move'

But using fenics 1.6 version, the solution to your problem is the next:

p = Point(x0, y0, z0)
for i in range(1):

   print("marking for refinement")

   # Mark cells for refinement
   cell_markers = CellFunction("bool", mesh)
   cell_markers.set_all(False)
   for c in cells(mesh):
       if c.midpoint().distance(p) < 0.2:
           cell_markers[c] = True

   # Refine mesh
   adapt(mesh, cell_markers)

   # adapt function space to refined mesh
   adapt(V, mesh.child())

# Update mesh and function space to refined versions    
mesh = mesh.child()
V = V.child()

lpx = 0.01
lpy = 0.01

class MyExpression1(Expression):
    def eval(self, value, x):
        value[0] = lpx*exp(-((x[0]-x0)**2.+(x[1]-y0)**2.+(x[2]-z0)**2.)/lpx**2)
        value[1] = -lpy*exp(-((x[0]-x0)**2.+(x[1]-y0)**2.+(x[2]-z0)**2.)/lpy**2)
        value[2] = 0
    def value_shape(self):
        return (3,)

u3D = interpolate(MyExpression1(), V)
mesh.move(u3D)
answered Mar 25, 2016 by hernan_mella FEniCS Expert (19,460 points)
edited Apr 5, 2016 by hernan_mella

It works fine, thanks ! Perhaps I was wrong about the version : how do you check it ?

write in a terminal: dolfin-version

Regards!

1.7.0dev
mysterious....

Maybe we have installed the dev version in different times (with some changes in between)

If I understand well, now mesh.move is in ALE.move. The new class ALE has extended functionality for this. This should be the relevant changset: ba595c2

Great. Many thanks for the clarification =)

...