simgeometry 0.1.0__py3-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.
Files changed (62) hide show
  1. simgeometry/__init__.py +38 -0
  2. simgeometry/_bounds.py +16 -0
  3. simgeometry/_normalize.py +23 -0
  4. simgeometry/_particle_boundaries.py +37 -0
  5. simgeometry/_types.py +22 -0
  6. simgeometry/api.py +247 -0
  7. simgeometry/boundingbox.py +231 -0
  8. simgeometry/collection.py +65 -0
  9. simgeometry/crossings.py +319 -0
  10. simgeometry/cut_edges.py +309 -0
  11. simgeometry/cylindrical.py +43 -0
  12. simgeometry/domain_decomposition.py +496 -0
  13. simgeometry/evaluation.py +105 -0
  14. simgeometry/fractions.py +68 -0
  15. simgeometry/grid.py +238 -0
  16. simgeometry/kernels/__init__.py +1 -0
  17. simgeometry/kernels/_build.py +53 -0
  18. simgeometry/kernels/_metal.py +41 -0
  19. simgeometry/kernels/compile.py +24 -0
  20. simgeometry/kernels/contains_ball/__init__.py +12 -0
  21. simgeometry/kernels/contains_ball/contains_ball_cuda.cu +27 -0
  22. simgeometry/kernels/contains_ball/contains_ball_metal.py +53 -0
  23. simgeometry/kernels/contains_ball/contains_ball_numpy.py +23 -0
  24. simgeometry/kernels/contains_ball/contains_ball_pyccel.py +31 -0
  25. simgeometry/kernels/contains_box/__init__.py +12 -0
  26. simgeometry/kernels/contains_box/contains_box_cuda.cu +26 -0
  27. simgeometry/kernels/contains_box/contains_box_metal.py +50 -0
  28. simgeometry/kernels/contains_box/contains_box_numpy.py +24 -0
  29. simgeometry/kernels/contains_box/contains_box_pyccel.py +32 -0
  30. simgeometry/kernels/contains_polygon_2d/__init__.py +12 -0
  31. simgeometry/kernels/contains_polygon_2d/contains_polygon_2d_cuda.cu +35 -0
  32. simgeometry/kernels/contains_polygon_2d/contains_polygon_2d_metal.py +58 -0
  33. simgeometry/kernels/contains_polygon_2d/contains_polygon_2d_numpy.py +28 -0
  34. simgeometry/kernels/contains_polygon_2d/contains_polygon_2d_pyccel.py +40 -0
  35. simgeometry/mesh.py +147 -0
  36. simgeometry/objects/__init__.py +35 -0
  37. simgeometry/objects/aperture2d.py +183 -0
  38. simgeometry/objects/aperture3d.py +361 -0
  39. simgeometry/objects/circle.py +138 -0
  40. simgeometry/objects/cuboid.py +173 -0
  41. simgeometry/objects/function_object.py +214 -0
  42. simgeometry/objects/line.py +127 -0
  43. simgeometry/objects/polygon.py +182 -0
  44. simgeometry/objects/polyline.py +67 -0
  45. simgeometry/objects/rectangle.py +130 -0
  46. simgeometry/objects/sphere.py +181 -0
  47. simgeometry/objects/triangle.py +148 -0
  48. simgeometry/operations.py +386 -0
  49. simgeometry/panels.py +80 -0
  50. simgeometry/plotting.py +179 -0
  51. simgeometry/py.typed +0 -0
  52. simgeometry/queries.py +445 -0
  53. simgeometry/sampling.py +75 -0
  54. simgeometry/shapes.py +402 -0
  55. simgeometry/simulation_domain.py +277 -0
  56. simgeometry/utils.py +24 -0
  57. simgeometry/visualization.py +381 -0
  58. simgeometry-0.1.0.dist-info/METADATA +128 -0
  59. simgeometry-0.1.0.dist-info/RECORD +62 -0
  60. simgeometry-0.1.0.dist-info/WHEEL +5 -0
  61. simgeometry-0.1.0.dist-info/licenses/LICENSE.txt +21 -0
  62. simgeometry-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,381 @@
