


{"id":326278,"date":"2023-12-05T00:51:29","date_gmt":"2023-12-05T00:51:29","guid":{"rendered":"\/forum\/forums\/topic\/troubleshooting-a-couple-of-errors-in-lumerical-scripting\/"},"modified":"2023-12-05T00:51:29","modified_gmt":"2023-12-05T00:51:29","slug":"troubleshooting-a-couple-of-errors-in-lumerical-scripting","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/troubleshooting-a-couple-of-errors-in-lumerical-scripting\/","title":{"rendered":"Troubleshooting a couple of errors in Lumerical scripting"},"content":{"rendered":"<p>I am attempting to recreate the Lumerical RCWA portion of <a href=\"https:\/\/optics.ansys.com\/hc\/en-us\/articles\/360042097313-Small-Scale-Metalens-Field-Propagation\">the small metalens tutorial<\/a>&nbsp;using only Lumerical scripting rather than starting from the pre-built .fsp example file. When scripting Lumerical, I am having trouble with the command:<br \/>addrcwa;<br \/><img decoding=\"async\" src=\"\/forum\/wp-content\/uploads\/sites\/2\/2023\/12\/05-12-2023-1701736318-mceclip0.png\"><br \/>Yet, this command appears in the online knowledge base <a href=\"https:\/\/optics.ansys.com\/hc\/en-us\/articles\/15335330773395-addrcwa-Script-Command\">here<\/a>.&nbsp;<br \/>If I choose to use the command &#8220;addfdtd;&#8221; instead of &#8220;addrcwa;&#8221; the line executes, but I get an error further down the script when using the command:<br \/>addsweepresult(&#8220;thickness_sweep_script&#8221;, result_1);<br \/><img decoding=\"async\" src=\"\/forum\/wp-content\/uploads\/sites\/2\/2023\/12\/05-12-2023-1701736777-mceclip1.png\"><\/p>\n<p>This seems strange to me because the code worked last week without errors when using the &#8220;addfdtd;&#8221; command.<br \/>A couple of notes: <br \/>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, &#8220;addrcwa;&#8221; fails even when run as a lone command in the command window.<br \/>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<\/p>\n<p>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&#8217;s another topic.) Thanks in advance for any advice!<\/p>\n<p>SCRIPT:&nbsp;<\/p>\n<div>deleteall;<\/div>\n<div>if(exist(&#8220;cylinder_height_sweep&#8221;)) {deletesweep(&#8220;cylinder_height_sweep&#8221;);}<\/div>\n<div>if(exist(&#8220;cylinder_radius_sweep&#8221;)) {deletesweep(&#8220;cylinder_radius_sweep&#8221;);}<\/div>\n<div>### VARIABLES ###<\/div>\n<div># Constants and Units<\/div>\n<div>nm = 1e-9;<\/div>\n<div>um = 1e-6;<\/div>\n<div># Nanopillar<\/div>\n<div>height_np_min = 600*nm;<\/div>\n<div>height_np_max = 1.2*um;<\/div>\n<div>radius_np_min = 75*nm;<\/div>\n<div>radius_np_max = 125*nm;<\/div>\n<div>material_np = &#8220;Si (Silicon) &#8211; Palik&#8221;;<\/div>\n<div># Substrate<\/div>\n<div>period = 400*nm;<\/div>\n<div>thick_sub = 100*nm;<\/div>\n<div>material_sub = &#8220;SiO2 (Glass) &#8211; Palik&#8221;;<\/div>\n<div># FDTD<\/div>\n<div>lda_min = 400*nm;<\/div>\n<div>lda_max = 800*nm;<\/div>\n<div>airgap = lda_max\/2;<\/div>\n<div>#height_cell = height_np_max+thick_sub+2*airgap;<\/div>\n<div>zmin_cell = -1*(thick_sub + airgap);<\/div>\n<div>zmax_cell = height_np_max + airgap;<\/div>\n<div>&nbsp;<\/div>\n<div># Cylindrical Nanopillar<\/div>\n<div>addcircle;<\/div>\n<div>set(&#8220;x&#8221;,0);<\/div>\n<div>set(&#8220;y&#8221;,0);<\/div>\n<div>set(&#8220;radius&#8221;,radius_np_min);<\/div>\n<div>set(&#8220;z min&#8221;,0);<\/div>\n<div>set(&#8220;z max&#8221;,height_np_min);<\/div>\n<div>set(&#8220;material&#8221;,material_np);<\/div>\n<div>&nbsp;<\/div>\n<div># Substrate<\/div>\n<div>addrect;<\/div>\n<div>set(&#8220;x&#8221;,0);<\/div>\n<div>set(&#8220;x span&#8221;,period);<\/div>\n<div>set(&#8220;y&#8221;,0);<\/div>\n<div>set(&#8220;y span&#8221;,period);<\/div>\n<div>set(&#8220;z min&#8221;,-1*thick_sub);<\/div>\n<div>set(&#8220;z max&#8221;,0);<\/div>\n<div>set(&#8220;material&#8221;,material_sub);<\/div>\n<div>&nbsp;<\/div>\n<div># FDTD Region<\/div>\n<div>#addrcwa;<\/div>\n<div>addfdtd;<\/div>\n<div>set(&#8220;dimension&#8221;,2);&nbsp; #&nbsp; 1 = 2D, 2 = 3D<\/div>\n<div>set(&#8220;x&#8221;,0);<\/div>\n<div>set(&#8220;x span&#8221;,period);<\/div>\n<div>set(&#8220;y&#8221;,0);<\/div>\n<div>set(&#8220;y span&#8221;,period);<\/div>\n<div>set(&#8220;z min&#8221;,zmin_cell);<\/div>\n<div>set(&#8220;z max&#8221;,zmax_cell);<\/div>\n<div>set(&#8220;x min bc&#8221;,&#8221;Periodic&#8221;);<\/div>\n<div>set(&#8220;y min bc&#8221;,&#8221;Periodic&#8221;);<\/div>\n<div>set(&#8220;pml profile&#8221;,3); # 1. standard, 2. stabilized<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# 3. steep angle, 4. custom<\/div>\n<div>set(&#8220;allow symmetry on all boundaries&#8221;,true);<\/div>\n<div>set(&#8220;set simulation bandwidth&#8221;,true);<\/div>\n<div>set(&#8220;simulation wavelength min&#8221;,lda_min);<\/div>\n<div>set(&#8220;simulation wavelength max&#8221;,lda_max);<\/div>\n<div>set(&#8220;always use complex fields&#8221;,true);<\/div>\n<div>&nbsp;<\/div>\n<div>### Mesh Override Region<\/div>\n<div>addmesh;<\/div>\n<div>set(&#8220;dx&#8221;,10*nm);<\/div>\n<div>set(&#8220;dy&#8221;,10*nm);<\/div>\n<div>set(&#8220;dz&#8221;,10*nm);<\/div>\n<div>set(&#8220;based on a structure&#8221;,true);<\/div>\n<div>set(&#8220;structure&#8221;,&#8221;circle&#8221;);<\/div>\n<div>&nbsp;<\/div>\n<div>### Source<\/div>\n<div>addplane;<\/div>\n<div>set(&#8220;injection axis&#8221;,&#8221;z&#8221;);<\/div>\n<div>set(&#8220;x&#8221;,0);<\/div>\n<div>set(&#8220;x span&#8221;,period);<\/div>\n<div>set(&#8220;y&#8221;,0);<\/div>\n<div>set(&#8220;y span&#8221;,period);<\/div>\n<div>set(&#8220;z&#8221;,zmin_cell);<\/div>\n<div># If Frequency Domain<\/div>\n<div>set(&#8220;wavelength start&#8221;,lda_min);<\/div>\n<div>set(&#8220;wavelength stop&#8221;,lda_max);<\/div>\n<div># Else if Time Domain<\/div>\n<div>set(&#8220;set time domain&#8221;,true);<\/div>\n<div>&nbsp;<\/div>\n<div>### Monitor<\/div>\n<div>addpower;<\/div>\n<div>set(&#8220;name&#8221;,&#8221;Transmission&#8221;);<\/div>\n<div>set(&#8220;monitor type&#8221;,&#8221;2D Z-normal&#8221;);<\/div>\n<div>set(&#8220;x&#8221;,0);<\/div>\n<div>set(&#8220;x span&#8221;,period);<\/div>\n<div>set(&#8220;y&#8221;,0);<\/div>\n<div>set(&#8220;y span&#8221;,period);<\/div>\n<div>set(&#8220;z&#8221;,zmax_cell-airgap\/2);<\/div>\n<div>&nbsp;<\/div>\n<div>### Parameter Sweep<\/div>\n<div># create parameter sweep &#8220;height&#8221;<\/div>\n<div>addsweep;<\/div>\n<div>setsweep(&#8220;sweep&#8221;, &#8220;name&#8221;, &#8220;cylinder_height_sweep&#8221;);<\/div>\n<div>setsweep(&#8220;cylinder_height_sweep&#8221;, &#8220;type&#8221;, &#8220;Ranges&#8221;);<\/div>\n<div>setsweep(&#8220;cylinder_height_sweep&#8221;, &#8220;number of points&#8221;, 10);<\/div>\n<div># define the parameter height<\/div>\n<div>para_h = struct;<\/div>\n<div>para_h.Name = &#8220;height&#8221;;<\/div>\n<div>para_h.Parameter = &#8220;::model::height&#8221;;<\/div>\n<div>para_h.Type = &#8220;Length&#8221;;<\/div>\n<div>para_h.Start = height_np_min;<\/div>\n<div>para_h.Stop = height_np_max;<\/div>\n<div>para_h.Units = &#8220;microns&#8221;;<\/div>\n<div>addsweepparameter(&#8220;cylinder_height_sweep&#8221;, para_h);<\/div>\n<div># define results<\/div>\n<div>result_1 = struct;<\/div>\n<div>result_1.Name = &#8220;S&#8221;;<\/div>\n<div>result_1.Result = &#8220;S&#8221;;<\/div>\n<div>result_2 = struct;<\/div>\n<div>result_2.Name = &#8220;T&#8221;;<\/div>\n<div>result_2.Result = &#8220;T&#8221;;<\/div>\n<div># add the results R &amp; T to the sweep<\/div>\n<div>addsweepresult(&#8220;thickness_sweep_script&#8221;, result_1);<\/div>\n<div>addsweepresult(&#8220;thickness_sweep_script&#8221;, result_2);<\/div>\n<div>&nbsp;<\/div>\n<div># create parameter sweep &#8220;radius&#8221;<\/div>\n<div>addsweep;<\/div>\n<div>setsweep(&#8220;sweep&#8221;,&#8221;name&#8221;,&#8221;cylinder_radius_sweep&#8221;);<\/div>\n<div># define the parameter radius<\/div>\n<div>para_r = struct;<\/div>\n<div>para_r.Name = &#8220;radius&#8221;;<\/div>\n<div>para_r.Parameter = &#8220;::model::radius&#8221;;<\/div>\n<div>para_r.Type = &#8220;Length&#8221;;<\/div>\n<div>para_r.Start = radius_np_min;<\/div>\n<div>para_r.Stop = radius_np_max;<\/div>\n<div>para_r.Units = &#8220;microns&#8221;;<\/div>\n<div># add the parameters to the sweep<\/div>\n<div>addsweepparameter(&#8220;cylinder_height_sweep&#8221;, para_r);<\/div>\n<div># define results<\/div>\n<div>result_1 = struct;<\/div>\n<div>result_1.Name = &#8220;R&#8221;;<\/div>\n<div>result_1.Result = &#8220;::model::R::T&#8221;;<\/div>\n<div>&nbsp;<\/div>\n<div>result_2 = struct;<\/div>\n<div>result_2.Name = &#8220;T&#8221;;<\/div>\n<div>result_2.Result = &#8220;::model::T::T&#8221;;<\/div>\n<div>&nbsp;<\/div>\n<div># add the results R &amp; T to the sweep<\/div>\n<div>addsweepresult(&#8220;thickness_sweep_script&#8221;, result_1);<\/div>\n<div>addsweepresult(&#8220;thickness_sweep_script&#8221;, result_2);<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"template":"","class_list":["post-326278","topic","type-topic","status-closed","hentry"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["303674","2796"],"_bbp_author_ip":["96.7.74.191"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["3029"],"_bbp_topic_status":["unanswered"],"_bbp_status":["publish"],"_bbp_topic_id":["326278"],"_bbp_forum_id":["27833"],"_bbp_engagement":["2796","303674"],"_bbp_voice_count":["2"],"_bbp_reply_count":["4"],"_bbp_last_reply_id":["326761"],"_bbp_last_active_id":["326761"],"_bbp_last_active_time":["2023-12-07 00:53:08"]},"test":"crumbergeranyarinc-com"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/326278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/326278\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=326278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}