#准相位匹配情况下的比较，仅适用于SHGtry3.fsp。

#仿真计算
nonorm; #非归一化状态
T_w0=matrix(1,100); 
T_2w0=matrix(1,100);
f1=getdata("source","f");#基频
L=matrix(1,100);
for(i=1:100){
   T_w0(i)=transmission("w_0::w0"+num2str(i));
   T_2w0(i)=transmission("2w_0::2w0"+num2str(i));
   L(i)=i*0.1e-6;
}
power_w0=T_w0*sourcepower(f);
power_2w0=T_2w0*sourcepower(2*f);
conversion_efficiency=power_2w0/power_w0;


#理论计算
cwnorm;
omega1=2*pi*f1;#基频圆频率
omega2=2*omega1;#倍频圆频率
I=sourceintensity(f1);#基频光强(在cwnorm状态下才能得到与物理光学中公式一致的光强)
n1=real(getindex("nonlinear",f));#基频折射率
n2=real(getindex("nonlinear",2*f));#倍频折射率
chi2=getmaterial("nonlinear","χ 2");#二阶非线性极化率
deff=2/pi*chi2(1)/2;
k1=n1*omega1/c;
k2=n2*omega2/c;
deltak=0;#相位失配量
if(deltak==0){
    sinc=1;
}
else{sinc=sin(deltak*L/2)/(deltak*L/2);}

#系数是1的公式
#convention_efficiency_theory=8*(omega1*deff*L*sinc)^2*I/(eps0*c^3*n1^2*n2);

#系数是1/2的公式
convention_efficiency_theory=2*(omega1*deff*L*sinc)^2*I/(eps0*c^3*n1^2*n2);

plot(L*1e06,power_w0,power_2w0,"L(microns)","power_out");
legend('w0',"2w0");
plot(L*1e06,conversion_efficiency,convention_efficiency_theory,"L(microns)","convention_efficiency");
legend('simulation','theory');