Skip to content

Commit 905eb8f

Browse files
authored
Removing the display test from tests (#75)
* Removing the display test from tests * Removing the display test from test_propeller.py * Fixing test_blade.py and adding a test on the presence of the display method in test_shaft.py and test_propeller.py * Removing smesh from .travis.yml and the deprecated generate_stl_smesh method from blade.py with corresponding tests in test_blade.py
1 parent 2a76d72 commit 905eb8f

11 files changed

+24
-176
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ install:
5454
- echo $DYLD_LIBRARY_PATH
5555
- echo $PATH
5656
- python --version
57-
- conda install --yes -c conda-forge pythonocc-core=7.4.0 smesh numpy scipy matplotlib pip nose sip=4.18 setuptools coveralls python=3.7;
57+
- conda install --yes -c conda-forge pythonocc-core=7.4.0 numpy scipy matplotlib pip nose sip=4.18 setuptools coveralls python=3.7;
5858
- python setup.py install
5959

6060
script:

bladex/blade.py

+4-106
Original file line numberDiff line numberDiff line change
@@ -927,111 +927,6 @@ def generate_solid(self,
927927
result_solid = solid_maker.Solid()
928928
return result_solid
929929

930-
def generate_stl_smesh(self, min_length=None, max_length=None, outfile_stl=None):
931-
"""
932-
Generate and export the .STL surface mesh for the blade as a whole,
933-
including the upper face, lower face and tip. The method utilizes
934-
modules from OCC SMESH which is standalone mesh framework based on
935-
SALOME mesher project. Please refer to https://github.com/tpaviot
936-
and http://docs.salome-platform.org/7/gui/SMESH/index.html for
937-
further details.
938-
939-
This method requires PythonOCC and SMESH to be installed.
940-
941-
:param double min_length: smallest distance between two nodes. Default
942-
value is None
943-
:param double max_length: largest distance between two nodes. Default
944-
value is None
945-
:param string outfile_stl: if string is passed then the method exports
946-
the generated 2D surface mesh into .stl file holding the name
947-
<outfile_stl>.stl. Default value is None
948-
949-
We note that since the current implementation performs triangulation
950-
based on a topological compound that combines the blade 3 generated
951-
shapes without "fusion", it may happen that the generated triangulation
952-
of the upper and lower blade faces do not share the same exact nodes
953-
on the joint edge/wire resulting from the faces intersection. The
954-
current implementation can be enough for visualization purpose. However
955-
if the generated mesh is intended for computational analysis then a
956-
manual mesh healing is recommended by the user (e.g. see
957-
"Repair > Sewing" in SALOME GUI) for a proper mesh closure.
958-
"""
959-
from OCC.SMESH import SMESH_Gen
960-
from OCC.StdMeshers import (
961-
StdMeshers_Arithmetic1D, StdMeshers_TrianglePreference,
962-
StdMeshers_Regular_1D, StdMeshers_MEFISTO_2D)
963-
from OCC.Core.BRep import BRep_Builder
964-
from OCC.Core.TopoDS import TopoDS_Shape, TopoDS_Compound
965-
966-
if min_length <= 0 or max_length <= 0:
967-
raise ValueError('min_length and max_length must be positive.')
968-
if min_length >= max_length:
969-
raise ValueError('min_length can not be greater than max_length')
970-
971-
# First we check that blade shapes are generated, otherwise we generate
972-
# them. After that we combine the generated_upper_face,
973-
# generated_lower_face, and generated_tip into a topological compound
974-
# that we use to compute the surface mesh
975-
if (self.generated_upper_face is None) or not isinstance(
976-
self.generated_upper_face, TopoDS_Shape):
977-
# Upper face is generated with a maximal U degree = 1
978-
self._generate_upper_face(max_deg=1)
979-
if (self.generated_lower_face is None) or not isinstance(
980-
self.generated_lower_face, TopoDS_Shape):
981-
# Upper face is generated with a maximal U degree = 1
982-
self._generate_lower_face(max_deg=1)
983-
if (self.generated_tip is None) or not isinstance(
984-
self.generated_tip, TopoDS_Shape):
985-
# Upper face is generated with a maximal U degree = 1
986-
self._generate_tip(max_deg=1)
987-
988-
# Now we regroup all the shapes into a TopoDS_Compound
989-
aCompound = TopoDS_Compound()
990-
aBuilder = BRep_Builder()
991-
aBuilder.MakeCompound(aCompound)
992-
# Add shapes
993-
aBuilder.Add(aCompound, self.generated_upper_face)
994-
aBuilder.Add(aCompound, self.generated_lower_face)
995-
aBuilder.Add(aCompound, self.generated_tip)
996-
997-
# In the following we build the surface mesh according to the given
998-
# hypotheses
999-
aMeshGen = SMESH_Gen()
1000-
aMesh = aMeshGen.CreateMesh(0, True)
1001-
# Adding 1D hypothesis and algorithms
1002-
# Wire discretization. Nodes are distributed based on Arithmetic1D
1003-
# hypothesis which allows to split edges into segments with a length
1004-
# that changes in arithmetic progression (Lk = Lk-1 + d) beginning
1005-
# from a given min length and up to a given max length. More about
1006-
# 1D hypotheses can be viewed through:
1007-
# http://docs.salome-platform.org/7/gui/SMESH/a1d_meshing_hypo_page.html
1008-
an1DHypothesis = StdMeshers_Arithmetic1D(0, 0, aMeshGen)
1009-
# Smallest distance between 2 points
1010-
an1DHypothesis.SetLength(min_length, False)
1011-
# Longest distance between 2 points
1012-
an1DHypothesis.SetLength(max_length, True)
1013-
# Regular Interpolation
1014-
# Adding 2D hypothesis and algorithms
1015-
# 2D surface mesh -- Triangulations
1016-
1017-
#Calculate mesh for the topological compound containing the 3 shapes
1018-
aMesh.ShapeToMesh(aCompound)
1019-
1020-
#Assign hyptothesis to mesh
1021-
aMesh.AddHypothesis(aCompound, 0)
1022-
aMesh.AddHypothesis(aCompound, 1)
1023-
aMesh.AddHypothesis(aCompound, 2)
1024-
aMesh.AddHypothesis(aCompound, 3)
1025-
1026-
if outfile_stl is not None:
1027-
if not isinstance(outfile_stl, str):
1028-
raise ValueError('outfile_stl must be a valid string.')
1029-
1030-
#Compute the data
1031-
aMeshGen.Compute(aMesh, aMesh.GetShapeToMesh())
1032-
# Export STL
1033-
aMesh.ExportSTL(outfile_stl + '.stl', False)
1034-
1035930
def generate_stl(self, upper_face=None,
1036931
lower_face=None,
1037932
tip=None,
@@ -1079,6 +974,9 @@ def generate_stl(self, upper_face=None,
1079974
from OCC.Extend.DataExchange import write_stl_file
1080975
from OCC.Display.SimpleGui import init_display
1081976

977+
if max_deg <= 0:
978+
raise ValueError('max_deg argument must be a positive integer.')
979+
1082980
if upper_face:
1083981
self._check_string(filename=upper_face)
1084982
self._generate_upper_face(max_deg=max_deg)
@@ -1297,4 +1195,4 @@ def __str__(self):
12971195
' sections = {}'.format(self.pitch_angles)
12981196
string += '\nInduced rake from skew (in unit length)'\
12991197
' for the sections = {}'.format(self.induced_rake)
1300-
return string
1198+
return string

tests/test_blade.py

+13-55
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ def test_rotate_deg_section_0_xup(self):
353353
blade.apply_transformations()
354354
blade.rotate(deg_angle=90)
355355
rotated_coordinates = np.array([
356-
0.23913475, 0.20945559, 0.16609993, 0.11970761, 0.07154874,
357-
0.02221577, -0.02796314, -0.07881877, -0.13030229, -0.18246808
356+
0.2969784, 0.2653103, 0.2146533, 0.1597801, 0.1024542,
357+
0.0434981, -0.0166326, -0.0777027, -0.1396447, -0.202534
358358
])
359359
np.testing.assert_almost_equal(blade.blade_coordinates_up[0][0],
360360
rotated_coordinates)
@@ -364,8 +364,8 @@ def test_rotate_deg_section_0_yup(self):
364364
blade.apply_transformations()
365365
blade.rotate(deg_angle=90)
366366
rotated_coordinates = np.array([
367-
0.3488408, 0.37407923, 0.38722075, 0.39526658, 0.39928492,
368-
0.39980927, 0.39716902, 0.39160916, 0.38335976, 0.3726862
367+
-0.409087 , -0.449122 , -0.4720087, -0.4872923, -0.4963637,
368+
-0.4999122, -0.4983684, -0.4920609, -0.4813081, -0.4664844
369369
])
370370
np.testing.assert_almost_equal(blade.blade_coordinates_up[0][1],
371371
rotated_coordinates)
@@ -375,8 +375,8 @@ def test_rotate_deg_section_0_zup(self):
375375
blade.apply_transformations()
376376
blade.rotate(deg_angle=90)
377377
rotated_coordinates = np.array([
378-
0.19572966, 0.14165003, 0.1003, 0.06135417, 0.02390711, -0.01235116,
379-
-0.04750545, -0.08150009, -0.11417222, -0.14527558
378+
0.2874853, 0.2197486, 0.1649479, 0.1120097, 0.0601922,
379+
0.0093686, -0.04036, -0.0887472, -0.1354346, -0.1799786
380380
])
381381
np.testing.assert_almost_equal(blade.blade_coordinates_up[0][2],
382382
rotated_coordinates)
@@ -386,8 +386,8 @@ def test_rotate_rad_section_1_xdown(self):
386386
blade.apply_transformations()
387387
blade.rotate(rad_angle=np.pi / 2.0)
388388
rotated_coordinates = np.array([
389-
0.29697841, 0.2176438, 0.15729805, 0.10116849, 0.04749167,
390-
-0.00455499, -0.05542713, -0.10535969, -0.15442047, -0.20253397
389+
0.23913475, 0.17512439, 0.12479053, 0.07749333, 0.03196268,
390+
-0.01239386, -0.05590447, -0.09873836, -0.14094435, -0.18246808
391391
])
392392
np.testing.assert_almost_equal(blade.blade_coordinates_down[1][0],
393393
rotated_coordinates)
@@ -397,8 +397,8 @@ def test_rotate_rad_section_1_ydown(self):
397397
blade.apply_transformations()
398398
blade.rotate(rad_angle=np.pi / 2.0)
399399
rotated_coordinates = np.array([
400-
0.40908705, 0.42570092, 0.44956113, 0.47048031, 0.48652991,
401-
0.49660315, 0.49999921, 0.49627767, 0.48516614, 0.4664844
400+
-0.3488408, -0.3576312, -0.3719492, -0.3844258, -0.3936846,
401+
-0.3989522, -0.3997457, -0.3957593, -0.3867917, -0.3726862
402402
])
403403
np.testing.assert_almost_equal(blade.blade_coordinates_down[1][1],
404404
rotated_coordinates)
@@ -408,8 +408,8 @@ def test_rotate_rad_section_1_zdown(self):
408408
blade.apply_transformations()
409409
blade.rotate(rad_angle=np.pi / 2.0)
410410
rotated_coordinates = np.array([
411-
0.28748529, 0.26225699, 0.21884879, 0.16925801, 0.11527639,
412-
0.05818345, -0.00088808, -0.0608972, -0.1208876, -0.17997863
411+
0.19572966, 0.17916459, 0.14715217, 0.11052969, 0.07079877,
412+
0.02893379, -0.01426232, -0.05809137, -0.10194212, -0.14527558
413413
])
414414
np.testing.assert_almost_equal(blade.blade_coordinates_down[1][2],
415415
rotated_coordinates)
@@ -734,48 +734,6 @@ def test_stl_generate_errors_lower(self):
734734
self.assertTrue(os.path.isfile('tests/test_datasets/errors.txt'))
735735
self.addCleanup(os.remove, 'tests/test_datasets/errors.txt')
736736

737-
def test_stl_smesh_exception_1(self):
738-
blade = create_sample_blade_NACA()
739-
blade.apply_transformations()
740-
with self.assertRaises(ValueError):
741-
blade.generate_stl_smesh(min_length=-1, max_length=1, outfile_stl=None)
742-
743-
def test_stl_smesh_exception_2(self):
744-
blade = create_sample_blade_NACA()
745-
blade.apply_transformations()
746-
with self.assertRaises(ValueError):
747-
blade.generate_stl_smesh(min_length=2, max_length=1, outfile_stl=None)
748-
749-
def test_stl_smesh_generated_upper(self):
750-
# Requires OCC to be installed
751-
blade = create_sample_blade_NACA()
752-
blade.apply_transformations()
753-
blade.generated_upper_face = 5
754-
blade.generate_stl_smesh(min_length=1, max_length=10, outfile_stl=None)
755-
self.assertIsInstance(blade.generated_upper_face, TopoDS_Shape)
756-
757-
def test_stl_smesh_generated_lower(self):
758-
# Requires OCC to be installed
759-
blade = create_sample_blade_NACA()
760-
blade.apply_transformations()
761-
blade.generated_lower_face = None
762-
blade.generate_stl_smesh(min_length=1, max_length=10, outfile_stl=None)
763-
self.assertIsInstance(blade.generated_lower_face, TopoDS_Shape)
764-
765-
def test_stl_smesh_generated_tip(self):
766-
# Requires OCC to be installed
767-
blade = create_sample_blade_NACA()
768-
blade.apply_transformations()
769-
blade.generated_tip = 0
770-
blade.generate_stl_smesh(min_length=1, max_length=10, outfile_stl=None)
771-
self.assertIsInstance(blade.generated_tip, TopoDS_Shape)
772-
773-
def test_stl_smesh_export_exception(self):
774-
blade = create_sample_blade_NACA()
775-
blade.apply_transformations()
776-
with self.assertRaises(ValueError):
777-
blade.generate_stl_smesh(min_length=1, max_length=10, outfile_stl=55)
778-
779737
def test_solid_max_deg_exception(self):
780738
blade = create_sample_blade_NACA()
781739
blade.apply_transformations()
@@ -876,4 +834,4 @@ def test_blade_str_method(self):
876834
' sections = {}'.format(blade.pitch_angles)
877835
string += '\nInduced rake from skew (in unit length)'\
878836
' for the sections = {}'.format(blade.induced_rake)
879-
assert blade.__str__() == string
837+
assert blade.__str__() == string
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/test_propeller.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ def test_generate_stl(self):
155155
prop.generate_stl("tests/test_datasets/propeller_and_shaft.stl")
156156
self.assertTrue(os.path.isfile('tests/test_datasets/propeller_and_shaft.stl'))
157157
self.addCleanup(os.remove, 'tests/test_datasets/propeller_and_shaft.stl')
158-
159-
def test_display(self):
160-
sh = Shaft("tests/test_datasets/shaft.iges")
161-
prop = create_sample_blade_NACApptc()
162-
prop = Propeller(sh, prop, 4)
163-
prop.display()
158+
159+
def test_isdisplay(self):
160+
assert hasattr(Propeller, "display") == True

tests/test_shaft.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ def test_generate_solid_02(self):
1818
shaft_solid = sh.generate_solid()
1919
self.assertIsInstance(shaft_solid, TopoDS_Solid)
2020

21-
def test_display_01(self):
22-
sh = Shaft("tests/test_datasets/shaft.iges")
23-
sh.display()
24-
25-
def test_display_02(self):
26-
sh = Shaft("tests/test_datasets/shaft.stl")
27-
sh.display()
28-
2921
def test_exception(self):
3022
sh = Shaft("tests/test_datasets/parameters.prm")
3123
with self.assertRaises(Exception):
@@ -34,3 +26,6 @@ def test_exception(self):
3426
def test_init(self):
3527
sh = Shaft("tests/test_datasets/shaft.iges")
3628
assert sh.filename == "tests/test_datasets/shaft.iges"
29+
30+
def test_isdisplay(self):
31+
assert hasattr(Shaft, "display") == True

0 commit comments

Comments
 (0)