Skip to content

Commit 2c064c2

Browse files
authored
Merge pull request #122 from nschloe/documentation-for-sizes
Documentation for sizes
2 parents 8abb8b1 + f1361a6 commit 2c064c2

30 files changed

Lines changed: 680 additions & 518 deletions

README.md

Lines changed: 77 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ import pygalmesh
3636
points = numpy.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
3737
constraints = [[0, 1], [1, 2], [2, 3], [3, 0]]
3838

39-
mesh = pygalmesh.generate_2d(points, constraints, edge_size=1.0e-1, num_lloyd_steps=10)
39+
mesh = pygalmesh.generate_2d(
40+
points,
41+
constraints,
42+
max_edge_size=1.0e-1,
43+
num_lloyd_steps=10,
44+
)
4045
# mesh.points, mesh.cells
4146
```
4247
The quality of the mesh isn't very good, but can be improved with
@@ -49,7 +54,7 @@ The quality of the mesh isn't very good, but can be improved with
4954
import pygalmesh
5055

5156
s = pygalmesh.Ball([0, 0, 0], 1.0)
52-
mesh = pygalmesh.generate_mesh(s, cell_size=0.2)
57+
mesh = pygalmesh.generate_mesh(s, max_cell_circumradius=0.2)
5358

5459
# mesh.points, mesh.cells, ...
5560
```
@@ -65,7 +70,7 @@ The mesh generation comes with many more options, described
6570
<!--exdown-skip-->
6671
```python
6772
mesh = pygalmesh.generate_mesh(
68-
s, cell_size=0.2, edge_size=0.1, odt=True, lloyd=True, verbose=False
73+
s, max_cell_circumradius=0.2, odt=True, lloyd=True, verbose=False
6974
)
7075
```
7176

@@ -80,7 +85,11 @@ import pygalmesh
8085
s0 = pygalmesh.Tetrahedron(
8186
[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]
8287
)
83-
mesh = pygalmesh.generate_mesh(s0, cell_size=0.1, edge_size=0.1)
88+
mesh = pygalmesh.generate_mesh(
89+
s0,
90+
max_cell_circumradius=0.1,
91+
max_edge_size_at_feature_edges=0.1,
92+
)
8493
```
8594

8695
#### Domain combinations
@@ -111,8 +120,8 @@ u = pygalmesh.Difference(s0, s1)
111120

112121
# add circle
113122
a = numpy.sqrt(radius ** 2 - displacement ** 2)
114-
edge_size = 0.15
115-
n = int(2 * numpy.pi * a / edge_size)
123+
max_edge_size_at_feature_edges = 0.15
124+
n = int(2 * numpy.pi * a / max_edge_size_at_feature_edges)
116125
circ = [
117126
[0.0, a * numpy.cos(i * 2 * numpy.pi / n), a * numpy.sin(i * 2 * numpy.pi / n)]
118127
for i in range(n)
@@ -122,15 +131,16 @@ circ.append(circ[0])
122131
mesh = pygalmesh.generate_mesh(
123132
u,
124133
feature_edges=[circ],
125-
cell_size=0.15,
126-
edge_size=edge_size,
127-
facet_angle=25,
128-
facet_size=0.15,
129-
cell_radius_edge_ratio=2.0,
134+
max_cell_circumradius=0.15,
135+
max_edge_size_at_feature_edges=max_edge_size_at_feature_edges,
136+
min_facet_angle=25,
137+
max_radius_surface_delaunay_ball=0.15,
138+
max_circumradius_edge_ratio=2.0,
130139
)
131140
```
132-
Note that the length of the polygon legs are kept in sync with the `edge_size` of the
133-
mesh generation. This makes sure that it fits in nicely with the rest of the mesh.
141+
Note that the length of the polygon legs are kept in sync with
142+
`max_edge_size_at_feature_edges` of the mesh generation. This makes sure that it fits in
143+
nicely with the rest of the mesh.
134144

135145
#### Domain deformations
136146
<img src="https://nschloe.github.io/pygalmesh/egg.png" width="30%">
@@ -141,7 +151,7 @@ import pygalmesh
141151

142152
s = pygalmesh.Stretch(pygalmesh.Ball([0, 0, 0], 1.0), [1.0, 2.0, 0.0])
143153

144-
mesh = pygalmesh.generate_mesh(s, cell_size=0.1)
154+
mesh = pygalmesh.generate_mesh(s, max_cell_circumradius=0.1)
145155
```
146156

147157
#### Extrusion of 2D polygons
@@ -153,10 +163,18 @@ alongside!
153163
import pygalmesh
154164

155165
p = pygalmesh.Polygon2D([[-0.5, -0.3], [0.5, -0.3], [0.0, 0.5]])
156-
edge_size = 0.1
157-
domain = pygalmesh.Extrude(p, [0.0, 0.0, 1.0], 0.5 * 3.14159265359, edge_size)
166+
max_edge_size_at_feature_edges = 0.1
167+
domain = pygalmesh.Extrude(
168+
p,
169+
[0.0, 0.0, 1.0],
170+
0.5 * 3.14159265359,
171+
max_edge_size_at_feature_edges,
172+
)
158173
mesh = pygalmesh.generate_mesh(
159-
domain, cell_size=0.1, edge_size=edge_size, verbose=False
174+
domain,
175+
max_cell_circumradius=0.1,
176+
max_edge_size_at_feature_edges=max_edge_size_at_feature_edges,
177+
verbose=False,
160178
)
161179
```
162180
Feature edges are automatically preserved here, which is why an edge length needs to be
@@ -171,10 +189,13 @@ body.
171189
import pygalmesh
172190

