test_py.py 2.3 KB

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