# How to use the Grid Sag surface type

This article provides an overview of the Grid Sag surface and shows how to implement it in a sequential system.

Authored By Alexandra Culler & Erin Elliott

## Introduction

Grid Sag surfaces can be used to model virtually any surface shape in Sequential Mode in OpticStudio. Each Grid Sag surface is defined by providing an array of sag values at a uniform grid of (X, Y) points across the surface. The Grid Sag format is particularly useful for modeling freeform surfaces, which may lack symmetry or an analytic expression to describe the surface.

## Grid Sag surface definition

In OpticStudio, the Grid Sag surface is highly versatile; having a shape defined by a base plane, sphere, conic asphere, polynomial asphere, or Zernike asphere alongside sag terms defined by a rectangular array of sag values. All discrete points are connected by a bicubic or linear spline function.

The base sag function of the Grid Sag surface is given by the standard sag equation:

Where c is the curvature of the surface (the inverse of the radius), r is the radial coordinate, and k is the conic constant.

This sag function can be modified through a user-defined set of sag values provided in a data (DAT) file that may be imported into OpticStudio. This DAT file has a specific file format, shown below:

The values of interest are the following:

• “nx” and “ny”: These values define the number of points within the sag profile.
• “delx” and “dely”: These values provide the distance between sag points.
• “unitflag”: This value will tell OpticStudio what the units of distance are between points. Choose "0" for mm, "1" for cm, and so on.
• “z”: The sag values are given by this value. Multiple lines of sag data can be added and then connected by the program through the use of a bicubic spline.

The other values are usually left as zero, but can be modified depending on the application.

Such a file can be generated programmatically. A tutorial on how to do so may be found in the Knowledgebase article “How to write a Grid Sag DAT file programmatically."

It is important to note that a Grid Sag surface is limited by available memory. For example, a 255x255 grid will require nearly 2 Mb of memory. This means that a file with many Grid Sag surfaces or with a Grid Sag surface featuring a large amount of points has the potential to run much slower than usual.

## Importing a Grid Sag surface

Grid Sag – like any other surface in Sequential Mode – may be selected by typing directly into the “Surface Type” column, or by choosing it from the drop-down menu in the Type tab of the Surface Properties dialog.

The Grid Sag surface is defined, in part, by the standard sag equation; however, most users want to leave the definition of the sag profile solely to the imported DAT file. To ensure that the information in the DAT file data is not altered, we will need to set the Radius of the surface to “Infinity” and the Conic parameter to 0. This will ensure that the base sag equation for the Grid Sag surface is set to 0 – meaning that the sag profile is defined entirely by the imported DAT file.

Note: This is only required if the DAT file you're importing is meant to represent the surface shape in its entirety. The DAT file can also be used as "additional sag" placed on top of a base curvature.

When initialized, the Grid Sag surface loads without a DAT file. To import a sag profile, navigate to Surface Properties…Import. At this menu, you will have the ability to browse for a DAT file. To be able to see a given file in the drop-down menu, it will need to be located in the {Zemax}\Objects\Grid Files folder. You may also browse for a file in another location.

Once you’ve selected the file you want to use, click “Import”. The comment field of the Grid Sag surface should update with the name of the chosen file.

To ensure that the DAT file has been properly imported, the Surface Sag analysis tool can be used. Open this analysis by navigating to Analyze…Surface…Sag.

Update the settings so that the surface being observed is the Grid Sag one, and the profile should be visible. The data in the “Text” tab will correspond to the data provided in the DAT file. The numbers will match best if the values chosen for “nx” and “ny” match the resolution of the Surface Sag tool. Otherwise, the values you see will be approximations of the DAT file values, fit to match the chosen resolution.

KA-01847