Skip to content

Moving bodies ​

What it does ​

A rigidly moving body needs its geometry at every new pose. Rebuilding the tree every time step is the cost to avoid. FOSSIL offers two mechanisms, and the kind of query decides which one to use:

MechanismUse it forCostAgreement with a mesh moved and rebuilt
Body-frame queries: pass pose=distance, IB queries, inside tests (CPU and device)one 3 × 3 product per pointdistances ≤ 1e-16 (L + |t|), signs equal away from the surface
Moved copy: move(pose) with a tree refitgrid-aligned queries: box tagging, line crossings, cut cellsO(N) (a refit, not a rebuild)bit for bit (feet at edge and vertex ties to 4 ulps)

state_changes flags the points (cell centres) that change state between two poses: fresh (solid → fluid; newborn in Bayyuk et al. 1993, emerging in Schneiders et al. 2013) and dead (fluid → solid; vanishing, submerging).

a NACA 0012 section seen from above at the start of a step (dark brown) and at its end (yellow), pitched 3 degrees nose up and moved 0.02 forward and 0.01 up, inside the outline of a grid of cell centres of spacing 0.02: only the 292 centres near the wall that the band filter sends to a second query are drawn, grey; among them 59 fresh centres (teal) along the lower aft surface the section leaves and 54 dead centres (ember) along the upper surface it covers

f90
p0 = pose_2d(angle=0._R8P)
p1 = pose_2d(angle=3._R8P * PI / 180._R8P, translation=[-0.02_R8P, 0.01_R8P])
call foil%state_changes(pose0=p0, pose1=p1, points=p, fresh=fresh, dead=dead, checked=checked)
$ fig_ref_moving_bodies_states
centres 1452, second query 292 (band drawn: 292), fresh 59, dead 54

Of the 1452 centres, 1160 are decided by one query: their distance at the old pose exceeds how far they move in the body frame. The other 292 are queried again.

swept_cells_2d / swept_cells_3d give the swept geometry a conservative moving cut-cell update needs over a step (see Swept geometry).

Example ​

The posed queries, state_changes and the 2-D swept area of a dragon section are in tutorial chapter 11, and a posed query of a rotated cube in the cookbook. This program checks the pose algebra, compares the three ways to query a moved body, and runs the swept geometry of one step of the unit cube on each of its paths.

f90
!< Reference page "Moving bodies": pose algebra and the screw motion, body-frame queries against a moved copy and a
!< mesh moved and rebuilt, and the swept geometry of one step of the unit cube: exact translation, the Gauss path as
!< a negative control, and an exact rotation.
program ref_moving_bodies
use fossil, only : surface_stl_object, rigid_pose_t, pose_identity, pose_from_axis_angle, pose_compose, pose_inverse, &
                   pose_interpolate, to_world, to_body, swept_cells_3d_t, swept_cells_3d
use penf,   only : I4P, R8P
use vecfor, only : vector_R8P
implicit none
real(R8P), parameter     :: PI = acos(-1._R8P)
type(rigid_pose_t)       :: p0, p1, q, half
type(surface_stl_object) :: cube, moved, rebuilt
type(swept_cells_3d_t)   :: sw
type(vector_R8P)         :: points(27)
real(R8P)                :: d_posed(27), d_moved(27), d_rebuilt(27), x(7), b(3)
integer(I4P)             :: i, j, k, l

p0 = pose_identity()
p1 = pose_from_axis_angle(axis=[1._R8P, 1._R8P, 1._R8P], angle=PI / 6._R8P, translation=[0.1_R8P, -0.05_R8P, 0.02_R8P])
q = pose_compose(pose_inverse(p1), p1)                                          ! p1^-1 o p1 = identity
print '(A,ES9.2)', 'p1^-1 o p1 - identity: ', max(maxval(abs(q%r - p0%r)), maxval(abs(q%t)))
b = to_body(p1, to_world(p1, [0.3_R8P, 0.2_R8P, 0.1_R8P]))
print '(A,ES9.2)', 'to_body(to_world(x)) - x: ', maxval(abs(b - [0.3_R8P, 0.2_R8P, 0.1_R8P]))
half = pose_interpolate(p0, p1, 0.5_R8P)                                       ! the screw motion at mid-step
print '(A,ES9.2,A,ES9.2)', 'R(1/2)^2 - R1: ', maxval(abs(matmul(half%r, half%r) - p1%r)), &  ! angle linear in s
                           ', t(1/2) - t1/2: ', maxval(abs(half%t - 0.5_R8P * p1%t))           ! translation linear in s
q = pose_interpolate(p0, p1, 1._R8P)
print '(A,L1)', 'interpolate(p0, p1, 1) = p1 bit for bit: ', all(q%r == p1%r) .and. all(q%t == p1%t)
call cube%load_from_file(file_name='cube-01.stl', guess_format=.true.)
i = 0
do k = 0, 2 ; do j = 0, 2 ; do l = 0, 2                                     ! 27 world points across the moved cube
   i = i + 1
   points(i) = vector_R8P(-0.1_R8P + 0.6_R8P * l, -0.1_R8P + 0.6_R8P * j, -0.1_R8P + 0.6_R8P * k)
enddo ; enddo ; enddo
call cube%distance_many(points=points, distances=d_posed, is_signed=.true., is_square_root=.true., pose=p1)
moved = cube
call moved%move(p1)                                                              ! refit, not rebuilt
call moved%distance_many(points=points, distances=d_moved, is_signed=.true., is_square_root=.true.)
rebuilt = moved
call rebuilt%analyze                                                             ! the tree rebuilt from scratch
call rebuilt%distance_many(points=points, distances=d_rebuilt, is_signed=.true., is_square_root=.true.)
print '(A,ES9.2,A,I0)', 'posed - moved: ', maxval(abs(d_posed - d_moved)), ', inside ', count(d_posed < 0._R8P)
print '(A,L1)', 'moved = rebuilt, bit for bit: ', all(d_moved == d_rebuilt)
x = [(-0.22_R8P + 0.25_R8P * i, i = 0, 6)]                                     ! 6^3 cells of side 1/4
call swept_cells_3d(cube, p0, pose_from_axis_angle(axis=[0._R8P, 0._R8P, 1._R8P], angle=0._R8P, &
                    translation=[0.1_R8P, 0.05_R8P, 0._R8P]), x, x, x, sw)
print '(A,L1,A,I0,A,ES9.2,A,ES9.2)', 'translation: exact ', sw%exact, ', evaluations ', sw%evaluations, &
                                     ', residual ', maxval(abs(sw%residual)), ', sum of swept ', sum(sw%swept)
call swept_cells_3d(cube, p0, pose_from_axis_angle(axis=[0._R8P, 0._R8P, 1._R8P], angle=0._R8P, &
                    translation=[0.1_R8P, 0.05_R8P, 0._R8P]), x, x, x, sw, exact=.false.)
print '(A,L1,A,I0,A,ES9.2,A,ES9.2)', '  Gauss:     exact ', sw%exact, ', nodes ', sw%evaluations, &
                                     ', residual ', maxval(abs(sw%residual)), ', estimate ', sw%error_estimate
call swept_cells_3d(cube, p0, pose_from_axis_angle(axis=[0._R8P, 0._R8P, 1._R8P], angle=0.2_R8P, &
                    translation=[0.1_R8P, 0.05_R8P, 0._R8P]), x, x, x, sw)
print '(A,L1,A,I0,A,ES9.2)', 'rotation:    exact ', sw%exact, ', evaluations ', sw%evaluations, &
                             ', residual ', maxval(abs(sw%residual))
print '(A,I0,A,I0,A,ES10.3)', '  cleared ', count(sw%cleared), ', covered ', count(sw%covered), &
                              ', wall sum ', maxval(abs(sum(sum(sum(sw%wall, 4), 3), 2)))
