test_py.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import unittest
  2. from scattnlay import mie, mie_mp
  3. from scattnlay import mesomie
  4. # A list of tests for a bulk sphere from
  5. # Hong Du, "Mie-scattering calculation," Appl. Opt. 43, 1951-1956 (2004)
  6. # table 1: sphere size and refractive index
  7. # followed by resulting extinction and scattering efficiencies
  8. test_cases = [
  9. # x, m, Qext, Qsca #, test_name
  10. [0.099, 0.75+0j, 7.417859e-06, 7.417859e-06], # ,'a'],
  11. [0.101, 0.75+0j, 8.033538e-06, 8.033538e-06], # ,'b'],
  12. [10, 0.75+0j, 2.232265, 2.232265], # ,'c'],
  13. [0.055, 1.5+1j, 0.10149104, 1.131687e-05], # ,'g'],
  14. [0.056, 1.5+1j, 0.1033467, 1.216311e-05], # ,'h'],
  15. [1, 10+10j, 2.532993, 2.049405], # ,'k'],
  16. [100, 1.33+1e-5j, 2.101321, 2.096594], # ,'e'],
  17. [100, 1.5+1j, 2.097502, 1.283697], # ,'i'],
  18. [1000, 0.75+0j, 1.997908, 1.997908], # ,'d'],
  19. [100, 10+10j, 2.071124, 1.836785], # ,'l'],
  20. [10000, 1.33+1e-5j, 2.004089, 1.723857], # ,'f'],
  21. [10000, 1.5+1j, 2.004368, 1.236574], # ,'j'],
  22. [10000, 10+10j, 2.005914, 1.795393], # ,'m'],
  23. ]
  24. class TestStringMethods(unittest.TestCase):
  25. def test_bulk_mesomie(self):
  26. tol = 3e-7
  27. for solver in [mesomie]:
  28. if solver is None:
  29. continue
  30. print('Using solver: ', solver)
  31. for case in test_cases:
  32. x = case[0]
  33. m = case[1]
  34. solver.calc_ab(x, # R
  35. x, # xd
  36. x * m, # xm
  37. 1, # eps_d
  38. m * m, # eps_m
  39. 0, # d_parallel
  40. 0) # d_perp
  41. solver.calc_Q()
  42. Qext = solver.GetQext()
  43. Qsca = solver.GetQsca()
  44. self.assertTrue((case[2]-Qext)/Qext < tol)
  45. self.assertTrue((case[3]-Qsca)/Qsca < tol)
  46. def test_bulk_multilayer(self):
  47. tol = 3e-7
  48. for solver in [mie, mie_mp]:
  49. if solver is None:
  50. continue
  51. print('Using solver: ', solver)
  52. for case in test_cases:
  53. solver.SetLayersSize(case[0])
  54. solver.SetLayersIndex(case[1])
  55. solver.RunMieCalculation()
  56. Qext = solver.GetQext()
  57. Qsca = solver.GetQsca()
  58. self.assertTrue((case[2]-Qext)/Qext < tol)
  59. self.assertTrue((case[3]-Qsca)/Qsca < tol)
  60. if __name__ == '__main__':
  61. unittest.main()