173191
p = pygalmesh.Polygon2D([[0.5, -0.3], [1.5, -0.3], [1.0, 0.5]])
174-
edge_size = 0.1
175-
domain = pygalmesh.RingExtrude(p, edge_size)
192+
max_edge_size_at_feature_edges = 0.1
193+
domain = pygalmesh.RingExtrude(p, max_edge_size_at_feature_edges)
176194
mesh = pygalmesh.generate_mesh(
177-
domain, cell_size=0.1, edge_size=edge_size, verbose=False
195+
domain,
196+
max_cell_circumradius=0.1,
197+
max_edge_size_at_feature_edges=max_edge_size_at_feature_edges,
198+
verbose=False,
178199
)
179200
```
180201

@@ -204,7 +225,7 @@ class Heart(pygalmesh.DomainBase):
204225

205226

206227
d = Heart()
207-
mesh = pygalmesh.generate_mesh(d, cell_size=0.1)
228+
mesh = pygalmesh.generate_mesh(d, max_cell_circumradius=0.1)
208229
```
209230
Note that you need to specify the square of a bounding sphere radius, used as an input
210231
to CGAL's mesh generator.
@@ -213,33 +234,37 @@ to CGAL's mesh generator.
213234
#### Local refinement
214235
<img src="https://nschloe.github.io/pygalmesh/ball-local-refinement.png" width="30%">
215236

216-
Use `generate_mesh` with a function (regular or lambda) as `cell_size`. The same goes
217-
for `edge_size`, `facet_size`, and `facet_distance`.
237+
Use `generate_mesh` with a function (regular or lambda) as `max_cell_circumradius`. The
238+
same goes for `max_edge_size_at_feature_edges`, `max_radius_surface_delaunay_ball`, and
239+
`max_facet_distance`.
218240
```python
219241
import numpy
220242
import pygalmesh
221243

222244
mesh = pygalmesh.generate_mesh(
223245
pygalmesh.Ball([0.0, 0.0, 0.0], 1.0),
224-
facet_angle=30,
225-
facet_size=0.1,
226-
facet_distance=0.025,
227-
cell_radius_edge_ratio=2,
228-
cell_size=lambda x: abs(numpy.sqrt(numpy.dot(x, x)) - 0.5) / 5 + 0.025,
246+
min_facet_angle=30.0,
247+
max_radius_surface_delaunay_ball=0.1,
248+
max_facet_distance=0.025,
249+
max_circumradius_edge_ratio=2.0,
250+
max_cell_circumradius=lambda x: abs(numpy.sqrt(numpy.dot(x, x)) - 0.5) / 5 + 0.025,
229251
)
230252
```
231253

232254
#### Surface meshes
233255

