Skip to content

Commit

Permalink
Adding function to recombine mesh for generation of quad elements (#305)
Browse files Browse the repository at this point in the history
* adding set_recombined_surfaces in geometry.py for generation of quad meshes and adding corresponding test in test_recombine.py. Related to issue #304

* reformatting test_recombine.py to pass ci/lint checks:

*  adding whitespace around arithmetic operator as indicated by ci/lint tests

* using black to reformat

* reformatting test_recombine.py
  • Loading branch information
amine-aboufirass authored Feb 13, 2020
1 parent e5216ff commit 61882d9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pygmsh/built_in/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ def set_transfinite_surface(self, surface, size=None, orientation=None):
self._GMSH_CODE.append(code + ";")
return

def set_recombined_surfaces(self, surfaces):
for i, surface in enumerate(surfaces):
assert isinstance(
surface, (PlaneSurface, Surface)
), "item {} is not a surface".format(i)
code = "Recombine Surface {{{}}}".format(
", ".join([surface.id for surface in surfaces])
)
self._GMSH_CODE.append(code + ";")
return

def add_circle(
self,
x0,
Expand Down
34 changes: 34 additions & 0 deletions test/test_recombine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pygmsh
import numpy as np


def test():
geom = pygmsh.built_in.Geometry()
p0 = geom.add_point((0.0, 0.0, 0.0), lcar=1.0)
p1 = geom.add_point((2.0, 0.0, 0.0), lcar=1.0)
p2 = geom.add_point((0.0, 1.0, 0.0), lcar=1.0)
p3 = geom.add_point((2.0, 1.0, 0.0), lcar=1.0)
l0 = geom.add_line(p0, p1)
l1 = geom.add_line(p1, p3)
l2 = geom.add_line(p3, p2)
l3 = geom.add_line(p2, p0)
ll0 = geom.add_line_loop((l0, l1, l2, l3))
rs0 = geom.add_surface(ll0)
geom.set_transfinite_lines([l3, l1], 3, progression=1)
geom.set_transfinite_lines([l2, l0], 3, progression=1)
geom.set_transfinite_surface(rs0)
geom.set_recombined_surfaces([rs0])

mesh = pygmsh.generate_mesh(geom)

assert "quad" in mesh.cells.keys()
ref = np.array([[0, 4, 8, 7], [7, 8, 6, 2], [4, 1, 5, 8], [8, 5, 3, 6]])
assert np.array_equal(ref, mesh.cells["quad"])

return mesh


if __name__ == "__main__":
import meshio

meshio.write("rectangle_structured.vtk", test())

0 comments on commit 61882d9

Please sign in to comment.