1 '''Defines the ThinLens class for theia.'''
2
3
4
5
6
7
8 import numpy as np
9 from ..helpers import settings
10 from ..helpers.units import mm, cm, deg, pi
11 from ..helpers.geometry import rectToSph
12 from .lens import Lens
13
15 '''
16
17 ThinLens class.
18
19 This class represents thin lenses, which are specified only by their focal
20 lengths, diameter, position and orientation. Only the initializer and the
21 printing distinguishes thin lenses (in implementation) from other lenses.
22
23 *=== Attributes ===*
24 SetupCount (inherited): class attribute, counts all setup components.
25 [integer]
26 OptCount (inherited): class attribute, counts optical components. [integer]
27 Name: class attribute. [string]
28 HRCenter (inherited): center of the 'chord' of the HR surface. [3D vector]
29 HRNorm (inherited): unitary normal to the 'chord' of the HR (always pointing
30 towards the outside of the component). [3D vector]
31 Thick (inherited): thickness of the optic, counted in opposite direction to
32 HRNorm. [float]
33 Dia (inherited): diameter of the component. [float]
34 Ref (inherited): reference string (for keeping track with the lab). [string]
35 ARCenter (inherited): center of the 'chord' of the AR surface. [3D vector]
36 ARNorm (inherited): unitary normal to the 'chord' of the AR (always pointing
37 towards the outside of the component). [3D vector]
38 N (inherited): refraction index of the material. [float]
39 HRK, ARK (inherited): curvature of the HR, AR surfaces. [float]
40 HRr, HRt, ARr, ARt (inherited): power reflectance and transmission
41 coefficients of the HR and AR surfaces. [float]
42 KeepI (inherited): whether of not to keep data of rays for interference
43 calculations on the HR. [boolean]
44 Focal: Focal length of the lens. [float]
45
46 **Note**: the curvature of any surface is positive for a concave surface
47 (coating inside the sphere).
48 Thus kurv*HRNorm/|kurv| always points to the center
49 of the sphere of the surface, as is the convention for the lineSurfInter of
50 geometry module. Same for AR.
51
52 ******* HRK > 0 and ARK > 0 ******* HRK > 0 and ARK < 0
53 ***** ******** and |ARK| > |HRK|
54 H***A H*********A
55 ***** ********
56 ******* *******
57
58 '''
59
60 Name = "ThinLens"
61
62 - def __init__(self, Focal = 10.e-2, KeepI = False, Theta = pi/2., Phi = 0.,
63 Diameter = 5.e-2, R = .1, T = .9,
64 X = 0., Y = 0., Z = 0., Ref = None):
65 '''ThinLens initializer.
66
67 Parameters are the attributes.
68
69 Returns a ThinLens.
70
71 '''
72
73 self.Focal = float(Focal)
74 Theta = float(Theta)
75 Phi = float(Phi)
76 Diameter = float(Diameter)
77 R = float(R)
78 T = float(T)
79
80
81 HRNorm = np.array([np.sin(Theta)*np.cos(Phi),
82 np.sin(Theta) * np.sin(Phi),
83 np.cos(Theta)], dtype = np.float64)
84 Center = np.array([X, Y, Z], dtype = np.float64)
85 N = 1.4548
86
87
88 HRK = - 0.5/(self.Focal*(N - 1.))
89 ARK = HRK
90 ARNorm = - HRNorm
91
92
93 if self.Focal >= 0.:
94 Thickness = settings.zero
95 else:
96 try:
97 theta = np.arcsin(Diameter * HRK/2.)
98 except FloatingPointError:
99 theta = pi/2.
100 Thickness = 2.*settings.zero + 2.*(1.-np.cos(theta))/HRK
101 HRCenter = Center + Thickness*HRNorm/2.
102 ARCenter = Center - Thickness*HRNorm/2.
103
104
105 super(Lens, self).__init__(ARCenter = ARCenter, ARNorm = ARNorm, N = N,
106 HRK = HRK, ARK = ARK,
107 ARr = R, ARt = T, HRr = R, HRt = T, KeepI = KeepI,
108 HRCenter = HRCenter, HRNorm = HRNorm, Thickness = Thickness,
109 Diameter = Diameter, Ref = Ref)
110
111
112 if settings.warning:
113 self.geoCheck("thinlens")
114
116 '''Returns the list of lines necessary to print the object.
117 '''
118 ans = []
119 ans.append("ThinLens: " + self.Name + " (" + str(self.Ref) + ") {")
120 ans.append("Diameter: " + str(self.Dia/cm) + "cm")
121 ans.append("Focal: " + str(self.Focal/mm) + "mm")
122 ans.append("Center: " + str(self.HRCenter))
123 sph = rectToSph(self.HRNorm)
124 ans.append("Norm: (" + str(sph[0]/deg) + ', ' \
125 + str(sph[1]/deg) + ')deg')
126 ans.append("R, T: " + str(self.HRr) + ", " + str(self.HRt) )
127 ans.append("}")
128
129 return ans
130