Rotating Prisms by Scripting
Introduction
This knowledge base article will describe how to set up an embedded script that rotates two prisms, traces a source at each rotation position, and calculates and displays the sum total irradiance for all rotation positions. The number of rotation positions is controlled through a global script variable and the irradiance summation is calculated using Analysis Results Nodes (ARN).
Download the FRED file: rotatingElement.frd
System Layout
The system layout is shown in Figure 1 below, where we have a collimated plane wave source passing through two wedge prisms to a detector plane.
The wedged prisms will be rotated in opposite directions at equal rates. The path that the beam will trace throughout a 360orotation of the two prisms is shown in Figure 2.
Script Implementation
The pseudocode for the script is provided below:
- Retrieve relevant node numbers from the FRED document
- Create and zero two ARNs; one for the current trace and one for the accumulated results
- Loop over each rotation position for the prisms
- Modify the CW prism
- Modify the CCW prism
- Trace the source
- Calculate irradiance for (c) and accumulate sum total irradiance
- Write accumulated results to file and display the plot
- Modify the prism rotation positions back to zero
The specifics for each step in the pseudocode above are the following:
An easy way to set up retrieval of the node numbers is to right mouse click on the node of interest in the object tree of the FRED document and choose “Copy Find-Name Command to Clipboard”.
Then, in the script editor window you can paste (Ctrl + V) the command directly. For the CW prism this would paste the line “FindFullName( "Geometry.Prisms.CW Wedge Prism" )”
- We are going to use two ARNs to track the irradiance results for the current raytrace and the accumulated irradiance for the entire prism rotation. To setup two empty ARN we first delete any rays that exist in the document and issue two IrradianceToARN function calls, one for the current raytrace ARN (“SingleArn”) and one for the sum total ARN (“SumArn”).
- The number of positions to trace is specified by the global script variable “numPos”. This variable should not be dimensioned within the script itself. Rather, it is defined in the global script variables dialog (Menu > Tools > Edit/View Global Script Variables). The increment for the prism rotations is defined to be 360/numPos and this value will simply be added to the existing prism Z-axis rotation value as defined below.
Updating the prism rotation value is achieved by use of the T_OPERATION structure, which allows us to access the position orientation operations of a given node number. The CW Prism has the following position/orientation operations
The script code that accesses the Z-angle (deg) position/orientation value is shown below. In this case, the operation # is 1 and Z-angle is given by T_OPERATION structure member op.val1.
As shown in the code, the procedure is to GetOperation in order to populate the members of the T_OPERATION structure “op”, modify the structure member op.val1 which controls the Z-angle, and then SetOperation back to the cwPrism node to implement the changed value.
The procedure for the CCW prism is the same as (a) but the position/orientation operation number is different, as shown below.
- Tracing the rays for the current orientation of the prisms is performed using the TraceCreateDraw command. Drawing the rays is not necessary and will in fact be slower than tracing without drawing. The TraceCreate command can be issued and will not draw the rays to the screen.
- The command IrradianceToARN calculates the irradiance for the rays currently in the ray buffer using the supplied analysis node number (“anaNode”) and stores the results in the ARN “SingleArn”. To accumulate the total results, the command ARNLinearCombination is used to sum the results of “arnSum” and “arnSingle” and store the results in “arnSum”.
- The command ARNWriteToFile is used to write out the contents of the accumulated results ARN, “arnSum”, to an *.fgd file. Then, the command DisplayPlotFile is issued to display that file in FRED.
- Finally, the rotation of the prisms is set back to zero using the method described previously