# Testing of the Code

In order to simulate the system properly, random numbers must be used in such a fashion that when many photons are simulated, the probabilistic events occur in the simulation with the frequency predicted by theory.  To verify that the code is correct, each  components of the code was tested.  The results are presented here.

Random Number Generation:

The random number generator must provide uniform weighting on the interval (0,1).  The graph below shows the distribution of 10 million random numbers from Matlab’s default Marsaglia subtract with borrow random number generator, with resolution 0.001.  As one can see, the distribution is quite uniform.  Although this preliminary test appears reasonable, further testing will be carried out.

Figure 1.  10 million random numbers from Matlab’s default generator.

Optical path length selection:

Bulk layers have an IOP known as the “volume extinction coefficient” (or just “extinction”), which is the sum of the volume scattering coefficient and the volume absorption coefficient.  The extinction σ is defined as the fraction of photons or energy lost from a beam per infinitesimal distance traveled.  For finite distances this results in “Beer’s Law” , which states that the intensity decreases exponentially with the extinction times the distance: .  This is rigorously true for absorption loss, but for scattering, photons may multiply scatter and “reenter” the beam path.  Also, depending on how one measures the “beam”, photons may be scattered through such small angles that they still appear to be part of the initial beam, and are counted even when measured in a very small solid angle.  But for low scattering path lengths, Beer’s Law holds up.

The AO3D model employs a random number to determine the path transmission (optical path traveled) for each photon.  By integrating the optical path within each layer, the photon’s final extinction location is determined.  In order to test this algorithm, the number of photons passing through each distance interval were calculated with AO3D, and plotted (green markers) in Figures 2 and 3.  A plot of Beer’s Law is also shown for comparison (solid blue line).    Figure 2 is for pure absorption, while Figure 3 is for pure scattering.  The results are from a run of the code with a single atmospheric layer with a marine aerosol, which scatters almost entirely into small angles, and the extinction set to 0.01 m-1.  The observation is set to a downwelling radiance grid with 1-meter resolution in the z-direction, and 1-degree acceptance half-angle.

Figure 2.  Beer’s Law Test, 50,000 photons, absorption = 0.01 m-1, scattering = 0 m-1.

Figure 2 shows the results of the pure absorption test.  Note the near-perfect conformance to Beer’s Law, as expected.

Figure 3.  Beer’s Law Test, 50,000 photons, absorption = 0 m-1, scattering = 0.01 m-1, acceptance half-angle = 1 degree.

Figure 3 shows the results of the pure scattering test.  Again it is nearly perfect.  Note that for longer distances, the number of photons in the beam is higher than Beer’s Law predicts.  We also see that virtually no photons exit and reenter the beam within 1 degree, as the conformance at greater distances is nearly complete.  Further studies are being carried out with higher scattering coefficients.

Scattering Angle Selection (Phase Function tests):

The phase function is the probability density function of scattering for a particular solid angle (PDFΩ).  When the phase function is integrated over a solid angle (PDFangle), it describes the probability of a photon being scattered within particular polar and azimuth angles.  The Monte Carlo approach must select scattering angles which conform with the phase function once many realizations have been carried out.  To test the AO3D code, scattering angles selected from the Monte Carlo approach were compared  with the original probability density curves for the phase functions.

Figure 4 shows the base-10 logarithm of the total weighted phase function for a typical polluted marine aerosol with air.  Figure 5 is a plot of the theoretical PDFangle and the frequency of occurrence of sampled angles.

Figure 4.  Polluted Marine Atmosphere Phase Function, 500 nm

Figure 5.  Polluted Marine Atmosphere Actual and Sampled PDF – 100,000 photons

Figure 6 shows the base-10 logarithm of the total weighted phase function for typical turbid water.  Figure 7 is a plot of the theoretical probability density function (PDFangle) and the frequency of occurrence of sampled angles.

Figure 6.  Snohomish River West of Jetty Phase Function, 500 nm

Figure 7.  Snohomish River West of Jetty Actual and Sampled PDF – 100,000 photons

Ocean Surface Tilt Selection – Cox and Munk Slope Distribution:

The well-known Cox and Munk slope distribution is employed in the AO3D code as an approximation to sea surface tilt for moderate wind speeds (<~14 m/s).  To implement this, a lookup table of x- and y-slopes is generated for a chosen wind speed and direction.  A random number then selects both x- and y-slopes at once (their probabilities are not independent in the Cox and Munk formulation).  The graph below shows a 3-D scatter plot of x- and y-slope frequencies of occurrence for 1 million realizations, for a wind speed of 10 m/s.  The expected quasi-Gaussian theoretical distribution is reproduced well by the weighted-random Monte Carlo process (Figure 8) and confirmed by cross-sections which are compared directly with the Cox and Munk expressions in Figures 9 and 10.

Figure 8.  Frequencies of occurrence of ocean surface x- and y-tilts calculated by Monte Carlo approach.  The weighting distribution is based on the Cox and Munk model.  (wind speed 10 m/s, 1 million photons).

Figure 9. Frequency of occurrence of alongwind slope (y-axis), wind speed of 10 m/s in y-direction.

Solid line is the Cox and Munk expression.  Green markers show Monte Carlo results.

Figure 10. Frequency of occurrence of crosswind slope (x-axis), wind speed of 10 m/s in y-direction.

Solid line is the Cox and Munk expression.  Green markers show Monte Carlo results.

id line is the Cox and Munk expression.  Green markers show Monte Carlo results.