1
+ """Optional 1D/2D inspection and 3D surface viewers.
2
+
3
+ Matplotlib is the default backend; PyVista adds interactive clipping widgets.
4
+ Plots are sampled views. Increase resolution before interpreting small features.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from itertools import product
10
+
11
+ import numpy as np
12
+
13
+
14
+ def _finish(ax, display, save):
15
+ import matplotlib.pyplot as plt
16
+
17
+ if save:
18
+ ax.figure.savefig(save, bbox_inches="tight")
19
+ if display:
20
+ plt.show()
21
+ return ax
22
+
23
+
24
+ def show(
25
+ shape,
26
+ *,
27
+ x=None,
28
+ y=None,
29
+ z=None,
30
+ ax=None,
31
+ resolution=None,
32
+ bounds=None,
33
+ grid=None,
34
+ nodes=False,
35
+ labels=True,
36
+ normals=False,
37
+ show_bounds=False,
38
+ color=None,
39
+ color_by="name",
40
+ opacity=0.65,
41
+ display=True,
42
+ save=None,
43
+ **kwargs,
44
+ ):
45
+ """Plot occupancy or a slice; dimensions and coordinates are labelled."""
46
+ import matplotlib.pyplot as plt
47
+ from matplotlib.colors import ListedColormap
48
+ from matplotlib.patches import Patch
49
+
50
+ selectors = {k: v for k, v in zip("xyz", (x, y, z)) if v is not None}
51
+ if resolution is None:
52
+ resolution = 48 if shape.ndim == 3 and not selectors else 128
53
+ if shape.ndim == 3 and not selectors:
54
+ return show_3d(
55
+ shape,
56
+ ax=ax,
57
+ resolution=resolution,
58
+ bounds=bounds,
59
+ grid=grid,
60
+ nodes=nodes,
61
+ labels=labels,
62
+ normals=normals,
63
+ show_bounds=show_bounds,
64
+ color=color,
65
+ color_by=color_by,
66
+ opacity=opacity,
67
+ display=display,
68
+ save=save,
69
+ **kwargs,
70
+ )
71
+ if color_by not in (None, "name"):
72
+ raise ValueError("color_by must be 'name' or None")
73
+ if grid is True:
74
+ raise ValueError("Pass a Grid object, or use domain.show(grid=True)")
75
+ if grid is not None and grid.ndim != shape.ndim:
76
+ raise ValueError("Grid and geometry dimensions must match")
77
+ grid_axes = list(grid.get_grid_points()) if grid is not None else None
78
+ if selectors:
79
+ if len(selectors) != 1:
80
+ raise ValueError("Select one coordinate for a geometry slice")
81
+ source_names = getattr(shape, "axis_names", tuple("xyz"[: shape.ndim]))
82
+ name = next(iter(selectors))
83
+ if name not in source_names:
84
+ raise ValueError(f"Available slice axes are {source_names}")
85
+ axis = source_names.index(name)
86
+ shape = shape.slice(**selectors)
87
+ if grid_axes is not None:
88
+ grid_axes.pop(axis)
89
+ if bounds is not None:
90
+ bounds = tuple(np.delete(v, axis) for v in bounds)
91
+ names = getattr(shape, "axis_names", tuple("xyz"[: shape.ndim]))
92
+ coordinates = dict(zip(names, grid_axes)) if grid_axes is not None else {}
93
+ quantity = "labels" if hasattr(shape, "labels") else "occupancy"
94
+ values = shape.evaluate(
95
+ **coordinates, resolution=resolution, bounds=bounds, quantity=quantity
96
+ )
97
+ ax = ax or plt.subplots()[1]
98
+ if shape.ndim == 1:
99
+ ax.step(
100
+ values.coords[names[0]], values.values, where="mid", color=color, **kwargs
101
+ )
102
+ ax.set_ylabel(quantity)
103
+ else:
104
+ xs, ys = (values.coords[n].values for n in names)
105
+ object_names = getattr(shape, "names", ("geometry",))
106
+ styles = getattr(
107
+ shape, "styles", getattr(getattr(shape, "source", None), "styles", {})
108
+ )
109
+ colors = [
110
+ styles.get(name, {}).get(
111
+ "color",
112
+ styles.get(name, {}).get(
113
+ "facecolor", color or (f"C{i % 10}" if color_by == "name" else "C0")
114
+ ),
115
+ )
116
+ for i, name in enumerate(object_names)
117
+ ]
118
+ cmap = ListedColormap(colors or [color or "C0"])
119
+ data = np.ma.masked_where(values.values == 0, values.values.astype(float) - 1)
120
+ style = {
121
+ "cmap": cmap,
122
+ "vmin": -0.5,
123
+ "vmax": max(len(colors) - 0.5, 0.5),
124
+ "alpha": opacity,
125
+ **kwargs,
126
+ }
127
+ ax.pcolormesh(xs, ys, data.T, shading="nearest", **style)
128
+ if labels and len(object_names):
129
+ ax.legend(
130
+ handles=[Patch(color=c, label=n) for n, c in zip(object_names, colors)]
131
+ )
132
+ if grid_axes is not None:
133
+ for value in xs:
134
+ ax.axvline(value, color="gray", linewidth=0.4, alpha=0.5)
135
+ for value in ys:
136
+ ax.axhline(value, color="gray", linewidth=0.4, alpha=0.5)
137
+ if nodes:
138
+ xx, yy = np.meshgrid(xs, ys, indexing="ij")
139
+ ax.scatter(
140
+ xx.ravel(),
141
+ yy.ravel(),
142
+ c=(values.values != 0).ravel(),
143
+ cmap="coolwarm",
144
+ s=5,
145
+ )
146
+ if normals:
147
+ mesh = shape.to_mesh(resolution=resolution, bounds=bounds)
148
+ stride = max(1, len(mesh.cells) // 48)
149
+ ax.quiver(*mesh.centres[::stride].T, *mesh.normals[::stride].T, angles="xy")
150
+ if show_bounds:
151
+ lower, upper = bounds or (shape.lower_bound, shape.upper_bound)
152
+ ax.plot(
153
+ [lower[0], upper[0], upper[0], lower[0], lower[0]],
154
+ [lower[1], lower[1], upper[1], upper[1], lower[1]],
155
+ color="black",
156
+ )
157
+ ax.set_aspect("equal")
158
+ ax.set_ylabel(names[1])
159
+ ax.set_xlabel(names[0])
160
+ if selectors:
161
+ ax.set_title(", ".join(f"{k} = {v:g}" for k, v in selectors.items()))
162
+ return _finish(ax, display, save)
163
+
164
+
165
+ def _clip_triangles(vertices, faces, origin, normal):
166
+ """Clip each triangle against a half-space, without adding artificial caps."""
167
+ origin, normal = np.asarray(origin, float), np.asarray(normal, float)
168
+ if (
169
+ origin.shape != (3,)
170
+ or normal.shape != (3,)
171
+ or not np.all(np.isfinite([origin, normal]))
172
+ or np.linalg.norm(normal) == 0
173
+ ):
174
+ raise ValueError("Clip plane needs finite 3D origin and nonzero normal")
175
+ triangles = []
176
+ for triangle in vertices[faces]:
177
+ polygon = []
178
+ for a, b in zip(triangle, np.roll(triangle, -1, axis=0)):
179
+ da, db = np.dot(a - origin, normal), np.dot(b - origin, normal)
180
+ if da >= 0:
181
+ polygon.append(a)
182
+ if (da >= 0) != (db >= 0):
183
+ polygon.append(a + da / (da - db) * (b - a))
184
+ for i in range(1, len(polygon) - 1):
185
+ triangles.append([polygon[0], polygon[i], polygon[i + 1]])
186
+ vertices = np.asarray(triangles).reshape(-1, 3)
187
+ return vertices, np.arange(len(vertices)).reshape(-1, 3)
188
+
189
+
190
+ def _box_edges(lower, upper):
191
+ vertices = np.array(list(product(*zip(lower, upper))))
192
+ return np.array(
193
+ [
194
+ [a, b]
195
+ for i, a in enumerate(vertices)
196
+ for b in vertices[i + 1 :]
197
+ if np.count_nonzero(a != b) == 1
198
+ ]
199
+ )
200
+
201
+
202
+ def show_3d(
203
+ shape,
204
+ *,
205
+ ax=None,
206
+ resolution=48,
207
+ bounds=None,
208
+ opacity=0.65,
209
+ wireframe=False,
210
+ normals=False,
211
+ labels=True,
212
+ color=None,
213
+ color_by="name",
214
+ grid=None,
215
+ nodes=False,
216
+ show_bounds=True,
217
+ clip=None,
218
+ backend="matplotlib",
219
+ display=True,
220
+ save=None,
221
+ **kwargs,
222
+ ):
223
+ """Render surfaces; return axes or an optional PyVista Plotter.
224
+
225
+ clip=(origin, normal) retains the positive half-space, without caps.
226
+ clip=True enables a PyVista clipping widget. PyVista callers own and should
227
+ close the returned plotter. No MPI operations are performed.
228
+ """
229
+ if shape.ndim != 3:
230
+ raise ValueError("show_3d requires three-dimensional geometry")
231
+ if backend not in ("matplotlib", "pyvista"):
232
+ raise ValueError("backend must be matplotlib or pyvista")
233
+ if color_by not in (None, "name"):
234
+ raise ValueError("color_by must be 'name' or None")
235
+ if grid is True:
236
+ raise ValueError("Pass a Grid object, or use domain.show_3d(grid=True)")
237
+ if grid is not None and grid.ndim != 3:
238
+ raise ValueError("A 3D view requires a 3D grid")
239
+ objects = getattr(shape, "named_objects", {"geometry": shape})
240
+ styles = getattr(shape, "styles", {})
241
+ lower, upper = bounds or (shape.lower_bound, shape.upper_bound)
242
+ if backend == "pyvista":
243
+ try:
244
+ from importlib import import_module
245
+
246
+ pv = import_module("pyvista")
247
+ except ImportError as exc:
248
+ raise ImportError("Interactive 3D needs simgeometry[interactive]") from exc
249
+ plotter = ax if ax is not None else pv.Plotter(off_screen=not display)
250
+ else:
251
+ import matplotlib.pyplot as plt
252
+ from matplotlib.colors import to_rgba
253
+ from matplotlib.patches import Patch
254
+ from mpl_toolkits.mplot3d.art3d import Line3DCollection, Poly3DCollection
255
+
256
+ if clip is True:
257
+ raise ValueError(
258
+ "Use backend='pyvista' for interactive clipping, or supply a plane"
259
+ )
260
+ ax = ax if ax is not None else plt.figure().add_subplot(projection="3d")
261
+ if not hasattr(ax, "set_zlabel"):
262
+ raise ValueError("Pass 3D axes to show_3d")
263
+ handles = []
264
+ for i, (name, obj) in enumerate(objects.items()):
265
+ mesh = obj.to_mesh(
266
+ resolution=resolution,
267
+ bounds=bounds
268
+ if bounds is not None
269
+ else ((lower, upper) if obj.inverted else None),
270
+ )
271
+ vertices, faces = mesh.vertices, mesh.cells
272
+ if clip is not None and clip is not False and clip is not True:
273
+ vertices, faces = _clip_triangles(vertices, faces, *clip)
274
+ if not len(faces):
275
+ continue
276
+ style = dict(styles.get(name, {}))
277
+ chosen = style.pop(
278
+ "color",
279
+ style.pop(
280
+ "facecolor", color or (f"C{i % 10}" if color_by == "name" else "C0")
281
+ ),
282
+ )
283
+ alpha = style.pop("opacity", style.pop("alpha", opacity))
284
+ if backend == "pyvista":
285
+ # Resolve Matplotlib cycle colors to RGB before passing to VTK.
286
+ from matplotlib.colors import to_rgb
287
+
288
+ data = pv.PolyData(
289
+ vertices, np.column_stack((np.full(len(faces), 3), faces)).ravel()
290
+ )
291
+ add = plotter.add_mesh_clip_plane if clip is True else plotter.add_mesh
292
+ add(
293
+ data,
294
+ color=to_rgb(chosen),
295
+ opacity=alpha,
296
+ style="wireframe" if wireframe else "surface",
297
+ label=name if labels else None,
298
+ **style,
299
+ **kwargs,
300
+ )
301
+ if normals:
302
+ stride = max(1, len(mesh.cells) // 64)
303
+ plotter.add_arrows(
304
+ mesh.centres[::stride],
305
+ mesh.normals[::stride],
306
+ mag=float(np.max(np.asarray(upper) - lower)) * 0.05,
307
+ )
308
+ else:
309
+ artist = Poly3DCollection(
310
+ vertices[faces],
311
+ facecolors="none" if wireframe else to_rgba(chosen, alpha),
312
+ edgecolors=chosen if wireframe else "none",
313
+ **style,
314
+ **kwargs,
315
+ )
316
+ ax.add_collection3d(artist)
317
+ handles.append(Patch(color=chosen, label=name))
318
+ if normals:
319
+ triangles = vertices[faces][:: max(1, len(faces) // 64)]
320
+ points = triangles.mean(axis=1).T
321
+ normal = np.cross(
322
+ triangles[:, 1] - triangles[:, 0], triangles[:, 2] - triangles[:, 0]
323
+ )
324
+ normal /= np.linalg.norm(normal, axis=1)[:, None]
325
+ ax.quiver(
326
+ *points,
327
+ *normal.T,
328
+ length=float(np.max(np.asarray(upper) - lower)) * 0.05,
329
+ )
330
+ if backend == "pyvista":
331
+ if show_bounds:
332
+ plotter.show_bounds(bounds=np.array([lower, upper]).T.ravel())
333
+ if grid is not None:
334
+ edges = _grid_lines_3d(grid)
335
+ for segment in edges:
336
+ plotter.add_lines(segment, color="gray", width=1)
337
+ if nodes:
338
+ plotter.add_points(grid.node_points().T, point_size=4)
339
+ if labels and objects:
340
+ plotter.add_legend()
341
+ if display or save:
342
+ plotter.show(screenshot=str(save) if save else None, auto_close=False)
343
+ return plotter
344
+ if show_bounds:
345
+ ax.add_collection3d(
346
+ Line3DCollection(_box_edges(lower, upper), colors="black", linewidths=0.6)
347
+ )
348
+ if grid is not None:
349
+ ax.add_collection3d(
350
+ Line3DCollection(
351
+ _grid_lines_3d(grid), colors="gray", linewidths=0.3, alpha=0.4
352
+ )
353
+ )
354
+ if nodes:
355
+ ax.scatter(*grid.node_points(), s=2, alpha=0.25)
356
+ for setter, a, b in zip((ax.set_xlim, ax.set_ylim, ax.set_zlim), lower, upper):
357
+ setter(a, b)
358
+ from matplotlib.ticker import MaxNLocator
359
+
360
+ for axis in (ax.xaxis, ax.yaxis, ax.zaxis):
361
+ axis.set_major_locator(MaxNLocator(nbins=4))
362
+ ax.set_box_aspect(np.asarray(upper) - lower)
363
+ ax.set_xlabel("x")
364
+ ax.set_ylabel("y")
365
+ ax.set_zlabel("z")
366
+ if labels and handles:
367
+ ax.legend(handles=handles)
368
+ return _finish(ax, display, save)
369
+
370
+
371
+ def _grid_lines_3d(grid):
372
+ axes = grid.get_grid_points()
373
+ segments = []
374
+ for axis in range(3):
375
+ other = [i for i in range(3) if i != axis]
376
+ for values in product(*(axes[i] for i in other)):
377
+ a, b = np.zeros(3), np.zeros(3)
378
+ a[other], b[other] = values, values
379
+ a[axis], b[axis] = grid.lower_bound[axis], grid.upper_bound[axis]
380
+ segments.append([a, b])
381
+ return np.asarray(segments)
@@ -0,0 +1,128 @@
1
+ Metadata-Version: 2.4
2
+ Name: simgeometry
3
+ Version: 0.1.0
4
+ Summary: Shapes, grids, and simulation domains for numerical simulations
5
+ Author: Max
6
+ License-Expression: MIT
7
+ Project-URL: Source, https://github.com/max-models/simgeometry
8
+ Keywords: geometry,grids,simulation,mpi
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE.txt
19
+ Requires-Dist: cunumpy>=0.6.2
20
+ Requires-Dist: maybempi>=0.1
21
+ Requires-Dist: mpiarray>=0.1.0
22
+ Requires-Dist: numpy
23
+ Provides-Extra: dev
24
+ Requires-Dist: jupyterlab; extra == "dev"
25
+ Requires-Dist: pre-commit; extra == "dev"
26
+ Requires-Dist: pyproject-fmt; extra == "dev"
27
+ Requires-Dist: pyright; extra == "dev"
28
+ Requires-Dist: ruff; extra == "dev"
29
+ Requires-Dist: simgeometry[docs,test]; extra == "dev"
30
+ Provides-Extra: docs
31
+ Requires-Dist: griffe; extra == "docs"
32
+ Requires-Dist: simgeometry[clip,plot]; extra == "docs"
33
+ Requires-Dist: ipykernel; extra == "docs"
34
+ Requires-Dist: matplotlib>=3.10.9; extra == "docs"
35
+ Requires-Dist: nbclient>=0.11; extra == "docs"
36
+ Requires-Dist: nbformat>=5.11.1; extra == "docs"
37
+ Provides-Extra: clip
38
+ Requires-Dist: shapely>=2; extra == "clip"
39
+ Provides-Extra: evaluate
40
+ Requires-Dist: xarray; extra == "evaluate"
41
+ Provides-Extra: mesh
42
+ Requires-Dist: scikit-image>=0.22; extra == "mesh"
43
+ Provides-Extra: plot
44
+ Requires-Dist: matplotlib>=3.10; extra == "plot"
45
+ Requires-Dist: simgeometry[evaluate,mesh]; extra == "plot"
46
+ Provides-Extra: interactive
47
+ Requires-Dist: pyvista>=0.44; extra == "interactive"
48
+ Requires-Dist: simgeometry[plot]; extra == "interactive"
49
+ Provides-Extra: mpi
50
+ Requires-Dist: mpi4py; extra == "mpi"
51
+ Provides-Extra: pyccel
52
+ Requires-Dist: pyccel>2.0; extra == "pyccel"
53
+ Provides-Extra: gpu
54
+ Requires-Dist: cupy-cuda12x; extra == "gpu"
55
+ Provides-Extra: metal
56
+ Requires-Dist: mlx; (sys_platform == "darwin" and platform_machine == "arm64") and extra == "metal"
57
+ Provides-Extra: test
58
+ Requires-Dist: mpi4py; extra == "test"
59
+ Requires-Dist: pytest; extra == "test"
60
+ Requires-Dist: pytest-cov; extra == "test"
61
+ Requires-Dist: simgeometry[clip]; extra == "test"
62
+ Dynamic: license-file
63
+
64
+ # simgeometry
65
+
66
+
67
+ Geometry primitives for numerical simulations: bounded domains,
68
+ structured grids, MPI domain decomposition, and 1D, 2D, and 3D shapes.
69
+ Box, ball, and polygon containment have NumPy, Pyccel, CUDA, and Metal
70
+ implementations. Originally developed for
71
+ [Picnic](https://github.com/max-models/picnic).
72
+
73
+ ## Install
74
+
75
+ ``` bash
76
+ pip install simgeometry
77
+ ```
78
+
79
+ For development, install this checkout with `pip install -e '.[test]'`.
80
+ NumPy, cunumpy, maybempi, and mpiarray are runtime dependencies.
81
+ Matplotlib is optional. Install `simgeometry[plot]` for plotting,
82
+ labelled evaluation and surface meshing, or `simgeometry[interactive]`
83
+ for interactive 3D clipping with PyVista. Install `simgeometry[mpi]` for
84
+ MPI, `simgeometry[pyccel]` for compiled CPU containment kernels, or
85
+ `simgeometry[gpu]` for CUDA.
86
+
87
+ ## Example
88
+
89
+ ``` python
90
+ from simgeometry.grid import Grid
91
+ from simgeometry.objects import Circle
92
+
93
+ boundary = Circle(midpoint=(0.5, 0.5), radius=0.25)
94
+ grid = Grid(ndim=2, lower_bound=(0, 0), upper_bound=(1, 1), num_gridpoints=(32, 32))
95
+ mask = boundary.node_mask(grid)
96
+ ```
97
+
98
+ `SimulationDomain` accepts field and particle boundary objects through
99
+ their `get_bc(dir=..., side=...).bc_type` interface. Applications may
100
+ supply a seeded random function with `BoundingBox.random` and an
101
+ accelerated particle boundary implementation with
102
+ `SimulationDomain.boundary_kernel`.
103
+
104
+ ## Inspect, slice, and compose
105
+
106
+ ``` python
107
+ from simgeometry import Sphere
108
+
109
+ shell = Sphere((0, 0, 0), 1) - Sphere((0, 0, 0), 0.4)
110
+ shell.show_3d(opacity=0.6)
111
+ shell.slice(z=0.2).show()
112
+ inside = shell.evaluate(x=[0, 0.8], y=0, z=0)
113
+ ```
114
+
115
+ Shapes support named collections, Boolean operations, affine transforms,
116
+ surface queries, point sampling, mesh export, cut-edge geometry and
117
+ approximate cell/face fractions. See the [executed
118
+ tutorials](https://max-models.github.io/simgeometry/tutorials/) and [API
119
+ guide](https://max-models.github.io/simgeometry/getting-started/geometry-api/)
120
+ for examples and the accuracy limits of sampled operations.
121
+
122
+ ## Development
123
+
124
+ ``` bash
125
+ pytest src/simgeometry/tests
126
+ ```
127
+
128
+ Documentation: <https://max-models.github.io/simgeometry/>
@@ -0,0 +1,62 @@
1
+ simgeometry/__init__.py,sha256=nf5mHb0bu5owT7LVv9sY85jzB8x0tw4q7sgFy0cHpAk,723
2
+ simgeometry/_bounds.py,sha256=_x4gTpmbbWpaxcpnS82aeSap53GXfSPIB8eBnGY36uo,583
3
+ simgeometry/_normalize.py,sha256=-l1arr_RSAyu8dOdX5EZDkHnNvKqo6SZ9EcXrm6nEN4,767
4
+ simgeometry/_particle_boundaries.py,sha256=C-hrznsJlCQUNWVOA2Q4yRyxnfbzK6sYH3eWGDGlUMo,1314
5
+ simgeometry/_types.py,sha256=Uq-RmwX9NzM5mZ7BV3kYbnb8hM7EJSBYvgYoWSo9tH8,615
6
+ simgeometry/api.py,sha256=TvtLw24WGN3X2xWMrG_NTx9rLAI30wMxf6vPTllDtuE,9802
7
+ simgeometry/boundingbox.py,sha256=LncuxkLbtYJLF-ZVmTGqfG672Qb5145Nsn0_n_fP8Co,7385
8
+ simgeometry/collection.py,sha256=hDYf2fI3K7oRN_cSK1ZbPfPe9C6Eq_xBJGBs6KV8aIM,2720
9
+ simgeometry/crossings.py,sha256=FgbhqrEkeMMmocpkhJVMWzUyYxHCrk2BT2VuLilUVKY,12712
10
+ simgeometry/cut_edges.py,sha256=NGSYjSKn9BRJozZeSF0LO88jrAXGIrdAKoJwaz1y9SQ,12408
11
+ simgeometry/cylindrical.py,sha256=V2zW4CiflW50-HPbczyfglcE_bwN1aZo7H6QgJD6_vo,1854
12
+ simgeometry/domain_decomposition.py,sha256=csorErbtmyYMcCgMQgFH3a2qtDCtrHgZ6ykabEK5SAY,18629
13
+ simgeometry/evaluation.py,sha256=A5auXqggAQHz1687HfpPF_9yetAIRZtHmtsy78RfgUg,3868
14
+ simgeometry/fractions.py,sha256=EniF091r68CXbeKsm_qNQmQpglAhJjzYmtslyfpK2ms,2744
15
+ simgeometry/grid.py,sha256=AXcOxZ0LAoHD3MskwHttVR8zedhefks3qH9TKPSgzo4,9237
16
+ simgeometry/mesh.py,sha256=Cab_Q2JiOlLSV3zX8Z8lEVszypnw5hd_5cRBVHrMdN8,5821
17
+ simgeometry/operations.py,sha256=QUgCpMZJhPzgKbPuvrQ5NqO-DG6srqEEsOVkmUJr3GY,15851
18
+ simgeometry/panels.py,sha256=OKJkzD4V8rviYy6piJgUtyJ0axR83205UCxMO2Kjrjo,2796
19
+ simgeometry/plotting.py,sha256=85i2RQWsbpL6y0kU-NZYZBlNHU6--zoLe0C-75IPgho,5695
20
+ simgeometry/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
+ simgeometry/queries.py,sha256=Lmlc2kQViEI0PsE9F2s3TG5gq-R4yeUu0ENHXdxq0ZE,17058
22
+ simgeometry/sampling.py,sha256=-n0RuV_nN7j5GxC4egjuIizQbNhMaeGde659dsF8O2k,2949
23
+ simgeometry/shapes.py,sha256=Ifypi308KLTM1fpNdhYgv1pdQk7lqVwxSOwEVhqC1nQ,13935
24
+ simgeometry/simulation_domain.py,sha256=jCS7e5OKhoW5BlIxGWuWdjGFh7LNE14WbQTOmlkv-S8,10257
25
+ simgeometry/utils.py,sha256=OVXzau-hACj_uyp-9hzowAzL48cEQ3jokkwIWeXXqWM,692
26
+ simgeometry/visualization.py,sha256=zxagBKYPTQyvJ9Z4nhHf6kwWGxzU7reIu9OG2O_b0zg,13726
27
+ simgeometry/kernels/__init__.py,sha256=Dy_0n8PJdLTrOMhVae0PvE4qEjuJmJM7BBH893Kb7Gg,58
28
+ simgeometry/kernels/_build.py,sha256=tu35VuhBI4MK3fr7qi19lCiLveakrhowh9EVVyTkNr8,1900
29
+ simgeometry/kernels/_metal.py,sha256=47BVhlisjL-7HZfTPD2-F-MSmna8wN451fJIDUtkyXM,1307
30
+ simgeometry/kernels/compile.py,sha256=urr_xmaw8tXOd6oud37bWZmq-UY0bQe5va55htV3mCQ,1117
31
+ simgeometry/kernels/contains_ball/__init__.py,sha256=L3k3zxbP1V5YGZQ7Sa_in4S_vauRnK5q3IRBpVcN7Y0,455
32
+ simgeometry/kernels/contains_ball/contains_ball_cuda.cu,sha256=1psPVSXIuCMXBGcC7G1tD8ODKyUUyUi0xCaavFdEqvg,998
33
+ simgeometry/kernels/contains_ball/contains_ball_metal.py,sha256=DgQJc___uACqX7XcUWYZ0FB3UPEyuPRHjP_AfImzEnc,1665
34
+ simgeometry/kernels/contains_ball/contains_ball_numpy.py,sha256=gcub-froE6hu2x2p_KaUmA9DmMhJZXEkAY7RYJiJKA4,639
35
+ simgeometry/kernels/contains_ball/contains_ball_pyccel.py,sha256=JRoAH2boH5SD-BPYYF8nqNeILtBabdV3IPoh42yJ3dk,1193
36
+ simgeometry/kernels/contains_box/__init__.py,sha256=Yq25a4PlIQRNGuvbSwEKJK6YfJ1nHCbBNGd_ov7bd1U,454
37
+ simgeometry/kernels/contains_box/contains_box_cuda.cu,sha256=vhwnWR9EU_IDsjR0GhH4ti_1Sp5_qBLlx9cwv_lDt50,939
38
+ simgeometry/kernels/contains_box/contains_box_metal.py,sha256=wbbuJjr92O4ADwkv6OLfZu8PNG4agRHp3CcbHwsj748,1559
39
+ simgeometry/kernels/contains_box/contains_box_numpy.py,sha256=kg6t71Z0xre6ebTz58QNLkuS3se_IycqsrE9ieW6-5E,658
40
+ simgeometry/kernels/contains_box/contains_box_pyccel.py,sha256=zyPOA0xLRobM1Gl1iknBMXmtZNsqS--o0Hm4LylpR-g,1159
41
+ simgeometry/kernels/contains_polygon_2d/__init__.py,sha256=MnZZAjlgicPDq254YcHysf8AmfFF4JSes4xf9xohMfM,461
42
+ simgeometry/kernels/contains_polygon_2d/contains_polygon_2d_cuda.cu,sha256=10g2bvtA5mPkTGZlPxkjDz_vbeKcQEN8b7N7-EY6cPk,1226
43
+ simgeometry/kernels/contains_polygon_2d/contains_polygon_2d_metal.py,sha256=mUDrogUdYC1S4g_VMy9BsmV9fAax1FTBhnALr65obFY,1858
44
+ simgeometry/kernels/contains_polygon_2d/contains_polygon_2d_numpy.py,sha256=YjAr8paCZyXQOrU5-14YvaSMJ1fHOJVkF6prDTu1_gg,822
45
+ simgeometry/kernels/contains_polygon_2d/contains_polygon_2d_pyccel.py,sha256=4v28t9i6NYr9dotco8m82Gylq8jOE6_xjY6GbwVnPto,1455
46
+ simgeometry/objects/__init__.py,sha256=hYrBck7eTU3A1eYyDSt81SnIaoKRIIw-RTZK5kOWCRY,936
47
+ simgeometry/objects/aperture2d.py,sha256=0Sp7g6ZbZ6uaGFPBd030CemiZDbAsrhmd6EmqZ3UZ4I,6289
48
+ simgeometry/objects/aperture3d.py,sha256=28RVcPaFn5WXXoGemOhTxWn4BBpMp3JZvwUkhvMtwA8,14561
49
+ simgeometry/objects/circle.py,sha256=JQm0C1_eRldXquWtvtESdNS9fJg9kb2S6ldF2tOrBLc,4828
50
+ simgeometry/objects/cuboid.py,sha256=rTj0IX-lHvUxDB-cXxbCZ4KDuZ-OjIDAFPZKHkUX32M,6308
51
+ simgeometry/objects/function_object.py,sha256=thxzDKqijuWzoOGtj592a_O4F8skqtfM8xElKH7f-mA,6824
52
+ simgeometry/objects/line.py,sha256=B7IryvfcHlci9J1zWlTloZK_dXoiTawGCEO9WI7raEo,4247
53
+ simgeometry/objects/polygon.py,sha256=YU-FVjscOmLBpvrHQIIZ0gQS0Obix-iCkX2XtTFee60,6162
54
+ simgeometry/objects/polyline.py,sha256=Cwb8nSVJoHZiGeNBxmraQykhY66OAWnMBxtcE3TtEGw,2596
55
+ simgeometry/objects/rectangle.py,sha256=ZfuV-kqDrc7HTmFlJ5ptbwjuietKY8djLQv8yAZ3MYA,4637
56
+ simgeometry/objects/sphere.py,sha256=VWEWWz6nWtQiyEZHEUnnFMfJwGsOIAoO9ZW6qgKsmU0,6431
57
+ simgeometry/objects/triangle.py,sha256=xjEWv8y6wP9OrnyqiNBaWkk0pe2EQXDAIm9EqZ8GVS4,5499
58
+ simgeometry-0.1.0.dist-info/licenses/LICENSE.txt,sha256=OUlDVbMHs0P7ZhgqM6Obmo2_ff1RSwNpzEJROYbma1w,1070
59
+ simgeometry-0.1.0.dist-info/METADATA,sha256=WUWvXCJBXMCsH-WqArWY3s7fUbiSbtCudeclijNfwX8,4531
60
+ simgeometry-0.1.0.dist-info/WHEEL,sha256=a-udL2m4V_6Yn8b-uKzWb12RjRxwwMo6ohYFM24tpaY,91
61
+ simgeometry-0.1.0.dist-info/top_level.txt,sha256=VdQfEVxy9w8_S19sGhQZOSsKNuj3zhNyycDVmq4YYhM,12
62
+ simgeometry-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Max Lindqvist
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ simgeometry