From 4d6ba1e69e850d4c60403660459edb8b665856e7 Mon Sep 17 00:00:00 2001 From: Thomas Lambert <t.lambert@uliege.be> Date: Thu, 14 Apr 2022 14:26:37 +0200 Subject: [PATCH] doc: add details to contributing, emph on MISS_HIT --- +af_tools/+utils/appendextension.m | 4 +- +af_tools/+utils/miss_hit.cfg | 1 - +af_tools/+utils/parsefileinputs.m | 14 +- +af_tools/+utils/parsenacainputs.m | 13 +- +af_tools/+utils/parsepolarinputs.m | 51 ++++---- +af_tools/+utils/sanitizestring.m | 4 +- +af_tools/+utils/savetodat.m | 7 +- +af_tools/+utils/spacedvector.m | 4 +- +af_tools/+utils/trimtorange.m | 4 +- +af_tools/+utils/vecttocol.m | 4 +- +af_tools/extendpolar.m | 68 +++++----- +af_tools/findcllinearrange.m | 46 +++---- +af_tools/findstall.m | 48 +++---- +af_tools/findzerolift.m | 52 ++++---- +af_tools/nacaairfoil.m | 60 +++++---- +af_tools/nacacamber.m | 38 +++--- +af_tools/plotpolars.m | 43 ++++--- +af_tools/uiuccleaner.m | 58 ++++----- +af_tools/xf2mat.m | 62 +++++---- CONTRIBUTING.md | 191 +++++++++++++++++++++------- miss_hit.cfg | 21 +-- 21 files changed, 457 insertions(+), 336 deletions(-) delete mode 100644 +af_tools/+utils/miss_hit.cfg diff --git a/+af_tools/+utils/appendextension.m b/+af_tools/+utils/appendextension.m index 2f83f6b..12b5850 100644 --- a/+af_tools/+utils/appendextension.m +++ b/+af_tools/+utils/appendextension.m @@ -1,10 +1,12 @@ function str = appendextension(str, ext) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- if isempty(regexp(str, [ext, '$'], 'once')) diff --git a/+af_tools/+utils/miss_hit.cfg b/+af_tools/+utils/miss_hit.cfg deleted file mode 100644 index f89ddc5..0000000 --- a/+af_tools/+utils/miss_hit.cfg +++ /dev/null @@ -1 +0,0 @@ -enable: 1 diff --git a/+af_tools/+utils/parsefileinputs.m b/+af_tools/+utils/parsefileinputs.m index 15eaaa3..7b90870 100644 --- a/+af_tools/+utils/parsefileinputs.m +++ b/+af_tools/+utils/parsefileinputs.m @@ -1,18 +1,20 @@ function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, varargin) % PARSEFILEINPUTS Parses the input and checks their validity. - % Returns the filenames and filepaths for the input files, as well as the - % index where the remaining options start. + % Returns the filenames and filepaths for the input files, as well as the index where the + % remaining options start. % - % ----- % + % ----- % Usage: % [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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- import af_tools.utils.* @@ -67,7 +69,7 @@ function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, va 'it must contain only character vectors!\n']); end - % ------------------------------------------------------ + % --------------------------------------- % Look for files % Get absolute path @@ -107,7 +109,7 @@ function [filenames, filepaths, idxOpts] = parsefileinputs(optList, filetype, va end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function bool = isoption(optList, var) % ISOPTION Returns true if var is contained in option list diff --git a/+af_tools/+utils/parsenacainputs.m b/+af_tools/+utils/parsenacainputs.m index ae46759..5d34de4 100644 --- a/+af_tools/+utils/parsenacainputs.m +++ b/+af_tools/+utils/parsenacainputs.m @@ -1,9 +1,8 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin) % PARSENACAINPUTS Parses the inputs for naca* functions and checks their validity. - % Returns the naca denomination, the number of points and the index where the - % remaining options start. - % If some inputs were not provided, the functions returns an empty array for - % those. + % Returns the naca denomination, the number of points and the index where the remaining + % options start. + % If some inputs were not provided, the functions returns an empty array for those. % % ----- % Usage: @@ -13,10 +12,12 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin) % [...] = 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- import af_tools.utils.* @@ -97,7 +98,7 @@ function [digits, nPoints, idxOpts] = parsenacainputs(optList, varargin) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function bool = isoption(optList, var) % ISOPTION Returns true if var is contained in option list diff --git a/+af_tools/+utils/parsepolarinputs.m b/+af_tools/+utils/parsepolarinputs.m index 70f37ee..b4df076 100644 --- a/+af_tools/+utils/parsepolarinputs.m +++ b/+af_tools/+utils/parsepolarinputs.m @@ -1,13 +1,12 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin) % PARSEPOLARINPUTS Parses the input and checks their validity. - % Returns the arrays for the main polar arrays (alpha, cl, cd, cm), as well as - % the index where the remaining options start. - % If some inputs were not provided (alpha, cl, cd, cm), the functions returns - % an empty array for those. + % Returns the arrays for the main polar arrays (alpha, cl, cd, cm), as well as the index where + % the remaining options start. + % If some inputs were not provided (alpha, cl, cd, cm), the functions returns an empty array + % for those. % - % This function also contains checks on every "polar" input (i.e. the Polar - % strcture or the four arrays: alpha, cl, cd and cm) to ensure they are - % correct. + % This function also contains checks on every "polar" input (i.e. the Polar strcture or the + % four arrays: alpha, cl, cd and cm) to ensure they are correct. % % ----- % Usage: @@ -19,10 +18,12 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin) % [...] = 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- import af_tools.utils.* @@ -79,18 +80,9 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin) validateattributes(alpha, {'numeric'}, {'real', '2d', 'nonempty', 'increasing'}, ... mfilename(), 'alpha', 1); - if ~isempty(cl) - validateattributes(cl, {'numeric'}, {'real', 'nrows', size(alpha, 1), 'nonempty'}, ... - mfilename(), 'cl', 2); - 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 + checkarray(cl, size(alpha, 1), 2); + checkarray(cd, size(alpha, 1), 3); + checkarray(cm, size(alpha, 1), 4); % Standardize alpha size so we have one column per Polar as well if size(alpha, 2) == 1 && ~isempty(cl) @@ -99,14 +91,14 @@ function [alpha, cl, cd, cm, idxOpts] = parsepolarinputs(optList, varargin) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- 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)); end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function [alpha, cl, cd, cm] = extractpolar(Polar) % EXTRACTPOLAR Extract alpha, cl, cd and cm fields Polar structure. @@ -116,7 +108,7 @@ function [alpha, cl, cd, cm] = extractpolar(Polar) cm = Polar.cm; end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function [var, idxOpts, foundOpts] = assignvar(optList, var, data, idx) % ASSIGNVAR Assign varargin value to a variable, ouptut corresponding idxOpts. @@ -130,3 +122,14 @@ function [var, idxOpts, foundOpts] = assignvar(optList, var, data, idx) 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 diff --git a/+af_tools/+utils/sanitizestring.m b/+af_tools/+utils/sanitizestring.m index 72258c4..a223db2 100644 --- a/+af_tools/+utils/sanitizestring.m +++ b/+af_tools/+utils/sanitizestring.m @@ -1,10 +1,12 @@ function str = sanitizestring(str) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- % Mapping table (maps unwanted chars with their replacements) diff --git a/+af_tools/+utils/savetodat.m b/+af_tools/+utils/savetodat.m index a1be960..cf462b7 100644 --- a/+af_tools/+utils/savetodat.m +++ b/+af_tools/+utils/savetodat.m @@ -1,14 +1,15 @@ function savetodat(filename, header, varargin) % SAVETODAT Saves input table or list of vectors to a dat file % Note: - % This inputs need to have the same dimensions to be concatenated into a - % single output array. + % This inputs need to have the same dimensions to be concatenated into a 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- import af_tools.utils.vecttocol diff --git a/+af_tools/+utils/spacedvector.m b/+af_tools/+utils/spacedvector.m index 759c17e..ecf48e3 100644 --- a/+af_tools/+utils/spacedvector.m +++ b/+af_tools/+utils/spacedvector.m @@ -1,10 +1,12 @@ function vect = spacedvector(spacing, nPoints) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- switch spacing diff --git a/+af_tools/+utils/trimtorange.m b/+af_tools/+utils/trimtorange.m index b964589..0d5e166 100644 --- a/+af_tools/+utils/trimtorange.m +++ b/+af_tools/+utils/trimtorange.m @@ -1,10 +1,12 @@ function [alphaTrim, clTrim, cdTrim] = trimtorange(range, alpha, cl, cd) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- narginchk(2, 4); diff --git a/+af_tools/+utils/vecttocol.m b/+af_tools/+utils/vecttocol.m index ed34b43..0f77e8b 100644 --- a/+af_tools/+utils/vecttocol.m +++ b/+af_tools/+utils/vecttocol.m @@ -1,10 +1,12 @@ function var = vecttocol(var) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- if isvector(var) diff --git a/+af_tools/extendpolar.m b/+af_tools/extendpolar.m index d58e0fc..83a2e15 100644 --- a/+af_tools/extendpolar.m +++ b/+af_tools/extendpolar.m @@ -1,45 +1,43 @@ function [alphaExt, clExt, cdExt] = extendpolar(varargin) % EXTENDPOLAR Extends polars to the full range of AOA ([-180, 180] deg). - % This function implements different empirical methods to extend the polars - % outside of their usual range. + % This function implements different empirical methods to extend the polars outside of their + % usual range. % - % EXTENDPOLAR accepts inputs in the form of a Polar structure (generated with - % XF2MAT) or values for angles of attack and their associated cl and cd. + % EXTENDPOLAR accepts inputs in the form of a Polar structure (generated with XF2MAT) or + % 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 - % same number of rows (one for each angle of attack). The columns indicate - % values for different polars (different Mach, different Reynolds,...). - % For example, if the cl values are given for 2 different Reynols and there - % are 100 values for the aoa, cl and cd must be [100 x 2]. + % If the input is specified as aoa, cl and cd, the three arrays must have the same number of + % rows (one for each angle of attack). The columns indicate values for different polars + % (different Mach, different Reynolds,...). + % For example, if the cl values are given for 2 different Reynols and there are 100 values for + % the aoa, cl and cd must be [100 x 2]. % % IMPORTANT: - % To be extended, the input polar must AT LEAST containt the points where - % AOA = 0 deg and stall point. + % To be extended, the input polar must AT LEAST containt the points where AOA = 0 deg and + % 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/-/issues">Report an issue</a> % ----- % % Usage: - % [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR prompts the user to input a Polar - % structure and extends the angle of attack (ALPHAEXT), lift coefficient - % (CLEXT) and drag coefficient (CDEXT). + % [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR prompts the user to input a Polar structure and + % extends the angle of attack (ALPHAEXT), lift coefficient (CLEXT) and drag coefficient + % (CDEXT). % - % [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR(POLAR) uses the POLAR strcture given - % as input instead of prompting the user to select the file. + % [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR(POLAR) uses the POLAR strcture given as input instead + % of prompting the user to select the file. % - % [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR(ALPHA, CL, CD) extends directly the - % values given in ALPHA, CL and CD over the whole range of angles of attack. + % [ALPHAEXT, CLEXT, CDEXT] = EXTENDPOLAR(ALPHA, CL, CD) extends directly the values given in + % ALPHA, CL and CD over the whole range of angles of attack. % % [...] = EXTENDPOLAR(..., 'method', METHOD) specifies the extension method. % The available methods are: - % % 'Viterna' - (default) Viterna & Corrigan. 1982. "Fixed Pitch Rotor % Performance of Large Horizontal Axis Wind Turbines". % - % [...] = EXTENDPOLAR(..., 'limit', LIMIT) specifies the point from where to - % extend. The available limits are: - % + % [...] = EXTENDPOLAR(..., 'limit', LIMIT) specifies the point from where to extend. + % The available limits are: % 'last' - (default) last point of the input polar % 'stall' - stall point, the points after stall are disregarded % @@ -65,10 +63,12 @@ function [alphaExt, clExt, cdExt] = extendpolar(varargin) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- % Check number of inputs @@ -102,7 +102,7 @@ function [alphaExt, clExt, cdExt] = extendpolar(varargin) 'To be extended, a polar must at least contain the stall point.'); end - % ------------------------------------ + % ------------------------------------------- % Extend polars if alpha(1, 1) == -pi || alpha(end, 1) == pi @@ -120,7 +120,7 @@ function [alphaExt, clExt, cdExt] = extendpolar(varargin) end -% -------------------------------------------------------------------------- +% -------------------------------------------------------------------------------------------------- function [method, limit] = parseoptioninputs(varargin) % PARSEINPUTS Parses the input and checks their validity @@ -146,17 +146,17 @@ function [method, limit] = parseoptioninputs(varargin) end -% -------------------------------------------------------------------------- +% -------------------------------------------------------------------------------------------------- function [alphaExt, clExt, cdExt] = viterna(limit, alpha, cl, cd) % VITERNA Implementation of the original Viterna model % Source: - % Viterna & Corrigan. 1982. "Fixed Pitch Rotor Performance of Large Horizontal - % Axis Wind Turbines". + % Viterna & Corrigan. 1982. "Fixed Pitch Rotor Performance of Large Horizontal Axis Wind + % Turbines". % Note: - % The typical subscript 's' used in most definitions is here replaced by the - % generic 'l' (for limit) as the function can be used either with the stall - % point or the last available data. + % The typical subscript 's' used in most definitions is here replaced by the generic 'l' + % (for limit) as the function can be used either with the stall point or the last available + % data. % % Process (the number will indicate the index of alpha, cl, cd): % 1. Extend Cl/Cd to ]limit, 90] @@ -260,12 +260,12 @@ function [alphaExt, clExt, cdExt] = viterna(limit, alpha, cl, cd) end -% -------------------------------------------------------------------------- +% -------------------------------------------------------------------------------------------------- function [cl, cd] = viternaeq(VitCoeffs, alpha, clScaling) % VITERNAEQ Viterna's equation for the extension of the polars % Source: - % Viterna & Corrigan. 1982. "Fixed Pitch Rotor Performance of Large Horizontal - % Axis Wind Turbines". + % Viterna & Corrigan. 1982. "Fixed Pitch Rotor Performance of Large Horizontal Axis Wind + % Turbines". cl = VitCoeffs.a1 * sin(2 * alpha) + VitCoeffs.a2 * cos(alpha).^2 ./ sin(alpha); cl = cl * clScaling; diff --git a/+af_tools/findcllinearrange.m b/+af_tools/findcllinearrange.m index 381c4f3..facb543 100644 --- a/+af_tools/findcllinearrange.m +++ b/+af_tools/findcllinearrange.m @@ -1,37 +1,35 @@ function [alphaRange, clRange, clSlope] = findcllinearrange(varargin) % FINDCLLINEARRANGE Finds the linear range of the lift coefficient its slope. - % This function approximates the lift coefficient linear range by looking at - % its first and second derivatives (using hard-coded tolerance values). + % This function approximates the lift coefficient linear range by looking at its first and + % second derivatives (using hard-coded tolerance values). % - % FINDCLLINEARRANGE accepts inputs in the form of a Polar structure (generated - % with XF2MAT) or values for angles of attack and their associated cl. + % FINDCLLINEARRANGE accepts inputs in the form of a Polar structure (generated with XF2MAT) or + % values for angles of attack and their associated cl. % - % If the input is specified as aoa and cl, the two arrays must have the - % same number of rows (one for each angle of attack). The columns indicate - % values for different polars (different Mach, different Reynolds,...). - % For example, if the cl values are given for 2 different Reynols and there - % are 100 values for the aoa, cl must be [100 x 2]. + % If the input is specified as aoa and cl, the two arrays must have the same number of rows + % (one for each angle of attack). The columns indicate values for different polars + % (different Mach, different Reynolds,...). + % For example, if the cl values are given for 2 different Reynols and there are 100 values for + % the aoa, cl must be [100 x 2]. % - % If extended polars are used as input (see EXTENDPOLAR), the function will - % only look for the zero-lift angle in the range of [-30, 30] deg. + % If extended polars are used as input (see EXTENDPOLAR), the function will only look for the + % 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/-/issues">Report an issue</a> % ----- % % Usage: - % [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE prompts the user to - % input a Polar structure and determines the range of angles of attach - % (ALPHA_RANGE) in which the cl is linear. It also outputs the values of the - % lift coefficient in that range (CL_RANGE) and the slope of the linear cl - % (CL_SLOPE). + % [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE prompts the user to input a Polar + % structure and determines the range of angles of attach (ALPHA_RANGE) in which the cl is + % linear. It also outputs the values of the lift coefficient in that range (CL_RANGE) and the + % slope of the linear cl (CL_SLOPE). % - % [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE(POLAR) uses the POLAR - % strcture given as input instead of prompting the user to select the file. + % [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE(POLAR) uses the POLAR strcture given + % as input instead of prompting the user to select the file. % - % [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE(ALPHA, CL) uses - % directly the values given in ALPHA and CL to determine the linear range - % characteristics. + % [ALPHA_RANGE, CL_RANGE, CL_SLOPE] = FINDCLLINEARRANGE(ALPHA, CL) uses directly the values + % given in ALPHA and CL to determine the linear range characteristics. % % Inputs: % Polar : Polar structure (e.g. output from XF2MAT) @@ -51,10 +49,12 @@ function [alphaRange, clRange, clSlope] = findcllinearrange(varargin) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- narginchk(0, 2); @@ -82,7 +82,7 @@ end % -------------------------------------------------------------------------------------------------- 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: % - First derivative close to 2*pi (TOL_DCL defines how close) % - Second derivative close to 0 (TOL_DDCL defines how close) diff --git a/+af_tools/findstall.m b/+af_tools/findstall.m index f84780a..78cd051 100644 --- a/+af_tools/findstall.m +++ b/+af_tools/findstall.m @@ -1,37 +1,35 @@ function [alpha_s, cl_s, cd_s] = findstall(varargin) % 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 - % the stall point. + % This function uses Matlab's findpeak in order to determine the position of the stall point. % - % FINDSTALL accepts inputs in the form of a Polar structure (generated with - % XF2MAT) or values for angles of attack and their associated cl and cd. While - % alpha and cl are required for this function, cd is optional. If it is - % provided, the function will return the drag value at stall as well, else - % the cd_s will be an empty vector. + % FINDSTALL accepts inputs in the form of a Polar structure (generated with XF2MAT) or values + % for angles of attack and their associated cl and cd. While alpha and cl are required for + % this function, cd is optional. If it is provided, the function will return the drag value at + % stall as well, else the cd_s will be an empty vector. % - % If the input is specified as aoa, cl and cd, the three arrays must have the - % same number of rows (one for each angle of attack). The columns indicate - % values for different polars (different Mach, different Reynolds,...). - % For example, if the cl values are given for 2 different Reynols and there - % are 100 values for the aoa, cl and cd must be [100 x 2]. + % If the input is specified as aoa, cl and cd, the three arrays must have the same number of + % rows (one for each angle of attack). The columns indicate values for different polars + % (different Mach, different Reynolds,...). + % For example, if the cl values are given for 2 different Reynols and there are 100 values for + % the aoa, cl and cd must be [100 x 2]. % - % If extended polars are used as input (see EXTENDPOLAR), the function will - % only look for the zero-lift angle in the range of [0, 30] deg. + % If extended polars are used as input (see EXTENDPOLAR), the function will only look for the + % 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/-/issues">Report an issue</a> % ----- % % Usage: - % [ALPHA_S, CL_S, CD_S] = FINDSTALL prompts the user to input a Polar - % structure and determines the stall angle of attack (ALPHA_S), the lift - % coefficient value at stall (CL_S) and the drag coefficient at stall (CD_S). + % [ALPHA_S, CL_S, CD_S] = FINDSTALL prompts the user to input a Polar structure and determines + % the stall angle of attack (ALPHA_S), the lift coefficient value at stall (CL_S) and the drag + % coefficient at stall (CD_S). % - % [ALPHA_S, CL_S, CD_S] = FINDSTALL(POLAR) uses the POLAR strcture given - % as input instead of prompting the user to select the file. + % [ALPHA_S, CL_S, CD_S] = FINDSTALL(POLAR) uses the POLAR strcture given as input instead of + % prompting the user to select the file. % - % [ALPHA_S, CL_S, CD_S] = FINDSTALL(ALPHA, CL, CD) uses directly the values - % given in in ALPHA, CL and CD to determine the stall. + % [ALPHA_S, CL_S, CD_S] = FINDSTALL(ALPHA, CL, CD) uses directly the values given in in ALPHA, + % CL and CD to determine the stall. % % Inputs: % Polar : Polar structure (e.g. output from XF2MAT) @@ -53,10 +51,12 @@ function [alpha_s, cl_s, cd_s] = findstall(varargin) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- narginchk(0, 3); @@ -75,14 +75,14 @@ function [alpha_s, cl_s, cd_s] = findstall(varargin) % (avoid issues if extended polars are used as input) [alpha, cl, cd] = trimtorange(ORIGINAL_RANGE, alpha, cl, cd); - % ------------------------------------ + % ------------------------------------------- % Find stall for each polar [alpha_s, cl_s, cd_s] = stallfinder(alpha, cl, cd); end -% -------------------------------------------------------------------------- +% -------------------------------------------------------------------------------------------------- function [alpha_s, cl_s, cd_s] = stallfinder(alpha, cl, cd) % STALLFINDER Finds the stall point and returns the corresponding AOA, CL and CD diff --git a/+af_tools/findzerolift.m b/+af_tools/findzerolift.m index f1f2686..4138c66 100644 --- a/+af_tools/findzerolift.m +++ b/+af_tools/findzerolift.m @@ -1,39 +1,39 @@ function [alpha_zeroL, cd_zeroL] = findzerolift(varargin) % FINDZEROLIFT Finds the zero-lift angle and the associated cd. - % This function finds the zero-lift angle by interpolating around the last - % negative and first positive values for the lift coefficient. + % This function finds the zero-lift angle by interpolating around the last negative and first + % positive values for the lift coefficient. % - % FINDZEROLIFT accepts inputs in the form of a Polar structure (generated with - % XF2MAT) or values for angles of attack and their associated cl and cd. + % FINDZEROLIFT accepts inputs in the form of a Polar structure (generated with XF2MAT) or + % 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 - % same number of rows (one for each angle of attack). The columns indicate - % values for different polars (different Mach, different Reynolds,...). - % For example, if the cl values are given for 2 different Reynols and there - % are 100 values for the aoa, cl and cd must be [100 x 2]. + % If the input is specified as aoa, cl and cd, the three arrays must have the same number of + % rows (one for each angle of attack). The columns indicate values for different polars + % (different Mach, different Reynolds,...). + % For example, if the cl values are given for 2 different Reynols and there are 100 values for + % the aoa, cl and cd must be [100 x 2]. % - % If extended polars are used as input (see EXTENDPOLAR), the function will - % only look for the zero-lift angle in the range of [-30, 30] deg. + % If extended polars are used as input (see EXTENDPOLAR), the function will only look for the + % 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/-/issues">Report an issue</a> % ----- % % Usage: - % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT prompts the user to input a Polar - % structure and determines the zero-lift angle of attack (ALPHA_ZEROL) and the - % drag coefficient at this angle (CD_ZEROL). + % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT prompts the user to input a Polar structure and + % determines the zero-lift angle of attack (ALPHA_ZEROL) and the drag coefficient at this + % angle (CD_ZEROL). % - % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(POLAR) uses the POLAR strcture given - % as input instead of prompting the user to select the file. + % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(POLAR) uses the POLAR strcture given as input instead + % of prompting the user to select the file. % - % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(ALPHA, CL) uses directly the values - % given in in ALPHA and CL to determine the zero-lift angle. As no CD is - % provided, CD_ZEROL will be an empty vector. + % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(ALPHA, CL) uses directly the values given in in ALPHA + % and CL to determine the zero-lift angle. As no CD is provided, CD_ZEROL will be an empty + % vector. % - % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(ALPHA, CL, CD) uses directly the - % values given in in ALPHA and CL to determine the zero-lift angle. As CD is - % provided, CD_ZEROL will be returned as well. + % [ALPHA_ZEROL, CD_ZEROL] = FINDZEROLIFT(ALPHA, CL, CD) uses directly the values given in in + % ALPHA and CL to determine the zero-lift angle. As CD is provided, CD_ZEROL will be returned + % as well. % % Inputs: % Polar : Polar structure (e.g. output from XF2MAT) @@ -54,10 +54,12 @@ function [alpha_zeroL, cd_zeroL] = findzerolift(varargin) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- narginchk(0, 3); @@ -76,14 +78,14 @@ function [alpha_zeroL, cd_zeroL] = findzerolift(varargin) % (avoid issues if extended polars are used as input) [alpha, cl, cd] = trimtorange(ORIGINAL_RANGE, alpha, cl, cd); - % ------------------------------------ + % ------------------------------------------- % Find zero lift for each polar [alpha_zeroL, cd_zeroL] = zerofinder(alpha, cl, cd); end -% -------------------------------------------------------------------------- +% -------------------------------------------------------------------------------------------------- function [alpha_zeroL, cd_zeroL] = zerofinder(alpha, cl, cd) % FINDZEROLIFTVECT Finds the zero-lift point and returns the corresponding AOA and CD % For vectors! diff --git a/+af_tools/nacaairfoil.m b/+af_tools/nacaairfoil.m index c896cdb..17c4fa3 100644 --- a/+af_tools/nacaairfoil.m +++ b/+af_tools/nacaairfoil.m @@ -1,47 +1,43 @@ function [x, y] = nacaairfoil(varargin) % NACAAIRFOIL Generates the full coordinates of a NACA 4 or 5 digits airfoil. - % By default, the airfoil is generated with 100 points distributed - % following a half-cosine rule in order to be finer at the leading and - % trailing edges. The default output has a zero thickness trailing edge. - % Coefficients for a finite trailing edge are also implemented. + % By default, the airfoil is generated with 100 points distributed following a half-cosine + % rule in order to be finer at the leading and trailing edges. The default output has a zero + % thickness trailing edge. Coefficients for a finite trailing edge are also implemented. % See below for details on how to override the defaults. % % Note: - % This function will always output an odd number of points, even if the user - % asks for an even value of nPoints. This is because the upper and - % lower surfaces will have the same number of points, and the leading - % edge is counted twice (as the first and last element to close the shape) - % while the trailing edge is counted once. + % This function will always output an odd number of points, even if the user asks for an even + % value of nPoints. This is because the upper and lower surfaces will have the same number of + % points, and the leading edge is counted twice (as the first and last element to close the + % shape) 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/-/issues">Report an issue</a> % ----- % % Usage: - % [X, Y] = NACAAIRFOIL prompts the user for the airfoil denomination, then - % determines its coordinates. + % [X, Y] = NACAAIRFOIL prompts the user for the airfoil denomination, then determines its + % coordinates. % - % [X, Y] = NACAAIRFOIL(DIGITS) determines the coordinates of the airfoil using - % the airfoil denomination given by DIGITS. + % [X, Y] = NACAAIRFOIL(DIGITS) determines the coordinates of the airfoil using the airfoil + % denomination given by DIGITS. % - % [X, Y] = NACAAIRFOIL(DIGITS, NPOINTS) determines the NPOINTS coordinates of - % the airfoil named after DIGITS. - % - % [...] = NACAAIRFOIL(..., 'spacing', SP) uses the defined spacing rule to - % determine to position of the coordinates. The available spacings are: + % [X, Y] = NACAAIRFOIL(DIGITS, NPOINTS) determines the NPOINTS coordinates of the airfoil + % named after DIGITS. % + % [...] = NACAAIRFOIL(..., 'spacing', SP) uses the defined spacing rule to determine to + % position of the coordinates. The available spacings are: % 'linear' - linear % 'halfcosine' - (default) finer at leading and trailing edges % 'cosine' - finer at leading edge, coarser at the trailing edge % - % [...] = NACAAIRFOIL(..., 'zerote', TE) picks between the zero thickness - % trailing edge or a finite one. The values for zerote are: - % + % [...] = NACAAIRFOIL(..., 'zerote', TE) picks between the zero thickness trailing edge or a + % finite one. The values for zerote are: % true - (default) zero thickness trailing edge % false - finite trailing edge % - % [...] = NACAAIRFOIL(..., 'savedat', false) saves the output coordinates in a - % dat files. savedat can either be true or false (default). + % [...] = NACAAIRFOIL(..., 'savedat', false) saves the output coordinates in a dat-file. + % savedat can either be true or false (default). % % Inputs: % digits : Character vector representing the NACA airfoil (ex: '0012', '24120', '24012') @@ -49,9 +45,9 @@ function [x, y] = nacaairfoil(varargin) % % Output: % [X, Y] : Airfoil coordinates, with 0 <= X <= 1. - % The output coordinates follow the most usual order. They start at - % the trailing edge, along the upper surface to the leading edge and - % back around the lower surface to trailing edge. + % The output coordinates follow the most usual order. They start at the trailing + % edge, along the upper surface to the leading edge and back around the lower surface + % to trailing edge. % % Example: % NACAAIRFOIL @@ -63,10 +59,12 @@ function [x, y] = nacaairfoil(varargin) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- narginchk(0, 6); @@ -81,11 +79,11 @@ function [x, y] = nacaairfoil(varargin) [digits, nPoints, idxOpts] = parsenacainputs(OPTION_LIST, varargin{:}); [spacing, zerote, savedat] = parseoptioninputs(varargin{idxOpts:end}); - % ------------------------------------ + % ------------------------------------------- % Coordinates calculation - % Get camberline (we use ceil((nPoints+1)/2) to ensure the airfoil has the same - % number of points on the upper and lower surfaces. + % Get camberline (we use ceil((nPoints+1)/2) to ensure the airfoil has the same number of points + % on the upper and lower surfaces. [xc, yc, gradY] = nacacamber(digits, ceil((nPoints + 1) / 2), 'spacing', spacing); % Flip camberline, so the first element is the trailing edge @@ -129,7 +127,7 @@ function [x, y] = nacaairfoil(varargin) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function [spacing, zerote, savedat] = parseoptioninputs(varargin) % PARSEOPTIONINPUTS Parses the options and checks their validity diff --git a/+af_tools/nacacamber.m b/+af_tools/nacacamber.m index c8a94d6..bd6a761 100644 --- a/+af_tools/nacacamber.m +++ b/+af_tools/nacacamber.m @@ -1,8 +1,7 @@ function [xc, yc, gradY] = nacacamber(varargin) % 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 - % following a half-cosine rule in order to be finer at the leading and - % trailing edges. + % By default, the camberline is generated with 100 points distributed following a half-cosine + % rule in order to be finer at the leading and trailing edges. % See below for details on how to override the defaults. % % <a href="https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox">Documentation (README)</a> @@ -10,20 +9,17 @@ function [xc, yc, gradY] = nacacamber(varargin) % ----- % % Usage: - % [X, Y] = NACACAMBER prompts the user for the airfoil digits, then calculates - % the coordinates of the camberline using 100 points spaced with the - % half-cosine rule. + % [X, Y] = NACACAMBER prompts the user for the airfoil digits, then calculates the coordinates + % of the camberline using 100 points spaced with the half-cosine rule. % - % [X, Y] = NACACAMBER(DIGITS) calculates the coordinates of the camberline for - % the NACA airfoil specified by DIGITS, without further input. + % [X, Y] = NACACAMBER(DIGITS) calculates the coordinates of the camberline for the NACA + % airfoil specified by DIGITS, without further input. % - % [X, Y] = NACACAMBER(DIGITS, NPOINTS) calculates the coordinates of the - % the NACA airfoil specified by DIGITS, using NPOINTS points spaced with the - % half-cosine rule. - % - % [...] = NACACAMBER(..., 'spacing', SP) uses the defined spacing rule to - % determine to position of the coordinates. The available spacings are: + % [X, Y] = NACACAMBER(DIGITS, NPOINTS) calculates the coordinates of the NACA airfoil + % specified by DIGITS, using NPOINTS points spaced with the half-cosine rule. % + % [...] = NACACAMBER(..., 'spacing', SP) uses the defined spacing rule to determine to + % position of the coordinates. The available spacings are: % 'linear' - linear % 'halfcosine' - (default) finer at leading and trailing edges % 'cosine' - finer at leading edge, coarser at the trailing edge @@ -46,10 +42,12 @@ function [xc, yc, gradY] = nacacamber(varargin) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- narginchk(0, 4); @@ -63,7 +61,7 @@ function [xc, yc, gradY] = nacacamber(varargin) [digits, nPoints, idxOpts] = parsenacainputs(OPTION_LIST, varargin{:}); [spacing] = parseoptioninputs(varargin{idxOpts:end}); - % ------------------------------------ + % ------------------------------------------- % Coordinates calculation if length(digits) == 4 @@ -74,7 +72,7 @@ function [xc, yc, gradY] = nacacamber(varargin) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function [spacing] = parseoptioninputs(varargin) % PARSEINPUTS Parses the input and checks their validity @@ -95,7 +93,7 @@ function [spacing] = parseoptioninputs(varargin) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function [xc, yc, gradY] = camber4digits(digits, nPoints, spacing) % CAMBER4DIGITS Give the camberline coordinates for a 4 digits airfoil. % @@ -127,7 +125,7 @@ function [xc, yc, gradY] = camber4digits(digits, nPoints, spacing) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function [xc, yc, gradY] = camber5digits(digits, nPoints, spacing) % CAMBER5DIGITS Give the camberline coordinates for a 5 digits airfoil. % @@ -178,7 +176,7 @@ function [xc, yc, gradY] = camber5digits(digits, nPoints, spacing) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function [r, k1, k2k1] = getcoeffs5digits(q, p) % GETCOEFFS5DIGITS Coefficients for the NACA 5-digit formula. % Source: http://www.airfoiltools.com/airfoil/naca5digit diff --git a/+af_tools/plotpolars.m b/+af_tools/plotpolars.m index c603bcc..d48ab33 100644 --- a/+af_tools/plotpolars.m +++ b/+af_tools/plotpolars.m @@ -2,14 +2,14 @@ function plotpolars(varargin) % PLOTPOLARS Plot various polars. % Plots the typical polars curves of an airfoil. % - % PLOTPOLARS accepts inputs in the form of a Polar structure (generated with - % XF2MAT) or values for angles of attack and their associated cl, cd and cm. + % PLOTPOLARS accepts inputs in the form of a Polar structure (generated with XF2MAT) or values + % 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 - % same number of rows (one for each angle of attack). The columns indicate - % values for different polars (different Mach, different Reynolds,...). - % For example, if the cl values are given for 2 different Reynols and there - % are 100 values for the aoa, cl and cd must be [100 x 2]. + % If the input is specified as aoa, cl and cd, the three arrays must have the same number of + % rows (one for each angle of attack). The columns indicate values for different polars + % (different Mach, different Reynolds,...). + % For example, if the cl values are given for 2 different Reynols and there are 100 values for + % the aoa, cl and cd must be [100 x 2]. % % Plots: % - Cl - aoa @@ -23,20 +23,19 @@ function plotpolars(varargin) % ----- % % Usage: - % PLOTPOLARS prompts the user to input a Polar structure and plots the various - % curves. + % PLOTPOLARS prompts the user to input a Polar structure and plots the various curves. % - % PLOTPOLARS(POLAR) uses the POLAR strcture given as input instead of - % prompting the user to select the file. + % PLOTPOLARS(POLAR) uses the POLAR strcture given as input instead of prompting the user to + % select the file. % - % PLOTPOLARS(ALPHA, CL) uses directly the values provided by ALPHA and CL to - % plot the available curves. + % PLOTPOLARS(ALPHA, CL) uses directly the values provided by ALPHA and CL to plot the + % available curves. % - % PLOTPOLARS(ALPHA, CL, CD) uses directly the values provided by ALPHA and CL - % and CD to plot the available curves. + % PLOTPOLARS(ALPHA, CL, CD) uses directly the values provided by ALPHA and CL and CD to plot + % the available curves. % - % PLOTPOLARS(ALPHA, CL, CD, CM) uses directly the values provided by ALPHA, CL, - % and CM to plot all possible curves. + % PLOTPOLARS(ALPHA, CL, CD, CM) uses directly the values provided by ALPHA, CL, and CM to plot + % all possible curves. % % Inputs: % Polar : Polar structure (e.g. output from XF2MAT) @@ -58,10 +57,12 @@ function plotpolars(varargin) % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- narginchk(0, 4); @@ -75,7 +76,7 @@ function plotpolars(varargin) % Extract and validate the inputs [alpha, cl, cd, cm] = parsepolarinputs(OPTION_LIST, varargin{:}); - % ------------------------------------ + % ------------------------------------------- % Plots set(0, 'defaultTextInterpreter', 'latex'); % Default interpreter for all plots @@ -93,7 +94,7 @@ function plotpolars(varargin) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function plotsinglepolar(dataX, dataY, fTitle, fXlabel, fYlabel) % PLOTSINGLE Standardize polar plots @@ -114,7 +115,7 @@ function plotsinglepolar(dataX, dataY, fTitle, fXlabel, fYlabel) setgca(); end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function setgca() % SETGCA Sets axes options for all plots diff --git a/+af_tools/uiuccleaner.m b/+af_tools/uiuccleaner.m index 1d72533..804b0de 100644 --- a/+af_tools/uiuccleaner.m +++ b/+af_tools/uiuccleaner.m @@ -1,47 +1,43 @@ function Dat = uiuccleaner(varargin) % UIUCCLEANER Cleans airfoil data from UIUC Airfoil Database. - % The UIUC airfoil database from the University of Illinois gathers the - % coordinates for more than 1600 airfoils. However, there is a few - % discrepancies between the format and ordering of these coordinates. This - % script alleviates that by re-formatting any input file from the original - % database. + % The UIUC airfoil database from the University of Illinois gathers the coordinates for more + % than 1600 airfoils. However, there is a few discrepancies between the format and ordering of + % these coordinates. This script alleviates that by re-formatting any input file from the + % original database. % % Format: - % The output format of this script follows the "labeled coordinates" file, - % used originally by Selig on the UIUC Airfoil Database. - % The first line contains the name of the airfoil, and each line after that is - % a set of coordinates. The coordinates are ordered from the trailing edge, - % along the upper surface to the leading edge and back around the lower - % surface to trailing edge. + % The output format of this script follows the "labeled coordinates" file, used originally by + % Selig on the UIUC Airfoil Database. + % The first line contains the name of the airfoil, and each line after that is a set of + % coordinates. The coordinates are ordered from the trailing edge, along the upper surface to + % the leading edge and back around the lower surface to trailing edge. % % Note: - % This function can be used on many files at once in order to speed-up the - % process. + % This function can be used on many files at once in order to speed-up the process. % % <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> % ----- % % Usage: - % DAT = UIUCCLEANER prompts the user for all inputs, then converts the - % coordinates to the correct standard. + % DAT = UIUCCLEANER prompts the user for all inputs, then converts the coordinates to the + % correct standard. % % DAT = UIUCCLEANER(INPUTDIR) converts all dat files found in INPUTDIR. % - % DAT = UIUCCLEANER(INPUTDIR, INPUTFILES) converts only the polars - % specified by INPUTFILES found in INPUTDIR. + % DAT = UIUCCLEANER(INPUTDIR, INPUTFILES) converts only the polars specified by INPUTFILES + % found in INPUTDIR. % - % DAT = UIUCCLEANER(..., 'autosave', true) saves the resulting coordinates - % in a new dat-file. + % DAT = UIUCCLEANER(..., 'autosave', true) saves the resulting coordinates in a new dat-file. % - % DAT = UIUCCLEANER(..., 'overwrite', true) saves the resulting coordinates - % by overwriting the original dat-file. If autosave is not specified but - % overwrite is true, the file will be overwritten anyway. If autosave is set - % to false and overwrite is true, the file will not be saved at all. + % DAT = UIUCCLEANER(..., 'overwrite', true) saves the resulting coordinates by overwriting the + % original dat-file. If autosave is not specified but overwrite is true, the file will be + % overwritten anyway. If autosave is set to false and overwrite is true, the file will not be + % saved at all. % - % DAT = UIUCCLEANER(..., 'refine', true) refines the input data by using a - % spline interpolation with 100 coordinates in total, spaced following the - % half-cosine rule. False by default. + % DAT = UIUCCLEANER(..., 'refine', true) refines the input data by using a spline + % interpolation with 100 coordinates in total, spaced following the half-cosine rule. + % False by default. % % Inputs: % inputDir : Path of the directory with the UIUC oridinal dat-files @@ -68,10 +64,12 @@ function Dat = uiuccleaner(varargin) % ----- % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- narginchk(0, 8); @@ -92,7 +90,7 @@ function Dat = uiuccleaner(varargin) % Convert filenames to string array allFileNames = string(allFileNames); - % ------------------------------------- + % ------------------------------------------- % Convert all files % Number of files found @@ -150,7 +148,7 @@ function Dat = uiuccleaner(varargin) end - % ------------------------------------- + % ------------------------------------------- % Save results automatically if autosave @@ -171,7 +169,7 @@ function Dat = uiuccleaner(varargin) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function [autosave, overwrite, refine] = parseoptioninputs(varargin) % PARSEOPTIONINPUTS Parses the options and checks their validity diff --git a/+af_tools/xf2mat.m b/+af_tools/xf2mat.m index 1121c35..af1057b 100644 --- a/+af_tools/xf2mat.m +++ b/+af_tools/xf2mat.m @@ -1,47 +1,43 @@ function Polar = xf2mat(varargin) % XF2MAT Aggregates multiple XFOIL or XFLR5 polar results into a single structure. - % This function aggregates different airfoil polars obtained with XFOIL or - % XFLR5 (saved as textfiles) into a single structure for easier handling in - % other scripts. + % This function aggregates different airfoil polars obtained with XFOIL or XFLR5 (saved as + % textfiles) into a single structure for easier handling in other scripts. % - % This function can be run without arguments, in this case it will prompt the - % user for the input. - % Otherwile, the function asks for two main arguments: + % This function can be run without arguments, in this case it will prompt the user for the + % input. Otherwhile, the function asks for two main arguments: % 1. inputDir: the directory where to look for the files % 2. inputFiles: the files to load % - % The function also comes with options to save automatically the resulting - % Polar structure and to trim all results to the same range of angles of - % attack. + % The function also comes with options to save automatically the resulting Polar structure and + % to trim all results to the same range of angles of attack. % % Note: - % If multiple textfiles are selected as input, by default, the function will - % extend every polar to the maximum range of angles of attack found. Polars - % with fewer data will be assigned NaN values at the missing angles of attack. - % If the 'trimAoas' is set to true, the function will find the largest common - % range of angles of attack accross the various input polars and trim - % everything to that range. This prevents NaN values in the polars, but - % removes some data from the most complete inputs. + % If multiple textfiles are selected as input, by default, the function will extend every + % polar to the maximum range of angles of attack found. Polars with fewer data will be + % assigned NaN values at the missing angles of attack. + % If the 'trimAoas' is set to true, the function will find the largest common range of angles + % of attack accross the various input polars and trim everything to that range. This prevents + % NaN values in the polars, but 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/-/issues">Report an issue</a> % ----- % % Usage: - % POLAR = XF2MAT prompts the user for all inputs, then aggregate and convert - % the polar in a single POLAR structure. + % POLAR = XF2MAT prompts the user for all inputs, then aggregate and convert the polar in a + % single POLAR structure. % - % POLAR = XF2MAT(INPUTDIR) aggregates all polars found in INPUTDIR into a - % single Polar structure. + % POLAR = XF2MAT(INPUTDIR) aggregates all polars found in INPUTDIR into a single Polar + % structure. % - % POLAR = XF2MAT(INPUTDIR, INPUTFILES) aggregates only the polars specified by - % INPUTFILES found in INPUTDIR into a single Polar structure. + % POLAR = XF2MAT(INPUTDIR, INPUTFILES) aggregates only the polars specified by INPUTFILES + % found in INPUTDIR into a single Polar structure. % - % POLAR = XF2MAT(..., 'autosave', true) saves the resulting POLAR structure - % automatically in a MAT-file. + % POLAR = XF2MAT(..., 'autosave', true) saves the resulting POLAR structure automatically in + % a MAT-file. % - % POLAR = XF2MAT(..., 'trimAoas', true) trims all input polars to the largest - % common range of angles of attack to prevent NaN values in the ouput. + % POLAR = XF2MAT(..., 'trimAoas', true) trims all input polars to the largest common range of + % angles of attack to prevent NaN values in the ouput. % % Inputs: % inputDir : Path of the directory with the XFOIL/XFLR5 data @@ -73,10 +69,12 @@ function Polar = xf2mat(varargin) % XFOIL: http://web.mit.edu/drela/Public/web/xfoil/ % 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 % Apache 2.0 License % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox + % ---------------------------------------------------------------------------------------------- narginchk(0, 6); @@ -98,7 +96,7 @@ function Polar = xf2mat(varargin) % Convert filenames to string array allFileNames = string(allFileNames); - % ------------------------------------- + % ------------------------------------------- % Process XFoil/XFLR5 results % Number of files found @@ -189,7 +187,7 @@ function Polar = xf2mat(varargin) Polar.cd(:, :) = Polar.cd(:, indSort); Polar.cm(:, :) = Polar.cm(:, indSort); - % ------------------------------------- + % ------------------------------------------- % Save results automatically if nargin == 0 % Prompt only if user input is to be expected @@ -236,7 +234,7 @@ function Polar = xf2mat(varargin) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function [autosave, trimAoas] = parseoptioninputs(varargin) % PARSEOPTIONINPUTS Parses the options and checks their validity @@ -259,7 +257,7 @@ function [autosave, trimAoas] = parseoptioninputs(varargin) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function aoaRange = findcommonrange(aoaRange, resArray) % FINDCOMMONRANGE Find the best common range accors all polars @@ -279,7 +277,7 @@ function aoaRange = findcommonrange(aoaRange, resArray) end -% ------------------------------------------------------------------------------ +% -------------------------------------------------------------------------------------------------- function aoaRange = findmaxrange(aoaRange, resArray) % FINDMAXRANGE Find the max range between all polars diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 27ce1c4..8c40b34 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,61 +3,162 @@ When contributing to this repository, please first discuss the change you wish 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 All changes submitted must conform to the following code standards. -### Main functions - -The so called _Main functions_ are the ones present in the root of `+af_tools/`. -These are the core functions of the package. - -- 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 - (this line is searched when the user type `lookfor <keyword>` in Matlab). The - next block of continuous comment is printed when the user types `help - <function>`. As this is the only documentation provided for the different - 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 - 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. +### Function design + +The functions of this packages are divided in two parts: the _main functions_ +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 +directly by the users. The _utilities_ are located in `+af_tools/+utils/`. These +are small sub-routines, meant to perform basic tasks and shared among the +different _main functions_. These sub-routines are not intended to be called by +the end user (although they could if they want). Therefore they do not require +the same level of documentation, testing, etc. + +- Each main function should be standalone tool that makes a complete operation. - 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 prompted through the command window or a dialog box. All other arguments - should be set at proper defaults values. -- 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). + should be set at proper defaults values (documented in the help block). - The functions must be inter-operable with little effort from the user - (function B reuses the output of function A without much modification). -- The functions can be called directly from one another. In that case, the + (function B reuses the output of function A without much modification). This + 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. -- 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 -interest in themselves, but are shared by different _Main functions_. To -separate them clearly, they must be placed in `+af_tools/+utils/`. +Besides typical style verification (spaces at the right spot, line width, etc), +MISS_HIT is also used to analyze the complexity of the code. To simplify +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. -- 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 @@ -66,4 +167,8 @@ separate them clearly, they must be placed in `+af_tools/+utils/`. 2. Ensure all tests pass in Matlab (`runtests('tests')`). 3. Update the CHANGELOG.md and CODEOWNERS to document the changes. 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 diff --git a/miss_hit.cfg b/miss_hit.cfg index 12a5360..8f01876 100644 --- a/miss_hit.cfg +++ b/miss_hit.cfg @@ -1,24 +1,29 @@ # miss_hit style checker # (https://florianschanda.github.io/miss_hit/style_checker.html) +# +project_root # Ensure copyright notice is everywhere +copyright_primary_entity: "University of Liege" copyright_entity: "Thomas Lambert <t.lambert@uliege.be>" -copyright_entity: "University of Liège" -# Currently disbale miss_hit by default, enable it on a per folder basis +# Enable miss_hit on the whole repo enable: 1 +enforce_encoding: "utf8" # Layout line_length: 100 tab_width: 4 # Regex to enforce naming convention -suppress_rule: "naming_parameters" -regex_function_name: "[a-z]([a-zA-Z0-9])+" -regex_parameter_name: "[a-zA-Z]([a-zA-Z0-9])+" +regex_function_name: "[a-z]([a-z0-9]+)*" +regex_parameter_name: "[a-zA-Z](_?[a-zA-Z0-9]+)*" -# metrics limit for the code quality (https://florianschanda.github.io/miss_hit/metrics.html) +# metrics limit for the code quality +# (https://florianschanda.github.io/miss_hit/metrics.html) metric "cnest": limit 5 metric "file_length": limit 800 -metric "cyc": limit 16 -metric "parameters": limit 6 +metric "cyc": limit 15 +metric "parameters": limit 8 +metric "globals": limit 0 +metric "persistent": limit 0 -- GitLab