1 '''Defines the SetupComponent class for theia.'''
2
3
4
5
6
7
8
9
10
11
12 import numpy as np
13 from abc import ABCMeta, abstractmethod
14 from ..helpers.tools import formatter
17 '''
18
19 SetupComponent class.
20
21 This is an Abstract Base Class for all the components (optical or not) of
22 the setup. Its methods may be implemented in daughter classes.
23
24 *=== Attributes ===*
25 SetupCount: class attribute, counts setup components. [integer]
26 HRCenter: center of the principal face of the component in space.
27 [3D vector]
28 ARCenter: center of the secondary face of the component in space.
29 [3D vector]
30 HRNorm: normal unitary vector the this principal face, supposed to point
31 outside the media. [3D vector]
32 Thick: thickness of the component, counted in opposite direction to
33 HRNorm. [float]
34 Dia: diameter of the component. [float]
35 Name: name of the component. [string]
36 InBeams: list of all beams incident on the component. [list of GaussianBeam]
37 OutBeams: list of all beams out
38 Ref: reference string (for keeping track with the lab). [string]
39
40
41 '''
42
43 __metaclass__ = ABCMeta
44 SetupCount = 0
45 Name = "SetupComponent"
46
47 - def __init__(self, HRCenter, HRNorm, Ref, Thickness, Diameter, ARCenter):
48 '''SetupComponent initializer.
49
50 Parameters are the attributes of the object to construct.
51
52 Returns a setupComponent.
53
54 '''
55
56 if Ref is None:
57 Ref = "Set%s" % str(SetupComponent.SetupCount)
58
59 self.HRCenter = HRCenter
60 self.ARCenter = ARCenter
61 self.HRNorm = HRNorm
62 self.Thick = Thickness
63 self.Dia = Diameter
64 self.Ref = Ref
65
66 SetupComponent.SetupCount = SetupComponent.SetupCount + 1
67
69 '''String representation of the component, when calling print(object).
70
71 '''
72 return formatter(self.lines())
73
74 @abstractmethod
76 '''Method to return the list of strings to __str__.
77
78 Abstract (pure virtual) method.
79
80 '''
81 pass
82
83 @abstractmethod
85 '''Method to determine if component is hit by a beam.
86
87 Abstract (pure virtual) method.
88
89 '''
90 pass
91
92 @abstractmethod
93 - def hit(self, beam, order, threshold):
94 '''Compute the refracted and reflected beams after interaction.
95
96 Abstract (pure virtual) method.
97
98 '''
99
100 - def translate(self, X = 0., Y = 0., Z = 0.):
101 '''Move the component to (current position + (X, Y, Z)).
102
103 This version only takes care of the HRCenter, version of sub classes
104 take care of ARCenter if relevant.
105
106 X, Y, Z: components of the translation vector.
107
108 No return value.
109 '''
110 self.HRCenter = self.HRCenter + np.array([X, Y, Z], dtype = np.float64)
111