-
Notifications
You must be signed in to change notification settings - Fork 9
/
wing_geometry.cpp
1452 lines (1233 loc) · 53.9 KB
/
wing_geometry.cpp
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
//generates trailing edge vortex elements of a panel
void Trailing_Edge_Generation\
(const PANEL, const GENERAL, const BOUND_VORTEX*,\
BOUND_VORTEX *, int &);
//identifies edges of separate wings
void Wing_Generation(const PANEL*,int,int[5],int[5],int[5],int[5],\
int[5],int[5]);
//Rotates panels for attitude during turning flight
void Panel_Rotation(GENERAL &,PANEL *);
//generates surface DVE elements
void Surface_DVE_Generation(const GENERAL,const PANEL *,DVE *,double ***,\
const double);
//moves wing by delta x every time step,
void Move_Wing(const GENERAL, DVE*, const double[3],double[3]);
//moves flexible wing by delta x every time step,
void Move_Flex_Wing(const GENERAL, DVE*);
//moves DVEs according do the input camber line
void Apply_Camber(const PANEL*, double[3], double[3] ,double ***, int, \
int, double,double *,double *,double *,double *);
//deflects DVEs about the hinge
void DeflectAboutHinge(const PANEL*, const double, double[3], double[3], \
int, int, double, double *,double *m,double[3], double[3]);
//calculates U_inf for circling flight
void Circling_UINF(GENERAL, DVE*,double[3], const double [3]);
// Re-calculated DVE parameters based on DVE LE pts and Control pts
void DVE_LEandCPtoParam(GENERAL, DVE*);
//===================================================================//
//FUNCTION Trailing_Edge_Generation
//generates trailing edge vortex elements of panel 'j'
//===================================================================//
void Trailing_Edge_Generation(const PANEL panel,const GENERAL info,\
const BOUND_VORTEX* elementPtr,\
BOUND_VORTEX* trailedgePtr, int &l)
{
//defines trailing edge of panel 'j' and devides it into trailing edge
//elements for cumulating bound vortex upstream of it
//
//input:
// For panel 'j'(in panel):
// x1[], x2[] -x,y,z coordinates of leading edge corners
// c1,c2 -chord length of panel sides
// eps1, eps2 -incident angle of panel sides
// u1[], u2[] -local free stream velocity variation at panel sides
// (for rotating wings}
// n -number of elementary wings in span direction
//
// info.m -number of elementary wings in chord direction
// info.U -free stream velocity
//
// l -trailing edge element index, incremented by one at end
//
//ouput:
//definition of trailing edge element properties.
// For each trailing edge element in trailedgePtr:
// xo[] -midspan location of trailing edge vortex in global ref.frame
// xA[] -not used
// normal[] -not used
// chord -not used
// eta -half span of elementary wing
// phi -sweep of elementary wing
// nu -dihedral of elementary wing
// u[3] -local free stream velocity at mid span
// of trailing edge element in global ref.frame.
int k; //loop counters, k=0..(panel.n-1)
double phi, nu, eta; //panel sweep, dihedral, span
double xte1[3],xte2[3],xte[3]; //trailing edge points of edge 1 and 2
double tempS, tempA[3],tempA1[3]; //temporary scalar, array
scalar(panel.x1,-1,tempA); //negates x1
vsum(panel.x2,tempA,tempA1); //x_1/4. = x1/4_2-x1/4_1
tempS= sqrt(tempA1[1]*tempA1[1]+tempA1[2]*tempA1[2]); //panel span at 1/4c
nu = asin(tempA1[2]/tempS); //panel dihedral at 1/4c
//computing the left trailing edge point of panel
xte1[0] = panel.x1[0]+0.75*panel.c1*cos(panel.eps1);
xte1[1] = panel.x1[1]+0.75*panel.c1*sin(panel.eps1)*sin(nu);
xte1[2] = panel.x1[2]-0.75*panel.c1*sin(panel.eps1)*cos(nu);
//computing the right leading edge point of panel
xte2[0] = panel.x2[0]+0.75*panel.c2*cos(panel.eps2);
xte2[1] = panel.x2[1]+0.75*panel.c2*sin(panel.eps2)*sin(nu);
xte2[2] = panel.x2[2]-0.75*panel.c2*sin(panel.eps2)*cos(nu);
//computing trailing edge vector
xte[0] = xte2[0]-xte1[0];
xte[1] = xte2[1]-xte1[1];
xte[2] = xte2[2]-xte1[2];
//printf("xte\t%2.5lf %2.5lf %2.5lf\n",xte[0]/norm2(xte),xte[1]/norm2(xte),xte[2]/norm2(xte));
phi = asin(xte[0]/norm2(xte)); //sweep of panel's trailing edge
tempS= sqrt(xte[1]*xte[1]+xte[2]*xte[2]); //panel span at TE
nu = asin(xte[2]/tempS); //trailing edge dihedral
eta = tempS/panel.n*0.5; //halfspan of trailing edge of elementary wings
//loop over number of spanwise elements 'n'
for (k=0;k<panel.n;k++)
{
tempS= (.5+k)/panel.n;
//computes mid span point of trailing edge element
scalar(xte,tempS,tempA);
vsum(xte1, tempA, trailedgePtr[l].xo);
trailedgePtr[l].phi = phi; // elementary wing sweep
trailedgePtr[l].nu = nu; // elementary wing dihedral
trailedgePtr[l].eta = eta; // elementary wing halfspan
//computes local free stream velocity at xo location
//varies along span in case of rotating wings
scalar(panel.u2,tempS,tempA); //u2/n*(.5+k)
scalar(panel.u1,(1-tempS),tempA1); //-u1(1/n*(.5+k)-1)
vsum(tempA,tempA1,trailedgePtr[l].u);//u2+(u2-u1)/n*(.5+k)
//KHH small angle approach,
//ctrl. point lies in shed vortex sheet 3/4chord aft of bound vortex
//added 6/24/03 G.B.
if ((info.linear == 1) && (panel.m == 1))
{
trailedgePtr[l].xo[0]=elementPtr[l].xo[0]+elementPtr[l].chord*.75;
trailedgePtr[l].xo[1]=elementPtr[l].xo[1];
trailedgePtr[l].xo[2]=elementPtr[l].xo[2];
}
l++; //increment elementary wing index l=0..(noelement-1)
} //End loop over k
}
//===================================================================//
//END FUNCTION Trailing_Edge_Generation
//===================================================================//
//===================================================================//
//FUNCTION Wing_Generation
//identifies separate wings
//===================================================================//
void Wing_Generation(const PANEL* panelPtr,const int nopanel,\
int wing1[5],int wing2[5],int panel1[5],int panel2[5],\
int dve1[5], int dve2[5])
{
//identifies the separate wings and their span indices of their tips
//
//input:
// panel - information on panels
// nopanel - number of panels
//
//ouput:
//
// wing1[wing] - span index of left edge of wing "wing"
// wing2[wing] - span index of right edge of wing "wing"
// panel1[wing]- index of left panel of wing "wing"
// panel2[wing]- index of right panel of wing "wing"
// panel1 and panel2 added G.B. 11-5-06
// dve1[wing]- index of first dve of wing "wing"
// dve2[wing]- index of last dve of wing "wing" added GB 2-9-20
int k,span,wing,index,panel; //loop counters, k=0..(panel.n-1)
panel1[0]=0; panel2[0]=0; //first left panel of wing 1
for(wing=0;wing<info.nowing;wing++)
{
k=panel1[wing]+1;
while((panelPtr[k].left-1<=panel2[wing] && panelPtr[k].left-1 !=-1) \
|| (panelPtr[k].right-1<=panel2[wing] && panelPtr[k].right-1 !=-1))
{
panel2[wing]=k;
panel1[wing+1]=k+1;
panel2[wing+1]=k+1;
k++;
}
}
//identify DVE indices
span=0; wing=0; index=0; //initialize
for(wing=0;wing<info.nowing;wing++) //loop over wings
{
wing1[wing] = span;
dve1[wing] = index;
//loop over panels of wing
for(panel=panel1[wing];panel <= panel2[wing];panel++)
{
span += panelPtr[panel].n-1;
index += panelPtr[panel].n*panelPtr[panel].m-1;
wing2[wing] = span;
dve2[wing] = index;
index++;
span++;
}// next panel
}// next wing
}
//===================================================================//
//END FUNCTION Wing_Generation
//===================================================================//
//===================================================================//
//FUNCTION Panel_Rotation
//===================================================================//
void Panel_Rotation(GENERAL &info,PANEL* panelPtr)
{
//Function important for turning flight simulation.
//Function rotates panels to account for aircraft sideslip, roll angles
//and angle of attack.
//rotation by alpha on only considered when turning flight
//happens in during level flight.
//
//input:
// info - uses alpha, beta and phi to rotate panels and Ref. Pt
// panel - information of panels
//
//ouput:
// I. updated panel geometry (move x1 & x2);
// Ia. update epsilon of panel if horizontal flight
// II. updated CG location (RefPt)
// III. adjust beta and if horizontal flight alpha
// IV. adjust freestream vector (info.U), also to include upwind info.Ws
//
//1. rotation about x-axis by phi; positive if left wing down
//2. rotarion about z'-axis; positive nose to left of flow
//3. rotation about y"; only if in horizontal plane; posit. nose up
//
//rotateX, rotateY, ratateZ found in vector_algebra.h
int panel; //panel counter
double tempA[3],tempAA[3], tempS; //temporary arrays and scalar
double eps,psi,nu,wingNu;
// I. updated panel geometry (move x1 & x2);
if(info.flagHORZ) eps = info.alpha;
else eps = 0;
psi = info.beta;
nu = info.bank;
for(panel=0;panel<info.nopanel;panel++)
{
//rotate X1
rotateZ(panelPtr[panel].x1,psi,tempA);
rotateX(tempA,-nu,tempAA);
rotateY(tempAA,eps,panelPtr[panel].x1);
//rotate X2
rotateZ(panelPtr[panel].x2,psi,tempA);
rotateX(tempA,-nu,tempAA);
rotateY(tempAA,eps,panelPtr[panel].x2);
// Ia. update epsilon of panel if horizontal flight
if(info.flagHORZ)
{
{ //code block taken from FUNCTION Surface_DVE_Generation
//xquart: vector along leading edge of panel
scalar(panelPtr[panel].x1,-1,tempA); //negates x1
vsum(panelPtr[panel].x2,tempA,tempAA); //x_l.e. = x1/4_2-x1/4_1
//panel span
tempS = sqrt(tempAA[1]*tempAA[1]+tempAA[2]*tempAA[2]);
//leading edge dihedral
wingNu = asin(tempAA[2]/tempS);
}
//correcting epsilons for alpha considering dihedral (wingNu) and bank (nu)
panelPtr[panel].eps1 += eps*cos(nu+wingNu);
panelPtr[panel].eps2 += eps*cos(nu+wingNu);
} //END if(info.flagHORZ)
}//END loop over panels
// II. updated CG location (RefPt)
//rotate reference point (CG)
rotateZ(info.RefPt,psi,tempA);
rotateX(tempA,-nu,tempAA);
rotateY(tempAA,eps,info.RefPt);
// III. adjust beta and if horizontal flight alpha
info.beta = 0;
if(info.flagHORZ) info.alpha=0;
// IV. adjust freestream vector (info.U), also to include upwind info.Ws
info.U[0]=info.Uinf*cos(info.alpha)*cos(info.beta);
info.U[1]=info.Uinf *sin(info.beta);
info.U[2]=info.Uinf*sin(info.alpha)*cos(info.beta)-info.Ws;
}
//===================================================================//
//END FUNCTION Panel_Rotation
//===================================================================//
//===================================================================//
//FUNCTION Surface_DVE_Generation
//===================================================================//
void Surface_DVE_Generation(const GENERAL info,const PANEL* panelPtr,\
DVE* surfacePtr, double ***camberPtr, \
const double epsilonHT)
{
//generates surface Distributied-Vorticity elements. The element
//exists of a leading and
//trailing edge vortex with parabolic circulation distributions that
//are gamma=A+B*eta+C*eta^2 and gamma=-A-B*eta-C*eta^2 respectively.
//Inbetween the two vortices is a vortex sheet with a linear vorticity
//distribution. The elements location is defined with its control point
//that is located at half span and and half chord.
//The element is planar and and is rotated about the x-axis by the
//dihedral or "bank angle" nu and pitched about the new y axis by epsilon.
//in the current version (6/25/03) these angles are determined with the
//surface normal of the elementary wings.
//
//input:
// l -elementary wing index, incremented by one at end
// of loop 'k' over number of spanwise elementary wings.
// Hence, l = 0 .. (noelement-1)
//
//ouput:
//definition of properties of surface DVE.
// For each surface DVE in surfacePtr:
// xo[] -DVE reference and control point, global ref.frame
// xsi -half chord at midspan of DVE
// eta -half span of DVE
// phiLE -sweep of leading edge of DVE
// phiTE -sweep of trailing edge of DVE
// nu -dihedral of DVE
// epsilon -incident angle of DVE
// u[3] -velocity at xA in global ref.frame.
// singfct -rate at which singularity at edge of vortex sheet decays
// ## singfct added 2/8/05 G.B.
// ratio -interpolation ratio between left and right edge a panel 14/2/20 G.B.
int i,m,n,wing; //loop counters
int l=0; //l => suface DVE counter,
double singfct; //decay rate of singularity at edge of vortex sheet
double tempS,tempA[3],tempAA[3];
double xquart[3]; //1/4chord line of panel, defined in input
double x1LE[3],x2LE[3],x1[3],x2[3]; //edge points of panel and spanwise rows
double xLE[3],xsiLE[3]; //vector along LE of a spanewise row of surface DVEs
double delchord1,delchord2,delchord; //edge 1&2 chord,chord span-increment,
double deleps,ceps,seps;//increments of epsi; cos/sin of incidence angle
double nu,nu2; //nus of panel 1/4c line, LE of DVE row
double delTANphi; //tan(phiLE-phiTE)
double delX[3]; //vector from center of leading edge to control point
double eps1,eps2; //epsilon of chordwise section (needed for camber/hinges)
double epsH1,epsH2; //epsilon of chordwise section of hinge
double epsC1,epsC2; //epsilon of chordwise section of camber
double chord1,chord2; //new chord due to camber
double xH1[3],xH2[3]; //hinge location
//loop over number of panels
for (i=0;i<info.nopanel;i++)
{
//xquart: vector between 1/4 chord points of panel edges
scalar(panelPtr[i].x1,-1,tempA); //negates x1
vsum(panelPtr[i].x2,tempA,xquart); //x_l.e. = x1/4_2-x1/4_1
//panel span
tempS = sqrt(xquart[1]*xquart[1]+xquart[2]*xquart[2]);
//1/4chord line dihedral
nu = asin(xquart[2]/tempS);
delchord1 = panelPtr[i].c1/panelPtr[i].m; //chordwise increment left side
delchord2 = panelPtr[i].c2/panelPtr[i].m; //chordwise increment right side
delchord = (delchord2-delchord1)/panelPtr[i].n;//chord/span increment
//tangent of change in sweep angle of each chordwise row
delTANphi = (delchord2-delchord1)/tempS;
//spanwise incident increments
deleps = (panelPtr[i].eps2-panelPtr[i].eps1)/panelPtr[i].n;
/* Changed 20.02.20 D.F.B. User now defined panel at LE and the wing
/ pitch is adjusted about the LE of the wing (instead of the 1/4 chord)
//computing the left leading edge point of panel
x1LE[0] = panelPtr[i].x1[0]-0.25*panelPtr[i].c1*cos(panelPtr[i].eps1);
x1LE[1] = panelPtr[i].x1[1]-0.25*panelPtr[i].c1*sin(panelPtr[i].eps1)\
*sin(nu);
x1LE[2] = panelPtr[i].x1[2]+0.25*panelPtr[i].c1*sin(panelPtr[i].eps1)\
*cos(nu);
computing the right leading edge point of panel
x2LE[0] = panelPtr[i].x2[0]-0.25*panelPtr[i].c2*cos(panelPtr[i].eps2);
x2LE[1] = panelPtr[i].x2[1]-0.25*panelPtr[i].c2*sin(panelPtr[i].eps2)\
*sin(nu);
x2LE[2] = panelPtr[i].x2[2]+0.25*panelPtr[i].c2*sin(panelPtr[i].eps2)\
*cos(nu);
*/
//computing the left leading edge point of panel
x1LE[0] = panelPtr[i].x1[0];
x1LE[1] = panelPtr[i].x1[1];
x1LE[2] = panelPtr[i].x1[2];
//computing the right leading edge point of panel
x2LE[0] = panelPtr[i].x2[0];
x2LE[1] = panelPtr[i].x2[1];
x2LE[2] = panelPtr[i].x2[2];
//loop over number of chordwise elements 'info.m'
//removed GB 2-9-20 for (m=0;m<info.m;m++)
for (m=0;m<panelPtr[i].m;m++)
{
/* Changed 20.02.20 D.F.B. There was issues with multiple m so now
// panels are defined in input along LE instead of quater chord
tempS = (0.25+m); //leading edge location/chord, 1/4c of spanwise row
//computing left LE locations of current spanwise row of DVEs
x1[0] = x1LE[0]+delchord1*tempS*cos(panelPtr[i].eps1);
x1[1] = x1LE[1]+delchord1*tempS*sin(panelPtr[i].eps1)*sin(nu);
x1[2] = x1LE[2]-delchord1*tempS*sin(panelPtr[i].eps1)*cos(nu);
//computing right LE locations of current spanwise row of DVEs
x2[0] = x2LE[0]+delchord2*tempS*cos(panelPtr[i].eps2);
x2[1] = x2LE[1]+delchord2*tempS*sin(panelPtr[i].eps2)*sin(nu);
x2[2] = x2LE[2]-delchord2*tempS*sin(panelPtr[i].eps2)*cos(nu);
*/
//computing left LE locations of current spanwise row of DVEs
x1[0] = x1LE[0]+delchord1*m*cos(panelPtr[i].eps1);
x1[1] = x1LE[1]+delchord1*m*sin(panelPtr[i].eps1)*sin(nu);
x1[2] = x1LE[2]-delchord1*m*sin(panelPtr[i].eps1)*cos(nu);
//computing right LE locations of current spanwise row of DVEs
x2[0] = x2LE[0]+delchord2*m*cos(panelPtr[i].eps2);
x2[1] = x2LE[1]+delchord2*m*sin(panelPtr[i].eps2)*sin(nu);
x2[2] = x2LE[2]-delchord2*m*sin(panelPtr[i].eps2)*cos(nu);
// Assign espilon of m section as the panel edge eps
// Needed for camber or trim
eps1 = panelPtr[i].eps1;
eps2 = panelPtr[i].eps2;
// If there is camber, add it to x1 and x2 and compute new
//chord and epsilon values
if(info.flagCAMBER){
Apply_Camber(panelPtr,x1,x2,camberPtr, m, i, nu, \
&epsC1, &epsC2, &chord1, &chord2);
eps1 += epsC1;
eps2 += epsC2;
}
// If there is trim adjust the tail at its hinge according to
//the deflection of epsilonHT
if(info.trim){
DeflectAboutHinge(panelPtr,epsilonHT, x1, x2, m, i, \
nu, &epsH1, &epsH2, xH1, xH2);
eps1 +=epsH1; //If there is camber, add the epsilon to that value
eps2 +=epsH2;
}
//computing vector along LE of current spanwise row of DVEs
tempS = 1./panelPtr[i].n;
xLE[0] = (x2[0]-x1[0])*tempS;
xLE[1] = (x2[1]-x1[1])*tempS;
xLE[2] = (x2[2]-x1[2])*tempS;
//computing dihedral of LE of current spanwise row of DVEs
tempS = sqrt(xLE[1]*xLE[1]+xLE[2]*xLE[2]);
nu2 = asin(xLE[2]/tempS);
//loop over number of spanwise elements 'n'
for (n=0;n<panelPtr[i].n;n++)
{
tempS = (0.5+n);
if(info.flagCAMBER){
//half-chord length at midspan of DVE using camber info
surfacePtr[l].xsi=0.5*(chord1+tempS*(chord2-chord1)/panelPtr[i].n);
//temporary incidence angle at half span of DVE using camber info
surfacePtr[l].epsilon = eps1 + tempS*(eps2-eps1)/panelPtr[i].n;
} else if(info.trim){
//If camber is off but trim is on
//half-chord length at midspan of DVE
surfacePtr[l].xsi=0.5*(delchord1+delchord*tempS);
//temporary incidence angle at half span of DVE using camber info
surfacePtr[l].epsilon = eps1+ + tempS*(eps2-eps1)/panelPtr[i].n;
}
else{
//half-chord length at midspan of DVE
surfacePtr[l].xsi=0.5*(delchord1+delchord*tempS);
//temporary incidence angle at half span of DVE
surfacePtr[l].epsilon = panelPtr[i].eps1 + tempS*deleps;
}
ceps = cos(surfacePtr[l].epsilon); //needed for tempA below
seps = sin(surfacePtr[l].epsilon);
//computing the mid-span location of the DVE LE
//temporarily saved in xleft
tempA[0] = x1[0]+xLE[0]*tempS;
tempA[1] = x1[1]+xLE[1]*tempS;
tempA[2] = x1[2]+xLE[2]*tempS;
//vector from LE mid-span point to reference point
delX[0] = surfacePtr[l].xsi * ceps;
delX[1] = surfacePtr[l].xsi * seps * sin(nu2);
delX[2] = -surfacePtr[l].xsi * seps * cos(nu2);
//computing the DVE reference point
surfacePtr[l].xo[0] = tempA[0] + delX[0];
surfacePtr[l].xo[1] = tempA[1] + delX[1];
surfacePtr[l].xo[2] = tempA[2] + delX[2];
//computing the normal of DVE,
cross(delX,xLE,tempA);
tempS = 1/norm2(tempA);
scalar(tempA,tempS,surfacePtr[l].normal);
//computes local free stream velocity at xo location
scalar(panelPtr[i].u2,tempS,tempA); //u2/n*(.5+k)
scalar(panelPtr[i].u1,(1-tempS),tempAA);//-u1(1/n*(.5+k)-1)
vsum(tempA,tempAA,surfacePtr[l].u); //u2+(u2-u1)/n*(.5+k)
//the normalized free stream direction, G.B. 10/19/04
tempS=1./norm2(surfacePtr[l].u);
surfacePtr[l].U[0] = surfacePtr[l].u[0]*tempS;
surfacePtr[l].U[1] = surfacePtr[l].u[1]*tempS;
surfacePtr[l].U[2] = surfacePtr[l].u[2]*tempS;
//*************************************************************
//dihedral angle, nu, tan(nu)=-(ny)/(nz)
if(fabs(surfacePtr[l].normal[2]) > DBL_EPS)
{ tempS=-atan(surfacePtr[l].normal[1]/surfacePtr[l].normal[2]);
if (surfacePtr[l].normal[2] < 0) tempS += Pi;//|nu|>Pi/2
}
else //tan(nu) -> infinity -> |nu| = Pi/2
{
if(surfacePtr[l].normal[1]>0) tempS = -0.5*Pi;
else tempS = 0.5*Pi;
}
surfacePtr[l].nu = tempS;
//*************************************************************
//computing epsilon
surfacePtr[l].epsilon = asin(surfacePtr[l].normal[0]);
//computing psi, set to zero for surface DVEs
surfacePtr[l].psi= 0;
//computing yaw angle psi
//psi is the angle between vector from LE to Xo and xsi-axis
//transforming xLE into local reference frame
Glob_Star(delX,surfacePtr[l].nu,surfacePtr[l].epsilon,\
surfacePtr[l].psi,tempA);
//function in ref_frame_transform.h
surfacePtr[l].psi = atan(tempA[1]/tempA[0]);
//transforming xLE into local reference frame
Glob_Star(xLE,surfacePtr[l].nu,surfacePtr[l].epsilon,\
surfacePtr[l].psi,xsiLE);
//function in ref_frame_transform.h
//DVE half span, eta
surfacePtr[l].eta = 0.5*xsiLE[1];
//GB 2-14-20
//interpolation ratio for airfoil and camber, =0 at panel1 and =1 at panel2
//ratio = [span location of X0]/[panel span] reduces to:
surfacePtr[l].ratio = (n+0.5)/panelPtr[i].n;
//DVE leading edge sweep
tempS = xsiLE[0]/xsiLE[1]; //tan(phi)=xsi/eta
surfacePtr[l].phiLE = atan(tempS);
//DVE trailing edge sweep
surfacePtr[l].phiTE = atan(tempS+delTANphi);
//DVE mid-chord sweep
surfacePtr[l].phi0 = 0.5 * \
(surfacePtr[l].phiLE+surfacePtr[l].phiTE);
//DVE area 4*eta*xsi G.B. 8-10-07
surfacePtr[l].S = 4* surfacePtr[l].eta*surfacePtr[l].xsi;
//DVE assign airfoil number to element
//two airfoils to interpolate between panel edge 1 and 2
//GB 2-14-20
surfacePtr[l].airfoil[0] = panelPtr[i].airfoil1;
surfacePtr[l].airfoil[1] = panelPtr[i].airfoil2;
//printf("phiLE %2.4lf phiTE %2.4lf phi0 %2.4lf \n",\
//surfacePtr[l].phiLE*RtD,surfacePtr[l].phiTE*RtD,surfacePtr[l].phi0*RtD);
l++; //next surface-DVE
}//END loop over number of spanwise elements 'n'
}//loop over number of chordwise elements 'panel.m'
}//END loop over number of panels
//##this part has been added 2/9/05 G.B.
//computing decaying factor for added singularity at wing tip
int k=0; //k => trailing-edge element counter
if(info.nowing>1) //more than one wing and possible interaction
{ //between surface and wake
for(wing=0;wing<info.nowing;wing++)
{
//index of last DVE of this wing (located at tip and trail. edge)
//removed GB 2-9-20 l = k + (info.wing2[wing]-info.wing1[wing]+1)*info.m - 1;
l=info.dve2[wing];
//is the wing symmetrical or not?
if(info.sym == 1) //decay factor is 1% of tip-element half-span
singfct = 0.01*surfacePtr[l].eta;
else//wing has two tips, possibly different in geometry
{ //in that case, decay factor is 1% of the shorter half-span
if( surfacePtr[k].eta < surfacePtr[l].eta)
singfct = 0.01*surfacePtr[k].eta;
else singfct = 0.01*surfacePtr[l].eta;
}
//loop over surface DVEs of current wing
for(i=k;i<=l;i++)
surfacePtr[i].singfct = singfct; //assigning decay factor
k = l+1; //updating index for next wing
}//next wing
}
else //if more than one wing and the potential of
{ //wake-surface interaction exists; 8/16/05 G.B.
for(i=0;i<info.noelement;i++) surfacePtr[i].singfct = 0.;
}
//computing points that are at right and left edge oof leading edge of element
//This section was added for FlexWing on 10-29-06 G.B.
void Edge_Point(const double [3],const double,const double,const double,\
const double,const double,const double,double [3]);
//found in wake_geometry.cpp
for (i=0;i<info.noelement;i++)
{
//computes point at left side of ledge edge of DVE
Edge_Point(surfacePtr[i].xo,surfacePtr[i].nu,\
surfacePtr[i].epsilon,surfacePtr[i].psi,\
surfacePtr[i].phiLE,-surfacePtr[i].eta,\
-surfacePtr[i].xsi,surfacePtr[i].x1);
//subroutine in wake_geometry.cpp
//computes point at right side of ledge edge of DVE
Edge_Point(surfacePtr[i].xo,surfacePtr[i].nu,\
surfacePtr[i].epsilon,surfacePtr[i].psi,\
surfacePtr[i].phiLE,surfacePtr[i].eta,\
-surfacePtr[i].xsi,surfacePtr[i].x2);
//subroutine in wake_geometry.cpp
//initializing velocities in x1 and x2 with the one found in xo
surfacePtr[i].u1[0]=surfacePtr[i].u[0];
surfacePtr[i].u1[1]=surfacePtr[i].u[1];
surfacePtr[i].u1[2]=surfacePtr[i].u[2];
surfacePtr[i].u2[0]=surfacePtr[i].u[0];
surfacePtr[i].u2[1]=surfacePtr[i].u[1];
surfacePtr[i].u2[2]=surfacePtr[i].u[2];
//computing point at center of trailing edge xTE
Edge_Point(surfacePtr[i].xo,surfacePtr[i].nu,\
surfacePtr[i].epsilon,surfacePtr[i].psi,\
surfacePtr[i].phiLE,0,\
surfacePtr[i].xsi,surfacePtr[i].xTE);
//subroutine in wake_geometry.cpp
//computing vector along trailing edge TEvc
//right edge point of trailinge edge
Edge_Point(surfacePtr[i].xo,surfacePtr[i].nu,\
surfacePtr[i].epsilon,surfacePtr[i].psi,\
surfacePtr[i].phiLE,surfacePtr[i].eta,\
surfacePtr[i].xsi,tempA);
//subroutine in wake_geometry.cpp
surfacePtr[i].TEvc[0] = tempA[0]-surfacePtr[i].xTE[0];
surfacePtr[i].TEvc[1] = tempA[1]-surfacePtr[i].xTE[1];
surfacePtr[i].TEvc[2] = tempA[2]-surfacePtr[i].xTE[2];
}
}
//===================================================================//
//END FUNCTION Surface_DVE_Generation
//===================================================================//
//===================================================================//
//START FUNCTION Move_Flex_Wing
//===================================================================//
void Move_Flex_Wing(const GENERAL info, DVE* surfacePtr)
{
//new routine added 10-29-06 G.B.
//moves flexible wing by delta x every time step,
//1. moves xo, x1, x2
//2. computes new eta nu, epsilon, psi, xsi of DVE
//3. updates singularity decay factor
//4. updates circulation coefficients as DVE stretches in span
//
//
// input
// info general information
// surfacePtr surface DVE's
//
int i,wing,k,l; //counters
double delx[3]; //increment x1,xo, and x2 move during timestep
double delX1[3]; //vector between center of leading edge and ref. pt
double delX2[3]; //vector between left and right leading edge
double delXSI1[3]; //delX1 in local DVE coordinates
double delXSI2[3]; //delX2 in local DVE coordinates
double delPhi; //change in sweep
double singfct; //temporary decay factor
double tempA[3];
//####################################################################
//1. moves xo, x1, x2
for(i=0;i<info.noelement;i++)
{
//moves reference point
//delta x = local U * delta time
delx[0] = surfacePtr[i].u[0] * info.deltime;
delx[1] = surfacePtr[i].u[1] * info.deltime;
delx[2] = surfacePtr[i].u[2] * info.deltime;
//move reference point
surfacePtr[i].xo[0] -= delx[0];
surfacePtr[i].xo[1] -= delx[1];
surfacePtr[i].xo[2] -= delx[2];
//moves point at left edge of DVE-leading edge
//delta x = local U * delta time
delx[0] = surfacePtr[i].u1[0] * info.deltime;
delx[1] = surfacePtr[i].u1[1] * info.deltime;
delx[2] = surfacePtr[i].u1[2] * info.deltime;
//move reference point
surfacePtr[i].x1[0] -= delx[0];
surfacePtr[i].x1[1] -= delx[1];
surfacePtr[i].x1[2] -= delx[2];
//moves point at right edge of DVE-leading edge
//delta x = local U * delta time
delx[0] = surfacePtr[i].u2[0] * info.deltime;
delx[1] = surfacePtr[i].u2[1] * info.deltime;
delx[2] = surfacePtr[i].u2[2] * info.deltime;
//move reference point
surfacePtr[i].x2[0] -= delx[0];
surfacePtr[i].x2[1] -= delx[1];
surfacePtr[i].x2[2] -= delx[2];
}
//####################################################################
//2. computes new eta nu, epsilon, psi, xsi of DVE
//routine similar to the one found in wake_geometry.cpp for relaxing
for(i=0;i<info.noelement;i++)
{
//********************************************************************
//computing vector from center of leading edge to reference point
delX1[0] = surfacePtr[i].xo[0] \
- 0.5*(surfacePtr[i].x1[0]+surfacePtr[i].x2[0]);
delX1[1] = surfacePtr[i].xo[1] \
- 0.5*(surfacePtr[i].x1[1]+surfacePtr[i].x2[1]);
delX1[2] = surfacePtr[i].xo[2] \
- 0.5*(surfacePtr[i].x1[2]+surfacePtr[i].x2[2]);
//vector along leading edge of DVE
delX2[0] = surfacePtr[i].x2[0] - surfacePtr[i].x1[0];
delX2[1] = surfacePtr[i].x2[1] - surfacePtr[i].x1[1];
delX2[2] = surfacePtr[i].x2[2] - surfacePtr[i].x1[2];
//computing the normal of DVE,
cross(delX1,delX2,tempA);
scalar(tempA,1/norm2(tempA),surfacePtr[i].normal);
//here begins the stuff you been waiting for:
//********************************************************************
//dihedral angle, nu,
//tan(nu)=-(ny)/(nz)
if(fabs(surfacePtr[i].normal[2]) > DBL_EPS)
{
surfacePtr[i].nu=-atan(surfacePtr[i].normal[1]\
/surfacePtr[i].normal[2]);
if (surfacePtr[i].normal[2]<0) surfacePtr[i].nu+= Pi;//|nu|>Pi/2
}
else //tan(nu) -> infinity -> |nu| = Pi/2
{
if(surfacePtr[i].normal[1]>0) surfacePtr[i].nu = -0.5*Pi;
else surfacePtr[i].nu = 0.5*Pi;
}
//********************************************************************
//computing epsilon
surfacePtr[i].epsilon = asin(surfacePtr[i].normal[0]);
//********************************************************************
//computing yaw angle psi
//the orientation of the rotational axis of the vortex seet,
//is parallel to delX1.
//delX1 in xsi reference frame (psi = 0)
Glob_Star(delX1,surfacePtr[i].nu,surfacePtr[i].epsilon,0,delXSI1);
//function in ref_frame_transform.h
//tan(psi)=(eta2)/(xsi1)
if(delXSI1[0]*delXSI1[0] > DBL_EPS)
{
surfacePtr[i].psi= atan(delXSI1[1]/delXSI1[0]);
if(delXSI1[0] < 0) surfacePtr[i].psi += Pi;//|nu|>Pi/2
}
else //tan(psi) -> infinity -> |psi| = Pi/2
surfacePtr[i].psi = 0.5*Pi*fabs(delXSI1[1])/delXSI1[1];
//length of projection
surfacePtr[i].xsi = sqrt(delXSI1[0]*delXSI1[0]+delXSI1[1]*delXSI1[1]);
//********************************************************************
//computing sweep and halfspan
//1. transform delX2 into local frame
Glob_Star(delX2,surfacePtr[i].nu,surfacePtr[i].epsilon,\
surfacePtr[i].psi,delXSI2);
//function in ref_frame_transform.h
//if everything works => delXSI[2] = 0
if(delXSI2[1] < 0)
{
printf(" ohwei! around line 765, wing_geometry.cpp\n %2.2lf %2.16lf\n",delXSI2[1],delXSI2[2]);
exit(0);
}
//computing change in sweep
delPhi = atan(delXSI2[0]/delXSI2[1]) - surfacePtr[i].phiLE;
//updating sweeps
surfacePtr[i].phiLE += delPhi;
surfacePtr[i].phi0 += delPhi;
surfacePtr[i].phiTE += delPhi;
//computing the new half span
surfacePtr[i].eta = 0.5*delXSI2[1];
//********************************************************************
}
//####################################################################
//3. updates singularity decay factor
//computing decaying factor for added singularity at wing tip
k=0; //k => trailing-edge element counter
if(info.nowing>1) //more than one wing and possible interaction
{ //between surface and wake
for(wing=0;wing<info.nowing;wing++)
{
//index of last DVE of this wing (located at tip and trail. edge)
//removed GB 2-9-20 l = k + (info.wing2[wing]-info.wing1[wing]+1)*info.m - 1;
l=info.dve2[wing];
//is the wing symmetrical or not?
if(info.sym == 1) //decay factor is 1% of tip-element half-span
singfct = 0.01*surfacePtr[l].eta;
else//wing has two tips, possibly different in geometry
{ //in that case, decay factor is 1% of the shorter half-span
if( surfacePtr[k].eta < surfacePtr[l].eta)
singfct = 0.01*surfacePtr[k].eta;
else singfct = 0.01*surfacePtr[l].eta;
}
//loop over surface DVEs of current wing
for(i=k;i<=l;i++)
surfacePtr[i].singfct = singfct; //assigning decay factor
k = l+1; //updating index for next wing
}//next wing
}
else //if more than one wing and the potential of
{ //wake-surface interaction exists; 8/16/05 G.B.
for(i=0;i<info.noelement;i++) surfacePtr[i].singfct = 0.;
}
//####################################################################
//4. updates circulation coefficients as DVE stretches in span
//not needed since new circulation distribution is computed based on
//newly squirted out wake row
//####################################################################
}
//===================================================================//
//END FUNCTION Move_Flex_Wing
//===================================================================//
//===================================================================//
//START FUNCTION Move_Wing
//===================================================================//
void Move_Wing(const GENERAL info, DVE* surfacePtr,const double circCenter[3], double XCG[3])
{
//moves wing by delta x every time step,
//function updates xo location of surface DVE's
//
// INPUTS:
// info general information
// surfacePtr surface DVE's
// circCenter center point of circling flight Added by D.F.B. 03-2020
int i;
double delx[3],delX1[3],delX2[3];
double tempA[3];
double rotAngle; // How many radian to rotate points
if(!info.flagCIRC){
for(i=0;i<info.noelement;i++)
{
//delta x = local U * delta time
delx[0] = surfacePtr[i].u[0] * info.deltime;
delx[1] = surfacePtr[i].u[1] * info.deltime;
delx[2] = surfacePtr[i].u[2] * info.deltime;
//move reference point
surfacePtr[i].xo[0] -= delx[0];
surfacePtr[i].xo[1] -= delx[1];
surfacePtr[i].xo[2] -= delx[2];
}
// Updating CG location was moved from PitchMoment - D.F.B. 03-2020
//move CG
//newXCG -= local U * delta time
XCG[0] -= surfacePtr[0].u[0] * info.deltime;
XCG[1] -= surfacePtr[0].u[1] * info.deltime;
XCG[2] -= surfacePtr[0].u[2] * info.deltime;
} else{
for(i=0;i<info.noelement;i++)
{
// -------Move points for circling flight-------
// D.F.B. in Braunschweig, Germany, Mar. 2020
// Angle to rotate points
rotAngle = info.gradient * info.deltime;
// Apply rotation matrix about the z-axis
// Calculate vector from rotation center to control point
delx[0] = surfacePtr[i].xo[0] - circCenter[0];
delx[1] = surfacePtr[i].xo[1] - circCenter[1];
// Move control points
surfacePtr[i].xo[0] = delx[0]*cos(rotAngle)-delx[1]*sin(rotAngle)+circCenter[0];
surfacePtr[i].xo[1] = delx[0]*sin(rotAngle)+delx[1]*cos(rotAngle)+circCenter[1];
surfacePtr[i].xo[2] -= info.U[2] * info.deltime;
// Move left leading edge point
delx[0] = surfacePtr[i].x1[0] - circCenter[0];
delx[1] = surfacePtr[i].x1[1] - circCenter[1];
surfacePtr[i].x1[0] = delx[0]*cos(rotAngle)-delx[1]*sin(rotAngle)+circCenter[0];
surfacePtr[i].x1[1] = delx[0]*sin(rotAngle)+delx[1]*cos(rotAngle)+circCenter[1];
surfacePtr[i].x1[2] -= info.U[2] * info.deltime;
// Move right leading edge point
delx[0] = surfacePtr[i].x2[0] - circCenter[0];
delx[1] = surfacePtr[i].x2[1] - circCenter[1];
surfacePtr[i].x2[0] = (delx[0]*cos(rotAngle)-delx[1]*sin(rotAngle))+circCenter[0];
surfacePtr[i].x2[1] = (delx[0]*sin(rotAngle)+delx[1]*cos(rotAngle))+circCenter[1];
surfacePtr[i].x2[2] -= info.U[2] * info.deltime;
}
// Recompute DVE param based on new LE and Control pts
DVE_LEandCPtoParam(info, surfacePtr);
//Move CG with the circling flight
delx[0] = XCG[0] - circCenter[0];
delx[1] = XCG[1] - circCenter[1];
XCG[0] = (delx[0]*cos(rotAngle)-delx[1]*sin(rotAngle))+circCenter[0];
XCG[1] = (delx[0]*sin(rotAngle)+delx[1]*cos(rotAngle))+circCenter[1];
XCG[2] -= info.U[2] * info.deltime;
}
}
//===================================================================//
//END FUNCTION Move_Wing
//===================================================================//
//===================================================================//
//START FUNCTION Apply_Camber
//===================================================================//
void Apply_Camber(const PANEL* panelPtr, double x1[3], double x2[3], \
double ***camberPtr, int m, int i, double nu, \
double *epsC1, double *epsC2, double *chord1, double *chord2)
{
// The function Apply_Camber determines changed the LE panel points to follow
// the curvature of the camber line.
//
// Function inputs:
// PANEL* panelPtr -Panel structure for the panelPtr
// x1,x2 -x,y,z position of the left (1) and right (2) panel LE pts
// camberptr -camber ptr holding all of the camber data
// m -chorwise row of interest
// i -panelPtr of interest
// nu -dihedral angle of panel
// eps1, eps2 -(see output)
// chord1, chord2 -(see output)
//
// Function outputs: