CODEV Ch4
CODEV Ch4
CODEV Ch4
Search
Chapter 3
Make It Better: Optimization
In this chapter, you will learn how to optimize the digital camera lens that you set up
in the last chapter. This will include setting up variables, determining and defining
constraints, and analyzing the results of the optimization. Some advanced
optimization features will also be discussed, including Global Synthesis.
Contents
About Optimization
Search
Purpose
The purpose of optimization is to generate the best possible optical system that can
be achieved within a given set of physical and other constraints. The term “best” is
measured by an error function which combines image error data into a single
number that we then attempt to make as small as possible. CODE V’s error function
is pre-defined in its basic structure, although a variety of controls and weights are
available that allow you to modify it easily and extensively. It is even possible to
replace this error function with a completely user-defined error function, although
this is somewhat more difficult and is seldom actually necessary.
Methods
CODE V’s optimization feature is called Automatic Design, AUTO for short.
AUTO uses an accelerated damped least squares (DLS) algorithm to generate
changes in variables that improve the system. Constraints place boundaries on the
search for optimum solutions. AUTO uses Lagrangian multipliers to impose
constraints only when needed. This allows exact constraint control while not
requiring constraints to be included in the error function itself, usually resulting in
faster, smoother convergence to an optimum solution within the constrained
solution region.
Defaults
The default values built into AUTO allow you to use AUTO with little or no
attention to the details of error function construction and with minimal input
requests. At the same time, the many optional controls, weights, constraints, etc.,
allow you great flexibility when needed for unusual designs or fine tuning in later
design stages.
Define Lens
Designer Tasks
Define Variables
Define Constraints
Evaluate Design
• Print each cycle for user feedback
• Exit if time/cycle limit exceeded ,
if improvement has stalled,
or if user requests exit
No
Good Enough?
Yes
Stop
• Constrain the effective focal length (EFL) to the current 6 mm value (Specific
Constraints tab).
Search
• Draw the lens on each optimization cycle (Output Controls tab).
• Use the default spot size (transverse ray aberration) error function, but trace
more rays in the grid (Error Function Definitions and Controls tab).
• Analyze the lens by re-running earlier evaluations (one click updates on
windows from the last chapter, mainly the VIEW, MTF, and FIELD options).
• Modify AUTO settings to refine the solution (Error Function Weights tab).
Now on to the details!
Variables
Search
Defining Variables
You need to tell CODE V which lens parameters are free to vary when it tries to
optimize your lens. These variables are defined in the LDM and are stored with the
lens data when you save the lens in a file. Deciding what to vary is not always a
simple task, but in centered systems, it is typical to vary all glass surface curvatures
(but not the image surface curvature, since you usually want a flat film or detector
surface), all air spaces, and the thickness values of positive glass elements (to allow
the program to keep good lens edges without restricting curvatures too much).
Glass is often varied also (index and dispersion). This requires using a special
variable “fictitious glass” form in CODE V, since catalog glasses have fixed
properties and thus cannot be directly varied.
Search
4. Repeat this procedure for the thickness values (select and vary thickness for
surface 1 to surface 5 as a range, then select the image surface thickness and
vary it separately; do not include surface 6, as this will remove the PIM solve
from this surface).
The LDM spreadsheet window with all variables is shown on page 51, following
the discussion of fictitious glass.
Fictitious Glass
Varying glass involves additional considerations and possible extra steps, since
both the index and dispersion properties of a glass can vary. To be used as a
variable in AUTO, a material must be defined as a fictitious glass. If a catalog glass
is selected as a variable, it is automatically converted to its equivalent fictitious
glass (in a final design, the optimized fictitious glasses need to be replaced with
their nearest real equivalents by the user, often with the help of the supplied
glassfit.seq macro). Fictitious glasses have a special form. For a glass of refractive
index (at 587.6 nm, or “d” light) of 1.620 and an Abbe value (i.e., reciprocal
dispersion), or V-value of 60.3, the fictitious glass name is 620.603 (the period tells
the program this is a fictitious glass). An alternate form, 1.620:60.3, is also
accepted by CODE V, and allows the entry of glasses with n > 2.0 and v > 100.
In the case of the digital camera lens, the patent that it is based on already includes
fictitious glasses, although they are frozen. You should also note that all three
glasses have very high index of refraction values (1.7 to 1.8), which generally
indicates an expensive glass. You will need to vary glass but constrain its index in
AUTO (this will be done in the next section).
1. To vary the glass for surface 1, right click on the glass name in the LDM
window and choose Vary from the shortcut menu.
Search
The v will display next to the glass name, indicating that it is a variable. For a
polychromatic (multi-wavelength) system, we normally vary both index and
dispersion, and this is the default. But there are other possibilities for glass.
2. Left-click on the v for the glass on surface 1 (or right-click and choose Couple).
This displays the Coupling Editor dialog box. Coupling is one way to link
together variables, but in the case of variable glass, it also gives access to the
index and dispersion variables.
3. Double-click the Index and Dispersion cell for surface 1.
You can vary the index and dispersion separately or together. Since this is a
polychromatic lens, varying both Index and Dispersion is OK. Dispersion
Boundaries are the boundaries of the glass map polygon which limits the range
of allowed glass types. This will be discussed in the next section under General
Constraints.
4. Click Cancel.
5. Right-click and choose Vary from the shortcut menu for the glass for surfaces 3
and 5.
Search
When you are through, the LDM window should look like this:
6. Choose the File > Save Lens menu to save a new version of the lens file with
the variable definitions.
Note: Do not click the OK button in the Automatic Design dialog box until you
reach the end of this section.
You will be changing settings on several tabs before you click OK to run AUTO. If
you click OK by mistake, don’t panic: choose the Edit > Undo menu to get the
starting lens back and click the Settings button in the AUTO output window to
resume.
AUTO is a very powerful feature with many categories of settings divided among
ten tabs in the input dialog box.
Most of the settings determine parameters such as weights, or flags for special
behaviors, such as drawing the lens on each optimization cycle. Two categories of
settings define boundary conditions or constraints.
The first of these boundary condition categories is called General Constraints.
These are general boundary conditions that control thickness values and glass map
boundaries to help protect you from unrealistic designs. Thickness constraints
prevent such problems as negative edge thickness, or lens elements that overlap.
Glass boundaries keep the program from choosing physically unrealistic index and
dispersion values. General constraints are always in place, applying limits for all
surfaces in all zoom positions. You can set the values for these limits, and override
selected general constraints with specific constraints on a per-surface basis.
The second boundary condition category is called Specific Constraints. Specific
constraints are applied only when entered by the user. Many constraints are surface
based, referring to a physical or optical property. Other constraints apply to the
whole system or to a range of surfaces. Specific constraints allow you to define
your requirements in great detail, though you must be careful not to over-constrain
the system, since this can limit the improvement potential.
General Constraints
Search
General Thickness Constraints
For this small lens, you must be sure that the elements are thick enough to be
handled and worked easily. According to fabrication specialists, the values
suggested here are reasonable, though it's possible to go as thin as 0.5 mm for
elements of this size. This is best handled by the general thickness constraints. In
addition, we noted in the last section that the glasses in this patent are all high-index
glasses. Glass map boundary constraints can be used to limit the optimized glasses
to a lower index, lower cost region of the glass map. Assuming you have already
opened the AUTO dialog box (as described on page 52):
1. Click the General Constraints tab.
2. Enter 1.4 in the Maximum Center Thickness field.
3. Enter 0.9 in the Minimum Center Thickness field.
4. Enter 0.8 in the Minimum Edge Thickness field.
Search
The glass map constraint polygon can actually have 3 to 5 sides, labeled A through
E (it must be a convex polygon; see the CODE V Reference Manual for more
details). It appears that SF2 defines a convenient point for a three-sided glass region
that keeps the maximum index below 1.65 (the hope is that this will result in
cheaper glasses after optimization). Note that the glass map boundary changes will
apply to all surfaces by default, though you can define a separate glass map for each
surface if necessary.
1. On the General Constraints tab in the AUTO dialog box, click on the glass
SF4 in the cell Map4 of the Glass Map Boundary spreadsheet at the bottom of
the dialog box and press the Delete key (or CTRL-X) to remove the fourth
boundary.
2. Click in the cell Map3 and type SF2 to define the new corner point for the
triangle region.
Search
Specific Constraints
There are many things you can constrain when needed to define the boundary
conditions of the optimization. These include many physical and optical properties
(overall length, focal length, distortion, real ray properties, paraxial ray properties,
etc.). Constraints can be entered in several ways, including equality (hold to a
value), upper and/or lower bounds, and minimize (don't directly constrain, but
minimize difference from target value). You can also designate constraints as
display only (these are calculated and displayed on each cycle but not controlled in
any way). Constraints and constraint modes are discussed in detail in Chapter 18,
Automatic Design in CODE V of the CODE V Reference Manual.
In most lenses, at least one specific constraint is required to hold the scale of the
system. This could be a paraxial or real ray height at the image surface, a paraxial
slope, or a real-ray direction cosine value. But most often, it is the paraxial effective
focal length of the system (EFL), which you will use here.
1. In the Automatic Design dialog box, click the Specific Constraints tab.
The table starts out empty (no specific constraints are defined by default).
2. Click the Insert Specific Constraint button, which is near the bottom of the
dialog box.
Search
The Edit Constraint dialog box is displayed, with Effective Focal Length as
the default constraint (since this is the most common case). You could actually
just click OK in this case, but first note that you can choose from several catego-
ries from the list at the top left, and that for each category, there is a separate list
of constraints at the top right. Effective Focal Length is the first of the Optical
Definitions.
3. Click in the Constraint Target field and enter 10.0 (note that this is the
WRONG value; however, this is just a demonstration, since 6 is the value you
want).
4. Click the Calculate Default Target button.
Note that the value of 6 is back. This button evaluates the current value of the
constraint as a convenience. You don't have to keep it, but it's correct for this
case.
Search Tip: When entering a constraint, be sure to click in a data field after choosing
the constraint, to allow the program to display the data required by the constraint
type. If it is a surface-based or field-based constraint, be sure to select the
desired surface or field (and zoom position if it is a zoomed system). The
Calculate Default Target button will show the current value to help you
determine a good target.
Output Controls
For lenses with many surfaces, you might wish to restrict the amount of surface-
based output that appears. You might also wish to see a table of variables. In this
case, you can accept the defaults for these things, but it will be helpful to see a
picture of the lens on each optimization cycle. You are still modifying the AUTO
settings (almost done!).
1. In the Automatic Design dialog box, click the Output Controls tab.
2. Check the box labeled Draw system at each cycle.
Search
This will result in a separate tab in the AUTO output window for each cycle,
labeled with the error function.
and is listed under Sample Macros/ Optimization) for looking at the ray pattern
for specified DEL values. For the value of DEL chosen for this optimization, 0.22,
Search the pattern is as shown in the figure below. (Note that you cannot run this or any
macro while the AUTO dialog box or any other option dialog box is open.)
The transverse ray aberrations in X and Y are calculated on the image surface for
each of these many rays, and the weighted sum of the squares of these aberrations
determines the error function at each optimization cycle. The weights in this
summation are important controls in optimization. Weights are defined for aperture
position, wavelength, and field (X and Y components). For a more detailed
treatment of the error function and other mathematical aspects of optimization, see
“Technical Notes” on page 18-41 in the CODE V Reference Manual.
The header starts by displaying the commands generated by your settings (EFL,
DEL, etc.). It then lists potentially active specific constraints, in this case only EFL.
“Potentially active” means that AUTO will dynamically determine if a constraint is
needed at any given cycle, freeing as many variables as possible to control image
errors. General constraints are listed next; the commands are not too hard to
interpret (MNE is minimum edge thickness, MNT is minimum center thickness,
etc.).
Search Tip: To see the commands for a category of inputs, click the tab of interest in the
Automatic Design dialog box (e.g., General Constraints) and press the F1 key.
This displays the help page that describes the inputs, including their CODE V
command names.
Error Function Construction shows you the weights on the various components,
as well as the DEL value used in the ray trace grid. Convergence Controls
displays the exit conditions (MXC is maximum cycles, MNC is minimum cycles,
TAR is error function target, and IMP is the target per-cycle fractional
improvement). Output Controls includes only the lens drawing command in this
case (DRA). This is followed by the number of variables, 18 in this case (6 radii, 6
thickness values, and 6 glass variables, the index and dispersion for each of 3
glasses).
Tip: You can get a list of the variables by clicking the Print Cycle Value button
in the Variable Table area on the Output Controls tab of the AUTO dialog box.
Finally, the header text tells you that 18 constraints can be active, thanks to the 18
variables. This is an upper limit! In fact, you hope for a small number of active
constraints so most “degrees of freedom” (i.e., variables) can be applied to
improving the image quality.
Search
Note: The above output is for illustrative purposes only; your output may be
slightly different.
Starting and ending each cycle is the error function value, labeled ERR. F. This is
followed by its X and Y components from each field, allowing you to see which
fields and components are contributing most to the error function, though the total
error function value also includes weighting factors (e.g., a large X component at
field 4 may not contribute much if the WTX F4 field weight value is small). The
surface data is listed next, followed by the basic first system properties (EFL,
REDU or reduction ratio, PIM or paraxial image distance, OAL or overall length,
EN/EX PUP or entrance/exit pupil distances).
Finally there is a table of Active Constraints (10 on this particular cycle). EFL is
listed first, with its target value, current value, and difference between these. Given
that this is the only specific constraint, what are all the other constraints? They are
general constraints that AUTO has determined will require control at this particular
cycle. GL A S1 is a glass map boundary constraint (recall the glass polygon
boundaries labeled A, B, C, in this case). Mn ET S1 is a minimum edge thickness
constraint at surface 1.
Constraint Costs
The program dynamically determines the constraints it needs to control at every
Search
cycle, based on their Lagrange multiplier values, which are listed in the cost
column. Why is this called a “cost?” When a boundary condition is controlled, the
program is restricted from going to a solution-space point (set of variable values)
where the error function could get lower. This restriction from the optimum point
“costs” you something in terms of the error function that can be achieved (if it
could be released, the error function could be smaller).
Some constraints are harder to control than others, and these have larger magnitude
costs. Although you can't directly compare costs for different types of constraints,
larger values hurt more than smaller values, and if you see very large values (any
positive exponent, e.g., 1E+02), this constraint is causing a big problem. You may
need to remove it, or provide another variable that can allow it to be met more
easily.
The values and signs of the Lagrange multipliers are used along with other program
data to determine which constraints to control on each cycle. The remaining
variables (18 - 10, or 8 on this cycle) are available to try to improve the image
quality.
This plot shows that the MTF is good for most fields and azimuths (T,R for
tangential and radial, which correspond to Y and X), but a couple of the radial
(X, dashed) component curves are low. You can relate this to the AUTO output as
well. Click the Text tab of the AUTO output window and scroll to the bottom.
Note that the largest error function components are the X values for F3 and F4, plus
the Y component for F3. These correspond to the lowest MTF curves. Since the
Search problem is related to particular fields and X components, you can modify the
AUTO settings to increase the weight on some of these during optimization.
1. Click the Modify Settings button of the AUTO output window.
2. Click the Error Function Weights tab in the AUTO dialog box.
The default field weights come from the LDM data, which are all 1.0 as you can
see in the Fields/Vignetting page of the System Data window (Lens > System
Data menu). You can try to increase the X component weights for field F3 and
F4, using 1.2, for example.
3. Click in the first row of the spreadsheet labeled X-Aberration weights only,
then double-click the first cell and choose field 3 (F3).
4. Enter 1.2 in the Value field for this row.
5. Click the blank row and repeat the above procedure for field 4 (F4).
7. Click the Execute button in the MTF window to re-run the analysis.
Search
Now the radial (dotted) curves are higher, but the T curve for F3 is even lower and
will require more weight. You can quickly experiment with different field weights
in X and Y, even lowering the weights for the axis (F1) and 0.4 (F2) fields, which
have higher MTF than you need. Although you could switch to MTF optimization
at this point, defining the targets for the MTF error function will probably take
longer than interactively changing weights, re-running AUTO, and re-running
MTF.
As an aside, MTF is also convenient in another way, in that it reports both relative
illumination and distortion for each field (in the Text output). This allows you to
keep an eye on these specs as you tweak the MTF.
You may not get exactly the same solution, depending on the weights applied and
the starting point, but your solution should have a similar performance. You should
set a new title and save the lens file (by choosing the File > Save Lens As menu)
when you get a good solution.
The following figure shows the basic Quick 2D lens drawing, MTF, and LDM
surface data of the final glass lens.
Search
To get other final analysis results, click the Execute/Recalculate button on each
analysis window used in earlier analysis (or run them again if you have closed
them). For this solution, we get:
• MTF meeting the spec at 17 and close to meeting the 51 lp/mm spec at 68 lp/
mm as well, giving some performance margin.
• Distortion -1.7% at worst from Field Curves (Analysis > Diagnostics menu).
• Relative illumination 67.3% at full field (from MTF option). Transmission
Analysis (Analysis > System menu, or TRA option) is more accurate and gives
63.2% for field F4, still above the 60% spec.
• The same TRA option reports average transmission of 88.2% at full field,
although this is with the CODE V default of a single layer anti-reflection
coating (1/4 wave MgF2) on each surface, which was not specified. If all
coatings are removed (Lens > Surface Properties menu, Cement/Coating
page, click None for coating on each surface), the transmission drops to 66%.
Some coating will probably be applied, but you should always check on details
such as this in any lens specification.
Actually, there is more to be done on this lens before it could be built.
Lens or section of lens is Manufacturing & Packaging, OAL S3..9 < 21.5
too long Overall Length (surface range)
I can’t find a constraint User Defined Constraints allow See online Help and/
that does what I want to do you to define many conditions or CODE V Reference
using macros and program data. Manual.
See User Constraints tab and
Help for more details.
Search