FOSSIL
FOrtran Surfaces, Solids, Immersed boundaries and Level sets
- Documentation: FOSSIL (tutorial, cookbook, feature map)
- GitHub: GitHub - szaghi/FOSSIL: FOSSIL, FOrtran Stereo (si) Litography parser · GitHub
FOSSIL is a pure Fortran library of geometry for simulation codes, with no C underneath. It started as a small STL parser (the old name was “FOrtran Stereo Litography parser”). The last releases (2.0 to 3.0, with the help of an AI assistant) turned it into what a CFD code needs from its geometry: surfaces read and repaired, signed distances and level sets, immersed-boundary queries, AMR tagging, exact cut cells, curvilinear and overset grids, and moving bodies. Everything runs on the CPU, and the hot paths run on the GPU with results bit-exact to the CPU.

A NACA 0012 pitching through a Cartesian grid. Top: its exact cut cells. Bottom: the level sets of its signed distance. The pose is passed to the query, so the tree is never rebuilt.
What is in it
- STL in, STL out. ASCII or binary; format detected. NaN or Inf coordinates are rejected with a status.
analyzegives the box, volume, centroid, connectivity, shells, and bodies. Named patches come fromsolid <name>blocks. - Repair and processing.
sanitizeremoves slivers and duplicates, closes gaps, and orients the normals outward.fill_holespatches and fairs the holes. Exact booleans and self-intersections, decimation, isotropic remeshing, smoothing, alpha wrapping, marching cubes. - Analysis. Mass properties, deviation and Hausdorff distance (with a certified upper bound), feature edges, local thickness and gaps, curvature.
- Signed distance and level sets. The closest facet is found on a SAH BVH, bit-exact against brute force. Four sign algorithms are available; the fast winding number works on surfaces with holes. A signed-distance field on a stretched grid has an exact narrow band, fast sweeping, and an eikonal diagnostic.
- 2-D curves. Closed and open polylines, with the same queries as surfaces. Any STL can be sectioned by a grid plane.
- Immersed boundaries and AMR. Per point, you get the closest point, the feature it lies on (face, edge, or vertex), the pseudo-normal and the body, plus image points, probes, and wall distance with a cutoff. Boxes and cells are classified as cut, near, inside, or outside from the tree alone, and signed tag bands are set on a block.
- Exact cut cells. Grid-line crossings are decided by exact predicates. You get 2-D and 3-D fluid fractions, apertures, and the fluid pieces of each cell with their own volumes.


New in 3.0
- Cut-cell solver support. Links between pieces, state- and flux-redistribution neighbourhoods, merge targets, moments up to order 4, quadrature rules, and coarse levels equal to the direct coarse cut cells.
- Curvilinear structured blocks. Topology detection (abutting, periodic, singular), exact cell volumes, certified cell validity, point location by tree or stencil walk, Lagrange interpolation stencils, and quality metrics.
- Overset assembly. Holes are cut by winding number, a Cartesian hole map, or X-rays. Donor candidates come with their quality. Classification is explicit or implicit, orphans are reported by cause, and there are fringe levels, wall projection for viscous walls, and a connectivity output.
- Body-fitted grids. Projection constrained to patches, feature curves, and corners. 2-D hyperbolic extrusion. A wall-spacing and quality report with y1+.
- Collision. Body-body distance with the closest pair. Time of first contact by conservative advancement, with no tunnelling. The first impact among many bodies.
- Exact swept geometry under rotation. Swept volumes and time-averaged apertures of a moving body over a time step, in 2-D and 3-D.

An O-grid moves through a background grid. Its holes, receptors, and orphans are recomputed every frame.

Points tracked through an O-grid by stencil walks, across its seam

An O-grid marched out of a NACA 0012 by hyperbolic extrusion.

The small cut-cell pieces of a moving ellipse and their merge targets, every frame.

Conservative advancement to the time of impact. The plain bound takes 25 steps; the directional bound takes 5.
Exact, not tolerant
FOSSIL decides geometry by exact predicates, not tolerances. orient2d and orient3d use exact expansion arithmetic. Booleans and self-intersections are built on implicit points (line-plane and three-plane intersections) and constrained triangulations, so they need no epsilon. Grid-line crossings use one global symbolic perturbation, which makes ties consistent across the x, y, and z axes.

A block drilled nine times. Each step is checked by an independent boolean: the volume residual stays at round-off and the result stays watertight.
A taste
use fossil, only : surface_stl_object, SIGN_FAST_WINDING_NUMBER
call surface%load_from_file(file_name='dragon-placed.stl', guess_format=.true.)
do k = 0, 4
p(k) = 0._R8P * ex_R8P + (-0.6_R8P + 0.3_R8P * k) * ey_R8P + 0._R8P * ez_R8P
d_pn = surface%distance(point=p(k), is_signed=.true., is_square_root=.true.)
d_wn = surface%distance(point=p(k), is_signed=.true., is_square_root=.true., sign_algorithm=SIGN_FAST_WINDING_NUMBER)
inside(k) = surface%is_point_inside(point=p(k), sign_algorithm=SIGN_FAST_WINDING_NUMBER)
print '(F7.3,2F15.6,L5)', p(k)%y, d_pn, d_wn, inside(k)
enddo
y d (pseudo-n.) d (winding n.) inside
-0.600 0.150398 0.150398 F
-0.300 -0.000289 -0.000289 T
0.000 -0.015419 -0.015419 T
0.300 -0.002330 -0.002330 T
0.600 0.114892 0.114892 F

On the GPU, bit for bit
The device path is OpenACC with nvfortran. Distances, rich IB queries, AMR box tagging, posed queries, deviation and block location share their kernels with the CPU path. Every device result is compared with the host result, and the gate is zero mismatches:
pseudo-normal : device vs host mismatches 0 of 13824
winding number: device vs host mismatches 0 of 13824
How it is checked
- 211 regression test programs run on every push. 34 validation programs (large meshes, sweeps, benchmarks) run nightly and before a release.
- The booleans are validated by identities that need no analytic answer: volume, second moments, area, deviation, and membership. Among the validation runs is a dense degenerate sweep of 360 cases from 1e-4 down to 1e-14.
- Every snippet, output, figure, and animation in the documentation comes from a program that is compiled and run. Nothing is typed by hand.
The documentation has a 16-chapter tutorial (the GPU is the last chapter), a cookbook, a reference page with design notes for each feature, and an Upgrading to 3.0 page. No public name was removed in 3.0, but some routines behave differently; that page lists each change.
FOSSIL builds with FoBiS or fpm and compiles with GNU gfortran, Intel ifx, and NVIDIA nvfortran (OpenACC on the device). It is multi-licensed (GPL v3, BSD 2-Clause, BSD 3-Clause, MIT): pick the one that fits you.
Feedback, issues, and contributions are welcome.
Stefano

