Skip to content

Instantly share code, notes, and snippets.

@swarbhanu
Created December 13, 2011 20:43
Show Gist options
  • Save swarbhanu/1473803 to your computer and use it in GitHub Desktop.
Save swarbhanu/1473803 to your computer and use it in GitHub Desktop.
Localized mesh refinement using a CellFunction
from dolfin import *
import numpy
mesh = UnitSquare(8,8)
mesh = refine(mesh)
# editor = MeshEditor()
# editor.open(mesh,2,2)
# editor.add_cell(0,0,1,2)
# editor.add_cell(1,0,2,3)
# editor.close()
# plot(mesh, interactive = True) # uncomment to plot
#######################################################################
## One way of creating a mesh function
#######################################################################
# create a mesh function
# mesh_function = MeshFunction(mesh, 2)
# initialize it all to False
cell_marker = CellFunction("bool", mesh)
cell_marker.set_all(False)
# mesh_function.set_all(0)
origin=Point(0,0,0)
for cell in cells(mesh):
p=cell.midpoint()
if p.distance(origin) < 0.1:
cell_marker[cell]=True
# mesh_function[cell]=1
#refine the mesh in the sub domain where meshFunction is True
mesh=refine(mesh, cell_marker)
#plot(mesh_function, mesh=mesh, rescale=True, title="Vector function")
plot(mesh, interactive=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment