Navigation: Optimize Commands > Define/Edit > Variables

 

Variables

 

Contact Us: fredsupport@photonengr.com

 

 

 

Description


Optimization variables specify which quantities in the system are allowed to vary during the optimization procedure.  At least one variable must be selected for the optimization to proceed (1-D optimization), though there is not an upper-limit on the number of variables that can be defined.  Caution must be observed however, as the length of the optimization increases with an increasing number of variables.  In general, any system parameter can be defined as a variable through the use of the scripting language.  To make optimization setup simpler, some common default variables are provided as list items in the variable definition dialog.

 

 

Navigation


This feature can be accessed by selecting Optimization > Define/Edit: Variables from the menu.

 

 

Controls


Control

Inputs / Description

Defaults

Variable Spreadsheet

Index column

Zero based index reference for each variable definition.  This index is referenced both in the scripting language and for defining fractional variables.

0

Active

The variable is active when toggled.

Checked

Description

Text description of the variable.

 

Entity

Indicates which object in the model is being modified.

 

Type

Indicates the specific parameter of Entity being modified or designates a user-defined script which will set and retrieve the parameter.  The following variable types are available:

Position/Orientation parameter

Curvature

Conic constant

Aspheric even power coefficient

X, Y, Z component of a NURB control point

Weight of a NURB control point

Bending parameter of a lens element

Power of a lens element

Thickness of a lens element

User defined script

User defined script (extra parameters)

Min/Max X,Y,Z trimming volume coordinate

Parameter value of an element primitive (value is the intrinsic property of the primitive.  See Element Primitive help topic for specific information.)

Source power

Coefficients, positions, widths and rotation angles for component super-gaussians in an SGS surface.

 

Index#

For variable types which can contain multiple rows in a spreadsheet style list (ex. position/orientation or NURB control points), the Index# specifies which row contains the variable.

 

Use a value of -1 if there are no index values associated with this parameter.

-1

Subindex#

Variables defined using an Index# scheme can also contain a Subindex# specification which points to a specific component of the entity.  In this convention, the Index# can be thought of as the row of a spreadsheet and the Subindex# as the column.  As an example, consider a position orientation specification list (spreadsheet format).  Each row in the position/orientation list is a single operation and a particular operation would be called out in the variable definition by its Index#.  Within each position/orientation operation there are one or more columns that define the operation values (ex. Rotate about X, Shift Y, etc.).  Each column would be called out in the variable definition by its Subindex#.

 

Use a value of -1 if there are no subindex values associated with this parameter.

-1

Fraction Var#

This entry is the index of an existing variable and indicates that the variable in this row has its limits, initial value and current value interpreted as a fraction of the indexed variable value.

 

For example, if variable 0 were the front curvature of a lens and variable 1 were the back curvature, this feature could be used to force the back curvature to be remain some fraction of the front curvature.  In this case, 0 would be the Fraction Var# entry for variable 1.

not fraction

Value

Current Value for the variable. This value can be entered manually or retrieved from the document by right mouse clicking in the Value cell and selecting the appropriate option from the list menu.  The following list menu options are available

Get Starting Value(s) From Doc

Apply Starting Value(s) To Doc

Apply Previous Start Value(s) To Doc

The list menu options apply to all rows currently selected in the Variables dialog.

0

Previous Value

Indicates the variable value at the beginning of the previous optimization.  FRED retrieves and displays this value after an optimization cycle is completed.

0

Lower Limit

Smallest value the variable can acquire during optimization (subject to limit enforcements).

0

Upper Limit

Largest value the variable can acquire during optimization (subject to limit enforcements).

0

Frac Step

Sets the initial step size of the variable search as a fraction of the upper and lower limit widths.  For example, 0.1 indicates an initial step size 10% of the limit width.  The initial step is centered on the current variable value.  Initial steps which take the variable value outside of the variable range be truncated to the closest endpoint value of the range.

0.1

Variable Limits Enforcement During Optimization

Option 1: Hard Limits (strictly enforce)

This option prevents the variables from taking values outside of the designated minimum and maximum limits.

 

Option2: Soft Limits (apply penalty)

Variables are allowed to take values outside of the designated minimum and maximum limits but a base penalty value (1020 plus an additional term that is linear with distance from the closest variable limits endpoint) is applied to the merit function in order to influence the variable values to move back into the designated range.

