Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
matlab_airfoil_toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aerospace and Mechanical Engineering
matlab_airfoil_toolbox
Commits
34dc2698
Verified
Commit
34dc2698
authored
3 years ago
by
Thomas Lambert
Browse files
Options
Downloads
Patches
Plain Diff
refactor(findccllinrange): improve cyclomatic complexity
parent
9622fc96
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
+af_tools/findcllinearrange.m
+67
-57
67 additions, 57 deletions
+af_tools/findcllinearrange.m
CHANGELOG.md
+8
-3
8 additions, 3 deletions
CHANGELOG.md
with
75 additions
and
60 deletions
+af_tools/findcllinearrange.m
+
67
−
57
View file @
34dc2698
...
...
@@ -91,7 +91,6 @@ function [alphaRange, clRange, clSlope] = linearrangefinder(alpha, cl)
IDEAL_LIFT_SLOPE
=
2
*
pi
;
% Ideal Cl curve, [rad]
TOL_DCL
=
0.6
;
% Tolerance on the slope
TOL_DDCL
=
0.01
;
% Tolerance on the curvature
PLOT_POLAR_IF_ERROR
=
true
;
% Plot the polar if error so user can see why it fails
% Initialization
alphaRange
=
zeros
(
2
,
size
(
cl
,
2
));
...
...
@@ -100,64 +99,11 @@ function [alphaRange, clRange, clSlope] = linearrangefinder(alpha, cl)
% Loop for every polar data (every column of cl)
for
i
=
1
:
size
(
cl
,
2
)
% First and second derivatives
dalpha
=
diff
(
alpha
(:,
i
));
dcl
=
diff
(
cl
(:,
i
))
.
/
dalpha
(
1
);
ddcl
=
diff
(
dcl
)
.
/
dalpha
(
1
);
% Adapt tolerance to angle of attack
ddClTol
=
TOL_DDCL
/
dalpha
(
1
)
^
2
;
% Initialize loop
maxFound
=
false
;
minFound
=
false
;
% Initialize linear range start and end (mostly useful for debugging)
tmpRange
=
[
1
,
length
(
alpha
(:,
i
))];
for
j
=
1
:(
length
(
alpha
))
-
2
% Check if current point is a valid point of the linear range
isMin
=
isbound
(
dcl
(
j
),
ddcl
(
j
),
TOL_DCL
,
ddClTol
,
IDEAL_LIFT_SLOPE
);
isMax
=
isbound
(
dcl
(
end
+
1
-
j
),
ddcl
(
end
+
1
-
j
),
TOL_DCL
,
ddClTol
,
...
IDEAL_LIFT_SLOPE
);
if
isMin
&&
~
minFound
minFound
=
true
;
tmpRange
(
1
)
=
j
;
end
if
isMax
&&
~
maxFound
maxFound
=
true
;
tmpRange
(
end
)
=
length
(
dcl
)
+
2
-
j
;
end
% Stop when both min and max were found
if
minFound
&&
maxFound
break
end
end
[
tmpRange
,
rangeFound
]
=
findrange
(
i
,
alpha
,
cl
,
TOL_DCL
,
TOL_DDCL
,
IDEAL_LIFT_SLOPE
);
% Check issues in case linear range was not found
if
~
minFound
||
~
maxFound
if
PLOT_POLAR_IF_ERROR
% Plot the polar if error so user can see why it fails
% Display issue
figure
(
'Name'
,
'linearrange:Debug'
);
hold
on
;
plot
(
alpha
(:,
i
),
cl
(:,
i
),
'--'
);
plot
(
alpha
(
tmpRange
(
1
):
tmpRange
(
2
),
i
),
cl
(
tmpRange
(
1
):
tmpRange
(
2
),
i
),
...
'color'
,
'r'
,
'lineWidth'
,
1.2
);
if
~
minFound
plot
(
alpha
(
tmpRange
(
1
),
i
),
cl
(
tmpRange
(
1
),
i
),
...
's'
,
'MarkerFaceColor'
,
'b'
,
'Markersize'
,
12
);
end
if
~
maxFound
plot
(
alpha
(
tmpRange
(
2
),
i
),
cl
(
tmpRange
(
2
),
i
),
...
's'
,
'MarkerFaceColor'
,
'b'
,
'Markersize'
,
12
);
end
grid
on
;
legend
(
'Polar'
,
'Attempt at linear range'
,
'Missing point(s)'
);
end
if
~
rangeFound
ploterror
(
alpha
,
cl
,
i
,
tmpRange
);
error
(
'MATLAB:findcllinearrange:noRangeFound'
,
...
[
'findcllinearrange was not able to determine the linear range of the given '
...
'polar.\nMaybe the polar does not have enough points, or it is malformed.\n '
...
...
...
@@ -193,3 +139,67 @@ function bool = iscurvaturezero(ddCl, tol)
% ISCURVATUREZERO Returns true if the curvature is almost zero
bool
=
abs
(
ddCl
)
<
tol
;
end
% --------------------------------------------------------------------------------------------------
function
ploterror
(
alpha
,
cl
,
i
,
tmpRange
)
% PLOTERROR Plots the polar in case of error
figure
(
'Name'
,
'linearrange:Debug'
);
hold
on
;
plot
(
alpha
(:,
i
),
cl
(:,
i
),
'--'
);
plot
(
alpha
(
tmpRange
(
1
):
tmpRange
(
2
),
i
),
cl
(
tmpRange
(
1
):
tmpRange
(
2
),
i
),
...
'color'
,
'r'
,
'lineWidth'
,
1.2
);
plot
(
alpha
(
tmpRange
(
1
),
i
),
cl
(
tmpRange
(
1
),
i
),
...
's'
,
'MarkerFaceColor'
,
'b'
,
'Markersize'
,
12
);
plot
(
alpha
(
tmpRange
(
2
),
i
),
cl
(
tmpRange
(
2
),
i
),
...
's'
,
'MarkerFaceColor'
,
'b'
,
'Markersize'
,
12
);
grid
on
;
legend
(
'Polar'
,
'Attempt at linear range'
,
'Missing point(s)'
);
end
% --------------------------------------------------------------------------------------------------
function
[
tmpRange
,
rangeFound
]
=
findrange
(
i
,
alpha
,
cl
,
TOL_DCL
,
TOL_DDCL
,
IDEAL_LIFT_SLOPE
)
% FINDRANGE Finds the range iteratively.
rangeFound
=
false
;
% First and second derivatives
dalpha
=
diff
(
alpha
(:,
i
));
dcl
=
diff
(
cl
(:,
i
))
.
/
dalpha
(
1
);
ddcl
=
diff
(
dcl
)
.
/
dalpha
(
1
);
% Adapt tolerance to angle of attack
ddClTol
=
TOL_DDCL
/
dalpha
(
1
)
^
2
;
% Initialize linear range start and end (mostly useful for debugging)
tmpRange
=
[
1
,
length
(
alpha
(:,
i
))];
maxFound
=
false
;
minFound
=
false
;
for
j
=
1
:(
length
(
alpha
))
-
2
% Check if current point is a valid point of the linear range
isMin
=
isbound
(
dcl
(
j
),
ddcl
(
j
),
TOL_DCL
,
ddClTol
,
IDEAL_LIFT_SLOPE
);
isMax
=
isbound
(
dcl
(
end
+
1
-
j
),
ddcl
(
end
+
1
-
j
),
TOL_DCL
,
ddClTol
,
...
IDEAL_LIFT_SLOPE
);
if
isMin
&&
~
minFound
minFound
=
true
;
tmpRange
(
1
)
=
j
;
end
if
isMax
&&
~
maxFound
maxFound
=
true
;
tmpRange
(
end
)
=
length
(
dcl
)
+
2
-
j
;
end
if
minFound
&&
maxFound
rangeFound
=
true
;
break
end
end
end
This diff is collapsed.
Click to expand it.
CHANGELOG.md
+
8
−
3
View file @
34dc2698
...
...
@@ -9,16 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
-
Start using MISS_HIT for style and code analysis.
### Changed
-
Style: Adopt style from MISS_HIT
-
Copyright notice: change main copyright holder to the University
-
Doc: Revamp
`CONTRIBUTING.md`
to put emphasis on MISS_HIT and conventions
-
Refactor: Rework functions to lower their complexity using mh_metrics
### Deprecated
### Removed
### Fixed
### Security
## [1.2.0] - 2022-04-10
### Added
...
...
@@ -51,7 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-
Initial release
[
Unreleased
]:
https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/compare/v1.
0
.0...master
[
Unreleased
]:
https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/compare/v1.
2
.0...master
[
1.2.0
]:
https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/compare/v1.1.0...v1.2.0
[
1.1.0
]:
https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/compare/v1.0.0...v1.1.0
[
1.0.0
]:
https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/releases/v1.0.0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment