Hi,
I have a similar problem. I would like to optimize the system by avoiding back focusing on the previous lenses (focusing due to single-bounce reflections). Unfortunately, the operands available in the merit function allow controlling the focusing from double reflections, not from single reflections. Doing the study in non-sequential mode is not a solution, because it is necessary to control the reflections during the sequential optimization. Any suggestions?
Thanks!
I faced this issue previously and ended up writing my own User Defined Operand. It wasn’t particularly difficult. I started with the example file CppUserOperandApplication.cpp located in the following directory:
\Documents\Zemax\ZOS-API Projects\CppUserOperandApplication\
Then I added the following code at the designated location to create a copy of the system and make it double pass at any surface from which I wanted to consider a reflection:
// Add your custom code here...
// Read the operand arguments (Note: we aren't using arguments 2-4)
int surf = (int)TheApplication->OperandArgument1;
// create system copy for ghost analysis
IOpticalSystemPtr TheSystemCopy = TheSystem->CopySystem();
// reflect system at surf
TheSystemCopy->LDE->RunTool_MakeDoublePass(surf);
// get single-bounce ghost results
// PARY -- paraxial ray y-height
int last_surf = (int)TheSystemCopy->LDE->NumberOfSurfaces - 1;
double ym = TheSystemCopy->MFE->GetOperandValue(MeritOperandType_PARY, last_surf, 1, 0, 0, 0, 1, 0, 0);
operandResultsu0] = ym;
After making the double-pass system, you can call whatever standard merit function operands you like to evaluate ray properties or system quantities of interest.
I compiled the code using Microsoft Visual Studio. The Ansys version of Zemax requires 64-bit. This KB article was helpful: How to create a User Operand using ZOS-API
Regards,
Jeff
Hi Jeff,
Thanks for the sharing by using UDOC operand. Have you tried with ZPLM operand and compared it with UDOC? because I found in many testing cases, ZPLM is more stable and with better compatibility. Maybe
also has a running speed superiority than UDOC?
Best regards,
Deyang
Hi @yu.deyang,
I don’t think the ZPL provides a way to generate a double-pass system for ghost reflection analysis, but please let me know if you think there is some way to do this.
When using my UDOC I had no problems with stability. Typically, compiled code executes very fast, so a well-written UDOC should run efficiently. I didn’t have any issues with speed, so I didn’t bother to benchmark the execution time.
I agree, though, that for simple user operands the ZPLM approach is easier to implement.
Regards,
Jeff
Hi Jeff,
Thanks for the clarification. My concern on stability and compatibility issue when using UDOC comes from that I saw many users in this forum who had updated or changed OpticStudio to more newer version or back, then their API code doesn’t work any more. There are many possible reasons could cause such compatibility issue. Compared to ZPL, there is seems no big compatibility issue for ZPL.
That give me an impression that ZPL is more robust and with no worries on compatability although it has weak data processing capability than API.
It seems make double pass function isn’t implemented in ZPL. The UDOC and API is the most elegant way I think for this case. Again, I appreciate the clarification. Thanks Jeff.
Best regards,
Deyang