-
Notifications
You must be signed in to change notification settings - Fork 0
/
bladeprop.py
2601 lines (2106 loc) · 97.3 KB
/
bladeprop.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
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 9 10:56:21 2011
@author: dave
"""
import os
import math
import warnings
import numpy as np
import scipy
import scipy.interpolate
import scipy.integrate as integrate
from matplotlib import pyplot as plt
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigCanvas
from matplotlib.figure import Figure
import matplotlib as mpl
plt.rc('font', family='serif')
plt.rc('xtick', labelsize=10)
plt.rc('ytick', labelsize=10)
plt.rc('axes', labelsize=12)
plt.rc('text', usetex=True)
plt.rc('legend', fontsize=11)
plt.rc('legend', numpoints=1)
plt.rc('legend', borderaxespad=0)
mpl.rcParams['text.latex.unicode'] = True
import HawcPy
from crosssection import properties as crosprop
import materials
import Simulations as sim
from misc import find0, _linear_distr_blade
import plotting
sti = HawcPy.ModelData.st_headers
# numpy print options:
np.set_printoptions(precision=6, suppress=True)
def coord_continuous(coord, res=100000, method=None):
"""
Continuous series of coordinate points
======================================
The original format of the coordinates is not increasing and
continious. Convert to a two series (upper and lower serface) with
continious properties. If method is properly defined, the coordinates
will also be interpolated onto a uni-spaced high resolution grid.
Main assumption on the data is that the coordinates are ordered. The
points are described following the circular motion: starting from the
LE, going over either pressure or suction side to the TE and back over
the other surface. This method will fail if the data has a more
random character.
Parameters
----------
coord : ndarray(n,2)
Array holding the x/c and y/c coordinates respectivaly.
res : int, default=100000
Integer specifying how many x/c points should be maintained for
the higher resultion coord array. Value ignored when method=None.
Note that a leading edge usually already has a high resolution
hence the relative high default resultion.
method : str, default=None
String specifying the interpolation method to go from low to high
resoltion. See scipy.interpolate.griddata for more info. Possible
values are 'cubic', 'linear' or 'nearest'. If None no interpolation
to a higher resolution grid will be carried out
Returns
-------
coord_up : ndarray(n_new1, 2)
Array holding the x/c and y/c coordinates of the upper surface,
and where n = n_new1 + n_new2.
coord_low : ndarray(n_new2, 2)
Array holding the x/c and y/c coordinates of the upper surface,
and where n = n_new1 + n_new2
"""
# TODO: add check on continuity: smoothness of the function
# see if the first, second, third derivatives are within a certain
# range
xval = coord[:,0]
yval = coord[:,1]
# split up in two increasing sets
xval_delta = xval[1::] - xval[0:-1]
# values are >0 when x is increasingxval_delta = xval[1::] - xval[0:-1]
# the last value falls of now, but it should be the same as the
# previous value (n-1)
xval_sel = xval_delta.__ge__(0)
p1_x = xval[np.append(xval_sel, xval_sel[-1])]
p1_y = yval[np.append(xval_sel, xval_sel[-1])]
# values are <=0 when decreasing, and switch the array order to get
# increasing steps on the x axis
xval_sel = xval_delta.__lt__(0)
p2_x = xval[np.append(xval_sel, xval_sel[-1])][::-1]
p2_y = yval[np.append(xval_sel, xval_sel[-1])][::-1]
# split in upper and lower surface
if p1_y.mean() < 0:
# now close the circle by adding the first point of the lower
# in front of the upper surface. Note that continuity has to
# be preserved!
# By doing so, both upper and lower surface start at the same
# point at the leading edge!
p2_x = np.append(p1_x[0], p2_x)
p2_y = np.append(p1_y[0], p2_y)
coord_low = np.array([p1_x, p1_y]).transpose()
coord_up = np.array([p2_x, p2_y]).transpose()
else:
# now close the circle by adding the first point of the lower
# in front of the upper surface. Note that continuity has to
# be preserved!
p1_x = np.append(p2_x[0], p1_x)
p1_y = np.append(p2_y[0], p1_y)
coord_low = np.array([p2_x, p2_y]).transpose()
coord_up = np.array([p1_x, p1_y]).transpose()
# alternative, where all is in one coord array
# xval_mod = np.append(p1_x, p2_x)
# yval_mod = np.append(p1_y, p2_y)
# coord_mod = np.array([xval_mod, yval_mod]).transpose()
# if applicable, increase resolution.
if res < 2*len(coord_up) and type(method).__name__ == 'str':
raise ValueError, 'res needs to be at least 2x len(coord1_up)'
if method in ['cubic', 'linear', 'nearest']:
# convert to float128, to be sure not to lose anything when
# interpolating to a very high resolution grid
coord_up = np.array(coord_up, dtype=np.float128)
coord_low = np.array(coord_low, dtype=np.float128)
# the first point is close to but not exactly 0
# both up and lower surface share the beginning point
xval_hr = np.linspace(coord_up[0,0],np.float128(1),res)
# upper surface
xval = coord_up[:,0].__copy__()
yval = coord_up[:,1].__copy__()
coord_up = scipy.zeros((len(xval_hr),2), dtype=np.float128)
# make first xval a tiny bit smaller than xval_hr so it will
# include the first point
coord_up[:,1] = scipy.interpolate.griddata(xval, yval, xval_hr,
method=method)
coord_up[:,0] = xval_hr
# lower surface
xval = coord_low[:,0].__copy__()
yval = coord_low[:,1].__copy__()
coord_low = scipy.zeros((len(xval_hr),2), dtype=np.float128)
coord_low[:,1] = scipy.interpolate.griddata(xval, yval, xval_hr,
method=method)
coord_low[:,0] = xval_hr
# check if the two series realy are continuous data sets:
# delta = n - n_-1: all should be possitive for increasing x
x_delta_up = coord_up[1::,0] - coord_up[0:-1,0]
if not x_delta_up.__gt__(0).all():
raise UserWarning, 'upper coord: only increasing x allowed'
x_delta_low = coord_low[1::,0] - coord_low[0:-1,0]
if not x_delta_low.__gt__(0).all():
raise UserWarning, 'lower coord: only increasing x allowed'
# make sure the interpolation didn't created any nan's
if not np.all(np.isfinite(coord_up)):
raise UserWarning, 'found nan\'s in coord_up, check interpolation'
if not np.all(np.isfinite(coord_low)):
raise UserWarning, 'found nan\'s in coord_low, check interpolation'
return coord_up, coord_low
# TODO: implement the list of float on t_new
def interp_airfoils(coord1, t1, coord2, t2, t_new, res=100000, verplot=False,
verbose=False):
"""
Interpolate two airfoils with respect to thickness
==================================================
Weight two different airfoils with respect to their max thickness.
Parameters
----------
coord1 : ndarray(n,2)
Array holding the x/c and y/c coordinates respectivaly.
t1 : float
coord2 : ndarray(n,2)
Array holding the x/c and y/c coordinates respectivaly.
t2 : float
t_new : list of floats
Desired thickness for the new airfoil. This value should always
lay in between the thickness of airfoil1 and airfoil2.
Necessary condition for t_new: t1 > t_new > t2 (root-mid-tip).
For each list entry a new weighted airfoil will be created.
res : int, default=100000
Integer specifying how many x/c points should be maintained for
the higher resultion coord array. Value ignored when method=None.
Note that a leading edge usually already has a high resolution
hence the relative high default resultion.
"""
# TODO: also allow array input, so you could interpollate any airfoil
# not in the database as well
# data check: t_new has to be inbetween t1 and t2!
if not t_new <= t1 or not t_new >= t2:
raise ValueError, 'wrong size for t_new: t1 > t_new > t2'
# coord_continuous will split up in 2 continuous functions, one
# for lower and one for upper surface. Next it will interpolate
# the grid to a uni-spaced high resolution grid
coord1_up, coord1_low = coord_continuous(coord1, method='linear', res=res)
coord2_up, coord2_low = coord_continuous(coord2, method='linear', res=res)
# and now interpolate with respect to thickness, meaning for each
# x/c point we have a pair of (t1,y1) and (t2,y2) -> (t_new,y_new)
# t is the xvalue, y/c is the yvalue for a given x/c position
# TODO:
# for tt in t_new:
# save coordinates as an array in root.coord and make a note
# in root.coord.coord_tbl
# airfoil name: airfoil1_frac1_airfoil2_frac2
# or simply do that by weighting
frac1 = 1.-((t1-t_new) / (t1-t2))
frac2 = 1.-((t_new-t2) / (t1-t2))
if verbose:
print 't1 :', t1
print 't_new:', t_new
print 't2 :', t2
print 'frac1:', frac1, 'frac1:', frac2
# both airfoil1 and airfoil2 have the same number of points,
# since coord_continuous will take create an equal grid for both
# x/c grid remains the same (non dimensional chord!)
coord_new_up = coord2_up.__copy__()
coord_new_low = coord2_low.__copy__()
# and weight y/c accorindg to relative thickness
coord_new_up[:,1] = frac1*coord1_up[:,1] + frac2*coord2_up[:,1]
coord_new_low[:,1]= frac1*coord1_low[:,1] + frac2*coord2_low[:,1]
# check that coord2 and coord2_int are similar
if verplot:
plt.figure(1)
# airfoil 1
plt.plot(coord1[:,0], coord1[:,1], 'co', label='c1')
plt.plot(coord1_up[:,0], coord1_up[:,1], 'c--', label='c1 up')
plt.plot(coord1_low[:,0], coord1_low[:,1], 'b--', label='c1 low')
# arfoil 2
plt.plot(coord2[:,0], coord2[:,1], 'ro', label='c2')
plt.plot(coord2_up[:,0], coord2_up[:,1], 'r--', label='c2 up')
plt.plot(coord2_low[:,0], coord2_low[:,1], 'k--', label='c2 low')
# interpolated airfoil
plt.plot(coord_new_up[:,0], coord_new_up[:,1],'g-',label='c3 up')
plt.plot(coord_new_low[:,0],coord_new_low[:,1],'m-',label='c3 low')
plt.legend()
plt.show()
return coord_new_up, coord_new_low
def cross_prop(coord_up, coord_low, tests=False, verplot=False):
"""
Cross sectional airfoil properties
==================================
Calculate the properties of the 2D airfoil cross section. Assume it
is a full enclosed 2D shape. Following properties are supported:
* Ixx and Iyy wrt neutral bending axis
* location of centroid (neutral axis coordinates) wrt to LE
* cross sectional area
The upper and lower coordinates should have the same x coordinates,
as given by coord_continuous() and interp_airfoils().
This method is a piecewise linear integration method that also
calculates the second moment of inertia wrt the neutral x and y axis.
Note that for the mass moment of inertia we have: Im_xx = Ixx*rho
Parameters
----------
coord_up : ndarray(n,2)
Upper surface coordinates of the airfoil, moving from LE to TE
coord_low : ndarray(n,2)
Lower surface coordinates of the airfoil, moving from LE to TE
tests : boolean, default=False
Returns
-------
A
x_na
y_na
Ixx
Iyy
"""
# TODO: data checks
# continuity: does it? I think it can deal with any curvature
# better and seperate tests and result verification
# make sure the grids for both upper and lower surface are the same
if not np.allclose(coord_up[:,0], coord_low[:,0]):
msg = 'coord_up and low need to be defined on the same grid'
raise ValueError, msg
# TODO: if not, interpolate and fix it on equal x grids
# NUMERICAL APPROACH: split up into blocks. Since we already
# interpolated the coordinates to a high res grid, this approach
# should be sound. The upper block is a triangle, lower is just a
# rectangle (see drawings)
# even though they are identical, put in one array to have the
# correct summation over all the elements of upper and lower curve
x = np.ndarray((len(coord_up),2), dtype=np.float128)
x[:,0] = coord_up[:,0]
x[:,1] = coord_low[:,0]
x1 = x[:-1,:]
# for convience, put both y's in one array: [x, up, low]
y = np.ndarray((len(coord_up),2), dtype=np.float128)
y[:,0] = coord_up[:,1]
y[:,1] = coord_low[:,1]
# y1, first y value of each element
y1 = y[:-1,:]
# delta's define each element
dx = np.diff(x, axis=0)
dy = np.diff(y, axis=0)
# we have the top triangle (A) and the bottom rectangle (B)
# This approach goes right automatically. When dy<0, B is too big
# (because y1 > y2) and dA_a gets negative. Other way around for lower
# surface. Note that we need to be consistent in this approach all
# the way through
dA_a = dx * dy * 0.5
dA_b = y1 * dx
# reverse sign for lower surface area's, they are negative if under
# the y axis=0
dA_a[:,1] *= -1.
dA_b[:,1] *= -1.
# total area is then
A = np.sum(dA_a + dA_b)
# cg positions for each block with respect to (x,y)=(0,0)
# upper and lower share the same x_cg positions
x_cg_b = x1 + (dx*0.5)
y_cg_b = y1*0.5
# inclined side is directed towards y axis, so 2x/3 instead of x/3.
x_cg_a = (2.*dx/3.) + x1
# when on the lower side this reverses, but since then y1 > y2,
# and y1 + dy/3 becomes y2 + 2*dy/3. Check the figures for better
# and more correct understanding/description of why it goes right.
y_cg_a = (dy/3.) + y1
# find the neutral axis wrt (0,0)
x_na = np.sum( (dA_a*x_cg_a) + (dA_b*x_cg_b) ) /A
y_na = np.sum( (dA_a*y_cg_a) + (dA_b*y_cg_b) ) /A
# Moments of inertia for each piece around local cg
# since dy can switch sign, only consider absolute value
Ixx_cg_a = np.abs(dx*dy*dy*dy/36.)
Iyy_cg_a = np.abs(dx*dx*dx*dy/36.)
Ixx_cg_b = np.abs(dx*y1*y1*y1/12.)
Iyy_cg_b = np.abs(dx*dx*dx*y1/12.)
# the Steiner terms: distance local cg to neutral axis
Ixx_steiner_a = dA_a*(y_na-y_cg_a)*(y_na-y_cg_a)
Ixx_steiner_b = dA_b*(y_na-y_cg_b)*(y_na-y_cg_b)
Iyy_steiner_a = dA_a*(x_na-x_cg_a)*(x_na-x_cg_a)
Iyy_steiner_b = dA_b*(x_na-x_cg_b)*(x_na-x_cg_b)
# and finally the moments of inertia with respect to the neutral axis
Ixx = np.sum(Ixx_cg_a + Ixx_steiner_a + Ixx_cg_b + Ixx_steiner_b)
Iyy = np.sum(Iyy_cg_a + Iyy_steiner_a + Iyy_cg_b + Iyy_steiner_b)
if tests:
# ANALYTICAL APPROACH
# find enclosed airfoil area, integrate two curves
# Since we have a closed curve, negative y/c values for the upper
# side will result be corrected by the exact same amount of area
# surplus on the lower side
area_up = integrate.trapz(coord_up[:,1], x=x[:,0])
area_low = integrate.trapz(coord_low[:,1], x=x[:,0])
area = abs(area_up) + abs(area_low)
# area moments, moment of inertia
# wrt to neutral line, see also:
# Area and Bending Inertia of Airfoil Sections in Library
cc_up = np.array(coord_up[:,1])
cc_low = np.array(coord_low[:,1])
# for convenience, make shorter notation for the squared coord.
yyu = cc_up*cc_up
yyl = cc_low*cc_low
# neutral bending line
neutral = (0.5/area)*integrate.trapz(yyu-yyl, x=x[:,0])
# moment of inertia with respect to neutral line
term = np.power(cc_up-neutral,3) - np.power(cc_low-neutral,3)
Ixx_anal = (1./3.)*integrate.trapz(term, x=x[:,0])
# Ixx upper analytical
term = np.power(cc_up-neutral,3)
Ixx_up_anal = (1./3.)*integrate.trapz(term, x=x[:,0])
# Ixx numerical upper only
Ixx_up = np.sum( Ixx_cg_a[:,0] + Ixx_steiner_a[:,0] \
+ Ixx_cg_b[:,0] + Ixx_steiner_b[:,0])
# only upper side
A_up = np.sum(dA_a[:,0] + dA_b[:,0])
y_na_up = np.sum( (dA_a[:,0]*y_cg_a[:,0]) \
+ (dA_b[:,0]*y_cg_b[:,0]) )/A_up
y_na_up_anal = (0.5/area_up)*integrate.trapz(yyu, x=x[:,0])
print 'Comparing analytical and numerical approaches'
print ' area:', np.allclose(area, A)
print ' y_na:', np.allclose(neutral, y_na)
print ' A_up:', np.allclose(area_up, A_up)
print 'y_na_up:', np.allclose(y_na_up, y_na_up_anal)
print ' Ixx:', np.allclose(Ixx, Ixx_anal)
print Ixx
print Ixx_anal
print (1-(Ixx/Ixx_anal))
print ' Ixx_up:', np.allclose(Ixx_up, Ixx_up_anal)
print format(Ixx_up, '2.15f')
print format(Ixx_up_anal, '2.15f')
print (1-(Ixx_up/Ixx_up_anal))
# check that coord2 and coord2_int are similar
if verplot:
plt.figure(1)
# airfoil
plt.plot(x[:,0], y[:,0], 'c--', label='up')
plt.plot(x[:,0], y[:,1], 'b--', label='low')
# x_na
plt.hlines(y_na,0,1, label='y_na', colors='r')
plt.vlines(x_na,y.min(),y.max(), label='x_na', colors='k')
plt.grid(True)
plt.legend()
plt.show()
plt.figure(2)
plt.plot(y_cg_a[:,0], label='y_cg_a up')
plt.plot(y_cg_a[:,1], label='y_cg_a low')
plt.plot(y_cg_b[:,0], label='y_cg_b up')
plt.plot(y_cg_b[:,1], label='y_cg_b low')
plt.hlines(y_na,0,len(y_cg_a))
plt.legend()
plt.show()
plt.figure(3)
plt.plot(x_cg_a, label='x_cg_a')
plt.plot(x_cg_b, label='x_cg_b')
plt.legend()
plt.show()
return A, x_na, y_na, Ixx, Iyy
def S823_coordinates():
"""return coordinates and max t/c
"""
return np.loadtxt('data/model/S823.dat', skiprows=1), 21.0
def S822_coordinates():
"""return coordinates and max t/c
"""
return np.loadtxt('data/model/S822.dat', skiprows=1), 16.0
class Blade:
"""
Create a Blade based on airfoil coordinates
===========================================
"""
def __init__(self, **kwargs):
"""
"""
self.figpath = kwargs.get('figpath', '')
self.plot = kwargs.get('plot', False)
# one inch expressed in centimeters
self.oneinch = 2.54
self.units = 'SI'
def scale_figure(self, xlim, ylim):
"""
Set figure size so that when printing 1cm = 1cm
This should be a very generic plotting method/class.
By default it is assumed that the units for xlim, ylim are in cm!
"""
if self.units is not 'SI':
raise UserWarning, 'unsupported units for scaling plot'
# unit: inches. 1 inch = 2.54 cm
# define the length based on the limits
xlength = xlim[1] - xlim[0]
ylength = ylim[1] - ylim[0]
# scale the figure size accordingly
if self.units == 'SI':
figsize_x = xlength/self.oneinch
figsize_y = ylength/self.oneinch
return figsize_x, figsize_y
def _plot_cross_section(self, section_nr, **kwargs):
"""
Plot Airfoil cross section
==========================
Generate a plot of the given airofil coordinates.
"""
points = kwargs.get('points', False)
if points:
pointsx = points[0]
pointsy = points[1]
fontsize = kwargs.get('fontsize', 'medium')
figsize_x = kwargs.get('figsize_x', 6)
figsize_y = kwargs.get('figsize_y', 4)
title = kwargs.get('title', '')
dpi = kwargs.get('dpi', 200)
# wsleft = kwargs.get('wsleft', 0.15)
# wsbottom = kwargs.get('wsbottom', 0.15)
# wsright = kwargs.get('wsright', 0.95)
# wstop = kwargs.get('wstop', 0.90)
# wspace = kwargs.get('wspace', 0.2)
# hspace = kwargs.get('hspace', 0.2)
wsleft = kwargs.get('wsleft', 0.0)
wsbottom = kwargs.get('wsbottom', 0.0)
wsright = kwargs.get('wsright', 1.0)
wstop = kwargs.get('wstop', 1.0)
wspace = kwargs.get('wspace', 0.0)
hspace = kwargs.get('hspace', 0.0)
textbox = kwargs.get('textbox', None)
xlabel = kwargs.get('xlabel', 'x [m]')
ylabel = kwargs.get('ylabel', 'y [m]')
# for half chord coordinates
xlim = kwargs.get('xlim', [-0.07, 0.06])
ylim = kwargs.get('ylim', [-0.025, 0.020])
# for the LE coordinates
xlim = kwargs.get('xlim', [-0.01, 0.12])
ylim = kwargs.get('ylim', [-0.025, 0.020])
# scale the image
xlength = (xlim[1] - xlim[0])*100.
ylength = (ylim[1] - ylim[0])*100.
figsize_x = xlength/self.oneinch
figsize_y = ylength/self.oneinch
figpath = kwargs.get('figpath', self.figpath)
fig = Figure(figsize=(figsize_x, figsize_y), dpi=dpi)
canvas = FigCanvas(fig)
fig.set_canvas(canvas)
mpl.rc('font',**{'family':'lmodern','serif':['Computer Modern'], \
'monospace': ['Computer Modern Typewriter']})
mpl.rc('text', usetex=True)
mpl.rcParams['font.size'] = 11
# add_subplot(nr rows nr cols plot_number)
ax1 = fig.add_subplot(111)
# original linewidth was set to 0.3
ax1.plot(self.coord_up[:,0], self.coord_up[:,1],
'k-', label='upper', linewidth=1.1)
ax1.plot(self.coord_low[:,0], self.coord_low[:,1],
'k-', label='lower', linewidth=1.1)
# insert the plate
# plate[point on plate, coordinate(x,y)]
ax1.plot(self.plate[:,0], self.plate[:,1], 'k-', linewidth=1.1)
fig.subplots_adjust(left=wsleft, bottom=wsbottom, right=wsright,
top=wstop, wspace=wspace, hspace=hspace)
# set the textboxres=None
textbox = 't/c=' + format(self.tc, '1.02f') + '\%'
textbox += ' r=' + format(self.r*1000, '1.0f') +'mm'
textbox += ' c=' + format(self.chord*1000, '1.0f') +'mm'
if textbox:
xpos = xlim[0] + ((xlim[1]-xlim[0])/3.)
ypos = ylim[0]
ax1.text(xpos, ypos, textbox, fontsize=12, va='bottom',
bbox = dict(boxstyle="round",
ec=(1., 0.5, 0.5), fc=(1., 0.8, 0.8),))
# textbox with the number of stations
numberbox = str(section_nr+1)
ax1.text(xlim[0], ylim[0], numberbox, fontsize=12, va='bottom',
bbox = dict(boxstyle="round",
ec=(1., 0.5, 0.5), fc=(1., 0.8, 0.8),))
# plot the neutral axes
# this should be plotting line, otherwise it not rotated as the
# rest of the coordinates
#if x_na:
#ax1.axvline(x=x_na,linewidth=1,color='k',linestyle='-',aa=False)
#if y_na:
#ax1.axhline(y=y_na,linewidth=1,color='k',linestyle='-',aa=False)
# plot the indicated points as well
if points:
ax1.plot(pointsx[0], pointsy[0], 'ro') # strain gauge pos
ax1.plot(pointsx[1], pointsy[1], 'rs') # cg
ax1.plot(pointsx[2], pointsy[2], 'r^') # na
ax1.plot(0, 0, 'kd') # half chord point
ax1.set_xlabel(xlabel, size=fontsize)
ax1.set_ylabel(ylabel, size=fontsize)
title = self.airfoil1 + ' - ' + self.airfoil2
title += ' t/c=' + format(self.tc, '1.02f') + '\%'
ax1.set_title(title)
ax1.xaxis.set_ticks( np.arange(xlim[0], xlim[1], 0.005).tolist() )
ax1.yaxis.set_ticks( np.arange(ylim[0], ylim[1], 0.005).tolist() )
ax1.set_xlim(xlim)
ax1.set_ylim(ylim)
ax1.grid(True)
figpath += self.airfoil1 + '-' + self.airfoil2
figpath += '_' + format(section_nr+1, '02.0f')
figpath += '_tc_' + format(self.tc, '1.03f')
figpath += '_c_' + format(self.chord, '1.03f')
figpath += '_r_' + format(self.r, '1.03f')
# filter out the dots in the file name, LaTeX doesn't like them
figpath = figpath.replace('.', '')
print 'saving: ' + figpath
fig.savefig(figpath + '.png')
fig.savefig(figpath + '.eps')
# fig.savefig(figpath + '.jpg')
# fig.savefig(figpath + '.svg')
# canvas.close()
fig.clear()
# save as text file
tmp = np.append(self.coord_up, self.coord_low[::-1], axis=0)
np.savetxt(figpath+'.txt', tmp)
tmp = np.append(self.coord_up_nodim[::-1], self.coord_low_nodim, axis=0)
np.savetxt(figpath+'_nodim.txt', tmp)
# ax1.plot(self.coord_up[:,0], self.coord_up[:,1],
# 'k-', label='upper', linewidth=1.1)
# ax1.plot(self.coord_low[:,0], self.coord_low[:,1],
# 'k-', label='lower', linewidth=1.1)
def build(self, blade, airfoils, res=None, step=None, plate=False,
tw1_t=0, tw2_t=0, st_arr_tw=None, res_chord=100000):
"""
Create a blade
==============
Create a blade based on radius, chord, t/c and twist distributions,
and combined with a list of airfoil names (from the database).
Additionally, cross-sectional paramters are calculated for the full
2D airfoil sections.
Parameters
----------
blade : array
blade[radius, chord, t/c, twist]
airfoils : list
[airfoil1 name, coord1, t1, airfoil2 name, coord2, t2]
res : int, default=None
If set, the blade input data will be interpolated to a linspace
with res number of steps. For accurate volume integration results,
the OJF example with 18 stations showed to be sufficient.
Higher resolutions are not required.
step : float, default=None
Optionaly interpolate blade input data with np.arange using
step.
plate : boolean, default=False
If set to True, the glass fibre sandwich will be included
tw1_t : float, default=0
Thickness of the thin walled structural part
tw1_t : float, default=0
Thickness of the thin walled structural part
res_chord : int, default=100000
Integer specifying how many x/c points should be maintained for
the higher resultion coord array. Value ignored when method=None.
Note that a leading edge usually already has a high resolution
hence the relative high default resultion.
Returns
-------
blade_hr : ndarray(n, 4)
radial stations, [radius, chord, t/c, twist]
volume : float
area : ndarray(n)
cross sectional area per section
x_na : ndarray(n)
Location of the neutral axis for the full airfoil wrt half chord
point.
y_na : ndarray(n)
Location of the neutral axis for the full airfoil wrt half chord
point.
Ixx : ndarray(n)
Moment of inertia wrt neutral axis for the full airfoil section
Iyy : ndarray(n)
Moment of inertia wrt neutral axis for the full airfoil section
st_arr : ndarray(n,19)
strainpos : ndarray(n,3)
Position of the strain gauges (r,x,y) expressed in half chord
coordinates and where r refers to the radial position along the
blade
"""
plate_twist = 0
# should the blade have a high res for better volume estimate?
# for res=1000 : 0.000838272318841
# for res= 100 : 0.000838306414751
# for res=None : 0.000838681278719
# NO NEED TO INTERPOLATE TO HIGH RES
if res is None and step is None:
blade_hr = blade
hr = blade_hr[:,0]
elif step is None:
hr = np.linspace(blade[0,0],blade[-1,0],res)
blade_hr = scipy.zeros((len(hr),4))
blade_hr[:,0]= hr
blade_hr[:,1]= scipy.interpolate.griddata(blade[:,0],blade[:,1],hr)
blade_hr[:,2]= scipy.interpolate.griddata(blade[:,0],blade[:,2],hr)
blade_hr[:,3]= scipy.interpolate.griddata(blade[:,0],blade[:,3],hr)
else:
# step distribution
hr = np.arange(blade[0,0],blade[-1,0],step)
# and add the tip position
hr = np.append(hr, blade[-1,0])
blade_hr = scipy.zeros((len(hr),4))
blade_hr[:,0]= hr
blade_hr[:,1]= scipy.interpolate.griddata(blade[:,0],blade[:,1],hr)
blade_hr[:,2]= scipy.interpolate.griddata(blade[:,0],blade[:,2],hr)
blade_hr[:,3]= scipy.interpolate.griddata(blade[:,0],blade[:,3],hr)
# TODO: move how the plate is made to another method!!
# The plate is expressed in LE (0,0) coordinates
if plate:
# and corresponding plate:
plate_chord = np.linspace(3.5e-2, 1.5e-2, len(hr))
plate_t_height = np.linspace(1.0e-2, 0.2e-2, len(hr))
plate_t_width = np.linspace(2.5e-2, 0.5e-2, len(hr))
# define the plates position
plate_twist = -10*np.pi/180.
plate_x0 = 0.0059
plate_y0 = 0.0015
# 6 points on the plate are
# 2----3
# | |
# 0-----1 4-----5
# 6----------------5
# plate[radial station, point on plate, coordinate(x,y)]
plate_blade = scipy.zeros((len(hr),7,2))
# x positions of first points
plate_blade[:,0,0] = plate_x0
plate_blade[:,0,1] = plate_y0
plate_blade[:,1,0] = plate_x0 + plate_chord/2. - plate_t_width/2.
plate_blade[:,1,1] = plate_y0
plate_blade[:,2,0] = plate_x0 + plate_chord/2. - plate_t_width/2.
plate_blade[:,2,1] = plate_y0 - plate_t_height
plate_blade[:,3,0] = plate_x0 + plate_chord/2. + plate_t_width/2.
plate_blade[:,3,1] = plate_y0 - plate_t_height
plate_blade[:,4,0] = plate_x0 + plate_chord/2. + plate_t_width/2.
plate_blade[:,4,1] = plate_y0
plate_blade[:,5,0] = plate_x0 + plate_chord
plate_blade[:,5,1] = plate_y0
# and back to zero, close the section
plate_blade[:,6,0] = plate_x0
plate_blade[:,6,1] = plate_y0
# structural data for the thin walled section interpollated to hr
if type(st_arr_tw).__name__ is 'ndarray':
st_hr = scipy.interpolate.griddata(st_arr_tw[:,0], st_arr_tw, hr)
else:
st_hr = False
area = scipy.zeros(len(blade_hr), dtype=np.float128)
x_na = scipy.zeros(len(blade_hr), dtype=np.float128)
y_na = scipy.zeros(len(blade_hr), dtype=np.float128)
Ixx = scipy.zeros(len(blade_hr), dtype=np.float128)
Iyy = scipy.zeros(len(blade_hr), dtype=np.float128)
st_arr = scipy.zeros((len(blade_hr),19), dtype=np.float128)
strainpos = scipy.zeros((len(blade_hr),3), dtype=np.float128)
# calculate the volume at each blade radial station
for k in range(len(blade_hr)):
self.r = blade_hr[k,0]
self.tc = blade_hr[k,2]
twist = blade_hr[k,3]*np.pi/180. + plate_twist
chord = blade_hr[k,1]
coord1, t1, = airfoils[1], airfoils[2]
coord2, t2, = airfoils[4], airfoils[5]
coord_up, coord_low = interp_airfoils(coord1, t1, coord2, t2,
self.tc, res=res_chord)
self.coord_up_nodim, self.coord_low_nodim = coord_up, coord_low
self.airfoil1 = airfoils[0]
self.airfoil2 = airfoils[3]
# dimensionalize: multiply with chord length
self.coord_up, self.coord_low = coord_up*chord, coord_low*chord
self.chord = chord
# we need a different grid for the thin walled concept of
# crosssection.properties: tw[x,y,t]
# 2----3
# | |
# 0-----1 4-----5
# 6----------------5
# plate for plotting format, set to zero for no plotting
self.plate = scipy.zeros((7,2))
if plate:
tw1 = np.ndarray((6,3))
# beam x coordinates of the section
tw1[:,0] = plate_blade[k,:6,0]
# beam y coordinates of the section
tw1[:,1] = plate_blade[k,:6,1]
# and the thickness for each element is
tw1[:,2] = tw1_t
# and number two is from point 0 to point 5
# scipy.interpolate.griddata(points, values, high_res_points)
tw2 = np.ndarray(tw1.shape)
# beam x coordinates of the section
xtmp = np.linspace(plate_blade[k,0,0], plate_blade[k,5,0], 6)
tw2[:,0] = xtmp
# beam y coordinates of the section
tw2[:,1] = scipy.interp(xtmp, plate_blade[k,[0,5],0],
plate_blade[k,[0,5],1])
# and the thickness for each element is
tw2[:,2] = tw2_t
# put in the plotting format
self.plate[:,0] = plate_blade[k,:,0]
self.plate[:,1] = plate_blade[k,:,1]
else:
tw1 = scipy.zeros((4,3))
tw2 = scipy.zeros((4,3))
# cross sectional area properties
area[k], x_na[k], y_na[k], Ixx[k], Iyy[k] \
= cross_prop(self.coord_up, self.coord_low)
# the other cross sectional analysis
E = materials.Materials().cores['PVC_H200'][1]
rho = materials.Materials().cores['PVC_H200'][15]
st_arr[k,:],EA,EIxx, EIyy = crosprop(self.coord_up, self.coord_low,
tw1=tw1, tw2=tw2, rho=rho, E=E, st_arr_tw=st_hr)
# put the correct radial position in the st_arr because that is
# not set in the crosssection.properties method
st_arr[k,sti.r] = self.r
# express x_na and y_na wrt half chord point
# chord length is determined by knowing the TE and LE coordinates
# LE should be (0,0), but take into account just to be sure
x = self.coord_up[-1,0] - self.coord_up[0,0]
y = self.coord_up[-1,1] - self.coord_up[0,1]
chordlen = math.sqrt(x*x + y*y)
c2 = chordlen/2.
cos_a = x/chordlen
sin_a = y/chordlen
x_c2 = cos_a*c2
y_c2 = sin_a*c2
# and convert to half chord point coordinates
# in the original format, the chord line is already horizontal
# no need to apply any transformation
#theta = math.acos(cos_a)
#x_na[k] = x_c2*math.cos(theta) - y_c2*math.sin(theta)
#y_na[k] = x_c2*math.sin(theta) + y_c2*math.cos(theta)
# the translation of the coordinate system to half chord
x_na[k] = x_c2 - x_na[k]
y_na[k] = y_c2 + y_na[k]
# -----------------------------------------------------------------
# determine coordinates of the strain gauges, wrt c/2 point
if plate:
strain_x = x_c2 - plate_blade[k,2:4,0].mean()
strain_y = y_c2 + plate_blade[k,2,1]
else:
strain_x, strain_y = 0, 0
# remember, HAWC2 is half chord points as reference,
# the plot uses LE as reference point
xcgi = sim.ModelData.st_headers.x_cg
xnai = sim.ModelData.st_headers.x_e
ycgi = sim.ModelData.st_headers.y_cg
ynai = sim.ModelData.st_headers.y_e
# -----------------------------------------------------------------
# rotate with the twist angle
# plot the current cross section
if self.plot:
# -------------------------------------------------------------
# plot in half chord coordinates to have better check
# # put the three points as follows: [strain, CG, NA]
# # now all points are in half chord points
# pointsx = np.array([strain_x, st_arr[k,xcgi], st_arr[k,xnai]])
# pointsy = np.array([strain_y, st_arr[k,ycgi], st_arr[k,ynai]])
# # the airfoil coordinates
# self.coord_up[:,0] = x_c2 - self.coord_up[:,0]
# self.coord_low[:,0] = x_c2 - self.coord_low[:,0]
# self.coord_up[:,1] += y_c2
# self.coord_low[:,1] += y_c2
# # now we rotate the plate instead of the airfoil
# x, y = self.plate[:,0], self.plate[:,1]
# self.plate[:,0], self.plate[:,1] \
# = self._tohalfchord(x, y, -twist, x_c2, y_c2)
# # the strain gauge position now also needs to be rotated
# pointsx[0], pointsy[0] = self._rotate(pointsx[0], pointsy[0],
# -twist)
# # and plot
# self._plot_cross_section(k, points=[pointsx, pointsy],
# xlim=[-0.07, 0.06],
# ylim=[-0.025, 0.020])
#
# # for later reference, save in half chord points
# strainpos[k,:] = [self.r, pointsx[0], pointsy[0]]
# -------------------------------------------------------------
# plotting in LE coordinates was done for easy drafting the
# put the three points as follows: [strain, CG, NA]
# now already all is in half chord points
pointsx = np.array([strain_x, st_arr[k,xcgi], st_arr[k,xnai]])
pointsy = np.array([strain_y, st_arr[k,ycgi], st_arr[k,ynai]])
# for later reference, save in half chord points