Skip to content

Commit 0a4379e

Browse files
gortalindem0
andauthored
update to newest python-occ version (#107)
* update to newest python-occ version * Update testing_pr.yml * interpolant 5% curve --------- Co-authored-by: Nicola Demo <[email protected]>
1 parent f6a3e16 commit 0a4379e

File tree

3 files changed

+90
-23
lines changed

3 files changed

+90
-23
lines changed

.github/workflows/testing_pr.yml

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,40 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [windows-latest, macos-latest, ubuntu-latest]
16-
python-version: [3.7, 3.8]
16+
python-version: [3.8, 3.9]
1717

1818
steps:
19-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v4
2020

2121

2222
- name: Set up Python
23-
uses: actions/setup-python@v2
23+
uses: actions/setup-python@v4
2424
with:
2525
python-version: ${{ matrix.python-version }}
2626

27-
- name: Setup conda
28-
uses: s-weigand/setup-[email protected]
27+
- name: Setup Conda
28+
uses: conda-incubator/setup-miniconda@v3
2929
with:
30-
update-conda: true
31-
python-version: ${{ matrix.python-version }}
32-
conda-channels: anaconda, conda-forge
33-
30+
channels: conda-forge, defaults
31+
activate-environment: ""
32+
3433
- name: Install Python dependencies on Linux/MacOS
34+
shell: bash -el {0}
3535
if: startsWith(matrix.os, 'windows') != true
3636
run: |
37-
conda install --yes pythonocc-core=7.4.1
38-
python3 -m pip install --upgrade pip
39-
python3 -m pip install smithers[vtk]
40-
python3 -m pip install .[test]
37+
conda create -n occ python=${{ matrix.python-version }} pythonocc-core
38+
conda info
39+
conda activate occ
40+
conda info
41+
python -m pip install --upgrade pip
42+
python -m pip install smithers[vtk]
43+
python -m pip install .[test]
44+
python -c 'import OCC'
4145
4246
- name: Install Python dependencies on Windows
4347
if: startsWith(matrix.os, 'windows')
4448
run: |
45-
conda install --yes pythonocc-core=7.4.1
49+
conda install --yes pythonocc-core
4650
python -m pip install --upgrade pip
4751
python -m pip install smithers[vtk]
4852
python -m pip install .[test]
@@ -52,5 +56,8 @@ jobs:
5256
run: python -m pytest
5357

5458
- name: Test with pytest on Linux/MacOS
59+
shell: bash -el {0}
5560
if: startsWith(matrix.os, 'windows') != true
56-
run: python3 -m pytest
61+
run: |
62+
conda activate occ
63+
python -m pytest

bladex/blade.py

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,6 @@ def scale(self, factor):
429429
self.blade_coordinates_down[i][1] = new_coord_matrix_down[1]
430430
self.blade_coordinates_down[i][2] = new_coord_matrix_down[2]
431431

432-
433-
434432
def plot(self, elev=None, azim=None, ax=None, outfile=None):
435433
"""
436434
Plot the generated blade sections.
@@ -1088,7 +1086,59 @@ def generate_stl_blade(self, filename):
10881086

10891087
write_stl_file(self.sewed_full, filename)
10901088

1091-
def generate_iges_blade(self, filename):
1089+
def _generate_leading_edge_curves(self):
1090+
"""
1091+
Private method to generate curves that follow the leading edge of the blade
1092+
(top and bottom surfaces).
1093+
"""
1094+
self._import_occ_libs()
1095+
1096+
# Extract points at leftmost 5% for upper and lower surfaces
1097+
upper_points = []
1098+
lower_points = []
1099+
1100+
for i in range(self.n_sections):
1101+
min_x = np.min(self.sections[i].xdown_coordinates)
1102+
max_x = np.max(self.sections[i].xdown_coordinates)
1103+
delta_x = max_x - min_x
1104+
1105+
target_x = min_x + 0.95 * delta_x
1106+
1107+
idx = np.abs(self.sections[i].xdown_coordinates - target_x).argmin()
1108+
1109+
# Create points for upper and lower curves
1110+
upper_points.append(gp_Pnt(
1111+
1000 * self.blade_coordinates_up[i][0][idx],
1112+
1000 * self.blade_coordinates_up[i][1][idx],
1113+
1000 * self.blade_coordinates_up[i][2][idx]
1114+
))
1115+
1116+
lower_points.append(gp_Pnt(
1117+
1000 * self.blade_coordinates_down[i][0][idx],
1118+
1000 * self.blade_coordinates_down[i][1][idx],
1119+
1000 * self.blade_coordinates_down[i][2][idx]
1120+
))
1121+
1122+
# Create arrays of points for interpolation
1123+
upper_array = TColgp_HArray1OfPnt(1, len(upper_points))
1124+
lower_array = TColgp_HArray1OfPnt(1, len(lower_points))
1125+
1126+
for i, (up, low) in enumerate(zip(upper_points, lower_points)):
1127+
upper_array.SetValue(i + 1, up)
1128+
lower_array.SetValue(i + 1, low)
1129+
1130+
# Create interpolated curves
1131+
upper_curve = GeomAPI_Interpolate(upper_array, False, 1e-9)
1132+
lower_curve = GeomAPI_Interpolate(lower_array, False, 1e-9)
1133+
1134+
upper_curve.Perform()
1135+
lower_curve.Perform()
1136+
1137+
# Convert to edges
1138+
self.upper_le_edge = BRepBuilderAPI_MakeEdge(upper_curve.Curve()).Edge()
1139+
self.lower_le_edge = BRepBuilderAPI_MakeEdge(lower_curve.Curve()).Edge()
1140+
1141+
def generate_iges_blade(self, filename, include_le_curves=False):
10921142
"""
10931143
Generate and export the .IGES file for the entire blade.
10941144
This method requires PythonOCC (7.4.0) to be installed.
@@ -1099,11 +1149,20 @@ def generate_iges_blade(self, filename):
10991149
self._generate_lower_face(max_deg=1)
11001150
self._generate_root(max_deg=1)
11011151
self._generate_tip(max_deg=1)
1152+
1153+
if include_le_curves:
1154+
self._generate_leading_edge_curves()
1155+
11021156
iges_writer = IGESControl_Writer()
11031157
iges_writer.AddShape(self.generated_upper_face)
11041158
iges_writer.AddShape(self.generated_lower_face)
11051159
iges_writer.AddShape(self.generated_root)
11061160
iges_writer.AddShape(self.generated_tip)
1161+
1162+
if include_le_curves:
1163+
iges_writer.AddShape(self.upper_le_edge)
1164+
iges_writer.AddShape(self.lower_le_edge)
1165+
11071166
iges_writer.Write(filename)
11081167

11091168
@staticmethod
@@ -1244,6 +1303,7 @@ def export_ppg(self,
12441303
if i == len(hub_offsets) - 1:
12451304
output_string += str("%.8e" % offset[0]) + ' ' + str(
12461305
"%.8e" % hub_offsets[i][1])
1306+
12471307
continue
12481308
output_string += str("%.8e" % offset[0]) + ' ' + str(
12491309
"%.8e" % offset[1]) + '\n'

bladex/reversepropeller.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
BRep_Tool_CurveOnSurface)
2020
import OCC.Core.TopoDS
2121
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Fuse
22-
from OCC.Core.BRepAlgo import BRepAlgo_Section
22+
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section
2323
from OCC.Core.TopTools import TopTools_ListOfShape, TopTools_MapOfShape
2424
from OCC.Core.TopExp import TopExp_Explorer
2525
from OCC.Core.TopAbs import TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_WIRE
@@ -29,7 +29,7 @@
2929
from OCC.Core.TopoDS import TopoDS_Shape
3030
from OCC.Core.TColgp import TColgp_HArray1OfPnt, TColgp_Array1OfPnt
3131
from OCC.Core.GeomAPI import GeomAPI_Interpolate, GeomAPI_IntCS, GeomAPI_ProjectPointOnSurf
32-
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve, BRepAdaptor_HCurve
32+
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve
3333
from OCC.Core.GCPnts import GCPnts_AbscissaPoint
3434
from OCC.Core.BRep import BRep_Tool
3535
from OCC.Core.IntTools import IntTools_FClass2d
@@ -38,7 +38,7 @@
3838
from OCC.Core.TopoDS import topods, TopoDS_Edge, TopoDS_Compound
3939
from subprocess import call
4040
from OCC.Core.IntCurvesFace import IntCurvesFace_ShapeIntersector
41-
from OCC.Core.Adaptor3d import Adaptor3d_Curve, Adaptor3d_HCurve
41+
from OCC.Core.Adaptor3d import Adaptor3d_Curve
4242
from OCC.Core.Geom import Geom_Line
4343
from OCC.Display.SimpleGui import init_display
4444
from OCC.Core.BRepGProp import (brepgprop_LinearProperties,
@@ -48,8 +48,8 @@
4848
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCylinder
4949
from OCC.Core.GeomLProp import GeomLProp_SLProps
5050
from OCC.Core.GCPnts import GCPnts_AbscissaPoint
51-
from OCC.Core.BRepAdaptor import (BRepAdaptor_Curve, BRepAdaptor_HCurve,
52-
BRepAdaptor_CompCurve, BRepAdaptor_HCompCurve)
51+
from OCC.Core.BRepAdaptor import (BRepAdaptor_Curve,
52+
BRepAdaptor_CompCurve)
5353
from OCC.Core.GCPnts import GCPnts_UniformDeflection
5454
from OCC.Core.GeomAPI import GeomAPI_PointsToBSpline
5555
from OCC.Core.GeomAbs import (GeomAbs_C0, GeomAbs_G1, GeomAbs_C1, GeomAbs_G2,

0 commit comments

Comments
 (0)