Ask an Engineer: Making a Surface DLL


Userlevel 6
Badge +2

Topic: Creating a user-defined surface using DLLs

Live solution reveal and Q&A: May 19th, 8am - 9am PDT (See the attachments for a calendar invite.)

Engineer: @Sandrine Auriol - Lead Application Engineer at Ansys Zemax

 

This month, Ask an Engineer looks a little different! Give the challenge a try to learn more about DLLs, then come back on May 19th to discuss! Submit your solution or questions as a reply to this thread.

 

Challenge opens: May 2nd 

Submit your code as a reply by: May 18th, EOD

Challenge:  OpticStudio surfaces are typically represented with continuous curves - either given by a smooth sag equation, or a spline which connects individual sag points. However, discrete steps may be needed to best represent an optical surface. For example, when manufacturing an optic with a 3D printer or lathe, the tool may generate the shape through the use of different zones of sag data, instead of a smooth profile, and you may want to represent a rough first-pass prototype in your simulation. In this case, a User Defined surface is preferable over, say, a Grid Sag as it will allow for this type of non-continuous sag information.

This month, we challenge you to create a User Defined Surface which has a sag profile that is step-wise in YZ. The profile should be given by an external TXT file. When viewing the surface in the Surface Sag plot, the output should be similar to the following:

 

False Color plot of the surface sag profile of the User Defined surface

 

Files: 

  • Calendar invite for May 19th. This will connect you to the Teams meeting where @Sandrine Auriol will present her solution and answer your questions.
  • A sample TXT file representing the radial sag information the DLL should refer to. 

Resources/Tips:

Questions? Comments? Ready to submit your code? Reply to this thread. Replies may be posted in any supported language (English, Chinese, Japanese). Once the event is concluded, the thread will be closed. 

The Ask an Engineer live event will be limited to discussing this challenge and general DLL questions. For questions on troubleshooting personal DLLs or OpticStudio files, please submit a ticket with Zemax Support. In that case, your license support status will be considered. 

Allie 4 months ago

Hi @Alicia and @Sandrine Auriol - apologies for the delay. The recording, notes, and files from yesterday’s meeting are available at the link below. 

Ask an engineer_May 2022

This ZIP drive includes a ZAR file which contains the resulting DLL. The CPP code for the DLL is also provided. To use the CPP code, follow the directions in the KBA “How to compile a user defined DLL” - linked above. 

For convenience, the recording is also available here:

 

 

View original

This topic is closed to new comments

13 replies

Userlevel 2
Badge +1

テーマ: Ask an Engineer:ユーザ定義面 DLL の作成

ライブ解説および Q&A 回答日時:5月19日午前8時~午前9時(米国太平洋標準時)

エンジニア: @Sandrine Auriol - Ansys-Zemax リードアプリケーションエンジニア

 

今月の Ask an Engineer は今までと方法が少々異なります。DLL について詳細を知るために、ぜひ課題に挑戦しましょう!5月19日 にはライブで解説および Q&A があります。 このスレッドに返信する形で、解決策や質問を投稿してください

 

Click “Show content” to read the Japanese translation of the challenge.

課題への挑戦開始日: 5月2日

コード提出期限日: 5月18日

課題  

OpticStudio の面は通常、滑らかなたるみ式、または個々のたるみ点を結ぶスプラインによって与えられる連続曲線で表現されます。しかし、光学面を最適に表現するためには、離散的なステップが必要な場合があります。例えば、3Dプリンターや旋盤で光学部品を製造する場合、工具は滑らかなプロファイルではなく、異なるゾーンのサグデータを使用して形状を生成することがあり、シミュレーションでは粗いファーストパスのプロトタイプを表現したいと思うかもしれません。このような場合、このような非連続的なサグ情報を使用できるため、グリッドサグよりもユーザ定義サーフェスの方が望ましいと言えます。

今月は、YZ 方向に段階的に変化するサグプロファイルを持つユーザ定義面を作成することに挑戦します。プロファイルは外部の TXT ファイルから取得します。面を面のサグプロットで表示すると、以下のように出力します。

 

