Skip to content

Commit

Permalink
Merge pull request #1 from NanoComp/master
Browse files Browse the repository at this point in the history
sync docs with meep main
  • Loading branch information
theogdoctorg authored Dec 5, 2023
2 parents c40e811 + 7e747d2 commit bf1eec0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 38 deletions.
88 changes: 50 additions & 38 deletions doc/docs/Python_Tutorials/Basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,31 +572,6 @@ wvl = f[:,1]
# create a 2d matrix for the wavelength by repeating the column vector for each angle
wvls = np.matlib.repmat(np.reshape(wvl, (wvl.size,1)),1,theta_in.size)

plt.figure()
plt.pcolormesh(kxs, wvls, Rmeep, cmap='hot', shading='gouraud', vmin=0, vmax=Rmeep.max())
plt.axis([kxs[0,0], kxs[0,-1], wvl[-1], wvl[0]])
plt.yticks([t for t in np.arange(0.4,0.9,0.1)])
plt.xlabel("Bloch-periodic wavevector ($k_x/2π$)")
plt.ylabel("wavelength (μm)")
plt.title("reflectance (meep)")
cbar = plt.colorbar()
cbar.set_ticks([t for t in np.arange(0,0.4,0.1)])
cbar.set_ticklabels(["{:.1f}".format(t) for t in np.arange(0,0.4,0.1)])
plt.show()

plt.figure()
plt.pcolormesh(thetas, wvls, Rmeep, cmap='hot', shading='gouraud', vmin=0, vmax=Rmeep.max())
plt.axis([thetas.min(), thetas.max(), wvl[-1], wvl[0]])
plt.xticks([t for t in range(0,100,20)])
plt.yticks([t for t in np.arange(0.4,0.9,0.1)])
plt.xlabel("angle of incident planewave (degrees)")
plt.ylabel("wavelength (μm)")
plt.title("reflectance (meep)")
cbar = plt.colorbar()
cbar.set_ticks([t for t in np.arange(0,0.4,0.1)])
cbar.set_ticklabels(["{:.1f}".format(t) for t in np.arange(0,0.4,0.1)])
plt.show()

n1=1
n2=3.5

Expand All @@ -606,25 +581,62 @@ theta_out = lambda theta_in: math.asin(n1*math.sin(theta_in)/n2)

# compute Fresnel reflectance for P-polarization in medium n2
# for incident planewave in medium n1 at angle theta_in
Rfresnel = lambda theta_in: math.fabs((n1*math.cos(theta_out(theta_in))-n2*math.cos(theta_in))/(n1*math.cos(theta_out(theta_in))+n2*math.cos(theta_in)))**2
Rfresnel = lambda theta_in: math.fabs((n1*math.cos(theta_out(theta_in)) -
n2*math.cos(theta_in)) /
(n1*math.cos(theta_out(theta_in)) +
n2*math.cos(theta_in)))**2

Ranalytic = np.empty((50, theta_in.size))
for m in range(wvl.size):
for n in range(theta_in.size):
Ranalytic[m,n] = Rfresnel(math.radians(thetas[m,n]))

plt.figure()
plt.pcolormesh(thetas, wvls, Ranalytic, cmap='hot', shading='gouraud', vmin=0, vmax=Ranalytic.max())
plt.axis([thetas.min(), thetas.max(), wvl[-1], wvl[0]])
plt.xticks([t for t in range(0,100,20)])
plt.yticks([t for t in np.arange(0.4,0.9,0.1)])
plt.xlabel("angle of incident planewave (degrees)")
plt.ylabel("wavelength (μm)")
plt.title("reflectance (analytic)")
cbar = plt.colorbar()
cbar.set_ticks([t for t in np.arange(0,0.4,0.1)])
cbar.set_ticklabels(["{:.1f}".format(t) for t in np.arange(0,0.4,0.1)])
plt.show()
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(9,6))

wvl_idx = 0
axs[0, 0].plot(theta_in,Rmeep[wvl_idx,:], 'bo-', label="meep")
axs[0, 0].plot(theta_in,Ranalytic[wvl_idx,:], 'ro-', label="analytic")
axs[0, 0].set_xlabel("angle of incident planewave (degrees)")
axs[0, 0].set_ylabel(f"reflectance at $\lambda$ = {wvl[wvl_idx]:.1f} μm")
axs[0, 0].legend()

pc = axs[0, 1].pcolormesh(kxs, wvls, Rmeep, cmap='hot_r', shading='gouraud',
vmin=0, vmax=Rmeep.max())
axs[0, 1].axis([kxs[0,0], kxs[0,-1], wvl[-1], wvl[0]])
axs[0, 1].set_yticks([t for t in np.arange(wvl[-1], wvl[0] + 0.1, 0.1)])
axs[0, 1].set_xlabel("Bloch-periodic wavevector ($k_x/2π$)")
axs[0, 1].set_ylabel("wavelength (μm)")
axs[0, 1].set_title("reflectance (meep)")
cbar = fig.colorbar(pc, ax=axs[0, 1])
cbar.set_ticks([t for t in np.arange(0, 0.4, 0.1)])
cbar.set_ticklabels(["{:.1f}".format(t) for t in np.arange(0, 0.4, 0.1)])

pc = axs[1, 0].pcolormesh(thetas, wvls, Rmeep, cmap='hot_r', shading='gouraud',
vmin=0, vmax=Rmeep.max())
axs[1, 0].axis([thetas.min(), thetas.max(), wvl[-1], wvl[0]])
axs[1, 0].set_xticks([t for t in range(0,100,20)])
axs[1, 0].set_yticks([t for t in np.arange(wvl[-1], wvl[0] + 0.1, 0.1)])
axs[1, 0].set_xlabel("angle of incident planewave (degrees)")
axs[1, 0].set_ylabel("wavelength (μm)")
axs[1, 0].set_title("reflectance (meep)")
cbar = fig.colorbar(pc, ax=axs[1, 0])
cbar.set_ticks([t for t in np.arange(0, 0.4, 0.1)])
cbar.set_ticklabels(["{:.1f}".format(t) for t in np.arange(0, 0.4, 0.1)])

pc = axs[1, 1].pcolormesh(thetas, wvls, Ranalytic, cmap='hot_r', shading='gouraud',
vmin=0, vmax=Ranalytic.max())
axs[1, 1].axis([thetas.min(), thetas.max(), wvl[-1], wvl[0]])
axs[1, 1].set_xticks([t for t in range(0,100,20)])
axs[1, 1].set_yticks([t for t in np.arange(wvl[-1], wvl[0] + 0.1, 0.1)])
axs[1, 1].set_xlabel("angle of incident planewave (degrees)")
axs[1, 1].set_ylabel("wavelength (μm)")
axs[1, 1].set_title("reflectance (analytic)")
cbar = fig.colorbar(pc, ax=axs[1, 1])
cbar.set_ticks([t for t in np.arange(0, 0.4, 0.1)])
cbar.set_ticklabels(["{:.1f}".format(t) for t in np.arange(0, 0.4, 0.1)])

fig.tight_layout()
fig.savefig('reflectance_angular_spectrum.png', bbox_inches='tight', dpi=150)
```

![](../images/reflectance_angular_spectrum.png#center)
Expand Down
Binary file modified doc/docs/images/reflectance_angular_spectrum.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bf1eec0

Please sign in to comment.