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

MeshFunction Refine

+2 votes

Hi all,

http://fenicsproject.org/qa/44/mesh-refine-meshfunction
from the link above we know we can refine the mesh, which is equivalent to use high order function space.
But I have a problem about the MeshFunction refine. Suppose we do the following:

mesh=UnitSquareMesh(2,2)
mesh1=refine(mesh)
f=CellFunction("uint",mesh)
f.set_all(0)
f.array()[2:5]=1
f_refined = adapt(f,mesh1)

Traceback (most recent call last):
File "", line 1, in
File "/Applications/FEniCS1.2.app/Contents/Resources/lib/python2.7/site-packages/dolfin/cpp/fem.py", line 3572, in adapt
return _fem.adapt(*args)
RuntimeError:

*** -------------------------------------------------------------------------
*** Error: Unable to adapt mesh function.
*** Reason: Unable to extract information about parent mesh entites.
*** Where: This error was encountered inside adapt.cpp.
*** Process: 0
*** -------------------------------------------------------------------------

In the help file, the python support the syntax adapt(mesh_function, refined_mesh). I do not what goes wrong here. since in above asked question, they all have the same problems. Any help would be appreciated. Thanks.

asked Aug 17, 2013 by jying FEniCS User (2,020 points)
reopened Aug 19, 2013 by jying

2 Answers

+1 vote
 
Best answer

Hi,
I think that there is some problem with the refine () function if it is called just with one argument.
In fact, if you do the following, it should work

from dolfin import *
mesh=UnitSquareMesh(2,2)
cell_markers = CellFunction("bool", mesh)
cell_markers.set_all(True)
mesh1=refine(mesh, cell_markers)
f=CellFunction("uint",mesh)
f.set_all(0)
f.array()[2:5]=1
f_refined = adapt(f,mesh1)
answered Aug 20, 2013 by gedeone FEniCS User (1,110 points)
selected Aug 21, 2013 by jying

Funny, same answer in five minutes :D

+3 votes

Avoid using uniform refinement which does not set parent entities. Reported as issue 105.

mesh = UnitSquareMesh(2, 2)

cf = CellFunction('bool', mesh, True)
mesh1 = refine(mesh, cf)

f = CellFunction("size_t", mesh)
f.set_all(0)
f.array()[2:5] = 1
f_refined = adapt(f, mesh1)
answered Aug 20, 2013 by Jan Blechta FEniCS Expert (51,420 points)

Thanks a lot for answering, guys.

...