How to implement local mesh refinement?


278
views
1
5 months ago by
Dario  
I'm using Fenics 2017.2.0 version and have problems with refine. I would like to refine the mesh in the middle of the square
In all situation I get this warning:

File "/usr/lib/python3/dist-packages/dolfin/mesh/refinement.py", line 79, in refine
cpp.refine(refined_mesh, mesh, cell_markers, redistribute)
File "/usr/lib/python3/dist-packages/dolfin/cpp/mesh.py", line 8857, in refine
return _mesh.refine(*args)
TypeError: in method 'refine', argument 3 of type 'dolfin::MeshFunction< bool > const &'

Code is:
from fenics import *
from mshr import *

# Domain and mesh generation
domain = Rectangle(Point(0, 0), Point(1, 1))
mesh = generate_mesh(domain, 15)

cell_markers = MeshFunction("int", mesh, 2)
origin = Point(0.5, 0.5)
for cell in cells(mesh):
	p = cell.midpoint()
	if p.distance(origin) < 0.2:
		cell_markers[cell] = True

mesh2 = refine(mesh, cell_markers, redistribute=True)
​
I used redistribute as a third argument in refine and I tried without it, with false and other combination.
Community: FEniCS Project

1 Answer


6
5 months ago by
Hi Dario,
Try changing cell_markers to:

cell_markers = MeshFunction("bool", mesh, 2)​


Hope it works for you!

Please login to add an answer/comment or follow this question.

Similar posts:
Search »