123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- from scattnlay import fieldnlay
- import numpy as np
- nL = 10
- Xmax = 60.0
- x = np.array([np.linspace(Xmax/nL, Xmax, nL)], dtype = np.float64)
- m = np.array((np.sqrt((2.0 - (x[0]/Xmax - 0.5/nL)**2.0))), dtype = np.complex128)
- print "x =", x
- print "m =", m
- npts = 100
- scan = np.linspace(-3*Xmax, 3*Xmax, npts)
- coordX, coordY = np.meshgrid(scan, scan)
- coordX.resize(npts*npts)
- coordY.resize(npts*npts)
- coordZ = np.zeros(npts*npts, dtype = np.float64)
- terms, E, H = fieldnlay(x, m, coordX, coordY, coordZ)
- print "E", E
- Er = np.absolute(E)
- print "Er", Er
- Eh = np.sqrt(Er[0, :, 0]**2 + Er[0, :, 1]**2 + Er[0, :, 2]**2)
- print "Eh", Eh
- 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.1
- max_tick = 1.0
- edata = np.resize(Eh, (npts, npts))
- fig = plt.figure()
- ax = fig.add_subplot(111)
-
- scale_x = np.linspace(min(coordX), max(coordX), npts)
- scale_y = np.linspace(min(coordY), max(coordY), npts)
-
- print np.amin(edata), np.amax(edata)
- min_tick = 0.
- max_tick = 10.0
- scale_ticks = np.linspace(min_tick, max_tick, 6)
-
-
- cax = ax.imshow(edata, interpolation = 'nearest', cmap = cm.jet,
- origin = 'lower', vmin = min_tick, vmax = max_tick,
- extent = (min(scale_x), max(scale_x), min(scale_y), max(scale_y)))
-
-
- cbar = fig.colorbar(cax, ticks = [a for a in scale_ticks])
- cbar.ax.set_yticklabels(['%3.1e' % (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('X')
- plt.ylabel('Y')
-
- from matplotlib import patches
- s1 = patches.Arc((0, 0), 2.0*Xmax, 2.0*Xmax, angle=0.0, zorder=2,
- theta1=0.0, theta2=360.0, linewidth=1, color='#00fa9a')
- ax.add_patch(s1)
-
- plt.draw()
- plt.show()
- plt.clf()
- plt.close()
- finally:
- np.savetxt("test04_field.txt", result, fmt = "%.5f")
- print result
|