Looping Over Raypaths
FRED has many tools for helping the optical engineer determine the contribution and causes of stray light in an optical system, including the Image Artifact Diagnostic Tool and the Stray Light Report.
The Stray Light Report provides a detailed report of system scatter and ghost paths, including number of rays in path, percentage of reference power, ray path power and scatter / ghost surfaces. However, the FRED user might need to expand this functionality and automate diagnostics.
This example script shows how to loop through the list of raypaths, check if they end up on the designated detector surface and if so calculate the Irradiance and return the peak power value. This will provide the FRED user with information about which paths cause localized "hot spots" – information that can’t be specifically obtained by looking at the total power value for that path.
The script is a stand‐alone script that is hopefully quite self explanatory; however there are some key points that are worth discussing.
First it should be noted that the user needs to define the "detector" surface and the associated Analysis Surface. This can easily be done by right‐clicking on the surface in the Tree, and selecting Copy Find‐Name Command to Clipboard, then pasting into line 43 of the script. Similarly for the Analysis Surface (line 44).
The script has two distinct parts. First it sets up and performs an Advanced Raytrace telling FRED to store information regarding each unique raypath and the ray histories.
'********************************** 'Setup and run an Advanced Raytrace '********************************** Dim adv As T_ADVANCEDRAYTRACE, numTraced As Long InitAdvancedRaytrace adv 'loads default values (what you see when you open dialog) adv.rayPaths = True adv.rayHistory = True adv.draw = False numTraced = AdvancedRaytrace ( adv ) '********************************** 'End Advanced RayTrace '**********************************<br>
The InitAdvancedRaytrace subroutine is a convenient way to load the default values for the Advanced Raytrace. These default values are visible when you open the Advanced Raytrace dialog when operating the GUI.
In the second part of the script, after the raytrace, the script then loops through all of the paths, and for each path that ends on the detector, calculates the Irradiance and looks at the plot statistics to obtain and print the peak Irradiance value.
'loop through all paths... For i = 0 To PathCount ( ) - 1 numEvents = PathEventCount ( i ) '...if they end on the detector... If PathEventItemID ( i, numEvents - 1 ) = det Then '...change the Ray Selection Filter of the Analysis Surface to specific path success = GetAnalysisSurfIthOp ( ana, 0, op ) op.opCode = 22 'See T_RAYFILTEROP page in Help op.datum = i SetAnalysisSurfIthOp ana, 0, op '...calculate the Irradiance numTraced = IrradianceToARN(ana, "Path-"&i, arnNode) '...obtain and print the peak power value ARNCompute2DCellStatistics arnNode, cellStats EnableTextPrinting True Print i & Chr(9) & cellStats.MaxCellVal EnableTextPrinting False 'delete the ARN to save memory ARNDelete(arnNode) End If Next i<br>
The function PathCount() returns the number of raypaths, and provides an easy way to loop through each path. Then the function PathEventCount() is used to obtain the number of events (surface interactions) that occur on this raypath. Once this is known it is easy to determine the final surface of this path using PathEventItemID, allowing the FRED user to check if this is a path that ends up on the detector surface.
If that is the case, then the Ray Selection filter of the Analysis Surface is changed so it will calculate the Irradiance for only this specific path. Here the T_RAYFILTEROP structure is used. Details of the various opCodes available are shown in a table on the Help page for this structure. In this case opCode = 22 is equivalent to the “Rays on the specified ray path” criterion shown in the figure below.
Then the Irradiance is calculated using the IrradianceToARN function (and it's worth pointing out that if you only need to calculate individual Irradiance profiles for each path you can stop here).
Finally, the ARNCompute2DCellStatistics command is used to obtain the peak power value. The path numbers and the peak Irradiance values are outputted in separate columns in FRED’s Output Window.
Associated FRED Script File: Raypath Loop Script