endprogram ref_moving_bodies
$ ref_moving_bodies
p1^-1 o p1 - identity:  1.11E-16
to_body(to_world(x)) - x:  5.55E-17
R(1/2)^2 - R1:  1.11E-16, t(1/2) - t1/2:  0.00E+00
interpolate(p0, p1, 1) = p1 bit for bit: T
posed - moved:  1.11E-16, inside 4
moved = rebuilt, bit for bit: T
translation: exact T, evaluations 14, residual  2.52E-17, sum of swept -5.90E-17
  Gauss:     exact F, nodes 4, residual  1.10E-03, estimate  1.13E-02
rotation:    exact T, evaluations 508, residual  4.34E-17
  cleared 12, covered 9, wall sum  8.327E-17
  • Pose algebra. pose_compose(pose_inverse(p1), p1) is the identity to 1.11·10⁻¹⁶, and to_body undoes to_world to 5.55·10⁻¹⁷.
  • Screw motion. At s = 1/2 the rotation, squared, is R₁ to 1.11·10⁻¹⁶, and the translation is exactly t₁/2: the angle and the translation are linear in s. The motion is not a power of a pose, so pose_compose(half, half) is not p1 when the translation has a component off the axis. At s = 1 pose_interpolate returns p1 bit for bit.
  • Three ways to query. The posed query (pose=, tree as built) and the moved copy (move, tree refitted) agree to 1.11·10⁻¹⁶ on 27 points, 4 of them inside. The refitted copy and the same copy re-analyzed from scratch (analyze, tree rebuilt) agree bit for bit.
  • Translation. The cube faces cross the grid planes x = 0.03, 1.03 and y = 0.03, 1.03 during the step, and the fluid areas of those planes jump at the crossings. The exact path places its breakpoints there: 14 evaluations on the busiest plane, residual 2.52·10⁻¹⁷. The swept volumes add up to -5.90·10⁻¹⁷: a rigid motion keeps the volume.
  • Gauss, the negative control. exact=.false. integrates the same step with 4 Gauss nodes across the jumps: residual 1.10·10⁻³; error_estimate, the largest face change from 4 to 8 nodes, is 1.13·10⁻².
  • Rotation. The same shift with a 0.2 rad turn about z takes the exact rotation path: 508 evaluations on the busiest plane, residual 4.34·10⁻¹⁷. 12 cells are cleared (no fluid at the start, fluid at the end) and 9 covered. Summed over the block, which holds the body at both poses, the projected walls cancel to 8.327·10⁻¹⁷.

The 2-D swept geometry over several steps: a square of side 0.5 rolls along a grid of spacing 0.1, turning 0.15 rad and advancing 0.14 per step while it bobs up and down, one swept_cells_2d call per step between consecutive poses.

f90
p0 = pose(k) ; p1 = pose(k + 1)
call swept_cells_2d(square, p0, p1, x, y, sw, status=status)
if (status /= STATUS_OK .or. .not. sw%exact) error stop 'swept_cells_2d: no exact result'
worst = max(worst, maxval(abs(sw%residual)))

a square of side 0.5 rolling to the right over a 24 by 12 grid of spacing 0.1 in 10 steps, each frame one step: the cells shaded by their swept area over the cell area, ember behind the square where fluid is gained, teal ahead of it where fluid is lost, the square at the start of the step in dark brown and at its end in yellow; every step takes the exact rotation path, with a largest residual of 1.04e-16

$ anim_ref_moving_bodies_swept
step 1: sum of swept  4.65E-17, max residual  3.73E-17, cleared 10, covered 10
step 2: sum of swept -2.42E-17, max residual  3.73E-17, cleared 7, covered 6
step 3: sum of swept  6.60E-18, max residual  4.04E-17, cleared 6, covered 6
step 4: sum of swept -5.16E-17, max residual  3.51E-17, cleared 7, covered 5
step 5: sum of swept  8.57E-17, max residual  6.06E-17, cleared 6, covered 7
step 6: sum of swept  9.80E-17, max residual  3.79E-17, cleared 7, covered 6
step 7: sum of swept -3.56E-16, max residual  4.68E-17, cleared 6, covered 6
step 8: sum of swept  2.11E-16, max residual  7.03E-17, cleared 6, covered 6
step 9: sum of swept  1.08E-16, max residual  5.91E-17, cleared 5, covered 7
step 10: sum of swept -1.20E-16, max residual  1.06E-16, cleared 8, covered 9
largest residual over the 10 steps  1.06E-16

Every step takes the exact rotation path (sw%exact); the swept areas of a step add up to at most 3.56·10⁻¹⁶ and the largest uniform-flow residual over the 10 steps is 1.04·10⁻¹⁶.

Poses ​

  • rigid_pose_t holds r(3, 3) and t(3), with x_world = R x_body + t.
    • Constructors: pose_identity, pose_from_axis_angle(axis, angle, translation), pose_from_quaternion(q, translation).
    • Algebra: pose_compose(a, b) (apply b, then a) and pose_inverse.
    • Maps: to_body, to_world, rotate, which are device-callable.
  • rigid_pose_2d_t (pose_2d(angle, translation)) is the in-plane pose of a curve.
  • pose_interpolate(p0, p1, s) (2-D and 3-D) is the screw motion between two poses: the translation and the rotation angle, about the fixed axis of R₁R₀ᵀ, are linear in s ∈ [0, 1]. The end poses are returned exactly.

The pose argument is on:

  • distance_many, query_many, is_point_inside and their device twins distance_many_device, query_many_device;
  • for surfaces and curves alike.

Closest points, second foot points and normals come back in the world frame.

the unit cube drawn by its edges at six poses of the screw motion from the identity to a turn of 120 degrees about z with translation (1.8, 0.6, 1.2), at s = 0, 1/5, ..., 1, grey up to the yellow end pose; the body-frame origin moves on a straight teal line, one corner on an ember arc; a teal cube drawn at pose_compose(half, half), with the end rotation but displaced from the end cube by 0.949

$ fig_ref_moving_bodies_screw
compose(half, half): rotation off p1 by  1.11E-16, translation off p1 by  0.9487
pose_interpolate at s = 1 is p1 bit for bit: T

The body-frame origin moves on the straight line s t₁ while the body turns about it at a constant rate. Composing the half-way pose with itself gives the end rotation to 1.11·10⁻¹⁶ but misses the end position by 0.949: applying the half pose twice turns the first half-step's translation too, which the screw motion does not.

How it works ​

  • Body-frame queries. The points are mapped by x̃ = Rᵀ (x − t); the results are mapped back. Distances are invariant. The device twins map on the host with the CPU code, so the posed device results equal the posed CPU results bit for bit.

    the unit cube at rest drawn by its edges and, translucent, at a pose turned 35 degrees about z and lifted by 0.25; a ring of 40 world points around the posed cube, each joined by a yellow segment to its closest point on the posed cube, teal where the point is outside, ember where a corner of the cube reaches past the ring

    The tree of the figure is the one built at rest; query_many(pose=) returns the closest points on the posed cube, in the world frame. 28 points are outside, 12 inside, with signed distances from -0.0684 to 0.0999.

  • Move and refit.

    • The vertices move, and everything derived from coordinates is recomputed exactly as analyze does.
    • The SAH BVH keeps its topology: node boxes are recomputed bottom-up as unions of facet boxes, and the payloads are rebuilt. Curves refit their segment tree the same way.
    • Topology, shells and bodies are kept. An octree is rebuilt.
    • The facets equal those of the mesh moved and analyzed from scratch, so the queries agree with a rebuild.
    • Exception: a foot on an edge or vertex shared by tied facets is parametrized differently by each; which facet is reported depends on the tree, so its bits can differ by a few ulps.
  • Fresh and dead points.

    • A point at the two body-frame positions b₀ and b₁ can change state only if the segment b₀b₁ reaches the surface.
    • So when |φ(b₀)| > |b₀ − b₁| the second query is skipped. That filter is exact.
    • States come from the signed distance with the chosen sign algorithm.

Swept geometry ​

