Photonics

Photonics

Topics related to Lumerical and more.

Optimization script writing

    • bailin.zhang
      Subscriber

      Hello  All,

      Is it possible to add a control in a script for RCWA optimization of diffraction elements: for some wvelength, it is of a high diffraction efficiency, for other wavelength, it is of different efficiency wanted ?

      Thank you

    • Afroditi Petropoulou
      Ansys Employee

      Dear Bailin,

       

      Thank you for reaching out to us!

       

      I am not exactly sure what you want to optimize and what your settings are (if for example you use 2D or 3D grating, if you use more than one input angle for the excitation, and so on).

       

      An optimization example of a 2D grating that the target is to get 0.2 transmission for s-polarized light if the wavelength is smaller than or equal to 500nm target wavelength and 0.5 transmission if the wavelength is greater than 500nm in a specific diffraction order (in this example it is the -1 diffraction order), could be the following:

       

      lambda_target=500e-9; # wavelength to be used as a condition

      target_lower = 0.2; # diffraction efficiency for wavelengths smaller than lambda_target

      target_upper = 0.5; # diffraction efficiency for wavelengths greater than lambda_target

       

      lambda=grating.lambda;

      Ts=grating.Ts_grating; # result that we need to optimize

      target_order = -1; # the diffraction order that we are interested in optimizing the power

       

      n = grating.n;

      target_order_index = find(n, target_order);

       

      fom=0;

       

      for (i=1:length(lambda)) {

          if (lambda(i)<=lambda_target) {

              fom=fom+abs(Ts(i,1,target_order_index,1)-target_lower);

          } else {

              fom=fom+abs(Ts(i,1,target_order_index,1)-target_upper);

          }

      }

       

       

      where the result that has been used is the grating_orders result and the fom type is set to minimize:


       

      Please keep in mind that the above optimization script can also be used for simulations that run for multiple wavelengths (more than 1 frequency points in the excitation tab of RCWA). In this case the optimization will try to minimize the difference from the target efficiencies for all wavelengths, i.e. the sum of the differences for all wavelengths will be minimized.

       

      I hope this helps.

       

      Best regards,

      Afroditi

    • bailin.zhang
      Subscriber

      Hi Afroditi,

      Thank you very much for answering my question. My question is described in a detail in the figure below:

      For example on the left, if I want have incidence including many wavelength such as three wavelength R, G, and B.  I want to optimize the grating parameters to reach the following goal:

       

      When the light hits the grating, I hope all the energy of blue light can flow into its positive first diffraction order, at the same time, the red and green light will completely pass the grating without any energy loss, namely all the energy will flow to their 0th diffraction orders.

       

      How to write such an optimization scripts for that?

       

      Thank you very much and appreciated !

       

      Best,

      Bailin

    • Afroditi Petropoulou
      Ansys Employee

      Dear Bailin,

       

      An indicative script for the optimization that you describe is the following:

       

      lambda_cond=450e-9; # wavelength to be used as a condition

       

      lambda=grating_orders.lambda;

      Ts=grating_orders.Ts_grating; # result that we need to optimize

      target_order_b = 1; # the diffraction order for blue

      target_order_rg = 0; # the diffraction order for red and green

       

      n = grating_orders.n;

      index_b = find(n, target_order_b);

      index_rg = find(n, target_order_rg);

       

      fom=0;

       

      for (i=1:length(lambda)) {

          if (lambda(i)

              fom=fom+Ts(i,1,index_b,1);

          } else {

              fom=fom+Ts(i,1,index_rg,1);

          }

      }

       

      In this case you need to use maximize in the optimization fom type:

       


       

      In the above script the transmission for s-polarized light is used for the optimization. You can change it to p-polarization or you can use the average of the two.

       

      Also, please keep in mind that the fom used in the script is the maximum transmission for all three wavelengths (the sum of transmission of red in 0th order, of green in 0th order and blue in 1st order). If you have other constrains you can add them to the script.

       

      For the simulation you can set the wavelengths in the excitation tab of RCWA (in order to have the specific three wavelengths) as below:

       


       

      Best regards,

      Afroditi

    • bailin.zhang
      Subscriber

      Hi Afroditi,

      It is really a good support and highly appreciated !

      For the wavelength setting, when set minmum wavelngth at 0.42, maximum wavelength at 0.6, it just set two of them correct, but how to set the "middle wwavelength" correct?  if have more descrete wavelength need to be set, how to do that?

      Best,

      Bailin

    • Afroditi Petropoulou
      Ansys Employee

      Dear Bailin,

       

      I am not sure if it is not displayed correctly or it wasn't copied correctly but the for loop of the script should be the following:

      for (i=1:length(lambda)) {

          if (lambda(i)

              fom=fom+Ts(i,1,index_b,1);

          } else {

              fom=fom+Ts(i,1,index_rg,1);

          }

      }

      I think the if condition was missing in my previous message for some reason.

       

      Regarding your question, if you set the limits to 0.42um and 0.6um, and select 3 frequency points and enable the "use wavelength spacing" option as shown in the image I sent you, the three wavelengths that the simulation will run for will be 420nm, 510nm and 600nm (since they are equally spaced).

      If you needed more wavelengths or they were not equally spaced, you would need to use more frequency points in order to have higher resolution in the wavelength and then use the wavelength that would be closer to your target. Using more wavelengths though will increase the simulation time too.

       

      Best regards,

      Afroditi

    • Afroditi Petropoulou
      Ansys Employee

      Sorry Bailin but I think it cannot display the less than symbol. The for loop is the following:

      Regards,

      Afroditi

    • bailin.zhang
      Subscriber

      Hi Afroditi,

      Your answer "...not equally spaced,  use more frequency points in order to...  use the wavelength that be closer to your target" solved my question. Thank you very much for your excellent support ! 

      Best,

      Bailin

    • Afroditi Petropoulou
      Ansys Employee

      Thank you Bailin! I am happy I could help.

       

      Have a nice weekend

      Best regards,

      Afroditi

    • bailin.zhang
      Subscriber

      Hi Afroditi,

      i tested the script for the application. it seems the results obtained is not that reasonable. You can see in the screenshot below,  the transmission 0 orders of two shorter wavelength reached a good maximum. While the reflection +1 order of anohter longer wavelength was almost at its minimum efficiency.  Can you help figure out waht is the possible issues?   Thank you very much.

      Best,

      Bailin

    • Afroditi Petropoulou
      Ansys Employee

      Dear Bailin,

       

      As you probably already know, the number of grating orders supported by a grating depend on the period of the grating, the wavelength, the incident angle, and the refractive index of the substrates (the “substrate” result from RCWA). It does not depend on the properties of the actual grating.

      Having high transmission or reflection to a specific order though, depends on the actual grating and its properties. For specific grating shapes, you might or might not have high transmission/reflection on a specific order although this order is supported.

      From the plots you shared, I see that you have high transmission for the 0th order for all three wavelengths, although you wanted to have high transmission for the 0th order for the red and green and 1st order for the blue.

      This might be attributed to two factors:

      1.       Since the fom defined in the script uses the sum of the three transmissions (sum of 0th order for the red and green and 1st order for the blue), you might need to use a weighting factor to the transmission of the blue wavelength.

      2.       The grating shape and its properties used in the optimization do not support high transmission to the 1st order for the blue wavelength.

      Since the latter is possible, I would suggest starting by optimizing your grating only for high transmission to the 1st order for the blue wavelength to check whether it is possible to achieve it. The Surface Relief Grating for Augmented Reality System – Ansys Optics example describes how to optimize the grating in order to achieve high transmission to a specific order (the order is -1 in the example but you can use 1).

       

      Best regards,

      Afroditi

    • bailin.zhang
      Subscriber

      Hi Afroditi,

      Thank you for the analysis of the fundamental reasons. I agree with you about this.  Really appreciated !

      By the way, the script grammar used in Lumerical FDTD is its own language or other language such as matlab, or python?

      Best,

      Bailin

    • Afroditi Petropoulou
      Ansys Employee

      Dear Bailin,

       

      The scripting language used in Lumerical is the Lumerical scripting language.

      The commands are similar to matlab.

      You can find a full list of commands in Lumerical scripting language - By category – Ansys Optics

       

      Best regards,

      Afroditi

    • bailin.zhang
      Subscriber

      Thank you, Afroditi, I got it.  Best,

      Bailin

Viewing 13 reply threads
  • The topic ‘Optimization script writing’ is closed to new replies.