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

Source Code for Module theia.optics.beamdump

  1  '''Defines the BeamDump class for theia.''' 
  2   
  3  # Provides: 
  4  #   class BeamDump 
  5  #       __init__ 
  6  #       lines 
  7  #       isHit 
  8  #       hit 
  9   
 10  import numpy as np 
 11  from ..helpers import settings 
 12  from ..helpers.geometry import rectToSph, linePlaneInter, lineCylInter 
 13  from ..helpers.units import deg, pi 
 14  from ..helpers.tools import shortRef 
 15  from .component import SetupComponent 
 16   
17 -class BeamDump(SetupComponent):
18 ''' 19 20 BeamDump class. 21 22 This class represents components on which rays stop. They have cylindrical 23 symmetry and stop beams on all their faces. They can represent baffles 24 for example. 25 26 *=== Attributes ===* 27 SetupCount (inherited): class attribute, counts all setup components. 28 [integer] 29 Name: class attribute. [string] 30 HRCenter (inherited): center of the principal face of the BeamDump in space. 31 [3D vector] 32 ARCenter (inherited): center of the secondary face of the BeamDump in space. 33 [3D vector] 34 HRnorm (inherited): normal unitary vector the this principal face, 35 supposed to point outside the media. [3D vector] 36 Thick (inherited): thickness of the dump, counted in opposite direction to 37 HRNorm. [float] 38 Dia (inherited): diameter of the component. [float] 39 Ref (inherited): reference string (for keeping track with the lab). [string] 40 41 ''' 42 Name = "BeamDump"
43 - def __init__(self, X = 0., Y = 0., Z = 0., Theta = pi/2., Phi = 0., 44 Ref = None, 45 Thickness = 2.e-2, Diameter = 5.e-2):
46 '''BeamDump initializer. 47 48 Parameters are the attributes. 49 50 Returns a BeamDump. 51 52 ''' 53 #Check input 54 Thickness = float(Thickness) 55 Diameter = float(Diameter) 56 57 # prepare for mother initializer 58 Norm = np.array([np.sin(Theta)*np.cos(Phi), 59 np.sin(Theta) * np.sin(Phi), 60 np.cos(Theta)], dtype = np.float64) 61 62 HRCenter = np.array([X, Y, Z], dtype = np.float64) 63 ARCenter = HRCenter - Thickness * Norm 64 65 # initialize from base initializer 66 super(BeamDump, self).__init__(Ref = Ref, 67 Diameter = Diameter, HRCenter = HRCenter, HRNorm = Norm, 68 Thickness = Thickness, ARCenter = ARCenter)
69
70 - def lines(self):
71 '''Return the list of lines needed to print the object. 72 ''' 73 sph = rectToSph(self.HRNorm) 74 return ["BeamDump: %s {" % self.Ref, 75 "Thick: %sm" % str(self.Thick), 76 "Diameter: %sm" % str(self.Dia), 77 "Center: %s" % str(self.HRCenter), 78 "Norm: (%s, %s)deg" % (str(sph[0]/deg), str(sph[1]/deg)), 79 "}"]
80
81 - def isHit(self, beam):
82 '''Determine if a beam hits the BeamDump. 83 84 This uses the line***Inter functions from the geometry module to find 85 characteristics of impact of beams on beamdumps. 86 87 beam: incoming beam. [GaussianBeam] 88 89 Returns a dictionary with keys: 90 'isHit': whether the beam hits the dump. [boolean] 91 'intersection point': point in space where it is first hit. 92 [3D vector] 93 'face': to indicate which face is first hit, can be 'HR', 'AR' or 94 'side'. [string] 95 'distance': geometrical distance from beam origin to impact. [float] 96 97 ''' 98 99 # Get impact parameters 100 HRDict = linePlaneInter(beam.Pos, beam.Dir, self.HRCenter, 101 self.HRNorm, self.Dia) 102 103 SideDict =lineCylInter(beam.Pos, beam.Dir, 104 self.HRCenter, self.HRNorm, 105 self.Thick, self.Dia) 106 107 ARCenter = self.HRCenter - self.Thick*self.HRNorm 108 109 ARDict = linePlaneInter(beam.Pos, beam.Dir, ARCenter, 110 - self.HRNorm, self.Dia) 111 112 # face tags 113 HRDict['face'] = 'HR' 114 ARDict['face'] = 'AR' 115 SideDict['face'] = 'Side' 116 117 # determine first hit 118 hitFaces = filter(lambda dic: dic['isHit'], [HRDict, ARDict, SideDict]) 119 120 if len(hitFaces) == 0: 121 return {'isHit': False, 122 'intersection point': np.array([0., 0., 0.], 123 dtype=np.float64), 124 'face': None, 125 'distance': 0.} 126 127 ans = hitFaces[0] 128 for dic in hitFaces: 129 if dic['distance'] < ans['distance']: 130 ans = dic 131 132 return {'isHit': True, 133 'intersection point': ans['intersection point'], 134 'face': ans['face'], 135 'distance': ans['distance'] 136 }
137
138 - def hit(self, beam, order, threshold):
139 '''Compute the refracted and reflected beams after interaction. 140 141 BeamDumps always stop beams. 142 143 beam: incident beam. [GaussianBeam] 144 order: maximum strayness of daughter beams, which are not returned if 145 their strayness is over this order. [integer] 146 threshold: idem for the power of the daughter beams. [float] 147 148 Returns a dictionary of beams with keys: 149 't': None 150 'r': None 151 152 ''' 153 # get impact parameters and update beam 154 dic = self.isHit(beam) 155 beam.Length = dic['distance'] 156 beam.OptDist = beam.N * beam.Length 157 beam.TargetOptic = self.Ref 158 beam.TargetFace = dic['face'] 159 endSize = beam.width(beam.Length) 160 beam.TWx = endSize[0] 161 beam.TWy = endSize[1] 162 163 if settings.info and (beam.N == 1. or not settings.short): 164 print "theia: Info: Reached beam stop (%s on %s)." \ 165 % (beam.Ref if not settings.short else shortRef(beam.Ref), 166 self.Ref) 167 168 return {'r': None, 't': None}
169