FDTD Script命令学习-farfield3dintegrate/farfieldspherical

本文介绍了FDTD仿真中的两个关键命令:farfield3dintegrate用于在锥形区域内对3D远场投影数据进行积分,而farfieldspherical则将远场数据转换为球坐标系。这两个命令涉及的角度参数以度为单位但在计算中转换为弧度。示例代码展示了如何使用这些命令来计算特定锥形区域内的能量比例以及生成球坐标系下的电场分布图像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、farfield3dintegrate命令介绍
(1)语法
(2)示例
二、farfieldspherical命令介绍
(1)语法

(2)示例

一、参考FDTD官网farfield3dintegrate命令介绍:

https://optics.ansys.com/hc/en-us/articles/360034410174-farfield3dintegrate-Script-command

1. farfield3dintegrate命令功能:在3D模拟中,在以立体角theta0(与z轴的夹角)和方位角phi0(与x轴的夹角) 为中心、在指定的半角宽度的锥形区域下的远场投影积分。远场电场是方向余弦(ux,uy)的函数,但是farfileld3dintegrate会自动对变量进行变更(根据下一句话,应该是进行单位换算)。类似的,角度是指定以度为单位,但是进行积分计算前会转化为弧度。不同监视器取向ux,uy,na,nb的介绍可以参考farfield3d命令介绍。

(1)语法:out=farfield3dintegrate(E2,ux,uy,halfangle,theta0,phi0);见上述积分公式,该语法是对3D远场投影数据的积分。

参数默认值类型描述
E2必须矩阵来自于farfield3d的电场数据
ux必须矢量来自于farfieldux。注意这个结果是个矢量,因此只在一个频率点下执行farfieldux脚本命令就足够了。
uy必须矢量来自于farfielduy。注意这个结果是个矢量,因此只在一个频率点下执行farfieldux脚本命令就足够了。
halfangle可选90矢量积分锥形区域的半角大小,单位为度,长度必须为L或1(维度相关长度?)。半角应该在0-90°之间。
theta0可选0矢量积分锥形区域的中心较theta,单位为度,长度必须为L或1。Theta0必须在0-90°之间。
phi0可选0矢量积分的锥形区域的中心角,单位为度,长度必须为L或1。phi0必须在0-360°之间。

(2)示例

计算光源达到中心角theta=phi=0,30°的锥形远场区域的能量比例。

代码如下:
m="monitor1"; 
res = 201;
E2 = farfield3d(m,1,res,res); #返回远场投影的电场强度数据,结果为201*201阶矩阵;
ux = farfieldux(m,1,res,res);#返回结果为201*201阶矩阵,方向矢量;
uy = farfielduy(m,1,res,res);
halfangle=30;#半角大小为30°
theta0=0;
phi0=0;
cone_30 = farfield3dintegrate(E2, ux, uy, halfangle, theta0, phi0); # integrate over 30 degree cone,采用上述公式进行积分计算;
total = farfield3dintegrate(E2, ux, uy); # integrate over entire hemisphere,对半角大小为90°的半球电场强度进行积分计算;
T   = transmission(m); # fraction of source power transmitted into far field,返回监视器monitor1中的透过率数据;
?cone_30/total;  # fraction of far field power within a 30 degree cone,显示投影到远场中半角大小为30°电场强度与整个半球远场区域的电场强度比例;
?cone_30/total*T; # fraction of source power transmitted into the far field within a 30 degree cone,显示投影到远场中半角大小为30°电场强度与整个光源的强度比例;

附:transmission命令可以参考:https://optics.ansys.com/hc/en-us/articles/360034405354-transmission-Script-command

二、参考FDTD官网farfieldspherical命令介绍:

https://optics.ansys.com/hc/en-us/articles/360034410194-farfieldspherical-Script-command

 1. farfieldspherical命令功能:将3D模拟的远场电场E(ux,uy)数据转换到球坐标系下一位阵列的电场E(theta,phi)中。远场投影函数一般会返回关于ux,uy(方向余弦)函数的投影。farfieldspherical用来将这个远场投影数据转化为到更加普遍的theta,phi单位中(功能即坐标系的转化:三维笛卡尔坐标系转换为球坐标系)。不同监视器取向ux,uy,na,nb的介绍可以参考farfield3d命令介绍。

(1)语法:out=farfieldspherical(E2,ux,uy,theta,phi);将远场数据转化为球坐标系下的数据。输出结果为维度为(M*N,1)(其中M和N分别为nb和na的投影分辨率);

参数数值类型描述
E2必须矩阵来自于farfield3d的电场数据
ux必须矢量来自于farfieldux的ux数据。注意这个结果是个矢量,因此只在一个频率点下执行farfieldux脚本命令就足够了。
uy必须矢量来自于farfielduy的uy数据。注意这个结果是个矢量,因此只在一个频率点下执行farfielduy脚本命令就足够了。
theta必须矢量立体角θ矢量,以度为单位。长度必须为M或者1。
phi必须矢量方位角φ矢量,以度为单位。长度必须为N或者1。

(2)示例1:生成E2_far关于立体角theta的图片,方位角phi=0;

代码如下:

m="Monitor1";  # Monitor name
res = 201;    # projection resolution
E2 = farfield3d(m,1,res,res);
ux = farfieldux(m,1,res,res);
uy = farfielduy(m,1,res,res);
theta = linspace(-90,90,100); #theta角取值范围[-90,90],等间隔取100个点位
phi = 0;
plot(theta, farfieldspherical(E2,ux,uy,theta,phi) ,"theta", "E^2", "E^2 at phi=0");#以theta为x轴,farfieldspherical为轴,"theta"为x轴名称,“E^2”为y轴名称,“E^2 at phi=0”为图片名称,进行作图

示例2:将厂数据转化为以theta和phi角网格坐标系下。

代码如下:

theta = linspace(-90,90,10);
phi = linspace(0,45,11);
Theta = meshgridx(theta,phi); #将theta数据转化为11*10阶矩阵,其中矩阵中每行数据中元素为原始theta矩阵中的元素,且每行元素均相同
Phi = meshgridy(theta,phi);#将phi数据转化为11*10阶矩阵
E2_angle = farfieldspherical(E2,ux,uy,Theta,Phi);
E2_angle = reshape(E2_angle, [length(theta), length(phi)]);#将E2_angle矩阵11*10转换为10*11阶矩阵
image(theta, phi, E2_angle, "theta","phi","E2");#以theta为x轴,phi为y轴,对z进行作图,“theta”为x轴名称,“phi”为y轴名称,“E2”为图片名称

(3)其它参考

List of commands farfield3d farfieldux farfielduy Far field projections - Direction unit vector coordinates meshgridx meshgridy

