接《使用脚本语言实现Lumerical官方案例——闪耀光栅(Blazed grating)(纯代码)(1)》
一、添加分析组
1.1 代码实现
#添加分析组
addanalysisgroup();
set("name", "grating_R");
set("x", 0);
set("y", 2.5*um);
addanalysisgroup();
set("name", "grating_T");
set("x", 0);
set("y", -1.5*um);#添加功率监视器
addpower();
set("name", "transmission_grating");
set("monitor type", "2D Z-normal");
set("x min", -2*um);
set("x max", 2*um);
set("y min", 0);
set("y max", 0);
set("z", 0);
addtogroup("grating_R");addpower();
set("name", "transmission_grating");
set("monitor type", "2D Z-normal");
set("x min", -2*um);
set("x max", 2*um);
set("y min", 0);
set("y max", 0);
set("z", 0);
addtogroup("grating_T");
1.2 分析组的设置
1.2.1 grating_R
(1)setup
#grating_R_setup_script.lsf
#这段if语句用于检查名为normal的输入参数值是否合法。如果normal的值既不是"x"也不是"y",则认为是无效的表面法线方向输入,会输出相应的错误提示信息(通过message函数)
#告知用户输入有误,并将normal默认设置为"y",以保证后续代码能按合理的默认情况继续执行
if ((normal != "x") and (normal != "y")) { message("Surface normal '" + normal + "' is invalid. Must be 'x', 'y'. Using y normal.");normal ="y"; # if normal is not specified properly, default to y normal
}
#这两个if语句根据normal的值来对x_span或y_span进行调整。如果normal的值为"x",意味着在x方向是表面法线方向,此时将x_span设置为 0,因为对于这个特定的监视器(用于计算光栅透射率且必须是 1D 的情况下)
#在法线方向的跨度需要忽略;同理,当normal为"y"时,将y_span设置为 0。
if (normal=="x") { x_span = 0; } # set span in normal direction to zero
if (normal=="y") { y_span = 0; }
(2) analysis
##############################################
# Grating transmission
# This object calculates the fraction of power transmitted to each
# grating order at all frequency points recorded by the monitor.
# It also calculates the number of propagating grating orders
#
# Input properties
# make plots: 1 to make plots, 0 otherwise
# n target: grating order to plot
# lambda target: wavelength to plot
#
# Output properties
# f: frequency vector
# n: grating order number vector
# T(f): total transmitted power vs frequency
# T_grating(n,f): transmitted power to each grating order
# num_orders(f): number of propagating grating orders
# theta(n,f): grating order angles
#
# Tags: far field grating order transmission
#
# Copyright 2012 Lumerical Solutions Inc
############################################## #grating_R_analys