Overview
simgeometry is the geometry of the simulation codes, nothing physical: shapes with an inside
test, a signed distance and a normal; the first crossing of a particle’s step with them; the
cut-cell data of a grid; and the uniform grids and the MPI process grid that splits them.
Every array query takes component-major points of shape (ndim, n) and runs on NumPy or,
through cunumpy, on CuPy; the hot loops are compiled Pyccel kernels.
Each equation on these pages is declared on the code that implements it, as a method card, and checked by the tests: 20 closed forms (the level sets of the shapes, the Boolean and affine level sets, the analytic crossings, the segment-triangle test) against SymPy rules, five discretisations against their order of convergence. The pages of the section list the cards module by module; this one shows how they fit together.
Shapes
Section titled “Shapes”A shape is a set with a membership test (contains_points) and, where it has an analytic
description, a level set : negative inside, zero on the boundary, the exact Euclidean
signed distance where level_set_exact is true and a bound on it otherwise. An inverted shape is
the complement, with the sign of flipped
(shape conventions). The level sets are the standard exact
distances of boxes, segments, capped cones and tori:
- Line, Circle, Sphere;
- boxes with rounded edges: Rectangle, Cuboid;
- polygons by the even-odd rule: Polygon, Triangle, Aperture2D, and the profile of Aperture3D (no level set);
- solids of revolution, whose distance is that of their profile in the half-plane : Cylinder, Tube, Cone, Torus, and the SlantedTube, a bound near its cut;
- the Helix, a helical wire (an RF coil), its distance found by Newton steps along the centreline;
- surfaces given by data: the TriangleMesh (closed or open, e.g. a first wall from CAD) and the FourierSurface of a stellarator’s boundary or wall, with its normal offset; membership on their triangles (no level set);
- Booleans, affine transforms and sections, whose level sets are bounds, and collections of labelled objects.
Rectangle
classsourceRepresent a rectangular geometry object.
- inside
- level set
- Assumes
- axis-aligned, centre , half sides ; and of componentwise
- the fillet rounds the corners: the box shrunk by , widened by a disc of radius
- without a fillet the inside test is the half-open box of
BoundingBox.contains - is the exact signed distance, negative inside
- References
2D shapes also give their boundary as counter-clockwise loops (outlines, second order in the
spacing for curved boundaries) and as boundary panels for
boundary-element solvers.
Crossings
Section titled “Crossings”A particle pusher tests the whole step of every marker, not only its end, so a fast particle cannot pass through a thin plate. First crossings are analytic for balls, boxes, polygons, slanted tubes and their affine images, and exact for triangle meshes (segment-triangle test in the cells of a grid, compiled) and Fourier surfaces (their triangles, then Newton steps onto the surface); other shapes are sampled along the step and refined by Illinois steps on the level set, or bisected on membership without one.
crossings
functionsourceReturn the first boundary crossing of each segment start[:, i] -> end[:, i].
- ball
- slab
- first
- polygon
- transformed
- bisection
- illinois
- normal
- Order
- 1
- Assumes
- each step , ; the first crossing , entering or leaving; crossings at are ignored, at counted; grazing contacts and zero steps are not crossings
- analytic (
exact): balls, boxes and rounded boxes (the hull of the intervals of the inner box widened along one axis and the discs, edge cylinders and corner balls of radius ), polygonal 2D shapes (, ), slanted tubes and affine images of them, triangle meshes (Möller–Trumbore in the cells of a grid) and Fourier surfaces whose hits were refined onto the surface - sampled otherwise: membership at points (
samples), then Illinois steps on the level set to if it changes sign, else bisections on membership (iterations) - normals point out of the region where
containsis true: radial for balls, for boxes, for counter-clockwise edges; the level-set gradient ( times the extent) or 64 (2D) or 128 (3D) membership probes for sampled shapes; flipped for inverted shapes - a
GeometryCollection: each object on its own path, the earliest crossing wins, the first listed on a tie - the order is that of the bisection on membership in the final bracket width ; the analytic paths are exact and Illinois converges superlinearly (about 1.44)
- References
The compiled swept absorption of 2D markers runs the same segment-edge test against packed polygon objects in one pass and returns the object each marker hit first.
Cut cells
Section titled “Cut cells”Edge crossings locate where the edges of a grid enter a shape (Illinois on the level set, bisection otherwise); cut edges collect them per grid edge for embedded-boundary finite differences. Cut-cell fractions give the inside part of every cell by midpoint quadrature, and of every edge and face of a Yee grid, with the trace of the surface, for conformal field solvers.
Grids and decomposition
Section titled “Grids and decomposition”A grid has uniform nodes per axis, the first and last on the bounds (one spacing short of the upper bound on a periodic axis). The domain decomposition splits it over a process grid with row-major ranks: one near-even split of the nodes, shared by the field arrays (mpiarray) and the markers, whose owner follows from the subdomain edges. The particle boundaries of the box kill, reflect, wrap or reinject markers per axis.
Conventions
Section titled “Conventions”Lengths are in the units of the caller. Shapes and grids are axis-aligned unless an axis or a
matrix is given. Normals have unit length and point out of the region where contains is
true, so they flip for inverted shapes. Fractions along a step lie in : a crossing at
the very start () is not reported, one exactly at the end is. Boundary
conventions of the inside tests differ: Cuboid, Line and the balls are closed; Rectangle,
Polygon, Triangle and Aperture3D use the half-open bounding box .
Not covered
Section titled “Not covered”- No winding-number test: self-intersecting polygons follow the even-odd rule.
- The absorption kernel reports the object only, not the hit point, edge or normal, and tests the end points of long (wrapped) steps only.
- Sampled crossings miss features thinner than a step over
samples; Boolean, section and collection level sets are bounds, sosigned_distancefalls back to a sampled mesh for them. Aperture3Dand function objects have no level set and no analytic crossing; a section of a 3D shape only bounds the in-plane distance.- Halo exchange, ghost cells and field layouts are mpiarray’s; simgeometry hands over the process grid and the halo width.
- The process-grid search does not balance the axes and never fails.
- The cut-cell fractions have no single order: the Yee fractions are exact for planes and second order or better for curved surfaces, the midpoint fractions are multiples of .
Verification
Section titled “Verification”Besides the checks of the cards, the tests compare every vectorised inside test with the scalar one, the compiled kernels (Pyccel, NumPy, CUDA in emulation) with each other and with the shapes, the level sets with exact distances and the Boolean bounds, the analytic crossings with dense sampling, the Illinois roots with bisection (fewer than 10 level-set evaluations per edge against 50 membership tests), the Yee fractions with planes (exact) and with a circle and a sphere (area, perimeter and volume), and the decomposition with brute-force owners and with runs on 4 and 6 MPI ranks.