This section gives a conceptual outline of how Union_master actually propagates rays; see the original thesis [Ber17] for the full derivation and pseudocode.
Within a volume, the distance to the next scattering position is drawn from the usual exponential distribution set by the total inverse penetration depth (sum over the volume’s absorption and all its processes’ scattering contributions). If this distance is less than the distance to the volume’s boundary, a scattering event occurs there; the specific process is chosen by a weighted Monte Carlo choice between the processes active in the current material (or forced via interact_fraction, in which case the ray weight is corrected to remain unbiased). Otherwise, the ray is propagated to the boundary and the simulation continues in whichever volume lies on the other side.
Naively, determining "the other side" of a boundary would require testing every other defined volume for intersection and containment, for every propagation step – prohibitively expensive once more than a handful of volumes are involved. Instead, in the initialize section of each Union_master, the whole ensemble of volumes is analysed once to build, for every volume \(n\):
an intersection list \(I_n\): the (usually small) set of other volumes that actually need an intersection test while the ray is inside volume \(n\) – volumes with lower priority, or volumes properly nested inside another candidate, are pruned out;
a destinations list \(D_n\): the set of volumes the ray could possibly end up in immediately after leaving volume \(n\) through its own boundary, used to resolve exactly which volume that is when several overlap there.
This turns an \(O(N)\)-per-step cost (checking every volume) into something close to \(O(1)\) in typical geometries, and is what makes simulating sample environments built from dozens of volumes computationally practical. Figure B.2 sketches the resulting behaviour for a simple case.
| Figure B.2.: | Illustration of the Union propagation algorithm for a single scattering event between two overlapping volumes. Only intersections actually relevant given the ray’s current volume are calculated at each step (the orange volume, never reachable from the ray’s actual path here, is never tested). |
Coincident surfaces. If two volume boundaries coincide exactly, the algorithm cannot reliably determine which volume a ray enters (the decision is essentially made by floating-point rounding). It is safe, and normal, to overlap volumes – but two volumes should never be placed so that a face merely touches without any overlap or gap; leaving even a micron-scale gap or overlap avoids the problem entirely.
No gravity. The underlying intersection algorithms are linear, so Union volumes do not support gravity; propagation inside a Union_master is always a straight line even if --gravity is enabled for the rest of the instrument.
GPU. The default Union_master is CPU-only (NOACC); use Union_master_GPU for OpenACC builds (see the User Manual’s chapter on running McStas, section on GPU acceleration).