-
Notifications
You must be signed in to change notification settings - Fork 2
/
Apricott.py
662 lines (348 loc) · 23 KB
/
Apricott.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
"""
author: david.planas-andres
Systematic sample generation for orthogonal -least squares algorithm APRICOT
The following variables are varied for longitudinal and lateral cases
x + fix = [alpha, p, q, r, phi, theta, delta_a, delta_e, delta_r, delta_xi(hay 12), V , beta , gamma, omega]
Given example. For a function y=f(x1,x2,x3) . In order to get a systematic sample working in apricott a 3 points
sample is taken (0,1,2) for the three variables, so number of points = variations^variables = (3^3=27)
Apricott requires the order of the sample to be as following (systematic)
# x1: 0 0 0 0 0 0 O O O 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
# x2: 0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2
# x3: 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2
#It is required to build a matrix of:
# rows: 3 (number of variables)
# colons: 27 (variations^variables, 3^3)
#VARIABLE 1: suffers a variation each number of variations^2
#VARIABLE 2: suffers a variation each number of variations^1
#VARIABLE 3: suffers a variation each number of variations^0
variables=3
variations=3
samplevector=np.zeros((variables,variations**variables))
for i in range(variations): #from 0 to 2
for j in range(variations): #from 0 to 2
for k in range(variations): #from 0 to 2
samplevector[variables-3,i*variations**2+j*variations+k] = i
samplevector[variables-2,i*variations**2+j*variations+k] = j
samplevector[variables-1,i*variations**2+j*variations+k] = k
"""
import numpy as np
import math
from StabilityMapUtils import AeroForces
from numpy.linalg import inv
import ReadFileUtils as Read # utils to read Xfoil file
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
from scipy.interpolate import InterpolatedUnivariateSpline as IUS
import matplotlib.pyplot as plt
def Sample_generation(x, fix, CoefMatrix, atmo, g, PropWing):
if g.hangar['aircraft']=='ATR72':
phimax = 5 # in degree the max bank angle authorized
alphamax = 25 # in degree, stall bound for trimming
deltaRmax = 30 # in degree
ThrottleMax = 1 # max thrust level
ThrottleMin = 1e-9 # min thruttle, don't accept 0 thrust
V=fix[0]
# alfa p q r phi theta delta_a delta_e delta_r
# bnds=( (-5*math.pi/180,alphamax*math.pi/180), (-0.2,0.2), (-0.2,0.2), (-0.2,0.2), (-phimax/180*math.pi,phimax/180*math.pi), (-30/180*math.pi,30/180*math.pi), (-30/180*math.pi,30/180*math.pi), (-20/180*math.pi,20/180*math.pi), (-deltaRmax/180*math.pi,deltaRmax/180*math.pi))
bnds = (( x[0] - 3 * math.pi / 180, x[0] + 3* math.pi / 180), (-0.2*(g.b/(2*V)), 0.2*(g.b/(2*V))), (-0.2*(g.c/(2*V)), 0.2*(g.c/(2*V))), (-0.2*(g.b/(2*V)), 0.2*(g.b/(2*V))),
(-phimax / 180 * math.pi, phimax / 180 * math.pi), (-5 / 180 * math.pi, 5 / 180 * math.pi),
(-10 / 180 * math.pi, 10 / 180 * math.pi), ( x[7] -5 / 180 * math.pi, x[7] + 5 / 180 * math.pi),
(-10 / 180 * math.pi, 10 / 180 * math.pi))
limfix = ( ((V-0.9)/V, (V+0.9)/V), (-5 / 180 * math.pi, 5 / 180 * math.pi), (-5 / 180 * math.pi, 5 / 180 * math.pi), (-0.2, 0.2))
elif g.hangar['aircraft']=='DECOL':
phimax = 10 # in degree the max bank angle authorized
alphamax = 25 # in degree, stall bound for trimming
deltaRmax = 30 # in degree
ThrottleMax = 1 # max thrust level
ThrottleMin = 0.0001 # min throttle, don't accept 0 thrust
V=fix[0]
# alfa p q r phi theta delta_a delta_e delta_r
#bnds=( (-5*math.pi/180,alphamax*math.pi/180), (-0.2,0.2), (-0.2,0.2), (-0.2,0.2), (-phimax/180*math.pi,phimax/180*math.pi), (-30/180*math.pi,30/180*math.pi), (-30/180*math.pi,30/180*math.pi), (-20/180*math.pi,20/180*math.pi), (-deltaRmax/180*math.pi,deltaRmax/180*math.pi))
bnds = ((0 * math.pi / 180, 5 * math.pi / 180), (-0.2*(g.b/(2*V)), 0.2*(g.b/(2*V))), (-0.2*(g.c/(2*V)), 0.2*(g.c/(2*V))), (-0.2*(g.b/(2*V)), 0.2*(g.b/(2*V))),
(-phimax / 180 * math.pi, phimax / 180 * math.pi), (-5 / 180 * math.pi, 5 / 180 * math.pi),
(-10 / 180 * math.pi, 10 / 180 * math.pi), ( x[7] -5 / 180 * math.pi, x[7] + 5 / 180 * math.pi),
(-10 / 180 * math.pi, 10 / 180 * math.pi))
limfix=( (21/V,26/V),(-5/180*math.pi,5/180*math.pi),(-5/180*math.pi,5/180*math.pi),(-0.2,0.2) )
#For longitudinal
bnds_eng_long=((ThrottleMin,ThrottleMax))
bnds_long=bnds+(bnds_eng_long,) + limfix
#For Lateral
bnds_eng_lat = tuple()
bnds_eng_lat=((x[10]-0.25,x[10]+0.25))
bnds_lat=bnds+(bnds_eng_lat,) + limfix
x = np.concatenate((x, fix))
# Adimensionalizing variables:
x[1] = x[1] / (2 * V / g.b) #p
x[2] = x[2] / (2 * V / g.c) #q
x[3] = x[3] / (2 * V / g.b) #r
x[-4] = x[-4] / V #V
#LONGITUDINAL
# (CD,CL,Cm)
#Variables (5): alpha ,q , delta_e ,delta_xi (all engines) , V
#variables and position in vector x (starting on 0)
# alpha 0
# q 2
# delta_e 7
# delta_xi: -(g.N_eng+4):-4
# V -4
#IN LONGITUDINAL, ALL ENGINES ARE VARIED IN THE SAME WAY, dx FROM 0 TO 1
variations=5
variables=5
testvector=np.zeros((len(x),(variations**variables)))
Xsample_longitudinal = np.zeros((variables, variations ** variables))
CD_sample = np.zeros((variations**variables))
CL_sample = np.zeros((variations**variables))
Cm_sample = np.zeros((variations**variables))
Coefs=np.zeros((6,(variations**variables)))
for i in range(variations):
for j in range(variations):
for k in range(variations):
for p in range(variations):
for q in range(variations):
testvector[:,i*variations**4+j*variations**3+k*variations**2+p*variations+q]=x
testvector[0, i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds_long[0][0] +i*(bnds_long[0][1] - bnds_long[0][0])/ (variations-1)
testvector[2, i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds_long[2][0] +j*(bnds_long[2][1] - bnds_long[2][0])/(variations-1)
testvector[7, i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds_long[7][0] +k*(bnds_long[7][1] - bnds_long[7][0])/(variations-1)
#ENGINES
testvector[-(g.N_eng+4):-4, i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds_long[-5][0]+p*(bnds_long[-5][1] - bnds_long[-5][0])/(variations-1)
testvector[-4 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds_long[-4][0]+q*(bnds_long[-4][1] - bnds_long[-4][0])/(variations-1)
Coefs[:, i*variations**4+j*variations**3+k*variations**2+p*variations+q] = Constraints_DEP(testvector[:, i*variations**4+j*variations**3+k*variations**2+p*variations+q], CoefMatrix, atmo, g, PropWing,V)
Xsample_longitudinal[0, :] = testvector[0, :]
Xsample_longitudinal[1, :] = testvector[2, :]
Xsample_longitudinal[2, :] = testvector[7, :]
Xsample_longitudinal[3, :] = testvector[12, :]
Xsample_longitudinal[4, :] = testvector[-4, :]
CD_sample = Coefs[0, :]
CL_sample = Coefs[2, :]
Cm_sample = Coefs[4, :]
#LATERAL
# (Cy,Cl,Cn)
# Variables (6): p , r , delta_a , delta_r , delta_xi, beta
# variables and position in vector x (starting on 0)
# p 1
# r 3
# delta_a 6
# delta_r 8
# delta_xi: -(g.N_eng+4):-4
# beta -3
#IN LATERAL ENGINES SHOULD BE VARIED DIFFERENTLY IN EACH WING. WHILE ONES ARE GIVEN MORE THRUST,
#THE OTHERS SHOULD BE GIVEN LESS THRUST
# left wing (with y negative): x[(-g.N_eng-4):-(g.N_eng//2+4)] = [ -16 : -10 ] (ATR)
# right wing (with y positive): x[-(g.N_eng//2+4):-4] = [-10 : -4 ] (ATR)
# bnds_lat=((2*x[9]-1,1), (1,2*x[9]-1))
variations2 = 5
variables2 = 6
testvector2 = np.zeros((len(x), (variations2 ** variables2)))
Xsample_lateral = np.zeros((variables2, variations2 ** variables2))
CY_sample = np.zeros((variations2**variables2))
Cl_sample = np.zeros((variations2**variables2))
Cn_sample = np.zeros((variations2**variables2))
Coefs2 = np.zeros((6, (variations2 ** variables2)))
for i in range(variations2):
for j in range(variations2):
for k in range(variations2):
for p in range(variations2):
for q in range(variations2):
for r in range(variations2):
testvector2[:, i*variations2**5+j*variations2**4+k*variations2**3+p*variations2**2+q*variations2+r]=x
testvector2[1, i*variations2**5+j*variations2**4+k*variations2**3+p*variations2**2+q*variations2+r] = bnds_lat[1][0] +i*(bnds_lat[1][1] - bnds_lat[1][0])/(variations2-1)
testvector2[3, i*variations2**5+j*variations2**4+k*variations2**3+p*variations2**2+q*variations2+r] = bnds_lat[3][0] +j*(bnds_lat[3][1] - bnds_lat[3][0])/(variations2-1)
testvector2[6, i*variations2**5+j*variations2**4+k*variations2**3+p*variations2**2+q*variations2+r] = bnds_lat[6][0] +k*(bnds_lat[6][1] - bnds_lat[6][0])/(variations2-1)
testvector2[8, i*variations2**5+j*variations2**4+k*variations2**3+p*variations2**2+q*variations2+r] = bnds_lat[8][0]+p*(bnds_lat[8][1] - bnds_lat[8][0])/(variations2-1)
if g.hangar['aircraft'] == 'ATR72':
# ENGINES
# Left
testvector2[(-g.N_eng - 4):-(g.N_eng // 2 + 4), i * variations2 ** 5 + j * variations2 ** 4 + k * variations2 ** 3 + p * variations2 ** 2 + q * variations2 + r] = bnds_lat[-5][0] + q * (bnds_lat[-5][1] - bnds_lat[-5][0]) / (variations2 - 1)
# Right
testvector2[-(g.N_eng // 2 + 4):-4, i * variations2 ** 5 + j * variations2 ** 4 + k * variations2 ** 3 + p * variations2 ** 2 + q * variations2 + r] = bnds_lat[-5][1] + q * (bnds_lat[-5][0] - bnds_lat[-5][1]) / (variations2 - 1)
elif g.hangar['aircraft'] == 'DECOL':
# ENGINES EN DECOL SOLO VARIAN LOS DOS MOTORES EXTERIORES. EL RESTO TIENEN QUE TENER UN VALOR NOMINAL DE POTENCIA, CUAL? LES PONGO 0.5? los dejo a su valor de trimado
# Left
testvector2[(-g.N_eng - 4):(-g.N_eng -2), i * variations2 ** 5 + j * variations2 ** 4 + k * variations2 ** 3 + p * variations2 ** 2 + q * variations2 + r] = bnds_lat[-5][0] + q * (bnds_lat[-5][1] - bnds_lat[-5][0]) / (variations2 - 1)
# Right
testvector2[-6:-4, i * variations2 ** 5 + j * variations2 ** 4 + k * variations2 ** 3 + p * variations2 ** 2 + q * variations2 + r] = bnds_lat[-5][1] + q * (bnds_lat[-5][0] - bnds_lat[-5][1]) / (variations2 - 1)
testvector2[-3, i*variations2**5+j*variations2**4+k*variations2**3+p*variations2**2+q*variations2+r] = bnds_lat[-3][0]+r*(bnds_lat[-3][1] - bnds_lat[-3][0])/(variations2-1)
Coefs2[:,i*variations2**5+j*variations2**4+k*variations2**3+p*variations2**2+q*variations2+r]=Constraints_DEP(testvector2[:,i*variations2**5+j*variations2**4+k*variations2**3+p*variations2**2+q*variations2+r], CoefMatrix, atmo, g, PropWing,V)
Xsample_lateral[0, :] = testvector2[1, :]
Xsample_lateral[1, :] = testvector2[3, :]
Xsample_lateral[2, :] = testvector2[6, :]
Xsample_lateral[3, :] = testvector2[8, :]
Xsample_lateral[4, :] = testvector2[10, :]
Xsample_lateral[5, :] = testvector2[-3, :]
CY_sample = Coefs2[1, :]
Cl_sample = Coefs2[3, :]
Cn_sample = Coefs2[5, :]
"""
#CD
#Variables: alpha, delta_e, deltax_i , V
#variables and position in vector x (starting on 0)
# alpha : 0
# delta_e : 7
# deltax_i r : 12
# V : -4
variations=10
variables=4
testvector=np.zeros((len(x),(variations**variables)))
CD_Xsample = np.zeros((variables, variations ** variables))
CD_Ysample=np.zeros(variations**variables)
Coefs=np.zeros((6,(variations**variables)))
for i in range(variations):
for j in range(variations):
for k in range(variations):
for p in range(variations):
testvector[:,i*variations**3+j*variations**2+k*variations+p]=x
testvector[0 ,i*variations**3+j*variations**2+k*variations+p] = bnds2[0][0] +i*(bnds2[0][1] - bnds2[0][0] )/variations
testvector[7 ,i*variations**3+j*variations**2+k*variations+p] = bnds2[7][0] +j*(bnds2[7][1] - bnds2[7][0] )/variations
testvector[12 ,i*variations**3+j*variations**2+k*variations+p] = bnds2[12][0]+k*(bnds2[12][1] - bnds2[12][0])/variations
testvector[-4 ,i*variations**3+j*variations**2+k*variations+p] = bnds2[-4][0]+p*(bnds2[-4][1] - bnds2[-4][0])/variations
Coefs[:,i*variations**3+j*variations**2+k*variations+p]=Constraints_DEP(testvector[:,i*variations**3+j*variations**2+k*variations+p], CoefMatrix, atmo, g, PropWing)
CD_Xsample[0,:]=testvector[0 ,:]
CD_Xsample[1,:]=testvector[7 ,:]
CD_Xsample[2,:]=testvector[12 ,:]
CD_Xsample[3,:]=testvector[-4 ,:]
CD_Ysample=Coefs[0,:]
#CONSIDERACIONES
#HAY QUE TENER CUIDADO CON TESTVECTOR, PORQUE SE LLAMA EN TODOS LOS BUCLES IGUAL, REVISA SI CUANDO DENTRO DEL BUCLE LE DICES QUE ES IGUAL QUE X SE REINICIA Y
#TOMA EL VALOR DEL VECTOR DE ESTADO
#PARA PONER TODOS LOS MOTORES DE UNA VEZ YO CREO QUE SERÍA:
# testvector[-(g.N_eng+4):-4 ,LO QUE SEA] = bnds2[-(g.N_eng+4):-4][0]+(LO QUE SEA)*(bnds2[12][1] - bnds2[12][0])/variations
#Cy
#Variables: p ,r , delta_r (if true) ,CT_i
#variables and position in vector x (starting on 0)
# p 1
# r 3
# delta r 8
# CT_i
# beta -3
variations=10
variables=5
testvector=np.zeros((len(x),(variations**variables)))
CY_Xsample = np.zeros((variables, variations ** variables))
CY_Ysample=np.zeros(variations**variables)
Coefs=np.zeros((6,(variations**variables)))
for i in range(variations):
for j in range(variations):
for k in range(variations):
for p in range(variations):
for q in range(variations):
testvector[:,i*variations**4+j*variations**3+k*variations**2+p*variations+q]=x
testvector[1 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds2[1][0] +i*(bnds2[1][1] - bnds2[1][0] )/variations
testvector[3 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds2[3][0] +j*(bnds2[3][1] - bnds2[3][0] )/variations
testvector[8 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds2[8][0] +k*(bnds2[8][1] - bnds2[8][0])/variations
testvector[12 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds2[12][0]+p*(bnds2[12][1] - bnds2[12][0])/variations
testvector[-3 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds2[-3][0]+q*(bnds2[-3][1] - bnds2[-3][0])/variations
Coefs[:,i*variations**4+j*variations**3+k*variations**2+p*variations+q]=Constraints_DEP(testvector[:,i*variations**4+j*variations**3+k*variations**2+p*variations+q], CoefMatrix, atmo, g, PropWing)
CY_Xsample[0,:]=testvector[1 ,:]
CY_Xsample[1,:]=testvector[3 ,:]
CY_Xsample[2,:]=testvector[8 ,:]
CY_Xsample[3,:]=testvector[12 ,:]
CY_Xsample[4, :] = testvector[-3, :]
CY_Ysample=Coefs[1,:]
#CL
#Variables , alfa ,q , delta_e ,CT_i , V
#variables and position in vector x (starting on 0)
# alfa 0
# q 2
# delta_e 6
# CT_i 12
# V -4
variations=10
variables=5
testvector=np.zeros((len(x),(variations**variables)))
Xsample = np.zeros((variables, variations ** variables))
Ysample=np.zeros(variations**variables)
Coefs=np.zeros((6,(variations**variables)))
for i in range(variations):
for j in range(variations):
for k in range(variations):
for p in range(variations):
for q in range(variations):
testvector[:,i*variations**4+j*variations**3+k*variations**2+p*variations+q]=x
testvector[0 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds2[0][0] +i*(bnds2[0][1] - bnds2[0][0] )/variations
testvector[2 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds2[2][0] +j*(bnds2[2][1] - bnds2[2][0] )/variations
testvector[6 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds2[6][0] +k*(bnds2[6][1] - bnds2[6][0])/variations
testvector[12 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds2[12][0]+p*(bnds2[12][1] - bnds2[12][0])/variations
testvector[-4 ,i*variations**4+j*variations**3+k*variations**2+p*variations+q] = bnds2[-4][0]+q*(bnds2[-4][1] - bnds2[-4][0])/variations
Coefs[:,i*variations**4+j*variations**3+k*variations**2+p*variations+q]=Constraints_DEP(testvector[:,i*variations**4+j*variations**3+k*variations**2+p*variations+q], CoefMatrix, atmo, g, PropWing)
Xsample[0,:] =testvector[0 ,:]
Xsample[1,:] =testvector[2 ,:]
Xsample[2,:] =testvector[6 ,:]
Xsample[3,:] =testvector[12 ,:]
Xsample[4,:] = testvector[-4, :]
Ysample=Coefs[2,:]
#Cl y Cn match in variables, so we do just one time
# Variables: p , r , delta_a , delta_r , CT_i , beta
# variables and position in vector x (starting on 0)
# p 0
# r 2
# delta_a 6
# delta_r 8
# CT_i 12
#beta -3
variations=10
variables=6
testvector=np.zeros((len(x),(variations**variables)))
Xsample = np.zeros((variables, variations ** variables))
Ysample=np.zeros(variations**variables)
Coefs=np.zeros((6,(variations**variables)))
for i in range(variations):
for j in range(variations):
for k in range(variations):
for p in range(variations):
for q in range(variations):
for r in range(variations):
testvector[:,i*variations**5+j*variations**4+k*variations**3+p*variations**2+q*variations+r]=x
testvector[0 ,i*variations**5+j*variations**4+k*variations**3+p*variations**2+q*variations+r] = bnds2[0][0] +i*(bnds2[0][1] - bnds2[0][0] )/variations
testvector[2 ,i*variations**5+j*variations**4+k*variations**3+p*variations**2+q*variations+r] = bnds2[2][0] +j*(bnds2[2][1] - bnds2[2][0] )/variations
testvector[6 ,i*variations**5+j*variations**4+k*variations**3+p*variations**2+q*variations+r] = bnds2[6][0] +k*(bnds2[6][1] - bnds2[6][0])/variations
testvector[8 ,i*variations**5+j*variations**4+k*variations**3+p*variations**2+q*variations+r] = bnds2[8][0]+p*(bnds2[8][1] - bnds2[8][0])/variations
testvector[12 ,i*variations**5+j*variations**4+k*variations**3+p*variations**2+q*variations+r] = bnds2[12][0]+q*(bnds2[12][1] - bnds2[12][0])/variations
testvector[-3, i*variations**5+j*variations**4+k*variations**3+p*variations**2+q*variations+r] = bnds2[-3][0]+q*(bnds2[-3][1] - bnds2[-3][0])/variations
Coefs[:,i*variations**5+j*variations**4+k*variations**3+p*variations**2+q*variations+r]=Constraints_DEP(testvector[:,i*variations**5+j*variations**4+k*variations**3+p*variations**2+q*variations+r], CoefMatrix, atmo, g, PropWing)
Xsample[0,:] =testvector[0 ,:]
Xsample[1,:] =testvector[2 ,:]
Xsample[2,:] =testvector[6 ,:]
Xsample[3,:] =testvector[8 ,:]
Xsample[4,:] =testvector[12, :]
Xsample[5,:] =testvector[-3,:]
Ysample=Coefs[3,:]
Ysample2 = Coefs[5, :]
#Cm
"""
return Xsample_longitudinal, Xsample_lateral, CD_sample, CY_sample, CL_sample, Cl_sample, Cm_sample, Cn_sample
def Constraints_DEP(x, CoefMatrix, atmo, g, PropWing,Vfix):
rho = atmo[1]
n_eng = int(g.N_eng / 2)
# --- Now prepare variables for equations ---
V = x[-4]*Vfix
alpha = x[0]
beta = x[-3]
gamma = x[-2]
omega = x[-1]
p = x[1]*(2*Vfix/g.b)
q = x[2]*(2*Vfix/g.c)
r = x[3]*(2*Vfix/g.b)
phi = x[4]
theta = x[5]
I = np.array([[g.Ix, 0, -g.Ixz], [0, g.Iy, 0], [-g.Ixz, 0, g.Iz]])
# --- Compute aerodynamic forces ---
# here subvector must be : (alpha, beta, p, q, r, da, de,dr, dx)
sub_vect = np.array([alpha, beta, p, q, r])
if g.nofin == False:
sub_vect = np.append(sub_vect, [x[6], x[7], x[8]]) # rudder is allowed
else:
sub_vect = np.append(sub_vect, [x[6], x[7]]) # no fin allowed, default case
V_vect = np.ones(g.N_eng) * V * np.cos((-np.sign(g.PosiEng)) * beta + g.wingsweep) - r * g.PosiEng
Fx_vec = g.Thrust(x[-(g.N_eng+4):-4], V_vect)
Tc = Fx_vec / (2 * rho * g.Sp * V_vect ** 2)
F = AeroForces.CalcForce_aeroframe_DEP(V, np.copy(CoefMatrix), np.copy(sub_vect), Tc, atmo, g, PropWing)
# F contains forces and moments in wind reference system, just the aerodynammic, not thrust
Coefs=np.zeros(len(F))
for i in range(len(F)):
if i==0 or i==1 or i==2:
Coefs[i] = F[i] / (0.5 * rho * V**2 * g.S)
elif i==4:
Coefs[i] = F[i] / (0.5 * rho * V**2 * g.S * g.c)
else:
Coefs[i] = F[i] / (0.5 * rho * V ** 2 * g.S * g.b)
return Coefs