-
Notifications
You must be signed in to change notification settings - Fork 3
/
ysimi.py
executable file
·1433 lines (1397 loc) · 55 KB
/
ysimi.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
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
#!/usr/bin/env python
#
## ysimi.py: YASim Interactively Adjust Numbers: a pandas / bokeh testbench for YASim
# takes a given YASim config file, offers a web based plotter for Lift, drag, L/D
# creates modified YASim configs for different YASim versions
# offers slider control of various key YASim elements and re-plots interactively
#
# [cdir]-yasim-inpt.xml yasim config xml Original
# ..-outp.xml yasim config xml generated with eg modified varied elements
# ..-lvsd.txt generated Lift / Drag tables ( version specific )
# ..-mia?.txt generated IAS for 0vSpd vs AoA ( version specific )
# ..-soln.txt generated solution values ( version specific )
#
# To run a local server: bokeh serve ysimi.py and then
# browse to: http://localhost:5006/ysimi
#
# Suggested workflow ( various files are created / written )
# Make a working directory named for the model ex: '[myModel]' for North-American-T6-Texan
# and use it as your working directory:
# mkdir [myModel]; cd [myModel]
# Copy ysimi.py into this working directory so it can run
#
# Copy the YASim configuration from Flightgear's Aircraft folder
# then rename it to retain the original
# ( the executable's input YASim configuration file has a specific fileID )
# cp fgaddon/Aircraft/[myModel-yasim.xml] [thisDir]-yasim-inpt.xml
# mv fgaddon/Aircraft/[myModel-yasim.xml] fgaddon/Aircraft/[myModel-yasim-orig.xml]
# In Flightgear's Aircraft folder use the modified output as YASim config:
# ( This way you can continually flight test adhustments yo the FDM configuration )
# ln -s [thisDir]-yasim-outp.xml] fgaddon/Aircraft/[myModel-yasim.xml]
#
# In a command console: start bokeh server, with a refence to the python script:
# Watch this console for updated YASim solution summaries
# bokeh serve [ --port x ] ../ysimi.py
#
# Browse with your web browser to the interactive panel:
# http://localhost:5006/ysimi
# As you adjust the sliders: YASim reruns, curves and console are updated
# and the changed yasim configuration is written to [myModel]-yasim-outp.xml
# save the changed yasim configuration [myModel]-yasim-outp.xml to the -inpt,
# whenever the web page is refreshed the screen will rload from -inpt
#
# For comparing with a model in aNewModel folder open a second command console:
# mkdir aNewmodel; cd aNewmodel
# copy ysomi.py
# copy its configuration from flightgear into: aNewModel-yasim-inpt.xml
# and open the app on a different port: bokeh serve --port 5007 ysimi.py
# Open a new tab with new port from your browser : http://localhost:5007
# so that two models may be compared in side-by-side browser tabs
#
# ysim will not write any element that is missing ( ie defaulted ) in the input file,
# if you need to adjust an elemnt slider it must be included in the input file
#
# only the first ballast element is adjusted, following ones should be untouched.
#
# developed from bokeh example: bokehSliders.py:
# https://www.pluralsight.com/guides/
# importing-data-from-tab-delimited-files-with-python
# https://pandas.pydata.org/docs/getting_started/intro_tutorials/
# 02_read_write.html#min-tut-02-read-write
#
##
##
import os, shlex, subprocess, sys, getopt, math
import csv, numpy as np, pandas as pd
#
from bokeh.io import curdoc
from bokeh.models.callbacks import CustomJS
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource, Slider, Dropdown
from bokeh.models import TextInput, DataTable, TableColumn
from bokeh.plotting import figure
from collections import OrderedDict
from time import gmtime, strftime
##
# Python Version
global pythVers
pythVers = sys.version_info[0]
#print('pythVers:', pythVers)
if (pythVers < 3) :
import xml.etree.ElementTree as ET
else :
import xml.etree.ElementTree as ET
#
##
global wdir, procPref, lvsdFid, iasaFid, iascFid, drgaFid, solnFid
global solnDict, solnCDS, solnCols, solnDT, solnIter, solnElev, solnCgMC, solnCgWB
global yCfgName, yCfgFid, aCfgFid, vCfgFid, versDict, versToDo, versKywd
#
## These vbles correspond to the elements in the config file:
global Va, Aa, Ka, Ta, Fa # Appr Spd, Aoa, Thrt, Fuel, Flaps
global Vc, Hc, Kc, Tc # Cruise Spd, Alt, Thrt, Fuel
global Iw, Aw, Cw, Lf, La, Dw, Ww, Pw, Df, Da, Hw # Wing, Flap, Ailr
global Tx, Ax, Cx, Lg, Lt, D1, W1, Px, Dg, Dt, Tw # Wng1, Flap, Ailr
global Ch, Ah, Eh, Le, Cv, Dh, Wh, Ph, De, Dv, H1 # Hstab, Elev (incidence set by solver )
global Av, Ev, Iv, Tv, Lr, Wv, Pv, Iu, Tu, Dr # Vstab V0:'v' V1:'u', Rudder
global Mp, Rp, Ap, Np, Xp, Ip, Op, Vp, Cp, Tp # Prop
global Mb, Xb, Yb, Zb, Hy, Vy, Wx, Wb, Gx # Ballast, Solver, Wh main, base, CG
global fracInci, totlInci # Wing incidence and CoG
##
# Pull args from command line
def pullArgs(argv):
global wdir
try:
opts, args = getopt.getopt(argv, "i:w:", \
["inputID=", "workdir="] )
except getopt.GetoptError:
print ('sorry, args do not make sense ')
sys.exit(2)
#
wdir = ''
for opt, arg in opts:
if opt in ("-i", "--inputID"):
print( "args I: ", arg)
if opt in ("-w", "--workdir"):
wdir = arg
print( "wdir now: ", wdir)
# Set Defaults
def presets():
global wdir, procPref, lvsdFid, iasaFid, iascFid, drgaFid, solnFid
global yCfgName, yCfgFid, aCfgFid, vCfgFid, versDict, versToDo, versKywd
global Hy, Vy # Solver parms
#print( 'Entr presets')
# non blank wdir: work folder is specified in args
if (wdir == ''):
wdir = os.getcwd()
wdirTail = wdir.rfind( '/' )
if ( wdirTail == -1 ) :
procPref = 'ysimi'
else :
procPref = wdir[ ( wdirTail + 1 ):]
#print(procPref)
#procPref = "ysimi"
## Default File IDs
# aCFig is output yasim config files with element(s) modified
aCfgFid = wdir + '/' + procPref + '-yasim-outp.xml'
# yasim config xml file read input
yCfgFid = wdir + '/' + procPref + '-yasim-inpt.xml'
#
yCfgName = yCfgFid.find('.xml')
yCfgName = yCfgFid[0:yCfgName]
##
# Versions in YASim configuration strings, OrderedDict
# all versions
versDict = OrderedDict([ ('-vOrig', 'YASIM_VERSION_ORIGINAL'), \
('-v2017-2', '2017.2'), \
('-v32', 'YASIM_VERSION_32',), \
('-vCurr', 'YASIM_VERSION_CURRENT', )])
versToDo = '-vCurr'
versKywd = versDict[versToDo]
#print('presets versKywd:', versKywd)
#
lvsdFid = procPref + versToDo + '-lvsd.txt'
drgaFid = procPref + versToDo + '-drga.txt'
iasaFid = procPref + versToDo + '-iasa.txt'
iascFid = procPref + versToDo + '-iasc.txt'
solnFid = procPref + versToDo + '-soln.txt'
#
#print( 'Exit presets')
##
# Return numeric value from 'name="nn.nnn"' tuple in config file
#
def tuplValu( tChrs, tText ):
# opening quote is '="' chars beyond name
begnValu = tText.find( tChrs) + len(tChrs) + 2
endsValu = begnValu + (tText[begnValu:]).find('"')
#print( tChrs, ': ', tText[(begnValu) : (endsValu) ] )
return( float( tText[(begnValu) : (endsValu) ] ))
##
# Return given text with given value substituted at name="value" in config file
#
def tuplSubs( tChrs, tText, tValu ):
if ( tChrs in tText ) :
# opening quote is '="' chars beyond name
begnValu = tText.find( tChrs) + len(tChrs) + 2
endsValu = begnValu + (tText[begnValu:]).find('"')
resp = tText[ : begnValu] + (('%f' % tValu).rstrip('0').rstrip('.')) + tText[endsValu :]
return(resp)
else :
return(tText)
##
# Scan original YASim config and extract numeric elements, save for tix menu
#
def vblsFromTplt():
#print( 'Entr vblsFromTplt')
global procPref, lvsdFid, iasaFid, iascFid, drgaFid, solnFid
global solnDict, solnCDS, solnCols, solnDT, solnIter, solnElev, solnCgMC, solnCgWB
global yCfgName, yCfgFid, aCfgFid, vCfgFid, versDict, versToDo, versKywd
#
## These vbles correspond to the elements in the config file:
global Va, Aa, Ka, Ta, Fa # Appr Spd, Aoa, Thrt, Fuel, Flaps
global Vc, Hc, Kc, Tc # Cruise Spd, Alt, Thrt, Fuel
global Iw, Aw, Cw, Lf, La, Dw, Ww, Pw, Df, Da, Hw # Wing, Flap, Ailr
global Tx, Ax, Cx, Lg, Lt, D1, W1, Px, Dg, Dt, Tw # Wng1, Flap, Ailr
global Ch, Ah, Eh, Le, Cv, Dh, Wh, Ph, De, Dv, H1 # Hstab, Elev (incidence set by solver )
global Av, Ev, Iv, Tv, Lr, Wv, Pv, Iu, Tu, Dr # Vstab V0:'v' V1:'u', Rudder
global Mp, Rp, Ap, Np, Xp, Ip, Op, Vp, Cp, Tp # Prop
global Mb, Xb, Yb, Zb, Hy, Vy, Wx, Wb, Gx # Ballast, Solver, Wh main, base, CG
global fracInci, totlInci # Wing incidence and CoG
##
# These flags indicate parsing has detected various sections of yasim config
apprFlag = 0
cruzFlag = 0
wingFlag = 0
wng1Flag = 0
hstabFlag = 0
vstabFlag = 0
vstabDone = 0
mstabFlag = 0
mstabDone = 0
ballFlag = 0
ballDone = 0
propFlag = 0
# YASim 'Solve At' values for Speed and Altitude
Vy = 100
Hy = 1000
#
Va = Aa = Ka = Ta = Fa = Vc = Hc = Kc = Tc = Hw = H1 = Wx = Wb = Gx = 0.00
Iw = Aw = Tw = Tx = Ax = Ah = Cv = Av = Wv = Pv = Iv = Tv = Iu = Tu = Cw = Cx = Ch = 0.00
Eh = Ev = La = Lf = Lg = Lt = Lh = Lv = Lr = Da = Df = Dg = Dt = Dh = Dr = Dw = D1 = Dv = 1.00
Pw = Px = Ph = 1.50
Ww = W1 = Wh = 2.00
Mp = Rp = Ap = Np = Xp = Ip = Op = Vp = Cp = Tp = 0
# in case ballast element is missing, fake with tiny value
Mb = Xb = Yb = Zb = 0.001
#
# open base yasim config file and parse elements
#print(yCfgFid)
with open(yCfgFid, 'r') as yCfgHndl:
# step each line in template yasim config file
for line in yCfgHndl:
# set / clear flags for each section
# flag on approach section
if '<approach' in line:
apprFlag = 1
if '</approach' in line:
apprFlag = 0
# flag on cruise section
if '<cruise' in line:
cruzFlag = 1
if '</cruise' in line:
cruzFlag = 0
# flag on wing section
if '<wing' in line:
wingFlag = 1
#print('fromTplt <wing')
if '</wing' in line:
wingFlag = 0
wng1Flag = 0
#print('fromTplt </wing')
# flag on hstab section
if '<hstab' in line:
hstabFlag = 1
if '</hstab' in line:
hstabFlag = 0
# flag on vstab section
if '<vstab' in line:
vstabFlag = 1
if '</vstab' in line:
vstabFlag = 0
vstabDone = 1
# flag on mstab section
if '<mstab' in line:
mstabFlag = 1
#print('fromTplt <mstab')
if '</mstab' in line:
mstabFlag = 0
mstabDone = 1
#print('fromTplt </mstab')
# flag on ballast section
if '<ballast' in line:
ballFlag = 1
if '</ballast' in line:
ballFlag = 0
ballDone = 1
# flag on prop section
if '<propeller' in line:
propFlag = 1
if '</propeller' in line:
propFlag = 0
### appr section parse approach speed and AoA elements
if (apprFlag == 1):
##
#in appr section, find elements
if ('approach' in line):
# find element names, save values to post in Tix gui
if ( 'speed' in line):
Va = tuplValu('speed', line)
#
if ( 'aoa' in line):
Aa = tuplValu('aoa', line)
#
if ( 'fuel' in line):
Ka = tuplValu('fuel', line)
#
#print ('Va: ', Va, ' Aa: ', Aa, ' Ka: ', Ka)
if ('throttle' in line):
if ( 'value' in line):
Ta = tuplValu('value', line)
# print ('Ta: ', Ta)
#
if ('flaps' in line):
if ( 'value' in line):
Fa = tuplValu('value', line)
# print (' Fa: ', Fa,)
#
### cruise section parse cruise speed element
if (cruzFlag == 1):
# find element names, save values to post in Tix gui
if ( 'speed' in line):
Vc = tuplValu('speed', line)
#
if ( 'alt' in line):
Hc = tuplValu('alt', line)
#
if ( 'fuel' in line):
Kc = tuplValu('fuel', line)
#
#print ('Vc: ', Vc, ' Hc: ', Hc, ' Kc: ', Kc)
if ('throttle' in line):
if ( 'value' in line):
Tc = tuplValu('value', line)
#
###
### wing sections parse camber and induced drag elements
if ( (wingFlag == 1)or (mstabFlag == 1) ) :
if ( ( (wingFlag == 1) and ( 'append=\"1\"' in line ) ) \
or ( (mstabFlag == 1) and ( mstabDone == 0) ) ) :
# first mstab uses wing1 settings
wng1Flag = 1
if ( wng1Flag != 1 ) :
if ( 'camber' in line):
Cw = tuplValu('camber', line)
#
if ('idrag' in line):
Dw = tuplValu('idrag', line)
#
if ( 'incidence' in line):
Iw = tuplValu('incidence', line)
#
if ( 'twist' in line):
Tw = tuplValu('twist', line)
#
if ( 'dihedral' in line):
Hw = tuplValu('dihedral', line)
#
# print ('Read Cw: ', Cw, 'Dw: ', Dw, ' Iw: ', Iw, ' Tw: ', Tw, ' Hw: ', Hw)
##
#in wing section, find stall element values
if ('stall' in line):
# find element names, save values to post in Tix gui
if ( 'aoa' in line):
Aw = tuplValu('aoa', line)
#
if ( 'peak' in line):
Pw = tuplValu('peak', line)
#
if ( 'width' in line):
Ww = tuplValu('width', line)
#
# print (' read Aw: ', Aw, ' Ww: ', Ww, ' Pw: ', Pw)
##
#in wing section, find flap0 element values
if ('flap0' in line):
# find element names, save values to post in Tix gui
if ( 'lift' in line):
Lf = tuplValu('lift', line)
#
if ( 'drag' in line):
Df = tuplValu('drag', line)
#
#print ('Lf: ', Lf, ' Df: ', Df)
##
#in wing section, find flap1 element values
if ('flap1' in line):
# find element names, save values to post in Tix gui
if ( 'lift' in line):
La = tuplValu('lift', line)
#
if ( 'drag' in line):
Da = tuplValu('drag', line)
#
#print ('La: ', La, ' Da: ', Da)
## end wing
else :
## wing append 1 print('wng1')
if ( 'camber' in line):
Cx = tuplValu('camber', line)
#
if ('idrag' in line):
D1 = tuplValu('idrag', line)
#
if ( 'twist' in line):
Tx = tuplValu('twist', line)
#
if ( 'dihedral' in line):
H1 = tuplValu('dihedral', line)
#
# print ('Read Cx: ', Cx, 'D1: ', D1, ' Tx: ', Tx, ' H1: ', H1)
##
#in wing section, find stall element values
if ('stall' in line):
# find element names, save values to post in Tix gui
if ( 'aoa' in line):
Ax = tuplValu('aoa', line)
#
if ( 'peak' in line):
Px = tuplValu('peak', line)
#
if ( 'width' in line):
W1 = tuplValu('width', line)
#
# print ('Ax: ', Ax, ' W1: ', W1, ' Px: ', Px)
##
#in wing section, find flap0 element values
if ('flap0' in line):
# find element names, save values to post in Tix gui
if ( 'lift' in line):
Lg = tuplValu('lift', line)
#
if ( 'drag' in line):
Dg = tuplValu('drag', line)
#
#print ('Lg: ', Lg, ' Dg: ', Dg)
##
#in wing section, find flap1 element values
if ('flap1' in line):
# find element names, save values to post in Tix gui
if ( 'lift' in line):
Lt = tuplValu('lift', line)
#
if ( 'drag' in line):
Dt = tuplValu('drag', line)
#
#print ('Lt: ', Lt, ' Dt: ', Dt)
## end wng1
### hstab section parse camber, drag, stall and flap0 elements
if (hstabFlag == 1):
## hstab section parse camber and induced drag elements if present
if ('camber' in line):
Ch = tuplValu('camber', line)
if ('idrag' in line):
Dh = tuplValu('idrag', line)
if ('effectiveness' in line):
Eh = tuplValu('effectiveness', line)
#
#print ('Ch: ', Ch, 'Dh: ', Dh, 'Eh: ', Eh)
##
#in hstab section, find stall elements
if ('stall' in line):
# find element names, save values to post in Tix gui
if ( 'aoa' in line):
Ah = tuplValu('aoa', line)
#
if ( 'peak' in line):
Ph = tuplValu('peak', line)
#
if ( 'width' in line):
Wh = tuplValu('width', line)
#
#print ('Ah: ', Ah, ' Wh: ', Wh, ' Ph: ', Ph)
##
#in hstab section, find flap0 elements
if ('flap0' in line):
# find element names, save values to post in Tix gui
if ( 'lift' in line):
Le = tuplValu('lift', line)
#
if ( 'drag' in line):
De = tuplValu('drag', line)
#
#print ('Lh: ', Lh, ' Dh: ', Dh, 'Le: ', Le, ' De: ', De)
### vstab section parse camber, idrag, stall and flap0 elements
if ((vstabFlag == 1) and (vstabDone == 0)):
### vstab section parse camber and induced drag elements if present
if ('camber' in line):
Cv = tuplValu('camber', line)
#
if ('idrag' in line):
Dv = tuplValu('idrag', line)
#
if ('effectiveness' in line):
Ev = tuplValu('effectiveness', line)
#
#print ('Cv: ', Cv, 'Dv: ', Dv, 'Ev: ', Ev)
if ( 'incidence' in line):
Iv = tuplValu('incidence', line)
#
if ( 'twist' in line):
Tv = tuplValu('twist', line)
#
#print ('Iv: ', Iv, 'Tv: ', Tv)
#in vstab section, find stall elements
if ('stall' in line):
# find element names, save values to post in Tix gui
if ( 'aoa' in line):
Av = tuplValu('aoa', line)
#
if ( 'width' in line):
Wv = tuplValu('width', line)
#
if ( 'peak' in line):
Pv = tuplValu('peak', line)
#
#print ('Av: ', Av, ' Wv: ', Wv, ' Pv: ', Pv)
#in vstab section, find flap0 elements
if ('flap0' in line):
# find element names, save values to post in Tix gui
if ( 'lift' in line):
Lr = tuplValu('lift', line)
#
if ( 'drag' in line):
Dr = tuplValu('drag', line)
#
#print ('Lr: ', Lr, ' Dr: ', Dr)
###
#ballast
if ((ballFlag == 1) and (ballDone == 0)):
## ballast section single line for all elements
if ('mass' in line):
Mb = tuplValu('mass', line)
#
if ('x=' in line):
Xb = tuplValu('x', line)
#
if ('y=' in line):
Yb = tuplValu('y', line)
#
if ('z=' in line):
Zb = tuplValu('z', line)
#
if ('/>' in line):
ballDone = 1
ballFlag = 0
#
###
#prop
if (propFlag == 1):
## prop section parse elements if present
if ('mass' in line):
Mp = tuplValu('mass', line)
#
if ('radius' in line):
Rp = tuplValu('radius', line)
#
if ('moment' in line):
Ap = tuplValu('moment', line)
#
if ('min-rpm' in line):
Np = tuplValu('min-rpm', line)
#
if ('max-rpm' in line):
Xp = tuplValu('max-rpm', line)
#
if ('fine-stop' in line):
Ip = tuplValu('fine-stop', line)
#
if ('coarse-stop' in line):
Op = tuplValu('coarse-stop', line)
#
if ('cruise-speed' in line):
Vp = tuplValu('cruise-speed', line)
#
if ('cruise-rpm' in line):
Cp = tuplValu('cruise-rpm', line)
#
if ('takeoff-rpm' in line):
Tp = tuplValu('takeoff-rpm', line)
#
###
#close and sync file
yCfgHndl.close
#print( 'Exit vblsFromTplt')
##
#
def cfigFromVbls( tFID):
#print( 'Entr cfigFromVbls')
global procPref, lvsdFid, iasaFid, iascFid, drgaFid, solnFid
global solnDict, solnCDS, solnCols, solnDT, solnIter, solnElev, solnCgMC, solnCgWB
global yCfgName, yCfgFid, aCfgFid, vCfgFid, versDict, versToDo, versKywd
#
## These vbles correspond to the elements in the config file:
global Va, Aa, Ka, Ta, Fa # Appr Spd, Aoa, Thrt, Fuel, Flaps
global Vc, Hc, Kc, Tc # Cruise Spd, Alt, Thrt, Fuel
global Iw, Aw, Cw, Lf, La, Dw, Ww, Pw, Df, Da, Hw # Wing, Flap, Ailr
global Tx, Ax, Cx, Lg, Lt, D1, W1, Px, Dg, Dt, Tw # Wng1, Flap, Ailr
global Ch, Ah, Eh, Le, Cv, Dh, Wh, Ph, De, Dv, H1 # Hstab, Elev (incidence set by solver )
global Av, Ev, Iv, Tv, Lr, Wv, Pv, Iu, Tu, Dr # Vstab V0:'v' V1:'u', Rudder
global Mp, Rp, Ap, Np, Xp, Ip, Op, Vp, Cp, Tp # Prop
global Mb, Xb, Yb, Zb, Hy, Vy, Wx, Wb, Gx # Ballast, Solver, Wh main, base, CG
global fracInci, totlInci # Wing incidence and CoG
##
apprFlag = 0
cruzFlag = 0
wingFlag = 0
wng1Flag = 0
hstabFlag = 0
vstabFlag = 0
vstabDone = 0
mstabFlag = 0
mstabDone = 0
ballFlag = 0
ballDone = 0
propFlag = 0
if ( pythVers < 3 ) :
aCfgHndl = open(tFID, 'w', 0)
else :
aCfgHndl = open(tFID, 'w')
# write auto file via yconfig template and subsVbls from Tix
with open(yCfgFid, 'r') as yCfgHndl:
# step each line in template yasim config file
for line in yCfgHndl:
# set / clear flags for each section
if '<approach' in line:
apprFlag = 1
if '</approach' in line:
apprFlag = 0
if '<cruise' in line:
cruzFlag = 1
if '</cruise' in line:
cruzFlag = 0
if '<wing' in line:
wingFlag = 1
if '</wing' in line:
wingFlag = 0
wng1Flag = 0
if '<hstab' in line:
hstabFlag = 1
if '</hstab' in line:
hstabFlag = 0
if '<vstab' in line:
vstabFlag = 1
if '</vstab' in line:
vstabDone = 1
vstabFlag = 0
if '<mstab' in line:
mstabFlag = 1
if '</mstab' in line:
mstabDone = 1
mstabFlag = 0
if '<ballast' in line:
ballFlag = 1
if '</ballast'in line:
ballFlag = 0
ballDone = 1
if '<propeller' in line:
propFlag = 1
if '</propeller'in line:
propFlag = 0
### in each section substitute updated element values
## approach
if (apprFlag == 1):
line = tuplSubs( 'speed', line, Va )
line = tuplSubs( 'aoa', line, Aa )
line = tuplSubs( 'fuel', line, Ka )
#print('subsLine: ', line)
if ('throttle' in line):
line = tuplSubs( 'value', line, Ta )
if ('flaps' in line):
line = tuplSubs( 'value', line, Fa )
## cruise
if (cruzFlag == 1):
if ('cruise speed' in line):
#print ('Vc: ', Vc, ' Hc: ', Hc, ' Kc: ', Kc)
line = tuplSubs( 'speed', line, Vc )
line = tuplSubs( 'alt', line, Hc )
if ('fuel' in line):
line = tuplSubs( 'value', line, Kc )
if ('throttle' in line):
line = tuplSubs( 'value', line, Tc )
### wing sections parse camber and induced drag elements
if ( (wingFlag == 1)or (mstabFlag == 1) ) :
if ( ( (wingFlag == 1) and ( 'append=\"1\"' in line ) ) \
or ( (mstabFlag == 1) and ( mstabDone == 0) ) ) :
# first mstab uses wing1 settings
wng1Flag = 1
if ( wng1Flag != 1 ) :
line = tuplSubs( 'camber', line, Cw )
line = tuplSubs( 'idrag', line, Dw )
line = tuplSubs( 'incidence', line, Iw )
line = tuplSubs( 'twist', line, Tw )
line = tuplSubs( 'dihedral', line, Hw )
#print ('Wrt Cw: ', Cw, 'Dw: ', Dw, ' Iw: ', Iw ,' Tw: ', Tw,' Hw: ', Hw)
#
if ('stall' in line):
line = tuplSubs( 'aoa' , line, Aw )
line = tuplSubs( 'peak' , line, Pw )
line = tuplSubs( 'width', line, Ww )
#
if ('flap0' in line):
line = tuplSubs( 'lift', line, Lf )
line = tuplSubs( 'drag', line, Df )
#
if ('flap1' in line):
line = tuplSubs( 'lift', line, La )
line = tuplSubs( 'drag', line, Da )
# end wing
else :
line = tuplSubs( 'camber', line, Cx )
line = tuplSubs( 'idrag', line, D1 )
line = tuplSubs( 'dihedral', line, H1 )
#print ('Wrt Cw: ', Cw, 'Dw: ', Dw, ' Iw: ', Iw ,' Tw: ', Tw,' H1: ', H1)
#
if ('stall' in line):
line = tuplSubs( 'aoa' , line, Ax )
line = tuplSubs( 'peak' , line, Px )
line = tuplSubs( 'width', line, W1 )
#
if ('flap0' in line):
line = tuplSubs( 'lift', line, Lg )
line = tuplSubs( 'drag', line, Dg )
#
if ('flap1' in line):
line = tuplSubs( 'lift', line, Lt )
line = tuplSubs( 'drag', line, Dt )
# end wng1
## HStab
if (hstabFlag == 1):
line = tuplSubs( 'camber', line, Ch )
line = tuplSubs( 'idrag', line, Dh )
line = tuplSubs( 'effectiveness', line, Eh )
#
if ('stall' in line):
line = tuplSubs( 'aoa' , line, Ah )
line = tuplSubs( 'peak' , line, Ph )
line = tuplSubs( 'width', line, Wh )
#
if ('flap0' in line):
line = tuplSubs( 'lift', line, Le )
line = tuplSubs( 'drag', line, De )
#
## Vstab
if ((vstabFlag == 1) and (vstabDone == 0)):
line = tuplSubs( 'camber', line, Cv )
line = tuplSubs( 'idrag', line, Dv )
line = tuplSubs( 'effectiveness', line, Ev )
#
line = tuplSubs( 'incidence', line, Iv )
line = tuplSubs( 'twist', line, Tv )
#print ('Wrt Iv: ', Iv, 'Tv: ', Tv)
#
#
if ('stall' in line):
line = tuplSubs( 'aoa' , line, Av )
line = tuplSubs( 'peak' , line, Pv )
line = tuplSubs( 'width', line, Wv )
#
if ('flap0' in line):
line = tuplSubs( 'lift', line, Lr )
line = tuplSubs( 'drag', line, Dr )
#
#
## ballast ( Ensure input config does not enclose ballast in comments )
if ((ballFlag == 1) and (ballDone == 0)):
## ballast section one line for all elements if present
line = tuplSubs( 'mass', line, Mb )
line = tuplSubs( 'x', line, Xb )
line = tuplSubs( 'y', line, Yb )
line = tuplSubs( 'z', line, Zb )
ballFlag = 0
ballDone = 1
#
## prop
if (propFlag == 1):
## prop section parse elements if present
line = tuplSubs( 'mass', line, Mp )
line = tuplSubs( 'radius', line, Rp )
line = tuplSubs( 'moment', line, Ap )
line = tuplSubs( 'min-rpm',line, Np )
line = tuplSubs( 'max-rpm',line, Xp )
line = tuplSubs( 'fine-stop', line, Ip )
line = tuplSubs( 'coarse-stop', line, Op )
line = tuplSubs( 'cruise-speed',line, Vp )
line = tuplSubs( 'cruise-rpm', line, Cp )
line = tuplSubs( 'takeoff-rpm', line, Tp )
#
## Version string
# look for <airplane mass= to insert keyword for selected version
if '<airplane mass="' in line:
#
metaLine = strftime("<!-- %d%b%Y %H:%M:%S auto generated by ysimi.py -->\n", gmtime())
#metaLine = '<!-- ysimi-outp {%i} {%i}:{%i} -->\n'
aCfgHndl.write(metaLine)
#print('airplane kywd:', versKywd, ' todo: ', versToDo)
# make an index list of double quotes in the line
sepsList = []
sepsChar = '"'
lastIndx = 0
while (lastIndx > -1):
sepsIndx = line.find( sepsChar, (lastIndx +1))
if (sepsIndx > 0) :
sepsList.append(sepsIndx)
lastIndx = sepsIndx
#
if ('version=' in line ):
linePart = line[:line.find('version=')]
sepsIndx = line.find('version=')
sepsIndx = line.find('"', (sepsIndx+1))
sepsIndx = line.find('"', (sepsIndx+1))
linePart = linePart + 'version="' + versKywd
linePart = linePart + line[sepsIndx:]
line = linePart
else :
# Use index list to split line into text and numbers
lineMass = line[0:(sepsList[1]+1)]
line = lineMass + ' version="' + versKywd + '">'
#
# Write unchanged/modified line into auto.xml
aCfgHndl.write(line)
#close and sync files
aCfgHndl.flush
os.fsync(aCfgHndl.fileno())
aCfgHndl.close
yCfgHndl.close
#print( 'Exit cfigFromVbls')
##
# Make up command line and execuute external process call to YASim
def spinYasim(tFid):
#print( 'Entr spinYasim')
global procPref, lvsdFid, iasaFid, iascFid, drgaFid, solnFid
global solnDict, solnCDS, solnCols, solnDT, solnIter, solnElev, solnCgMC, solnCgWB
global yCfgName, yCfgFid, aCfgFid, vCfgFid, versDict, versToDo, versKywd
#
global Mb, Xb, Yb, Zb, Hy, Vy, Wx, Wb, Gx # Ballast, Solver, Wh main, base, CG
global fracInci, totlInci # Wing incidence and CoG
##
#
## update fileIDs with version selected from dropdown
lvsdFid = procPref + versToDo + '-lvsd.txt'
drgaFid = procPref + versToDo + '-drga.txt'
iasaFid = procPref + versToDo + '-iasa.txt'
iascFid = procPref + versToDo + '-iasc.txt'
solnFid = procPref + versToDo + '-soln.txt'
#print('spinYasim tFid: ', tFid)
##
spinFast = 0
if ( spinFast < 1 ) :
# run yasim external process to generate LvsD data table saved dataset file
vDatHndl = open(lvsdFid, 'w')
if ( sys.platform.startswith('linux')):
command_line = 'yasim {:s} --detailed-graph -a {:.2f} -s {:.2f}' \
.format(tFid, (Hy/3.3), (Vy))
else:
command_line = 'yasim {:s} -g -a {:.2f} -s {:.2f}' \
.format(tFid, (Hy/3.3), (Vy))
# print(command_line)
args = shlex.split(command_line)
DEVNULL = open(os.devnull, 'wb')
p = subprocess.run(args, stdout=vDatHndl, stderr=DEVNULL)
DEVNULL.close()
vDatHndl.close
if ( sys.platform.startswith('linux')):
os.sync()
#p.wait()
##
# run yasim external process to generate min IAS data table saved dataset file
vDatHndl = open(iasaFid, 'w')
if ( sys.platform.startswith('linux')):
command_line = 'yasim {:s} --detailed-min-speed -a {:.2f}' \
.format(tFid, (Hy/3.3))
else:
command_line = 'yasim {:s} --min-speed -a {:.2f}' \
.format(tFid, (Hy/3.3))
# print(command_line)
args = shlex.split(command_line)
DEVNULL = open(os.devnull, 'wb')
p = subprocess.run(args, stdout=vDatHndl, stderr=DEVNULL)
DEVNULL.close()
vDatHndl.close
if ( sys.platform.startswith('linux')):
os.sync()
#p.wait()
##
## Perforamnce
if (0) :
# run yasim external process to generate min IAS data table saved dataset file
vDatHndl = open(iascFid, 'w')
if ( sys.platform.startswith('linux')):
command_line = 'yasim ' + tFid + ' --detailed-min-speed -cruise '
else:
command_line = 'yasim ' + tFid + ' --min-speed -cruise '
# print(command_line)
args = shlex.split(command_line)
DEVNULL = open(os.devnull, 'wb')
p = subprocess.run(args, stdout=vDatHndl, stderr=DEVNULL)
DEVNULL.close()
vDatHndl.close
if ( sys.platform.startswith('linux')):
os.sync()
#p.wait()
##
# run yasim external process to generate min IAS data table saved dataset file
vDatHndl = open(drgaFid, 'w')
if ( sys.platform.startswith('linux')):
command_line = 'yasim ' + tFid + ' --detailed-drag -approach '
else:
command_line = 'yasim ' + tFid + ' -d -approach '
# print(command_line)
args = shlex.split(command_line)
DEVNULL = open(os.devnull, 'wb')
p = subprocess.run(args, stdout=vDatHndl, stderr=DEVNULL)
DEVNULL.close()
vDatHndl.close
if ( sys.platform.startswith('linux')):
os.sync()
#p.wait()
##
else :
# run yasim external process to generate LvsD data table saved dataset file
vDatHndl = open(lvsdFid, 'w')
command_line = 'yasim ' + tFid + ' -g -a '+ str(Hy/3.3) + ' -s ' + str(Vy)
# print(command_line)
args = shlex.split(command_line)
DEVNULL = open(os.devnull, 'wb')
p = subprocess.run(args, stdout=vDatHndl, stderr=DEVNULL)
DEVNULL.close()
vDatHndl.close
if ( sys.platform.startswith('linux')):
os.sync()
#p.wait()
##
# run yasim external process to generate min IAS data table saved dataset file
vDatHndl = open(iasaFid, 'w')
command_line = 'yasim ' + tFid + ' --min-speed -approach '
# print(command_line)
args = shlex.split(command_line)
DEVNULL = open(os.devnull, 'wb')
p = subprocess.run(args, stdout=vDatHndl, stderr=DEVNULL)
DEVNULL.close()
vDatHndl.close
if ( sys.platform.startswith('linux')):
os.sync()
#p.wait()
##
## Perforamnce
if (0) :
# run yasim external process to generate min IAS data table saved dataset file
vDatHndl = open(iascFid, 'w')
command_line = 'yasim ' + tFid + ' --min-speed -cruise '
# print(command_line)
args = shlex.split(command_line)
DEVNULL = open(os.devnull, 'wb')
p = subprocess.run(args, stdout=vDatHndl, stderr=DEVNULL)
DEVNULL.close()
vDatHndl.close
if ( sys.platform.startswith('linux')):
os.sync()
#p.wait()
##
# run yasim external process to generate min IAS data table saved dataset file
vDatHndl = open(drgaFid, 'w')
command_line = 'yasim ' + tFid + ' -drag -approach '
# print(command_line)
args = shlex.split(command_line)
DEVNULL = open(os.devnull, 'wb')
p = subprocess.run(args, stdout=vDatHndl, stderr=DEVNULL)
DEVNULL.close()
vDatHndl.close
if ( sys.platform.startswith('linux')):
os.sync()
#p.wait()
##
# run yasim external process to create console output of solution
vDatHndl = open(solnFid, 'w')
command_line = 'yasim ' + tFid
# print(command_line)
args = shlex.split(command_line)
DEVNULL = open(os.devnull, 'wb')
p = subprocess.run(args, stdout=vDatHndl, stderr=DEVNULL)
DEVNULL.close()
vDatHndl.flush
vDatHndl.close
if ( sys.platform.startswith('linux')):
os.sync()
##
# Pull key values from yasim solution console output for dict, dataTable
wingInci( aCfgFid)
solnIter = scanSoln( solnFid, 'Iterations')