m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.9 KiB

7 months ago
  1. from sympy.core.evalf import N
  2. from sympy.core.numbers import (Float, I, oo, pi)
  3. from sympy.core.symbol import symbols
  4. from sympy.functions.elementary.miscellaneous import sqrt
  5. from sympy.functions.elementary.trigonometric import atan2
  6. from sympy.matrices.dense import Matrix
  7. from sympy.polys.polytools import factor
  8. from sympy.physics.optics import (BeamParameter, CurvedMirror,
  9. CurvedRefraction, FlatMirror, FlatRefraction, FreeSpace, GeometricRay,
  10. RayTransferMatrix, ThinLens, conjugate_gauss_beams,
  11. gaussian_conj, geometric_conj_ab, geometric_conj_af, geometric_conj_bf,
  12. rayleigh2waist, waist2rayleigh)
  13. def streq(a, b):
  14. return str(a) == str(b)
  15. def test_gauss_opt():
  16. mat = RayTransferMatrix(1, 2, 3, 4)
  17. assert mat == Matrix([[1, 2], [3, 4]])
  18. assert mat == RayTransferMatrix( Matrix([[1, 2], [3, 4]]) )
  19. assert [mat.A, mat.B, mat.C, mat.D] == [1, 2, 3, 4]
  20. d, f, h, n1, n2, R = symbols('d f h n1 n2 R')
  21. lens = ThinLens(f)
  22. assert lens == Matrix([[ 1, 0], [-1/f, 1]])
  23. assert lens.C == -1/f
  24. assert FreeSpace(d) == Matrix([[ 1, d], [0, 1]])
  25. assert FlatRefraction(n1, n2) == Matrix([[1, 0], [0, n1/n2]])
  26. assert CurvedRefraction(
  27. R, n1, n2) == Matrix([[1, 0], [(n1 - n2)/(R*n2), n1/n2]])
  28. assert FlatMirror() == Matrix([[1, 0], [0, 1]])
  29. assert CurvedMirror(R) == Matrix([[ 1, 0], [-2/R, 1]])
  30. assert ThinLens(f) == Matrix([[ 1, 0], [-1/f, 1]])
  31. mul = CurvedMirror(R)*FreeSpace(d)
  32. mul_mat = Matrix([[ 1, 0], [-2/R, 1]])*Matrix([[ 1, d], [0, 1]])
  33. assert mul.A == mul_mat[0, 0]
  34. assert mul.B == mul_mat[0, 1]
  35. assert mul.C == mul_mat[1, 0]
  36. assert mul.D == mul_mat[1, 1]
  37. angle = symbols('angle')
  38. assert GeometricRay(h, angle) == Matrix([[ h], [angle]])
  39. assert FreeSpace(
  40. d)*GeometricRay(h, angle) == Matrix([[angle*d + h], [angle]])
  41. assert GeometricRay( Matrix( ((h,), (angle,)) ) ) == Matrix([[h], [angle]])
  42. assert (FreeSpace(d)*GeometricRay(h, angle)).height == angle*d + h
  43. assert (FreeSpace(d)*GeometricRay(h, angle)).angle == angle
  44. p = BeamParameter(530e-9, 1, w=1e-3)
  45. assert streq(p.q, 1 + 1.88679245283019*I*pi)
  46. assert streq(N(p.q), 1.0 + 5.92753330865999*I)
  47. assert streq(N(p.w_0), Float(0.00100000000000000))
  48. assert streq(N(p.z_r), Float(5.92753330865999))
  49. fs = FreeSpace(10)
  50. p1 = fs*p
  51. assert streq(N(p.w), Float(0.00101413072159615))
  52. assert streq(N(p1.w), Float(0.00210803120913829))
  53. w, wavelen = symbols('w wavelen')
  54. assert waist2rayleigh(w, wavelen) == pi*w**2/wavelen
  55. z_r, wavelen = symbols('z_r wavelen')
  56. assert rayleigh2waist(z_r, wavelen) == sqrt(wavelen*z_r)/sqrt(pi)
  57. a, b, f = symbols('a b f')
  58. assert geometric_conj_ab(a, b) == a*b/(a + b)
  59. assert geometric_conj_af(a, f) == a*f/(a - f)
  60. assert geometric_conj_bf(b, f) == b*f/(b - f)
  61. assert geometric_conj_ab(oo, b) == b
  62. assert geometric_conj_ab(a, oo) == a
  63. s_in, z_r_in, f = symbols('s_in z_r_in f')
  64. assert gaussian_conj(
  65. s_in, z_r_in, f)[0] == 1/(-1/(s_in + z_r_in**2/(-f + s_in)) + 1/f)
  66. assert gaussian_conj(
  67. s_in, z_r_in, f)[1] == z_r_in/(1 - s_in**2/f**2 + z_r_in**2/f**2)
  68. assert gaussian_conj(
  69. s_in, z_r_in, f)[2] == 1/sqrt(1 - s_in**2/f**2 + z_r_in**2/f**2)
  70. l, w_i, w_o, f = symbols('l w_i w_o f')
  71. assert conjugate_gauss_beams(l, w_i, w_o, f=f)[0] == f*(
  72. -sqrt(w_i**2/w_o**2 - pi**2*w_i**4/(f**2*l**2)) + 1)
  73. assert factor(conjugate_gauss_beams(l, w_i, w_o, f=f)[1]) == f*w_o**2*(
  74. w_i**2/w_o**2 - sqrt(w_i**2/w_o**2 - pi**2*w_i**4/(f**2*l**2)))/w_i**2
  75. assert conjugate_gauss_beams(l, w_i, w_o, f=f)[2] == f
  76. z, l, w = symbols('z l r', positive=True)
  77. p = BeamParameter(l, z, w=w)
  78. assert p.radius == z*(pi**2*w**4/(l**2*z**2) + 1)
  79. assert p.w == w*sqrt(l**2*z**2/(pi**2*w**4) + 1)
  80. assert p.w_0 == w
  81. assert p.divergence == l/(pi*w)
  82. assert p.gouy == atan2(z, pi*w**2/l)
  83. assert p.waist_approximation_limit == 2*l/pi