Skip to main content
Question

Large amount of single ray trace


Hi,

 

I’m currently trying to trace a large amount (~1 million) of rays with very specific output position and trace their path length it takes them to reach a detector and then output the position as well as the specific path length of that beam. Currently not using scattering, but in future, I would like to extend this to scattering as well.

 

My first thought was to create a loop that would create single rays, trace them, return the OPL through a Merit Function and then output in the end, but I assume that this would take forever to compute. Any idea how this would be done more efficiently? I’ve seen that batch ray trace might be an option, but I don’t know enough about it or other alternatives to evaluate correctly.

 

Thank you for any help!

3 replies

David.Nguyen
Luminary
Forum|alt.badge.img+2

@ma-sunde 

 

Your intuition is correct, I also think it is a case for batch raytracing. You’ll save a lot of overhead that you’d have with the single raytrace.

@Ali H wrote a nice section about batch raytracing in the Help File to get you started, also described here:

@MichaelH made a DLL to have fast access to the ray binary data in Python/MATLAB:

https://support.zemax.com/hc/en-us/articles/1500005576882-Batch-Processing-of-Ray-Trace-Data-using-ZOS-API-in-MATLAB-or-Python

If you prototype something and encounter any issues let us know.

Take care,


David


  • Author
  • Infrared
  • 5 replies
  • July 10, 2025

I’m currently using a Two Angle source in non-sequential mode but my challenge is that I didn’t find a way to find the OPL for specific rays simulated.

Looking at the RayTrace.dll I’m now wondering if i could continue to use the Two Angle source, run a non sequential ray-trace and store the zrd file for the raytrace? Using the IZRD Reader, would I be able to read the segments (and specific angular positions of each ray) and OPL from the zrd file? This would avoid using the batch raytracing if I’m not mistaken.


David.Nguyen
Luminary
Forum|alt.badge.img+2

@ma-sunde 

 

Indeed, the DLL is made to read ZRD files. Whether you generate them via batch raytracing in ZOSAPI or simply through the user interface shouldn’t matter. Let us know otherwise. And yes you should be able to read segment data as you expect.

EDIT: the DLL was posted in 2021, and there have been some changes in the ZRD format in between as ​@MichaelH  documented in this post:

Therefore, I’m not sure if the DLL is fully up-to-date, I’ll let you check.

Take care,

 

David


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings