Top tips on how to maximize your Ansys Zemax with Custom User-Defined Features
Would you like to take the efficiency of your Ansys Zemax to the next level? Would you like to save yourself from doing the same task repeatedly? Ansys Zemax supports user-defined custom features that will be your new friend.
One of the key aspects of is its flexibility in allowing users to create custom features to extend the capabilities of the software. These custom features can help you overcome challenges, improve your efficiency, and maintain precision in your work. In this article, Olli Hakala introduces how to create custom features for collimating shapes. Collimating shapes are being used from camera lenses to illumination and from medical applications to precision welding.
For decades, Zemax has been a leading software in optical design. It is a powerful and versatile tool for any kind of optical systems with vast number of features and readily available objects to be used. Yet there are instances where you may find that certain features are missing or not quite aligning with your specific needs. In such cases, it’s time to consider harnessing the potential of user-defined custom features.
Here are the three symptoms when you should consider user-defined custom features:
1. When Zemax Objects Don’t Behave as Desired
Regardless of the extensive library of optical components in Ansys Zemax, you may encounter situations where a particular component doesn’t behave exactly as you want it to. This could be due to unique specifications or unconventional requirements in your project. Instead of settling for a compromise, a user defined function can be tailored can be tailored to meet your specific needs. It offers you the flexibility to create, modify, or fine-tune optical elements to suit your design, ensuring that your optical system behaves exactly as intended.
2. When You’re Stuck in a Loop of Repetitive Calculations
In many optical design projects, there is a need to perform calculations that span multiple software applications, often involving back-and-forth data transfers between Ansys Zemax and tools like Microsoft Excel. If you find yourself repeatedly crunching numbers or copying data between these platforms, it’s a clear sign that you could benefit from a UDF. By streamlining these calculations within Zemax, you not only save time but also minimize the risk of errors associated with data transfer.
3. When Design Workarounds Become Routine
Sometimes, innovative optical designs demand unconventional approaches. You may find yourself repeatedly implementing workarounds to achieve your desired outcomes. While creativity is essential in optics, constantly resorting to workarounds can lead to inefficiencies and convoluted designs. With a user-defined custom feature, you can formalize these workarounds into standardized, efficient processes within your Zemax. This not only simplifies your workflow but also ensures consistency and quality across your projects.
How to Get Started with User-Defined Custom Features in Zemax
You might be thinking now, that doesn’t this require more than a bit of programming skills? Yes. There can be no way around the programming phase, but it is not the most important part, nor the most difficult part. The difficult part is to recognize the need (which you already might have done!) and clearly define it.
The Basic Steps Of The Process
1. Identify the Need: Recognize the specific scenarios in your optical design process where a custom feature could enhance efficiency or address limitations. 2. Form a concept of how to implement: Can a feature be created with simple script or do you need a more powerful DLL-based object.
2. Design and Implement: Plan and design your custom feature, keeping your project’s requirements in mind. Implement it within Zemax, ensuring that it integrates seamlessly into your workflow.
3. Testing and Validation: Thoroughly test your custom feature to ensure it behaves as intended and provides the expected results. Validate it against your design requirements.
4. Documentation: Document your custom feature, including usage instructions and any unique considerations for future reference.
5. Share Knowledge: Consider sharing your custom features within the Zemax community if they have broad relevance. Collaborative innovation benefits everyone in the optics field!
Example – Automatically collimating shape
In optics it is quite common to use collimating shapes. This can be either one component within an optical system that sets the focus to infinity or just a simple lens producing a narrow beam from an LED light source. Collimating shapes are integral in maintaining the precision, accuracy, and efficiency in Optics, Sensors and Detectors, Laser Technology, Medical Imaging. As an example, let us consider an entrance surface that requires to have a collimating shape.
In sequential (SC) mode of Zemax such surface is easy to define and constrain within the merit function. However, in non-sequential (NSC) mode, adding such constrain to one surface within a merit function can be quite time-consuming in an optimization. If you know that a certain part of your design must always have theoretical collimating shape, it would be best to define it as constantly collimating in relation focal distance and index of refraction, while maintaining flexibility to positional changes. This way, you would not need Zemax to consider this in optimization, freeing up valuable calculation time, especially in NSC. Such a feature could be defined within Zemax Programming Language (ZPL) script or be embedded into a User-Defined Object (UDO). If you want to know more about UDO, please see next chapter “For Programming Enthusiasts” for details.
In conclusion, user-defined custom features in Zemax are powerful tools that empower optical designers and engineers to overcome challenges, improve efficiency, and maintain precision in their work. Whether you’re dealing with non-standard components, repetitive calculations, or persistent design workarounds, harnessing the potential of customization within Ansys Zemax can elevate your optical design projects to new heights of efficiency and innovation.
For Programming Enthusiasts
The easiest way to tackle the example described in previous chapter would be to write a simple Zemax Programming Language (ZPL) script with the Zemax macro language. As there is less information about User-Defined Surfaces (UDS) and User Defined Objects (UDOs), let us approach this by using VB.net programming. General information about UDOs is covered in Zemax Knowledge-Base article KA-01846, which I recommend going through before reading this.
The anatomy of UDOs is specific. Zemax expects an entry-point to a DLL function with a specific name, carrying pointers to two objects with specific structures called UD and FD (User Data and Fixed Data). Some more experienced programmers might realize at this point, that DLL export functionality is only provided in native C and C++ language. However, I have good news for those who prefer VB.NET and C#: There is a way around this, but it will require a little bit of compiler configuration and marshalling, which I am looking forward to cover in detail in a PDSVISION Conference talk.
Below example (Snippet 1) shows, how the called function is defined using version 3 of UDS surfaces. Version histories are better discussed in the above mentioned Knowledge Base article, but the key is, that the expected entry point has to be named as “UserDefinedSurface3”, while also having corresponding “FIXED_DATA3” structure (Snippet 2) for the FD object.
A User Data object UD (Snippet 3) has only one structure. As Zemax is written in C and this example is provided in VB.NET, some Marshalling will be required for the interpretation. Also, please bear in mind that the name of called function should remain unchanged after the compilation, which might not always be the case. Inside the called function we will have the communication routine for data exchange, which will provide Zemax the object parameters, parameter names, object behaviour, and more, for which there are plenty of examples available in the “..User\Documents\Zemax\DLL” -folder.
In our case example, we would only adjust the conic value according to index of refraction reported by Zemax. Index of refraction is included in FIXED_DATA3 n1 and n2 pointers, and the values will change whenever the material will be changed in the Lens Data Editor (LDE). We can simply read the index values, apply them to the equation, and set the conic value accordingly. The other part of equation states, that radius should be half of the distance from focal point. For the sake of simplicity, this can be defined as pick-up value in LDE, however it is also possible to import it straight to DLL object to make it fully independent.
Snippet 1. Definition of the DLL function.
Snippet 2. Structure of the fixed data object.
Snippet 3. Structure of user data object.
Did this spark any interest? Contact us HERE!
Olli Hakala, Senior Optical Engineer