field.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python
  2. # This test case calculates the differential scattering
  3. # cross section from a Luneburg lens, as described in:
  4. # B. R. Johnson, Applied Optics 35 (1996) 3286-3296.
  5. # The Luneburg lens is a sphere of radius a, with a
  6. # radially-varying index of refraction, given by:
  7. # m(r) = [2 - (r/a)**1]**(1/2)
  8. # For the calculations, the Luneburg lens was approximated
  9. # as a multilayered sphere with 500 equally spaced layers.
  10. # The refractive index of each layer is defined to be equal to
  11. # m(r) at the midpoint of the layer: ml = [2 - (xm/xL)**1]**(1/2),
  12. # with xm = (xl-1 + xl)/2, for l = 1,2,...,L. The size
  13. # parameter in the lth layer is xl = l*xL/500. According to
  14. # geometrical optics theory, the differential cross section
  15. # can be expressed as:
  16. # d(Csca)/d(a**2*Omega) = cos(Theta)
  17. # The differential cross section from wave optics is:
  18. # d(Csca)/d(a**2*Omega) = S11(Theta)/x**2
  19. from scattnlay import fieldnlay
  20. import numpy as np
  21. x = np.ones((1, 1), dtype = np.float64)
  22. x[0, 0] = 1.
  23. m = np.ones((1, 1), dtype = np.complex128)
  24. m[0, 0] = (0.0252 + 2.0181j)/1.46
  25. nc = 1001
  26. coordX = np.zeros((nc, 3), dtype = np.float64)
  27. coordY = np.zeros((nc, 3), dtype = np.float64)
  28. coordZ = np.zeros((nc, 3), dtype = np.float64)
  29. scan = np.linspace(-10.0*x[0, 0], 10.0*x[0, 0], nc)
  30. one = np.ones(nc, dtype = np.float64)
  31. coordX[:, 0] = scan
  32. coordY[:, 1] = scan
  33. coordZ[:, 2] = scan
  34. terms, Ex, Hx = fieldnlay(x, m, coordX)
  35. terms, Ey, Hy = fieldnlay(x, m, coordY)
  36. terms, Ez, Hz = fieldnlay(x, m, coordZ)
  37. Exr = np.absolute(Ex)
  38. Eyr = np.absolute(Ey)
  39. Ezr = np.absolute(Ez)
  40. # |E|/|Eo|
  41. Exh = np.sqrt(Exr[0, :, 0]**2 + Exr[0, :, 1]**2 + Exr[0, :, 2]**2)
  42. Eyh = np.sqrt(Eyr[0, :, 0]**2 + Eyr[0, :, 1]**2 + Eyr[0, :, 2]**2)
  43. Ezh = np.sqrt(Ezr[0, :, 0]**2 + Ezr[0, :, 1]**2 + Ezr[0, :, 2]**2)
  44. result = np.vstack((scan, Exh, Eyh, Ezh)).transpose()
  45. try:
  46. import matplotlib.pyplot as plt
  47. fig = plt.figure()
  48. ax = fig.add_subplot(111)
  49. ax.errorbar(result[:, 0], one, fmt = 'k')
  50. ax.errorbar(result[:, 0], result[:, 1], fmt = 'r', label = 'X axis')
  51. ax.errorbar(result[:, 0], result[:, 2], fmt = 'g', label = 'Y axis')
  52. ax.errorbar(result[:, 0], result[:, 3], fmt = 'b', label = 'Z axis')
  53. ax.legend()
  54. plt.xlabel('X|Y|Z')
  55. plt.ylabel('|E|/|Eo|')
  56. plt.draw()
  57. plt.show()
  58. finally:
  59. np.savetxt("field.txt", result, fmt = "%.5f")
  60. print result