Code gives different result when run as a script compared to analysis
TAGGED: lumerical, Lumerical-FDTD, lumerical-script
-
-
May 28, 2025 at 2:30 pm
williamfraser3
SubscriberI am designing a grating coupler in Lumerical FDTD. I have some code in the Analysis tab of the "model" object that calculates the overlap between the field radiated by the grating and a Gaussian fiber mode. If I copy this code and run it as a script instead of inside the "model" object, it gives a different result, i.e., calculates an overlap of 72% instead of 77%. It is the EXACT same code (copy and pasted). What is going on?
-
May 28, 2025 at 8:54 pm
Kirill
Ansys EmployeeDear Subscriber,
My guess is that some variables under Model > Analysis > Variables may have different values in your Script Workspace. So, while the "exact same code" is being used, it might not be processing exactly the same data.
Best regards,
Kirill-
May 29, 2025 at 1:14 pm
williamfraser3
SubscriberHi Kirill,
Yes, I discovered what the problem was. In the Model variables I have a length parameter called 'wav' that I use to set the wavelength for the sources. Inside the analysis, I have an if statement that checks the wavelength to set the appropriate fiber MFD. Even though 'wav' was set to 1.55 um, the condition 'wav == 1.55e-6' was returning false, so the wrong fiber MFD was being used. Changing the 'wav' parameter to be a number instead of a length fixes this problem. Not sure if that is a bug or intentional.Â
-
-
May 29, 2025 at 3:25 pm
Kirill
Ansys EmployeeHi @williamfraser3,
Using um unit should give exactly 1e-6 factor... Anyway, I'm glad that you have resolve the issue. Thanks for confirming!
Best regards,
Kirill-
May 29, 2025 at 3:28 pm
williamfraser3
SubscriberHi Kirill,
Yes, that's what I figured. But for some reason 1.55e-6 == 1.55e-6 is not true according to Lumerical when the left side is a "length" but 1.55 == 1.55 is true if the left side is a "number". Weird, but glad I noticed and found a workaround.
Best,
William
-
-
- You must be logged in to reply to this topic.
-
3236
-
1031
-
969
-
859
-
798
© 2025 Copyright ANSYS, Inc. All rights reserved.