mmgpy 0.5.0__cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.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.
Files changed (109) hide show
  1. mmgpy/__init__.py +296 -0
  2. mmgpy/__main__.py +13 -0
  3. mmgpy/_io.py +535 -0
  4. mmgpy/_logging.py +290 -0
  5. mmgpy/_mesh.py +2286 -0
  6. mmgpy/_mmgpy.cpython-311-x86_64-linux-gnu.so +0 -0
  7. mmgpy/_mmgpy.pyi +2140 -0
  8. mmgpy/_options.py +304 -0
  9. mmgpy/_progress.py +850 -0
  10. mmgpy/_pyvista.py +410 -0
  11. mmgpy/_result.py +143 -0
  12. mmgpy/_transfer.py +273 -0
  13. mmgpy/_validation.py +669 -0
  14. mmgpy/_version.py +3 -0
  15. mmgpy/_version.py.in +3 -0
  16. mmgpy/bin/mmg2d_O3 +0 -0
  17. mmgpy/bin/mmg3d_O3 +0 -0
  18. mmgpy/bin/mmgs_O3 +0 -0
  19. mmgpy/interactive/__init__.py +24 -0
  20. mmgpy/interactive/sizing_editor.py +790 -0
  21. mmgpy/lagrangian.py +394 -0
  22. mmgpy/lib/libmmg2d.so +0 -0
  23. mmgpy/lib/libmmg2d.so.5 +0 -0
  24. mmgpy/lib/libmmg2d.so.5.8.0 +0 -0
  25. mmgpy/lib/libmmg3d.so +0 -0
  26. mmgpy/lib/libmmg3d.so.5 +0 -0
  27. mmgpy/lib/libmmg3d.so.5.8.0 +0 -0
  28. mmgpy/lib/libmmgs.so +0 -0
  29. mmgpy/lib/libmmgs.so.5 +0 -0
  30. mmgpy/lib/libmmgs.so.5.8.0 +0 -0
  31. mmgpy/lib/libvtkCommonColor-9.5.so.1 +0 -0
  32. mmgpy/lib/libvtkCommonComputationalGeometry-9.5.so.1 +0 -0
  33. mmgpy/lib/libvtkCommonCore-9.5.so.1 +0 -0
  34. mmgpy/lib/libvtkCommonDataModel-9.5.so.1 +0 -0
  35. mmgpy/lib/libvtkCommonExecutionModel-9.5.so.1 +0 -0
  36. mmgpy/lib/libvtkCommonMath-9.5.so.1 +0 -0
  37. mmgpy/lib/libvtkCommonMisc-9.5.so.1 +0 -0
  38. mmgpy/lib/libvtkCommonSystem-9.5.so.1 +0 -0
  39. mmgpy/lib/libvtkCommonTransforms-9.5.so.1 +0 -0
  40. mmgpy/lib/libvtkDICOMParser-9.5.so.1 +0 -0
  41. mmgpy/lib/libvtkFiltersCellGrid-9.5.so.1 +0 -0
  42. mmgpy/lib/libvtkFiltersCore-9.5.so.1 +0 -0
  43. mmgpy/lib/libvtkFiltersExtraction-9.5.so.1 +0 -0
  44. mmgpy/lib/libvtkFiltersGeneral-9.5.so.1 +0 -0
  45. mmgpy/lib/libvtkFiltersGeometry-9.5.so.1 +0 -0
  46. mmgpy/lib/libvtkFiltersHybrid-9.5.so.1 +0 -0
  47. mmgpy/lib/libvtkFiltersHyperTree-9.5.so.1 +0 -0
  48. mmgpy/lib/libvtkFiltersModeling-9.5.so.1 +0 -0
  49. mmgpy/lib/libvtkFiltersParallel-9.5.so.1 +0 -0
  50. mmgpy/lib/libvtkFiltersReduction-9.5.so.1 +0 -0
  51. mmgpy/lib/libvtkFiltersSources-9.5.so.1 +0 -0
  52. mmgpy/lib/libvtkFiltersStatistics-9.5.so.1 +0 -0
  53. mmgpy/lib/libvtkFiltersTexture-9.5.so.1 +0 -0
  54. mmgpy/lib/libvtkFiltersVerdict-9.5.so.1 +0 -0
  55. mmgpy/lib/libvtkIOCellGrid-9.5.so.1 +0 -0
  56. mmgpy/lib/libvtkIOCore-9.5.so.1 +0 -0
  57. mmgpy/lib/libvtkIOGeometry-9.5.so.1 +0 -0
  58. mmgpy/lib/libvtkIOImage-9.5.so.1 +0 -0
  59. mmgpy/lib/libvtkIOLegacy-9.5.so.1 +0 -0
  60. mmgpy/lib/libvtkIOParallel-9.5.so.1 +0 -0
  61. mmgpy/lib/libvtkIOParallelXML-9.5.so.1 +0 -0
  62. mmgpy/lib/libvtkIOXML-9.5.so.1 +0 -0
  63. mmgpy/lib/libvtkIOXMLParser-9.5.so.1 +0 -0
  64. mmgpy/lib/libvtkImagingCore-9.5.so.1 +0 -0
  65. mmgpy/lib/libvtkImagingSources-9.5.so.1 +0 -0
  66. mmgpy/lib/libvtkParallelCore-9.5.so.1 +0 -0
  67. mmgpy/lib/libvtkParallelDIY-9.5.so.1 +0 -0
  68. mmgpy/lib/libvtkRenderingCore-9.5.so.1 +0 -0
  69. mmgpy/lib/libvtkdoubleconversion-9.5.so.1 +0 -0
  70. mmgpy/lib/libvtkexpat-9.5.so.1 +0 -0
  71. mmgpy/lib/libvtkfmt-9.5.so.1 +0 -0
  72. mmgpy/lib/libvtkjpeg-9.5.so.1 +0 -0
  73. mmgpy/lib/libvtkjsoncpp-9.5.so.1 +0 -0
  74. mmgpy/lib/libvtkkissfft-9.5.so.1 +0 -0
  75. mmgpy/lib/libvtkloguru-9.5.so.1 +0 -0
  76. mmgpy/lib/libvtklz4-9.5.so.1 +0 -0
  77. mmgpy/lib/libvtklzma-9.5.so.1 +0 -0
  78. mmgpy/lib/libvtkmetaio-9.5.so.1 +0 -0
  79. mmgpy/lib/libvtkpng-9.5.so.1 +0 -0
  80. mmgpy/lib/libvtkpugixml-9.5.so.1 +0 -0
  81. mmgpy/lib/libvtksys-9.5.so.1 +0 -0
  82. mmgpy/lib/libvtktiff-9.5.so.1 +0 -0
  83. mmgpy/lib/libvtktoken-9.5.so.1 +0 -0
  84. mmgpy/lib/libvtkverdict-9.5.so.1 +0 -0
  85. mmgpy/lib/libvtkzlib-9.5.so.1 +0 -0
  86. mmgpy/metrics.py +596 -0
  87. mmgpy/progress.py +69 -0
  88. mmgpy/py.typed +0 -0
  89. mmgpy/repair/__init__.py +37 -0
  90. mmgpy/repair/_core.py +226 -0
  91. mmgpy/repair/_elements.py +241 -0
  92. mmgpy/repair/_vertices.py +219 -0
  93. mmgpy/sizing.py +370 -0
  94. mmgpy/ui/__init__.py +97 -0
  95. mmgpy/ui/__main__.py +87 -0
  96. mmgpy/ui/app.py +1837 -0
  97. mmgpy/ui/parsers.py +501 -0
  98. mmgpy/ui/remeshing.py +448 -0
  99. mmgpy/ui/samples.py +249 -0
  100. mmgpy/ui/utils.py +280 -0
  101. mmgpy/ui/viewer.py +587 -0
  102. mmgpy-0.5.0.dist-info/METADATA +186 -0
  103. mmgpy-0.5.0.dist-info/RECORD +109 -0
  104. mmgpy-0.5.0.dist-info/WHEEL +6 -0
  105. mmgpy-0.5.0.dist-info/entry_points.txt +13 -0
  106. mmgpy-0.5.0.dist-info/licenses/LICENSE +38 -0
  107. share/man/man1/mmg2d.1.gz +0 -0
  108. share/man/man1/mmg3d.1.gz +0 -0
  109. share/man/man1/mmgs.1.gz +0 -0
mmgpy/_options.py ADDED
@@ -0,0 +1,304 @@
1
+ """Typed options dataclasses for mmgpy remeshing operations.
2
+
3
+ This module provides structured configuration objects for mesh remeshing,
4
+ offering better IDE support, validation, and preset configurations.
5
+
6
+ Example:
7
+ -------
8
+ >>> from mmgpy import MmgMesh3D, Mmg3DOptions
9
+ >>>
10
+ >>> mesh = MmgMesh3D(vertices, elements)
11
+ >>>
12
+ >>> # Using options dataclass
13
+ >>> options = Mmg3DOptions(hmax=0.1, hausd=0.001)
14
+ >>> mesh.remesh(options)
15
+ >>>
16
+ >>> # Using factory presets
17
+ >>> mesh.remesh(Mmg3DOptions.fine(hmax=0.05))
18
+
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ from dataclasses import dataclass, fields
24
+ from typing import TYPE_CHECKING
25
+
26
+ if TYPE_CHECKING:
27
+ from typing import Self
28
+
29
+ # Maximum angle value for ridge detection (degrees)
30
+ _MAX_ANGLE_DEGREES = 180
31
+
32
+ # Minimum gradation value
33
+ _MIN_GRADATION = 1.0
34
+
35
+
36
+ def _validate_common_options(opts: Mmg3DOptions | Mmg2DOptions | MmgSOptions) -> None:
37
+ """Validate options common to all mesh types.
38
+
39
+ Parameters
40
+ ----------
41
+ opts : Mmg3DOptions | Mmg2DOptions | MmgSOptions
42
+ Options object to validate.
43
+
44
+ Raises
45
+ ------
46
+ ValueError
47
+ If any option value is invalid.
48
+
49
+ """
50
+ if opts.hmin is not None and opts.hmin <= 0:
51
+ msg = "hmin must be positive"
52
+ raise ValueError(msg)
53
+ if opts.hmax is not None and opts.hmax <= 0:
54
+ msg = "hmax must be positive"
55
+ raise ValueError(msg)
56
+ if opts.hsiz is not None and opts.hsiz <= 0:
57
+ msg = "hsiz must be positive"
58
+ raise ValueError(msg)
59
+ if opts.hmin is not None and opts.hmax is not None and opts.hmin > opts.hmax:
60
+ msg = "hmin must be less than or equal to hmax"
61
+ raise ValueError(msg)
62
+ if opts.hausd is not None and opts.hausd <= 0:
63
+ msg = "hausd must be positive"
64
+ raise ValueError(msg)
65
+ if opts.hgrad is not None and opts.hgrad < _MIN_GRADATION:
66
+ msg = f"hgrad must be >= {_MIN_GRADATION}"
67
+ raise ValueError(msg)
68
+ # hgradreq can be -1 to disable, or >= 1.0 for gradation control
69
+ if (
70
+ opts.hgradreq is not None
71
+ and opts.hgradreq != -1
72
+ and opts.hgradreq < _MIN_GRADATION
73
+ ):
74
+ msg = f"hgradreq must be >= {_MIN_GRADATION} or -1 to disable"
75
+ raise ValueError(msg)
76
+ if opts.ar is not None and (opts.ar < 0 or opts.ar > _MAX_ANGLE_DEGREES):
77
+ msg = f"ar (angle detection) must be between 0 and {_MAX_ANGLE_DEGREES} degrees"
78
+ raise ValueError(msg)
79
+ if opts.mem is not None and opts.mem <= 0:
80
+ msg = "mem must be positive"
81
+ raise ValueError(msg)
82
+
83
+
84
+ def _options_to_dict(
85
+ opts: _MmgOptionsBase,
86
+ ) -> dict[str, float | int]:
87
+ """Convert options to dictionary for passing to remesh().
88
+
89
+ Parameters
90
+ ----------
91
+ opts : _MmgOptionsBase
92
+ Options object to convert.
93
+
94
+ Returns
95
+ -------
96
+ dict[str, float | int]
97
+ Dictionary with non-None values, booleans converted to int.
98
+
99
+ """
100
+ result: dict[str, float | int] = {}
101
+ for f in fields(opts):
102
+ value = getattr(opts, f.name)
103
+ if value is None:
104
+ continue
105
+ if isinstance(value, bool):
106
+ if value:
107
+ result[f.name] = 1
108
+ else:
109
+ result[f.name] = value
110
+ return result
111
+
112
+
113
+ @dataclass(slots=True, kw_only=True, frozen=True)
114
+ class _MmgOptionsBase:
115
+ """Base class for MMG options with common parameters.
116
+
117
+ This class contains parameters shared by all MMG variants (2D, 3D, surface).
118
+ Do not instantiate directly - use the specific subclasses.
119
+
120
+ """
121
+
122
+ # Size control parameters
123
+ hmin: float | None = None
124
+ """Minimum edge size."""
125
+
126
+ hmax: float | None = None
127
+ """Maximum edge size."""
128
+
129
+ hsiz: float | None = None
130
+ """Constant edge size (overrides hmin/hmax)."""
131
+
132
+ hausd: float | None = None
133
+ """Hausdorff distance for geometry approximation."""
134
+
135
+ # Gradation parameters
136
+ hgrad: float | None = None
137
+ """Gradation parameter (default ~1.3). Controls size transition between
138
+ adjacent elements. Must be >= 1.0."""
139
+
140
+ hgradreq: float | None = None
141
+ """Gradation on required entities (advanced usage). Must be >= 1.0,
142
+ or -1 to disable gradation control on required entities."""
143
+
144
+ # Geometry detection
145
+ ar: float | None = None
146
+ """Angle detection threshold in degrees (0-180). Edges with angles
147
+ sharper than this are preserved as ridges."""
148
+
149
+ # Runtime parameters
150
+ verbose: int | None = None
151
+ """Verbosity level (-1=silent, 0=errors, 1=info, higher=debug)."""
152
+
153
+ mem: int | None = None
154
+ """Maximum memory usage in MB."""
155
+
156
+ # Optimization flags
157
+ optim: bool = False
158
+ """Enable mesh optimization mode."""
159
+
160
+ noinsert: bool = False
161
+ """Disable point insertion."""
162
+
163
+ noswap: bool = False
164
+ """Disable edge/face swapping."""
165
+
166
+ nomove: bool = False
167
+ """Disable point relocation."""
168
+
169
+ def to_dict(self) -> dict[str, float | int]:
170
+ """Convert options to dictionary for passing to remesh().
171
+
172
+ Returns
173
+ -------
174
+ dict[str, float | int]
175
+ Dictionary with non-None values, booleans converted to int.
176
+
177
+ """
178
+ return _options_to_dict(self)
179
+
180
+ @classmethod
181
+ def fine(cls, *, hmax: float, hausd: float | None = None) -> Self:
182
+ """Create options for fine mesh with tight quality control.
183
+
184
+ Parameters
185
+ ----------
186
+ hmax : float
187
+ Maximum edge size.
188
+ hausd : float | None
189
+ Hausdorff distance. Defaults to hmax/10.
190
+
191
+ """
192
+ return cls(
193
+ hmax=hmax,
194
+ hausd=hausd if hausd is not None else hmax / 10,
195
+ hgrad=1.2,
196
+ )
197
+
198
+ @classmethod
199
+ def coarse(cls, *, hmax: float) -> Self:
200
+ """Create options for coarse mesh with relaxed constraints.
201
+
202
+ Parameters
203
+ ----------
204
+ hmax : float
205
+ Maximum edge size.
206
+
207
+ """
208
+ return cls(
209
+ hmax=hmax,
210
+ hgrad=1.5,
211
+ )
212
+
213
+ @classmethod
214
+ def optimize_only(cls, *, verbose: int | None = None) -> Self:
215
+ """Create options for optimization without topology changes.
216
+
217
+ Only moves vertices to improve quality, no insertion/deletion.
218
+
219
+ """
220
+ return cls(
221
+ optim=True,
222
+ noinsert=True,
223
+ verbose=verbose,
224
+ )
225
+
226
+
227
+ @dataclass(slots=True, kw_only=True, frozen=True)
228
+ class Mmg3DOptions(_MmgOptionsBase):
229
+ """Options for 3D tetrahedral mesh remeshing (MMG3D).
230
+
231
+ All parameters are optional. When None, MMG uses its internal defaults.
232
+ Options are immutable after creation.
233
+
234
+ Inherits from _MmgOptionsBase:
235
+ hmin, hmax, hsiz, hausd, hgrad, hgradreq, ar, verbose, mem,
236
+ optim, noinsert, noswap, nomove
237
+
238
+ Additional Attributes
239
+ ---------------------
240
+ nosurf : bool
241
+ Disable surface modifications (3D only).
242
+
243
+ Example:
244
+ -------
245
+ >>> opts = Mmg3DOptions(hmax=0.1, hausd=0.01)
246
+ >>> mesh.remesh(opts) # Pass options directly
247
+
248
+ """
249
+
250
+ nosurf: bool = False
251
+ """Disable surface modifications (3D only)."""
252
+
253
+ def __post_init__(self) -> None:
254
+ """Validate options after initialization."""
255
+ _validate_common_options(self)
256
+
257
+
258
+ @dataclass(slots=True, kw_only=True, frozen=True)
259
+ class Mmg2DOptions(_MmgOptionsBase):
260
+ """Options for 2D triangular mesh remeshing (MMG2D).
261
+
262
+ All parameters are optional. When None, MMG uses its internal defaults.
263
+ Options are immutable after creation.
264
+
265
+ Inherits from _MmgOptionsBase:
266
+ hmin, hmax, hsiz, hausd, hgrad, hgradreq, ar, verbose, mem,
267
+ optim, noinsert, noswap, nomove
268
+
269
+ Additional Attributes
270
+ ---------------------
271
+ nosurf : bool
272
+ Disable boundary modifications.
273
+
274
+ """
275
+
276
+ nosurf: bool = False
277
+ """Disable boundary modifications."""
278
+
279
+ def __post_init__(self) -> None:
280
+ """Validate options after initialization."""
281
+ _validate_common_options(self)
282
+
283
+
284
+ @dataclass(slots=True, kw_only=True, frozen=True)
285
+ class MmgSOptions(_MmgOptionsBase):
286
+ """Options for surface mesh remeshing (MMGS).
287
+
288
+ All parameters are optional. When None, MMG uses its internal defaults.
289
+ Options are immutable after creation.
290
+
291
+ Inherits from _MmgOptionsBase:
292
+ hmin, hmax, hsiz, hausd, hgrad, hgradreq, ar, verbose, mem,
293
+ optim, noinsert, noswap, nomove
294
+
295
+ Note: Surface remeshing (MMGS) does not have a nosurf option.
296
+
297
+ """
298
+
299
+ def __post_init__(self) -> None:
300
+ """Validate options after initialization."""
301
+ _validate_common_options(self)
302
+
303
+
304
+ __all__ = ["Mmg2DOptions", "Mmg3DOptions", "MmgSOptions"]