123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- from scattnlay import fieldnlay
- import numpy as np
- n1 = 1.46
- nm = 1.0
- x = np.ones((1, 1), dtype = np.float64)
- x[0, 0] = 5.0
- m = np.ones((1, 1), dtype = np.complex128)
- m[0, 0] = n1/nm
- print "x =", x
- print "m =", m
- npts = 1001
- scan = np.linspace(-3.0*x[0, -1], 3.0*x[0, -1], npts)
- coordX, coordZ = np.meshgrid(scan, scan)
- coordX.resize(npts*npts)
- coordZ.resize(npts*npts)
- coordY = np.zeros(npts*npts, dtype = np.float64)
- coord = np.vstack((coordX, coordY, coordZ)).transpose()
- terms, E, H = fieldnlay(x, m, coord)
- Er = np.absolute(E)
- Eh = np.sqrt(Er[0, :, 0]**2 + Er[0, :, 1]**2 + Er[0, :, 2]**2)
- result = np.vstack((coordX, coordY, coordZ, Eh)).transpose()
- try:
- import matplotlib.pyplot as plt
- from matplotlib import cm
- from matplotlib.colors import LogNorm
- min_tick = 0.5
- max_tick = 1.0
- edata = np.resize(Eh, (npts, npts)).transpose()
- fig = plt.figure()
- ax = fig.add_subplot(111)
-
- scale_x = np.linspace(min(coordX), max(coordX), npts)
- scale_z = np.linspace(min(coordZ), max(coordZ), npts)
-
- min_tick = min(min_tick, np.amin(edata))
- max_tick = max(max_tick, np.amax(edata))
- scale_ticks = np.power(10.0, np.linspace(np.log10(min_tick), np.log10(max_tick), 6))
-
-
- cax = ax.imshow(edata, interpolation = 'nearest', cmap = cm.jet,
- origin = 'lower', vmin = min_tick, vmax = max_tick,
- extent = (min(scale_z), max(scale_z), min(scale_x), max(scale_x)),
- norm = LogNorm())
-
- cbar = fig.colorbar(cax, ticks = [a for a in scale_ticks])
- cbar.ax.set_yticklabels(['%4.2g' % (a) for a in scale_ticks])
- pos = list(cbar.ax.get_position().bounds)
- fig.text(pos[0] - 0.02, 0.925, '|E|/|E$_0$|', fontsize = 14)
- plt.xlabel('Z')
- plt.ylabel('X')
-
- from matplotlib import patches
- s1 = patches.Arc((0, 0), 2.0*x[0, 0], 2.0*x[0, 0], angle=0.0, zorder=2,
- theta1=0.0, theta2=360.0, linewidth=1, color='black')
- ax.add_patch(s1)
-
- plt.draw()
- plt.show()
- plt.clf()
- plt.close()
- finally:
- np.savetxt("field-silica.txt", result, fmt = "%.5f")
- print result
|