• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WISDEM / WEIS / 12283078613

11 Dec 2024 06:59PM UTC coverage: 78.249% (-0.6%) from 78.802%
12283078613

Pull #308

github

dzalkind
Merge remote-tracking branch 'origin/DLC_RefactorCaseInputs' into DLC_RefactorCaseInputs
Pull Request #308: DLC Generation - Refactor and New Cases

446 of 665 new or added lines in 9 files covered. (67.07%)

3 existing lines in 3 files now uncovered.

21416 of 27369 relevant lines covered (78.25%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.95
/weis/aeroelasticse/IEC_CoeherentGusts.py
1
import numpy as np
1✔
2
import os
1✔
3

4
class IEC_CoherentGusts():
1✔
5

6
    def __init__(self):
1✔
7

8
        self.Vert_Slope = 0 # Vertical slope of the wind inflow (deg)
×
9
        self.T0 = 0.
×
10
        self.TF = 630.
×
11
        self.TStart = 30 # Time to start transient conditions (s)
×
12
        self.dt = 0.05 # Transient wind time step (s)
×
13
        self.D = 90. # Rotor diameter (m)
×
14
        self.HH = 100. # Hub height (m)        
×
15

16
    def execute(self, dir, base_name, dlc):
1✔
17

18
        if self.HH > 60:
×
NEW
19
            self.Lambda_1 = 42
×
20
        else:
NEW
21
            self.Lambda_1 = 0.7*self.HH
×
22

23
        wind_file_name = os.path.join(dir, base_name + '_' + dlc.IEC_WindType + '_U%1.6f'%dlc.URef +  '_D%s'%dlc.direction_pn + '_S%s'%dlc.shear_hv + '.wnd')
×
24

25
        if dlc.IEC_WindType == 'EOG':
×
26
            self.EOG(dlc, wind_file_name)
×
27
        elif dlc.IEC_WindType == 'EDC':
×
28
            self.EDC(dlc, wind_file_name)
×
29
        elif dlc.IEC_WindType == 'ECD':
×
30
            self.ECD(dlc, wind_file_name)
×
31
        elif dlc.IEC_WindType == 'EWS':
×
32
            self.EWS(dlc, wind_file_name)
×
33
        elif dlc.IEC_WindType == 'Custom':
×
34
            wind_file_name = dlc.wind_file
×
35
        else:
36
            raise Exception('The gust ' + dlc.IEC_WindType + ' is not supported by WEIS')
×
37

38
        return wind_file_name
×
39

40
    def EOG(self, dlc, wind_file_name):
1✔
41
        # Extreme operating gust: 6.3.2.2
42

43
        T = 10.5
×
44
        t = np.linspace(0., T, num=int(T/self.dt+1))
×
45

46
        # constants from standard
47
        alpha = 0.2
×
48

49
        # Flow angle adjustments
50
        V_hub = dlc.URef*np.cos(self.Vert_Slope*np.pi/180)
×
51
        V_vert_mag = dlc.URef*np.sin(self.Vert_Slope*np.pi/180)
×
52

53
        sigma_1 = dlc.sigma1
×
54
        V_e1 = dlc.V_e1
×
55

56
        # Contant variables
57
        V = np.zeros_like(t)+V_hub
×
58
        V_dir = np.zeros_like(t)
×
59
        V_vert = np.zeros_like(t)+V_vert_mag
×
60
        shear_horz = np.zeros_like(t)
×
61
        shear_vert = np.zeros_like(t)+alpha
×
62
        shear_vert_lin = np.zeros_like(t)
×
63
        V_gust = np.zeros_like(t)
×
64
        upflow = np.zeros_like(t)
×
65

NEW
66
        V_gust = min([ 1.35*(V_e1 - V_hub), 3.3*(sigma_1/(1+0.1*(self.D/self.Lambda_1))) ])
×
67

68
        V_gust_t = np.zeros_like(t)
×
69
        for i, ti in enumerate(t):
×
70
            if ti<T:
×
71
                V_gust_t[i] = 0. - 0.37*V_gust*np.sin(3*np.pi*ti/T)*(1-np.cos(2*np.pi*ti/T))
×
72
            else:
73
                V_gust_t[i] = 0.
×
74
        
75
        data = np.column_stack((t, V, V_dir, V_vert, shear_horz, shear_vert, shear_vert_lin, V_gust_t, upflow))
×
76
        # Header
77
        hd = '! EOG gust, wind speed = ' + str(dlc.URef)
×
78
        self.write_wnd(wind_file_name, data, hd)
×
79

80
    def EDC(self, dlc, wind_file_name):
1✔
81
        # Extreme direction change: 6.3.2.4
82
        
83
        T = 6.
×
84
        t = np.linspace(0., T, num=int(T/self.dt+1))
×
85

86
        # constants from standard
87
        alpha = 0.2
×
88

89
        # Flow angle adjustments
90
        V_hub = dlc.URef*np.cos(self.Vert_Slope*np.pi/180)
×
91
        V_vert_mag = dlc.URef*np.sin(self.Vert_Slope*np.pi/180)
×
92

93
        sigma_1 = dlc.sigma1
×
94

95
        # Contant variables
96
        V = np.zeros_like(t)+V_hub
×
97
        V_vert = np.zeros_like(t)+V_vert_mag
×
98
        shear_horz = np.zeros_like(t)
×
99
        shear_vert = np.zeros_like(t)+alpha
×
100
        shear_vert_lin = np.zeros_like(t)
×
101
        V_gust = np.zeros_like(t)
×
102
        upflow = np.zeros_like(t)
×
103

104
        # Transient
NEW
105
        Theta_e = 4.*np.arctan(sigma_1/(V_hub*(1.+0.01*(self.D/self.Lambda_1))))*180./np.pi
×
106
        if Theta_e > 180.:
×
107
            Theta_e = 180.
×
108

109
        if dlc.direction_pn == 'p':
×
110
            k=1.
×
111
        elif dlc.direction_pn == 'n':
×
112
            k=-1.
×
113
        else:
114
            raise Exception('The EDC gust can only have positive (p) or negative (n) direction, whereas the script receives '+ dlc.direction_pn)
×
115

116
        Theta = np.zeros_like(t)
×
117
        for i, ti in enumerate(t):
×
118
            if ti<T:
×
119
                Theta[i] = k * 0.5*Theta_e*(1-np.cos(np.pi*ti/T))
×
120
            else:
121
                Theta[i] = k * Theta_e
×
122

123

124
        data = np.column_stack((t, V, Theta, V_vert, shear_horz, shear_vert, shear_vert_lin, V_gust, upflow))
×
125
        # Header
126
        hd = '! EDC gust, wind speed = ' + str(dlc.URef) + ', direction ' + dlc.direction_pn
×
127
        self.write_wnd(wind_file_name, data, hd)
×
128
    
129
    def ECD(self, dlc, wind_file_name):
1✔
130
        # Extreme coherent gust with direction change: 6.3.2.5
131
        
132
        T = 10.
×
133
        t = np.linspace(0., T, num=int(T/self.dt+1))
×
134

135
        # constants from standard
136
        alpha = 0.2
×
137
        V_cg = 15 #m/s
×
138

139
        # Flow angle adjustments
140
        V_hub = dlc.URef*np.cos(self.Vert_Slope*np.pi/180)
×
141
        V_vert_mag = dlc.URef*np.sin(self.Vert_Slope*np.pi/180)
×
142

143
        # Contant variables
144
        V_vert = np.zeros_like(t)+V_vert_mag
×
145
        shear_horz = np.zeros_like(t)
×
146
        shear_vert = np.zeros_like(t)+alpha
×
147
        shear_vert_lin = np.zeros_like(t)
×
148
        V_gust = np.zeros_like(t)
×
149
        upflow = np.zeros_like(t)
×
150

151
        # Transient
152
        if V_hub < 4:
×
153
            Theta_cg = 180
×
154
        else:
155
            Theta_cg = 720/V_hub
×
156

157
        if dlc.direction_pn == 'p':
×
158
            k=1.
×
159
        elif dlc.direction_pn == 'n':
×
160
            k=-1.
×
161
        else:
162
            raise Exception('The ECD gust can only have positive (p) or negative (n) direction, whereas the script receives '+ dlc.direction_pn)
×
163
        Theta = np.zeros_like(t)
×
164
        V = np.zeros_like(t)
×
165
        for i, ti in enumerate(t):
×
166
            if ti<T:
×
167
                V[i] = V_hub + 0.5*V_cg*(1-np.cos(np.pi*ti/T))
×
168
                Theta[i] = k * 0.5*Theta_cg*(1-np.cos(np.pi*ti/T))
×
169
            else:
170
                V[i] = V_hub+V_cg
×
171
                Theta[i] = k * Theta_cg
×
172
      
173
        data = np.column_stack((t, V, Theta, V_vert, shear_horz, shear_vert, shear_vert_lin, V_gust, upflow))
×
174
        # Header
175
        hd = '! ECD gust, wind speed = ' + str(dlc.URef) + ', direction ' + dlc.direction_pn
×
176
        self.write_wnd(wind_file_name, data, hd)
×
177

178
    def EWS(self, dlc, wind_file_name):
1✔
179
        T = 12
×
180
        t = np.linspace(0., T, num=int(T/self.dt+1))
×
181

182
        # constants from standard
183
        alpha = 0.2
×
184
        Beta = 6.4
×
185

186
        # Flow angle adjustments
187
        V_hub = dlc.URef*np.cos(self.Vert_Slope*np.pi/180)
×
188
        V_vert_mag = dlc.URef*np.sin(self.Vert_Slope*np.pi/180)
×
189

190
        sigma_1 = dlc.sigma1
×
191

192
        # Contant variables
193
        V = np.zeros_like(t)+V_hub
×
194
        V_dir = np.zeros_like(t)
×
195
        V_vert = np.zeros_like(t)+V_vert_mag
×
196
        shear_vert = np.zeros_like(t)+alpha
×
197
        V_gust = np.zeros_like(t)
×
198
        upflow = np.zeros_like(t)
×
199

200
        # Transient
201
        shear_lin = np.zeros_like(t)
×
202

203
        if dlc.direction_pn == 'p':
×
204
            k_dir=1.
×
205
        elif dlc.direction_pn == 'n':
×
206
            k_dir=-1.
×
207
        else:
208
            raise Exception('The EWS gust can only have positive (p) or negative (n) direction, whereas the script receives '+ dlc.direction_pn)
×
209

210
        if dlc.shear_hv == 'v':
×
211
            k_v=1.
×
212
            k_h=0.
×
213
        elif dlc.shear_hv == 'h':
×
214
            k_v=0.
×
215
            k_h=1.
×
216
        else:
217
            raise Exception('The EWS gust can only have vertical (v) or horizontal (h) shear, whereas the script receives '+ dlc.shear_hv)
×
218

219
        for i, ti in enumerate(t):
×
NEW
220
            shear_lin[i] = k_dir * (2.5+0.2*Beta*sigma_1*(self.D/self.Lambda_1)**(1/4))*(1-np.cos(2*np.pi*ti/T))/V_hub
×
221

222
        hd1 = ['Time', 'Wind', 'Wind', 'Vertical', 'Horiz.', 'Pwr. Law', 'Lin. Vert.', 'Gust', 'Upflow']
×
223
        hd2 = ['',     'Speed', 'Dir', 'Speed',    'Shear', 'Vert. Shr', 'Shear',     'Speed', 'Angle']
×
224

225
        data = np.column_stack((t, V, V_dir, V_vert, k_h * shear_lin, shear_vert, k_v * shear_lin, V_gust, upflow))
×
226

227
        # Header
228
        hd = '! EWS gust, wind speed = ' + str(dlc.URef) + ', direction ' + dlc.direction_pn + ', shear ' + dlc.shear_hv
×
229
        self.write_wnd(wind_file_name, data, hd)
×
230

231
    def write_wnd(self, fname, data, hd):
1✔
232

233
        # Move transient event to user defined time
234
        data[:,0] += self.TStart
×
235
        data = np.vstack((data[0,:], data, data[-1,:]))
×
236
        data[0,0] = self.T0
×
237
        data[-1,0] = self.TF
×
238

239
        # Headers
240
        hd1 = ['Time', 'Wind', 'Wind', 'Vertical', 'Horiz.', 'Pwr. Law', 'Lin. Vert.', 'Gust', 'Upflow']
×
241
        hd2 = ['', 'Speed', 'Dir', 'Speed', 'Shear', 'Vert. Shr', 'Shear', 'Speed', 'Angle']
×
242
        hd3 = ['(s)', '(m/s)', '(deg)', '(m/s)', '(-)', '(-)', '(-)', '(m/s)', '(deg)']
×
243

244
        fid = open(fname, 'w')
×
245

246
        fid.write('! Wind file generated by WEIS - IEC 61400-1 3rd Edition\n')
×
247
        for ln in hd:
×
248
            fid.write(ln)
×
249
        fid.write('! ---------------------------------------------------------------\n')
×
250
        fid.write('! '+''.join([('%s' % val).center(12) for val in hd1]) + '\n')
×
251
        fid.write('! '+''.join([('%s' % val).center(12) for val in hd2]) + '\n')
×
252
        fid.write('! '+''.join([('%s' % val).center(12) for val in hd3]) + '\n')
×
253
        for row in data:
×
254
            fid.write('  '+''.join([('%.6f' % val).center(12) for val in row]) + '\n')
×
255

256
        fid.close()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc