Absorbed energy with NSDD operand

  • 20 June 2022
  • 1 reply

Hello all,

I have a simple system of a source and an object (CAD object checked with “object is a detector”). The CAD object has a coating defined with 80 % reflectance and 20 % absorbtance.

I´m trying to get the absorbed energy via ZPL macro with the operand NSDD. However, with the macro shown below, I always get the fully incident energy and not only the absorbed one.


NSTR 1,0,1,1,1,1,15
detector1= NSDD(1,2,0,4)
PRINT "Absorbed energy:    ",detector1


In the help file (Non-sequential Ray Tracing and Detector Operands) it says:

For Object Is A Detector: There are two additional options for data. Data is 4 for absorbed flux and 5 for absorbed flux/area.

What am I doing wrong?





Best answer by David.Nguyen 20 June 2022, 15:40

View original

1 reply

Userlevel 6
Badge +2

Hi Julian,


When things like this happen, I tend to check if I can reproduce the problem with the user interface only. If you create a Merit Function like so:

Then, you can’t set the Data column of the second NSDD operand to 4 (OpticStudio puts it back to zero automatically). Therefore, I’m not expecting this to work in your ZPL macro either. If you specify a valid pixel number (say 1 for example), then you can have Data = 4 for this particular pixel.

However, you want to know the total abosrption of your object and not for a single pixel.

I’m not sure how you should cannonically go about this problem, but here’s what I’ve done. First, I created a 1 x 1 x 1 mm^3 STEP file and uploaded it to OpticStudio as a Detector. I’ve assigned all its faces to Face 0 and used a coating like so:



Meaning, 0% transmission, 80% reflection, and, thus, 20% absorption.

Then, I’ve made a 1W Source Ray go through the cube and saved the raytrace (sanity check):

Ray 1, Wavelength 1 (0.5500 µm), 2 segments, 1 branches:
Seg#      Prnt      Levl      In      Hit      Face      XRTS     DGEF      BZ              Intensity      Comment
   0        0        0        0        0        0      ----     ----     --       1.000000000E+00      Source 1: 
   1        0        1        0        2        0      -*--     ----     --       1.000000000E+00      111_Cube.STEP
   2        1        2        0        0        0      *---     -*--     --       8.000000119E-01      Missed


After that, I’ve opened a Detector Viewer and in the Text Tab, I found the total number of pixels on my cube was:

CAD Part: STEP/IGES/SAT 2, NSCG Surface 1: 111_Cube.STEP
Number of pixels: 172, Total Hits = 1


In the pixel list, I searched for the pixel where my Source Ray hit:

Pixel             Flux       Irradiance             X             Y             Z             R    Angle (deg)
    1   0.00000000E+00   0.00000000E+00  -3.05556E-01  -4.16667E-01   0.00000E+00   5.16697E-01    -126.25384
    2   0.00000000E+00   0.00000000E+00  -1.38889E-01  -5.00000E-01   1.66667E-01   5.45039E-01    -105.52411
    3   0.00000000E+00   0.00000000E+00  -3.05556E-01  -5.00000E-01   8.33333E-02   5.91869E-01    -121.42957
    4   0.00000000E+00   0.00000000E+00  -1.38889E-01  -3.33333E-01   0.00000E+00   3.61111E-01    -112.61987
    5   0.00000000E+00   0.00000000E+00  -5.00000E-01  -3.05556E-01   8.33333E-02   5.91869E-01    -148.57043
    6   0.00000000E+00   0.00000000E+00  -4.16667E-01  -3.05556E-01   0.00000E+00   5.16697E-01    -143.74616
    7   0.00000000E+00   0.00000000E+00  -3.33333E-01  -1.38889E-01   0.00000E+00   3.61111E-01    -157.38013
    8   0.00000000E+00   0.00000000E+00  -5.00000E-01  -1.38889E-01   1.66667E-01   5.45039E-01    -164.47589
    9   1.00000000E+00   3.20000000E+03  -1.66667E-01  -8.33333E-02   0.00000E+00   1.86339E-01    -153.43495


Fortunately, it was early on in the list. I went back to my Merit Function and tried the absorption at pixel 9, and this is the result:

As expected, since I have only one ray of 1 W hitting a single pixel, then 20% or 0.2 W is absorbed.

Finally, I’ve made a macro to go through all the pixel and sum the absorbtion:

pixel_number = 172

total_absorbed = 0

clear_detectors = NSDD(1, 0, 0, 0)
NSTR 1, 0, 1, 1, 1, 1, 0

FOR pixel_id, 1, pixel_number, 1
    total_absorbed = total_absorbed + NSDD(1, 2, pixel_id, 4)

PRINT "Total flux absorbed = ", total_absorbed


As a last sanity check, I changed the Source Ray to a Source Ellipse (1E5 rays) with a 0.2 by 0.2 size and checked that I would still get the 0.2 W absorption. I’ve uploaded my file for you to check:

Executing C:\Users\David Nguyen\Documents\Zemax\MACROS\Total_absorbance.ZPL.
Total flux absorbed = 0.2000


The draw back is that you need to figure out the total pixel number (by going to the Detector text tab) by hand (I couldn’t find an automatic way to get this number, perhaps @Csilla Timar-Fulep@Berta.Bernad, or @Sandrine Auriol can further comment on this last issue). EDIT: I guess you could also parse the text file of the detector created by GETTEXTFILE for example.

Let me know if this helps.

Take care,