ユーザ定義面のサグプロファイルの疑似カラープロット

 

ファイル

  • 5月19日 のカレンダーの招待状です。これは @Sandrine Auriol が解決策を発表し、ユーザ様の質問に答えるチームミーティングにつなぎます。
  • DLL が参照すべき半径方向のたるみ情報を表す TXT ファイルのサンプルファイルです。

リソース/ヒント:

質問やコメント、コードを提出する準備はできましたか?このスレッドに返信してください。返信は、サポートされている言語 (英語、中国語、日本語) で投稿できます。イベント終了後、このスレッドは閉鎖されます。

Ask an Engineer ライブイベントは、この課題への挑戦と一般的な DLL に関する質問に限定されます。個人用 DLL または OpticStudio ファイルのトラブルシューティングに関する質問については、Zemax サポートにチケットを提出してください。その場合、お客様のライセンスサポート状況が考慮されます。

 

Userlevel 1
Badge

Ask an Engineer - 詢問工程師系列:使用DLL创建用户定义的表面

 

在线解决方案展示和问答时间:5月19日,太平洋夏令时间上午8点至上午9点。(请参阅附件以获取日历邀请)

工程师@Sandrine Auriol - Ansys Zemax首席应用工程师

 

这个月,Ask an Engineer环节将有所不同!我们提供了以下挑战供用户尝试,以便用户了解有关DLL的更多信息,然后在5月19日展开讨论!请提交您的解决方案或问题作为对此主题的回复。

 

Click “Show content” to read the Chinese translation of the challenge.

挑战开始日期52

代码提交截止日期51824:00

挑战内容 

OpticStudio表面通常用连续曲线表示——由平滑的矢高方程或连接各个矢高点的样条曲线给出。然而,为了更好地表示光学表面,可能需要离散的步骤例如,当使用3D打印机或车床制造光学器件时,该工具可能会通过使用不同的区域矢高数据而不是平滑的轮廓来生成形状,并且您可能希望在模拟中表示一个粗略的原型。在这种情况下,用户定义的表面比矢高网格更可取,因为它将允许这种类型的非连续矢高信息。

本月,我们将为您提供一个创建用户定义表面的挑战,该表面的矢高轮廓在YZ中是阶梯式的。配置文件应由外部TXT文件提供。在表面矢高图中查看表面时,输出应类似于以下图片: 

用户定义表面的表面矢高轮廓的伪彩色图

附件

  • 5月19日在线活动邀请。这会方便您直接连接到活动,@Sandrine Auriol 将在该会议上展示她的解决方案并回答您的问题。
  • 代表DLL应参考的径向矢高信息的样本TXT文件。

 

参考资料/提示:

如果有任何问题评论或者准备好提交您的代码了?回复这个主题。欢迎各位使用任何支持的语言(英语、中文、日语)发布回复。当活动结束后,主题将被关闭。

Ask an Engineer在线活动将仅限于讨论这一挑战和DLL常规问题。有关对个人DLL文件或其他OpticStudio文件的故障排除问题,请向Zemax Support提交问题,我们会根据您授权的状态来提供支持

 

Dear Sandrine,

 

I am not able to download the attachments. As mentioned in the text, the attachments include calendar invite for May 19th. Could you please provide the joining link in another way, possibly by posting it here?

I would like to make sure that I can join this meeting.

 

Best regards,

Vahideh

Userlevel 6
Badge +2

Hi @Vahide.Karbasi - apologies for the problem with the link. I think if you right-click on the attachment and open in a new tab the attachment will download. If that doesn’t work for you, click the link below instead:

Ask and Engineer - Making a Surface DLL - Supplemental Files

Good morning Sandrine,

 

I want to simulate a lens in Zemax OpticStudio with a user-defined surface. I have a notepad with two columns of numbers. The first column represents the positions of one meridian of the lens from -3.5 mm to +3.5 mm and the second column represents the average power of the lens in each of the positions. Then, the data should be extrapolated radially to create the surface. I attach an example .txt of what I want to create. If I understood correctly, I need to create a DLL based on this .txt.? The code has to follow the same steps/template as the example US_FILT_FILE.CCP? This is the first time I try do an user-defined surface and I need help

Thank you very much, kind regards

 

Alicia

 

Userlevel 6
Badge +2

Hi Alicia

The power of the lens is related to the effective focal length. So I think that a way to solve that could be to define a surface and optimize it with your power values in the merit function.

I am not sure the user-defined surface would be the best solution for that case. We also have surfaces where you can give the sag and the software does the interpolation like the radial sag, the cubic spline. So if the power can be converted to a sag, that could also be an option.

But if you want to learn about user defined surfaces, come to the session tomorrow!

Userlevel 6
Badge +2

Hi all! The Ask An Engineer event is about to begin. You can find the meeting at this link:

 

________________________________________________________________________________

Microsoft Teams meeting

Join on your computer or mobile app

Click here to join the meeting

Or call in (audio only)

+1 267-419-7621,,227890820#   United States, Philadelphia

Phone Conference ID: 227 890 820#

Dear Sandrine,

Thanks for your help! I dont have an Ansys account so could you please tell me how I can download and watch again the recording from the teams session we had yesterday?

Thank you very much

 

Alicia

Userlevel 6
Badge +2

Thank you Alicia!

@Allie can you share the recording?

Userlevel 6
Badge +2

Hi @Alicia and @Sandrine Auriol - apologies for the delay. The recording, notes, and files from yesterday’s meeting are available at the link below. 

Ask an engineer_May 2022

This ZIP drive includes a ZAR file which contains the resulting DLL. The CPP code for the DLL is also provided. To use the CPP code, follow the directions in the KBA “How to compile a user defined DLL” - linked above. 

For convenience, the recording is also available here:

 

 

Userlevel 6
Badge +2

@Vahide.Karbasi - Following up on your question - here are the two C files I would recommend starting with for your project:

  • us_stand2.c
    • This C code provides a basis for a Standard surface. That is one of the simplest surface forms we have in the program, so the code is not too long. Use this to help familiarize yourself with the core code of a DLL. You can also use it as a basis for your surface.
  • us_arrayeven2.c
    • This C code is used to build an array of Even Asphere surfaces. While you are not after an array, you could use this code to better understand how to add extra parameters to your surface in cases 2 and 7. The code also shows how those parameters can be used in the sag equations of cases 3 and 5!

If you use either of these files as a basis for your code, please keep in mind that you will need to tweak them so they are compatible with the CPP format used by Visual Studio. You can read more about that in the KBA “How to compile a user defined DLL”.

Also don’t forget that you are able to share your solution with the community if you want to! You can post it to the Code Exchange with the tag “Code Exchange - for review”. 

Userlevel 6
Badge +2

The Ask an engineer event raised a few questions regarding user-defined surface dlls, so here is a selection of the frequently asked questions:

  • “Since UDS uses an external file, does it slow down the computation?”
    UDS reads the external file when the DLL is loaded and then stores the data of the external file into memory. So every time the DLL needs that data, it reads the memory.
    When the DLL is no longer used, that memory space is no longer allocated.
  • “Does OS need to communicate with the DLL every time a ray trace is run?"
    Yes. Every time OS runs a raytrace, it calls the DLL because for each ray traced through the system, it needs to know the new intercept point with the surface (x, y, z) as well as the new direction cosines after the surface (l, m, n).
  • “Is the ray-tracing slower with a DLL than with a built-in OS surface?”
    Yes it is slower because there is a tiny overhead every time you call the DLL. The more you call the DLL, the slower it is.
  • “Where can I find examples of DLLs?”
    The sample folder is a good place to start {Zemax}\DLL\Surfaces.
    Check also the Code Exchange: https://community.zemax.com/code-exchange-10. Don’t forget to login to be able to download the DLLs.
Userlevel 6
Badge +2

Hi all! I have added the video as an embedded item in the pinned post so you can watch it without downloading. Now that that’s done, I’m closing this post. If you have questions about DLLs, feel free to post them here: DLLs | Zemax Community