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
dc49c400
Verified
Commit
dc49c400
authored
3 years ago
by
Thomas Lambert
Browse files
Options
Downloads
Patches
Plain Diff
test: add test for trimtorange, fix special cases
parent
c3630ad5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
+af_tools/+utils/trimtorange.m
+10
-3
10 additions, 3 deletions
+af_tools/+utils/trimtorange.m
README.md
+6
-6
6 additions, 6 deletions
README.md
tests/test_trimtorange.m
+169
-0
169 additions, 0 deletions
tests/test_trimtorange.m
with
185 additions
and
9 deletions
+af_tools/+utils/trimtorange.m
+
10
−
3
View file @
dc49c400
...
...
@@ -10,16 +10,23 @@ function [alphaTrim, clTrim, cdTrim] = trimtorange(range, alpha, cl, cd)
narginchk
(
2
,
4
);
for
i
=
1
:
size
(
alpha
,
2
)
if
nargin
>=
3
clTrim
(:,
i
)
=
cl
(
alpha
(:,
i
)
>=
range
(
1
)
&
alpha
(:,
i
)
<=
range
(
2
),
i
);
clTrim
(:,
i
)
=
cl
(
alpha
(:,
i
)
>=
range
(
1
)
&
alpha
(:,
i
)
<=
range
(
end
),
i
);
if
nargin
==
4
cdTrim
(:,
i
)
=
cd
(
alpha
(:,
i
)
>=
range
(
1
)
&
alpha
(:,
i
)
<=
range
(
2
),
i
);
cdTrim
(:,
i
)
=
cd
(
alpha
(:,
i
)
>=
range
(
1
)
&
alpha
(:,
i
)
<=
range
(
end
),
i
);
else
nargoutchk
(
1
,
2
);
end
else
nargoutchk
(
1
,
1
);
end
alphaTrim
(:,
i
)
=
alpha
(
alpha
(:,
i
)
>=
range
(
1
)
&
alpha
(:,
i
)
<=
range
(
2
),
i
);
alphaTrim
(:,
i
)
=
alpha
(
alpha
(:,
i
)
>=
range
(
1
)
&
alpha
(:,
i
)
<=
range
(
end
),
i
);
end
% If impossible to trim, just return the input
if
isempty
(
alphaTrim
)
alphaTrim
=
alpha
;
clTrim
=
cl
;
cdTrim
=
cd
;
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
README.md
+
6
−
6
View file @
dc49c400
...
...
@@ -25,10 +25,9 @@ Each function contains a complete description in its preamble. Type `help
1.
Either clone this repository or download a
`.zip`
version of the source code.
2.
Place the
`+af_tools/`
folder somewhere on your Matlab Path such as:
-
in you current project
-
in a folder that is already in Matlab's path (e.g.
`/Documents/Matlab/`
).
-
somewhere else, but then
[
explicitly add it to Matlab's Path
][
matlabDoc_path
]
.
-
in you current project
-
in a folder that is already in Matlab's path (e.g.
`/Documents/Matlab/`
).
-
somewhere else, but then
[
explicitly add it to Matlab's Path
][
matlabDoc_path
]
.
#### Remark
...
...
@@ -188,8 +187,9 @@ import af_tools.nacaairfoil
### plotpolars
Plots the following polars: $
`C_l-\alpha`
$, $
`C_d-\alpha`
$, $
`C_m-\alpha`
$
$
`C_l/C_d-\alpha`
$, $
`C_l-C_d`
$.
Plots the following polars: $
`C_l-\alpha`
$
,
`C_d-\alpha`
$
,
$
`C_m-\alpha`
$
,
$
`C_l/C_d-\alpha`
$
,
$
`C_l-C_d`
$.
```
matlab
import
af_tools
.
plotpolars
...
...
This diff is collapsed.
Click to expand it.
tests/test_trimtorange.m
0 → 100644
+
169
−
0
View file @
dc49c400
% TEST_TRIMTORANGE Unitary tests for the trimtorange sub-function
% Note:
% The function needs to be imported at each test, because apparently Matlab
% does not pass it from setupOnce() or setup().
% For some reasons, the whole package needs to be imported, not just the
% function under testing.
% -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ------------------------------------------------------------------------------
%% Main test function
function
tests
=
test_trimtorange
tests
=
functiontests
(
localfunctions
);
end
%% Setup and teardown
function
setupOnce
(
testCase
)
% do not change function name
addpath
(
'../.'
);
% Add repository to Matlab Path
addpath
(
'./test_utils'
);
% Add utils to Matlab Path
% Set random number generator settings.
testCase
.
TestData
.
currentRNG
=
rng
;
end
function
teardownOnce
(
testCase
)
% do not change function name
rmpath
(
'../.'
);
% Remove repository from Matlab Path
rmpath
(
'./test_utils'
);
% Remove utils from Matlab Path
% Restore the random number generator settings.
s
=
testCase
.
TestData
.
currentRNG
;
rng
(
s
)
end
function
teardown
(
~
)
% do not change function name
close
all
;
% Close all figures that would have been openend
end
%% Arguments and error tests
function
test_nargout
(
testCase
)
% Ensure that the function throws an error too many output
import
af_tools
.
utils
.*
range
=
[
-
5
;
5
];
dummy
=
-
10
:
10
;
[
~
,
~
]
=
verifyError
(
testCase
,
@
()
trimtorange
(
range
,
dummy
),
'MATLAB:nargoutchk:tooManyOutputs'
);
[
~
,
~
,
~
]
=
verifyError
(
testCase
,
@
()
trimtorange
(
range
,
dummy
,
dummy
),
'MATLAB:nargoutchk:tooManyOutputs'
);
end
%% Test for correct output
function
test_rangeInAOA
(
testCase
)
% Ensure proper output if range is fully contained in alpha
import
af_tools
.
utils
.*
range
=
[
-
1
,
1
]
'
;
alpha
=
(
-
10
:
10
)
'
;
cl
=
alpha
+
10
;
cd
=
alpha
-
10
;
expAlphaTrim
=
(
-
1
:
1
)
'
;
[
alphaTrim
,
clTrim
,
cdTrim
]
=
trimtorange
(
range
,
alpha
,
cl
,
cd
);
verifyEqual
(
testCase
,
alphaTrim
,
expAlphaTrim
);
verifyEqual
(
testCase
,
clTrim
,
expAlphaTrim
+
10
);
verifyEqual
(
testCase
,
cdTrim
,
expAlphaTrim
-
10
);
end
function
test_rangeOutAOA
(
testCase
)
% If range is all out of AOA, just return the input
import
af_tools
.
utils
.*
range
=
[
-
20
,
-
15
]
'
;
alpha
=
(
-
10
:
10
)
'
;
cl
=
alpha
+
10
;
cd
=
alpha
-
10
;
[
alphaTrim
,
clTrim
,
cdTrim
]
=
trimtorange
(
range
,
alpha
,
cl
,
cd
);
verifyEqual
(
testCase
,
alphaTrim
,
alpha
);
verifyEqual
(
testCase
,
clTrim
,
cl
);
verifyEqual
(
testCase
,
cdTrim
,
cd
);
end
function
test_rangePartOutAOA
(
testCase
)
% Ensure proper output if range is partially out of alpha
import
af_tools
.
utils
.*
range
=
(
-
20
:
0
)
'
;
alpha
=
(
-
10
:
10
)
'
;
cl
=
alpha
+
10
;
cd
=
alpha
-
10
;
expAlphaTrim
=
(
-
10
:
0
)
'
;
[
alphaTrim
,
clTrim
,
cdTrim
]
=
trimtorange
(
range
,
alpha
,
cl
,
cd
);
verifyEqual
(
testCase
,
alphaTrim
,
expAlphaTrim
);
verifyEqual
(
testCase
,
clTrim
,
expAlphaTrim
+
10
);
verifyEqual
(
testCase
,
cdTrim
,
expAlphaTrim
-
10
);
end
function
test_rangeEqualAOA
(
testCase
)
% Ensure proper output if range is equal to alpha
import
af_tools
.
utils
.*
alpha
=
(
-
10
:
10
)
'
;
range
=
(
-
10
:
10
)
'
;
cl
=
(
20
:
40
)
'
;
cd
=
(
-
20
:
0
)
'
;
[
alphaTrim
,
clTrim
,
cdTrim
]
=
trimtorange
(
range
,
alpha
,
cl
,
cd
);
verifyEqual
(
testCase
,
alphaTrim
,
alpha
);
verifyEqual
(
testCase
,
clTrim
,
cl
);
verifyEqual
(
testCase
,
cdTrim
,
cd
);
end
function
test_scalarRange
(
testCase
)
% Ensure proper output if range is a scalar
import
af_tools
.
utils
.*
range
=
(
0
)
'
;
alpha
=
(
-
10
:
10
)
'
;
cl
=
alpha
+
10
;
cd
=
alpha
-
10
;
expAlphaTrim
=
0
;
[
alphaTrim
,
clTrim
,
cdTrim
]
=
trimtorange
(
range
,
alpha
,
cl
,
cd
);
verifyEqual
(
testCase
,
alphaTrim
,
expAlphaTrim
);
verifyEqual
(
testCase
,
clTrim
,
expAlphaTrim
+
10
);
verifyEqual
(
testCase
,
cdTrim
,
expAlphaTrim
-
10
);
end
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