-
Notifications
You must be signed in to change notification settings - Fork 1
/
gmshToolkit.py
3846 lines (3312 loc) · 199 KB
/
gmshToolkit.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
# Copyright (c) 2022-2023 Étienne Spieser (Tiānài), member of AANTC (https://aantc.ust.hk/)
# available under MIT licence at: https://github.com/etiennespieser
# ------------------------------------------------------------------------------------
# # Drawing of the NACA profile inspired from
# the Wikipedia page: https://en.wikipedia.org/wiki/NACA_airfoil
# JoshTheEngineer matlab's code: https://github.com/jte0419/NACA_4_Digit_Airfoil
# On the general use of Gmsh (correspondance of the .geo synthax with the python API provided)
# (C++ use of Gmsh is also supported, more consistent with MFEM?)
# https://gmsh.info/doc/texinfo/gmsh.html
# meshing with S.A.E. Miller, "Tutorial on Computational Grid Generation for CFD using GMSH"
# https://youtube.com/playlist?list=PLbiOzt50Bx-l2QyX5ZBv9pgDtIei-CYs_
# or tutorial of Bertrand Thierry:
# https://bthierry.pages.math.cnrs.fr/tutorial/gmsh/
# >> Blocking close to the airfoil (inside the <<regular CAA>> block) <<
#
# line BLUp point up line D point upRight line I point upFarRight
# --------------------<----------------X --------------------<-------------------- X --------------------<-------------------- X
# | | <<TE patchUp>> | <<wake Up>> |
# | <<BL structGridUp>> /\ line A /| line Ar /| line Aer
# | line airfoilUp | point TEu line M | point upMidRight line P |
# | -------<-------- X -------------------->-------------------- X -------------------->-------------------- X point upMidFarRight
# | | | | |
# | V /\ (if bluntTrailingEdge: line Eu) /\ (if bluntTrailingEdge: line Fu) /| (if bluntTrailingEdge: line Ju) |
# | point Left | point LE | point TE line K | point TEwake line N |
# X -------<-------- X X -------------------->-------------------- X -------------------->-------------------- X point TEfarWake
# | line G | | | |
# | V <<airfoil>> /\ (if bluntTrailingEdge: line El) /\ (if bluntTrailingEdge: line Fl) /| (if bluntTrailingEdge: line Jl) |
# | | | point TEl line L | point lowMidRight line O |
# | ------->-------- X -------------------->-------------------- X -------------------->-------------------- X point lowMidFarRight
# | line airfoilLow | | |
# | <<BL structGridLow>> V line B <<TE patchLow>> /| line Br <<wake Low>> /| line Ber
# | | | |
# -------------------->----------------X -------------------->-------------------- X -------------------->-------------------- X
# line BLlow point low line C point lowRight line H point lowFarRight
#
#
# "point LE" and "point Left" belongs to the upper part of the airfoil lines and BL lines
# when the TE is blunt: Tag TEu = Tag TEl = Tag TE
#
# "point TE" and the split into "line Eu" and "line El" in the case of a blunt TE is important
# because it enables to define two grid geometric progression of the grid at the TE of the
# airfoil.
#
# To create transfinite volumes around the airfoil using the .geo. kernel, each cell of the
# airfoil needs to be manually defined. <<BL structGridUp>> and <<BL structGridLow>> are thus
# sliced in a loop of elementary surface panels. No similar issue for <<TE patchUp>>, <<TE patchLow>>
# or <<wake region>> since their shape is a regular quadrangle.
#
# ******************************************************************************************************************************************************************************
# Import modules:
import gmsh
import numpy as np
import matplotlib.pyplot as plt
pb_1Dim = 1
pb_2Dim = 2
pb_3Dim = 3
def NACAxxx(NACA_type, bluntTrailingEdge, AoA, chord, airfoilReference, height_LE, height_TE, optimisedGridSpacing, gridPts):
# returns a list of (x,y) coordinates of a given NACA profile. which leading edge is located at (0,0)
#
# Extract percentage values of airfoil properties from type of airfoil
M = int(NACA_type[0])/100 # maximum camber
P = int(NACA_type[1])/10 # location of maximum camber
T = int(NACA_type[2:4])/100 # maximum thickness
#
# Constants used in thickness calculation
a0 = 0.2969
a1 = -0.1260
a2 = -0.3516
a3 = 0.2843
if bluntTrailingEdge:
a4 = -0.1015 # Open trailing edge
else:
a4 = -0.1036 # Closed trailing edge
#
# Airfoil X points
x = np.linspace(0,1,gridPts) # Uniform spacing
if optimisedGridSpacing:
### Non-uniform spacing - v0
# x = 0.5*(1-np.cos(x*np.pi))
### Non-uniform spacing - v1
# MTP = 1/3*np.max([0.2,P]) # including MTP meshTransitionParam
# x = MTP*(1-np.cos(x*np.pi/(2*MTP)))*(x < MTP) + x*(x >= MTP)
### Non-uniform spacing - v2 (resample the number of points before and after MTP split)
MTP = 1/3*np.max([0.2,P]) # meshTransitionParam
x_opti = MTP*(1-np.cos(x*np.pi/(2*MTP)))*(x < MTP) + x*(x >= MTP)
resamplingRatio = ( (x_opti[sum(x < MTP)]-x_opti[sum(x < MTP)-1])/(x_opti[sum(x < MTP)+1]-x_opti[sum(x < MTP)]) )
x_patch1 = np.linspace(0, x[sum(x < MTP)], 1+ int(resamplingRatio*sum(x < MTP)))
x_patch2 = np.linspace(x[sum(x < MTP)], 1, gridPts - int(resamplingRatio*sum(x < MTP)))
x_new = np.concatenate((x_patch1[:], x_patch2[1:]), axis=0)
x = MTP*(1-np.cos(x_new*np.pi/(2*MTP)))*(x_new < MTP) + x_new*(x_new >= MTP)
# Camber line and camber line gradient
yc = np.ones(gridPts)
dyc_dx = np.ones(gridPts)
theta = np.ones(gridPts)
for i in range(gridPts):
if (x[i] >= 0) & (x[i] < P):
yc[i] = M/P**2*(2*P*x[i]-x[i]**2)
dyc_dx[i] = 2*M/P**2*(P-x[i])
elif (x[i] >=P) & (x[i] <=1):
yc[i] = M/(1-P)**2*(1-2*P+2*P*x[i]-x[i]**2)
dyc_dx[i] = 2*M/(1-P)**2*(P-x[i])
theta[i] = np.arctan(dyc_dx[i])
#
# Thickness distribution
yt = 5*T*(a0*x**0.5 + a1*x + a2*x**2 + a3*x**3 + a4*x**4)
dyt_dx = 5*T*(a0/(2*x[1:len(x)]**0.5) + a1 + 2*a2*x[1:len(x)] + 3*a3*x[1:len(x)]**2 + 4*a4*x[1:len(x)]**3)
#
# Upper surface points
xu = x - yt*np.sin(theta)
yu = yc + yt*np.cos(theta)
#
# Lower surface points
xl = x + yt*np.sin(theta)
yl = yc - yt*np.cos(theta)
#
ht = height_LE/chord + (height_TE-height_LE)*x[1:len(x)]/chord # NB: turbulent boundary layers grow rather linearly, laminar ones rather like square root.
x_offset = x[1:len(x)]-ht*dyt_dx/(1+dyt_dx**2)**0.5
y_offset = yt[1:len(x)] + ht/(1+dyt_dx**2)**0.5
x_offset = np.concatenate((np.array([x[0]- height_LE/chord]),x_offset))
y_offset = np.concatenate((np.array([0]),y_offset))
#
xu_offset = x + (x_offset-x)*np.cos(theta) - y_offset*np.sin(theta)
yu_offset = yc + y_offset*np.cos(theta) + (x_offset-x)*np.sin(theta)
xl_offset = x + (x_offset-x)*np.cos(theta) + y_offset*np.sin(theta)
yl_offset = yc - y_offset*np.cos(theta) + (x_offset-x)*np.sin(theta)
#
# Redefine the airfoil reference
x = x - airfoilReference/chord
xu = xu - airfoilReference/chord
xl = xl - airfoilReference/chord
xu_offset = xu_offset - airfoilReference/chord
xl_offset = xl_offset - airfoilReference/chord
#
# Rotation of (x, yc), (xl, yl) and (xu, yu) to account for the AoA
rotationMat = np.array([[np.cos(AoA*np.pi/180),np.sin(AoA*np.pi/180)],[-np.sin(AoA*np.pi/180),np.cos(AoA*np.pi/180)]])
#
# rotation performed around the axis (0 , 0)
lower_rot = np.matmul(rotationMat,np.array([xl,yl]))
upper_rot = np.matmul(rotationMat,np.array([xu,yu]))
camber_rot = np.matmul(rotationMat,np.array([x,yc]))
lower_offset_rot = np.matmul(rotationMat,np.array([xl_offset,yl_offset]))
upper_offset_rot = np.matmul(rotationMat,np.array([xu_offset,yu_offset]))
#
# dimensionalise the profile
x = x*chord
lower_rot = lower_rot*chord
upper_rot = upper_rot*chord
camber_rot = camber_rot*chord
lower_offset_rot = lower_offset_rot*chord
upper_offset_rot = upper_offset_rot*chord
#
return np.flip(upper_rot,axis=1), lower_rot[:,1:], camber_rot, np.flip(upper_offset_rot,axis=1), lower_offset_rot[:,1:], 180*theta[-1]/np.pi-AoA
# ******************************************************************************************************************************************************************************
# ******************************************************************************************************************************************************************************
# ******************************************************************************************************************************************************************************
def rotationMatrix(rotAnglesVec): # rotation around axis [axisZ, axisY, axisX]
yawRot = np.array([[np.cos(rotAnglesVec[0]*np.pi/180), -np.sin(rotAnglesVec[0]*np.pi/180), 0.0],
[np.sin(rotAnglesVec[0]*np.pi/180), np.cos(rotAnglesVec[0]*np.pi/180), 0.0],
[0.0, 0.0, 1.0]])
pitchRot = np.array([[np.cos(rotAnglesVec[1]*np.pi/180), 0.0, np.sin(rotAnglesVec[1]*np.pi/180)],
[0.0, 1.0, 0.0],
[-np.sin(rotAnglesVec[1]*np.pi/180), 0.0, np.cos(rotAnglesVec[1]*np.pi/180)]])
rollRot = np.array([[1.0, 0.0, 0.0],
[0.0, np.cos(rotAnglesVec[2]*np.pi/180), -np.sin(rotAnglesVec[2]*np.pi/180)],
[0.0, np.sin(rotAnglesVec[2]*np.pi/180), np.cos(rotAnglesVec[2]*np.pi/180)]])
rotMat = np.matmul(yawRot,np.matmul(pitchRot,rollRot)) # https://en.wikipedia.org/wiki/Rotation_matrix
return rotMat
def gmeshed_airfoil(structTag, GeomSpec, GridPtsSpec, rotMat, shiftVec):
pointTag = structTag[0]
lineTag = structTag[1]
surfaceTag = structTag[2]
NACA_type = GeomSpec[0]
bluntTrailingEdge = GeomSpec[1]
AoA = GeomSpec[2]
chord = GeomSpec[3]
airfoilReferenceAlongChord = GeomSpec[4]
airfoilReferenceCoordinate = GeomSpec[5]
height_LE = GeomSpec[6]
height_TE = GeomSpec[7]
TEpatchLength = GeomSpec[8]
TEpatchGridFlaringAngle = GeomSpec[9]
wakeLength = GeomSpec[10]
wakeGridFlaringAngle = GeomSpec[11]
gridPts_alongNACA = GridPtsSpec[0]
gridPts_inBL = GridPtsSpec[1]
gridPts_inTE = GridPtsSpec[2]
gridPts_alongTEpatch = GridPtsSpec[3]
gridPts_alongWake = GridPtsSpec[4]
gridGeomProg_inBL = GridPtsSpec[5]
gridGeomProg_alongTEpatch = GridPtsSpec[6]
gridGeomProg_alongWake = GridPtsSpec[7]
shiftVec = np.array(shiftVec)
airfoilReferenceCoordinate = np.array(airfoilReferenceCoordinate)
optimisedGridSpacing = True
[upper_NACAfoil, lower_NACAfoil, camberLine, upper_offset, lower_offset, theta_TE] = NACAxxx(NACA_type, bluntTrailingEdge, AoA, chord, airfoilReferenceAlongChord, height_LE, height_TE, optimisedGridSpacing, gridPts_alongNACA)
dyc_dx_TE = np.tan(theta_TE*np.pi/180)
# translate the airfoil to the airfoil reference center
for i in range(2):
upper_NACAfoil[i,:] = upper_NACAfoil[i,:] - airfoilReferenceCoordinate[i]
lower_NACAfoil[i,:] = lower_NACAfoil[i,:] - airfoilReferenceCoordinate[i]
upper_offset[i,:] = upper_offset[i,:] - airfoilReferenceCoordinate[i]
lower_offset[i,:] = lower_offset[i,:] - airfoilReferenceCoordinate[i]
# simply compute the corners coordinate to create the TEpatch region
deltaTEpatch_flaringAngle = TEpatchLength*np.tan(TEpatchGridFlaringAngle*np.pi/180)/np.cos(theta_TE*np.pi/180)
x_TEpatch = np.array([lower_offset[0,-1] + TEpatchLength + deltaTEpatch_flaringAngle*np.cos(np.pi/2 - theta_TE*np.pi/180) , upper_offset[0,0] + TEpatchLength - deltaTEpatch_flaringAngle*np.cos(np.pi/2 - theta_TE*np.pi/180)])
y_TEpatch = np.array([lower_offset[1,-1] + TEpatchLength*dyc_dx_TE - deltaTEpatch_flaringAngle*np.sin(np.pi/2 - theta_TE*np.pi/180), upper_offset[1,0] + TEpatchLength*dyc_dx_TE + deltaTEpatch_flaringAngle*np.sin(np.pi/2 - theta_TE*np.pi/180)])
# simply compute the corners coordinate to stretch the wake region
deltaWake_flaringAngle = wakeLength*np.tan(wakeGridFlaringAngle*np.pi/180)/np.cos(theta_TE*np.pi/180)
x_wake = np.array([x_TEpatch[0] + wakeLength + deltaWake_flaringAngle*np.cos(np.pi/2 - theta_TE*np.pi/180), x_TEpatch[1] + wakeLength - deltaWake_flaringAngle*np.cos(np.pi/2 - theta_TE*np.pi/180)])
y_wake = np.array([y_TEpatch[0] + wakeLength*dyc_dx_TE - deltaWake_flaringAngle*np.sin(np.pi/2 - theta_TE*np.pi/180), y_TEpatch[1] + wakeLength*dyc_dx_TE + deltaWake_flaringAngle*np.sin(np.pi/2 - theta_TE*np.pi/180)])
# $$$$$$$$$$$$$$$$$$$$$$$$$$$$
# # creation of the Points # #
# $$$$$$$$$$$$$$$$$$$$$$$$$$$$
# creation of the NACA profile
point_TEu = pointTag+1
for i in range(gridPts_alongNACA):
rotVec = np.matmul(rotMat, np.array([upper_NACAfoil[0,i], upper_NACAfoil[1,i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100,pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_LE = pointTag
if bluntTrailingEdge:
for i in range(gridPts_alongNACA-1):
rotVec = np.matmul(rotMat, np.array([lower_NACAfoil[0,i], lower_NACAfoil[1,i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100,pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_TEl = pointTag
rotVec = np.matmul(rotMat, np.array([0.5*(upper_NACAfoil[0,0]+lower_NACAfoil[0,-1]), 0.5*(upper_NACAfoil[1,0]+lower_NACAfoil[1,-1]), airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100,pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_TE = pointTag
else:
for i in range(gridPts_alongNACA-2):
rotVec = np.matmul(rotMat, np.array([lower_NACAfoil[0,i], lower_NACAfoil[1,i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100,pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_TEl = point_TEu
point_TE = point_TEu
# creation of the offset layer
point_up = pointTag+1
for i in range(gridPts_alongNACA):
rotVec = np.matmul(rotMat, np.array([upper_offset[0,i], upper_offset[1,i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_left = pointTag
for i in range(gridPts_alongNACA-1):
rotVec = np.matmul(rotMat, np.array([lower_offset[0,i], lower_offset[1,i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_low = pointTag
# creation of the TEpatch
point_lowRight = pointTag+1
for i in range(np.size(x_TEpatch)):
rotVec = np.matmul(rotMat, np.array([x_TEpatch[i], y_TEpatch[i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_upRight = pointTag
point_lowFarRight = pointTag+1
for i in range(np.size(x_wake)):
rotVec = np.matmul(rotMat, np.array([x_wake[i], y_wake[i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_upFarRight = pointTag
rotVec = np.matmul(rotMat, np.array([0.5*(x_TEpatch[0]+x_TEpatch[-1]), 0.5*(y_TEpatch[0]+y_TEpatch[-1]), airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_TEwake = pointTag
rotVec = np.matmul(rotMat, np.array([0.5*(x_wake[0]+x_wake[-1]), 0.5*(y_wake[0]+y_wake[-1]), airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_TEfarWake = pointTag
# to define transfinite region, number of gridPoint must be >=2.
gridPts_inBL = max(gridPts_inBL,2)
gridPts_inTE = max(gridPts_inTE,2)
# for the Blossom algorithm to work (setRecombine when applied for the regular CAA domain), an odd
# number of points in the contour needs to be specified. All edges have a up/low twin appart from
# the line F. The discretisation of the TE is rounded so to ensure that an odd number of points in
# the periphery of the profile is used.
if ~(gridPts_inTE % 2):
gridPts_inTE = gridPts_inTE+1
if bluntTrailingEdge:
alphaStretch = (max(1,gridPts_inTE-2))/(gridPts_inTE+gridPts_inBL-3)
rotVec = np.matmul(rotMat, np.array([0.5*(1-alphaStretch)*x_TEpatch[-1]+0.5*(1+alphaStretch)*x_TEpatch[0],
0.5*(1-alphaStretch)*y_TEpatch[-1]+0.5*(1+alphaStretch)*y_TEpatch[0],
airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_lowMidRight = pointTag
rotVec = np.matmul(rotMat, np.array([0.5*(1-alphaStretch)*x_TEpatch[0]+0.5*(1+alphaStretch)*x_TEpatch[-1],
0.5*(1-alphaStretch)*y_TEpatch[0]+0.5*(1+alphaStretch)*y_TEpatch[-1],
airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_upMidRight = pointTag
# ~~~
rotVec = np.matmul(rotMat, np.array([0.5*(1-alphaStretch)*x_wake[-1]+0.5*(1+alphaStretch)*x_wake[0],
0.5*(1-alphaStretch)*y_wake[-1]+0.5*(1+alphaStretch)*y_wake[0],
airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_lowMidFarRight = pointTag
rotVec = np.matmul(rotMat, np.array([0.5*(1-alphaStretch)*x_wake[0]+0.5*(1+alphaStretch)*x_wake[-1],
0.5*(1-alphaStretch)*y_wake[0]+0.5*(1+alphaStretch)*y_wake[-1],
airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_upMidFarRight = pointTag
else:
point_lowMidRight = point_TEwake
point_upMidRight = point_TEwake
point_lowMidFarRight = point_TEfarWake
point_upMidFarRight = point_TEfarWake
# $$$$$$$$$$$$$$$$$$$$$$$$$$$
# # creation of the Lines # #
# $$$$$$$$$$$$$$$$$$$$$$$$$$$
# creation of the NACA profile
airfoil_startLineTag = lineTag + 1
for i in range(gridPts_alongNACA-1):
gmsh.model.geo.add_line(point_TEu+i, point_TEu+i+1,lineTag+i+1)
lineTag = lineTag+i+1 # store the last 'lineTag' from previous loop
airfoil_LE_lineTag = lineTag
if bluntTrailingEdge:
for i in range(gridPts_alongNACA-1):
gmsh.model.geo.add_line(point_LE+i, point_LE+i+1,lineTag+i+1)
else:
for i in range(gridPts_alongNACA-2):
gmsh.model.geo.add_line(point_LE+i, point_LE+i+1,lineTag+i+1)
# if the TE is sharp, the last point corresponds to the first one
i = i+1
gmsh.model.geo.add_line(point_LE+i, point_TEl, lineTag+i+1)
lineTag = lineTag+i+1 # store the last 'lineTag' from previous loop
airfoil_endLineTag = lineTag
# creation of the offset layer
structGrid_startLineTag = lineTag + 1
for i in range(gridPts_alongNACA-1):
gmsh.model.geo.add_line(point_up+i, point_up+i+1,lineTag+i+1)
lineTag = lineTag+i+1
structGrid_LE_lineTag = lineTag
for i in range(gridPts_alongNACA-1):
gmsh.model.geo.add_line(point_left+i, point_left+i+1,lineTag+i+1)
lineTag = lineTag+i+1 # store the last 'lineTag' from previous loop
structGrid_endLineTag = lineTag
line_A = lineTag+1
for i in range(gridPts_alongNACA-1):
gmsh.model.geo.add_line(point_TEu+i, point_up+i,lineTag+i+1)
lineTag = lineTag+i+1
line_G = lineTag+1
for i in range(gridPts_alongNACA-1):
gmsh.model.geo.add_line(point_LE+i, point_left+i,lineTag+i+1)
i = i+1
gmsh.model.geo.add_line(point_TEl, point_low,lineTag+i+1)
lineTag = lineTag+i+1
line_B = lineTag
gmsh.model.geo.add_line(point_lowRight, point_lowMidRight,lineTag+1)
lineTag = lineTag+1 # store the last 'lineTag' from previous loop
line_Br = lineTag
gmsh.model.geo.add_line(point_upMidRight, point_upRight,lineTag+1)
lineTag = lineTag+1 # store the last 'lineTag' from previous loop
line_Ar = lineTag
gmsh.model.geo.add_line(point_lowFarRight, point_lowMidFarRight,lineTag+1)
lineTag = lineTag + 1
line_Ber = lineTag
gmsh.model.geo.add_line(point_upMidFarRight, point_upFarRight,lineTag+1)
lineTag = lineTag + 1
line_Aer = lineTag
gmsh.model.geo.add_line(point_low, point_lowRight,lineTag+1)
lineTag = lineTag + 1
line_C = lineTag
gmsh.model.geo.add_line(point_upRight,point_up,lineTag+1)
lineTag = lineTag + 1
line_D = lineTag
gmsh.model.geo.add_line(point_lowRight,point_lowFarRight,lineTag+1)
lineTag = lineTag + 1
line_H = lineTag
gmsh.model.geo.add_line(point_upFarRight, point_upRight,lineTag+1)
lineTag = lineTag + 1
line_I = lineTag
gmsh.model.geo.add_line(point_TE,point_TEwake,lineTag+1)
lineTag = lineTag + 1
line_K = lineTag
gmsh.model.geo.add_line(point_TEwake, point_TEfarWake, lineTag+1)
lineTag = lineTag + 1
line_N = lineTag
if bluntTrailingEdge: # create a line for the TE
gmsh.model.geo.add_line(point_TEl,point_TE,lineTag+1)
lineTag = lineTag + 1
line_El = lineTag
gmsh.model.geo.add_line(point_TE, point_TEu,lineTag+1)
lineTag = lineTag + 1
line_Eu = lineTag
gmsh.model.geo.add_line(point_lowMidRight, point_TEwake,lineTag+1)
lineTag = lineTag+1 # store the last 'lineTag' from previous loop
line_Fl = lineTag
gmsh.model.geo.add_line(point_TEwake, point_upMidRight,lineTag+1)
lineTag = lineTag+1 # store the last 'lineTag' from previous loop
line_Fu = lineTag
gmsh.model.geo.add_line(point_lowMidFarRight, point_TEfarWake,lineTag+1)
lineTag = lineTag + 1
line_Jl = lineTag
gmsh.model.geo.add_line(point_TEfarWake, point_upMidFarRight,lineTag+1)
lineTag = lineTag + 1
line_Ju = lineTag
gmsh.model.geo.add_line(point_TEu,point_upMidRight,lineTag+1)
lineTag = lineTag + 1
line_M = lineTag
gmsh.model.geo.add_line(point_TEl, point_lowMidRight,lineTag+1)
lineTag = lineTag + 1
line_L = lineTag
gmsh.model.geo.add_line(point_lowMidRight, point_lowMidFarRight,lineTag+1)
lineTag = lineTag + 1
line_O = lineTag
gmsh.model.geo.add_line(point_upMidRight, point_upMidFarRight,lineTag+1)
lineTag = lineTag + 1
line_P = lineTag
else:
line_M = line_K
line_L = line_K
line_O = line_N
line_P = line_N
line_El = -1
line_Eu = -1
line_Fl = -1
line_Fu = -1
line_Jl = -1
line_Ju = -1
# $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
# # creation of some general CurveLoops # #
# $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
line_airfoilUp = list(range(airfoil_startLineTag, airfoil_LE_lineTag+1))
line_airfoilLow = list(range(airfoil_LE_lineTag+1, airfoil_endLineTag+1))
line_BLup = list(range(structGrid_startLineTag, structGrid_LE_lineTag+1))
line_BLlow = list(range(structGrid_LE_lineTag+1, structGrid_endLineTag+1))
line_BLradii = list(range(line_A, line_B+1))
# $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
# # creation of the surfaces # #
# $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
# mesh of the airfoil interior (test --> OK)
line_airfoil = list(range(airfoil_startLineTag, airfoil_endLineTag+1))
if bluntTrailingEdge: # taking into account of the TE to close the contour
airfoil_boundaries = [*line_airfoil, line_El, line_Eu]
else:
airfoil_boundaries = [*line_airfoil]
gmsh.model.geo.add_curve_loop( airfoil_boundaries, surfaceTag+1)
gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1) # mesh inside the airfoil
if bluntTrailingEdge:
if (gridPts_alongNACA <= gridPts_inTE):
print("Warning. A struct mesh cannot be created with this ration of points in the blunt TE and along the airfoil. Choose gridPts_alongNACA/gridPts_inTE > 1")
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1, "LeftRight", [point_TEl, point_TEu, point_LE-gridPts_inTE+2, point_LE+gridPts_inTE-2])
else:
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1, "LeftRight", [point_TE, point_TE+int(gridPts_alongNACA/2), point_LE, point_LE+int(gridPts_alongNACA/2)])
gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
surfaceTag = surfaceTag+1
surf_airfoil = surfaceTag
# (structured / transfinite) boundary layer grid
for i in range(2*gridPts_alongNACA-2):
gmsh.model.geo.mesh.setTransfiniteCurve(airfoil_startLineTag+i, 2) # just create one cell between two consecutive NACA gridtPts
gmsh.model.geo.mesh.setTransfiniteCurve(structGrid_startLineTag+i, 2) # just create one cell between two consecutive NACA gridtPts
for i in range(2*gridPts_alongNACA-1):
gmsh.model.geo.mesh.setTransfiniteCurve(line_BLradii[i], gridPts_inBL, "Progression", gridGeomProg_inBL)
BLstructStartSurfTag = surfaceTag+1
for i in range(2*gridPts_alongNACA-2):
gmsh.model.geo.add_curve_loop([structGrid_startLineTag+i, -line_BLradii[i+1], -(airfoil_startLineTag+i), line_BLradii[i]], surfaceTag+1)
gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1)
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1)
gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
surfaceTag = surfaceTag+1
BLstructEndSurfTag = surfaceTag
surf_BLstructGridUp = list(range(BLstructStartSurfTag, BLstructStartSurfTag+gridPts_alongNACA-1))
surf_BLstructGridLow = list(range(BLstructStartSurfTag+gridPts_alongNACA-1, BLstructEndSurfTag+1))
surf_BLstructGrid = [*surf_BLstructGridUp, *surf_BLstructGridLow]
# (structured / transfinite) TEpatch region
TEpatch_boundariesl = [line_C, line_Br, -line_L, line_B]
TEpatch_boundariesu = [line_M, line_Ar, line_D, -line_A]
gmsh.model.geo.add_curve_loop( TEpatch_boundariesl, surfaceTag+1)
gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1)
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1)
gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
surfaceTag = surfaceTag+1
surf_TEpatchLow = surfaceTag
gmsh.model.geo.add_curve_loop( TEpatch_boundariesu, surfaceTag+1)
gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1)
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1)
gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
surfaceTag = surfaceTag+1
surf_TEpatchUp = surfaceTag
if bluntTrailingEdge:
gmsh.model.geo.mesh.setTransfiniteCurve(line_El, gridPts_inTE-1, "Progression", gridGeomProg_inBL)
gmsh.model.geo.mesh.setTransfiniteCurve(line_Eu, gridPts_inTE-1, "Progression", -gridGeomProg_inBL)
gmsh.model.geo.mesh.setTransfiniteCurve(line_Fl, gridPts_inTE-1)
gmsh.model.geo.mesh.setTransfiniteCurve(line_Fu, gridPts_inTE-1)
TEpatch_boundariesml = [line_L, line_Fl, -line_K, -line_El]
TEpatch_boundariesmu = [line_K, line_Fu, -line_M, -line_Eu]
gmsh.model.geo.add_curve_loop( TEpatch_boundariesml, surfaceTag+1)
gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1)
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1)
gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
surfaceTag = surfaceTag+1
surf_TEpatchMidLow = surfaceTag
gmsh.model.geo.add_curve_loop( TEpatch_boundariesmu, surfaceTag+1)
gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1)
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1)
gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
surfaceTag = surfaceTag+1
surf_TEpatchMidUp = surfaceTag
else:
surf_TEpatchMidLow = -1
surf_TEpatchMidUp = -1
gmsh.model.geo.mesh.setTransfiniteCurve(line_Ar, gridPts_inBL)
gmsh.model.geo.mesh.setTransfiniteCurve(line_Br, gridPts_inBL)
gmsh.model.geo.mesh.setTransfiniteCurve(line_C, gridPts_alongTEpatch)
gmsh.model.geo.mesh.setTransfiniteCurve(line_D, gridPts_alongTEpatch)
gmsh.model.geo.mesh.setTransfiniteCurve(line_K, gridPts_alongTEpatch,"Progression", gridGeomProg_alongTEpatch)
if bluntTrailingEdge:
gmsh.model.geo.mesh.setTransfiniteCurve(line_M, gridPts_alongTEpatch,"Progression", gridGeomProg_alongTEpatch)
gmsh.model.geo.mesh.setTransfiniteCurve(line_L, gridPts_alongTEpatch,"Progression", gridGeomProg_alongTEpatch)
# (structured / transfinite) wake region
# if bluntTrailingEdge:
# wake_boundaries = [line_H, line_Ber, line_Jl, line_Ju, line_Aer, line_I, -line_Ar, -line_Fu, -line_Fl, -line_Br]
# else:
# wake_boundaries = [line_H, line_Ber, line_Aer, line_I, -line_Ar, -line_Br]
# wake_curveLoop = gmsh.model.geo.add_curve_loop( wake_boundaries, surfaceTag+1)
# gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1)
# gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1, "LeftRight", [point_lowRight, point_lowFarRight, point_upFarRight, point_upRight])
# gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
# surfaceTag = surfaceTag+1
# surf_wake = surfaceTag
# if bluntTrailingEdge:
# gmsh.model.geo.mesh.setTransfiniteCurve(line_J, 2*(gridPts_inBL+gridPts_inTE)-5)
# else:
# gmsh.model.geo.mesh.setTransfiniteCurve(line_J, 2*gridPts_inBL-1)
wake_boundariesl = [line_H, line_Ber, -line_O, -line_Br]
wake_boundariesu = [line_P, line_Aer, line_I, -line_Ar]
gmsh.model.geo.add_curve_loop( wake_boundariesl, surfaceTag+1)
gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1)
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1)
gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
surfaceTag = surfaceTag+1
surf_wakeLow = surfaceTag
gmsh.model.geo.add_curve_loop( wake_boundariesu, surfaceTag+1)
gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1)
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1)
gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
surfaceTag = surfaceTag+1
surf_wakeUp = surfaceTag
if bluntTrailingEdge:
wake_boundariesml = [line_O, line_Jl, -line_N, -line_Fl]
wake_boundariesmu = [line_N, line_Ju, -line_P, -line_Fu]
gmsh.model.geo.add_curve_loop( wake_boundariesml, surfaceTag+1)
gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1)
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1)
gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
surfaceTag = surfaceTag+1
surf_wakeMidLow = surfaceTag
gmsh.model.geo.add_curve_loop( wake_boundariesmu, surfaceTag+1)
gmsh.model.geo.addPlaneSurface([surfaceTag+1], surfaceTag+1)
gmsh.model.geo.mesh.setTransfiniteSurface(surfaceTag+1)
gmsh.model.geo.mesh.setRecombine(pb_2Dim, surfaceTag+1) # To create quadrangles instead of triangles
surfaceTag = surfaceTag+1
surf_wakeMidUp = surfaceTag
else:
surf_wakeMidLow = -1
surf_wakeMidUp = -1
gmsh.model.geo.mesh.setTransfiniteCurve(line_Aer, gridPts_inBL)
gmsh.model.geo.mesh.setTransfiniteCurve(line_Ber, gridPts_inBL)
if bluntTrailingEdge:
gmsh.model.geo.mesh.setTransfiniteCurve(line_Jl, gridPts_inTE-1)
gmsh.model.geo.mesh.setTransfiniteCurve(line_Ju, gridPts_inTE-1)
gmsh.model.geo.mesh.setTransfiniteCurve(line_H, gridPts_alongWake,"Progression", gridGeomProg_alongWake)
gmsh.model.geo.mesh.setTransfiniteCurve(line_I, gridPts_alongWake,"Progression", -gridGeomProg_alongWake)
gmsh.model.geo.mesh.setTransfiniteCurve(line_N, gridPts_alongWake,"Progression", gridGeomProg_alongWake)
if bluntTrailingEdge:
gmsh.model.geo.mesh.setTransfiniteCurve(line_P, gridPts_alongWake,"Progression", gridGeomProg_alongWake)
gmsh.model.geo.mesh.setTransfiniteCurve(line_O, gridPts_alongWake,"Progression", gridGeomProg_alongWake)
# # connection to regular CAA domain:
pointTag_list = [point_LE, point_TE, point_TEu, point_TEl, point_TEwake, point_TEfarWake, point_left, point_up, point_upRight, point_upFarRight, point_low, point_lowRight, point_lowFarRight, point_upMidRight, point_lowMidRight, point_upMidFarRight, point_lowMidFarRight]
lineTag_list = [[*line_airfoilUp], [*line_airfoilLow], [*line_BLup], [*line_BLlow], [*line_BLradii], line_A, line_B, line_C, line_D, line_Eu, line_El, line_Fu, line_Fl, line_G, line_H, line_I, line_Ju, line_Jl, line_K, line_L, line_M, line_N, line_O, line_P, line_Ar, line_Br, line_Aer, line_Ber]
surfaceTag_list = [surf_airfoil, [*surf_BLstructGrid], surf_BLstructGridUp, surf_BLstructGridLow, surf_TEpatchUp, surf_TEpatchLow, surf_TEpatchMidUp, surf_TEpatchMidLow, surf_wakeUp, surf_wakeLow, surf_wakeMidUp, surf_wakeMidLow]
return pointTag_list, lineTag_list, surfaceTag_list, pointTag, lineTag, surfaceTag
# ******************************************************************************************************************************************************************************
# ******************************************************************************************************************************************************************************
# ******************************************************************************************************************************************************************************
def gmeshed_airfoil_HO(structTag, GeomSpec, GridPtsSpec, rotMat, shiftVec): # high-order capable version of gmeshed_airfoil()
pointTag = structTag[0]
lineTag = structTag[1]
surfaceTag = structTag[2]
NACA_type = GeomSpec[0]
bluntTrailingEdge = GeomSpec[1]
AoA = GeomSpec[2]
chord = GeomSpec[3]
airfoilReferenceAlongChord = GeomSpec[4]
airfoilReferenceCoordinate = GeomSpec[5]
height_LE = GeomSpec[6]
height_TE = GeomSpec[7]
TEpatchLength = GeomSpec[8]
TEpatchGridFlaringAngle = GeomSpec[9]
wakeLength = GeomSpec[10]
wakeGridFlaringAngle = GeomSpec[11]
gridPts_alongNACA = GridPtsSpec[0]
gridPts_inBL = GridPtsSpec[1]
gridPts_inTE = GridPtsSpec[2]
gridPts_alongTEpatch = GridPtsSpec[3]
gridPts_alongWake = GridPtsSpec[4]
gridGeomProg_inBL = GridPtsSpec[5]
gridGeomProg_alongTEpatch = GridPtsSpec[6]
gridGeomProg_alongWake = GridPtsSpec[7]
shiftVec = np.array(shiftVec)
airfoilReferenceCoordinate = np.array(airfoilReferenceCoordinate)
optimisedGridSpacing = True
spline_controlPts = 500
[upper_NACAfoil, lower_NACAfoil, camberLine, upper_offset, lower_offset, theta_TE] = NACAxxx(NACA_type, bluntTrailingEdge, AoA, chord, airfoilReferenceAlongChord, height_LE, height_TE, optimisedGridSpacing, spline_controlPts)
dyc_dx_TE = np.tan(theta_TE*np.pi/180)
# translate the airfoil to the airfoil reference center
for i in range(2):
upper_NACAfoil[i,:] = upper_NACAfoil[i,:] - airfoilReferenceCoordinate[i]
lower_NACAfoil[i,:] = lower_NACAfoil[i,:] - airfoilReferenceCoordinate[i]
upper_offset[i,:] = upper_offset[i,:] - airfoilReferenceCoordinate[i]
lower_offset[i,:] = lower_offset[i,:] - airfoilReferenceCoordinate[i]
# simply compute the corners coordinate to create the TEpatch region
deltaTEpatch_flaringAngle = TEpatchLength*np.tan(TEpatchGridFlaringAngle*np.pi/180)/np.cos(theta_TE*np.pi/180)
x_TEpatch = np.array([lower_offset[0,-1] + TEpatchLength + deltaTEpatch_flaringAngle*np.cos(np.pi/2 - theta_TE*np.pi/180) , upper_offset[0,0] + TEpatchLength - deltaTEpatch_flaringAngle*np.cos(np.pi/2 - theta_TE*np.pi/180)])
y_TEpatch = np.array([lower_offset[1,-1] + TEpatchLength*dyc_dx_TE - deltaTEpatch_flaringAngle*np.sin(np.pi/2 - theta_TE*np.pi/180), upper_offset[1,0] + TEpatchLength*dyc_dx_TE + deltaTEpatch_flaringAngle*np.sin(np.pi/2 - theta_TE*np.pi/180)])
# simply compute the corners coordinate to stretch the wake region
deltaWake_flaringAngle = wakeLength*np.tan(wakeGridFlaringAngle*np.pi/180)/np.cos(theta_TE*np.pi/180)
x_wake = np.array([x_TEpatch[0] + wakeLength + deltaWake_flaringAngle*np.cos(np.pi/2 - theta_TE*np.pi/180), x_TEpatch[1] + wakeLength - deltaWake_flaringAngle*np.cos(np.pi/2 - theta_TE*np.pi/180)])
y_wake = np.array([y_TEpatch[0] + wakeLength*dyc_dx_TE - deltaWake_flaringAngle*np.sin(np.pi/2 - theta_TE*np.pi/180), y_TEpatch[1] + wakeLength*dyc_dx_TE + deltaWake_flaringAngle*np.sin(np.pi/2 - theta_TE*np.pi/180)])
# $$$$$$$$$$$$$$$$$$$$$$$$$$$$
# # creation of the Points # #
# $$$$$$$$$$$$$$$$$$$$$$$$$$$$
# creation of the NACA profile
point_TEu = pointTag+1
for i in range(spline_controlPts):
rotVec = np.matmul(rotMat, np.array([upper_NACAfoil[0,i], upper_NACAfoil[1,i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100,pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_LE = pointTag
if bluntTrailingEdge:
for i in range(spline_controlPts-1):
rotVec = np.matmul(rotMat, np.array([lower_NACAfoil[0,i], lower_NACAfoil[1,i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100,pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_TEl = pointTag
rotVec = np.matmul(rotMat, np.array([0.5*(upper_NACAfoil[0,0]+lower_NACAfoil[0,-1]), 0.5*(upper_NACAfoil[1,0]+lower_NACAfoil[1,-1]), airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100,pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_TE = pointTag
else:
for i in range(spline_controlPts-2):
rotVec = np.matmul(rotMat, np.array([lower_NACAfoil[0,i], lower_NACAfoil[1,i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100,pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_TEl = point_TEu
point_TE = point_TEu
# creation of the offset layer
point_up = pointTag+1
for i in range(spline_controlPts):
rotVec = np.matmul(rotMat, np.array([upper_offset[0,i], upper_offset[1,i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_left = pointTag
for i in range(spline_controlPts-1):
rotVec = np.matmul(rotMat, np.array([lower_offset[0,i], lower_offset[1,i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_low = pointTag
# creation of the TEpatch
point_lowRight = pointTag+1
for i in range(np.size(x_TEpatch)):
rotVec = np.matmul(rotMat, np.array([x_TEpatch[i], y_TEpatch[i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_upRight = pointTag
point_lowFarRight = pointTag+1
for i in range(np.size(x_wake)):
rotVec = np.matmul(rotMat, np.array([x_wake[i], y_wake[i], airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+i+1)
pointTag = pointTag+i+1 # store the last 'pointTag' from previous loop
point_upFarRight = pointTag
rotVec = np.matmul(rotMat, np.array([0.5*(x_TEpatch[0]+x_TEpatch[-1]), 0.5*(y_TEpatch[0]+y_TEpatch[-1]), airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_TEwake = pointTag
rotVec = np.matmul(rotMat, np.array([0.5*(x_wake[0]+x_wake[-1]), 0.5*(y_wake[0]+y_wake[-1]), airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_TEfarWake = pointTag
# to define transfinite region, number of gridPoint must be >=2.
gridPts_inBL = max(gridPts_inBL,2)
gridPts_inTE = max(gridPts_inTE,2)
# for the Blossom algorithm to work (setRecombine when applied for the regular CAA domain), an odd
# number of points in the contour needs to be specified. All edges have a up/low twin appart from
# the line F. The discretisation of the TE is rounded so to ensure that an odd number of points in
# the periphery of the profile is used.
if ~(gridPts_inTE % 2):
gridPts_inTE = gridPts_inTE+1
if bluntTrailingEdge:
alphaStretch = (max(1,gridPts_inTE-2))/(gridPts_inTE+gridPts_inBL-3)
rotVec = np.matmul(rotMat, np.array([0.5*(1-alphaStretch)*x_TEpatch[-1]+0.5*(1+alphaStretch)*x_TEpatch[0],
0.5*(1-alphaStretch)*y_TEpatch[-1]+0.5*(1+alphaStretch)*y_TEpatch[0],
airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_lowMidRight = pointTag
rotVec = np.matmul(rotMat, np.array([0.5*(1-alphaStretch)*x_TEpatch[0]+0.5*(1+alphaStretch)*x_TEpatch[-1],
0.5*(1-alphaStretch)*y_TEpatch[0]+0.5*(1+alphaStretch)*y_TEpatch[-1],
airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_upMidRight = pointTag
# ~~~
rotVec = np.matmul(rotMat, np.array([0.5*(1-alphaStretch)*x_wake[-1]+0.5*(1+alphaStretch)*x_wake[0],
0.5*(1-alphaStretch)*y_wake[-1]+0.5*(1+alphaStretch)*y_wake[0],
airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_lowMidFarRight = pointTag
rotVec = np.matmul(rotMat, np.array([0.5*(1-alphaStretch)*x_wake[0]+0.5*(1+alphaStretch)*x_wake[-1],
0.5*(1-alphaStretch)*y_wake[0]+0.5*(1+alphaStretch)*y_wake[-1],
airfoilReferenceCoordinate[2]])) + shiftVec
gmsh.model.geo.addPoint(rotVec[0], rotVec[1], rotVec[2], chord/100, pointTag+1)
pointTag = pointTag+1 # store the last 'pointTag' from previous loop
point_upMidFarRight = pointTag
else:
point_lowMidRight = point_TEwake
point_upMidRight = point_TEwake
point_lowMidFarRight = point_TEfarWake
point_upMidFarRight = point_TEfarWake
# $$$$$$$$$$$$$$$$$$$$$$$$$$$
# # creation of the Lines # #
# $$$$$$$$$$$$$$$$$$$$$$$$$$$
# creation of the NACA profile
gmsh.model.geo.addSpline(range(point_TEu, point_LE+1), lineTag+1)
lineTag = lineTag+1 # store the last 'pointTag' from previous loop
airfoilExtrado_lineTag = lineTag
if bluntTrailingEdge:
gmsh.model.geo.addSpline(range(point_LE, point_TEl+1), lineTag+1)
else:
gmsh.model.geo.addSpline([*range(point_LE, point_LE+spline_controlPts-1), point_TE], lineTag+1)
lineTag = lineTag+1 # store the last 'pointTag' from previous loop
airfoilIntrado_lineTag = lineTag
# creation of the offset layer
gmsh.model.geo.addSpline(range(point_up, point_left+1), lineTag+1)
lineTag = lineTag+1 # store the last 'pointTag' from previous loop
airfoilExtradoOffset_lineTag = lineTag
gmsh.model.geo.addSpline(range(point_left, point_low+1), lineTag+1)
lineTag = lineTag+1 # store the last 'pointTag' from previous loop
airfoilIntradoOffset_lineTag = lineTag
gmsh.model.geo.add_line(point_TEu, point_up,lineTag+1)
lineTag = lineTag+1
line_A = lineTag
gmsh.model.geo.add_line(point_LE, point_left,lineTag+1)
lineTag = lineTag+1
line_G = lineTag
gmsh.model.geo.add_line(point_TEl, point_low,lineTag+1)
lineTag = lineTag+1
line_B = lineTag
# # creation of the NACA profile
# airfoil_startLineTag = lineTag + 1
# for i in range(spline_controlPts-1):
# gmsh.model.geo.add_line(point_TEu+i, point_TEu+i+1,lineTag+i+1)
# lineTag = lineTag+i+1 # store the last 'lineTag' from previous loop
# airfoil_LE_lineTag = lineTag
# if bluntTrailingEdge:
# for i in range(spline_controlPts-1):
# gmsh.model.geo.add_line(point_LE+i, point_LE+i+1,lineTag+i+1)
# else:
# for i in range(spline_controlPts-2):
# gmsh.model.geo.add_line(point_LE+i, point_LE+i+1,lineTag+i+1)
# # if the TE is sharp, the last point corresponds to the first one
# i = i+1
# gmsh.model.geo.add_line(point_LE+i, point_TEl, lineTag+i+1)
# lineTag = lineTag+i+1 # store the last 'lineTag' from previous loop
# airfoil_endLineTag = lineTag
#
# # creation of the offset layer
# structGrid_startLineTag = lineTag + 1
# for i in range(spline_controlPts-1):
# gmsh.model.geo.add_line(point_up+i, point_up+i+1,lineTag+i+1)
# lineTag = lineTag+i+1
# structGrid_LE_lineTag = lineTag
# for i in range(spline_controlPts-1):
# gmsh.model.geo.add_line(point_left+i, point_left+i+1,lineTag+i+1)
# lineTag = lineTag+i+1 # store the last 'lineTag' from previous loop
# structGrid_endLineTag = lineTag
# line_A = lineTag+1
# for i in range(spline_controlPts-1):
# gmsh.model.geo.add_line(point_TEu+i, point_up+i,lineTag+i+1)
# lineTag = lineTag+i+1
# line_G = lineTag+1
# for i in range(spline_controlPts-1):
# gmsh.model.geo.add_line(point_LE+i, point_left+i,lineTag+i+1)
# i = i+1
# gmsh.model.geo.add_line(point_TEl, point_low,lineTag+i+1)
# lineTag = lineTag+i+1
# line_B = lineTag
gmsh.model.geo.add_line(point_lowRight, point_lowMidRight,lineTag+1)
lineTag = lineTag+1 # store the last 'lineTag' from previous loop
line_Br = lineTag
gmsh.model.geo.add_line(point_upMidRight, point_upRight,lineTag+1)
lineTag = lineTag+1 # store the last 'lineTag' from previous loop
line_Ar = lineTag
gmsh.model.geo.add_line(point_lowFarRight, point_lowMidFarRight,lineTag+1)
lineTag = lineTag + 1
line_Ber = lineTag
gmsh.model.geo.add_line(point_upMidFarRight, point_upFarRight,lineTag+1)
lineTag = lineTag + 1
line_Aer = lineTag
gmsh.model.geo.add_line(point_low, point_lowRight,lineTag+1)
lineTag = lineTag + 1
line_C = lineTag
gmsh.model.geo.add_line(point_upRight,point_up,lineTag+1)
lineTag = lineTag + 1
line_D = lineTag
gmsh.model.geo.add_line(point_lowRight,point_lowFarRight,lineTag+1)
lineTag = lineTag + 1
line_H = lineTag
gmsh.model.geo.add_line(point_upFarRight, point_upRight,lineTag+1)
lineTag = lineTag + 1
line_I = lineTag
gmsh.model.geo.add_line(point_TE,point_TEwake,lineTag+1)
lineTag = lineTag + 1
line_K = lineTag
gmsh.model.geo.add_line(point_TEwake, point_TEfarWake, lineTag+1)
lineTag = lineTag + 1
line_N = lineTag
if bluntTrailingEdge: # create a line for the TE
gmsh.model.geo.add_line(point_TEl,point_TE,lineTag+1)
lineTag = lineTag + 1
line_El = lineTag
gmsh.model.geo.add_line(point_TE, point_TEu,lineTag+1)
lineTag = lineTag + 1
line_Eu = lineTag
gmsh.model.geo.add_line(point_lowMidRight, point_TEwake,lineTag+1)
lineTag = lineTag+1 # store the last 'lineTag' from previous loop
line_Fl = lineTag
gmsh.model.geo.add_line(point_TEwake, point_upMidRight,lineTag+1)
lineTag = lineTag+1 # store the last 'lineTag' from previous loop
line_Fu = lineTag
gmsh.model.geo.add_line(point_lowMidFarRight, point_TEfarWake,lineTag+1)
lineTag = lineTag + 1
line_Jl = lineTag
gmsh.model.geo.add_line(point_TEfarWake, point_upMidFarRight,lineTag+1)
lineTag = lineTag + 1
line_Ju = lineTag
gmsh.model.geo.add_line(point_TEu,point_upMidRight,lineTag+1)
lineTag = lineTag + 1
line_M = lineTag
gmsh.model.geo.add_line(point_TEl, point_lowMidRight,lineTag+1)
lineTag = lineTag + 1
line_L = lineTag
gmsh.model.geo.add_line(point_lowMidRight, point_lowMidFarRight,lineTag+1)
lineTag = lineTag + 1
line_O = lineTag
gmsh.model.geo.add_line(point_upMidRight, point_upMidFarRight,lineTag+1)
lineTag = lineTag + 1
line_P = lineTag
else:
line_M = line_K