Photonics

Photonics

Topics related to Lumerical and more.

Troubleshooting a couple of errors in Lumerical scripting

    • crumberger
      Subscriber

      I am attempting to recreate the Lumerical RCWA portion of the small metalens tutorial using only Lumerical scripting rather than starting from the pre-built .fsp example file. When scripting Lumerical, I am having trouble with the command:
      addrcwa;

      Yet, this command appears in the online knowledge base here. 
      If I choose to use the command "addfdtd;" instead of "addrcwa;" the line executes, but I get an error further down the script when using the command:
      addsweepresult("thickness_sweep_script", result_1);

      This seems strange to me because the code worked last week without errors when using the "addfdtd;" command.
      A couple of notes:
      1) I initially built this script with FDTD in mind but decided to try switching to RCWA since that is what appears in the online tutorial linked above. I realize that I may need to change some parts of my code accordingly. However, "addrcwa;" fails even when run as a lone command in the command window.
      2) The screenshots above show the problematic lines being run alone in the command window. The errors are identical when running the full code. Only the line number in the error message changes

      I have included my code below. (I am still trying to work out how best to add sweeps and collect the results to get the phase response info, but that's another topic.) Thanks in advance for any advice!

      SCRIPT: 

      deleteall;
      if(exist("cylinder_height_sweep")) {deletesweep("cylinder_height_sweep");}
      if(exist("cylinder_radius_sweep")) {deletesweep("cylinder_radius_sweep");}
      ### VARIABLES ###
      # Constants and Units
      nm = 1e-9;
      um = 1e-6;
      # Nanopillar
      height_np_min = 600*nm;
      height_np_max = 1.2*um;
      radius_np_min = 75*nm;
      radius_np_max = 125*nm;
      material_np = "Si (Silicon) - Palik";
      # Substrate
      period = 400*nm;
      thick_sub = 100*nm;
      material_sub = "SiO2 (Glass) - Palik";
      # FDTD
      lda_min = 400*nm;
      lda_max = 800*nm;
      airgap = lda_max/2;
      #height_cell = height_np_max+thick_sub+2*airgap;
      zmin_cell = -1*(thick_sub + airgap);
      zmax_cell = height_np_max + airgap;
       
      # Cylindrical Nanopillar
      addcircle;
      set("x",0);
      set("y",0);
      set("radius",radius_np_min);
      set("z min",0);
      set("z max",height_np_min);
      set("material",material_np);
       
      # Substrate
      addrect;
      set("x",0);
      set("x span",period);
      set("y",0);
      set("y span",period);
      set("z min",-1*thick_sub);
      set("z max",0);
      set("material",material_sub);
       
      # FDTD Region
      #addrcwa;
      addfdtd;
      set("dimension",2);  #  1 = 2D, 2 = 3D
      set("x",0);
      set("x span",period);
      set("y",0);
      set("y span",period);
      set("z min",zmin_cell);
      set("z max",zmax_cell);
      set("x min bc","Periodic");
      set("y min bc","Periodic");
      set("pml profile",3); # 1. standard, 2. stabilized
                           # 3. steep angle, 4. custom
      set("allow symmetry on all boundaries",true);
      set("set simulation bandwidth",true);
      set("simulation wavelength min",lda_min);
      set("simulation wavelength max",lda_max);
      set("always use complex fields",true);
       
      ### Mesh Override Region
      addmesh;
      set("dx",10*nm);
      set("dy",10*nm);
      set("dz",10*nm);
      set("based on a structure",true);
      set("structure","circle");
       
      ### Source
      addplane;
      set("injection axis","z");
      set("x",0);
      set("x span",period);
      set("y",0);
      set("y span",period);
      set("z",zmin_cell);
      # If Frequency Domain
      set("wavelength start",lda_min);
      set("wavelength stop",lda_max);
      # Else if Time Domain
      set("set time domain",true);
       
      ### Monitor
      addpower;
      set("name","Transmission");
      set("monitor type","2D Z-normal");
      set("x",0);
      set("x span",period);
      set("y",0);
      set("y span",period);
      set("z",zmax_cell-airgap/2);
       
      ### Parameter Sweep
      # create parameter sweep "height"
      addsweep;
      setsweep("sweep", "name", "cylinder_height_sweep");
      setsweep("cylinder_height_sweep", "type", "Ranges");
      setsweep("cylinder_height_sweep", "number of points", 10);
      # define the parameter height
      para_h = struct;
      para_h.Name = "height";
      para_h.Parameter = "::model::height";
      para_h.Type = "Length";
      para_h.Start = height_np_min;
      para_h.Stop = height_np_max;
      para_h.Units = "microns";
      addsweepparameter("cylinder_height_sweep", para_h);
      # define results
      result_1 = struct;
      result_1.Name = "S";
      result_1.Result = "S";
      result_2 = struct;
      result_2.Name = "T";
      result_2.Result = "T";
      # add the results R & T to the sweep
      addsweepresult("thickness_sweep_script", result_1);
      addsweepresult("thickness_sweep_script", result_2);
       
      # create parameter sweep "radius"
      addsweep;
      setsweep("sweep","name","cylinder_radius_sweep");
      # define the parameter radius
      para_r = struct;
      para_r.Name = "radius";
      para_r.Parameter = "::model::radius";
      para_r.Type = "Length";
      para_r.Start = radius_np_min;
      para_r.Stop = radius_np_max;
      para_r.Units = "microns";
      # add the parameters to the sweep
      addsweepparameter("cylinder_height_sweep", para_r);
      # define results
      result_1 = struct;
      result_1.Name = "R";
      result_1.Result = "::model::R::T";
       
      result_2 = struct;
      result_2.Name = "T";
      result_2.Result = "::model::T::T";
       
      # add the results R & T to the sweep
      addsweepresult("thickness_sweep_script", result_1);
      addsweepresult("thickness_sweep_script", result_2);

       

    • Dimitris Polyzos
      Ansys Employee

      Hello, 

      Regarding the addrcwa; command it runs OK on my PC. Could you please let me know what version of Lumerical do you use? In the script you shared, I commented the addfdtd; command line and uncommented the addrcwa; and it works fine.

      It seems that your script needs a slight modification in order to work. After loading it in script file editor please change at line 120 and 121.

      addsweepresult("cylinder_height_sweep", result_1);

      addsweepresult("cylinder_height_sweep", result_2);

      Similarly do the same for lines 146  and 147 for the name :

      addsweepresult("cylinder_radius_sweep", result_1);

      addsweepresult("cylinder_radius_sweep", result_2);

      Otherwise, you can use the corrected script directly below:

      deleteall;

      if(exist("cylinder_height_sweep")) {deletesweep("cylinder_height_sweep");}

      if(exist("cylinder_radius_sweep")) {deletesweep("cylinder_radius_sweep");}

      ### VARIABLES ###

      # Constants and Units

      nm = 1e-9;

      um = 1e-6;

      # Nanopillar

      height_np_min = 600*nm;

      height_np_max = 1.2*um;

      radius_np_min = 75*nm;

      radius_np_max = 125*nm;

      material_np = "Si (Silicon) - Palik";

      # Substrate

      period = 400*nm;

      thick_sub = 100*nm;

      material_sub = "SiO2 (Glass) - Palik";

      # FDTD

      lda_min = 400*nm;

      lda_max = 800*nm;

      airgap = lda_max/2;

      #height_cell = height_np_max+thick_sub+2*airgap;

      zmin_cell = -1*(thick_sub + airgap);

      zmax_cell = height_np_max + airgap;

       

      # Cylindrical Nanopillar

      addcircle;

      set("x",0);

      set("y",0);

      set("radius",radius_np_min);

      set("z min",0);

      set("z max",height_np_min);

      set("material",material_np);

       

      # Substrate

      addrect;

      set("x",0);

      set("x span",period);

      set("y",0);

      set("y span",period);

      set("z min",-1*thick_sub);

      set("z max",0);

      set("material",material_sub);

       

      # FDTD Region

      addrcwa;

      #addfdtd;

      set("dimension",2); # 1 = 2D, 2 = 3D

      set("x",0);

      set("x span",period);

      set("y",0);

      set("y span",period);

      set("z min",zmin_cell);

      set("z max",zmax_cell);

      set("x min bc","Periodic");

      set("y min bc","Periodic");

      set("pml profile",3); # 1. standard, 2. stabilized

      # 3. steep angle, 4. custom

      set("allow symmetry on all boundaries",true);

      set("set simulation bandwidth",true);

      set("simulation wavelength min",lda_min);

      set("simulation wavelength max",lda_max);

      set("always use complex fields",true);

       

      ### Mesh Override Region

      addmesh;

      set("dx",10*nm);

      set("dy",10*nm);

      set("dz",10*nm);

      set("based on a structure",true);

      set("structure","circle");

       

      ### Source

      addplane;

      set("injection axis","z");

      set("x",0);

      set("x span",period);

      set("y",0);

      set("y span",period);

      set("z",zmin_cell);

      # If Frequency Domain

      set("wavelength start",lda_min);

      set("wavelength stop",lda_max);

      # Else if Time Domain

      set("set time domain",true);

       

      ### Monitor

      addpower;

      set("name","Transmission");

      set("monitor type","2D Z-normal");

      set("x",0);

      set("x span",period);

      set("y",0);

      set("y span",period);

      set("z",zmax_cell-airgap/2);

       

      ### Parameter Sweep

      # create parameter sweep "height"

      addsweep;

      setsweep("sweep", "name", "cylinder_height_sweep");

      setsweep("cylinder_height_sweep", "type", "Ranges");

      setsweep("cylinder_height_sweep", "number of points", 10);

      # define the parameter height

      para_h = struct;

      para_h.Name = "height";

      para_h.Parameter = "::model::height";

      para_h.Type = "Length";

      para_h.Start = height_np_min;

      para_h.Stop = height_np_max;

      para_h.Units = "microns";

      addsweepparameter("cylinder_height_sweep", para_h);

      # define results

      result_1 = struct;

      result_1.Name = "S";

      result_1.Result = "S";

      result_2 = struct;

      result_2.Name = "T";

      result_2.Result = "T";

      # add the results R & T to the sweep

      addsweepresult("cylinder_height_sweep", result_1);

      addsweepresult("cylinder_height_sweep", result_2);

       

      # create parameter sweep "radius"

      addsweep;

      setsweep("sweep","name","cylinder_radius_sweep");

      # define the parameter radius

      para_r = struct;

      para_r.Name = "radius";

      para_r.Parameter = "::model::radius";

      para_r.Type = "Length";

      para_r.Start = radius_np_min;

      para_r.Stop = radius_np_max;

      para_r.Units = "microns";

      # add the parameters to the sweep

      addsweepparameter("cylinder_radius_sweep", para_r);

      # define results

      result_1 = struct;

      result_1.Name = "R";

      result_1.Result = "::model::R::T";

       

      result_2 = struct;

      result_2.Name = "T";

      result_2.Result = "::model::T::T";

       

      # add the results R & T to the sweep

      addsweepresult("cylinder_radius_sweep", result_1);

      addsweepresult("cylinder_radius_sweep", result_2);

    • crumberger
      Subscriber

      Thanks for the response and for pointing out the mistake on lines 120-121.
      The version I am running is Lumerical 2022 R2.4

      I tried running it today on a fresh session and the addrcwa error persists.

    • Dimitris Polyzos
      Ansys Employee

      Hello, 

      Tha is definetely weird. Something you could try is to upgrade to a newer version of Lumerical, maybe due to a bug that could be in the old version and now it is fixed. I cannot think other explanation for the script command not to execute.

      I hope I helped. Kind regards

      Dimitris

    • crumberger
      Subscriber

      Thanks for trying to help me with this. I see that I also cannot find an option to add an RCWA solver region under the Simulation button on the toolbar. I have just contacted someone on the server admin side to see if our organizational license is somehow set up with access to the FDTD solver but not the RCWA solver (not even sure if that's possible, but it could explain the issue if so).

      Thanks again,
      Charles

Viewing 4 reply threads
  • The topic ‘Troubleshooting a couple of errors in Lumerical scripting’ is closed to new replies.