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.

Figure 1 - Wedged prism system layout

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.

Figure 2 - Beam path during a full rotation

Script Implementation

The pseudocode for the script is provided below:

  1. Retrieve relevant node numbers from the FRED document
  2. Create and zero two ARNs; one for the current trace and one for the accumulated results
  3. Loop over each rotation position for the prisms
    1. Modify the CW prism
    2. Modify the CCW prism
    3. Trace the source
    4. Calculate irradiance for (c) and accumulate sum total irradiance
  4. Write accumulated results to file and display the plot
  5. Modify the prism rotation positions back to zero

The specifics for each step in the pseudocode above are the following:

  1. 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" )”

  2. 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”).
  3. 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.
    1. 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.

    2. The procedure for the CCW prism is the same as (a) but the position/orientation operation number is different, as shown below.


    3. 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.
    4. 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”.
  4. 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.
  5. Finally, the rotation of the prisms is set back to zero using the method described previously

Still need help? Contact Us Contact Us