coating-flow.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2009-2015 Ovidio Peña Rodríguez <ovidio@bytesfall.com>
  5. #
  6. # This file is part of python-scattnlay
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # The only additional remark is that we expect that all publications
  19. # describing work using this software, or all commercial products
  20. # using it, cite the following reference:
  21. # [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
  22. # a multilayered sphere," Computer Physics Communications,
  23. # vol. 180, Nov. 2009, pp. 2348-2354.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. # This test case calculates the electric field in the
  28. # E-k plane, for an spherical Si-Ag-Si nanoparticle. Core radius is 17.74 nm,
  29. # inner layer 23.31nm, outer layer 22.95nm. Working wavelength is 800nm, we use
  30. # silicon epsilon=13.64+i0.047, silver epsilon= -28.05+i1.525
  31. import os, cmath
  32. import numpy as np
  33. from scattnlay import fieldnlay
  34. from fieldplot import fieldplot
  35. if __name__ == '__main__':
  36. import argparse
  37. parser = argparse.ArgumentParser()
  38. parser.add_argument("dirnames", nargs='*', default='.', help="read all data from DIR(S)")
  39. parser.add_argument("-f", "--filename", dest="fname", nargs='?', default=None,
  40. help="name of 'n' file")
  41. parser.add_argument("-w", "--wavelength", dest="wl", default=3.75, type=float,
  42. help="wavelength of electromagnetic wave")
  43. parser.add_argument("-r", "--radius", dest="rad", default=None, type=float,
  44. help="radius of PEC sphere")
  45. parser.add_argument("-t", "--thickness", dest="tc", default=0.8, type=float,
  46. help="thickness of cloaking layer")
  47. parser.add_argument("-n", "--npoints", dest="npts", default=101, type=int,
  48. help="number of points for the grid")
  49. args = parser.parse_args()
  50. for dirname in args.dirnames:
  51. print "Calculating spectra for data file(s) in dir '%s'..." % (dirname)
  52. wl = args.wl # cm
  53. if (args.rad is None):
  54. Rs = 0.75*wl # cm
  55. else:
  56. Rs = args.rad # cm
  57. tc = args.tc # cm
  58. if (args.fname is None):
  59. files = [x for x in os.listdir('%s/' % (dirname)) if x.endswith('.dat')]
  60. files.sort()
  61. else:
  62. files = [args.fname]
  63. npts = args.npts # cm
  64. if not os.path.exists('%s/flow-results/' % (dirname)):
  65. os.makedirs('%s/flow-results/' % (dirname))
  66. Rt = Rs + tc # cm
  67. print "Wl = %.2f, Rs = %.2f, tc = %.2f, Rt = %.2f" % (wl, Rs, tc, Rt)
  68. ms = 1.0 + 40.0j
  69. for i, fname in enumerate(files):
  70. print "Calculating spectra for file '%s'..." % (fname)
  71. basename = os.path.splitext(fname)[0]
  72. nvalues = np.loadtxt('%s/%s' % (dirname, fname))*1.0 + 1e-11j
  73. tl = tc/len(nvalues) # cm
  74. r = [Rs]
  75. for i in range(len(nvalues)):
  76. r += [r[i] + tl]
  77. x = np.ones((1, len(nvalues) + 1), dtype = np.float64)
  78. m = np.ones((1, len(nvalues) + 1), dtype = np.complex128)
  79. x[0] = 2.0*np.pi*np.array(r, dtype = np.float64)/wl
  80. m[0] = np.array([ms] + nvalues[:, 1].tolist(), dtype = np.complex128)
  81. print(x,m)
  82. factor = 2
  83. comment='PEC-'+basename
  84. WL_units='cm'
  85. #flow_total = 39
  86. flow_total = 25
  87. crossplane='XZ'
  88. #crossplane='YZ'
  89. #crossplane='XY'
  90. # Options to plot: Eabs, Habs, Pabs, angleEx, angleHy
  91. field_to_plot='Pabs'
  92. #field_to_plot='Eabs'
  93. #field_to_plot='angleEx'
  94. fieldplot(x[0],m[0], wl, comment, WL_units, crossplane, field_to_plot, npts,
  95. factor, flow_total, pl=0, outline_width=2.0)
  96. print "Done!!"