Skip to content
Snippets Groups Projects
Verified Commit 4d6ba1e6 authored by Thomas Lambert's avatar Thomas Lambert :helicopter:
Browse files

doc: add details to contributing, emph on MISS_HIT

parent 40edff04
No related branches found
No related tags found
No related merge requests found
Showing
with 444 additions and 328 deletions
function str = appendextension(str, ext) function str = appendextension(str, ext)
% APPENDEXTENSION Append an extension to a string. % APPENDEXTENSION Append an extension to a string.
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
if isempty(regexp(str, [ext, '$'], 'once')) if isempty(regexp(str, [ext, '$'], 'once'))
......
enable: 1
function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, varargin) function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, varargin)
% PARSEFILEINPUTS Parses the input and checks their validity. % PARSEFILEINPUTS Parses the input and checks their validity.
% Returns the filenames and filepaths for the input files, as well as the % Returns the filenames and filepaths for the input files, as well as the index where the
% index where the remaining options start. % remaining options start.
% %
% ----- % % -----
% Usage: % Usage:
% [filenames, filepaths, idxOpts] = PARSEPOLARINPUTS (optList, filetype) % [filenames, filepaths, idxOpts] = PARSEPOLARINPUTS (optList, filetype)
% [filenames, filepaths, idxOpts] = PARSEPOLARINPUTS (optList, filetype, ...) % [filenames, filepaths, idxOpts] = PARSEPOLARINPUTS (optList, filetype, ...)
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
import af_tools.utils.* import af_tools.utils.*
...@@ -67,7 +69,7 @@ function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, va ...@@ -67,7 +69,7 @@ function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, va
'it must contain only character vectors!\n']); 'it must contain only character vectors!\n']);
end end
% ------------------------------------------------------ % ---------------------------------------
% Look for files % Look for files
% Get absolute path % Get absolute path
...@@ -107,7 +109,7 @@ function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, va ...@@ -107,7 +109,7 @@ function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, va
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function bool = isoption(optList, var) function bool = isoption(optList, var)
% ISOPTION Returns true if var is contained in option list % ISOPTION Returns true if var is contained in option list
......
function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin) function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin)
% PARSENACAINPUTS Parses the inputs for naca* functions and checks their validity. % PARSENACAINPUTS Parses the inputs for naca* functions and checks their validity.
% Returns the naca denomination, the number of points and the index where the % Returns the naca denomination, the number of points and the index where the remaining
% remaining options start. % options start.
% If some inputs were not provided, the functions returns an empty array for % If some inputs were not provided, the functions returns an empty array for those.
% those.
% %
% ----- % -----
% Usage: % Usage:
...@@ -13,10 +12,12 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin) ...@@ -13,10 +12,12 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin)
% [...] = PARSEPOLARINPUTS (optList, DIGITS, NPOINTS, ...) % [...] = PARSEPOLARINPUTS (optList, DIGITS, NPOINTS, ...)
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
import af_tools.utils.* import af_tools.utils.*
...@@ -97,7 +98,7 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin) ...@@ -97,7 +98,7 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function bool = isoption(optList, var) function bool = isoption(optList, var)
% ISOPTION Returns true if var is contained in option list % ISOPTION Returns true if var is contained in option list
......
function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin) function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin)
% PARSEPOLARINPUTS Parses the input and checks their validity. % PARSEPOLARINPUTS Parses the input and checks their validity.
% Returns the arrays for the main polar arrays (alpha, cl, cd, cm), as well as % Returns the arrays for the main polar arrays (alpha, cl, cd, cm), as well as the index where
% the index where the remaining options start. % the remaining options start.
% If some inputs were not provided (alpha, cl, cd, cm), the functions returns % If some inputs were not provided (alpha, cl, cd, cm), the functions returns an empty array
% an empty array for those. % for those.
% %
% This function also contains checks on every "polar" input (i.e. the Polar % This function also contains checks on every "polar" input (i.e. the Polar strcture or the
% strcture or the four arrays: alpha, cl, cd and cm) to ensure they are % four arrays: alpha, cl, cd and cm) to ensure they are correct.
% correct.
% %
% ----- % -----
% Usage: % Usage:
...@@ -19,10 +18,12 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin) ...@@ -19,10 +18,12 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin)
% [...] = PARSEPOLARINPUTS (optList, ALPHA, CL, CD, CM, ...) % [...] = PARSEPOLARINPUTS (optList, ALPHA, CL, CD, CM, ...)
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
import af_tools.utils.* import af_tools.utils.*
...@@ -79,18 +80,9 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin) ...@@ -79,18 +80,9 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin)
validateattributes(alpha, {'numeric'}, {'real', '2d', 'nonempty', 'increasing'}, ... validateattributes(alpha, {'numeric'}, {'real', '2d', 'nonempty', 'increasing'}, ...
mfilename(), 'alpha', 1); mfilename(), 'alpha', 1);
if ~isempty(cl) checkarray(cl, size(alpha, 1), 2);
validateattributes(cl, {'numeric'}, {'real', 'nrows', size(alpha, 1), 'nonempty'}, ... checkarray(cd, size(alpha, 1), 3);
mfilename(), 'cl', 2); checkarray(cm, size(alpha, 1), 4);
end
if ~isempty(cd)
validateattributes(cd, {'numeric'}, {'real', 'nrows', size(alpha, 1), 'nonempty'}, ...
mfilename(), 'cd', 3);
end
if ~isempty(cm)
validateattributes(cm, {'numeric'}, {'real', 'nrows', size(alpha, 1), 'nonempty'}, ...
mfilename(), 'cm', 4);
end
% Standardize alpha size so we have one column per Polar as well % Standardize alpha size so we have one column per Polar as well
if size(alpha, 2) == 1 && ~isempty(cl) if size(alpha, 2) == 1 && ~isempty(cl)
...@@ -99,14 +91,14 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin) ...@@ -99,14 +91,14 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function bool = isoption(optList, var) function bool = isoption(optList, var)
% ISOPTION Returns true if var is contained in option list % ISOPTION Returns true if var is contained in option list.
bool = any(strcmpi(var, optList)); bool = any(strcmpi(var, optList));
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function [alpha, cl, cd, cm] = extractpolar(Polar) function [alpha, cl, cd, cm] = extractpolar(Polar)
% EXTRACTPOLAR Extract alpha, cl, cd and cm fields Polar structure. % EXTRACTPOLAR Extract alpha, cl, cd and cm fields Polar structure.
...@@ -116,7 +108,7 @@ function [alpha, cl, cd, cm] = extractpolar(Polar) ...@@ -116,7 +108,7 @@ function [alpha, cl, cd, cm] = extractpolar(Polar)
cm = Polar.cm; cm = Polar.cm;
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function [var, idxOpts, foundOpts] = assignvar(optList, var, data, idx) function [var, idxOpts, foundOpts] = assignvar(optList, var, data, idx)
% ASSIGNVAR Assign varargin value to a variable, ouptut corresponding idxOpts. % ASSIGNVAR Assign varargin value to a variable, ouptut corresponding idxOpts.
...@@ -130,3 +122,14 @@ function [var, idxOpts, foundOpts] = assignvar(optList, var, data, idx) ...@@ -130,3 +122,14 @@ function [var, idxOpts, foundOpts] = assignvar(optList, var, data, idx)
end end
end end
% --------------------------------------------------------------------------------------------------
function checkarray(array, nrows, idx)
% CHECKARRAY Checks type and diemnsions of array.
if ~isempty(array)
validateattributes(array, {'numeric'}, {'real', 'nrows', nrows, 'nonempty'}, ...
mfilename(), inputname(1), idx);
end
end
function str = sanitizestring(str) function str = sanitizestring(str)
% SANITIZESTRING Santitizes a string by replacing unwanted characters. % SANITIZESTRING Santitizes a string by replacing unwanted characters.
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
% Mapping table (maps unwanted chars with their replacements) % Mapping table (maps unwanted chars with their replacements)
......
function savetodat(filename, header, varargin) function savetodat(filename, header, varargin)
% SAVETODAT Saves input table or list of vectors to a dat file % SAVETODAT Saves input table or list of vectors to a dat file
% Note: % Note:
% This inputs need to have the same dimensions to be concatenated into a % This inputs need to have the same dimensions to be concatenated into a single output array.
% single output array.
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
import af_tools.utils.vecttocol import af_tools.utils.vecttocol
......
function vect = spacedvector(spacing, nPoints) function vect = spacedvector(spacing, nPoints)
% SPACEDVECTOR Returns a vector based on chosen spacing and number of points % SPACEDVECTOR Returns a vector based on chosen spacing and number of points
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
switch spacing switch spacing
......
function [alphaTrim, clTrim, cdTrim] = trimtorange(range, alpha, cl, cd) function [alphaTrim, clTrim, cdTrim] = trimtorange(range, alpha, cl, cd)
% TRIMTORANGE Trims polars to a given range of angles of attack. % TRIMTORANGE Trims polars to a given range of angles of attack.
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
narginchk(2, 4); narginchk(2, 4);
......
function var = vecttocol(var) function var = vecttocol(var)
% VECTTOCOL Transfor a row vector into a column vector. % VECTTOCOL Transfor a row vector into a column vector.
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
if isvector(var) if isvector(var)
......
function [alphaExt, clExt, cdExt] = extendpolar(varargin) function [alphaExt, clExt, cdExt] = extendpolar(varargin)
% EXTENDPOLAR Extends polars to the full range of AOA ([-180, 180] deg). % EXTENDPOLAR Extends polars to the full range of AOA ([-180, 180] deg).
% This function implements different empirical methods to extend the polars % This function implements different empirical methods to extend the polars outside of their
% outside of their usual range. % usual range.
% %
% EXTENDPOLAR accepts inputs in the form of a Polar structure (generated with % EXTENDPOLAR accepts inputs in the form of a Polar structure (generated with XF2MAT) or
% XF2MAT) or values for angles of attack and their associated cl and cd. % values for angles of attack and their associated cl and cd.
% %
% If the input is specified as aoa, cl and cd, the three arrays must have the % If the input is specified as aoa, cl and cd, the three arrays must have the same number of
% same number of rows (one for each angle of attack). The columns indicate % rows (one for each angle of attack). The columns indicate values for different polars
% values for different polars (different Mach, different Reynolds,...). % (different Mach, different Reynolds,...).
% For example, if the cl values are given for 2 different Reynols and there % For example, if the cl values are given for 2 different Reynols and there are 100 values for
% are 100 values for the aoa, cl and cd must be [100 x 2]. % the aoa, cl and cd must be [100 x 2].
% %
% IMPORTANT: % IMPORTANT:
% To be extended, the input polar must AT LEAST containt the points where % To be extended, the input polar must AT LEAST containt the points where AOA = 0 deg and
% AOA = 0 deg and stall point. % stall point.
% %
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a>
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/issues">Report an issue</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/issues">Report an issue</a>
% ----- % -----
% %
% Usage: % Usage:
% [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR prompts the user to input a Polar % [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR prompts the user to input a Polar structure and
% structure and extends the angle of attack (ALPHAEXT), lift coefficient % extends the angle of attack (ALPHAEXT), lift coefficient (CLEXT) and drag coefficient
% (CLEXT) and drag coefficient (CDEXT). % (CDEXT).
% %
% [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR(POLAR) uses the POLAR strcture given % [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR(POLAR) uses the POLAR strcture given as input instead
% as input instead of prompting the user to select the file. % of prompting the user to select the file.
% %
% [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR(ALPHA, CL, CD) extends directly the % [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR(ALPHA, CL, CD) extends directly the values given in
% values given in ALPHA, CL and CD over the whole range of angles of attack. % ALPHA, CL and CD over the whole range of angles of attack.
% %
% [...] = EXTENDPOLAR(..., 'method', METHOD) specifies the extension method. % [...] = EXTENDPOLAR(..., 'method', METHOD) specifies the extension method.
% The available methods are: % The available methods are:
%
% 'Viterna' - (default) Viterna & Corrigan. 1982. "Fixed Pitch Rotor % 'Viterna' - (default) Viterna & Corrigan. 1982. "Fixed Pitch Rotor
% Performance of Large Horizontal Axis Wind Turbines". % Performance of Large Horizontal Axis Wind Turbines".
% %
% [...] = EXTENDPOLAR(..., 'limit', LIMIT) specifies the point from where to % [...] = EXTENDPOLAR(..., 'limit', LIMIT) specifies the point from where to extend.
% extend. The available limits are: % The available limits are:
%
% 'last' - (default) last point of the input polar % 'last' - (default) last point of the input polar
% 'stall' - stall point, the points after stall are disregarded % 'stall' - stall point, the points after stall are disregarded
% %
...@@ -65,10 +63,12 @@ function [alphaExt, clExt, cdExt] = extendpolar(varargin) ...@@ -65,10 +63,12 @@ function [alphaExt, clExt, cdExt] = extendpolar(varargin)
% See also: XF2MAT, PLOTPOLARS. % See also: XF2MAT, PLOTPOLARS.
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
% Check number of inputs % Check number of inputs
...@@ -102,7 +102,7 @@ function [alphaExt, clExt, cdExt] = extendpolar(varargin) ...@@ -102,7 +102,7 @@ function [alphaExt, clExt, cdExt] = extendpolar(varargin)
'To be extended, a polar must at least contain the stall point.'); 'To be extended, a polar must at least contain the stall point.');
end end
% ------------------------------------ % -------------------------------------------
% Extend polars % Extend polars
if alpha(1, 1) == -pi || alpha(end, 1) == pi if alpha(1, 1) == -pi || alpha(end, 1) == pi
...@@ -120,7 +120,7 @@ function [alphaExt, clExt, cdExt] = extendpolar(varargin) ...@@ -120,7 +120,7 @@ function [alphaExt, clExt, cdExt] = extendpolar(varargin)
end end
% -------------------------------------------------------------------------- % --------------------------------------------------------------------------------------------------
function [method, limit] = parseoptioninputs(varargin) function [method, limit] = parseoptioninputs(varargin)
% PARSEINPUTS Parses the input and checks their validity % PARSEINPUTS Parses the input and checks their validity
...@@ -146,17 +146,17 @@ function [method, limit] = parseoptioninputs(varargin) ...@@ -146,17 +146,17 @@ function [method, limit] = parseoptioninputs(varargin)
end end
% -------------------------------------------------------------------------- % --------------------------------------------------------------------------------------------------
function [alphaExt, clExt, cdExt] = viterna(limit, alpha, cl, cd) function [alphaExt, clExt, cdExt] = viterna(limit, alpha, cl, cd)
% VITERNA Implementation of the original Viterna model % VITERNA Implementation of the original Viterna model
% Source: % Source:
% Viterna & Corrigan. 1982. "Fixed Pitch Rotor Performance of Large Horizontal % Viterna & Corrigan. 1982. "Fixed Pitch Rotor Performance of Large Horizontal Axis Wind
% Axis Wind Turbines". % Turbines".
% Note: % Note:
% The typical subscript 's' used in most definitions is here replaced by the % The typical subscript 's' used in most definitions is here replaced by the generic 'l'
% generic 'l' (for limit) as the function can be used either with the stall % (for limit) as the function can be used either with the stall point or the last available
% point or the last available data. % data.
% %
% Process (the number will indicate the index of alpha, cl, cd): % Process (the number will indicate the index of alpha, cl, cd):
% 1. Extend Cl/Cd to ]limit, 90] % 1. Extend Cl/Cd to ]limit, 90]
...@@ -260,12 +260,12 @@ function [alphaExt, clExt, cdExt] = viterna(limit, alpha, cl, cd) ...@@ -260,12 +260,12 @@ function [alphaExt, clExt, cdExt] = viterna(limit, alpha, cl, cd)
end end
% -------------------------------------------------------------------------- % --------------------------------------------------------------------------------------------------
function [cl, cd] = viternaeq(VitCoeffs, alpha, clScaling) function [cl, cd] = viternaeq(VitCoeffs, alpha, clScaling)
% VITERNAEQ Viterna's equation for the extension of the polars % VITERNAEQ Viterna's equation for the extension of the polars
% Source: % Source:
% Viterna & Corrigan. 1982. "Fixed Pitch Rotor Performance of Large Horizontal % Viterna & Corrigan. 1982. "Fixed Pitch Rotor Performance of Large Horizontal Axis Wind
% Axis Wind Turbines". % Turbines".
cl = VitCoeffs.a1 * sin(2 * alpha) + VitCoeffs.a2 * cos(alpha).^2 ./ sin(alpha); cl = VitCoeffs.a1 * sin(2 * alpha) + VitCoeffs.a2 * cos(alpha).^2 ./ sin(alpha);
cl = cl * clScaling; cl = cl * clScaling;
......
function [alphaRange, clRange, clSlope] = findcllinearrange(varargin) function [alphaRange, clRange, clSlope] = findcllinearrange(varargin)
% FINDCLLINEARRANGE Finds the linear range of the lift coefficient its slope. % FINDCLLINEARRANGE Finds the linear range of the lift coefficient its slope.
% This function approximates the lift coefficient linear range by looking at % This function approximates the lift coefficient linear range by looking at its first and
% its first and second derivatives (using hard-coded tolerance values). % second derivatives (using hard-coded tolerance values).
% %
% FINDCLLINEARRANGE accepts inputs in the form of a Polar structure (generated % FINDCLLINEARRANGE accepts inputs in the form of a Polar structure (generated with XF2MAT) or
% with XF2MAT) or values for angles of attack and their associated cl. % values for angles of attack and their associated cl.
% %
% If the input is specified as aoa and cl, the two arrays must have the % If the input is specified as aoa and cl, the two arrays must have the same number of rows
% same number of rows (one for each angle of attack). The columns indicate % (one for each angle of attack). The columns indicate values for different polars
% values for different polars (different Mach, different Reynolds,...). % (different Mach, different Reynolds,...).
% For example, if the cl values are given for 2 different Reynols and there % For example, if the cl values are given for 2 different Reynols and there are 100 values for
% are 100 values for the aoa, cl must be [100 x 2]. % the aoa, cl must be [100 x 2].
% %
% If extended polars are used as input (see EXTENDPOLAR), the function will % If extended polars are used as input (see EXTENDPOLAR), the function will only look for the
% only look for the zero-lift angle in the range of [-30, 30] deg. % zero-lift angle in the range of [-30, 30] deg.
% %
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a>
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/issues">Report an issue</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/issues">Report an issue</a>
% ----- % -----
% %
% Usage: % Usage:
% [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE prompts the user to % [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE prompts the user to input a Polar
% input a Polar structure and determines the range of angles of attach % structure and determines the range of angles of attach (ALPHA_RANGE) in which the cl is
% (ALPHA_RANGE) in which the cl is linear. It also outputs the values of the % linear. It also outputs the values of the lift coefficient in that range (CL_RANGE) and the
% lift coefficient in that range (CL_RANGE) and the slope of the linear cl % slope of the linear cl (CL_SLOPE).
% (CL_SLOPE).
% %
% [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE(POLAR) uses the POLAR % [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE(POLAR) uses the POLAR strcture given
% strcture given as input instead of prompting the user to select the file. % as input instead of prompting the user to select the file.
% %
% [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE(ALPHA, CL) uses % [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE(ALPHA, CL) uses directly the values
% directly the values given in ALPHA and CL to determine the linear range % given in ALPHA and CL to determine the linear range characteristics.
% characteristics.
% %
% Inputs: % Inputs:
% Polar : Polar structure (e.g. output from XF2MAT) % Polar : Polar structure (e.g. output from XF2MAT)
...@@ -51,10 +49,12 @@ function [alphaRange, clRange, clSlope] = findcllinearrange(varargin) ...@@ -51,10 +49,12 @@ function [alphaRange, clRange, clSlope] = findcllinearrange(varargin)
% See also: XF2MAT, FINDSTALL, FINDZEROLIFT. % See also: XF2MAT, FINDSTALL, FINDZEROLIFT.
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
narginchk(0, 2); narginchk(0, 2);
...@@ -82,7 +82,7 @@ end ...@@ -82,7 +82,7 @@ end
% -------------------------------------------------------------------------------------------------- % --------------------------------------------------------------------------------------------------
function [alphaRange, clRange, clSlope] = linearrangefinder(alpha, cl) function [alphaRange, clRange, clSlope] = linearrangefinder(alpha, cl)
% FINDLINEARRANGEVECT Finds the linearrange and returns the corresponding range and slope % FINDLINEARRANGEVECT Finds the linearrange and returns the corresponding range and slope.
% We consider that the linear range meets the two following criterions: % We consider that the linear range meets the two following criterions:
% - First derivative close to 2*pi (TOL_DCL defines how close) % - First derivative close to 2*pi (TOL_DCL defines how close)
% - Second derivative close to 0 (TOL_DDCL defines how close) % - Second derivative close to 0 (TOL_DDCL defines how close)
......
function [alpha_s, cl_s, cd_s] = findstall(varargin) function [alpha_s, cl_s, cd_s] = findstall(varargin)
% FINDSTALL Finds the stall point and returns the corresponding AOA, CL and CD. % FINDSTALL Finds the stall point and returns the corresponding AOA, CL and CD.
% This function uses Matlab's findpeak in order to determine the position of % This function uses Matlab's findpeak in order to determine the position of the stall point.
% the stall point.
% %
% FINDSTALL accepts inputs in the form of a Polar structure (generated with % FINDSTALL accepts inputs in the form of a Polar structure (generated with XF2MAT) or values
% XF2MAT) or values for angles of attack and their associated cl and cd. While % for angles of attack and their associated cl and cd. While alpha and cl are required for
% alpha and cl are required for this function, cd is optional. If it is % this function, cd is optional. If it is provided, the function will return the drag value at
% provided, the function will return the drag value at stall as well, else % stall as well, else the cd_s will be an empty vector.
% the cd_s will be an empty vector.
% %
% If the input is specified as aoa, cl and cd, the three arrays must have the % If the input is specified as aoa, cl and cd, the three arrays must have the same number of
% same number of rows (one for each angle of attack). The columns indicate % rows (one for each angle of attack). The columns indicate values for different polars
% values for different polars (different Mach, different Reynolds,...). % (different Mach, different Reynolds,...).
% For example, if the cl values are given for 2 different Reynols and there % For example, if the cl values are given for 2 different Reynols and there are 100 values for
% are 100 values for the aoa, cl and cd must be [100 x 2]. % the aoa, cl and cd must be [100 x 2].
% %
% If extended polars are used as input (see EXTENDPOLAR), the function will % If extended polars are used as input (see EXTENDPOLAR), the function will only look for the
% only look for the zero-lift angle in the range of [0, 30] deg. % zero-lift angle in the range of [0, 30] deg.
% %
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a>
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/issues">Report an issue</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/issues">Report an issue</a>
% ----- % -----
% %
% Usage: % Usage:
% [ALPHA_S, CL_S, CD_S] = FINDSTALL prompts the user to input a Polar % [ALPHA_S, CL_S, CD_S] = FINDSTALL prompts the user to input a Polar structure and determines
% structure and determines the stall angle of attack (ALPHA_S), the lift % the stall angle of attack (ALPHA_S), the lift coefficient value at stall (CL_S) and the drag
% coefficient value at stall (CL_S) and the drag coefficient at stall (CD_S). % coefficient at stall (CD_S).
% %
% [ALPHA_S, CL_S, CD_S] = FINDSTALL(POLAR) uses the POLAR strcture given % [ALPHA_S, CL_S, CD_S] = FINDSTALL(POLAR) uses the POLAR strcture given as input instead of
% as input instead of prompting the user to select the file. % prompting the user to select the file.
% %
% [ALPHA_S, CL_S, CD_S] = FINDSTALL(ALPHA, CL, CD) uses directly the values % [ALPHA_S, CL_S, CD_S] = FINDSTALL(ALPHA, CL, CD) uses directly the values given in in ALPHA,
% given in in ALPHA, CL and CD to determine the stall. % CL and CD to determine the stall.
% %
% Inputs: % Inputs:
% Polar : Polar structure (e.g. output from XF2MAT) % Polar : Polar structure (e.g. output from XF2MAT)
...@@ -53,10 +51,12 @@ function [alpha_s, cl_s, cd_s] = findstall(varargin) ...@@ -53,10 +51,12 @@ function [alpha_s, cl_s, cd_s] = findstall(varargin)
% See also: XF2MAT, FINDZEROLIFT, FINDCLLINEARRANGE. % See also: XF2MAT, FINDZEROLIFT, FINDCLLINEARRANGE.
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
narginchk(0, 3); narginchk(0, 3);
...@@ -75,14 +75,14 @@ function [alpha_s, cl_s, cd_s] = findstall(varargin) ...@@ -75,14 +75,14 @@ function [alpha_s, cl_s, cd_s] = findstall(varargin)
% (avoid issues if extended polars are used as input) % (avoid issues if extended polars are used as input)
[alpha, cl, cd] = trimtorange(ORIGINAL_RANGE, alpha, cl, cd); [alpha, cl, cd] = trimtorange(ORIGINAL_RANGE, alpha, cl, cd);
% ------------------------------------ % -------------------------------------------
% Find stall for each polar % Find stall for each polar
[alpha_s, cl_s, cd_s] = stallfinder(alpha, cl, cd); [alpha_s, cl_s, cd_s] = stallfinder(alpha, cl, cd);
end end
% -------------------------------------------------------------------------- % --------------------------------------------------------------------------------------------------
function [alpha_s, cl_s, cd_s] = stallfinder(alpha, cl, cd) function [alpha_s, cl_s, cd_s] = stallfinder(alpha, cl, cd)
% STALLFINDER Finds the stall point and returns the corresponding AOA, CL and CD % STALLFINDER Finds the stall point and returns the corresponding AOA, CL and CD
......
function [alpha_zeroL, cd_zeroL] = findzerolift(varargin) function [alpha_zeroL, cd_zeroL] = findzerolift(varargin)
% FINDZEROLIFT Finds the zero-lift angle and the associated cd. % FINDZEROLIFT Finds the zero-lift angle and the associated cd.
% This function finds the zero-lift angle by interpolating around the last % This function finds the zero-lift angle by interpolating around the last negative and first
% negative and first positive values for the lift coefficient. % positive values for the lift coefficient.
% %
% FINDZEROLIFT accepts inputs in the form of a Polar structure (generated with % FINDZEROLIFT accepts inputs in the form of a Polar structure (generated with XF2MAT) or
% XF2MAT) or values for angles of attack and their associated cl and cd. % values for angles of attack and their associated cl and cd.
% %
% If the input is specified as aoa, cl and cd, the three arrays must have the % If the input is specified as aoa, cl and cd, the three arrays must have the same number of
% same number of rows (one for each angle of attack). The columns indicate % rows (one for each angle of attack). The columns indicate values for different polars
% values for different polars (different Mach, different Reynolds,...). % (different Mach, different Reynolds,...).
% For example, if the cl values are given for 2 different Reynols and there % For example, if the cl values are given for 2 different Reynols and there are 100 values for
% are 100 values for the aoa, cl and cd must be [100 x 2]. % the aoa, cl and cd must be [100 x 2].
% %
% If extended polars are used as input (see EXTENDPOLAR), the function will % If extended polars are used as input (see EXTENDPOLAR), the function will only look for the
% only look for the zero-lift angle in the range of [-30, 30] deg. % zero-lift angle in the range of [-30, 30] deg.
% %
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a>
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/issues">Report an issue</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/issues">Report an issue</a>
% ----- % -----
% %
% Usage: % Usage:
% [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT prompts the user to input a Polar % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT prompts the user to input a Polar structure and
% structure and determines the zero-lift angle of attack (ALPHA_ZEROL) and the % determines the zero-lift angle of attack (ALPHA_ZEROL) and the drag coefficient at this
% drag coefficient at this angle (CD_ZEROL). % angle (CD_ZEROL).
% %
% [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(POLAR) uses the POLAR strcture given % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(POLAR) uses the POLAR strcture given as input instead
% as input instead of prompting the user to select the file. % of prompting the user to select the file.
% %
% [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(ALPHA, CL) uses directly the values % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(ALPHA, CL) uses directly the values given in in ALPHA
% given in in ALPHA and CL to determine the zero-lift angle. As no CD is % and CL to determine the zero-lift angle. As no CD is provided, CD_ZEROL will be an empty
% provided, CD_ZEROL will be an empty vector. % vector.
% %
% [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(ALPHA, CL, CD) uses directly the % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(ALPHA, CL, CD) uses directly the values given in in
% values given in in ALPHA and CL to determine the zero-lift angle. As CD is % ALPHA and CL to determine the zero-lift angle. As CD is provided, CD_ZEROL will be returned
% provided, CD_ZEROL will be returned as well. % as well.
% %
% Inputs: % Inputs:
% Polar : Polar structure (e.g. output from XF2MAT) % Polar : Polar structure (e.g. output from XF2MAT)
...@@ -54,10 +54,12 @@ function [alpha_zeroL, cd_zeroL] = findzerolift(varargin) ...@@ -54,10 +54,12 @@ function [alpha_zeroL, cd_zeroL] = findzerolift(varargin)
% See also: XF2MAT, FINDSTALL, FINDCLLINEARRANGE. % See also: XF2MAT, FINDSTALL, FINDCLLINEARRANGE.
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
narginchk(0, 3); narginchk(0, 3);
...@@ -76,14 +78,14 @@ function [alpha_zeroL, cd_zeroL] = findzerolift(varargin) ...@@ -76,14 +78,14 @@ function [alpha_zeroL, cd_zeroL] = findzerolift(varargin)
% (avoid issues if extended polars are used as input) % (avoid issues if extended polars are used as input)
[alpha, cl, cd] = trimtorange(ORIGINAL_RANGE, alpha, cl, cd); [alpha, cl, cd] = trimtorange(ORIGINAL_RANGE, alpha, cl, cd);
% ------------------------------------ % -------------------------------------------
% Find zero lift for each polar % Find zero lift for each polar
[alpha_zeroL, cd_zeroL] = zerofinder(alpha, cl, cd); [alpha_zeroL, cd_zeroL] = zerofinder(alpha, cl, cd);
end end
% -------------------------------------------------------------------------- % --------------------------------------------------------------------------------------------------
function [alpha_zeroL, cd_zeroL] = zerofinder(alpha, cl, cd) function [alpha_zeroL, cd_zeroL] = zerofinder(alpha, cl, cd)
% FINDZEROLIFTVECT Finds the zero-lift point and returns the corresponding AOA and CD % FINDZEROLIFTVECT Finds the zero-lift point and returns the corresponding AOA and CD
% For vectors! % For vectors!
......
function [x, y] = nacaairfoil(varargin) function [x, y] = nacaairfoil(varargin)
% NACAAIRFOIL Generates the full coordinates of a NACA 4 or 5 digits airfoil. % NACAAIRFOIL Generates the full coordinates of a NACA 4 or 5 digits airfoil.
% By default, the airfoil is generated with 100 points distributed % By default, the airfoil is generated with 100 points distributed following a half-cosine
% following a half-cosine rule in order to be finer at the leading and % rule in order to be finer at the leading and trailing edges. The default output has a zero
% trailing edges. The default output has a zero thickness trailing edge. % thickness trailing edge. Coefficients for a finite trailing edge are also implemented.
% Coefficients for a finite trailing edge are also implemented.
% See below for details on how to override the defaults. % See below for details on how to override the defaults.
% %
% Note: % Note:
% This function will always output an odd number of points, even if the user % This function will always output an odd number of points, even if the user asks for an even
% asks for an even value of nPoints. This is because the upper and % value of nPoints. This is because the upper and lower surfaces will have the same number of
% lower surfaces will have the same number of points, and the leading % points, and the leading edge is counted twice (as the first and last element to close the
% edge is counted twice (as the first and last element to close the shape) % shape) while the trailing edge is counted once.
% while the trailing edge is counted once.
% %
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a>
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/issues">Report an issue</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/issues">Report an issue</a>
% ----- % -----
% %
% Usage: % Usage:
% [X, Y] = NACAAIRFOIL prompts the user for the airfoil denomination, then % [X, Y] = NACAAIRFOIL prompts the user for the airfoil denomination, then determines its
% determines its coordinates. % coordinates.
% %
% [X, Y] = NACAAIRFOIL(DIGITS) determines the coordinates of the airfoil using % [X, Y] = NACAAIRFOIL(DIGITS) determines the coordinates of the airfoil using the airfoil
% the airfoil denomination given by DIGITS. % denomination given by DIGITS.
% %
% [X, Y] = NACAAIRFOIL(DIGITS, NPOINTS) determines the NPOINTS coordinates of % [X, Y] = NACAAIRFOIL(DIGITS, NPOINTS) determines the NPOINTS coordinates of the airfoil
% the airfoil named after DIGITS. % named after DIGITS.
%
% [...] = NACAAIRFOIL(..., 'spacing', SP) uses the defined spacing rule to
% determine to position of the coordinates. The available spacings are:
% %
% [...] = NACAAIRFOIL(..., 'spacing', SP) uses the defined spacing rule to determine to
% position of the coordinates. The available spacings are:
% 'linear' - linear % 'linear' - linear
% 'halfcosine' - (default) finer at leading and trailing edges % 'halfcosine' - (default) finer at leading and trailing edges
% 'cosine' - finer at leading edge, coarser at the trailing edge % 'cosine' - finer at leading edge, coarser at the trailing edge
% %
% [...] = NACAAIRFOIL(..., 'zerote', TE) picks between the zero thickness % [...] = NACAAIRFOIL(..., 'zerote', TE) picks between the zero thickness trailing edge or a
% trailing edge or a finite one. The values for zerote are: % finite one. The values for zerote are:
%
% true - (default) zero thickness trailing edge % true - (default) zero thickness trailing edge
% false - finite trailing edge % false - finite trailing edge
% %
% [...] = NACAAIRFOIL(..., 'savedat', false) saves the output coordinates in a % [...] = NACAAIRFOIL(..., 'savedat', false) saves the output coordinates in a dat-file.
% dat files. savedat can either be true or false (default). % savedat can either be true or false (default).
% %
% Inputs: % Inputs:
% digits : Character vector representing the NACA airfoil (ex: '0012', '24120', '24012') % digits : Character vector representing the NACA airfoil (ex: '0012', '24120', '24012')
...@@ -49,9 +45,9 @@ function [x, y] = nacaairfoil(varargin) ...@@ -49,9 +45,9 @@ function [x, y] = nacaairfoil(varargin)
% %
% Output: % Output:
% [X, Y] : Airfoil coordinates, with 0 <= X <= 1. % [X, Y] : Airfoil coordinates, with 0 <= X <= 1.
% The output coordinates follow the most usual order. They start at % The output coordinates follow the most usual order. They start at the trailing
% the trailing edge, along the upper surface to the leading edge and % edge, along the upper surface to the leading edge and back around the lower surface
% back around the lower surface to trailing edge. % to trailing edge.
% %
% Example: % Example:
% NACAAIRFOIL % NACAAIRFOIL
...@@ -63,10 +59,12 @@ function [x, y] = nacaairfoil(varargin) ...@@ -63,10 +59,12 @@ function [x, y] = nacaairfoil(varargin)
% See also: NACACAMBER. % See also: NACACAMBER.
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
narginchk(0, 6); narginchk(0, 6);
...@@ -81,11 +79,11 @@ function [x, y] = nacaairfoil(varargin) ...@@ -81,11 +79,11 @@ function [x, y] = nacaairfoil(varargin)
[digits, nPoints, idxOpts] = parsenacainputs(OPTION_LIST, varargin{:}); [digits, nPoints, idxOpts] = parsenacainputs(OPTION_LIST, varargin{:});
[spacing, zerote, savedat] = parseoptioninputs(varargin{idxOpts:end}); [spacing, zerote, savedat] = parseoptioninputs(varargin{idxOpts:end});
% ------------------------------------ % -------------------------------------------
% Coordinates calculation % Coordinates calculation
% Get camberline (we use ceil((nPoints+1)/2) to ensure the airfoil has the same % Get camberline (we use ceil((nPoints+1)/2) to ensure the airfoil has the same number of points
% number of points on the upper and lower surfaces. % on the upper and lower surfaces.
[xc, yc, gradY] = nacacamber(digits, ceil((nPoints + 1) / 2), 'spacing', spacing); [xc, yc, gradY] = nacacamber(digits, ceil((nPoints + 1) / 2), 'spacing', spacing);
% Flip camberline, so the first element is the trailing edge % Flip camberline, so the first element is the trailing edge
...@@ -129,7 +127,7 @@ function [x, y] = nacaairfoil(varargin) ...@@ -129,7 +127,7 @@ function [x, y] = nacaairfoil(varargin)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function [spacing, zerote, savedat] = parseoptioninputs(varargin) function [spacing, zerote, savedat] = parseoptioninputs(varargin)
% PARSEOPTIONINPUTS Parses the options and checks their validity % PARSEOPTIONINPUTS Parses the options and checks their validity
......
function [xc, yc, gradY] = nacacamber(varargin) function [xc, yc, gradY] = nacacamber(varargin)
% NACACAMBER Generates the coordinates of the camberline for a NACA 4 or 5 digits airfoil. % NACACAMBER Generates the coordinates of the camberline for a NACA 4 or 5 digits airfoil.
% By default, the camberline is generated with 100 points distributed % By default, the camberline is generated with 100 points distributed following a half-cosine
% following a half-cosine rule in order to be finer at the leading and % rule in order to be finer at the leading and trailing edges.
% trailing edges.
% See below for details on how to override the defaults. % See below for details on how to override the defaults.
% %
% <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a> % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a>
...@@ -10,20 +9,17 @@ function [xc, yc, gradY] = nacacamber(varargin) ...@@ -10,20 +9,17 @@ function [xc, yc, gradY] = nacacamber(varargin)
% ----- % -----
% %
% Usage: % Usage:
% [X, Y] = NACACAMBER prompts the user for the airfoil digits, then calculates % [X, Y] = NACACAMBER prompts the user for the airfoil digits, then calculates the coordinates
% the coordinates of the camberline using 100 points spaced with the % of the camberline using 100 points spaced with the half-cosine rule.
% half-cosine rule.
% %
% [X, Y] = NACACAMBER(DIGITS) calculates the coordinates of the camberline for % [X, Y] = NACACAMBER(DIGITS) calculates the coordinates of the camberline for the NACA
% the NACA airfoil specified by DIGITS, without further input. % airfoil specified by DIGITS, without further input.
% %
% [X, Y] = NACACAMBER(DIGITS, NPOINTS) calculates the coordinates of the % [X, Y] = NACACAMBER(DIGITS, NPOINTS) calculates the coordinates of the NACA airfoil
% the NACA airfoil specified by DIGITS, using NPOINTS points spaced with the % specified by DIGITS, using NPOINTS points spaced with the half-cosine rule.
% half-cosine rule.
%
% [...] = NACACAMBER(..., 'spacing', SP) uses the defined spacing rule to
% determine to position of the coordinates. The available spacings are:
% %
% [...] = NACACAMBER(..., 'spacing', SP) uses the defined spacing rule to determine to
% position of the coordinates. The available spacings are:
% 'linear' - linear % 'linear' - linear
% 'halfcosine' - (default) finer at leading and trailing edges % 'halfcosine' - (default) finer at leading and trailing edges
% 'cosine' - finer at leading edge, coarser at the trailing edge % 'cosine' - finer at leading edge, coarser at the trailing edge
...@@ -46,10 +42,12 @@ function [xc, yc, gradY] = nacacamber(varargin) ...@@ -46,10 +42,12 @@ function [xc, yc, gradY] = nacacamber(varargin)
% See also: NACAAIRFOIL. % See also: NACAAIRFOIL.
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
narginchk(0, 4); narginchk(0, 4);
...@@ -63,7 +61,7 @@ function [xc, yc, gradY] = nacacamber(varargin) ...@@ -63,7 +61,7 @@ function [xc, yc, gradY] = nacacamber(varargin)
[digits, nPoints, idxOpts] = parsenacainputs(OPTION_LIST, varargin{:}); [digits, nPoints, idxOpts] = parsenacainputs(OPTION_LIST, varargin{:});
[spacing] = parseoptioninputs(varargin{idxOpts:end}); [spacing] = parseoptioninputs(varargin{idxOpts:end});
% ------------------------------------ % -------------------------------------------
% Coordinates calculation % Coordinates calculation
if length(digits) == 4 if length(digits) == 4
...@@ -74,7 +72,7 @@ function [xc, yc, gradY] = nacacamber(varargin) ...@@ -74,7 +72,7 @@ function [xc, yc, gradY] = nacacamber(varargin)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function [spacing] = parseoptioninputs(varargin) function [spacing] = parseoptioninputs(varargin)
% PARSEINPUTS Parses the input and checks their validity % PARSEINPUTS Parses the input and checks their validity
...@@ -95,7 +93,7 @@ function [spacing] = parseoptioninputs(varargin) ...@@ -95,7 +93,7 @@ function [spacing] = parseoptioninputs(varargin)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function [xc, yc, gradY] = camber4digits(digits, nPoints, spacing) function [xc, yc, gradY] = camber4digits(digits, nPoints, spacing)
% CAMBER4DIGITS Give the camberline coordinates for a 4 digits airfoil. % CAMBER4DIGITS Give the camberline coordinates for a 4 digits airfoil.
% %
...@@ -127,7 +125,7 @@ function [xc, yc, gradY] = camber4digits(digits, nPoints, spacing) ...@@ -127,7 +125,7 @@ function [xc, yc, gradY] = camber4digits(digits, nPoints, spacing)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function [xc, yc, gradY] = camber5digits(digits, nPoints, spacing) function [xc, yc, gradY] = camber5digits(digits, nPoints, spacing)
% CAMBER5DIGITS Give the camberline coordinates for a 5 digits airfoil. % CAMBER5DIGITS Give the camberline coordinates for a 5 digits airfoil.
% %
...@@ -178,7 +176,7 @@ function [xc, yc, gradY] = camber5digits(digits, nPoints, spacing) ...@@ -178,7 +176,7 @@ function [xc, yc, gradY] = camber5digits(digits, nPoints, spacing)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function [r, k1, k2k1] = getcoeffs5digits(q, p) function [r, k1, k2k1] = getcoeffs5digits(q, p)
% GETCOEFFS5DIGITS Coefficients for the NACA 5-digit formula. % GETCOEFFS5DIGITS Coefficients for the NACA 5-digit formula.
% Source: http://www.airfoiltools.com/airfoil/naca5digit % Source: http://www.airfoiltools.com/airfoil/naca5digit
......
...@@ -2,14 +2,14 @@ function plotpolars(varargin) ...@@ -2,14 +2,14 @@ function plotpolars(varargin)
% PLOTPOLARS Plot various polars. % PLOTPOLARS Plot various polars.
% Plots the typical polars curves of an airfoil. % Plots the typical polars curves of an airfoil.
% %
% PLOTPOLARS accepts inputs in the form of a Polar structure (generated with % PLOTPOLARS accepts inputs in the form of a Polar structure (generated with XF2MAT) or values
% XF2MAT) or values for angles of attack and their associated cl, cd and cm. % for angles of attack and their associated cl, cd and cm.
% %
% If the input is specified as aoa, cl and cd, the three arrays must have the % If the input is specified as aoa, cl and cd, the three arrays must have the same number of
% same number of rows (one for each angle of attack). The columns indicate % rows (one for each angle of attack). The columns indicate values for different polars
% values for different polars (different Mach, different Reynolds,...). % (different Mach, different Reynolds,...).
% For example, if the cl values are given for 2 different Reynols and there % For example, if the cl values are given for 2 different Reynols and there are 100 values for
% are 100 values for the aoa, cl and cd must be [100 x 2]. % the aoa, cl and cd must be [100 x 2].
% %
% Plots: % Plots:
% - Cl - aoa % - Cl - aoa
...@@ -23,20 +23,19 @@ function plotpolars(varargin) ...@@ -23,20 +23,19 @@ function plotpolars(varargin)
% ----- % -----
% %
% Usage: % Usage:
% PLOTPOLARS prompts the user to input a Polar structure and plots the various % PLOTPOLARS prompts the user to input a Polar structure and plots the various curves.
% curves.
% %
% PLOTPOLARS(POLAR) uses the POLAR strcture given as input instead of % PLOTPOLARS(POLAR) uses the POLAR strcture given as input instead of prompting the user to
% prompting the user to select the file. % select the file.
% %
% PLOTPOLARS(ALPHA, CL) uses directly the values provided by ALPHA and CL to % PLOTPOLARS(ALPHA, CL) uses directly the values provided by ALPHA and CL to plot the
% plot the available curves. % available curves.
% %
% PLOTPOLARS(ALPHA, CL, CD) uses directly the values provided by ALPHA and CL % PLOTPOLARS(ALPHA, CL, CD) uses directly the values provided by ALPHA and CL and CD to plot
% and CD to plot the available curves. % the available curves.
% %
% PLOTPOLARS(ALPHA, CL, CD, CM) uses directly the values provided by ALPHA, CL, % PLOTPOLARS(ALPHA, CL, CD, CM) uses directly the values provided by ALPHA, CL, and CM to plot
% and CM to plot all possible curves. % all possible curves.
% %
% Inputs: % Inputs:
% Polar : Polar structure (e.g. output from XF2MAT) % Polar : Polar structure (e.g. output from XF2MAT)
...@@ -58,10 +57,12 @@ function plotpolars(varargin) ...@@ -58,10 +57,12 @@ function plotpolars(varargin)
% See also: XF2MAT, EXTENDPOLAR. % See also: XF2MAT, EXTENDPOLAR.
% %
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
narginchk(0, 4); narginchk(0, 4);
...@@ -75,7 +76,7 @@ function plotpolars(varargin) ...@@ -75,7 +76,7 @@ function plotpolars(varargin)
% Extract and validate the inputs % Extract and validate the inputs
[alpha, cl, cd, cm] = parsepolarinputs(OPTION_LIST, varargin{:}); [alpha, cl, cd, cm] = parsepolarinputs(OPTION_LIST, varargin{:});
% ------------------------------------ % -------------------------------------------
% Plots % Plots
set(0, 'defaultTextInterpreter', 'latex'); % Default interpreter for all plots set(0, 'defaultTextInterpreter', 'latex'); % Default interpreter for all plots
...@@ -93,7 +94,7 @@ function plotpolars(varargin) ...@@ -93,7 +94,7 @@ function plotpolars(varargin)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function plotsinglepolar(dataX, dataY, fTitle, fXlabel, fYlabel) function plotsinglepolar(dataX, dataY, fTitle, fXlabel, fYlabel)
% PLOTSINGLE Standardize polar plots % PLOTSINGLE Standardize polar plots
...@@ -114,7 +115,7 @@ function plotsinglepolar(dataX, dataY, fTitle, fXlabel, fYlabel) ...@@ -114,7 +115,7 @@ function plotsinglepolar(dataX, dataY, fTitle, fXlabel, fYlabel)
setgca(); setgca();
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function setgca() function setgca()
% SETGCA Sets axes options for all plots % SETGCA Sets axes options for all plots
......
function Dat = uiuccleaner(varargin) function Dat = uiuccleaner(varargin)
% UIUCCLEANER Cleans airfoil data from UIUC Airfoil Database. % UIUCCLEANER Cleans airfoil data from UIUC Airfoil Database.
% The UIUC airfoil database from the University of Illinois gathers the % The UIUC airfoil database from the University of Illinois gathers the coordinates for more
% coordinates for more than 1600 airfoils. However, there is a few % than 1600 airfoils. However, there is a few discrepancies between the format and ordering of
% discrepancies between the format and ordering of these coordinates. This % these coordinates. This script alleviates that by re-formatting any input file from the
% script alleviates that by re-formatting any input file from the original % original database.
% database.
% %
% Format: % Format:
% The output format of this script follows the "labeled coordinates" file, % The output format of this script follows the "labeled coordinates" file, used originally by
% used originally by Selig on the UIUC Airfoil Database. % Selig on the UIUC Airfoil Database.
% The first line contains the name of the airfoil, and each line after that is % The first line contains the name of the airfoil, and each line after that is a set of
% a set of coordinates. The coordinates are ordered from the trailing edge, % coordinates. The coordinates are ordered from the trailing edge, along the upper surface to
% along the upper surface to the leading edge and back around the lower % the leading edge and back around the lower surface to trailing edge.
% surface to trailing edge.
% %
% Note: % Note:
% This function can be used on many files at once in order to speed-up the % This function can be used on many files at once in order to speed-up the process.
% process.
% %
% <a href="https://gitlab.uliege.be/thlamb/airfoil_toolbox">Documentation (README)</a> % <a href="https://gitlab.uliege.be/thlamb/airfoil_toolbox">Documentation (README)</a>
% <a href="https://gitlab.uliege.be/thlamb/airfoil_toolbox/-/issues">Report an issue</a> % <a href="https://gitlab.uliege.be/thlamb/airfoil_toolbox/-/issues">Report an issue</a>
% ----- % -----
% %
% Usage: % Usage:
% DAT = UIUCCLEANER prompts the user for all inputs, then converts the % DAT = UIUCCLEANER prompts the user for all inputs, then converts the coordinates to the
% coordinates to the correct standard. % correct standard.
% %
% DAT = UIUCCLEANER(INPUTDIR) converts all dat files found in INPUTDIR. % DAT = UIUCCLEANER(INPUTDIR) converts all dat files found in INPUTDIR.
% %
% DAT = UIUCCLEANER(INPUTDIR, INPUTFILES) converts only the polars % DAT = UIUCCLEANER(INPUTDIR, INPUTFILES) converts only the polars specified by INPUTFILES
% specified by INPUTFILES found in INPUTDIR. % found in INPUTDIR.
% %
% DAT = UIUCCLEANER(..., 'autosave', true) saves the resulting coordinates % DAT = UIUCCLEANER(..., 'autosave', true) saves the resulting coordinates in a new dat-file.
% in a new dat-file.
% %
% DAT = UIUCCLEANER(..., 'overwrite', true) saves the resulting coordinates % DAT = UIUCCLEANER(..., 'overwrite', true) saves the resulting coordinates by overwriting the
% by overwriting the original dat-file. If autosave is not specified but % original dat-file. If autosave is not specified but overwrite is true, the file will be
% overwrite is true, the file will be overwritten anyway. If autosave is set % overwritten anyway. If autosave is set to false and overwrite is true, the file will not be
% to false and overwrite is true, the file will not be saved at all. % saved at all.
% %
% DAT = UIUCCLEANER(..., 'refine', true) refines the input data by using a % DAT = UIUCCLEANER(..., 'refine', true) refines the input data by using a spline
% spline interpolation with 100 coordinates in total, spaced following the % interpolation with 100 coordinates in total, spaced following the half-cosine rule.
% half-cosine rule. False by default. % False by default.
% %
% Inputs: % Inputs:
% inputDir : Path of the directory with the UIUC oridinal dat-files % inputDir : Path of the directory with the UIUC oridinal dat-files
...@@ -68,10 +64,12 @@ function Dat = uiuccleaner(varargin) ...@@ -68,10 +64,12 @@ function Dat = uiuccleaner(varargin)
% ----- % -----
% UIUC Airfoil Database: https://m-selig.ae.illinois.edu/ads/coord_database.html % UIUC Airfoil Database: https://m-selig.ae.illinois.edu/ads/coord_database.html
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
narginchk(0, 8); narginchk(0, 8);
...@@ -92,7 +90,7 @@ function Dat = uiuccleaner(varargin) ...@@ -92,7 +90,7 @@ function Dat = uiuccleaner(varargin)
% Convert filenames to string array % Convert filenames to string array
allFileNames = string(allFileNames); allFileNames = string(allFileNames);
% ------------------------------------- % -------------------------------------------
% Convert all files % Convert all files
% Number of files found % Number of files found
...@@ -150,7 +148,7 @@ function Dat = uiuccleaner(varargin) ...@@ -150,7 +148,7 @@ function Dat = uiuccleaner(varargin)
end end
% ------------------------------------- % -------------------------------------------
% Save results automatically % Save results automatically
if autosave if autosave
...@@ -171,7 +169,7 @@ function Dat = uiuccleaner(varargin) ...@@ -171,7 +169,7 @@ function Dat = uiuccleaner(varargin)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function [autosave, overwrite, refine] = parseoptioninputs(varargin) function [autosave, overwrite, refine] = parseoptioninputs(varargin)
% PARSEOPTIONINPUTS Parses the options and checks their validity % PARSEOPTIONINPUTS Parses the options and checks their validity
......
function Polar = xf2mat(varargin) function Polar = xf2mat(varargin)
% XF2MAT Aggregates multiple XFOIL or XFLR5 polar results into a single structure. % XF2MAT Aggregates multiple XFOIL or XFLR5 polar results into a single structure.
% This function aggregates different airfoil polars obtained with XFOIL or % This function aggregates different airfoil polars obtained with XFOIL or XFLR5 (saved as
% XFLR5 (saved as textfiles) into a single structure for easier handling in % textfiles) into a single structure for easier handling in other scripts.
% other scripts.
% %
% This function can be run without arguments, in this case it will prompt the % This function can be run without arguments, in this case it will prompt the user for the
% user for the input. % input. Otherwhile, the function asks for two main arguments:
% Otherwile, the function asks for two main arguments:
% 1. inputDir: the directory where to look for the files % 1. inputDir: the directory where to look for the files
% 2. inputFiles: the files to load % 2. inputFiles: the files to load
% %
% The function also comes with options to save automatically the resulting % The function also comes with options to save automatically the resulting Polar structure and
% Polar structure and to trim all results to the same range of angles of % to trim all results to the same range of angles of attack.
% attack.
% %
% Note: % Note:
% If multiple textfiles are selected as input, by default, the function will % If multiple textfiles are selected as input, by default, the function will extend every
% extend every polar to the maximum range of angles of attack found. Polars % polar to the maximum range of angles of attack found. Polars with fewer data will be
% with fewer data will be assigned NaN values at the missing angles of attack. % assigned NaN values at the missing angles of attack.
% If the 'trimAoas' is set to true, the function will find the largest common % If the 'trimAoas' is set to true, the function will find the largest common range of angles
% range of angles of attack accross the various input polars and trim % of attack accross the various input polars and trim everything to that range. This prevents
% everything to that range. This prevents NaN values in the polars, but % NaN values in the polars, but removes some data from the most complete inputs.
% removes some data from the most complete inputs.
% %
% <a href="https://gitlab.uliege.be/thlamb/airfoil_toolbox">Documentation (README)</a> % <a href="https://gitlab.uliege.be/thlamb/airfoil_toolbox">Documentation (README)</a>
% <a href="https://gitlab.uliege.be/thlamb/airfoil_toolbox/-/issues">Report an issue</a> % <a href="https://gitlab.uliege.be/thlamb/airfoil_toolbox/-/issues">Report an issue</a>
% ----- % -----
% %
% Usage: % Usage:
% POLAR = XF2MAT prompts the user for all inputs, then aggregate and convert % POLAR = XF2MAT prompts the user for all inputs, then aggregate and convert the polar in a
% the polar in a single POLAR structure. % single POLAR structure.
% %
% POLAR = XF2MAT(INPUTDIR) aggregates all polars found in INPUTDIR into a % POLAR = XF2MAT(INPUTDIR) aggregates all polars found in INPUTDIR into a single Polar
% single Polar structure. % structure.
% %
% POLAR = XF2MAT(INPUTDIR, INPUTFILES) aggregates only the polars specified by % POLAR = XF2MAT(INPUTDIR, INPUTFILES) aggregates only the polars specified by INPUTFILES
% INPUTFILES found in INPUTDIR into a single Polar structure. % found in INPUTDIR into a single Polar structure.
% %
% POLAR = XF2MAT(..., 'autosave', true) saves the resulting POLAR structure % POLAR = XF2MAT(..., 'autosave', true) saves the resulting POLAR structure automatically in
% automatically in a MAT-file. % a MAT-file.
% %
% POLAR = XF2MAT(..., 'trimAoas', true) trims all input polars to the largest % POLAR = XF2MAT(..., 'trimAoas', true) trims all input polars to the largest common range of
% common range of angles of attack to prevent NaN values in the ouput. % angles of attack to prevent NaN values in the ouput.
% %
% Inputs: % Inputs:
% inputDir : Path of the directory with the XFOIL/XFLR5 data % inputDir : Path of the directory with the XFOIL/XFLR5 data
...@@ -73,10 +69,12 @@ function Polar = xf2mat(varargin) ...@@ -73,10 +69,12 @@ function Polar = xf2mat(varargin)
% XFOIL: http://web.mit.edu/drela/Public/web/xfoil/ % XFOIL: http://web.mit.edu/drela/Public/web/xfoil/
% XFLR5: https://www.xflr5.tech/xflr5.htm % XFLR5: https://www.xflr5.tech/xflr5.htm
% ----- % -----
% Copyright 2022 Thomas Lambert <t.lambert@uliege.be> % (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics % ULiege - Aeroelasticity and Experimental Aerodynamics
% Apache 2.0 License % Apache 2.0 License
% https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
% ---------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------
narginchk(0, 6); narginchk(0, 6);
...@@ -98,7 +96,7 @@ function Polar = xf2mat(varargin) ...@@ -98,7 +96,7 @@ function Polar = xf2mat(varargin)
% Convert filenames to string array % Convert filenames to string array
allFileNames = string(allFileNames); allFileNames = string(allFileNames);
% ------------------------------------- % -------------------------------------------
% Process XFoil/XFLR5 results % Process XFoil/XFLR5 results
% Number of files found % Number of files found
...@@ -189,7 +187,7 @@ function Polar = xf2mat(varargin) ...@@ -189,7 +187,7 @@ function Polar = xf2mat(varargin)
Polar.cd(:, :) = Polar.cd(:, indSort); Polar.cd(:, :) = Polar.cd(:, indSort);
Polar.cm(:, :) = Polar.cm(:, indSort); Polar.cm(:, :) = Polar.cm(:, indSort);
% ------------------------------------- % -------------------------------------------
% Save results automatically % Save results automatically
if nargin == 0 % Prompt only if user input is to be expected if nargin == 0 % Prompt only if user input is to be expected
...@@ -236,7 +234,7 @@ function Polar = xf2mat(varargin) ...@@ -236,7 +234,7 @@ function Polar = xf2mat(varargin)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function [autosave, trimAoas] = parseoptioninputs(varargin) function [autosave, trimAoas] = parseoptioninputs(varargin)
% PARSEOPTIONINPUTS Parses the options and checks their validity % PARSEOPTIONINPUTS Parses the options and checks their validity
...@@ -259,7 +257,7 @@ function [autosave, trimAoas] = parseoptioninputs(varargin) ...@@ -259,7 +257,7 @@ function [autosave, trimAoas] = parseoptioninputs(varargin)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function aoaRange = findcommonrange(aoaRange, resArray) function aoaRange = findcommonrange(aoaRange, resArray)
% FINDCOMMONRANGE Find the best common range accors all polars % FINDCOMMONRANGE Find the best common range accors all polars
...@@ -279,7 +277,7 @@ function aoaRange = findcommonrange(aoaRange, resArray) ...@@ -279,7 +277,7 @@ function aoaRange = findcommonrange(aoaRange, resArray)
end end
% ------------------------------------------------------------------------------ % --------------------------------------------------------------------------------------------------
function aoaRange = findmaxrange(aoaRange, resArray) function aoaRange = findmaxrange(aoaRange, resArray)
% FINDMAXRANGE Find the max range between all polars % FINDMAXRANGE Find the max range between all polars
......
...@@ -3,61 +3,162 @@ ...@@ -3,61 +3,162 @@
When contributing to this repository, please first discuss the change you wish When contributing to this repository, please first discuss the change you wish
to make via issue, email, or any other before making a change. to make via issue, email, or any other before making a change.
- [Code standards](#code-standards)
- [Documentation](#documentation)
- [Inputs and errors](#inputs-and-errors)
- [Tests](#tests)
- [Style](#style)
- [MISS_HIT](#miss_hit)
- [Other](#other)
- [Naming convention](#naming-convention)
- [Merge request process](#merge-request-process)
## Code standards ## Code standards
All changes submitted must conform to the following code standards. All changes submitted must conform to the following code standards.
### Main functions ### Function design
The so called _Main functions_ are the ones present in the root of `+af_tools/`. The functions of this packages are divided in two parts: the _main functions_
These are the core functions of the package. and the _utilities_. The _main functions_ are the ones present at the root of
`+af_tools/`. These are the core functions of this package, meant to be called
- Every main function should start with a lengthy comment that details its use. directly by the users. The _utilities_ are located in `+af_tools/+utils/`. These
The first line of the comment must be a one-line description of the function are small sub-routines, meant to perform basic tasks and shared among the
(this line is searched when the user type `lookfor <keyword>` in Matlab). The different _main functions_. These sub-routines are not intended to be called by
next block of continuous comment is printed when the user types `help the end user (although they could if they want). Therefore they do not require
<function>`. As this is the only documentation provided for the different the same level of documentation, testing, etc.
functions, this comment should describe the whole function, as well as all
inputs and outputs. Some examples of use should also be provided. If some - Each main function should be standalone tool that makes a complete operation.
special design choices were made for the implementation, they should be
documented as well.
- Every main function should validate the user inputs (using
`validateattributes`, `validatestring`, `try/catch` blocks, etc) to ensure
proper use.
- All main functions should return a comprehensive error message in case of
failure. If applicable, warnings should be returned if the inputs/outputs are
expected to be of poor quality due to poor, but valid, input.
- If possible, the main functions should be coded so they can be run without any - If possible, the main functions should be coded so they can be run without any
input argument. If some argument is absolutely mandatory, the users should be input argument. If some argument is absolutely mandatory, the users should be
prompted through the command window or a dialog box. All other arguments prompted through the command window or a dialog box. All other arguments
should be set at proper defaults values. should be set at proper defaults values (documented in the help block).
- Each main function should be standalone tool that makes a complete operation.
Sub-routines for intermediary tasks are allowed, but must be placed in
`+af_tools/+utils/` (see below for details regarding sub-routines).
- The functions must be inter-operable with little effort from the user - The functions must be inter-operable with little effort from the user
(function B reuses the output of function A without much modification). (function B reuses the output of function A without much modification). This
- The functions can be called directly from one another. In that case, the means that the units of the input and output should remain the same, etc.
- The functions can be called directly from one another. In that situation, the
import statements must be the first lines of code in the function. import statements must be the first lines of code in the function.
- Each function should come with a set of tests (in `tests/`) to ensure all
errors are raised and standard outputs can always be reproduced.
- The functions should not contain commented code.
- Code should be properly formatted by Matlab (select all, then `ctrl`+ `i`)
### Sub-routines ### Documentation
- Every _main function_ should start with a lengthy comment that details its
use. The first line of the comment must be a one-line description of the
function. The first block of continuous comment is printed when the user types
`help <function>`. This is the main documentation for the different functions,
therefore it should be as complete as possible. This comment must document the
function's aim, its inputs and outputs. Various small examples should be also
provided.
If some special design choices were made for the implementation, they should
be documented in detail well.
- If the function implements a specific methodology, please add the source as
well in the documentation.
- The first comment block should always end with a copyright block detailing the
author and the license (Apache 2.0).
- The _utilities_ functions can just have a one-line description and the
copyright block. They should normally be simple enough to be understood
without much work.
- All _main functions_ should be briefly described in the `README.md` of this
repository. This small description should detail its aim, inputs and a few
examples.
### Inputs and errors
- Every _main function_ should validate completely the user inputs.
- This validation should be done using Matlab's built-in tools as much as
possible. Such tools are: `validateattributes`, `validatestring`, `try/catch`
blocks, etc. Some utilities functions already exist to take care of input
parsing. Ideally, your function should try to reuse them as is to standardize
things as much as possible.
- The sub-routines can skip these user input checks, as they are meant to be
used internally.
- All functions should return a comprehensive error message in case of failure.
This message is meant to help the user debug their issue on themselves.
- If applicable, warnings should be returned if the inputs/outputs are
expected to be of poor quality due to poor, but valid, input.
- In order to facilitate testing, the error and warnings must come with a custom
identifier and not just a description.
### Tests
- Each function (whereas _main function_ or _utility_) **must** come with a set
of tests, placed in the `tests/` directory.
- These tests typically check:
1. if errors and warning are returned as expected;
2. a few basic use cases.
- For _utilities_, the errors and warning tests can be skipped (typically the
error should be raised beforehand in the main function that calls the utility).
### Style
#### Miss_hit
The code style is enforced using [MISS_HIT][miss_hit], a code formatter and
analyser written in Python. **All pushes to the master branch and all merge
requests are first validated using MISS_HIT**.
The so called _Sub-routines_ are small chunks of code that do not bear great Besides typical style verification (spaces at the right spot, line width, etc),
interest in themselves, but are shared by different _Main functions_. To MISS_HIT is also used to analyze the complexity of the code. To simplify
separate them clearly, they must be placed in `+af_tools/+utils/`. maintenance and interoperability, each individual function should be kept as
small and simple as possible. Do not hesitate to use small local functions to do
basic operations within a larger function.
To install MISS_HIT, just use the following:
```bash
pip3 install --user miss_hit
```
The rules enforced by MISS_HIT are specified in the `miss_hit.cfg` [file at the
root of this repo][miss_hit_cfg].
To check the code style of the entire repository, just execute the following
line at the root of the repo.
```bash
mh_style .
```
You can also ask MISS_HIT to fix everything automatically by simply adding the
flag `--fix` to the bash command.
The code quality metrics can be checked with
```bash
mh_metrics .
```
The output is quite verbose as all metrics for all files is returned. Adding
the flag `--ci` will only list the metrics that conflict with the limits imposed
in the configuration file.
MISS_HIT also comes with a linting tool that will typically output warnings, etc
when some variables are poorly defined, or code may lead to future breaking
errors.
```bash
mh_lint .
```
#### Other
Some other conventions can not be currently enforced by MISS_HIT. They should
still apply:
- The sub-routines do not require a long help comment. A one line description is
enough.
- The sub-routines are not made to be used directly by the end user. As such,
there is no need for complex input validation.
- Sub-routines must also come with a set of tests (in `test/`). The error
verification tests can be skipped, so the test function only contains tests
for the expected outputs.
- The functions should not contain commented code. - The functions should not contain commented code.
- Code should be properly formatted by Matlab (select all, then `ctrl`+ `i`) - The functions should not be separated in code blocks using `%%`. Prefer a
separator line such as `% --------------------------`
#### Naming convention
The following naming convention is adopted:
- File names must be the same as the main function name.
- Functions should be _alllowercase_: `calculatestuff()`, `getallvariables()`
- Constants should be all caps, with underscore between words: `MAX_ITERATIONS`
- In general, variables should use _camelCase_: `myVariable`, `liftCoefficient`
- Matlab structures should be _PascalCase_: `MyStructure`
- Indices are allowed if they make sense: `alpha_0`, `cDrag_0`, `alpha_s`
## Merge Request Process ## Merge Request Process
...@@ -66,4 +167,8 @@ separate them clearly, they must be placed in `+af_tools/+utils/`. ...@@ -66,4 +167,8 @@ separate them clearly, they must be placed in `+af_tools/+utils/`.
2. Ensure all tests pass in Matlab (`runtests('tests')`). 2. Ensure all tests pass in Matlab (`runtests('tests')`).
3. Update the CHANGELOG.md and CODEOWNERS to document the changes. 3. Update the CHANGELOG.md and CODEOWNERS to document the changes.
4. Update the README.md to reflect the changes if applicable. 4. Update the README.md to reflect the changes if applicable.
5. Submit your Merge Request. 5. Ensure MISS_HIT is happy
6. Submit your Merge Request.
[miss_hit]: https://github.com/florianschanda/miss_hit
[miss_hit_cfg]: https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/blob/master/miss_hit.cfgj:w
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment