#############################################################
# scriptfile: dipole_2layer.lsf
#
# This file calculates the reflection spectrum for
# a single dielectric interface. It does both polarizations
# (TE and TM) and compares to the analytic result.
#
# Copyright 2012, Lumerical Solutions, Inc.
#############################################################
# Select which simulation to run
sweepname="2layer";
# choose to rerun or load simulations previously run
#runsweep;
f = getsweepdata(sweepname,"f");
theta = getsweepdata(sweepname,"theta");
n = getsweepdata(sweepname,"n");
d = getsweepdata(sweepname,"d");
Rs_fdtd = pinch(getsweepdata(sweepname,"r"),2,1);
Ts_fdtd = pinch(getsweepdata(sweepname,"t"),2,1);
Rp_fdtd = pinch(getsweepdata(sweepname,"r"),2,2);
Tp_fdtd = pinch(getsweepdata(sweepname,"t"),2,2);
# calculate the analytic response of the system
RT_Theory = stackrt(n,d,f,theta);
# compare to theoretical values
plot(theta,Rs_fdtd,RT_Theory.Rs,Rp_fdtd,RT_Theory.Rp,"angle (degrees)","Reflection","Reflection vs angle");
legend("S FDTD","S Theory","P FDTD","P Theory");
plot(theta,Ts_fdtd,RT_Theory.Ts,Tp_fdtd,RT_Theory.Tp,"angle (degrees)","Transmission","Transmission vs incident angle");
legend("S FDTD","S Theory","P FDTD","P Theory");