Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions openfast_toolbox/airfoils/Polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def correction3D(
Returns
-------
polar : Polar
A new Polar object corrected for 3-D effects
A new Polar object corrected for 3-D effects, with angles in degrees.

Notes
-----
Expand All @@ -345,29 +345,16 @@ def correction3D(

"""

if alpha_max_corr == None and alpha_linear_min == None and alpha_linear_max == None:
alpha_linear_region, _, cl_slope, alpha0 = self.linear_region()
alpha_linear_min = alpha_linear_region[0]
alpha_linear_max = alpha_linear_region[-1]
_, alpha_max_corr = self.cl_max()
find_linear_region = False
elif alpha_max_corr * alpha_linear_min * alpha_linear_max == None:
fit_limits = (alpha_max_corr, alpha_linear_min, alpha_linear_max)
fit_explicit_range = any(limit is not None for limit in fit_limits)
if fit_explicit_range and any(limit is None for limit in fit_limits):
raise Exception(
"Define all or none of the keyword arguments alpha_max_corr, alpha_linear_min, and alpha_linear_max"
)
else:
find_linear_region = True

# rename and convert units for convenience
if self._radians:
alpha = alpha
else:
alpha = np.radians(self.alpha)
alpha = self.alpha if self._radians else np.deg2rad(self.alpha)
cl_2d = self.cl
cd_2d = self.cd
alpha_max_corr = np.radians(alpha_max_corr)
alpha_linear_min = np.radians(alpha_linear_min)
alpha_linear_max = np.radians(alpha_linear_max)

# parameters in Du-Selig model
a = 1
Expand All @@ -380,14 +367,17 @@ def correction3D(
expon = d / lam / 1e-4

# find linear region with numpy polyfit
if find_linear_region:
if fit_explicit_range:
alpha_max_corr, alpha_linear_min, alpha_linear_max = np.deg2rad(fit_limits)
idx = np.logical_and(alpha >= alpha_linear_min, alpha <= alpha_linear_max)
p = np.polyfit(alpha[idx], cl_2d[idx], 1)
cl_slope = p[0]
alpha0 = -p[1] / cl_slope
else:
cl_slope = np.degrees(cl_slope)
alpha0 = np.radians(alpha0)
cl_slope, alpha0 = self.cl_linear_slope(radians=True)
_, alpha_max_corr = self.cl_max()
if not self._radians:
alpha_max_corr = np.deg2rad(alpha_max_corr)

if lift_method == "DuSelig":
# Du-Selig correction factor
Expand Down
16 changes: 16 additions & 0 deletions openfast_toolbox/airfoils/tests/test_polar_manip.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,21 @@ def test_read(self):
P=Polar(os.path.join(MyDir,'../data/Cylinder.dat'))
self.assertEqual(P.cl.size,3)

def test_correction3d_angle_units(self):
degrees = Polar(os.path.join(MyDir, '../data/FFA-W3-241-Re12M.dat'))
radians = Polar(Re=degrees.Re, alpha=np.deg2rad(degrees.alpha),
cl=degrees.cl, cd=degrees.cd, cm=degrees.cm, radians=True)
limits = dict(alpha_max_corr=12, alpha_linear_min=-4.1, alpha_linear_max=4.1)

for options in ({}, {'blending_method': 'heaviside'},
dict(limits, blending_method='heaviside')):
with self.subTest(options=options):
expected = degrees.correction3D(0.197, 0.232, 9.153, drag_method='Eggers', **options)
actual = radians.correction3D(0.197, 0.232, 9.153, drag_method='Eggers', **options)
self.assertFalse(np.allclose(expected.cl, degrees.cl))
np.testing.assert_allclose(actual.alpha, expected.alpha, atol=1e-12)
np.testing.assert_allclose(actual.cl, expected.cl, atol=1e-12)
np.testing.assert_allclose(actual.cd, expected.cd, atol=1e-12)

if __name__ == '__main__':
unittest.main()