# FDTD自定义光源代码问题

#1

###### power

su=.5/sourcepower(f);#used for calculating cross sections
##scattering
#x monitors
if(mx==1){
temp =real(pinch(ey_x1conj(hz_x1)-ez_x1conj(hy_x1)));
px1=suintegrate(temp,1:2,x2y,x2z);}
temp =real(pinch(ey_x2
conj(hz_x2)-ez_x2conj(hy_x2)));
px2=su
integrate(temp,1:2,x2y,x2z);
#y monitors
if(my==1){
temp =real(pinch(ez_y1conj(hx_y1)-ex_y1conj(hz_y1)));
py1=suintegrate(temp,1:2,y2x,y2z);}
temp =real(pinch(ez_y2
conj(hx_y2)-ex_y2conj(hz_y2)));
py2=su
integrate(temp,1:2,y2x,y2z);
#z monitors
if(mz==1){
temp =real(pinch(ex_z1conj(hy_z1)-ey_z1conj(hx_z1)));
pz1=suintegrate(temp,1:2,z2x,z2y);}
temp =real(pinch(ex_z2
conj(hy_z2)-ey_z2conj(hx_z2)));
pz2=su
integrate(temp,1:2,z2x,z2y);

#totaling the power, for the case the source is along z axis
if( (mx==1) and (my==1) ){
P_scat=-px1+px2-py1+py2-pz1+pz2;

}
if( (mx==0) and (my==1) ){
P_scat= px2+px2-py1+py2-pz1+pz2;

}
if( (mx==1) and (my==0) ){
P_scat=-px1+px2+py2+py2-pz1+pz2;

}
if( (mx==0) and (my==0) ){
P_scat= px2+px2+py2+py2-pz1+pz2;

}
scat_cross= 1e12P_scatsourcepower(f)/ave_intensity;

#2

#3

# this script is used for a customerized TFSF using NA beam source

mx=0;my=0;mz=0;#1 means using symmetry/antisymmetry BCs, automatic detect

#obtain E, H and the power
if (havedata(“total::x1”)) {
mx=1;e_ref_x1=getresult(“total::x1”,“E”);
h_ref_x1=getresult(“total::x1”,“H”);
}
e_ref_x2=getresult(“total::x2”,“E”);
h_ref_x2=getresult(“total::x2”,“H”);

if( (mx==0) and (my==0) ){
P_scat= px2+px2+py2+py2-pz1+pz2;

#4