forked from hugogarcia06/Patterson_code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForces_test.py
More file actions
1412 lines (858 loc) · 40.8 KB
/
Forces_test.py
File metadata and controls
1412 lines (858 loc) · 40.8 KB
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
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Useful model for computing the aerodynamic forces whichever the variables from state vector and fix vector are.
Therefore they can be calculated outside a trim state.
author: david.planas-andres
"""
import numpy as np
import math
from numpy.linalg import inv
from StabilityMapUtils import AeroForces
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 Distributed_engines(N_eng, DiameterHLP ):
"""
Function valid for the X-57 only. This function receives a number of engines and their diameter and distributes them equally
among the available span that starts outside the fuselage and finish at a distance of the wingtip equal to
1 radius of the wing-tip cruise propeller. It returns the value of yp, the vector containing the y position of
the engines (from left wing to right wing) in the body
reference system.
Modify so that for more engines the diameter is reduced.
"""
b = 9.642 # wingspan
Rtip = 0.5 * 60 * 0.0254 # radius of propeller at tip
FusR = 0.60198 # max. radius fuselage
change_diameter = True
if N_eng <= 12:
if change_diameter:
"""
For less than 12 engines, we increase the diameter in order to have still or the wing area washed.
"""
avail_y = 0.5*b - Rtip - FusR
RHLP = avail_y/(2*N_eng/2)
max_y = (0.5*b - Rtip - RHLP)
min_y = (FusR + RHLP)
yp = np.linspace(min_y, max_y, int(N_eng/2))
yp = np.hstack((np.flip(-yp), yp))
else:
# Diameter is not modified
RHLP = 0.5*DiameterHLP # radius of HLP
max_y = (0.5*b - Rtip - RHLP)
min_y = (FusR + RHLP)
yp = np.linspace(min_y, max_y, int(N_eng/2))
yp = np.hstack((np.flip(-yp), yp))
else: # Diameter needs to be modified so that there is space. In this case is modified for keeping all area wet
avail_y = 0.5*b - Rtip - FusR
RHLP = avail_y/(2*N_eng/2)
max_y = (0.5*b - Rtip - RHLP)
min_y = (FusR + RHLP)
yp = np.linspace(min_y, max_y, int(N_eng/2))
yp = np.hstack((np.flip(-yp), yp))
return yp, RHLP
def Constraints_DEP(CoefMatrix, atmo, g, PropWing):
#x = [alpha, p, q, r, phi, theta, delta_a, delta_e, delta_r, delta_i(hay 12), V , beta , gamma, omega] = x + fix
rho = atmo[1]
# --- Now prepare variables for equations ---
V = 70 # 51.741863715877166
beta = 0
gamma = 0
omega = 0
alpha = 0.2362537139286036
p = 0 # 0.25 max
q = 0
r = 0 # 0.1 max
phi = 0
theta = alpha
aileron = 0
elevator = -0.20600870692395656
rudder = 0
delta_x = 0.4 # dx = 0.5
g.FlapDefl = 0*np.pi/180 # 15*np.pi/180 , 30*np.pi/180
if g.FlapDefl == 0:
g.Cd0_fl = 0
g.CL0_fl = 0
g.Cm0_fl = 0
g.Cda = g.Cda_fl_0
g.Cdb = g.Cdb_fl_0
g.Cdc = g.Cdc_fl_0
g.eps0 = g.eps0_flaps0
g.deps_dalpha = g.deps_dalpha_flaps0
elif g.FlapDefl == 15 * np.pi / 180:
g.Cd0_fl = g.Cd0_fl_15
g.CL0_fl = g.CL0_fl_15
g.Cm0_fl = g.Cm0_fl_15
g.Cda = g.Cda_fl_15
g.Cdb = g.Cdb_fl_15
g.Cdc = g.Cdc_fl_15
g.eps0 = g.eps0_flaps15
g.deps_dalpha = g.deps_dalpha_flaps15
elif g.FlapDefl == 30 * np.pi / 180:
g.Cd0_fl = g.Cd0_fl_30
g.CL0_fl = g.CL0_fl_30
g.Cm0_fl = g.Cm0_fl_30
g.Cda = g.Cda_fl_30
g.Cdb = g.Cdb_fl_30
g.Cdc = g.Cdc_fl_30
g.eps0 = g.eps0_flaps30
g.deps_dalpha = g.deps_dalpha_flaps30
x = np.array([alpha, p, q, r, phi, theta, aileron, elevator, rudder])
for i in range(int(g.N_eng)):
x = np.append(x, delta_x)
#engines = np.array([0.5,0.5,0.5,0.8,0.5,0.5,0.5,0.5,0.2,0.5,0.5,0.5])
#x = np.append(x, engines)
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, [aileron, elevator, rudder]) # rudder is allowed
else:
sub_vect = np.append(sub_vect, [aileron, elevator]) # no fin allowed, default case
V_vect = np.ones(g.N_eng) * V * np.cos((-np.sign(g.yp)) * beta + g.wingsweep) - r * g.yp
Fx_vec = g.Thrust(x[-g.N_eng:],V_vect, atmo)
Fx = np.sum(Fx_vec)
#Matrix to transform a vector from body reference to aero reference
Body2Aero_matrix = np.array([[np.cos(alpha)*np.cos(beta), np.sin(beta), np.sin(alpha)*np.cos(beta)], [-np.cos(alpha)*np.sin(beta), np.cos(beta), -np.sin(alpha)*np.sin(beta)], [-np.sin(alpha), 0, np.cos(alpha)]])
# Moment and Force of thrust is obtained in body reference
Moment = np.zeros((g.N_eng, 3))
F_thrust_body = np.zeros((g.N_eng, 3))
for i in range(g.N_eng):
a = np.array([g.xp[i], g.yp[i], g.zp[i]])
b = np.array([Fx_vec[i]*np.cos(g.alpha_i - g.alpha_0+g.ip[i]), 0,-Fx_vec[i]*np.sin(g.alpha_i - g.alpha_0+g.ip[i])])
Moment[i, :] = np.cross(a, b)
F_thrust_body[i,:] = b
Thrust_moment_body = np.array((np.sum(Moment[:, 0]), np.sum(Moment[:, 1]), np.sum(Moment[:, 2])))
F_thrust_body = np.array((np.sum(F_thrust_body[:, 0]), np.sum(F_thrust_body[:, 1]), np.sum(F_thrust_body[:, 2])))
Mt = Thrust_moment_body
# Thrust force is transformed from body to aero reference
F_thrust_aero = Body2Aero_matrix @ F_thrust_body
Tc = Fx_vec / (2 * rho * g.Sp * V ** 2)
fixtest = np.array([V, beta, gamma, omega])
sinbank = np.sin(theta)*np.cos(alpha)*np.sin(beta) + np.cos(beta)*np.cos(theta)*np.sin(phi)-np.sin(alpha)*np.sin(beta)*np.cos(theta)*np.cos(phi)
cosbank = np.sin(theta)*np.sin(alpha)+np.cos(beta)*np.cos(theta)*np.cos(phi)
if g.IsPropWing:
h = 1
g.IsPropWing = True
g.IsPropWingDrag = True
F = AeroForces.CalcForce_aeroframe_DEP(V, np.copy(CoefMatrix), np.copy(sub_vect), Tc, atmo, g, PropWing)
# F contiene solo las fuerzas en ejes viento y momentos aerodinámicos en ejes cuerpo.
printx(x, fixtest, atmo, g, PropWing)
#CL = -F[2]/(0.5*rho*V**2 * g.S)
#CD = -F[0]/(0.5*rho*V**2 * g.S)
#CY = -F[1]/(0.5*rho*V**2 * g.S)
#Cm = -F[4]/(0.5*rho*V**2 * g.S * g.c)
Croll_thrust = Mt[0]/ (0.5 * rho * V ** 2 * g.S * g.b)
Cyawthrust = Mt[2]/ (0.5 * rho * V ** 2 * g.S * g.b)
Clroll = F[3]/(0.5*rho*V**2 * g.S * g.b)
Cn = F[5]/(0.5*rho*V**2 * g.S * g.b)
A=np.zeros(10)
A[0] = -9.81*np.sin(gamma)+(F[0]+F_thrust_aero[0])/g.m
A[1] = (p*np.sin(alpha) - r*np.cos(alpha))+g.m*9.81*sinbank/(g.m*V) + (F[1]+ F_thrust_aero[1])/(g.m*V)
A[2] = -(np.sin(beta)*(p*np.cos(alpha)+r*np.sin(alpha))-q*np.cos(beta))/np.cos(beta) + 9.81*cosbank/(V*np.cos(beta)) + (F[2] + F_thrust_aero[2])/(g.m*V*np.cos(beta))
A[3:6] = np.dot(inv(I), np.array([Mt[0], Mt[1], Mt[2]])+F[3:6]-np.cross(np.array([p, q, r]), np.dot(I, np.array([p, q, r]))))
A[6] = p+q*np.sin(phi)*np.tan(theta)+r*np.cos(phi)*np.tan(theta)
A[7] = q*math.cos(phi) - r * math.sin(phi)
A[8] = -np.sin(gamma)+np.cos(alpha)*np.cos(beta)*np.sin(theta)-np.sin(beta)*np.sin(phi)*np.cos(theta)-np.sin(alpha)*np.cos(beta)*np.cos(phi)*np.cos(theta)
A[9] = -omega + (q*np.sin(phi)+r*np.cos(phi))/np.cos(theta)
g.IsPropWing = False
g.IsPropWingDrag = False
F_no_int = AeroForces.CalcForce_aeroframe_DEP(V, np.copy(CoefMatrix), np.copy(sub_vect), Tc, atmo, g, PropWing)
A=np.zeros(10)
A[0] = -9.81*np.sin(gamma)+(F[0]+F_thrust_aero[0])/g.m
A[1] = (p*np.sin(alpha) - r*np.cos(alpha))+g.m*9.81*sinbank/(g.m*V) + (F[1]+ F_thrust_aero[1])/(g.m*V)
A[2] = -(np.sin(beta)*(p*np.cos(alpha)+r*np.sin(alpha))-q*np.cos(beta))/np.cos(beta) + 9.81*cosbank/(V*np.cos(beta)) + (F[2] + F_thrust_aero[2])/(g.m*V*np.cos(beta))
A[3:6] = np.dot(inv(I), np.array([Mt[0], Mt[1], Mt[2]])+F[3:6]-np.cross(np.array([p, q, r]), np.dot(I, np.array([p, q, r]))))
A[6] = p+q*np.sin(phi)*np.tan(theta)+r*np.cos(phi)*np.tan(theta)
A[7] = q*math.cos(phi) - r * math.sin(phi)
A[8] = -np.sin(gamma)+np.cos(alpha)*np.cos(beta)*np.sin(theta)-np.sin(beta)*np.sin(phi)*np.cos(theta)-np.sin(alpha)*np.cos(beta)*np.cos(phi)*np.cos(theta)
A[9] = -omega + (q*np.sin(phi)+r*np.cos(phi))/np.cos(theta)
if h == 1:
g.IsPropWing = True
g.IsPropWingDrag = True
return F,F_no_int
def Constraints_DEP_body(CoefMatrix, atmo, g, PropWing):
"""function defining constraints for power minimization
inputs:
-x =[alpha, p, q, r, phi, theta, delta_a, delta_e, delta_r, delta_i]
x is the state to determine
length of x except the propulsion levels is 8
-fix = [V, beta, gamma, omega]
fix is the vector of parameters whom are fixed by the user
"""
#x = [alpha, p, q, r, phi, theta, delta_a, delta_e, delta_r, delta_i(hay 12), V , beta , gamma, omega] = x + fix
rho = atmo[1]
PW = PropWing
# --- Now prepare variables for equations ---
V = 72
beta = 0
gamma = 0
omega = 0
alpha = 0.09727079748668332
p = -3.5734202462290796e-22 # 0.25 max
q = 8.205631676526035e-22
r = -3.6545873438358454e-22 # 0.1 max
phi = -9.355764297366552e-06
theta = 0.09727079748245356
aileron = -8.412261477902928e-05
elevator = -0.09318168652099662
rudder = -2.3758828310177916e-06
delta_x = 0.3153640459583273
g.FlapDefl = 0*np.pi/180 # 15*np.pi/180 , 30*np.pi/180
if g.FlapDefl == 0:
g.Cd0_fl = 0
g.CL0_fl = 0
g.Cm0_fl = 0
g.Cda = g.Cda_fl_0
g.Cdb = g.Cdb_fl_0
g.Cdc = g.Cdc_fl_0
g.eps0 = g.eps0_flaps0
g.deps_dalpha = g.deps_dalpha_flaps0
elif g.FlapDefl == 15 * np.pi / 180:
g.Cd0_fl = g.Cd0_fl_15
g.CL0_fl = g.CL0_fl_15
g.Cm0_fl = g.Cm0_fl_15
g.Cda = g.Cda_fl_15
g.Cdb = g.Cdb_fl_15
g.Cdc = g.Cdc_fl_15
g.eps0 = g.eps0_flaps15
g.deps_dalpha = g.deps_dalpha_flaps15
elif g.FlapDefl == 30 * np.pi / 180:
g.Cd0_fl = g.Cd0_fl_30
g.CL0_fl = g.CL0_fl_30
g.Cm0_fl = g.Cm0_fl_30
g.Cda = g.Cda_fl_30
g.Cdb = g.Cdb_fl_30
g.Cdc = g.Cdc_fl_30
g.eps0 = g.eps0_flaps30
g.deps_dalpha = g.deps_dalpha_flaps30
x = np.array([alpha, p, q, r, phi, theta, aileron, elevator, rudder])
for i in range(int(g.N_eng)):
x = np.append(x, delta_x)
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)
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
#Thrust forces and moments
V_vect = np.ones(g.N_eng) * V * np.cos((-np.sign(g.yp)) * beta + g.wingsweep) - r * g.yp
Fx_vec = g.Thrust(x[-g.N_eng:], V_vect, atmo)
Fx = np.sum(Fx_vec)
# convert thrust in Tc for patterson
Tc = Fx_vec/(2*rho*g.Sp*V**2) #For adimension V, has already been used for calculating FXi
F = AeroForces.CalcForce_aeroframe_DEP(V, np.copy(CoefMatrix), np.copy(sub_vect), Tc, atmo, g, PropWing)
#F gives out aerodinamical forces in aero axis: Drag, lateral force and lift and moments
# Does not give out X,Y,Z
#Matrix to transform a vector from body reference to aero reference
Body2Aero_matrix = np.array([[np.cos(alpha)*np.cos(beta), np.sin(beta), np.sin(alpha)*np.cos(beta)], [-np.cos(alpha)*np.sin(beta), np.cos(beta), -np.sin(alpha)*np.sin(beta)], [-np.sin(alpha), 0, np.cos(alpha)]])
# Moment and Force of thrust is obtained in body reference
Moment = np.zeros((g.N_eng, 3))
F_thrust_body = np.zeros((g.N_eng, 3))
for i in range(g.N_eng):
a = np.array([g.xp[i], g.yp[i], g.zp[i]])
b = np.array([Fx_vec[i]*np.cos(g.alpha_i - g.alpha_0+g.ip[i]), 0,-Fx_vec[i]*np.sin(g.alpha_i - g.alpha_0+g.ip[i])])
Moment[i, :] = np.cross(a, b)
F_thrust_body[i,:] = b
Thrust_moment_body = np.array((np.sum(Moment[:, 0]), np.sum(Moment[:, 1]), np.sum(Moment[:, 2])))
F_thrust_body = np.array((np.sum(F_thrust_body[:, 0]), np.sum(F_thrust_body[:, 1]), np.sum(F_thrust_body[:, 2])))
Mt = Thrust_moment_body
# Thrust force is transformed from body to aero reference
F_thrust_aero = Body2Aero_matrix @ F_thrust_body
# Transformation of aerodynamic forces from aero to body reference
F_aero_body=np.zeros(int(len(F)))
F_aero_body[0:3] = np.transpose(Body2Aero_matrix) @ F[0:3]
# Transformation of aerodynamic speed from aero to body reference
[u,v,w] = np.transpose(Body2Aero_matrix) @ np.concatenate(([V], [0], [0]))
sinbank = np.sin(theta)*np.cos(alpha)*np.sin(beta) + np.cos(beta)*np.cos(theta)*np.sin(phi)-np.sin(alpha)*np.sin(beta)*np.cos(theta)*np.cos(phi)
cosbank = np.sin(theta)*np.sin(alpha)+np.cos(beta)*np.cos(theta)*np.cos(phi)
A = np.zeros(10+g.inop)
A[0] = (1/g.m) * (F_thrust_body[0] + F_aero_body[0]) - 9.81*np.sin(theta) +r*v - q*w
A[1] =(1/g.m)*(F_aero_body[1]) + 9.81*np.cos(theta)*np.sin(phi) - r*u + p*w
A[2] =(1/g.m)*(F_thrust_body[2] +F_aero_body[2])+ 9.81*np.cos(theta)*np.cos(phi) +q*u - p*v
A[3:6] = np.dot(inv(I), np.array([Mt[0], Mt[1], Mt[2]])+F[3:6]-np.cross(np.array([p, q, r]), np.dot(I, np.array([p, q, r]))))
A[6] = p+q*np.sin(phi)*np.tan(theta)+r*np.cos(phi)*np.tan(theta)
A[7] = q*math.cos(phi) - r * math.sin(phi)
A[8] = -np.sin(gamma)+np.cos(alpha)*np.cos(beta)*np.sin(theta)-np.sin(beta)*np.sin(phi)*np.cos(theta)-np.sin(alpha)*np.cos(beta)*np.cos(phi)*np.cos(theta)
A[9] = -omega + (q*np.sin(phi)+r*np.cos(phi))/np.cos(theta)
for i in range(g.inop):
A[-1-i] = x[-1-i] #The inoperative engine are the last ones (right wing). Its value is minimized (to zero)
if g.hangar['version'] == 'original': #For obligating all the engines to have the same thrust
#no DEP with original twin or N engines; all engines have the same thrust
D = np.copy(A)
for i in range(g.N_eng-g.inop-1):
AAd = x[-g.N_eng]-x[-g.N_eng+i+1]
D = np.append(D, [AAd])
return D
else:
return A
def Long_equilibrium2(CoefMatrix, atmo, g, PropWing):
"""function defining constraints for speed minimization in longitudinal
inputs:
-x =[V, alpha, theta, delta_e, delta_i]
x is the state to determine
length of x except the propulsion levels is 8
-fix = [gamma, beta, p, q, r, phi, da, dr]
fix is the vector of parameters whom are fixed by the user
Again
gamma = beta = p = q = r = phi = da = dr = 0 as we are in LONGITUDINAL equilibrium
4 equations (2 forces, 1 moment, theta = alpha + gamma)
(variables = V, alpha, theta, de, di) problem oversized
that means there is place for optimization, with objective function V)
"""
"""
X-57 equilibrium conditions
V = 40.145
alpha = 0.0070674911658034625
de = -0.31381389162636214
dx = 0.9999996478122892
"""
rho = atmo[1]
# --- Now prepare variables for equations ---
V = 40.125
alpha = 8*np.pi/180
de = 0
dx = 0 # for zero thrust 0.022628 only at v=40.125
beta = (0*np.pi/180)
gamma = 0
p = (0*np.pi/180)
q = 0
r = (0*np.pi/180)
phi = 0
theta = alpha
da = 0
dr = 0
g.FlapDefl = 30 * np.pi/180 # 15*np.pi/180 , 30*np.pi/180
if g.FlapDefl == 0:
g.Cd0_fl = 0
g.CL0_fl = 0
g.Cm0_fl = 0
g.Cda = g.Cda_fl_0
g.Cdb = g.Cdb_fl_0
g.Cdc = g.Cdc_fl_0
g.eps0 = g.eps0_flaps0
g.deps_dalpha = g.deps_dalpha_flaps0
elif g.FlapDefl == 15 * np.pi / 180:
g.Cd0_fl = g.Cd0_fl_15
g.CL0_fl = g.CL0_fl_15
g.Cm0_fl = g.Cm0_fl_15
g.Cda = g.Cda_fl_15
g.Cdb = g.Cdb_fl_15
g.Cdc = g.Cdc_fl_15
g.eps0 = g.eps0_flaps15
g.deps_dalpha = g.deps_dalpha_flaps15
elif g.FlapDefl == 10 * np.pi / 180:
g.Cd0_fl = g.Cd0_fl_30
g.CL0_fl = g.CL0_fl_30
g.Cm0_fl = g.Cm0_fl_30
g.Cda = g.Cda_fl_30
g.Cdb = g.Cdb_fl_30
g.Cdc = g.Cdc_fl_30
g.eps0 = g.eps0_flaps30
g.deps_dalpha = g.deps_dalpha_flaps30
elif g.FlapDefl == 30 * np.pi / 180:
g.Cd0_fl = g.Cd0_fl_30
g.CL0_fl = g.CL0_fl_30
g.Cm0_fl = g.Cm0_fl_30
g.Cda = g.Cda_fl_30
g.Cdb = g.Cdb_fl_30
g.Cdc = g.Cdc_fl_30
g.eps0 = g.eps0_flaps30
g.deps_dalpha = g.deps_dalpha_flaps30
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)
sub_vect = np.array([alpha, beta, p, q, r, da, de, dr]) # rudder is allowed
# Thrust forces and moments
V_vect = np.ones(g.N_eng) * V * np.cos((-np.sign(g.yp)) * beta + g.wingsweep) - r * g.yp
Fx_vec = g.Thrust(np.full(g.N_eng, dx), V_vect, atmo)
Fx = np.sum(Fx_vec)
# Matrix to transform a vector from body reference to aero reference
Body2Aero_matrix = np.array([[np.cos(alpha)*np.cos(beta), np.sin(beta), np.sin(alpha)*np.cos(beta)], [-np.cos(alpha)*np.sin(beta), np.cos(beta), -np.sin(alpha)*np.sin(beta)], [-np.sin(alpha), 0, np.cos(alpha)]])
# Moment and Force of thrust is obtained in body reference
Moment = np.zeros((g.N_eng, 3))
F_thrust_body = np.zeros((g.N_eng, 3))
for i in range(g.N_eng):
a = np.array([g.xp[i], g.yp[i], g.zp[i]])
b = np.array([Fx_vec[i]*np.cos(g.alpha_i - g.alpha_0+g.ip[i]), 0, -Fx_vec[i]*np.sin(g.alpha_i - g.alpha_0+g.ip[i])])
Moment[i, :] = np.cross(a, b)
F_thrust_body[i, :] = b
Thrust_moment_body = np.array((np.sum(Moment[:, 0]), np.sum(Moment[:, 1]), np.sum(Moment[:, 2])))
F_thrust_body = np.array((np.sum(F_thrust_body[:, 0]), np.sum(F_thrust_body[:, 1]), np.sum(F_thrust_body[:, 2])))
Mt = Thrust_moment_body
# Thrust force is transformed from body to aero reference
F_thrust_aero = Body2Aero_matrix @ F_thrust_body
# Convert thrust in Tc for patterson
Tc = Fx_vec/(2*rho*g.Sp*V**2) # For turning dimensionless use V, V_vect has already been used for calculating FXi
F = AeroForces.CalcForce_aeroframe_DEP(V, np.copy(CoefMatrix), np.copy(sub_vect), Tc, atmo, g, PropWing)
# F gives CD CY CL aerodynamic forces in aero ref, Moments in body ref.
CD = -F[0]/(0.5*rho*V**2 * g.S)
CY = -F[1]/(0.5*rho*V**2 * g.S)
CL = -F[2]/(0.5*rho*V**2 * g.S)
Clroll = F[3]/(0.5*rho*V**2 * g.S * g.b)
Cm = F[4]/(0.5*rho*V**2 * g.S * g.c)
Cn = F[5]/(0.5*rho*V**2 * g.S * g.b)
# Now sum up the constraints:
A = np.zeros(4)
A[0] = +(F[0] + F_thrust_aero[0])
A[1] = 9.81*g.m + (F[2] + F_thrust_aero[2])
A[2] = (Mt[1] + F[4])
A[3] = alpha + gamma - theta
fixtest = np.array([V, beta, gamma, 0])
x = np.array([alpha, p, q, r, phi, theta, da, de, dr])
for i in range(int(g.N_eng)):
x = np.append(x, dx)
printx(x, fixtest, atmo, g, PropWing)
# Plotting
alpha_vector = np.linspace(-4, 24, 15)*np.pi/180
dx_vector = np.linspace(0.39, 0.39, 1)
Tc = np.zeros((len(dx_vector), g.N_eng))
Cm_matrix = np.zeros((len(dx_vector), len(alpha_vector)))
CL_matrix = np.zeros((len(dx_vector), len(alpha_vector)))
CD_matrix = np.zeros((len(dx_vector), len(alpha_vector)))
epsilon_matrix = np.zeros((len(dx_vector), len(alpha_vector)))
Cdi = np.zeros((len(dx_vector), len(alpha_vector)))
tempCdo = np.zeros((len(dx_vector), len(alpha_vector)))
Cdwash = np.zeros((len(dx_vector), len(alpha_vector)))
for i in range(len(dx_vector)):
Fx_vec = g.Thrust(np.full(g.N_eng, dx_vector[i]), V_vect, atmo)
Tc[i, :] = Fx_vec/(2*rho*g.Sp*V**2)
for j in range(len(alpha_vector)):
sub_vect = np.array([alpha_vector[j], beta, p, q, r, da, de, dr])
F = AeroForces.CalcForce_aeroframe_DEP(V, np.copy(CoefMatrix), np.copy(sub_vect), Tc[i, :], atmo, g, PropWing)
Drags = PropWing.CalcCoef(Tc[i, :], V/atmo[0], atmo, alpha_vector[j], 0, g.FlapDefl, g, beta, p, V, r)
Cdi[i, j] = Drags[2]
tempCdo[i, j] = Drags[3]
Cdwash[i, j] = Drags[5]
CL_matrix[i, j] = -F[2] / (0.5*rho*V**2 * g.S)
CD_matrix[i, j] = -F[0] / (0.5*rho*V**2 * g.S)
Cm_matrix[i, j] = F[4] / (0.5*rho*V**2 * g.S * g.c)
epsilon_matrix[i, j] = AeroForces.Cm_and_CL_tail(V, CoefMatrix, sub_vect, Tc[i, :], atmo, g, PropWing)[2]
print('alpha')
print(alpha)
print('CL')
print(CL_matrix)
print('Cdi')
print(Cdi)
print('tempCd0')
print(tempCdo)
print('Cdwash')
print(Cdwash)
print('CdTOTAL')
print(CD_matrix)
print('Cm')
print(Cm_matrix)
fig1 = plt.figure()
ax1 = fig1.gca()
for i in range(len(dx_vector)):
ax1.plot(alpha_vector*180/np.pi, Cm_matrix[i, :], label="$T_c$ = {0:0.3f}".format(Tc[i, 0]), linestyle=":", color='r', alpha = 0.8 + 0.8*i/11)
ax1.set_xlabel('alpha (°)')
ax1.set_ylabel('Cm')
ax1.legend()
ax1.grid()
fig1.tight_layout()
fig2 = plt.figure()
ax2 = fig2.gca()
for i in range(len(dx_vector)):
ax2.plot(alpha_vector*180/np.pi, epsilon_matrix[i, :]*180/np.pi, label="$T_c$ = {0:0.3f}".format(Tc[i, 0]), linestyle=":", color='g', alpha = 0.8 + 0.8*i/11)
ax2.set_xlabel('alpha (°)')
ax2.set_ylabel('Downwash')
ax2.legend()
ax2.grid()
fig2.tight_layout()
fig3 = plt.figure()
ax3 = fig3.gca()
for i in range(len(dx_vector)):
ax3.plot(alpha_vector*180/np.pi, CL_matrix[i, :], label="$T_c$ = {0:0.3f}".format(Tc[i, 0]), linestyle=":", color='g', alpha = 0.8 + 0.8*i/6)
ax3.set_xlabel('alpha (°)')
ax3.set_ylabel('CL')
ax3.legend()
ax3.grid()
fig3.tight_layout()
fig4 = plt.figure()
ax4 = fig4.gca()
for i in range(len(dx_vector)):
ax4.plot(alpha_vector*180/np.pi, CD_matrix[i, :], label="$T_c$ = {0:0.3f}".format(Tc[i, 0]), linestyle=":", color='b', alpha = 0.8 + 0.8*i/6)
ax4.set_xlabel('alpha (°)')
ax4.set_ylabel('CD')
ax4.legend()
ax4.grid()
fig4.tight_layout()
plt.show(block=True)
return A
def printx(x, fix, atmo, g, PW):
V = fix[0]
alpha = x[0]/math.pi*180
beta = fix[1]/math.pi*180
pqr = x[1:4]/math.pi*180
phi = x[4]/math.pi*180
theta = x[5]/math.pi*180
da = x[6]/math.pi*180
de = x[7]/math.pi*180
print("\nState vector value:")
print("V= {0:0.2f}m/s, alpha = {1:0.2f}\xb0, beta={2:0.2f}\xb0, phi={3:0.2f}\xb0, theta={4:0.2f}\xb0".format(V, alpha, beta, phi, theta))
print("p={0:0.4f}\xb0/s q={1:0.4f}\xb0/s r={2:0.4f}\xb0/s".format(*pqr))
print("da={0:0.2f}\xb0, de= {1:0.2f}\xb0".format(da,de))
V_vect = np.ones(g.N_eng) * V * np.cos((-np.sign(g.yp)) * fix[1] + g.wingsweep) - x[3] * g.yp
if g.IsPropWing:
if V <= g.VelFlap or g.FlapDefl != 0:
PW.PlotDist(g.Thrust(x[-g.N_eng:], V_vect, atmo)/(2*atmo[1]*g.Sp*V**2), V/atmo[0], atmo, x[0], x[6], g.FlapDefl, g, False, beta, x[1], V, x[3])
else:
PW.PlotDist(g.Thrust(x[-g.N_eng:], V_vect, atmo)/(2*atmo[1]*g.Sp*V**2), V/atmo[0], atmo, x[0], x[6], 0, g, False, beta, x[1], V, x[3])
if g.nofin==False:
print("dr = {0:0.2f}\xb0".format(x[8]/math.pi*180))
def PLOTSX57(CoefMatrix, atmo, g, PropWing):
"""
% Aircraft: X-57
% H = 0 m, V = 28.3 m/s , beta = 0, gamma = 0, omega = 0, dx = 1
% Flaps deployed: n
% dx = 1
% de = 0 (But we will just plot CL,wing anyways)
"""
rho = atmo[1]
# --- Now prepare variables for equations ---
V = 28.3 #40.145
de = 0
dx = 1
beta = 0
gamma = 0
p = 0
q = 0
r = 0
phi = 0
da = 0
dr = 0
g.FlapDefl = 0 * np.pi/180 # 15*np.pi/180 , 30*np.pi/180
if g.FlapDefl == 0:
g.Cd0_fl = 0
g.CL0_fl = 0
g.Cm0_fl = 0
g.Cda = g.Cda_fl_0
g.Cdb = g.Cdb_fl_0
g.Cdc = g.Cdc_fl_0
g.eps0 = g.eps0_flaps0
g.deps_dalpha = g.deps_dalpha_flaps0
elif g.FlapDefl == 30 * np.pi / 180:
g.Cd0_fl = g.Cd0_fl_30
g.CL0_fl = g.CL0_fl_30
g.Cm0_fl = g.Cm0_fl_30
g.Cda = g.Cda_fl_30
g.Cdb = g.Cdb_fl_30
g.Cdc = g.Cdc_fl_30
g.eps0 = g.eps0_flaps30
g.deps_dalpha = g.deps_dalpha_flaps30
I = np.array([[g.Ix, 0, -g.Ixz], [0, g.Iy, 0], [-g.Ixz, 0, g.Iz]])
ang_speed = np.array([p, q, r])
# Thrust forces and moments
#V_vect = np.ones(g.N_eng) * V * np.cos((-np.sign(g.yp)) * beta + g.wingsweep) - r * g.yp
original_ip_vector = g.ip
original_offset_vector = g.x_offset
original_diameter = g.Dp
#PLOT 1
#Angles of attack: 4, 8 [°] (two lines)
#Axe x: Variation of installation angle
#Axe y: CL,wing
"""
alpha_vector = np.linspace(8, 8, 1)*np.pi/180
ip_vector = np.linspace(g.ip[0]*180/np.pi-20, g.ip[0]*180/np.pi+8, 29)*np.pi/180
CL_matrix = np.zeros((len(alpha_vector), len(ip_vector)))
for i in range(len(alpha_vector)):
for j in range(len(ip_vector)):
g.ip = np.full(g.N_eng, ip_vector[j])
sub_vect = np.array([alpha_vector[i], beta, p, q, r, da, de, dr])
V_vect = np.zeros((g.N_eng))
for k in range(g.N_eng):
a = np.array([g.xp[k], g.yp[k], g.zp[k]])
V_vect[k] = (V + np.cross(ang_speed, a)[0])*np.cos((-np.sign(g.yp[k])) * beta + g.wingsweep)*np.cos(alpha_vector[i]+g.alpha_i-g.alpha_0+g.ip[k])
Fx_vec = g.Thrust(np.full(g.N_eng, dx), V_vect, atmo)
Fx = np.sum(Fx_vec)
# Convert thrust in Tc for patterson
Tc = Fx_vec/(2*rho*g.Sp*V**2) # For turning dimensionless use V, V_vect has already been used for calculating FXi
F = AeroForces.CalcForce_aeroframe_DEP(V, np.copy(CoefMatrix), np.copy(sub_vect), Tc, atmo, g, PropWing)
# CL_tail = AeroForces.Cm_and_CL_tail(V, np.copy(CoefMatrix), x, Tc, atmo, g, PropWing)[1]
CL_matrix[i, j] = -F[2] / (0.5*rho*V**2 * g.S)
print('Plot1')
print(ip_vector)
print(CL_matrix)
g.x_offset = original_offset_vector
"""
#PLOT 2
#Angles of attack: 4, 8 [°] (two lines)
#Axe x: Variation of installation angle
#Axe y: CL,eff, adding vertical contribution of thrust
"""
alpha_vector = np.linspace(4, 8, 2)*np.pi/180
ip_vector = np.linspace(-20, 8, 29)*np.pi/180
CL_matrix = np.zeros((len(alpha_vector), len(ip_vector)))
for i in range(len(alpha_vector)):
for j in range(len(ip_vector)):
g.ip = np.full(g.N_eng, ip_vector[j])
sub_vect = np.array([alpha_vector[i], beta, p, q, r, da, de, dr])
V_vect = np.zeros((g.N_eng))
for k in range(g.N_eng):
a = np.array([g.xp[i], g.yp[i], g.zp[i]])
V_vect[k] = (V + np.cross(ang_speed, a)[0])*np.cos((-np.sign(g.yp[k])) * beta + g.wingsweep)*np.cos(alpha_vector[i]+g.alpha_i-g.alpha_0+g.ip[k])
Fx_vec = g.Thrust(np.full(g.N_eng, dx), V_vect, atmo)
Fx = np.sum(Fx_vec)
# Convert thrust in Tc for patterson
Tc = Fx_vec/(2*rho*g.Sp*V**2) # For turning dimensionless use V, V_vect has already been used for calculating FXi
F = AeroForces.CalcForce_aeroframe_DEP(V, np.copy(CoefMatrix), np.copy(sub_vect), Tc, atmo, g, PropWing)
# Matrix to transform a vector from body reference to aero reference
Body2Aero_matrix = np.array([[np.cos(alpha_vector[i])*np.cos(beta), np.sin(beta), np.sin(alpha_vector[i])*np.cos(beta)], [-np.cos(alpha_vector[i])*np.sin(beta), np.cos(beta), -np.sin(alpha_vector[i])*np.sin(beta)], [-np.sin(alpha_vector[i]), 0, np.cos(alpha_vector[i])]])
# Moment and Force of thrust is obtained in body reference
Moment = np.zeros((g.N_eng, 3))
F_thrust_body = np.zeros((g.N_eng, 3))
for k in range(g.N_eng):
a = np.array([g.xp[k], g.yp[k], g.zp[k]])
b = np.array([Fx_vec[k]*np.cos(g.alpha_i - g.alpha_0+g.ip[k]), 0, -Fx_vec[k]*np.sin(g.alpha_i - g.alpha_0+g.ip[k])])
Moment[k, :] = np.cross(a, b)
F_thrust_body[k, :] = b
Thrust_moment_body = np.array((np.sum(Moment[:, 0]), np.sum(Moment[:, 1]), np.sum(Moment[:, 2])))
F_thrust_body = np.array((np.sum(F_thrust_body[:, 0]), np.sum(F_thrust_body[:, 1]), np.sum(F_thrust_body[:, 2])))
Mt = Thrust_moment_body
# Thrust force is transformed from body to aero reference
F_thrust_aero = Body2Aero_matrix @ F_thrust_body
CL_matrix[i, j] = (-F[2] - F_thrust_aero[2] )/ (0.5*rho*V**2 * g.S)