Package theia :: Package optics :: Module optic
[hide private]
[frames] | no frames]

Source Code for Module theia.optics.optic

  1  '''Defines the Optic class for theia.''' 
  2   
  3  # Provides: 
  4  #   class Optic 
  5  #       __init__ 
  6  #       hitSide 
  7  #       apexes 
  8  #       collision 
  9  #       geoCheck 
 10  #       translate 
 11   
 12  import numpy as np 
 13  from ..helpers import settings 
 14  from .component import SetupComponent 
 15   
16 -class Optic(SetupComponent):
17 ''' 18 19 Optic class. 20 21 This class is a base class for optics which may interact with Gaussian 22 beams and return transmitted and reflected beams (mirrors, lenses, etc.) 23 24 25 *=== Attributes ===* 26 SetupCount (inherited): class attribute, counts all setup components. 27 [integer] 28 OptCount: class attribute, counts optical components. [integer] 29 Name: class attribute. [string] 30 HRCenter (inherited): center of the 'chord' of the HR surface. [3D vector] 31 HRNorm (inherited): unitary normal to the 'chord' of the HR (always pointing 32 towards the outside of the component). [3D vector] 33 Thick (inherited): thickness of the optic, counted in opposite direction to 34 HRNorm. [float] 35 Dia (inherited): diameter of the component. [float] 36 Ref (inherited): reference string (for keeping track with the lab). [string] 37 ARCenter: center of the 'chord' of the AR surface. [3D vector] 38 ARNorm: unitary normal to the 'chord' of the AR (always pointing 39 towards the outside of the component). [3D vector] 40 N: refraction index of the material. [float] 41 HRK, ARK: curvature of the HR, AR surfaces. [float] 42 HRr, HRt, ARr, ARt: power reflectance and transmission coefficients of 43 the HR and AR surfaces. [float] 44 KeepI: whether of not to keep data of rays for interference calculations 45 on the HR. [boolean] 46 47 **Note**: the curvature of any surface is positive for a concave surface 48 (coating inside the sphere). 49 Thus kurv*HRNorm/|kurv| always points to the center 50 of the sphere of the surface, as is the convention for the lineSurfInter of 51 geometry module. Same for AR. 52 53 ******* HRK > 0 and ARK > 0 ******* HRK > 0 and ARK < 0 54 ***** ******** and |ARK| > |HRK| 55 H***A H*********A 56 ***** ******** 57 ******* ******* 58 59 ''' 60 61 OptCount = 0 #counts the setup components 62 Name = "Optic" 63
64 - def __init__(self, ARCenter, ARNorm, N, HRK, ARK, ARr, ARt, HRr, 65 HRt, KeepI, HRCenter, HRNorm, Thickness, Diameter, Ref):
66 '''Optic base initializer. 67 68 Parameters are the attributes of the object to construct. 69 70 Returns an Optic. 71 72 ''' 73 # allow empty initializer 74 if Ref is None: 75 Ref = "Opt" + str(Optic.OptCount) 76 77 # initialize with input data 78 self.ARCenter = ARCenter 79 self.ARNorm = ARNorm 80 self.N = N 81 self.HRK = HRK 82 self.ARK = ARK 83 self.HRr = HRr 84 self.HRt = HRt 85 self.ARr = ARr 86 self.ARt = ARt 87 self.KeepI = KeepI 88 89 #call mother initializer 90 super(Optic, self).__init__(HRCenter = HRCenter, HRNorm = HRNorm, 91 Ref = Ref, Thickness = Thickness, 92 Diameter = Diameter) 93 Optic.OptCount = Optic.OptCount + 1
94
95 - def hitSide(self, beam):
96 '''Compute the daughter beams after interaction on Side at point. 97 98 Generic function: all sides stop beams. 99 100 beam: incident beam. [GaussianBeam] 101 102 Returns {'t': None, 'r': None} 103 104 ''' 105 if settings.info: 106 print "theia: Info: Reached leaf of tree by interaction ("\ 107 + beam.Ref + " on " + self.Ref + ', ' + 'Side).' 108 return {'t': None, 'r': None}
109
110 - def apexes(self):
111 '''Returns the positions of the apexes of HR and AR as a tuple. 112 ''' 113 if self.HRK == 0.: 114 apex1 = self.HRCenter 115 else: 116 try: # the arcsin may fail because dia/2. > ROC 117 theta1 = np.arcsin(self.Dia * self.HRK/2.) #semi angles 118 except FloatingPointError: 119 #if it fails then the whole semisphere is in the mirror and apex 120 # is a radius away from Center. 121 theta = np.pi/2. 122 apex1 = self.HRCenter - (1-np.cos(theta1))*self.HRNorm/self.HRK 123 124 if self.ARK == 0.: 125 apex2 = self.ARCenter 126 else: 127 if self.Name == 'Mirror': 128 #ARdiameter different if wedge! 129 wedge = self.Wedge 130 else: 131 wedge = 0. 132 try: #same 133 theta2 = np.arcsin(self.Dia * self.ARK/(2.*np.cos(wedge))) 134 except FloatingPointError: 135 theta2 = np.pi/2. 136 apex2 = self.ARCenter - (1-np.cos(theta2))*self.ARNorm/self.ARK 137 138 return apex1, apex2
139
140 - def collision(self):
141 '''Determine whether the HR and AR surfaces intersect. 142 143 Returns True if there is an intersection, False if not. 144 145 ''' 146 147 if self.ARK <= 0. and self.HRK <= 0.: 148 # no collision if negative curvatures 149 return False 150 151 apex = self.apexes() 152 153 #vector from apex1 to apex2 154 vec = apex[1] - apex[0] 155 156 return np.dot(vec, self.HRNorm) > 0.
157
158 - def geoCheck(self, word):
159 '''Makes geometrical checks on surfaces and warns when necessary. 160 161 ''' 162 if self.HRt + self.HRr > 1.: 163 print "theia: Warning: In " + word + " %s (%s) on HR, R + T > 1."\ 164 %(self.Name, self.Ref) 165 166 if self.ARt + self.ARr > 1.: 167 print "theia: Warning: In " + word + " %s (%s) on AR, R + T > 1."\ 168 %(self.Name, self.Ref) 169 170 if self.N < 1.: 171 print "theia: Warning: In " + word + " %s (%s), optical index < 1."\ 172 %(self.Name, self.Ref) 173 174 if self.HRK != 0. and np.abs(1./self.HRK) < self.Dia/2.: 175 print "theia: Warning: In " + word + " %s (%s), the diameter of " \ 176 %(self.Name, self.Ref)\ 177 +"the "+word+" exceeds the diameter of the HR surface."\ 178 179 if self.ARK != 0. and np.abs(1./self.ARK) < self.Dia/2.: 180 print "theia: Warning: In " + word + " %s (%s), the diameter of " \ 181 %(self.Name, self.Ref)\ 182 +"the "+word+" exceeds the diameter of the AR surface."\ 183 184 if self.collision(): 185 print "theia: Warning: In " + word + " %s (%s), HR and AR surfaces"\ 186 %(self.Name, self.Ref)\ 187 +" intersect."
188
189 - def translate(self, X = 0., Y = 0., Z = 0.):
190 '''Move the optic to (current position + (X, Y, Z)). 191 192 This version takes care of HRcenter and ARCenter and overwrites the 193 SetupComponent version. 194 195 X, Y, Z: components of the translation vector. 196 197 No return value. 198 ''' 199 self.HRCenter = self.HRCenter + np.array([X, Y, Z], dtype = np.float64) 200 self.ARCenter = self.ARCenter + np.array([X, Y, Z], dtype = np.float64)
201