Ansys Learning Forum › Forums › Discuss Simulation › Photonics › Optimization script writing › Reply To: Optimization script writing

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 0^{th} order, of green in 0^{th} order and blue in 1^{st} 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