How the algorithm works
This page describes what the raytracer computes and why — the physics and the numerical idea, not the code. It is meant for judging whether a result can be trusted and for understanding where the run time goes.
The raytracing algorithm
The basic idea is that each patch of the substrate tries to get as much data from each histogram as possible. The approach goes back to the deposition model developed by Dr. Andreas Pflug and was extended later.
The program is split into time steps that discretise the trajectory of the substrate. In each time step the substrate is placed at the respective point of the trajectory and optionally rotated to keep its orientation towards a fixed point. Then each patch of the substrate geometry is iterated over by casting a number of rays between the centre of the patch and each histogram source, with each angular combination of the respective histogram defining the direction of one ray.
Any ray with the wrong direction, or hitting an obstacle — a concave part of the substrate or a mask — is discarded, leaving only rays that are physically able to reach the histogram.
For each remaining ray the intersection point with the histogram is obtained and the flux at that point is interpolated bilinearly from the four neighbouring histogram samples. All fluxes reaching the patch are summed and weighted by their normalised scalar product with the patch normal, since an oblique ray transfers geometrically less material to a patch than one hitting it perpendicularly.
Over the whole trajectory the intensities of each patch are summed up again. The final values can then be normalised or averaged, depending on what the evaluation needs.
Substrate generation
The predefined shapes are assembled from connected quadrilateral patches. Each patch is defined by four vertices produced from a 2D parametrisation of the 3D geometry — a sphere, for example, is parametrised in spherical coordinates at a constant radius. The exact formulas are on the Substrates page.
The geometry is sampled over a number of patches in two dimensions: a rectangle by a number of patches in x- and y-direction, a disk by its radial and angular direction.
From the vertices, the centre of each patch is the mean of its four corners. The normal at the centre follows from the cross product of the two diagonals. Two normals are always possible, so a sign convention decides which one points outwards — for that, the vertices have to be ordered consistently in every patch.
Mask intersections
A mask is a series of vertices connected by circular arcs — straight lines are approximated by a very large radius — plus a finite thickness in sputtering direction. Two independent tests decide whether a ray is blocked.
First the mask base is tested. The question whether a ray crosses the base reduces to whether the point of the ray at the z coordinate of the mask lies inside the 2D mask shape. This is answered by counting intersections: a point known to be outside the mask is connected to the ray point by a straight line, and this line is tested against every circular arc of the mask with a line-circle intersection. Whenever a circle is hit, the angle of incidence decides whether the intersection lies on the actual arc or only on the full circle, in which case it is discarded. An even number of true intersections means the ray point is outside the mask, an odd number means it is inside and the ray is blocked.
If the ray survives the base test, the mask walls are tested: the arcs extruded by the mask thickness act as cylinders, and a ray-wall intersection is a cylinder-line intersection with the same additional angle check. The top face of the mask needs no test at all — a straight ray that crossed neither the base nor a wall cannot hit the top.
Self-intersections in concave substrates
In a concave substrate a ray cast between the substrate and a histogram can hit the substrate again at a different point. Ignoring this would produce unphysical results: flux would appear at a patch that the geometry shadows.
Because the algorithm is structured as it is, there is only a finite, deterministic number of possible rays between the substrate and all histograms — the patch centres and the angular combinations of the histograms are fixed. This allows all of these intersections to be computed before the run starts, which costs some startup time and saves a large amount of run time.
The procedure: collect all angles from all histograms, cast a ray from every substrate patch along each of these directions into infinity, and test that ray against every patch of the substrate. Each patch is split into triangles for a line-triangle test. The closest intersection for each patch and angle combination is stored.
During the run, each ray looks up this table for its originating patch; if an intersection lies
between the histogram and the substrate, the ray is discarded. This is why
rt.precompute_substrate_intersections() has to be called for concave geometries — without it the
table is missing and shadowing is ignored.
Parallelisation
The self-intersection table and the raytracing loop are parallelised over substrate patches, which are independent of each other. The results do not depend on the number of threads: the same scenario produces the same numbers, only the run time changes.