4
4
import bladex .profiles as pr
5
5
import bladex .blade as bl
6
6
from bladex import NacaProfile , Shaft , Propeller
7
+ from smithers .io .obj import ObjHandler
8
+ from smithers .io .stlhandler import STLHandler
7
9
8
10
9
11
def create_sample_blade_NACApptc ():
10
12
sections = np .asarray ([NacaProfile ('5407' ) for i in range (13 )])
11
- radii = np .array ([0.034375 , 0.0375 , 0.04375 , 0.05 , 0.0625 , 0.075 , 0.0875 ,
13
+ radii = np .array ([0.034375 , 0.0375 , 0.04375 , 0.05 , 0.0625 , 0.075 , 0.0875 ,
12
14
0.1 , 0.10625 , 0.1125 , 0.11875 , 0.121875 , 0.125 ])
13
- chord_lengths = np .array ([0.039 , 0.045 , 0.05625 , 0.06542 , 0.08125 ,
14
- 0.09417 , 0.10417 , 0.10708 , 0.10654 , 0.10417 ,
15
+ chord_lengths = np .array ([0.039 , 0.045 , 0.05625 , 0.06542 , 0.08125 ,
16
+ 0.09417 , 0.10417 , 0.10708 , 0.10654 , 0.10417 ,
15
17
0.09417 , 0.07867 , 0.025 ])
16
- pitch = np .array ([0.35 , 0.35 , 0.36375 , 0.37625 , 0.3945 , 0.405 , 0.40875 ,
18
+ pitch = np .array ([0.35 , 0.35 , 0.36375 , 0.37625 , 0.3945 , 0.405 , 0.40875 ,
17
19
0.4035 , 0.3955 , 0.38275 , 0.3645 , 0.35275 , 0.33875 ])
18
- rake = np .array ([0.0 ,0.0 , 0.0005 , 0.00125 , 0.00335 , 0.005875 , 0.0075 ,
20
+ rake = np .array ([0.0 ,0.0 , 0.0005 , 0.00125 , 0.00335 , 0.005875 , 0.0075 ,
19
21
0.007375 , 0.006625 , 0.00545 , 0.004033 , 0.0033 , 0.0025 ])
20
- skew_angles = np .array ([6.6262795 , 3.6262795 , - 1.188323 , - 4.4654502 ,
21
- - 7.440779 , - 7.3840979 , - 5.0367916 , - 1.3257914 ,
22
- 1.0856404 , 4.1448947 , 7.697235 , 9.5368917 ,
22
+ skew_angles = np .array ([6.6262795 , 3.6262795 , - 1.188323 , - 4.4654502 ,
23
+ - 7.440779 , - 7.3840979 , - 5.0367916 , - 1.3257914 ,
24
+ 1.0856404 , 4.1448947 , 7.697235 , 9.5368917 ,
23
25
11.397609 ])
24
26
return bl .Blade (
25
27
sections = sections ,
@@ -38,54 +40,54 @@ class TestPropeller(TestCase):
38
40
def test_sections_inheritance_NACApptc (self ):
39
41
prop = create_sample_blade_NACApptc ()
40
42
self .assertIsInstance (prop .sections [0 ], pr .NacaProfile )
41
-
43
+
42
44
def test_radii_NACApptc (self ):
43
45
prop = create_sample_blade_NACApptc ()
44
- np .testing .assert_equal (prop .radii , np .array ([0.034375 , 0.0375 , 0.04375 ,
45
- 0.05 , 0.0625 , 0.075 ,
46
- 0.0875 , 0.1 , 0.10625 ,
47
- 0.1125 , 0.11875 , 0.121875 ,
46
+ np .testing .assert_equal (prop .radii , np .array ([0.034375 , 0.0375 , 0.04375 ,
47
+ 0.05 , 0.0625 , 0.075 ,
48
+ 0.0875 , 0.1 , 0.10625 ,
49
+ 0.1125 , 0.11875 , 0.121875 ,
48
50
0.125 ]))
49
51
50
52
def test_chord_NACApptc (self ):
51
53
prop = create_sample_blade_NACApptc ()
52
- np .testing .assert_equal (prop .chord_lengths ,np .array ([0.039 , 0.045 ,
53
- 0.05625 , 0.06542 ,
54
- 0.08125 , 0.09417 ,
55
- 0.10417 , 0.10708 ,
56
- 0.10654 , 0.10417 ,
57
- 0.09417 , 0.07867 ,
54
+ np .testing .assert_equal (prop .chord_lengths ,np .array ([0.039 , 0.045 ,
55
+ 0.05625 , 0.06542 ,
56
+ 0.08125 , 0.09417 ,
57
+ 0.10417 , 0.10708 ,
58
+ 0.10654 , 0.10417 ,
59
+ 0.09417 , 0.07867 ,
58
60
0.025 ]))
59
61
60
62
def test_pitch_NACApptc (self ):
61
63
prop = create_sample_blade_NACApptc ()
62
- np .testing .assert_equal (prop .pitch , np .array ([0.35 , 0.35 , 0.36375 ,
63
- 0.37625 , 0.3945 , 0.405 ,
64
- 0.40875 , 0.4035 , 0.3955 ,
65
- 0.38275 , 0.3645 , 0.35275 ,
64
+ np .testing .assert_equal (prop .pitch , np .array ([0.35 , 0.35 , 0.36375 ,
65
+ 0.37625 , 0.3945 , 0.405 ,
66
+ 0.40875 , 0.4035 , 0.3955 ,
67
+ 0.38275 , 0.3645 , 0.35275 ,
66
68
0.33875 ]))
67
69
68
70
def test_rake_NACApptc (self ):
69
71
prop = create_sample_blade_NACApptc ()
70
- np .testing .assert_equal (prop .rake , np .array ([0.0 ,0.0 , 0.0005 , 0.00125 ,
71
- 0.00335 , 0.005875 , 0.0075 ,
72
- 0.007375 , 0.006625 , 0.00545 ,
72
+ np .testing .assert_equal (prop .rake , np .array ([0.0 ,0.0 , 0.0005 , 0.00125 ,
73
+ 0.00335 , 0.005875 , 0.0075 ,
74
+ 0.007375 , 0.006625 , 0.00545 ,
73
75
0.004033 , 0.0033 , 0.0025 ]))
74
76
75
77
def test_skew_NACApptc (self ):
76
78
prop = create_sample_blade_NACApptc ()
77
- np .testing .assert_equal (prop .skew_angles , np .array ([6.6262795 ,
78
- 3.6262795 ,
79
- - 1.188323 ,
80
- - 4.4654502 ,
81
- - 7.440779 ,
82
- - 7.3840979 ,
83
- - 5.0367916 ,
84
- - 1.3257914 ,
85
- 1.0856404 ,
86
- 4.1448947 ,
87
- 7.697235 ,
88
- 9.5368917 ,
79
+ np .testing .assert_equal (prop .skew_angles , np .array ([6.6262795 ,
80
+ 3.6262795 ,
81
+ - 1.188323 ,
82
+ - 4.4654502 ,
83
+ - 7.440779 ,
84
+ - 7.3840979 ,
85
+ - 5.0367916 ,
86
+ - 1.3257914 ,
87
+ 1.0856404 ,
88
+ 4.1448947 ,
89
+ 7.697235 ,
90
+ 9.5368917 ,
89
91
11.397609 ]))
90
92
91
93
def test_sections_array_different_length (self ):
@@ -156,5 +158,63 @@ def test_generate_stl(self):
156
158
self .assertTrue (os .path .isfile ('tests/test_datasets/propeller_and_shaft.stl' ))
157
159
self .addCleanup (os .remove , 'tests/test_datasets/propeller_and_shaft.stl' )
158
160
161
+ def test_generate_obj_by_coords (self ):
162
+ sh = Shaft ("tests/test_datasets/shaft.iges" )
163
+ prop = create_sample_blade_NACApptc ()
164
+ prop = Propeller (sh , prop , 4 )
165
+ prop .generate_obj ("tests/test_datasets/propeller_and_shaft.obj" , region_selector = 'by_coords' )
166
+
167
+ data = ObjHandler .read ('tests/test_datasets/propeller_and_shaft.obj' )
168
+ assert data .regions == ['propellerTip' ,'propellerStem' ]
169
+
170
+ # we want 0 to be the first index
171
+ data .polygons = np .asarray (data .polygons ) - 1
172
+
173
+ tip_poly = data .polygons [:data .regions_change_indexes [1 ][0 ]]
174
+ stem_poly = data .polygons [data .regions_change_indexes [1 ][0 ]:]
175
+
176
+ blades_stl = STLHandler .read ('/tmp/temp_blades.stl' )
177
+ shaft_stl = STLHandler .read ('/tmp/temp_shaft.stl' )
178
+
179
+ # same vertices
180
+ all_vertices = np .concatenate (
181
+ [shaft_stl ["points" ], blades_stl ["points" ]], axis = 0
182
+ )
183
+ unique_vertices = np .unique (all_vertices , axis = 0 )
184
+ np .testing .assert_almost_equal (data .vertices , unique_vertices , decimal = 3 )
185
+
186
+ blades_min_x = np .min (blades_stl ['points' ][:,0 ])
187
+
188
+ assert np .all (data .vertices [np .asarray (tip_poly ).flatten ()][:,0 ] >= blades_min_x )
189
+ assert not any (np .all (data .vertices [np .asarray (stem_poly ).flatten ()][:,0 ].reshape (- 1 ,data .polygons .shape [1 ]) >= blades_min_x , axis = 1 ))
190
+
191
+ def test_generate_obj_blades_and_stem (self ):
192
+ sh = Shaft ("tests/test_datasets/shaft.iges" )
193
+ prop = create_sample_blade_NACApptc ()
194
+ prop = Propeller (sh , prop , 4 )
195
+ prop .generate_obj ("tests/test_datasets/propeller_and_shaft.obj" , region_selector = 'blades_and_stem' )
196
+
197
+ data = ObjHandler .read ('tests/test_datasets/propeller_and_shaft.obj' )
198
+ assert data .regions == ['propellerTip' ,'propellerStem' ]
199
+
200
+ tip_polygons = np .asarray (data .polygons [:data .regions_change_indexes [1 ][0 ]]) - 1
201
+ stem_polygons = np .asarray (data .polygons [data .regions_change_indexes [1 ][0 ]:]) - 1
202
+
203
+ blades_stl = STLHandler .read ('/tmp/temp_blades.stl' )
204
+ shaft_stl = STLHandler .read ('/tmp/temp_shaft.stl' )
205
+
206
+ # same vertices
207
+ all_vertices = np .concatenate (
208
+ [shaft_stl ["points" ], blades_stl ["points" ]], axis = 0
209
+ )
210
+
211
+ unique_vertices , indexing = np .unique (
212
+ all_vertices , return_index = True , axis = 0
213
+ )
214
+ np .testing .assert_almost_equal (data .vertices , unique_vertices , decimal = 3 )
215
+
216
+ assert np .all (indexing [stem_polygons .flatten ()] < shaft_stl ['points' ].shape [0 ])
217
+ assert np .all (indexing [tip_polygons .flatten ()] >= shaft_stl ['points' ].shape [0 ])
218
+
159
219
def test_isdisplay (self ):
160
220
assert hasattr (Propeller , "display" ) == True
0 commit comments