Hard Limits

 

 

Variables, Index and Subindex Examples


The following information details the Index and Subindex conventions for various variable and object types.

 

 

Index Specification

Subindex Specification

Position/Orientation parameter

Index (0-based) corresponds to a given row in the position/orientation dialog.  The index value is shown in the GUI on the left-most column of the position/orientation stack.

An individual parameter of the operation designated by Index.  Subindex values are 0-based.

 

 

 

Example:

The Y component of the Shift operation below can be accessed by designating Index=2, Subindex=1.

The X-angle of the Rotate about X-axis operation can be accessed by designating Index=1, Subindex=0.

 

 

 

Standard Asphere

Index Specification

Subindex Specification

Curvature

Not Applicable.  Set value to -1.

Not Applicable.  Set value to -1.

Conic constant

Not Applicable.  Set value to -1.

Not Applicable.  Set value to -1.

Aspheric Even Power Coefficient

Index (0-based) given by n/2, where n is the order of the aspheric term being accessed.

Not Applicable.  Set value to -1.

 

 

 

Example:

The r4 coefficient can be accessed by setting Index = 2

The r8 coefficient can be accessed by setting Index = 4

 

 

 

General Asphere

Index Specification

Subindex Specification

Curvature

Not Applicable.  Set value to -1.

Not Applicable.  Set value to -1.

Conic constant

Not Applicable.  Set value to -1.

Not Applicable.  Set value to -1.

Aspheric Even Power Coefficient

Index (0-based) given by n/2, where n is the order of the aspheric term being accessed.

Not Applicable.  Set value to -1.

 

Example:

The r4 coefficient can be accessed by setting Index = 2.

 

Odd order coefficients

(accessed via user-defined script variable)

Not Applicable.  Set value to -1.

Not Applicable.  Set value to -1.

 

Example:

The r5 coefficient can be accessed by using the user-defined script variable shown below.  The convention for idx in the script functions SetAsphereOddCoef() and GetAsphereOddCoef() is idx = (n-1)/2, where n is the order of the odd aspheric coefficient being accessed.

 

 

'Example: 5th order coefficient of General Asphere

Sub EvalMzrVar( ByVal g_entity&, ByVal g_setvar As Boolean, ByRef g_var#, ByRef g_success As Boolean )

 

g_success = False

 

Dim idx As Long

idx = 2

 

If g_setvar Then

    SetAsphereOddCoef( g_entity, idx, g_var )

Else

    g_var = GetAsphereOddCoef( g_entity, idx )

End If

 

g_success = True

 

End Sub

 

 

 

Polynomial Asphere

Index Specification

Subindex Specification

Curvature

Not Applicable.  Set value to -1.

Not Applicable.  Set value to -1.

Conic constant

Not Applicable.  Set value to -1.

Not Applicable.  Set value to -1.

Aspheric Even Power Coefficient

Index (0-based) matches the value shown in the Term column of the GUI.

Not Applicable.  Set value to -1.

 

 

Example:

The y2 coefficient can be accessed by setting index = 5.

 

 

 

XY Toroidal Asphere

Index Specification

Subindex Specification

X Curvature

Index = 1

Not Applicable.  Set value to -1.

Y Curvature

Index = 0

Not Applicable.  Set value to -1.

Conic constant

Not Applicable.  Set value to -1.

Not Applicable.  Set value to -1.

Aspheric Even Power Coefficient

Index (0-based) matches the value shown in the Term column of the GUI.

Not Applicable.  Set value to -1.

 

Example:

The A2 coefficient can be accessed by using the Aspheric Even Power Coefficient variable type and setting Index=2.

The A3 coefficient can be accessed by using the Aspheric Even Power Coefficient variable type and setting Index=3.

 

 

 

Toroidal Asphere

Index Specification

Subindex Specification

X Curvature

Index = 1

Not Applicable.  Set value to -1.

Y Curvature

Index = 0

Not Applicable.  Set value to -1.

X Conic constant

Index = 1

Not Applicable.  Set value to -1.

Y Conic constant

Index = 0

Not Applicable.  Set value to -1.

Aspheric Even Power Coefficient

Index = 0 for Ai coefficients

Index = 1 for Bi coefficients

Subindex matches the value shown in the Term column of the GUI.

 

Example:

The X radius can be accessed by using the Curvature variable and setting Index = 1.

The Y conic can be accessed by using the Conic constant variable and setting Index = 0.

The A4 coefficient can be accessed by using the Aspheric Even Power Coefficient variable type and setting Index = 0, Subindex = 4.

The B7 coefficient can be accessed by using the Aspheric Even Power Coefficient variable type and setting Index = 1, Subindex = 7.

 

 

 

Polynomial Surface

Index Specification

Subindex Specification

Polynomial coefficients accessed using variable type "Aspheric Even Power Coefficient"

Index matches the value shown in the Term column of the GUI.

Not Applicable.  Set value to -1.

 

Example:

The Z coefficient can be accessed by using the Aspheric Even Power Coefficient variable type and setting Index = 3.

The X^2 coefficient can be accessed by using the Aspheric Even Power Coefficient variable type and setting Index = 4.

 

 

 

Zernike Surface

Index Specification

Subindex Specification

Curvature

Not Applicable.  Set value to -1.

Not Applicable.  Set value to -1.

Conic constant

Not Applicable.  Set value to -1.

Not Applicable.  Set value to -1.

Aspheric Even Power Coefficient

Index matches the n value in "Asph n" label as shown in the GUI.

Not Applicable.  Set value to -1.

Zernike Coefficients can be accessed using the "User-defined script (extra parameters)" variable type as shown below

Index = n-1, where n is the Zernike coefficient desired to be accessed.

Not Applicable.  Set value to -1.

 

Example:

The Asph 5 coefficient can be retrieved by using the Aspheric Even Power Coefficient variable type and setting Index = 5.

 

 

'Example: Zernike terms

Sub EvalMzrVarEx( ByVal g_entity&, ByVal g_index&, ByVal g_subindex&, ByVal g_lowerlim#, ByVal g_upperlim#, ByVal g_setvar As Boolean, ByRef g_var#, ByRef g_success As Boolean )

g_success = False

 

'Use g_index as the index value into the Zernike coefficients array

'Index convention is N-1, where N is the term you want to access

'Ex. Accessing Z5 would use Index=4.

If g_setvar Then

    SetZernikeSurfIthCoef( g_entity, g_index, g_var )

Else

    g_var = GetZernikeSurfIthCoef( g_entity, g_index )

End If

 

g_success = True

 

End Sub

 

NURB Curve

Index Specification

Subindex Specification

X/Y/Z Component of a NURB control point

0-based indexing into each row of the control points list.  Index value matches the value shown in the Terms column of the GUI.

Not Applicable.  Set value to -1.

Weight of a NURB control point

0-based indexing into each row of the control points list.  Index value matches the value shown in the Terms column of the GUI.

Not Applicable.  Set value to -1.

 

Example:

The Y value of the second control point can be accessed by using the Y Component of a NURB control point variable type and setting Index=1.

The weight of the third control point can be accessed using the Weight of a NURB control point variable type and setting Index=2.

 

 

 

NURB Surface

Index Specification

Subindex Specification

X/Y/Z Component of a NURB control point

0-based indexing into each row of the control points list.  Index value matches the value shown in the Terms column of the GUI.

Not Applicable.  Set value to -1.

Weight of a NURB control point

0-based indexing into each row of the control points list.  Index value matches the value shown in the Terms column of the GUI.

Not Applicable.  Set value to -1.

 

Example:

The X component of the fourth control point can be accessed using the X Component of a NURB control point variable type and setting Index = 3.

The weight of the second control point can be accessed using the Weight of a NURB control point variable type and setting Index = 1.

 

 

 

Element Primitive

Index Specification

Subindex Specification

Parameter value of an element primitive

0-based indexing into the parameter list, with the Index matching the numeric index value shown in the GUI.

Not Applicable.  Set value to -1.

 

Example:

The Length parameter of the element primitive below can be accessed using the Parameter value of an element primitive variable type and setting Index = 2.

 

 

Super-Gaussians Superposition Surface

Index Specification

Subindex Specification

SuperGaussian Coefficient

0-based indexing where the Index value matches the value listed in the Term column of the GUI.

Not Applicable.  Set value to -1.

SuperGaussian Position X/Y

0-based indexing where the Index value matches the value listed in the Term column of the GUI.

Not Applicable.  Set value to -1.

SuperGaussian Width X/Y

0-based indexing where the Index value matches the value listed in the Term column of the GUI.

Not Applicable.  Set value to -1.

SuperGaussian rotation angle

0-based indexing where the Index value matches the value listed in the Term column of the GUI.

Not Applicable.  Set value to -1.

 

Example:

The X0 position of Term 3 can be accessed using the SuperGaussian Position X variable type and setting Index=2.

 

 

 

 

Application Notes


User-defined Script Variables

The User-defined Script Variable allows virtually any parameter of the model to be used as a variable for optimization by allowing the user to write a script which will access the desired parameter. To invoke the User-defined script variable type, first set the Type to User-defined script and then right mouse click on that same cell and select "Edit User-defined script variable" from the list menu.

 

The user-defined script variable dialog contains a default header and example script (bending parameter of a lens element).  Two operations can occur on a variable during optimization; setting of the value or retrieving of the value.  Four variables are pre-defined in the script variable subroutine (EvalMzrVar):

g_entity: A Long containing the node number of the entity whose parameter is a variable.  Passed into the subroutine.

g_setvar: A Boolean indicating whether the value is being set in the document (True) or being retrieved from the document (False).  Passed into the subroutine.

g_var: A Variant containing the current value of the variable.  Passed into and out of the subroutine.

g_success: A Boolean indicating whether the variable operation succeeded or failed.  Passed out of the subroutine.

 

It is important to maintain the scaffolding of the If/Else logic in the script with regard to g_setvar to ensure that the variable can be properly retrieved or set to the entity as needed.  The basic scaffolding should be:

          '----------------------------------------------------------------------------

'  Function:  Sets or retrieves an optimization variable.

'Input vars:  g_entity: the specified entity id number.

'             g_setvar: True=apply g_var to the FRED document,

'                       False=retrieve g_var from the FRED document.

'In/Out var:     g_var: if g_setvar=True, apply the given g_var to the doc,

'                       if g_setvar=False, compute g_var from the doc info.

'Output var: g_success: return code. True=success, False=fail.

'Note: ignore fraction setting.  Do not convert g_var to/from fraction value.

'----------------------------------------------------------------------------

Sub EvalMzrVar( ByVal g_entity&, ByVal g_setvar As Boolean, ByRef g_var#, ByRef g_success As Boolean )

 

g_success = False

If g_setvar Then

    'Assign g_var to g_entity as needed here

Else

    'Retrieve g_var from g_entity as needed here

End If

g_success = True

 

End Sub

 

 

Example: Y-Offset of a Surface's Inner Trimming Volume

'----------------------------------------------------------------------------

'  Function:  Sets or retrieves an optimization variable.

'Input vars:  g_entity: the specified entity id number.

'             g_setvar: True=apply g_var to the FRED document,

'                       False=retrieve g_var from the FRED document.

'In/Out var:     g_var: if g_setvar=True, apply the given g_var to the doc,

'                       if g_setvar=False, compute g_var from the doc info.

'Output var: g_success: return code. True=success, False=fail.

'Note: ignore fraction setting.  Do not convert g_var to/from fraction value.

'----------------------------------------------------------------------------

'Example: Inner Trimming Volume Y-Offset

Sub EvalMzrVar( ByVal g_entity&, ByVal g_setvar As Boolean, ByRef g_var#, ByRef g_success As Boolean )

 

Dim tvinner As T_TRIMVOLUME

 

g_success = False

If IsSurface(g_entity) Then

    If g_setvar Then

        GetTrimVolume g_entity, tvinner

        tvinner.yCenterHole = g_var

        SetTrimVolume g_entity, tvinner

    Else

        GetTrimVolume g_entity, tvinner

        g_var = tvinner.yCenterHole

    End If

    g_success = True

End If

 

End Sub

 

 

Example: X0Y3 Term of a HOE Grating Phase Departure

'----------------------------------------------------------------------------

'  Function:  Sets or retrieves an optimization variable.

'Input vars:  g_entity: the specified entity id number.

'             g_setvar: True=apply g_var to the FRED document,

'                       False=retrieve g_var from the FRED document.

'In/Out var:     g_var: if g_setvar=True, apply the given g_var to the doc,

'                       if g_setvar=False, compute g_var from the doc info.

'Output var: g_success: return code. True=success, False=fail.

'Note: ignore fraction setting.  Do not convert g_var to/from fraction value.

'----------------------------------------------------------------------------

'Example: HOE Grating Phase Departure

Sub EvalMzrVar( ByVal g_entity&, ByVal g_setvar As Boolean, ByRef g_var#, ByRef g_success As Boolean )

 

Dim grH As T_HOE

Dim phT As String, coef() As Double, indx As Long

 

g_success = False

If IsSurface(g_entity) Then

    If g_setvar Then

        GetDiffractHOE g_entity, grH, phT, coef

        coef(indx) = g_var

        SetDiffractHOE g_entity, grH, phT, coef

    Else

        GetDiffractHOE g_entity, grH, phT, coef

        g_var = coef(indx)

    End If

    g_success = True

End If

 

End Sub

 

 

Example: Source Wavelength Weight

'----------------------------------------------------------------------------

'  Function:  Sets or retrieves an optimization variable.

'Input vars:  g_entity: the specified entity id number.

'             g_setvar: True=apply g_var to the FRED document,

'                       False=retrieve g_var from the FRED document.

'In/Out var:     g_var: if g_setvar=True, apply the given g_var to the doc,

'                       if g_setvar=False, compute g_var from the doc info.

'Output var: g_success: return code. True=success, False=fail.

'Note: ignore fraction setting.  Do not convert g_var to/from fraction value.

'----------------------------------------------------------------------------

'Example: Source Wavelength Weight

Sub EvalMzrVar( ByVal g_entity&, ByVal g_setvar As Boolean, ByRef g_var#, ByRef g_success As Boolean )

 

Dim wvsp As T_WAVELENGTHSPEC

Dim indx As Long

 

indx = 2

 

g_success = False

If IsSource(g_entity) Then

    If g_setvar Then

        GetSourceIthWavelengthSpec g_entity, indx, wvsp

        wvsp.weight = g_var

        SetSourceIthWavelengthSpec g_entity, indx, wvsp

    Else

        GetSourceIthWavelengthSpec g_entity, indx, wvsp

        g_var = wvsp.weight

    End If

    g_success = True

End If

 

End Sub

 

 

Example: Surface Particulate Cleanliness Level

'----------------------------------------------------------------------------

'  Function:  Sets or retrieves an optimization variable.

'Input vars:  g_entity: the specified entity id number.

'             g_setvar: True=apply g_var to the FRED document,

'                       False=retrieve g_var from the FRED document.

'In/Out var:     g_var: if g_setvar=True, apply the given g_var to the doc,

'                       if g_setvar=False, compute g_var from the doc info.

'Output var: g_success: return code. True=success, False=fail.

'Note: ignore fraction setting.  Do not convert g_var to/from fraction value.

'----------------------------------------------------------------------------

'Example: Surface Particulate Cleanliness Level

Sub EvalMzrVar( ByVal g_entity&, ByVal g_setvar As Boolean, ByRef g_var#, ByRef g_success As Boolean )

 

Dim mscat As T_MIESCATTER

Dim Mnode As Long, sindx As Long

Dim mtrl As Long, rcnt As Long

 

sindx = 0 'index of particulate model on surface

 

g_success = False

If IsSurface(g_entity) Then

    Mnode = GetSurfIthScatter(g_entity, sindx)

    If GetScatterType(Mnode) = "Mie" Then

        If g_setvar Then

            GetMieScatter Mnode, mscat

            mscat.CleanLevel = g_var

            SetMieScatter Mnode, mscat

        Else

            GetMieScatter Mnode, mscat

            g_var = mscat.CleanLevel

        End If

    End If

    g_success = True

End If

 

End Sub

 

 

User-defined Script Variables (extra parameters)

The "extra parameters" version of the user-defined script variable type includes the following additional input arguments:

                    g_index - The index value of the optimization variable

                    g_subindex - The subindex value of the optimization variable

                    g_lowerlim - The lower limit of the optimization variable value range

                    g_upperlim - The upper limit of the optimization variable value range

          

A common use of the "extra parameters" type script variable would be if the same script is used for multiple optimization variables, with the only difference being a dependence on the values the "extra parameters".

 

 

Related Topics


Optimization Overview

Optimize - Merit Function Aberrations

Optimize - Method

Optimize - Output Results

Optimize - Sensitivity Analysis

 

 

 

 

 

Copyright © Photon Engineering, LLC