%*********************************************************************** % 3-D FDTD code with PEC boundaries %*********************************************************************** % % Program author: Susan C. Hagness % Department of Electrical and Computer Engineering % University of Wisconsin-Madison % 1415 Engineering Drive % Madison, WI 53706-1691 % 608-265-5739 % hagness@engr.wisc.edu % % Date of this version: February 2000 % % This MATLAB M-file implements the finite-difference time-domain % solution of Maxwell's curl equations over a three-dimensional % Cartesian space lattice comprised of uniform cubic grid cells. % % To illustrate the algorithm, an air-filled rectangular cavity % resonator (充气矩形空腔谐振器) is modeled. The length, width, and height of the % cavity are 10.0 cm (x-direction), 4.8 cm (y-direction), and % 2.0 cm (z-direction), respectively. % % The computational domain is truncated using PEC boundary % conditions: % ex(i,j,k)=0 on the j=1, j=jb, k=1, and k=kb planes % ey(i,j,k)=0 on the i=1, i=ib, k=1, and k=kb planes % ez(i,j,k)=0 on the i=1, i=ib, j=1, and j=jb planes % These PEC boundaries form the outer lossless walls of the cavity. % % The cavity is excited by an additive current source oriented % along the z-direction. The source waveform is a differentiated % Gaussian pulse given by % J(t)=-J0*(t-t0)*exp(-(t-t0)^2/tau^2), % where tau=50 ps. The FWHM ( 半最大值全宽度(full width at half maximum)) % spectral bandwidth of this zero-dc- % content pulse is approximately 7 GHz. The grid resolution (分辨率) % (dx = 2 mm) was chosen to provide at least 10 samples per % wavelength up through 15 GHz. % % To execute this M-file, type "fdtd3D" at the MATLAB prompt. % This M-file displays the FDTD-computed Ez fields at every other % time step (第一个时间步), and records those frames in a movie matrix, M, which % is played at the end of the simulation using the "movie" command. % %*********************************************************************** clear %*********************************************************************** % Fundamental constants %*********************************************************************** cc=2.99792458e8; %speed of light in free space muz=4.0*pi*1.0e-7; %permeability of free space epsz=1.0/(cc*cc*muz); %permittivity of free space %*********************************************************************** % Grid parameters %*********************************************************************** ie=50; %number of grid cells in x-direction je=24; %number of grid cells in y-direction ke=10; %number of grid cells in z-direction ib=ie+1; jb=je+1; kb=ke+1; is=26; %location of z-directed current source js=13; %location of z-directed current source kobs=5; dx=0.002; %space increment of cubic lattice dt=dx/(2.0*cc); %time step nmax=500; %total number of time steps %*********************************************************************** % Differentiated Gaussian pulse excitation %*********************************************************************** rtau=50.0e-12; tau=rtau/dt; ndelay=3*tau; srcconst=-dt*3.0e+11; %*********************************************************************** % Material parameters %*********************************************************************** eps=1.0; %相对介电常数 epsz,真空介电常数 sig=0.0; %相对电阻率 %*********************************************************************** % Updating coefficients %*********************************************************************** ca=(1.0-(dt*sig)/(2.0*epsz*eps))/(1.0+(dt*sig)/(2.0*epsz*eps)); cb=(dt/epsz/eps/dx)/(1.0+(dt*sig)/(2.0*epsz*eps)); da=1.0; db=dt/muz/dx; %*********************************************************************** % Field arrays %*********************************************************************** ex=zeros(ie,jb,kb); ey=zeros(ib,je,kb); ez=zeros(ib,jb,ke); hx=zeros(ib,je,ke); hy=zeros(ie,jb,ke); hz=zeros(ie,je,kb); %*********************************************************************** % Movie initialization %*********************************************************************** tview(:,:)=ez(:,:,kobs); sview(:,:)=ez(:,js,:); subplot('position',[0.15 0.45 0.7 0.45]), pcolor(tview'); %shading flat; %caxis([-1.0 1.0]); %colorbar; %axis image; title(['Ez(i,j,k=5), time step = 0']); xlabel('i coordinate'); ylabel('j coordinate'); subplot('position',[0.15 0.10 0.7 0.25]), pcolor(sview'); %shading flat; %caxis([-1.0 1.0]); %colorbar; %axis image; title(['Ez(i,j=13,k), time step = 0']); xlabel('i coordinate'); ylabel('k coordinate'); rect=get(gcf,'Position'); rect(1:2)=[0 0]; M=moviein(nmax/2,gcf,rect); %*********************************************************************** % BEGIN TIME-STEPPING LOOP %*********************************************************************** for n=1:nmax %*********************************************************************** % Update electric fields %*********************************************************************** ex(1:ie,2:je,2:ke)=ca*ex(1:ie,2:je,2:ke)+... cb*(hz(1:ie,2:je,2:ke)-hz(1:ie,1:je-1,2:ke)+... hy(1:ie,2:je,1:ke-1)-hy(1:ie,2:je,2:ke)); ey(2:ie,1:je,2:ke)=ca*ey(2:ie,1:je,2:ke)+... cb*(hx(2:ie,1:je,2:ke)-hx(2:ie,1:je,1:ke-1)+... hz(1:ie-1,1:je,2:ke)-hz(2:ie,1:je,2:ke)); ez(2:ie,2:je,1:ke)=ca*ez(2:ie,2:je,1:ke)+... cb*(hx(2:ie,1:je-1,1:ke)-hx(2:ie,2:je,1:ke)+... hy(2:ie,2:je,1:ke)-hy(1:ie-1,2:je,1:ke)); ez(is,js,1:ke)=ez(is,js,1:ke)+... srcconst*(n-ndelay)*exp(-((n-ndelay)^2/tau^2)); % J(t)=-J0*(t-t0)*exp(-(t-t0)^2/tau^2) %*********************************************************************** % Update magnetic fields %*********************************************************************** hx(2:ie,1:je,1:ke)=hx(2:ie,1:je,1:ke)+... db*(ey(2:ie,1:je,2:kb)-ey(2:ie,1:je,1:ke)+... ez(2:ie,1:je,1:ke)-ez(2:ie,2:jb,1:ke)); hy(1:ie,2:je,1:ke)=hy(1:ie,2:je,1:ke)+... db*(ex(1:ie,2:je,1:ke)-ex(1:ie,2:je,2:kb)+... ez(2:ib,2:je,1:ke)-ez(1:ie,2:je,1:ke)); hz(1:ie,1:je,2:ke)=hz(1:ie,1:je,2:ke)+... db*(ex(1:ie,2:jb,2:ke)-ex(1:ie,1:je,2:ke)+... ey(1:ie,1:je,2:ke)-ey(2:ib,1:je,2:ke)); %*********************************************************************** % Visualize fields %*********************************************************************** if mod(n,2)==0; timestep=int2str(n); tview(:,:)=ez(:,:,kobs); sview(:,:)=ez(:,js,:); subplot('position',[0.15 0.45 0.7 0.45]), pcolor(tview'); % shading flat; % caxis([-1.0 1.0]); % colorbar; % axis image; title(['Ez(i,j,k=5), time step = ',timestep]); xlabel('i coordinate'); ylabel('j coordinate'); subplot('position',[0.15 0.10 0.7 0.25]), pcolor(sview'); % shading flat; % caxis([-1.0 1.0]); % colorbar; % axis image; title(['Ez(i,j=13,k), time step = ',timestep]); xlabel('i coordinate'); ylabel('k coordinate'); nn=n/2; M(:,nn)=getframe(gcf,rect); end; %*********************************************************************** % END TIME-STEPPING LOOP %*********************************************************************** end movie(gcf,M,0,10,rect);
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值