### Afocal Optimization

The attached FRED example demonstrates how to optimize the inter-lens spacing of a Galilean beam reducer using geometric ray collimation as the optimization metric.

1. Open the model and expand out the Geometry folder and the Collimator subassembly node.  Observe that there are three geometry elements defined; a Positive Lens element with a focal length of 100 mm, a Negative Lens element with a focal length of -36 mm and an absorbing detector plane.
2. Double click on the Negative Lens node to open its dialog.  Note that the lens is located 64 mm away from the rear vertex of the positive lens.  Close the dialog.
3. Perform a raytrace (drawing the rays).  It should be apparent just by looking at the 3D viewer that the spacing between the lenses is not optimal for collimation.  The goal will be to use FRED’s optimizer to configure the appropriate lens spacing by varying the position of the Negative Lens position.
4. Navigate to Analyses > Directional Spot Diagram.  Summary information about the calculation will be printed to the output window, including the X,Y “Max” values (which are direction-cosines).  The Max values indicate the encircled direction spread of the ray bundle in direction-cosine space.  The value should be ~0.054133 for both X and Y.
5. Navigate to Optimize > Evaluate Once, which takes the model’s current state and evaluates the merit function that is defined in the optimizer (we’ll get to that in a step or two).  In the output window, you should see a report of the merit function value and each of the individual merit function aberrations (we only have one in this example).  FRED’s merit function is computed as the sum of the squares of the individual aberrations and so the reported value should be 0.054133*0.054133 = 0.00293.
6. Navigate to Optimize > Define/Edit:
1. There is one variable defined on the Variables tab.  This variable is the Position/Orientation parameter of the Negative Lens element that defines the position of the lens relative to the rear vertex of the positive element (see Step 2 above).  We are allowing this variable to range from 58 to 68 mm.  Please refer to the Optimization Help for specific information regarding the usage of Index and Subindex values for different variable types.
2. There is one aberration definition on the Merit Function Aberrations tab.  In this example we are using the “Encircled direction spread” option as the aberration definition and, since we only have one variable, the merit function is the square of the encircled direction spread.  In Step 4 above we described how to find the equivalent value from FRED’s Direction Spot Diagram analysis.
3. On the Method tab, the “Single variable minimization” option is used as the optimization mode and the “Negative Lens Z-Position” variable is being used.  The Stopping/Convergence Criteria is set to be when all variables change by less than 0.001 between optimization iterations.
7. Now that you have walked through the configuration of the optimization, its time to optimize!  Navigate to Optimize > Optimize.  During optimization, FRED will print information to the output window at various stages.  How much information is reported will be determined by the settings found on the Output/Results tab of the optimization define/edit dialog.  For this simple system, the convergence should be achieved in a relatively few number of cycles (<20) and settle on an inter-lens spacing of ~59.6 mm.
8. Perform a raytrace (drawing the rays)  to confirm visually that the output ray bundle appears collimated.
9. Navigate to Analyses > Directional Spot Diagram, as we did previously in Step 4, to confirm that the encircled direction spread has been reduced by an order of magnitude.
10. If you return to the Optimize > Define/Edit dialog and move to the Output/Results tab, you will see that FRED has stored the result of the last N optimizations (one optimization result per row in the dialog).  You can right mouse click on any row and choose the “Apply to Document” option to re-configure the model for a given optimization result.  This may be useful if you have run multiple optimizations under different settings and are trying to evaluate the performance of each.