FREDMPC Advanced Tutorial This tutorial is only applicable to users of the FREDMPC version and it is recommended that you work through the FREDMPC Basic Tutorial first.
The Basic FREDMPC Tutorial walked through a simple example where the user traced rays on the GPU using the Trace GPU Rays and the Trace CPU Rays modes of operation. This advanced example focuses on the topic of making sure that a model is configured correctly for use on the GPU and also looks at the MPC Advanced Raytrace options.
Begin this tutorial by opening the following FRED file: <FRED Installation Directory>\Resources\Samples\Tutorials & Examples\FREDmpc_Advanced_Tutorial.frd.
This is a model of a double Gauss lens system, with a Solar Source (simple) Source Primitive set up to enter the lens system at 20 degrees. The Image Plane is a Detector Entity configured to calculate the Irradiance “At Trace End” with the default Ray Filter of “All Rays.”
Raytracing this model on a 16-thread CPU with 10 million source rays takes about 4 minutes. The analysis results node (ARN) that is automatically generated by the detector entity shows a non-uniform irradiance distribution formed by the ghosting from the lens elements.
Note from the Raytrace Summary that the number of rays at the end of the raytrace is over 14x times what we started with due to the specular ray splitting at all of these lens surfaces.
We can reduce the statistical noise in the irradiance distribution by tracing more rays, but the CPU raytrace would then take more than 40 minutes. In this scenario, the GPU raytrace can be used to save significant raytrace time.
To test the validity of the GPU raytrace before increasing the number of rays in the source, click on the “MPC Trace CPU Rays” button on the toolbar or use the equivalent option from the MPC menu. As discussed in the Basic example, FRED will create the rays using the CPU and then pass them to the GPU for tracing, bringing them back afterwards to the CPU for post processing.
As expected, the raytrace finishes faster (~20 seconds on an RTX 3070) than the CPU trace and the new ARN shows a similar profile, although with some differences.
Modifying the Source Next we wish to increase the number of source rays and obtain a more refined result. Creating rays directly on the GPU is significantly faster than creating them on the CPU. As long as the source configuration uses features supported by the GPU, the rays will be created directly on the GPU as part of the Trace GPU Rays mode of raytracing. However, the Solar Source type uses a spectrum to define the ray wavelengths, which is not supported on the GPU.
Due to how the information for wavelength and sampled properties (coatings, materials, etc.) are stored on the GPUs, the wavelength specification “Randomly according to spectrum” can’t be used. As an alternative to spectra, multiple discrete wavelength values should be assigned to a source node's wavelength list and can then be weighted according to a desired spectrum. Right-click on the source and select, "Edit/View Detailed Optical Source", then click on the Wavelengths/Spectrum tab. Change Ray Wavelengths to “As specified by list” and then right click in the wavelengths grid to select Set Wavelength Range…
Then, choose a wavelength range from 0.38 to 0.75 um, with 20 steps. Then click OK.
Then, right-click again and select Set Weights using a Spectrum…, choosing “Solar Spectrum”, you should see that the weight values have changed according to the profile.
Before clicking OK, click on the Positions/Directions tab and reduce “Num Rays” by a factor of 20 from 10,000,000 to 500,000. This is because FRED will create 500,000 rays for each wavelength in the list. Thus, the total number of source rays generated will still be 10 million. When clicking OK, you are asked to confirm that these changes will convert this source to a Detailed Source type. Click Yes. Click the “MPC Trace GPU Rays” button, or the equivalent option from the MPC menu, and then display the ARN to see result that is much closer to the CPU raytrace.
Now we can be quite confident that we can increase the number of rays and obtain a more refined result. For example, the result below is achieved by increasing the number of starting ray positions to 5,000,000 (10x the original amount of total source rays):
Calculating a Color Image Color Image cannot be calculated directly on the GPU and therefore need to be done by returning the rays from the GPU back to the CPU ray buffer and then calling the Analyses > Color Image calculation. In other words, the “Trace CPU Rays” mode of raytracing is performed and an Analysis Surface is used afterwards to perform the analysis.
If, previously, you increased the number of source rays, then open the source again, click on the Positions/Directions tab and reset the number of starting ray positions to 500,000.
Perform a “Trace CPU Rays” and then go to Analyses > Color Image “Analysis” to calculate the Color Image result. We get an empty chart and a message that no rays were included in the calculation.
The reason for this is that when ray splitting is allowed during the “Trace CPU Rays” mode of operation, only the parent rays will be returned to the CPU ray buffer after the GPU raytrace. Any child rays resulting from ray splitting are not available in RAM for post-processing. In this model, the rays that arrive at the focal plane are all child rays that result from ghost ray splitting within the lens system.
If you wish to calculate the Color Image (or quantities other than Irradiance), then we’ll need to switch to the Monte Carlo raytrace mode so that no ray splitting occurs. This change needs to be made in the two Raytrace Controls that are currently used on surfaces in the model - the “Specular Only” and the “Halt All” Raytrace Controls.
After changing the Raytrace Controls, open the source again and increase the number of rays on the Positions/Directions tab by a factor of 10, then again use the “Trace CPU Rays” mode for the raytrace, followed by the Color Image calculation. Note that the Launch phase of the raytrace is much quicker than before - this is because previously, due to raysplitting, each batch of 1 million rays was creating ~14x child rays. In the monte-carlo configuration, there is no ray splitting and so each launch starts, and ends, with 1 million rays. The total number of source rays is increased to compensate for the fact that there is no additional ray generation due to splitting during the raytrace.
You will see that in the resulting color image analysis, the distribution seems poorly sampled even with the 10x increase in the ray counts. This is a consequence of the fact that the optical surfaces have a quarter wave AR coating applied. From a monte-carlo perspective, this means that only ~2 out of every 100 rays incident on the optical surfaces will follow the reflection event from a single surface. Forming double reflection ghosts in a refractive system with AR coatings is a very inefficient process in monte-carlo mode! This can be tested by making the coating of the optical surfaces "Uncoated" and then repeating the GPU raytrace and color image analysis. Because the surface reflectance of the bare substrate will generally be higher than the quarter wave AR coating, the statistics of the color image distribution will converge with fewer rays than in the AR coated case.
Raytrace Paths FRED can also keep track of the raypaths during a GPU raytrace when the model is set to run in Monte-Carlo mode.
This is done in a similar way to the CPU raytrace, via the MPC Advanced Raytrace dialog. This dialog can be accessed using the toolbar button shown below or by choosing the corresponding option from the MPC menu.
The MPC Advanced Raytrace window allows various options related to the GPU raytrace such as switching from single to double precision, or temporarily forcing the raytrace to be in Monte Carlo mode.
When selecting to record the ray paths, a user-supplied maximum total event count for path tracking must be supplied to the GPU prior to raytracing. This is necessary for determining how much memory to allocate on the GPU board.
Only paths with total event counts less than or equal to this user-supplied value will be available for review in the Raytrace Paths table or Stray Light Report at the conclusion of a GPU raytrace.
Select the option to Record ray paths, set 40 as the maximum number of events, make sure that Raytrace Action is “Create rays on the GPU” (i.e. Trace GPU Rays mode) and then click OK.
After the raytrace, opening up the Stray Light Report (Tools / Reports…) allows the user to browse the ray paths in this system. Selecting Specular paths of level 2, show all the ghost paths that arrive at the Image Plane, and power values for each.
As per usual, you are able to right-click on the path of interest and print the Output Path Details, or add this path to the User Defined Paths list for a sequential raytrace.
However, note that after a GPU raytrace there is currently no support for redrawing raytrace paths on the CPU, nor is there support for performing path-based analyses with rays (ex. analyzing the irradiance distribution for path #X or using the image artifact diagnostic "lasso" tool in a chart window).
|