DGTD学习_lumerical_编程_谐振器仿真电流电荷分布

DGTD学习_lumerical_编程_谐振器仿真电流电荷分布

最终的结果图

我暂时还没有做出来,继续学习_

DGTD学习_lumerical_编程_谐振器仿真电流电荷分布

#这段代码是 Lumerical FDTD Solutions 软件的脚本,用于分析等离子体石棚结构的等离子体模式并提取相应的场分布。

fmin = c/(2e-6);

#计算最小频率,基于光速 c 和 2 微米波长

fmax = c/(0.55e-6);

#计算最大频率,基于光速 c 和 0.55 微米波长

sourceCutoff = 15e-15;

#设置源截止时间为 15 飞秒,仅考虑源停止后的时间数据

## We are performing two runs of the same system, but with different symmetry

#我们将对同一系统进行两次运行,但使用不同的对称性

symmetryList = cell(2);

#创建一个包含 2 个元素的单元格数组,用于存储对称性条件

symmetryList{1} = “PEC”;

#第一个对称性性条件:理想导体体(Perfect Electric Conductor)

symmetryList{2} = “PMC”;

#第二个对称性性条件:理想磁体(Perfect Magnetic Conductor)

## We first make sure that the simulation region is set properly to only

#注释:我们首先确保仿真区域设置正确,仅

## mesh half the system

#注释:网格化系统的一半

switchtolayout;

#切换到布局模式

setnamed(“simulation region”,”x min boundary”,”closed”);

#设置仿真区域的 x 轴最小边界为封闭边界

setnamed(“simulation region”,”x min”,0);

#设置仿真区域的 x 轴最小值为 0

setnamed(“DGTD”,”use global excitation”,true);

#配置 DGTD 求解器使用全局激励

setnamed(“DGTD::point_monitor”,”enabled”,true);

#启用点监视器,用于测量特定点的场

setnamed(“DGTD::volume_monitor”,”enabled”,true);

#启用体积监视器,用于测量体积内的场分布

setnamed(“DGTD::plane_wave_source”,”enabled”,false);

#禁用平面波光源

setnamed(“DGTD::flux_monitor”,”enabled”,false);

#禁用通量监视器

## Use a loop to run two simulations with different boundary conditions

#注释:使用循环运行两个具有不同边界条件的仿真

