空心球的太复杂了);直接加不久仿真出来了嘛;
###########################################################################
# Scriptfile: mie_analysis_3d.lsf
#
# Description:
# This file shows how to use analysis groups in mie_example_3d.fsp to do 4
# types of analyses for 3D Mie scattering
# 1) The far field angular scattering in the x-y, x-z and y-z planes
#x-y, x-z和y-z平面的远场角散射
# 2) The far field XY half space (Note: This calculation can be time consuming)
#远场XY半空间(注意:这个计算可能会很耗时)
# 3) The absorption/scattering cross section
#吸收/散射截面
# 4) The field enhancement calculation
#场增强计算(电场)
# Copyright 2018, Lumerical Solutions, Inc.
###########################################################################
#判断仿真run,若没有,执行run
if(getresult("FDTD","status")==0) { # Run the simulation if it is in layout mode
run;
}
# Choose which of the 4 possible analyses you want to do从4个可能的分析中选择你想做的
#polar:极坐标散射相位;半区间(halfspace),截面,场增强
#,一个总开关,if判断
do_polar_plot = true; # true to perform the test and false to skip
do_halfspace = false; # true to perform the test and false to skip
do_cross_sections = true; # true to perform the test and false to skip
do_field_enhancement = true; # true to perform the test and false to skip
# Define target wavelength used for polar plot and field enhancement when enabled:
#定义用于极性图(极坐标)和场增强的目标波长。
target_wavelength = 0.5e-6;
# Define the resolution for the far field plots(远场图的分辨率)
polar_plot_res = 51;
halfspace_res = 31; # this number will significantly affect the time to run this analysis
# Far field polar plot and halfspace:远场极坐标图和半场
setnamed("scat_ff", "target wavelength", target_wavelength);#目标波长
#总开关,用if
if(do_polar_plot & do_halfspace ) {
?" Calculating far field angular distribution and halfspace";
?" NOTE: This calculation takes time!!";
setnamed("scat_ff", "do polar plot",0);#这的0(不开启)和1(开启),
setnamed("scat_ff", "do halfspace",1);
setnamed("scat_ff", "halfspace res", halfspace_res);
setnamed("scat_ff", "polar plot res", polar_plot_res);
runanalysis("scat_ff");
?" Calculation done!";
}else{
if(do_polar_plot) {
?" Calculating far field angular distribution";
setnamed("scat_ff", "do polar plot",0);
setnamed("scat_ff", "do halfspace",0);
setnamed("scat_ff", "halfspace res", halfspace_res);
setnamed("scat_ff", "polar plot res", polar_plot_res);
runanalysis("scat_ff");
}
if(do_halfspace) { # only for 3D simulation
?" Calculating far field halfspace";#远场半距
?" NOTE: This calculation takes time!!";
setnamed("scat_ff", "do polar plot",0);
setnamed("scat_ff", "do halfspace",1);
setnamed("scat_ff", "halfspace res", halfspace_res);
setnamed("scat_ff", "polar plot res", polar_plot_res);
runanalysis("scat_ff");
?" Calculation done!";
}
}
#开始判断,然后作图
if(do_polar_plot) {
XY = getresult("scat_ff","XY");
f1 = getnamed("mie_source","frequency start");
f2 = getnamed("mie_source","frequency stop");
n2 = getfdtdindex("Au (Gold) - Johnson and Christy Copy 1",XY.f,f1,f2);#设定了材料
n1 = getnamed("FDTD","background index");
m = n2/n1;
r = getnamed("sphere","radius"); # the radius of the mie particle粒子半径
size_parameter = 2*pi*r/XY.lambda * n1;#周长/波长*n1背景折射率
phi = XY.phi;
theta = 90*pi/180;
S = mie3ds12(cos(theta),m,size_parameter);
k = meshgridy(phi,2*pi/XY.lambda * n1);
phi = meshgridx(phi,2*pi/XY.lambda * n1);
R = 1;
fpoint = find(XY.lambda,target_wavelength);
Etheta = exp(1i*k*R)/(-1i*k*R)*cos(phi)*meshgridy(XY.phi,S.S2);
Ephi = exp(1i*k*R)/(1i*k*R)*sin(phi)*meshgridy(XY.phi,S.S1);
polar(XY.phi,pinch(XY.E2,2,fpoint),pinch(abs(Etheta)^2+abs(Ephi)^2,2,fpoint),"","","XY");
plot(XY.phi,pinch(XY.E2,2,fpoint),pinch(abs(Etheta)^2+abs(Ephi)^2,2,fpoint),"","","XY");
这段代码是在FDTD(有限差分时间域)仿真环境中对Mie散射情况进行计算和可视化的一部分。以下是对每个部分的解释:
XY = getresult("scat_ff","XY"); 这行获取了名为“scat_ff”的结果数据集,其中包含XY坐标的数据。
f1 = getnamed("mie_source","frequency start"); f2 = getnamed("mie_source","frequency stop"); 获取Mie源频率范围的开始和结束点。
n2 = getfdtdindex(...); 根据给定的金(Au)的复介电常数(n2),以及从之前的结果得到的波长(frequency)范围,计算出Mie粒子所在区域的相对折射率。
n1 = getnamed("FDTD","background index"); m = n2/n1; 得到背景介质(通常是真空)的折射率,并计算粒子相对背景的折射率比(m)。
r = ...; size_parameter = ...; 计算Mie粒子的大小参数,涉及粒子的半径、波长和背景折射率。
phi = XY.phi; theta = ...; S = mie3ds12(...): 算法可能涉及到Mie散射函数(S)的计算,依赖于角度(φ, θ)。
k = meshgridy(...); phi = meshgridx(...); R = 1; 创建网格变量,用于后续的物理量计算。
fpoint = find(...): 寻找目标波长对应的索引位置。
Etheta, Ephi = ...: 计算θ和φ方向上的场强分布。
polar(...,"XY"): 最后,使用polar函数进行二维极坐标表示,显示目标波长处的极化强度分布图,参数包括φ轴的数据、极化强度及坐标轴标签。