dmsh 0.3.9__cp315-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dmsh/py.typed ADDED
File without changes
@@ -0,0 +1,320 @@
1
+ Metadata-Version: 2.4
2
+ Name: dmsh
3
+ Version: 0.3.9
4
+ Summary: High-quality 2D mesh generator based on distmesh
5
+ Author-email: Nico Schlömer <nico.schloemer@gmail.com>
6
+ License-Expression: LicenseRef-Proprietary
7
+ Project-URL: Home, https://github.com/meshpro/dmsh
8
+ Project-URL: Issues, https://github.com/meshpro/dmsh/issues
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: 3.15
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ Requires-Dist: meshplex<0.23.0,>=0.22.4
25
+ Requires-Dist: npx
26
+ Requires-Dist: numpy
27
+ Requires-Dist: stonefish-license-manager>=0.8
28
+ Requires-Dist: stonefish-runtime>=0.8
29
+ Requires-Dist: scipy
30
+ Provides-Extra: all
31
+ Requires-Dist: matplotlib; extra == "all"
32
+ Requires-Dist: stonefish-runtime>=0.8.1
33
+
34
+ <p align="center">
35
+ <a href="https://github.com/nschloe/dmsh"><img alt="dmsh" src="https://raw.githubusercontent.com/meshpro/dmsh/main/logo/logo-with-text.svg" width="50%"></a>
36
+ <p align="center">The worst mesh generator you'll ever use.</p>
37
+ </p>
38
+
39
+ [![PyPi Version](https://img.shields.io/pypi/v/dmsh.svg?style=flat-square)](https://pypi.org/project/dmsh/)
40
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/dmsh.svg?style=flat-square)](https://pypi.org/project/dmsh/)
41
+ [![GitHub stars](https://img.shields.io/github/stars/nschloe/dmsh.svg?style=flat-square&logo=github&label=Stars&logoColor=white)](https://github.com/nschloe/dmsh)
42
+ [![PyPi downloads](https://img.shields.io/pypi/dm/dmsh.svg?style=flat-square)](https://pypistats.org/packages/dmsh)
43
+
44
+ [![Discord](https://img.shields.io/static/v1?logo=discord&label=chat&message=on%20discord&color=7289da&style=flat-square)](https://discord.gg/PBCCvwHqpv)
45
+
46
+ Inspired by [distmesh](http://persson.berkeley.edu/distmesh/), dmsh can be slow,
47
+ requires a lot of memory, and isn't terribly robust either.
48
+
49
+ On the plus side,
50
+
51
+ - it's got a user-friendly interface,
52
+ - is pure Python (and hence easily installable on any system), and
53
+ - it produces pretty high-quality meshes.
54
+
55
+ Combined with [optimesh](https://github.com/nschloe/optimesh), dmsh produces the
56
+ highest-quality 2D meshes in the west.
57
+
58
+ ### Examples
59
+
60
+ #### Primitives
61
+
62
+ | <img alt="circle" src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/circle.svg" width="100%"> | <img alt="circle" src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/rectangle.svg" width="100%"> | <img alt="circle" src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/polygon.svg" width="100%"> |
63
+ | :--------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------: |
64
+
65
+ ```python
66
+ import dmsh
67
+ import meshio
68
+ import optimesh
69
+
70
+ geo = dmsh.Circle([0.0, 0.0], 1.0)
71
+ X, cells = dmsh.generate(geo, 0.1)
72
+
73
+ # optionally optimize the mesh
74
+ X, cells = optimesh.optimize_points_cells(X, cells, "CVT (full)", 1.0e-10, 100)
75
+
76
+ # visualize the mesh
77
+ dmsh.show(X, cells, geo)
78
+
79
+ # and write it to a file
80
+ meshio.Mesh(X, {"triangle": cells}).write("circle.vtk")
81
+ ```
82
+
83
+ ```python
84
+ import dmsh
85
+
86
+ geo = dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0)
87
+ X, cells = dmsh.generate(geo, 0.1)
88
+ ```
89
+
90
+ ```python
91
+ import dmsh
92
+
93
+ geo = dmsh.Polygon(
94
+ [
95
+ [0.0, 0.0],
96
+ [1.1, 0.0],
97
+ [1.2, 0.5],
98
+ [0.7, 0.6],
99
+ [2.0, 1.0],
100
+ [1.0, 2.0],
101
+ [0.5, 1.5],
102
+ ]
103
+ )
104
+ X, cells = dmsh.generate(geo, 0.1)
105
+ ```
106
+
107
+ #### Combinations
108
+
109
+ ##### Difference
110
+
111
+ | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/moon.svg" width="100%"> | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/pacman.svg" width="100%"> | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/rectangle-hole-refinement.svg" width="100%"> |
112
+ | :-----------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------: |
113
+
114
+ ```python
115
+ import dmsh
116
+
117
+ geo = dmsh.Circle([-0.5, 0.0], 1.0) - dmsh.Circle([+0.5, 0.0], 1.0)
118
+ X, cells = dmsh.generate(geo, 0.1)
119
+ ```
120
+
121
+ ```python
122
+ import dmsh
123
+
124
+ geo = dmsh.Circle([0.0, 0.0], 1.0) - dmsh.Polygon([[0.0, 0.0], [1.5, 0.4], [1.5, -0.4]])
125
+ X, cells = dmsh.generate(geo, 0.1, tol=1.0e-10)
126
+ ```
127
+
128
+ The following example uses a nonconstant edge length; it depends on the distance to the
129
+ circle `c`.
130
+
131
+ ```python
132
+ import dmsh
133
+ import numpy as np
134
+
135
+ r = dmsh.Rectangle(-1.0, +1.0, -1.0, +1.0)
136
+ c = dmsh.Circle([0.0, 0.0], 0.3)
137
+ geo = r - c
138
+
139
+ X, cells = dmsh.generate(geo, lambda pts: np.abs(c.dist(pts)) / 5 + 0.05, tol=1.0e-10)
140
+ ```
141
+
142
+ ##### Union
143
+
144
+ | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/union-circles.svg" width="100%"> | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/union-rectangles.svg" width="100%"> | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/union-three-circles.svg" width="100%"> |
145
+ | :--------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------: |
146
+
147
+ ```python
148
+ import dmsh
149
+
150
+ geo = dmsh.Circle([-0.5, 0.0], 1.0) + dmsh.Circle([+0.5, 0.0], 1.0)
151
+ X, cells = dmsh.generate(geo, 0.15)
152
+ ```
153
+
154
+ ```python
155
+ import dmsh
156
+
157
+ geo = dmsh.Rectangle(-1.0, +0.5, -1.0, +0.5) + dmsh.Rectangle(-0.5, +1.0, -0.5, +1.0)
158
+ X, cells = dmsh.generate(geo, 0.15)
159
+ ```
160
+
161
+ ```python
162
+ import dmsh
163
+ import numpy as np
164
+
165
+ angles = np.pi * np.array([3.0 / 6.0, 7.0 / 6.0, 11.0 / 6.0])
166
+ geo = dmsh.Union(
167
+ [
168
+ dmsh.Circle([np.cos(angles[0]), np.sin(angles[0])], 1.0),
169
+ dmsh.Circle([np.cos(angles[1]), np.sin(angles[1])], 1.0),
170
+ dmsh.Circle([np.cos(angles[2]), np.sin(angles[2])], 1.0),
171
+ ]
172
+ )
173
+ X, cells = dmsh.generate(geo, 0.15)
174
+ ```
175
+
176
+ #### Intersection
177
+
178
+ | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/intersection-circles.svg" width="100%"> | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/intersection-three-circles.svg" width="100%"> | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/intersection-circle-halfspace.svg" width="100%"> |
179
+ | :---------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------: |
180
+
181
+ ```python
182
+ import dmsh
183
+
184
+ geo = dmsh.Circle([0.0, -0.5], 1.0) & dmsh.Circle([0.0, +0.5], 1.0)
185
+ X, cells = dmsh.generate(geo, 0.1, tol=1.0e-10)
186
+ ```
187
+
188
+ ```python
189
+ import dmsh
190
+ import numpy as np
191
+
192
+ angles = np.pi * np.array([3.0 / 6.0, 7.0 / 6.0, 11.0 / 6.0])
193
+ geo = dmsh.Intersection(
194
+ [
195
+ dmsh.Circle([np.cos(angles[0]), np.sin(angles[0])], 1.5),
196
+ dmsh.Circle([np.cos(angles[1]), np.sin(angles[1])], 1.5),
197
+ dmsh.Circle([np.cos(angles[2]), np.sin(angles[2])], 1.5),
198
+ ]
199
+ )
200
+ X, cells = dmsh.generate(geo, 0.1, tol=1.0e-10)
201
+ ```
202
+
203
+ The following uses the `HalfSpace` primtive for cutting off a circle.
204
+
205
+ ```python
206
+ import dmsh
207
+
208
+ geo = dmsh.HalfSpace([1.0, 1.0]) & dmsh.Circle([0.0, 0.0], 1.0)
209
+ X, cells = dmsh.generate(geo, 0.1)
210
+ ```
211
+
212
+ ### Rotation, translation, scaling
213
+
214
+ | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/rotation.svg" width="100%"> | <img src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/scaling.svg" width="100%"> |
215
+ | :---------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------: |
216
+
217
+ ```python
218
+ import dmsh
219
+ import numpy as np
220
+
221
+ geo = dmsh.Rotation(dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0), 0.1 * np.pi)
222
+ X, cells = dmsh.generate(geo, 0.1, tol=1.0e-10)
223
+ ```
224
+
225
+ ```python
226
+ import dmsh
227
+
228
+ geo = dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0) + [1.0, 1.0]
229
+ X, cells = dmsh.generate(geo, 0.1)
230
+ ```
231
+
232
+ ```python
233
+ import dmsh
234
+
235
+ geo = dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0) * 2.0
236
+ X, cells = dmsh.generate(geo, 0.1, tol=1.0e-5)
237
+ ```
238
+
239
+ ### Local refinement
240
+
241
+ <img alt="local-refinement" src="https://raw.githubusercontent.com/meshpro/dmsh/main/plots/local-refinement.svg" width="30%">
242
+
243
+ All objects can be used to refine the mesh according to the distance to the object;
244
+ e.g. a `Path`:
245
+
246
+ ```python
247
+ import dmsh
248
+
249
+ geo = dmsh.Rectangle(0.0, 1.0, 0.0, 1.0)
250
+
251
+ p1 = dmsh.Path([[0.4, 0.6], [0.6, 0.4]])
252
+
253
+
254
+ def target_edge_length(x):
255
+ return 0.03 + 0.1 * p1.dist(x)
256
+
257
+
258
+ X, cells = dmsh.generate(geo, target_edge_length, tol=1.0e-10)
259
+ ```
260
+
261
+ ### Custom shapes
262
+
263
+ It is also possible to define your own geometry. Simply create a class derived from
264
+ `dmsh.Geometry` that contains a `dist` method and a method to project points onto the
265
+ boundary.
266
+
267
+ ```python
268
+ import dmsh
269
+ import numpy as np
270
+
271
+
272
+ class MyDisk(dmsh.Geometry):
273
+ def __init__(self):
274
+ self.r = 1.0
275
+ self.x0 = [0.0, 0.0]
276
+ bounding_box = [-1.0, 1.0, -1.0, 1.0]
277
+ feature_points = np.array([[], []]).T
278
+ super().__init__(bounding_box, feature_points)
279
+
280
+ def dist(self, x):
281
+ assert x.shape[0] == 2
282
+ y = (x.T - self.x0).T
283
+ return np.sqrt(np.einsum("i...,i...->...", y, y)) - self.r
284
+
285
+ def boundary_step(self, x):
286
+ # project onto the circle
287
+ y = (x.T - self.x0).T
288
+ r = np.sqrt(np.einsum("ij,ij->j", y, y))
289
+ return ((y / r * self.r).T + self.x0).T
290
+
291
+
292
+ geo = MyDisk()
293
+ X, cells = dmsh.generate(geo, 0.1)
294
+ ```
295
+
296
+ ### Debugging
297
+
298
+ | ![level-set-poly](https://raw.githubusercontent.com/meshpro/dmsh/main/plots/levelset-polygon.png) | ![level-set-rect-hole](https://raw.githubusercontent.com/meshpro/dmsh/main/plots/levelset-rect-hole.png) |
299
+ | :-----------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------: |
300
+
301
+ dmsh is rather fragile, but sometimes the break-downs are due to an incorrectly defined
302
+ geometry. Use
303
+
304
+ ```
305
+ geo.show()
306
+ ```
307
+
308
+ to inspect the level set function of your domain. (It must be negative inside the
309
+ domain and positive outside. The 0-level set forms the domain boundary.)
310
+
311
+ ### Installation
312
+
313
+ dmsh is [available from the Python Package
314
+ Index](https://pypi.org/project/dmsh/), so simply type
315
+
316
+ ```
317
+ pip install dmsh
318
+ ```
319
+
320
+ to install.
@@ -0,0 +1,6 @@
1
+ dmsh/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ dmsh-0.3.9.dist-info/METADATA,sha256=so2YtsA95LHskBl6F3LCuoQFZsZa_cBjpHbQkUS_0yQ,11195
3
+ dmsh-0.3.9.dist-info/WHEEL,sha256=E0bxZwGow566sLu-koO-FIhzqGs-_etk-jdmZvGiCJ0,91
4
+ dmsh-0.3.9.dist-info/top_level.txt,sha256=k0yVaKPAwcsf1B5dwMb9lUsxo0GXQi23BzruoCHPdXw,5
5
+ dmsh.cpython-315.sfc,sha256=p0pUM_98qsttXjdlYtFG8wmtN7S0JMZY52YhN_28ElI,103722
6
+ dmsh-0.3.9.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: stonefish (0.8.1)
3
+ Root-Is-Purelib: true
4
+ Tag: cp315-none-any
5
+
@@ -0,0 +1 @@
1
+ dmsh
dmsh.cpython-315.sfc ADDED
Binary file