Skip to content

Commit

Permalink
extend the use of layers to rotational extrusions
Browse files Browse the repository at this point in the history
  • Loading branch information
capitalaslash committed Dec 18, 2017
1 parent 8f88bad commit 666b6f8
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions pygmsh/built_in/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,36 +301,35 @@ def extrude(

# out[] = Extrude{0,1,0}{ Line{1}; };
name = 'ex{}'.format(self._EXTRUDE_ID)
if translation_axis is not None and rotation_axis is not None:
self._GMSH_CODE.append(
'{}[] = Extrude{{{{{}}}, {{{}}}, {{{}}}, {}}}{{{};}};'
.format(
name,
','.join(repr(x) for x in translation_axis),
','.join(repr(x) for x in rotation_axis),
','.join(repr(x) for x in point_on_axis),
angle,
entity.id
))

elif translation_axis is not None:
# Only translation
if num_layers is None:
self._GMSH_CODE.append(
'{}[] = Extrude{{{}}}{{{};}};'.format(
if translation_axis is not None:
if rotation_axis is not None:
extrusion_string = \
'{}[] = Extrude{{{{{}}}, {{{}}}, {{{}}}, {}}}{{{};'.format(
name,
','.join(repr(x) for x in translation_axis),
','.join(repr(x) for x in rotation_axis),
','.join(repr(x) for x in point_on_axis),
angle,
entity.id
))
)
else:
self._GMSH_CODE.append(
'{}[] = Extrude{{{}}}{{{}; Layers{{{}}}; {}}};'.format(
# Only translation
extrusion_string = \
'{}[] = Extrude{{{}}}{{{};}};'.format(
name,
','.join(repr(x) for x in translation_axis),
entity.id,
entity.id
)

if num_layers is not None:
extrusion_string += \
' Layers{{{}}}; {}'.format(
num_layers,
'Recombine;' if recombine else ''
))
)
# close command
extrusion_string += '};'
self._GMSH_CODE.append(extrusion_string)
else:
assert rotation_axis is not None, \
'Specify at least translation or rotation.'
Expand Down

2 comments on commit 666b6f8

@gdmcbain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a problem here in case rotation_axis is None and num_layers is not None, as in test_layers.py #109. Looking at the two alternatives for extrusion_string depending on whether rotation_axis is not None (lines 306 and 317), I get (running that test in pdb), respectively:

'ex1[] = Extrude{{0,0,1.0}, {}, {}, None}{Surface{s1};'

and

'ex1[] = Extrude{0,0,1.0}{Surface{s1};};'

Since the latter applies to test_layers.py, the result for extrusion_string is:

'ex1[] = Extrude{0,0,1.0}{Surface{s1};}; Layers{1}; };'

which is syntactically invalid Gmsh .geo.

Actually it doesn't generate a syntax error in Gmsh because the line is unfinished (no end-of-line character); if one is added manually, it does. Is that a Gmsh quirk?

Anyway, I'll see whether I can propose a fix.

@capitalaslash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, the solution in #130 looks good to me.

Please sign in to comment.