Photonics

Photonics

FDTD: Issue with calling function from function library

Tagged: 

    • ferruccio.pisanello
      Subscriber

      Hi,

      I am runing a simulation using a script where I am calling a function library. The function library is present in the same folder which is working directory. Sometimes the simulation runs. However in some cases, when I changed some geometrical parameters to run another simulation, the program gives me an error saying the function/variable is undefined. This is the name of the function which I am calling from the function library. It's very strange. For one simulation it runs but for another, it says it's undefined. 

       

      Error: D:/TE0 785/plasmonic_pillar1_h550_d100_polarization_sweep.lsf line 77: scat_E is not a valid function or variable name

      scat_E is the name of the function I am calling from the function library. It runs normally for one case and for another case it says it's undefined? 

       

      Any help in this regard will be appreciated. 

       

      Regards

      FK

    • jackzhf
      Subscriber

      One of the possible causes:

      User-defined functions can be defined within your main script file, or saved in separate files, and must be defined at global scope. If you save the function in a separate file, ensure the script file name is different than the function name. It must also be different than any standard Lumerical script functions.

       

      Note that the function “add” needs to be defined in the global scope, and it won’t be recognized if it is defined inside the “add4” function. The following definition of the functions will give an error:

       

      function add4(i, j, k, l){  
      function add(a, b) {
      return a+b;
      }  return add(add(i, j), add(k, l));
      }
      Error: add is not a valid function or variable name

       

      https://optics.ansys.com/hc/en-us/articles/360034923573-function-Script-command-Create-your-own-functions

       

       

    • ferruccio.pisanello
      Subscriber

      Hi,

      Thanks for your comments. It seemed to be an issue related to the variable name conflict/ reuse. I changed some variable names to save the function output and it seems to be working. 

    • Guilin Sun
      Ansys Employee

      Thank you @jackzhf. 

      Lumerical script shares the same work space as you can check them:

    • ferruccio.pisanello
      Subscriber

      Hi,

      I changed some variable names and it worked. But for a second simulation, it's giving me the same issue. The error says the function name which I am calling is undefined. But it worked for an earlier execution. It's very strange. 

      Error: D:/plasmonic_pillar1_h550_d100_TE0785.lsf line 78: scat_E is not a valid function or variable name

       

      The following examples have these functions. 

      https://optics.ansys.com/hc/en-us/articles/360042160993-Plasmon-mode-excitation

Viewing 4 reply threads
  • You must be logged in to reply to this topic.