Skip to content

Commit

Permalink
AFI: add safety checks for ill-defined airfoils
Browse files Browse the repository at this point in the history
When calculating UA parameters, we need to check that there are sufficient points to compute the least-squares solution.
  • Loading branch information
bjonkman committed Oct 9, 2024
1 parent 853ba8c commit f8633f2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions modules/aerodyn/src/AirfoilInfo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,8 @@ SUBROUTINE CalculateUACoeffs(CalcDefaults,p,ColCl,ColCd,ColCm,ColUAf,UAMod)
! find bounding indices for limitAlphaRange
iHighLimit = min( maxloc( alpha_ , DIM=1, MASK=alpha_ < LimitAlphaRange) + 1, size(alpha_) ) ! we can limit this to some range
iLowLimit = max( minloc( alpha_ , DIM=1, MASK=alpha_ > -LimitAlphaRange) - 1, 1 ) ! we can limit this to some range
if (iHighLimit - iLowLimit < 3) iHighLimit = min(iLowLimit+2,size(alpha_)) ! this could still be an issue if we don't have very many points in the airfoil table. If that's the case, this data is not worth anything anyway
if (iHighLimit - iLowLimit < 3) iLowLimit = max(iHighLimit-2,1) ! this could still be an issue if we don't have very many points in the airfoil table. If that's the case, this data is not worth anything anyway

! find alphaUpper (using smoothed Cn values):
if (CalcDefaults%alphaUpper) then
Expand Down Expand Up @@ -1053,12 +1055,12 @@ SUBROUTINE CalculateUACoeffs(CalcDefaults,p,ColCl,ColCd,ColCm,ColUAf,UAMod)
!mask = p%alpha >= p%UA_BL%alphaLower+alphaMargin & p%alpha <= p%UA_BL%alphaUpper-alphaMargin;

iLow2 = iLowLimit
do while (iLow2 < iHighLimit .and. p%alpha(iLow2) < p%UA_BL%alphaLower + alphaMargin)
do while (iLow2 < iHighLimit-1 .and. p%alpha(iLow2) < p%UA_BL%alphaLower + alphaMargin)
iLow2 = iLow2 + 1
end do

iHigh2 = iHighLimit
do while (iHigh2 > iLowLimit .and. p%alpha(iHigh2) > p%UA_BL%alphaUpper - alphaMargin)
do while (iHigh2 > iLow2+1 .and. p%alpha(iHigh2) > p%UA_BL%alphaUpper - alphaMargin)
iHigh2 = iHigh2 - 1
end do

Expand Down Expand Up @@ -1181,6 +1183,15 @@ SUBROUTINE Calculate_C_alpha(alpha, Cn, Cl, Default_Cn_alpha, Default_Cl_alpha,
REAL(ReKi) :: A( size(alpha), 2)
REAL(ReKi) :: B(max(2,size(alpha)),2)

if (SIZE(Cn) < 2 .OR. SIZE(Cl) < 2) then
ErrMsg='Calculate_C_alpha: Not enough data points to compute Cn and Cl slopes.'
ErrStat=ErrID_Fatal
Default_Cn_alpha = EPSILON(Default_Cn_alpha)
Default_Cl_alpha = EPSILON(Default_Cl_alpha)
Default_alpha0 = 0.0_ReKi
return
end if

A(:,1) = alpha
A(:,2) = 1.0_ReKi

Expand Down

0 comments on commit f8633f2

Please sign in to comment.