Skip to content

Instantly share code, notes, and snippets.

@michalhabera
Created June 27, 2018 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michalhabera/456cb6179bed1b1e2205efe6bbe824c9 to your computer and use it in GitHub Desktop.
Save michalhabera/456cb6179bed1b1e2205efe6bbe824c9 to your computer and use it in GitHub Desktop.
Preliminary tests of mesh tagging with pygmsh-meshio-dolfin pipeline
from pygmsh.built_in.geometry import Geometry
from pygmsh import generate_mesh
import meshio
from dolfin import Mesh, MeshFunction, XDMFFile
geom = Geometry()
lc = .1
p0 = geom.add_point([0, 0, 0], lcar=lc)
p1 = geom.add_point([1, 0, 0], lcar=lc)
p2 = geom.add_point([1, 1, 0], lcar=lc)
p3 = geom.add_point([0, 1, 0], lcar=lc)
l0 = geom.add_line(p0, p1)
l1 = geom.add_line(p1, p2)
l2 = geom.add_line(p2, p3)
l3 = geom.add_line(p3, p0)
ll = geom.add_line_loop(lines=[l0, l1, l2, l3])
ps = geom.add_plane_surface(ll)
# Tag line and surface
geom.add_physical_line(lines=l3, label=444)
geom.add_physical_surface(surfaces=ps, label=456)
points, cells, point_data, cell_data, field_data = generate_mesh(geom)
meshio.write("mesh_2d.xdmf", meshio.Mesh(
points=points,
cells={"triangle": cells["triangle"]}))
meshio.write("mf_1d.xdmf", meshio.Mesh(
points=points,
cells={"line": cells["line"]},
cell_data={"line": cell_data["line"]}
))
mesh_2d = Mesh()
with XDMFFile("mesh_2d.xdmf") as infile:
infile.read(mesh_2d)
mf = MeshFunction("size_t", mesh_2d, 1)
with XDMFFile("mf_1d.xdmf") as infile:
infile.read(mf, "gmsh:physical")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment