Skip to content

Commit

Permalink
Re-implemented airfoil matching
Browse files Browse the repository at this point in the history
  • Loading branch information
mlauer154 committed Feb 14, 2024
1 parent 0ad9d8c commit 2473e28
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pymead/core/pymead_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DualRep:

# These attributes are non-serializable because they contain references to PyQt5 graphics or signal/slot objects,
# which are inherently non-serializable
non_serializable_attributes = ["tree", "tree_item", "canvas", "canvas_item"]
non_serializable_attributes = ["tree", "tree_item", "canvas", "canvas_item", "gui_obj"]

def __deepcopy__(self, memo):
"""
Expand Down
2 changes: 1 addition & 1 deletion pymead/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ def match_airfoil(self):
if dialog.exec_():
airfoil_match_settings = dialog.valuesFromWidgets()
# res = match_airfoil_ga(self.mea, target_airfoil, airfoil_name)
res = match_airfoil(self.geo_col.container()["airfoils"], airfoil_match_settings["tool_airfoil"],
res = match_airfoil(self.geo_col, airfoil_match_settings["tool_airfoil"],
airfoil_match_settings["target_airfoil"])
msg_mode = 'error'
if hasattr(res, 'success') and res.success or hasattr(res, 'F') and res.F is not None:
Expand Down
27 changes: 17 additions & 10 deletions pymead/utils/airfoil_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import scipy
from shapely.geometry import Polygon

from pymead.core.geometry_collection import GeometryCollection
from pymead.utils.get_airfoil import extract_data_from_airfoiltools
from pymead.core.mea import MEA

Expand All @@ -20,7 +21,8 @@
from pymoo.optimize import minimize


def airfoil_symmetric_area_difference(parameters: list, mea: MEA, target_airfoil: str, airfoil_to_match_xy: np.ndarray):
def airfoil_symmetric_area_difference(parameters: list, geo_col: GeometryCollection, target_airfoil: str,
airfoil_to_match_xy: np.ndarray):
r"""
This method uses the ``shapely`` package to convert the parametrized airfoil and the "discrete" airfoil to
`Polygon <https://shapely.readthedocs.io/en/stable/manual.html#Polygon>`_
Expand Down Expand Up @@ -51,9 +53,9 @@ def airfoil_symmetric_area_difference(parameters: list, mea: MEA, target_airfoil
"""

# Override airfoil parameters with supplied sequence of parameters
mea.update_parameters(parameters)
airfoil = mea.airfoils[target_airfoil]
coords = airfoil.get_coords(body_fixed_csys=False)
geo_col.assign_design_variable_values(parameters, bounds_normalized=True)
airfoil = geo_col.container()["airfoils"][target_airfoil]
coords = airfoil.get_coords_selig_format()

# Calculate the boolean symmetric area difference. If there is a topological error, such as a self-intersection,
# which prevents Polygon.area() from running, then make the symmetric area difference a large value to discourage
Expand All @@ -72,7 +74,7 @@ def airfoil_symmetric_area_difference(parameters: list, mea: MEA, target_airfoil
return symmetric_area_difference


def match_airfoil(mea: MEA, target_airfoil: str, airfoil_to_match: str or list or np.ndarray,
def match_airfoil(geo_col: GeometryCollection, target_airfoil: str, airfoil_to_match: str or list or np.ndarray,
repair: typing.Callable or None = None):
r"""
This method uses the `sequential least-squares programming
Expand Down Expand Up @@ -123,16 +125,21 @@ def match_airfoil(mea: MEA, target_airfoil: str, airfoil_to_match: str or list o
# plt.show()

# mea.deactivate_airfoil_matching_params(target_airfoil)
new_mea = mea.deepcopy()
new_mea.remove_airfoil_graphs()
# new_mea = MEA.generate_from_param_dict(mea_dict)
initial_guess = np.array(mea.extract_parameters()[0])
geo_col_deepcopy = deepcopy(geo_col)
initial_guess = np.array(geo_col.extract_design_variable_values())
# initial_guess = np.array([param.value for param in parameter_list])
# bounds = [param.bounds for param in parameter_list]
bounds = np.repeat(np.array([[0.0, 1.0]]), len(initial_guess), axis=0)
# try:
res = scipy.optimize.minimize(airfoil_symmetric_area_difference, initial_guess, method='SLSQP',
bounds=bounds, args=(new_mea, target_airfoil, airfoil_to_match_xy), options={'disp': True})
res = scipy.optimize.minimize(
airfoil_symmetric_area_difference,
initial_guess,
method="SLSQP",
bounds=bounds,
args=(geo_col_deepcopy, target_airfoil, airfoil_to_match_xy),
options=dict(disp=True)
)
# finally:
# mea.activate_airfoil_matching_params(target_airfoil)
return res
Expand Down

0 comments on commit 2473e28

Please sign in to comment.