for( curSymmetryIdx = 1:2 ) {

#开始循环,运行两次仿真,分别对应两种对称性条件

curSymmetry = symmetryList{curSymmetryIdx};

#获取当前对称性条件(PEC 或 PMC)

## Set the correct symmetry boundary condition

#注释:设置正确的对称边界条件

switchtolayout;

#切换到布局模式

setnamed(“DGTD::boundary conditions::PEC”,”enabled”,curSymmetry == “PEC”);

#根据当前对称性条件,启用或禁用 PEC 边界条件

setnamed(“DGTD::boundary conditions::PMC”,”enabled”,curSymmetry == “PMC”);

#根据当前对称性条件,启用或禁用 PMC 边界条件

## Run the simulation

#注释:运行仿真

run;

#执行仿真计算

# Get the time signal from a single point

#注释:从单个点获取时间信号

fields = getresult(“DGTD::point_monitor”,”fields”);

#从点监视器获取场数据

signal = real(fields.Ez);

#提取 Ez 场分量的实部作为信号

t = fields.time;

#获取时间数据

tFilter = find(t>=sourceCutoff);

#创建时间过滤器,仅保留源截止时间之后的数据

## Extract the resonance frequencies from the point data

#注释:从点数据中提取共振频率

r = findresonances(t(tFilter),signal(tFilter),[fmin,fmax]);

#使用 findresonances 函数从时间信号中提取共振频率,在 [fmin,fmax] 范围内

sizeR = size(r);

#获取共振结果的尺寸

## Print the results

#注释:打印结果

for( i = 1:sizeR(1)) {

#循环遍历每个找到的共振模式

?”Wavelength: ” + num2str(c/r(i,1)*1e9) +”nm, Q-factor: ” + num2str(r(i,3));

#打印每个共振模式的波长(转换为纳米)和品质因子 Q

}

#结束共振模式循环

## Extract the electric fields from the volume monitor and restrict them to

#注释:从体积监视器提取电场,并将其限制在

## the time after the sources is done

#注释:源关闭后的时间

fields = getresult(“DGTD::volume_monitor”,”fields”);

#从体积监视器获取场数据

t = fields.time;

#获取时间数据

tFilter = find(t>=sourceCutoff);

#创建时间过滤器,仅保留源截止时间之后的数据

t=t(tFilter);

#应用时间过滤器

Ex = real(pinch(fields.Ex(:,tFilter)));

#提取 Ex 场分量的实部,并压缩维度

Ey = real(pinch(fields.Ey(:,tFilter)));

#提取 Ey 场分量的实部,并压缩维度

Ez = real(pinch(fields.Ez(:,tFilter)));

#提取 Ez 场分量的实部,并压缩维度

## Setup a linear least-squares problem and solve it using SVD

#注释:设置线性最小二乘问题并使用 SVD 求解

w = 2*pi*r(:,1); alpha = r(:,2); phi = r(:,5);

#从共振结果中提取角频率、衰减系数和相位

A = matrix(length(t),length(w));

#创建一个矩阵 A,用于最小二乘拟合

tShifted = t-t(1);

#对时间进行偏移,从 t=0 开始

for(i=1:length(w)) { A(:,i) = cos(w(i)*tShifted-phi(i))*exp(-alpha(i)*tShifted); }

#填充矩阵 A,每列代表一个共振模式的衰减余弦函数

M = svd(A); U = M{1}; S = M{2}; V_ct = M{3};

#对矩阵 A 进行奇异值分解 (SVD)

for(i=1:min(size(S))) { if( abs(S(i,i)) > 0 ) { S(i,i) = 1/S(i,i); } }

#计算奇异值矩阵的伪逆

M_inv = mult(conj(U),S,conj(V_ct));

#计算矩阵 A 的伪逆

curModes = unstructureddataset(fields.x,fields.y,fields.z,fields.elements);

#创建一个非结构化数据集来存储模式数据

curModes.addparameter(“lambda”,c/r(:,1),”f”,r(:,1));

#向数据集中添加波长和频率参数

curModes.addattribute(“E”,mult(Ex,M_inv),mult(Ey,M_inv),mult(Ez,M_inv));

#计算并添加电场属性,通过将场数据与伪逆矩阵相乘来提取模式

## Depending on the symmetry, we need to unfold the data differently

#注释:根据对称性,我们需要以不同方式展开数据

if( curSymmetry == “PEC” ) {

#如果当前是 PEC 对称性

ModesPEC=unfoldsymmetricdata(curModes,'-x', 1.,-1.);

#使用 PEC 对称性展开数据,得到完整结构的模式

} else {

#否则(PMC 对称性)

ModesPMC=unfoldsymmetricdata(curModes,'-x',-1., 1.);

#使用 PMC 对称性展开数据,得到完整结构的模式

}

#结束对称性判断

## Clean up temporary variables

#注释:清理临时变量

clear(fields,signal,Ex,Ey,Ez,alpha,w,phi,sizeR,A,M,U,S,V_ct,M_inv,curModes,r);

#清除当前循环中的临时变量

}

#结束对称性循环

## Finally, we merge the symmetric and anti-symmetric modes into a single dataset and visualize it

#注释:最后,我们将对称和反对称模式合并到一个数据集中并可视化

plasmonicModes = unstructureddataset(ModesPEC.x,ModesPEC.y,ModesPEC.z,ModesPEC.elements);

#创建一个新的非结构化数据集,用于存储所有等离子体模式

plasmonicModes.addparameter(“lambda”,[ModesPEC.lambda;ModesPMC.lambda],”f”,[ModesPEC.f;ModesPMC.f]);

#合并波长和频率参数

plasmonicModes.addattribute(“E”,[pinch(ModesPEC.Ex),pinch(ModesPMC.Ex)],[pinch(ModesPEC.Ey),pinch(ModesPMC.Ey)],[pinch(ModesPEC.Ez),pinch(ModesPMC.Ez)]);

#合并电场属性

clear(ModesPEC,ModesPMC,t,tFilter,tShifted,symmetryList,curSymmetry,curSymmetryIdx,fmin,fmax,i,sourceCutoff);

#清除剩余的临时变量

visualize(plasmonicModes);

#可视化等离子体模式

#这段脚本通过利用对称性(PEC 和 PMC)来减少计算量,分别运行两次仿真,然后将结果展开以获得完整结构的等离子体模式。通过信号处理技术(如 SVD)从时间域数据中提取共振模式及其场分布,最后合并并可视化所有模式。

© 版权声明

相关文章

暂无评论

none
暂无评论...