Package windSimSuite :: Module references
[hide private]

Source Code for Module windSimSuite.references

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  # This file is part of MBDyn sim suite. 
  5  # Copyright (C) 2007 André ESPAZE, as part of a Master thesis supervised by 
  6  # Martin O.L.Hansen (DTU) and Nicolas Chauvat (Logilab) 
  7   
  8  # MBDyn sim suite is free software; you can redistribute it and/or modify 
  9  # it under the terms of the GNU General Public License as published by 
 10  # the Free Software Foundation; either version 2 of the License, or 
 11  # (at your option) any later version. 
 12  # 
 13  # This program is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU General Public License for more details. 
 17  # 
 18  # You should have received a copy of the GNU General Public License 
 19  # along with this program; if not, write to the Free Software 
 20  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 21  # 
 22  """The reference frames for the unsteady Blade Element Momentum (BEM) 
 23  calculations""" 
 24  import numpy as N 
 25  from windSimSuite.common import BasicObject 
 26   
 27   
28 -class ReferenceFrame(BasicObject):
29 """The top class of every reference frame. Only one reference 30 frame instance will exist but its reference will be shared 31 for every wind turbine component. The references to reference frames 32 will be kept in the L{ReferenceFrames} 33 instance: a list of needed reference frames.""" 34
35 - def __init__(self, name="reference"):
36 BasicObject.__init__(self, name) 37 self.key = None 38 self.array = N.zeros((3, 3)) 39 self.matrix = N.asmatrix(self.array)
40
41 - def update_array(self):
42 """Will be defined in the derived classes""" 43 pass
44
45 - def calculate(self):
46 """Calculate the reference frame""" 47 self.update_array() 48 self.matrix = N.asmatrix(self.array)
49 50
51 -class YawReferenceFrame(ReferenceFrame):
52 """The yaw reference frame 53 """ 54
55 - def __init__(self, name="yaw reference frame"):
56 ReferenceFrame.__init__(self, name) 57 self.key = "yaw" 58 self.yaw = None
59
60 - def set_angle(self, yaw):
61 """The yaw angle, instance from the C{Angle} 62 class in the C{mbdyn} package""" 63 self.yaw = yaw
64
65 - def update_array(self):
66 """Update the transformation array from the yaw angle value""" 67 self.array = N.array([ 68 [N.cos(self.yaw["rad"]), N.sin(self.yaw["rad"]), 0.], 69 [-N.sin(self.yaw["rad"]), N.cos(self.yaw["rad"]), 0.], 70 [0., 0., 1.] 71 ])
72 73
74 -class TiltReferenceFrame(ReferenceFrame):
75 """The tilt reference frame 76 """ 77
78 - def __init__(self, name="tilt reference frame"):
79 ReferenceFrame.__init__(self, name) 80 self.key = "tilt" 81 self.tilt = None
82
83 - def set_angle(self, tilt):
84 """The tilt angle, instance from the C{Angle} 85 class in the C{mbdyn} package""" 86 self.tilt = tilt
87
88 - def update_array(self):
89 """Update the transformation array from the tilt angle value""" 90 self.array = N.array([ 91 [N.cos(self.tilt["rad"]), 0., -N.sin(self.tilt["rad"])], 92 [0., 1., 0.], 93 [N.sin(self.tilt["rad"]), 0., N.cos(self.tilt["rad"])] 94 ])
95 96
97 -class WingReferenceFrame(ReferenceFrame):
98 """The wing reference frame 99 """ 100
101 - def __init__(self, name="wing reference frame"):
102 ReferenceFrame.__init__(self, name) 103 self.key = "wing" 104 self.wing = None
105
106 - def set_angle(self, wing):
107 """The wing angle, instance from the C{Angle} 108 class in the C{mbdyn} package""" 109 self.wing = wing
110
111 - def update_array(self):
112 """Update the transformation array from the wing angle value""" 113 self.array = N.array([ 114 [1., 0., 0.], 115 [0., N.cos(self.wing["rad"]), N.sin(self.wing["rad"])], 116 [0., -N.sin(self.wing["rad"]), N.cos(self.wing["rad"])] 117 ])
118 119
120 -class ConeReferenceFrame(ReferenceFrame):
121 """The cone reference frame 122 """ 123
124 - def __init__(self, name="cone reference frame"):
125 ReferenceFrame.__init__(self, name) 126 self.key = "cone" 127 self.cone = None
128
129 - def set_angle(self, cone):
130 """The cone angle, instance from the C{Angle} 131 class in the C{mbdyn} package""" 132 self.cone = cone
133
134 - def update_array(self):
135 """Update the transformation array from the cone angle value""" 136 self.array = N.array([ 137 [N.cos(self.cone["rad"]), 0., -N.sin(self.cone["rad"])], 138 [0., 1., 0.], 139 [N.sin(self.cone["rad"]), 0., N.cos(self.cone["rad"])] 140 ])
141 142
143 -class PitchReferenceFrame(ReferenceFrame):
144 """The pitch reference frame 145 """ 146
147 - def __init__(self, name="pitch reference frame"):
148 ReferenceFrame.__init__(self, name) 149 self.key = "pitch" 150 self.pitch = None
151
152 - def set_angle(self, pitch):
153 """The pitch angle, instance from the C{Angle} 154 class in the C{mbdyn} package""" 155 self.pitch = pitch
156
157 - def update_array(self):
158 """Update the transformation array from the pitch angle value""" 159 self.array = N.array([ 160 [N.cos(self.pitch["rad"]), -N.sin(self.pitch["rad"]), 0.], 161 [N.sin(self.pitch["rad"]), N.cos(self.pitch["rad"]), 0.], 162 [0., 0., 1.] 163 ])
164 165
166 -class ReferenceFrames(BasicObject):
167 """Manipulate L{ReferenceFrame} references in a list. 168 The first reference frame is supposed to represent 169 the first transformation from the absolute reference frame, and so 170 on until the final transformation for reaching the base of work. 171 This object is used by every wind turbine component, that according 172 to its placement keep a different list of L{ReferenceFrame} references. 173 """ 174
175 - def __init__(self, name="references"):
176 BasicObject.__init__(self, name) 177 self.nb_references = 0 178 self.refs = [] 179 self.reference_keys = []
180
181 - def add(self, reference_frame):
182 """Append a reference frame to the list""" 183 self.refs.append(reference_frame) 184 self.reference_keys.append(reference_frame.key) 185 self.nb_references += 1
186
187 - def prepend(self, refs_list):
188 """Prepend a list of reference frames to the list. 189 190 @type refs_list: a list 191 @param refs_list: a list made of reference frame""" 192 for idx, reference_frame in enumerate(refs_list): 193 self.refs.insert(idx, reference_frame) 194 self.reference_keys.insert(idx, reference_frame.key) 195 self.nb_references += 1
196
197 - def get_matrix_from(self, key):
198 """Return the transform matrix from the given 199 reference frame key to the global reference frame. 200 """ 201 given_refid = self.reference_keys.index(key) 202 matrix = self.refs[0].matrix.T.copy() 203 for refid in range(1, given_refid + 1): 204 matrix *= self.refs[refid].matrix.T 205 return matrix
206
207 - def __getitem__(self, key):
208 """Return a reference frame from its key""" 209 return self.refs[self.reference_keys.index(key)]
210 211 212 REFERENCE_FRAME = { 213 "yaw" : YawReferenceFrame, 214 "tilt" : TiltReferenceFrame, 215 "wing" : WingReferenceFrame, 216 "cone" : ConeReferenceFrame, 217 "pitch" : PitchReferenceFrame 218 } 219