A conservative cut-cell update over a step with a moving wall needs, per cell, the old and new fluid volumes. Per grid face it needs the fluid aperture averaged over the step (Falcovitz et al. 1997; Murman et al. 2003, §4). These apertures are those of the unsplit motion: Falcovitz et al. split it by direction, and Bennett et al. (2018, §2) find that directional swept volumes do not add up to the unsplit one, so a solver that splits by direction cannot use them as they are. Three decisions follow from the fixed grid (issue #41):

  • Nothing sweeps through a fixed face.
    • The volume the wall sweeps through a cell is its fluid volume change, by Reynolds transport.
    • So swept = (α₁ − α₀)·|cell| comes exactly from the cut cells at the two poses, in 2-D and 3-D.
    • The geometric conservation law holds by construction for the geometry: volume change = swept volume (Murman et al. 2003, §4). A scheme's GCL also depends on how its time integrator uses them (Schneiders et al. 2016, §3.6).
    • Natarajan et al. (2022) divide by the old volume fraction with no swept term (§2.1) and lose up to 0.92 % of the mass at 32³, 0.31 % at 64³ (§3.6); the paper does not isolate the cause. They attribute their first order on a receding piston to the fresh-cell fill (§3.2.2), untested: their flux redistribution is itself first order at cut cells (Berger & Giuliani 2021, §1), a disagreement the llm-wiki records as open.
  • The only time integral is the face aperture.
    • face_u / face_v (2-D) and face_x / face_y / face_z (3-D) are the fluid length or area of every grid face, averaged over the step.
    • wall = −Σ_f Ā_f n_f is the time-averaged projected wall area of the cell, which carries the wall pressure and work. It uses the same quantities as the face fluxes.
  • Motion. By default the motion is pose_interpolate. A caller that knows the true motion, such as a 6-DOF integrator, can instead pass the poses at the Gauss nodes (gauss_legendre_01).

a 12 x 12 grid seen from above, the middle layer of a 12 x 12 x 3 block, each cell shaded by the volume the unit cube sweeps through it over one step of a screw motion (0.35 rad about a tilted axis plus a shift), divided by the cell volume: ember where the cell gains fluid on the trailing side, teal where it loses fluid on the leading side, cream elsewhere; the section of the cube at mid-layer at the start in dark brown and at the end in yellow

In the figure the step takes the exact rotation path, with the cube's faces x, y = ±0.5 starting on grid planes (issue #84): the residual is at most 9.69·10⁻¹⁷ in every cell, and the swept volumes add up to -3.14·10⁻¹⁷.

fortran
call swept_cells_2d(curve, pose0, pose1, x, y, sw, nq, poses, exact, status, check_input)
call swept_cells_3d(surface, pose0, pose1, x, y, z, sw, nq, poses, exact, status, check_input)

Integration.

  • 2-D pure translation: exact. Both poses share their rotation.
    • Each face is an axis-aligned segment moving against the curve, so its fluid length is piecewise linear in time.
    • The breakpoints are the instants when a wall vertex crosses the face's line, or when an end node of the face crosses a wall segment.
    • Two-point Gauss on every piece is exact.
  • 3-D pure translation: exact. The same idea, one grid plane at a time.
    • In the frame of the body, a grid plane moves by −s d with its grid lines. Every vertex of a face's fluid polygon moves linearly in time while the combinatorics hold, so the area is quadratic in time.
    • The breakpoints of a plane are the instants when a mesh vertex crosses it, a mesh edge crosses one of its grid lines, or one of its grid nodes crosses a triangle.
    • Two-point Gauss on every piece is exact. One evaluation (a section of the shifted plane and the 2-D cut cells on the shifted grid) gives every face of the plane.
  • exact=.false. forces the Gauss path for a translation (both dimensions); sw%exact reports which path ran and sw%evaluations how many aperture evaluations it took (per face in 2-D, per plane in 3-D).
  • 2-D rotation: exact (issue #69, see Exact rotation below). The screw motion with a rotation takes certified breakpoints and Gauss–Legendre doubled to round-off on every piece; the residual falls to round-off (1.7e-16 to 6.3e-16 on the cases below, where 4-node Gauss left 1.7e-4 to 1.4e-2). Since issue #104 it integrates cell by cell on each cell's own wall (2-D, cell by cell below), 36–286 times faster than the per-face integration it replaced and cheaper than the Gauss call up to 2 cells per step; sw%evaluations is then the largest number of quadrature nodes of one cell.
  • 3-D rotation: exact (issue #69). The same scheme one grid plane at a time: a plane's breakpoints are a mesh vertex on it, a mesh edge meeting one of its grid lines, one of its grid nodes on a triangle; one evaluation slices a moved copy and gives every face of the plane. Residual 1.4e-16 to 1.8e-15 on the cases below, where 4-node Gauss left 1.0e-3 to 9.3e-3.
  • Otherwise (explicit node poses, or exact=.false.): Gauss–Legendre at nq nodes (default 4), on copies moved to the node poses. With the screw motion, error_estimate is the larger of the face change between nq and 2 nq nodes and the largest |residual| divided by the largest rigid-field speed on the grid (issue #104): a face's Gauss error enters its cells' balance times that speed, so the estimate is in face units and never below what the residual shows. refine=.true. (screw motion only) integrates the faces of every cell with an event inside the step per event interval on the cell's own wall elements, the piece map's machinery: the residual drops to round-off, and the faces of the other cells keep their Gauss values (no kink there).

Exact rotation (design, issue #69). The Gauss path converges algebraically under rotation (rate 2–3, see the validation table), because a face's fluid measure has kinks inside the step. The exact path removes them, as the translation path does, and is built as follows.

  • Motion. The screw motion of pose_interpolate has the angle linear in s ∈ [0, 1] about a fixed axis (the plane normal in 2-D) and the translation linear in s: a body point q is at X(s) = R_k(sΔθ) R₀ q + t₀ + s Δt. It is not a rotation about a fixed pivot, so the events below are transcendental in general.

  • Events. A face's fluid measure is smooth between the instants when

    • a wall vertex crosses the face's line (2-D) or plane (3-D);
    • an end node of the face crosses a wall segment (2-D), or a grid node of the plane crosses a triangle (3-D);
    • a mesh edge crosses one of the plane's grid lines (3-D).

    Each is a zero of an orientation of moving and fixed points, and with X(s) as above every one has the form

    g(s) = (p₀ + p₁ s) cos φ + (q₀ + q₁ s) sin φ + k₀ + k₁ s, φ = φ₀ + s Δθ,

    with coefficients from the input points (the rotation acts on differences of body points, the translation enters linearly), plus a check that the event lies on the face (the vertex inside the span, the node's foot inside the segment or triangle).

  • Certified isolation. |g''(s)| ≤ M = Δθ² max|(p, q)| + 2|Δθ| |(p₁, q₁)|, the maximum over [0, 1]. On an interval of length h whose end values have the same sign and exceed M h²/8 in magnitude, g has no zero (g lies above its chord minus M h²/8). Otherwise the interval is halved; a sign change is refined by bisection to one ulp of s. No pair of zeros is missed. An interval narrower than 1e-10 without a certificate (a tangency, a zero at an end of the step) gives one breakpoint; an interval on which |g| stays at round-off throughout (a zero zone: a mesh face starting on a grid plane) gets breakpoints at its two ends only; breakpoints within 1e-10 of each other merge. A kink that close to a breakpoint changes its piece's Gauss value by ~slope × 1e-20. If the 4096-interval budget of one event runs out, sw%exact is false.

  • Integration. On each piece between breakpoints the fluid measure is analytic, so Gauss–Legendre converges exponentially. The node count on a piece doubles from 2 until two successive values agree to round-off of the face measure (pieces shorter than 1e-6 to 64 ε of the measure times 1e-6: slices within 1e-10 of a mesh face carry ~1e-7 relative noise); sw%evaluations reports the largest count (per face in 2-D, per plane in 3-D). At 64 nodes the target becomes the round-off of one evaluation: 64 ε of the coordinate magnitude (2-D) or of that times the face side (3-D), no longer times the piece length (issues #84, #86). Near an instant when a wall side lies along a face's line, or a body face on a grid plane (a side or face starting there, a corner leaving a line tangentially), the crossings of a moved copy carry round-off amplified by 1/angle, and successive Gauss values stop agreeing at a floor that does not shrink with the piece. A piece that misses this target too marks the result sw%exact = .false., never silently. The flag still catches missing breakpoints: with every breakpoint dropped, the dragon sections and the cube of issue #84 all come out not exact (residuals 1e-6 to 2e-4). Each evaluation moves a copy of the body to the node's pose and measures the face exactly as the cut cells do, so apertures and fractions share one convention.

  • What changes. The swept volumes are exact already (cut-cell volumes at the two poses), and wall closes the uniform flow by construction, so a conservative update is consistent either way (Falcovitz's requirement). The exact path makes the time-averaged apertures exact under rotation too, and with them the rigid-field residual, which falls to round-off. Explicit node poses (poses=) keep the Gauss path; exact=.false. forces it.

  • 2-D, cell by cell (issue #104). Each Gauss node above places the whole curve, so a face cost O(curve) per node, and every face inside the box swept by the bounding circle was integrated, fully fluid ones included. The 2-D path now runs the piece map's machinery on every candidate cell (every cell the wall can meet during the step, from the paths of the segments' endpoints): the cell's events on its own local wall, then its faces per event interval by the same doubling to round-off, an event-free cell on the one interval [0, 1]. A face between two such cells takes the low cell's value. A face of no candidate cell is fluid or solid throughout the step (both its cells fluid, or both solid, at both poses): its value is closed form. Everything else (a cell the map marks untrusted or that fails its end check, an anomaly) falls back to the per-face integration above, which also takes every face of an open curve; sw%fallback_faces counts them. Against the per-face path (swept_cells_2d_reference, kept for tests) the faces agree within 1.5·10⁻¹⁶ and the residuals to round-off, on the ellipse and the NACA 0012 at 256² and 1024², from 0.5 to 2 cells per step and at 20 degrees; it is 36–286 times faster up to 2 cells per step (0.07–0.65 of a Gauss call) and 7.5–9 times at 20 degrees (fossil_val_rotation_2d_local).

Check. residual is the volume balance of the body's rigid velocity field: swept volume plus the time integral of the field's outflow through the fluid part of every face. It vanishes when a uniform flow moving with the body is reproduced exactly, Falcovitz's design requirement. It is not computed (0) when the caller passes the node poses. The residual also checks the input: the exact paths assume a wall that does not cross itself (see the limitation below).

cleared and covered flag the cells with no fluid at one pose and fluid at the other.

On the device ​

swept_cells_3d_device(surface, pose0, pose1, x, y, z, sw, ...) and swept_cells_2d_device(curve, pose0, pose1, x, y, sw, ...) (issue #100) take the arguments of swept_cells_3d / swept_cells_2d and return the same sw, bit for bit, on every path: exact translation, exact rotation, Gauss and explicit poses.

In 3-D:

  • The end poses go through cut_cells_3d_device(..., alpha_only=.true.).
  • The faces are batched: the host builds each (plane, Gauss node) as swept_cells_3d does, with the breakpoints, the events and isolate_zeros on the host (they are at most 1 % of a call). It slices every node through a plane sweep, and one multi-block launch per chunk cuts all the sections on their own grids.
  • Each face then adds over its nodes in node order on one device thread: the same additions in the same order.
  • The optional chunk_cells caps the device memory of a launch set without changing a bit.

In 2-D only the end poses move to the device on the translation and Gauss paths. The faces, measured at 94–99.9 % of a call, stay on the host, so the twin gains nothing measurable there. The exact rotation (issue #104) integrates every cell the wall can meet on the piece map's machinery, whose per-item passes (evaluations, tracks, measure rounds) run on the device as with map=; the end-pose cuts, the plan, the closed-form faces and the fallback faces stay on the host. The ellipse turning 2 degrees (3.6 cells per step at its tip on 256², 14 on 1024²) runs 1.5× and 1.9× faster than the host call (RTX 4070, shared machine, best of 3).

Measured on an RTX 4070, best of 5 after a warm-up:

bodycellspathCPU [s]device [s]
sphere (marching cubes)32³translation10.46.1
sphere32³rotation15.08.3
sphere64³translation56.819.8
sphere64³Gauss, nq = 42.370.59
cone32³rotation3.951.38
cone64³translation17.53.8
cone64³Gauss, nq = 41.670.38

That is 1.7–4.7×. The exact paths are dominated by the number of (plane, node) sections: 650–15 400 per plane at 64³, and the exact rotation costs 250–600 s per host call there. The Gauss path is two to three orders of magnitude cheaper than the exact rotation at 64³.

In a whole time step (move, tag, cut + links, swept) the swept geometry stays the largest device stage: 37–85 % of the step at 64³–128³. The step gains 5.4–9.3× there; the table is in GPU queries.

Piece map ​

A cut cell can hold several fluid pieces, and over a step the wall can move through it. A solver must then know which fluid at the end of the step came from which fluid at its start (issue #102). swept_cells_2d(..., map=) answers with the tracks of every cell, and swept_cells_3d(..., map=) does the same in 3-D.

In the literature. Bayyuk et al. (1993) merge cells so that no combined cell changes its intersection topology within a step, which needs the body wider than the cut cells and the step shorter than the smallest uncut cell. Meinke et al. (2013, §3.2) handle cells cut several times or split into unconnected parts. Murman et al. (2003, §4) and Badia et al. (2023, §2) treat a cut cell as a space-time cell. None of the sources in the llm-wiki bundle immersed-boundary-methods is recorded as linking a cell's pieces through a step.

Definition. Take the cell's fluid over the whole step, as a region of space and time: {(p, s) : p in the cell, p in the fluid at pose s, s in [0, 1]}. Its connected components are the tracks.

  • Pieces: every piece of the cut cells at pose0, and every piece at pose1, lies in exactly one track.
  • Fresh and dead: a track with no old piece is fresh; one with no new piece is dead.
  • Splits and merges: several pieces on one side make a split or a merge.
  • Transient: a track with no piece at either end is fluid that crosses the cell within the step.
f90
p0 = pose(k) ; p1 = pose(k + 1)
call swept_cells_2d(plate, p0, p1, x, y, sw, map=map, status=status)
if (status /= STATUS_OK) error stop 'swept_cells_2d: map refused'
write(caption, '(A,I0,A,I0,A,I0,A,I0,A,ES8.1)') 'step ', k + 1, ': ', map%nt, ' tracks, ', &
      map%multi_track_cells, ' cells with several, ', map%untrusted_cells, ' untrusted, max residual ', &
      maxval(abs(map%residual))

a thin plate 0.9 by 0.03, tilted 60 degrees, moving right by 0.16 per step and turning 0.04 rad over a 24 by 12 grid of spacing 0.1, each frame one step: the cells with several tracks in yellow (18 to 21 per step), along the band the plate swept between its start (grey) and its end (red); there the fluid ahead of the plate was pushed out of the cell, a dead track, while the fluid behind it grew, a continuing one; cells the wall touches with one continuing track in grey

$ anim_ref_moving_bodies_tracks
step 1: 306 tracks, 18 cells with several, 0 untrusted, max residual  2.2E-17
step 2: 307 tracks, 19 cells with several, 0 untrusted, max residual  2.3E-17
step 3: 306 tracks, 18 cells with several, 0 untrusted, max residual  2.0E-17
step 4: 307 tracks, 19 cells with several, 0 untrusted, max residual  3.5E-17
step 5: 307 tracks, 19 cells with several, 0 untrusted, max residual  4.5E-17
step 6: 308 tracks, 20 cells with several, 0 untrusted, max residual  1.3E-16
step 7: 309 tracks, 21 cells with several, 0 untrusted, max residual  1.2E-16
step 8: 306 tracks, 18 cells with several, 0 untrusted, max residual  6.2E-17

The end-pose overlap is not enough. Linking a piece at t with a piece at t + dt when they overlap gets two cases wrong, and both happen where a body is thin compared with its step:

In one cell, over one stepTracksOverlap of the end poses
The plate pushes the fluid ahead of it out of the cell, and the fluid behind it fills the cella dead track and a continuing oneone merged piece: the fluid on both sides of the wall mixes
A thin plate crosses the whole cella dead track and a fresh one"continuing"
A narrow gap moves more than its own widthcontinuingdead + fresh

Published schemes keep a step below one cell: Falcovitz et al. (1997, §3) assume no cell goes from fully exposed to fully covered in one step, Bayyuk et al. (1993) bound the step by the smallest uncut cell, and Mittal et al. (2008, §2.2) get one layer of fresh cells per step. The plate rows above and the 2-cell bench steps lie outside those assumptions. On the bench bodies (fossil_val_device_chain's ellipse, NACA 0012, sphere and cone, at displacements of 0.5 and 2 cells per step), the overlap disagrees with the tracks in 0.02–0.14 % of the cells the wall touches. Most of these cells are at the NACA trailing edge and on the cone's base rim.

How it is built (in 2-D):

  • Events. The topology of a cell's fluid changes only when the wall's contact with the cell boundary changes:

    • a wall vertex crossing a face line;
    • a cell corner crossing a wall segment.

    These are the instants the exact swept faces already isolate. Two parts of a rigid curve keep their distance, so they cannot meet inside a cell.

  • Pieces. They are evaluated at the two end poses, which must reproduce the end cuts bit for bit, and once inside every interval between events.

  • Links. Pieces of consecutive evaluations that share a boundary feature (a wall segment, a fluid corner) are one track. A feature present on both sides of an event keeps a non-degenerate part in the cell, and the fluid next to it is continuous.

  • The trivial case. A cell with no event has one track per piece, unchanged. "One piece at each end" is not enough: on the 2-D bench motions, 148 such cells have two tracks.

What a track carries:

  • its old and new pieces, numbered as cut_cells numbers them on a moved copy, plus the inverse maps old_track / new_track;
  • V0 and V1;
  • the time-averaged fluid length of each face that belongs to it;
  • its wall −Σ_f Ā_f n_f;
  • outflow: the time-integrated outflow of the step's rigid field through each face part, the consistency term that keeps a uniform flow moving with the body exact (under rotation the velocity varies along a face, so the apertures alone do not give it);
  • its residual, V1 − V0 + Σ_f outflow: the rigid-field balance of residual, per track.

The per-track residual is round-off on the exact paths: at most 1.3·10⁻¹⁶ in the run above. Summed over a cell's tracks, the measures give the cell's swept_cells_2d_t values: copied in a one-track cell, and to round-off in the others.

On the Gauss path (exact=.false.) a cell with several tracks still integrates per interval between its events, because a track lives only between events and Gauss nodes spread over the whole step would miss a short-lived one. Its tracks' residuals stay at round-off, and their sums differ from the cell's Gauss values by the quadrature error. A one-track cell copies the cell's Gauss values, quadrature error included.

A conservative update through the map. fossil_val_moving_conservation (validation) advects a passive scalar across 100 steps of an ellipse and a NACA 0012 at 40²–96², by translation and by the screw motion, at 0.5 and 2 cells per step. The update has four parts:

  • Face fluxes: one flux F_f per grid face, split to each side's tracks by their own rigid outflow outflow, so both sides exchange exactly F_f.
  • Track update: each track takes its old pieces' mass plus its fluxes. A fresh track fills by its own inflow, with no interpolation.
  • Dead tracks: a dead track hands its remainder to a neighbouring new piece.
  • New pieces: a track's mass is shared among its new pieces by area.
  • In the literature: Murman et al. (2003, §4) integrate an emerging cell without reconstructing it, as a fresh track does here. A dead track's remainder is the vanishing-cell state of Bayyuk et al. (1993), not guaranteed to vanish; Schneiders et al. (2016, §3.8) give it to the neighbours by volume weights.

Results:

  • Mass: constant to 1.5·10⁻¹⁴ (relative) in every case.
  • A uniform scalar carried by the body's own rigid field: stays uniform to 2.4·10⁻¹² of a cell on the exact paths. That is the per-track residual: a uniform flow moving with the body is exact, as Falcovitz et al. (1997) require, here shown numerically.

It is a demonstration, not a solver. Its first-order implicit upwind smears the two scalars of the leakage control (one on each side of the body). Tracks leak less than the end-pose overlap and than a per-cell lumped update, but only by 0.1–1 %.

Tolerances. The construction is exact, with two explicit thresholds:

  • every event carries the round-off of its instant: the explicit translation formulas their magnitudes over their denominator (times 64 eps), the screw events the width isolate_zeros localises them to (issue #104). Two events closer than the sum of their widths are one instant in double precision; the state between two farther apart is evaluated at its middle, however short (narrow_cells counts the cells with one shorter than 1e-10): a plate 2e-11 thick crossing a cell reads dead + fresh. In the bench every pair closer than 1e-10 is round-off (1e-17 to 2.5e-13 apart on translations, dyadic widths of uncertified zeros on rotations): no bench cell changed;

  • a piece with no known feature is dropped only if its face lengths are below 1e-9 of the cell side.

  • Exact tangential contact under rotation. A wall feature can touch a cell feature tangentially and leave without crossing, a double root of an event function. When that root lies within the round-off of the event function, it cannot be certified. Its cell is then marked TRACK_UNTRUSTED and counted in contact_cells, never linked by guess. Off by more than about 1e-12, the two roots are certified and the tracks are right. Translation cannot produce it, because its event functions are linear.

A cell whose evaluations cannot be matched is also flagged TRACK_UNTRUSTED: one track with all its pieces and the cell's values, so a conservative update stays exact there. Apart from the constructed exact-contact cases, there were none in the tests, the benches or the conservation runs.

In 3-D, swept_cells_3d(..., map=) returns a piece_map_3d_t with the same layout: six faces, a wall of three components, outflow(6, nt).

  • Events: a mesh vertex crossing one of the cell's face planes, a mesh edge crossing one of its edges, a cell corner crossing a facet. They come from the per-plane breakpoints of the exact swept faces.
  • Features: facet ids (a triangle clipped to a box is convex and bounds one piece) and fluid corners.
  • Results: on the sphere and the cone, under translation, exact rotation and Gauss rotation, there are 0 untrusted cells, and the per-track residuals stay at most 2.7·10⁻¹⁵ on the exact paths.

Cost: in 3-D, 3–13 % on top of a translating swept_cells_3d at 32³–64³ and 49–281 % on top of a Gauss rotation, where the swept call itself is cheap (0.15–1.7 s). In 2-D, 1–22 % on top of swept_cells_2d at 256²–1024², and 0 to 281 cells with several tracks per step (the NACA 0012 under a Gauss rotation at 1024²). The map is not combined with poses= (it needs the screw motion).

The map on the device ​

swept_cells_2d_device(..., map=) and swept_cells_3d_device(..., map=) (issue #105) return the map of swept_cells_2d(..., map=) / swept_cells_3d(..., map=), bit for bit. Every other output is that of the call without map.

  • On the device: the per-item passes. The one-cell evaluations, one item per (cell, evaluation), each with its own workspace sized by a count pass; the tracks of every cell; the measure rounds, one item per (cell, interval, node), summed in node order; the assembly by count, scan and fill. In 3-D the posed facets, the plan's facets and the evaluations stay resident for the whole build.
  • On the host: the plan (candidate cells, events, the pose of every evaluation and node, the Gauss nodes), the corner flags (2-D) or corner states (3-D), the scans and the convergence decisions of each round. The device cos, sin and atan2 differ from the host's by 1 ulp in 17 %, 14 % and 1.8 % of random arguments (RTX 4070, nvfortran 26.9, -gpu=nofma), so events and poses computed on the device would not be the host's bits. The device reads the host's pose table.
  • End poses: with map they are cut in full, by cut_cells_3d_device without alpha_only in 3-D and on the host in 2-D: the map needs their pieces.
  • chunk_bytes (default 2²⁸) caps the workspace of one launch set of items. No output depends on it.

How the map is timed. The map has no timer of its own: its cost is the call with map less the same call without it. A difference of two calls is noisy where the map is a small part of the call, so the benches pair them: each repetition runs both calls back to back (in reverse order every other repetition, so that a first-call penalty widens the spread instead of biasing the result), the share is the median of the paired differences, and its spread is twice their median absolute deviation. A share not above its spread is reported as not resolved, with no speed-up. The same holds for the refine machinery (the call with refine=.true. less the Gauss call).

Measured by fossil_test_distance_bench (dragon-fine run, Gauss nq = 4, 3 repetitions) on an RTX 4070 and a CPU shared with other jobs, so the ratios are indicative; every share below is resolved (spreads up to 22 % of the share for the map, up to 37 % for the refine machinery, largest on the device side):

bodycellsmap, CPU [s]map, device [s]speed-uprefine machinery, CPU [s]device [s]speed-up
sphere (marching cubes)32³0.2380.6000.40×3.420.8863.9×
sphere64³0.8630.2353.7×18.12.996.1×
cone32³0.5590.7460.75×2.401.062.3×
cone64³3.774.220.89×19.49.322.1×
  • With refine the per-item passes are most of the work, and they gain 2.1–6.1× (3.7–10.7× in an earlier run on the same shared machine, best of 2 without pairing: the device side varies most).
  • On the 3-D Gauss path the map gains nothing at 32³ (0.40–0.75×) and on the cone at 64³ (0.89×); only the sphere at 64³ gains (3.7×). In the device chain, over warm steps, the device map is 1.2–1.9× the host's at 32³ and 64³ (the sphere's host map at 64³ is not resolved there). Either way the host plan dominates, above all the events of the rotation (isolate_zeros), which stay on the host for the trig reason above.
  • In 2-D the device map gains nothing: few cells are evaluated (about 3,000 of a million at 1024²), so there is little device work to gain from, and the copies dominate. In fossil_test_curve_bench (ellipse, 5 repetitions) the Gauss map runs at 0.89× the host's at 256² and 0.67× at 1024², the translation map at 0.82× and 0.34×; with refine the map's share (its assembly only: the machinery is in both calls) is not resolved. In the device chain the 2-D map is 0.64–0.77× the host's.

The chain of a whole time step with the map is in GPU queries.

Several bodies ​

swept_cells_2d_bodies(curves, poses0, poses1, x, y, sw, nq=, exact=.false.) and swept_cells_3d_bodies(surfaces, poses0, poses1, x, y, z, sw, ...) give the swept geometry of several rigid bodies over one step, each body on its own screw motion from poses0(b) to poses1(b) (#109 WP3). They fill the same swept_cells_2d_t / swept_cells_3d_t:

  • Volumes. swept is (α₁ − α₀) |cell| from the cut of the union at the two end poses (several bodies: cut_cells_2d_bodies / cut_cells_3d_bodies), so it stays exact. An overlap at an end pose is refused.
  • Apertures. Gauss-Legendre over the step: at each of the nq nodes every body is placed at its own interpolated pose and the union is cut (with the overlap check), then the face apertures are read as for one body; nq and 2 nq nodes give error_estimate.
  • Residual. No single rigid field fits the walls of two bodies with different motions. A cell whose walls at a node belong to one body takes the outflow of that body's field through its fluid faces, as for one body. A cell holding the walls of two bodies takes the wall form instead, the sum over its wall terms of v_b(centroid) · A, A the term's vector area and v_b the field of its body. For one body the two forms agree by the closed-boundary identity: two cubes 0.2 apart on one motion give the merged surface's residual to 1.2e-17.
  • Exact paths not built. Only exact=.false. is accepted: exact absent or .true. returns STATUS_INVALID_INPUT. There is no map=, refine=, poses= or device path. One body gives swept_cells_2d / swept_cells_3d with exact=.false. bit for bit.

What the exact paths need was measured first (#109 WP3 step 04: circles and spheres passing at gaps of 0.5–2 cells, translating or rolling; a circle orbiting another; a three-blade star and a NACA 0012 rotor in an annular casing, tip gaps of 0.5–2 cells; two bodies approaching to contact):

  • No inter-body events while the bodies stay apart. A vertex of one body crossing a wall of the other means the bodies overlap, and the cut refuses that. Sampled densely, every case with a gap had 0 such crossings. The approach case had them only in the step that runs past contact, where every later sample is refused. Bodies can meet inside a cell only by touching: a double root, which needs contact detection over the step (time_of_impact), not a new event type.
  • Superposition. While the solids stay disjoint, a face's fluid length (area) is the sum of each body's minus (bodies − 1) times the face, at every instant. The exact time-averaged apertures of several bodies are therefore the single-body exact apertures combined, and the residual is the sum of the bodies' residuals.
  • Few cells see two bodies. In 2-D 0.4–10 cells per step held walls of both bodies (at a gap of 0.5 cell; the rotor in its casing the most), against 47–144 cells with an event of one body; in 3-D 1.7 per step against 1 200. At a gap of 2 cells none did, nor at a gap of 1 cell in the axis-aligned passings. Every such cell held one fluid piece bounded by both walls.
  • Piece map. The union's piece count changed in those cells only at an event of one of the bodies (a NACA 0012 rotor at a gap of half a cell: 22 changes in 30 steps). The map of several bodies is the map of the union with each body's own events, its local elements placed by their own body's pose, and contact made a reason for an untrusted cell. It is not built.

a three-blade rotor turning 0.15 rad inside a fixed annular casing on 16 x 16 cells of 0.1 seen from above, a tip gap of half a cell: the cells shaded by their swept area over the cell area, ember where fluid is gained behind the blades, teal ahead of them; the rotor at the start in dark brown and at the end in yellow, the casing in grey; eight cells at the blade tips, where the fluid piece is bounded by both the rotor and the casing, outlined in red

A rotor in a casing, each body on its own motion, swept on the Gauss path. The swept areas add up to round-off, and eight cells at the blade tips hold a fluid piece bounded by both walls. Asked for the exact path, the call refuses.

f90
!< Figure of the reference page "Moving bodies", section "Several bodies": a three-blade rotor (tip radius 0.55, a
!< 96-gon) turning 0.15 rad inside a fixed annular casing (radii 0.6 and 0.75), a tip gap of half a cell, on 16 x 16
!< cells of 0.1, swept by `swept_cells_2d_bodies` on the Gauss path. The cells are shaded by their swept area over the
!< cell area (ember: fluid gained, teal: fluid lost); the rotor at the start (dark) and at the end (yellow), the casing
!< (grey); the cells whose fluid piece is bounded by both bodies at the start or at the end are outlined in red. The run
!< prints the balance, the cells shared by the two bodies, then the refusal of the exact path.
program fig_ref_moving_bodies_several
use fossil,     only : curve_object, rigid_pose_2d_t, pose_2d, swept_cells_2d_t, swept_cells_2d_bodies, cut_cells_2d_t, &
                       cut_cells_2d_bodies, piece_bodies_t, STATUS_OK
use fossil_fig, only : fig_open, fig_segments, fig_quad, fig_close
use penf,       only : I4P, R8P
use vecfor,     only : vector_R8P

implicit none
integer(I4P), parameter       :: N = 16
real(R8P),    parameter       :: H = 0.1_R8P, PI = acos(-1._R8P), LIFT = 1.e-3_R8P
type(curve_object)            :: body(2), moved
type(rigid_pose_2d_t)         :: pose0(2), pose1(2)
type(swept_cells_2d_t)        :: sw
type(cut_cells_2d_t)          :: cut
type(piece_bodies_t)          :: pb
real(R8P)                     :: x(N + 1), u(192), v(192), th, r
type(vector_R8P), allocatable :: s(:), e(:)
logical                       :: both(N, N)
integer(I4P)                  :: i, j, k, m, p, status, w, nb0, nb1

x = [(-0.8_R8P + H * i, i = 0, N)]
do k = 1, 96                                                  ! the rotor: r = 0.55 (0.55 + 0.45 cos 3 theta)
   th = 2 * PI * (k - 1) / 96 ; r = 0.55_R8P * (0.55_R8P + 0.45_R8P * cos(3 * th))
   u(k) = r * cos(th) ; v(k) = r * sin(th)
enddo
call body(1)%adopt_loops(u=u(1:96), v=v(1:96), loop_sizes=[96_I4P])
do k = 1, 96                                                  ! the casing: outer loop counter-clockwise, inner clockwise
   u(k) = 0.75_R8P * cos(2 * PI * (k - 1) / 96) ; v(k) = 0.75_R8P * sin(2 * PI * (k - 1) / 96)
   u(96 + k) = 0.6_R8P * cos(-2 * PI * (k - 1) / 96) ; v(96 + k) = 0.6_R8P * sin(-2 * PI * (k - 1) / 96)
enddo
call body(2)%adopt_loops(u=u, v=v, loop_sizes=[96_I4P, 96_I4P])
pose0(1) = pose_2d(angle=0.1_R8P) ; pose1(1) = pose_2d(angle=0.25_R8P)   ! the rotor turns, each body on its own motion
pose0(2) = pose_2d(angle=0._R8P)  ; pose1(2) = pose0(2)                  ! the casing stays
call swept_cells_2d_bodies(body, pose0, pose1, x, x, sw, exact=.false., status=status)
if (status /= STATUS_OK) error stop 'swept_cells_2d_bodies failed'
print '(A,I0,A,I0,A,ES9.2)', 'Gauss nodes ', sw%evaluations, ', cells with a swept area ', count(sw%swept /= 0._R8P), &
                             ', sum of swept ', sum(sw%swept)
print '(A,ES9.2,A,ES9.2)', 'largest residual ', maxval(abs(sw%residual)), ', error estimate ', sw%error_estimate
both = .false.
call shared(pose0, nb0) ; call shared(pose1, nb1)
print '(A,I0,A,I0,A,I0)', 'pieces bounded by both bodies: start ', nb0, ', end ', nb1, ', cells ', count(both)
call swept_cells_2d_bodies(body, pose0, pose1, x, x, sw, status=status)
print '(A,I0,A)', 'exact path asked: status ', status, ' (refused: several bodies have the Gauss path only)'

! the figure
call swept_cells_2d_bodies(body, pose0, pose1, x, x, sw, exact=.false., status=status)
call fig_open(w, 'ref-moving-bodies-several', 'swept area / cell area; rotor start dark, end yellow; '// &
              'shared cells red', -90._R8P, 90._R8P, width=640_I4P, height=640_I4P)
do j = 1, N
   do i = 1, N
      call fig_quad(w, 'field', q(x(i), x(j), 0._R8P), q(x(i + 1), x(j), 0._R8P), q(x(i + 1), x(j + 1), 0._R8P), &
                    q(x(i), x(j + 1), 0._R8P), value=sw%swept(i, j) / H**2)
   enddo
enddo
allocate(s(4 * N * N), e(4 * N * N)) ; m = 0
do j = 1, N
   do i = 1, N
      if (.not. both(i, j)) cycle
      s(m + 1:m + 4) = [q(x(i), x(j), 2 * LIFT), q(x(i + 1), x(j), 2 * LIFT), q(x(i + 1), x(j + 1), 2 * LIFT), &
                        q(x(i), x(j + 1), 2 * LIFT)]
      e(m + 1:m + 4) = [q(x(i + 1), x(j), 2 * LIFT), q(x(i + 1), x(j + 1), 2 * LIFT), q(x(i), x(j + 1), 2 * LIFT), &
                        q(x(i), x(j), 2 * LIFT)]
      m = m + 4
   enddo
enddo
call fig_segments(w, 'hole', s(1:m), e(1:m))
moved = body(1) ; call moved%move(pose0(1)) ; call outline(moved, 'cell')
moved = body(1) ; call moved%move(pose1(1)) ; call outline(moved, 'accent')
call outline(body(2), 'box')
call fig_close(w)
contains
   subroutine shared(pose, nboth)
   !< The pieces bounded by both bodies at a pose set, their cells marked in `both`.
   type(rigid_pose_2d_t), intent(in)  :: pose(2) !< Poses.
   integer(I4P),          intent(out) :: nboth   !< Pieces bounded by both bodies.
   integer(I4P)                       :: p_      !< Piece.

   call cut_cells_2d_bodies(body, pose, x, x, cut, status=status, piece_bodies=pb)
   nboth = 0
   do p_ = 1, pb%np
      if (pb%start(p_ + 1) - pb%start(p_) < 2) cycle
      nboth = nboth + 1 ; both(cut%piece_cell(1, p_), cut%piece_cell(2, p_)) = .true.
   enddo
   endsubroutine shared

   subroutine outline(c, style)
   !< The segments of curve c, just above the cells.
   type(curve_object), intent(in) :: c     !< Curve.
   character(*),       intent(in) :: style !< Style.
   type(vector_R8P), allocatable  :: a(:), b(:)
   real(R8P)                      :: uv(2)
   integer(I4P)                   :: i_, n_, nv

   nv = c%get_vertices_number()
   allocate(a(nv), b(nv)) ; n_ = 0
   do i_ = 1, nv
      if (c%get_next(i_) == 0_I4P) cycle
      n_ = n_ + 1
      uv = c%get_vertex(i_) ; a(n_) = q(uv(1), uv(2), 3 * LIFT)
      uv = c%get_vertex(c%get_next(i_)) ; b(n_) = q(uv(1), uv(2), 3 * LIFT)
   enddo
   call fig_segments(w, style, a(1:n_), b(1:n_))
   endsubroutine outline

   function q(a_, b_, dz) result(r_)
   !< A point of the plane z = 0, lifted by dz towards the viewer.
   real(R8P), intent(in) :: a_, b_, dz !< Coordinates, lift.
   type(vector_R8P)      :: r_         !< Point.

   r_ = vector_R8P(a_, b_, dz)
   endfunction q
endprogram fig_ref_moving_bodies_several
$ fig_ref_moving_bodies_several
Gauss nodes 4, cells with a swept area 59, sum of swept  9.54E-17
largest residual  4.85E-04, error estimate  1.33E-02
pieces bounded by both bodies: start 6, end 6, cells 8
fossil swept_cells_2d_bodies: refused -- several bodies have the Gauss path only: pass exact=.false.
exact path asked: status 5 (refused: several bodies have the Gauss path only)

Results ​

CaseResult
body-frame vs moved and rebuilt: cube (also translated by 108), cone, L-prism, bunny, NACA 0012, annulusdistances ≤ 1e-16 (L + |t|), closest points ≤ 6.5e-15 (L + |t|), signs and inside flags equal
posed device vs posed CPUevery output bit for bit (device path run on the host)
move (refit) vs moved and rebuilt: cube, cone, L-prism, bunny, octree cube, NACA 0012, annulusgeometry, distances, inside flags, box codes, line crossings, cut cells bit for bit
refit time / rebuild time0.03 (bunny) to 0.4 (tiny meshes)
fresh / dead: cube translated, rotated about an off-centre axis, general poses; square, pitching NACA 00120 errors against the analytic change of membership; the band skips 9–60 % of the second queries
swept, 2-D translation: square (every face vs analytic), non-convex heptagon, heptagon at a rotated posefaces to 8.3e-17; uniform-flow residual ≤ 1.7e-16 in every cell; walls sum to ≤ 1.4e-16
swept, 2-D negative control: Gauss with 4 nodes, no breakpointsresidual 9.0e-3
swept, 2-D rotation, Gauss (exact=.false.): off-centre square, pitching NACA 0012; nq = 2, 4, 8, 16residual 5.6e-3 → 1.6e-4 (rate ≈ 2.3) and 1.5e-3 → 1.6e-6 (rate ≈ 3.4)
swept, 3-D rotation, exact (issue #69): cube 0.3 rad about (1, 1, 1) + shift (faces starting on grid planes), L-prism 0.5 rad about a tilted axis + shift, 32-face cone pitching 0.4 radresidual 1.4e-16, 1.8e-15, 5.0e-16 (6³ validation: 4.3e-17, 8.3e-16, 5.0e-16); walls sum ≤ 1.8e-15; Gauss nq = 8 ≥ 4× closer than nq = 2
swept, 2-D rotation, exact (issue #69): square 0.4 rad off-centre + shift, square 1.2 rad + shift, NACA 0012 pitching 0.15 radresidual 1.7e-16, 1.8e-16, 6.3e-16; walls sum ≤ 1.9e-16; Gauss nq = 16 ≥ 4× closer to the exact faces than nq = 4
swept, rotation with the wall starting on grid lines / planes (issues #84, #86; fossil_test_swept_rotation_onplane): square [−0.5, 0.5]² on a 0.5 grid, 0.1 rad + shift; centred unit cube 0.35 rad about (0.3, 0.2, 1) + shift, faces y = ±0.5 on grid planesexact (both were not before); residual 1.3e-16, 4.4e-16; walls sum ≤ 5.6e-17
swept, 2-D rotation of dragon sections, z = −0.35, −0.20, −0.10, −0.05, π/18 on a 0.025 grid (fossil_val_swept_rotation_2d)all exact (before: one or two of the four not, which ones depending on the round-off of the placed mesh; turned in 10-degree steps, most steps not); residual ≤ 1.2e-17
swept, 3-D translation: unit cube (every face vs analytic)faces to 5.6e-17; uniform-flow residual 2.5e-17; walls sum to ≤ 8.3e-17
swept, 3-D translation: cube and L-prism at a pose rotated about (1, 1, 1), 32-face coneuniform-flow residual 7.6e-17, 3.0e-16, 1.9e-16
swept, 3-D translation without one breakpoint class (vertex / edge-line / node-triangle)residual up to 5.7e-4 / 1.4e-3 / 1.3e-5: each class is needed
swept, 3-D negative control: unit cube translating, Gauss, nq = 2, 4, 8, 16faces vs analytic 2.5e-2 → 2.3e-3; residual 1.3e-2 → 7.1e-4
swept, 3-D: cube rotating about (1, 1, 1) while translating; nq = 2, 4, 8residual 1.1e-2 → 1.6e-3
swept: explicit node poses = screw posesface apertures bit for bit
swept on the device vs the host: every output of swept_cells_3d_t / swept_cells_2d_t, exact translation, exact rotation, Gauss, explicit poses; chunk boundaries (chunk_cells)0 mismatches (swept cells 3-D / 2-D device vs serial mismatches, fossil_test_swept_3d_device_twin, fossil_test_swept_2d_device_twin)
swept, several bodies (Gauss, swept_cells_2d_bodies / swept_cells_3d_bodies): one body vs swept_cells_*(exact=.false.); two far-apart bodies vs each alone; two bodies on one motion vs their merged bodybit for bit; per side bit for bit, the residual to 1e-16; faces and volumes bit for bit, residual (wall form) to 1.2e-17 (3-D) and 1.7e-18 (2-D) (fossil_test_swept_bodies, _2d)
piece map on the device vs the host: every field of piece_map_3d_t / piece_map_2d_t; sphere and cone at 32³ (exact translation, exact rotation, Gauss, Gauss + refine); ellipse at 256² (translation, Gauss, Gauss + refine), NACA 0012 rotating at 64²; launch sets of 4 KB (chunk_bytes)0 mismatches (piece map 3-D / 2-D device vs serial mismatches, fossil_test_piece_map_3d_device_twin, fossil_test_piece_map_2d_device_twin; the map stage of fossil_val_device_chain)

Limitations ​

  • Swept geometry: the Gauss path at large steps. With exact=.false. the face apertures use nq Gauss nodes over the whole step. The face integrands kink, and jump, at the events (a vertex crossing a face line, a corner crossing a segment, a face leaving the body), and global nodes resolve them at about first order.
    • Measured (issue #104; ellipse and NACA 0012 at 256², sphere and cone at 32³; 0.5, 1 and 2 cells per step): the largest per-cell residual is 7·10⁻⁴ to 0.45 of a cell at nq = 4, and still 2·10⁻⁴ to 0.15 at nq = 8.
    • error_estimate includes the residual since issue #104; the face change alone understated it a hundredfold.
    • refine=.true. makes the residual round-off: 1.1–2.2 times the Gauss call in 2-D, 2.7–22 times in 3-D, about the exact path's cost there. It stays off by default (the owner's decision on #104: too slow in 3-D for a default). In 2-D the exact rotation path is now cheaper than both up to 2 cells per step (0.07–0.65 of a Gauss call, issue #104), so there the exact path is also the fast one.
    • The piece map's multi-track cells do not inherit the error: they integrate per event interval on every path.
  • Spurious force oscillations are not addressed. Exact swept volumes remove the fresh/dead volume source that Seo & Mittal (2011, §2) call their primary cause. Schneiders et al. (2013, §4-§5) show oscillations in a conservative scheme whose discrete operator switches, a merge target turning on or off; the llm-wiki records the disagreement as open.
  • Swept geometry: a self-intersecting wall breaks the balance. The swept volumes come from the cut cells (Green's theorem: a region counts by its winding number) and the face apertures from line crossings (parity). Where the wall crosses itself the two count the knot differently, so the cells around the knot get a residual that is not round-off, even on the exact translation path. Measured on a section of the (non-manifold) dragon that crosses itself once at a fold: residual 5.3e-6 in the cell the knot enters; with the knot removed, 7.8e-18 over the same 25 shifts. Pass check_input=.true. to swept_cells_2d / swept_cells_3d: the input is checked first (one self_intersections, or find_self_intersections in 3-D, which costs more), sw%self_intersecting is set and a warning goes to stderr; the result is computed anyway.
  • Swept geometry: rotations converge slowly across jumps.
    • A face's fluid length (area) jumps when the face's line (plane) leaves the body. Gauss across a jump is O(1/nq).
    • Rotation in 2-D gives rates of about 2–3; in 3-D about first order (cube: residual 1.1e-2 → 1.6e-3 from nq = 2 to 8). The exact paths (the default) and refine do not have this error.
  • Swept geometry: the cost. The 2-D exact path costs O((faces + nodes) × segments). The 3-D exact path costs, per grid plane, a scan of the triangles in the slab the plane sweeps, plus 2 (breakpoints + 1) sections and 2-D cut-cell passes; the breakpoints grow with the mesh vertices and edges in that slab, so a fine mesh and a long step make it expensive (sw%evaluations reports it). The Gauss paths cost one moved copy and one face pass per node, plus as many again for the error estimate.
  • Several bodies: the Gauss path only. swept_cells_*_bodies has no exact path, piece map, refine or device path; the several bodies section says what they need. Overlap between Gauss nodes is not detected: check the step with time_of_impact / first_impact first.
  • Rigid bodies only. Deforming bodies, and refitting under deformation, are out of scope.
  • Points near the surface. state_changes decides states with the point-query sign, so a point within round-off of the wall can differ from the cut-cell parity.
  • GPU not validated yet. The posed device paths run on the host in tests-gnu; the GPU benches print posed device vs serial mismatches for the manual gate.