-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
91,361 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
""" | ||
BladeX init | ||
""" | ||
__all__ = ['profilebase', 'profiles', 'blade', 'deform', 'params', 'ndinterpolator'] | ||
__all__ = ['profilebase', 'profiles', 'blade', 'shaft', 'propeller', 'deform', 'params', 'ndinterpolator'] | ||
|
||
from .profilebase import ProfileBase | ||
from .profiles import CustomProfile, NacaProfile | ||
from .blade import Blade | ||
from .shaft import Shaft | ||
from .propeller import Propeller | ||
from .deform import Deformation | ||
from .params import ParamFile | ||
from .ndinterpolator import RBF, reconstruct_f, scipy_bspline | ||
from .ndinterpolator import RBF, reconstruct_f, scipy_bspline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
""" | ||
Module for the propeller with shaft bottom-up parametrized construction. | ||
""" | ||
import os | ||
import numpy as np | ||
from bladex import Blade, Shaft | ||
import OCC.Core.TopoDS | ||
from OCC.Core.gp import gp_Dir, gp_Pnt, gp_Ax1, gp_Trsf | ||
from OCC.Core.IGESControl import IGESControl_Reader, IGESControl_Writer | ||
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Transform, BRepBuilderAPI_Sewing | ||
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Fuse | ||
from OCC.Extend.DataExchange import write_stl_file | ||
from OCC.Display.SimpleGui import init_display | ||
|
||
class Propeller(object): | ||
""" | ||
Bottom-up parametrized propeller (including shaft) construction. | ||
The constructor requires PythonOCC to be installed. | ||
:param shaft.Shaft shaft: shaft to be added to the propeller | ||
:param blade.Blade blade: blade of the propeller | ||
:param int n_blades: number of blades composing the propeller | ||
:cvar OCC.Core.TopoDS.TopoDS_Solid shaft_solid: solid shaft | ||
:cvar OCC.Core.TopoDS.TopoDS_Shell sewed_full_body: propeller with shaft shell | ||
""" | ||
|
||
def __init__(self, shaft, blade, n_blades): | ||
self.shaft_solid = shaft.generate_solid() | ||
blade.apply_transformations(reflect=True) | ||
blade_solid = blade.generate_solid(max_deg=2, | ||
display=False, | ||
errors=None) | ||
blades = [] | ||
blades.append(blade_solid) | ||
for i in range(n_blades-1): | ||
blade.rotate(rad_angle=1.0*2.0*np.pi/float(n_blades)) | ||
blade_solid = blade.generate_solid(max_deg=2, display=False, errors=None) | ||
blades.append(blade_solid) | ||
blades_combined = blades[0] | ||
for i in range(len(blades)-1): | ||
boolean_union = BRepAlgoAPI_Fuse(blades_combined, blades[i+1]) | ||
boolean_union.Build() | ||
if not boolean_union.IsDone(): | ||
raise RuntimeError('Unsuccessful assembling of blade') | ||
blades_combined = boolean_union.Shape() | ||
boolean_union = BRepAlgoAPI_Fuse(self.shaft_solid, blades_combined) | ||
boolean_union.Build() | ||
result_compound = boolean_union.Shape() | ||
section_edges = boolean_union.SectionEdges() | ||
sewer = BRepBuilderAPI_Sewing(1e-2) | ||
sewer.Add(result_compound) | ||
sewer.Perform() | ||
self.sewed_full_body = sewer.SewedShape() | ||
|
||
def generate_iges(self, filename): | ||
""" | ||
Export the .iges CAD for the propeller with shaft. | ||
:param string filename: path (with the file extension) where to store | ||
the .iges CAD for the propeller and shaft | ||
:raises RuntimeError: if the solid assembling of blades is not | ||
completed successfully | ||
""" | ||
iges_writer = IGESControl_Writer() | ||
iges_writer.AddShape(self.sewed_full_body) | ||
iges_writer.Write(filename) | ||
|
||
def generate_stl(self, filename): | ||
""" | ||
Export the .stl CAD for the propeller with shaft. | ||
:param string filename: path (with the file extension) where to store | ||
the .stl CAD for the propeller and shaft | ||
:raises RuntimeError: if the solid assembling of blades is not | ||
completed successfully | ||
""" | ||
write_stl_file(self.sewed_full_body, filename) | ||
|
||
def display(self): | ||
""" | ||
Display the propeller with shaft. | ||
""" | ||
display, start_display, add_menu, add_function_to_menu = init_display() | ||
display.DisplayShape(self.sewed_full_body, update=True) | ||
start_display() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
from OCC.Core.IGESControl import IGESControl_Reader | ||
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeSolid, BRepBuilderAPI_Sewing | ||
import OCC.Core.TopoDS | ||
from OCC.Display.SimpleGui import init_display | ||
|
||
class Shaft(object): | ||
""" | ||
Bottom-up parametrized shaft construction. | ||
:param string filename: path (with the file extension) of a .iges file with | ||
stored shaft information. | ||
:cvar string filename: path (with the file extension) of a .iges file with | ||
stored shaft information. | ||
""" | ||
|
||
def __init__(self, filename): | ||
self.filename = filename | ||
|
||
def generate_solid(self): | ||
""" | ||
Generate an assembled solid shaft using the BRepBuilderAPI_MakeSolid | ||
algorithm. This method requires PythonOCC to be installed. | ||
:raises RuntimeError: if the assembling of the solid shaft is not | ||
completed successfully | ||
:return: solid shaft | ||
:rtype: OCC.Core.TopoDS.TopoDS_Solid | ||
""" | ||
iges_reader = IGESControl_Reader() | ||
iges_reader.ReadFile(self.filename) | ||
iges_reader.TransferRoots() | ||
shaft_compound = iges_reader.Shape() | ||
sewer = BRepBuilderAPI_Sewing(1e-2) | ||
sewer.Add(shaft_compound) | ||
sewer.Perform() | ||
result_sewed_shaft = sewer.SewedShape() | ||
shaft_solid_maker = BRepBuilderAPI_MakeSolid() | ||
shaft_solid_maker.Add(OCC.Core.TopoDS.topods_Shell(result_sewed_shaft)) | ||
if not shaft_solid_maker.IsDone(): | ||
raise RuntimeError('Unsuccessful assembling of solid shaft') | ||
shaft_solid = shaft_solid_maker.Solid() | ||
return shaft_solid | ||
|
||
def display(self): | ||
""" | ||
Display the shaft. | ||
""" | ||
shaft_solid = self.generate_solid() | ||
display, start_display, add_menu, add_function_to_menu = init_display() | ||
display.DisplayShape(shaft_solid, update=True) | ||
start_display() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.