234256
If you're only after the surface of a body, pygalmesh has `generate_surface_mesh` for
235-
you. It offers fewer options (obviously, `cell_size` is gone), but otherwise works the
236-
same way:
257+
you. It offers fewer options (obviously, `max_cell_circumradius` is gone), but otherwise
258+
works the same way:
237259
```python
238260
import pygalmesh
239261

240262
s = pygalmesh.Ball([0, 0, 0], 1.0)
241263
mesh = pygalmesh.generate_surface_mesh(
242-
s, angle_bound=30, radius_bound=0.1, distance_bound=0.1
264+
s,
265+
min_facet_angle=30.0,
266+
max_radius_surface_delaunay_ball=0.1,
267+
max_facet_distance=0.1,
243268
)
244269
```
245270
Refer to [CGAL's
@@ -272,11 +297,11 @@ class Schwarz(pygalmesh.DomainBase):
272297
mesh = pygalmesh.generate_periodic_mesh(
273298
Schwarz(),
274299
[0, 0, 0, 1, 1, 1],
275-
cell_size=0.05,
276-
facet_angle=30,
277-
facet_size=0.05,
278-
facet_distance=0.025,
279-
cell_radius_edge_ratio=2.0,
300+
max_cell_circumradius=0.05,
301+
min_facet_angle=30,
302+
max_radius_surface_delaunay_ball=0.05,
303+
max_facet_distance=0.025,
304+
max_circumradius_edge_ratio=2.0,
280305
number_of_copies_in_output=4,
281306
# odt=True,
282307
# lloyd=True,
@@ -302,10 +327,10 @@ import pygalmesh
302327

303328
mesh = pygalmesh.generate_volume_mesh_from_surface_mesh(
304329
"elephant.vtu",
305-
facet_angle=25.0,
306-
facet_size=0.15,
307-
facet_distance=0.008,
308-
cell_radius_edge_ratio=3.0,
330+
min_facet_angle=25.0,
331+
max_radius_surface_delaunay_ball=0.15,
332+
max_facet_distance=0.008,
333+
max_circumradius_edge_ratio=3.0,
309334
verbose=False,
310335
)
311336
```
@@ -326,7 +351,7 @@ import pygalmesh
326351

327352
mesh = pygalmesh.generate_from_inr(
328353
"skull_2.9.inr",
329-
cell_size=5.0,
354+
max_cell_circumradius=5.0,
330355
verbose=False,
331356
)
332357
```
@@ -357,7 +382,9 @@ with open("MergedPhantom.DAT", "rb") as fid:
357382

358383
vol = vol.reshape((Nx, Ny, Nz))
359384

360-
mesh = pygalmesh.generate_from_array(vol, h, facet_distance=0.2, cell_size=1.0)
385+
mesh = pygalmesh.generate_from_array(
386+
vol, h, max_facet_distance=0.2, max_cell_circumradius=1.0
387+
)
361388
mesh.write("breast.vtk")
362389
```
363390

@@ -368,7 +395,10 @@ tissue (label `5`), and *2 mm* for all other tissues (`default`).
368395
<!--exdown-skip-->
369396
```python
370397
mesh = pygalmesh.generate_from_array(
371-
vol, h, facet_distance=0.2, cell_size={"default": 2.0, 4: 1.0, 5: 0.5}
398+
vol,
399+
h,
400+
max_facet_distance=0.2,
401+
max_cell_circumradius={"default": 2.0, 4: 1.0, 5: 0.5},
372402
)
373403
mesh.write("breast_adapted.vtk")
374404
```
@@ -391,10 +421,10 @@ import pygalmesh
391421

392422
mesh = pygalmesh.remesh_surface(
393423
"lion-head.off",
394-
edge_size=0.025,
395-
facet_angle=25,
396-
facet_size=0.1,
397-
facet_distance=0.001,
424+
max_edge_size_at_feature_edges=0.025,
425+
min_facet_angle=25,
426+
max_radius_surface_delaunay_ball=0.1,
427+
max_facet_distance=0.001,
398428
verbose=False,
399429
)
400430
```

pygalmesh/_cli/_inr.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def inr(argv=None):
1616
odt=args.odt,
1717
perturb=args.perturb,
1818
exude=args.exude,
19-
edge_size=args.edge_size,
20-
facet_angle=args.facet_angle,
21-
facet_size=args.facet_size,
22-
facet_distance=args.facet_distance,
23-
cell_radius_edge_ratio=args.cell_radius_edge_ratio,
24-
cell_size=args.cell_size,
19+
max_edge_size_at_feature_edges=args.max_edge_size_at_feature_edges,
20+
min_facet_angle=args.min_facet_angle,
21+
max_radius_surface_delaunay_ball=args.max_radius_surface_delaunay_ball,
22+
max_facet_distance=args.max_facet_distance,
23+
max_circumradius_edge_ratio=args.max_circumradius_edge_ratio,
24+
max_cell_circumradius=args.max_cell_circumradius,
2525
verbose=not args.quiet,
2626
)
2727
meshio.write(args.outfile, mesh)
@@ -70,39 +70,51 @@ def _get_inr_parser():
7070
)
7171

7272
parser.add_argument(
73-
"--edge-size", "-e", type=float, default=0.0, help="edge size (default: 0.0)"
73+
"--max-edge-size-at-feature-edges",
74+
"-e",
75+
type=float,
76+
default=0.0,
77+
help="maximum edge size at feature edges (default: 0.0)",
7478
)
7579

7680
parser.add_argument(
77-
"--facet-angle",
81+
"--min-facet-angle",
7882
"-a",
7983
type=float,
8084
default=0.0,
81-
help="facet angle (default: 0.0)",
85+
help="minimum facet angle (default: 0.0)",
8286
)
8387

8488
parser.add_argument(
85-
"--facet-size", "-s", type=float, default=0.0, help="facet size (default: 0.0)"
89+
"--max-radius-surface-delaunay-ball",
90+
"-s",
91+
type=float,
92+
default=0.0,
93+
help="maximum radius of the surface facet Delaunay ball (default: 0.0)",
8694
)
8795

8896
parser.add_argument(
89-
"--facet-distance",
97+
"--max-facet-distance",
9098
"-d",
9199
type=float,
92100
default=0.0,
93-
help="facet distance (default: 0.0)",
101+
help="maximum facet distance (default: 0.0)",
94102
)
95103

96104
parser.add_argument(
97-
"--cell-radius-edge-ratio",
105+
"--max-circumradius-edge-ratio",
98106
"-r",
99107
type=float,
100108
default=0.0,
101109
help="cell radius/edge ratio (default: 0.0)",
102110
)
103111

104112
parser.add_argument(
105-
"--cell-size", "-c", type=float, default=0.0, help="cell size (default: 0.0)"
113+
"--max-cell-circumradius",
114+
"-c",
115+
type=float,
116+
default=0.0,
117+
help="maximum cell circumradius (default: 0.0)",
106118
)
107119

108120
parser.add_argument(

0 commit comments

Comments
 (0)