diff --git a/CHANGELOG.md b/CHANGELOG.md index e1018e433c473def66547fd00f3bea1c65663107..ca86f91436843e1b4f814f66276dfea30490ca12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ to [Semantic Versioning][sem_ver]. - Basic result summary table - Basic result plotting function +- Result filtering function ### Changed diff --git a/src/classes/@Result/Result.m b/src/classes/@Result/Result.m index 4fa4f0ed2ea2ee5dbe6d57a65b9e400c316c4db9..5230a0ed9f4f4e13d9206e7c9aab9051bcacca10 100644 --- a/src/classes/@Result/Result.m +++ b/src/classes/@Result/Result.m @@ -98,6 +98,7 @@ classdef Result < handle % Other methods save(self, SaveOpts) % Save the results to file summaryTable = summarize(self, propList) % Summarize results + [filtered, idx] = filter(self, alt, speed, rpm, coll) % Filter results end end diff --git a/src/classes/@Result/filter.m b/src/classes/@Result/filter.m new file mode 100644 index 0000000000000000000000000000000000000000..436858f386967841f1254a20931c041a697af4a4 --- /dev/null +++ b/src/classes/@Result/filter.m @@ -0,0 +1,70 @@ +function [filtered, idx] = filter(self, alt, speed, rpm, coll) + % FILTER Filter results based on operating point. + % This method isolate the OperRotor instances for each solver that corresponds to the + % operating point. + % + % ----- + % + % Syntax: + % [filtered, idx] = Result.filter(alt, rpm, coll, speed) Return the Results of the four + % solvers for the operating point defined by `alt`, `rpm`, `coll`, `speed`. + % + % Inputs: + % alt : Altitude, [m] + % rpm : Rotational speed, [rpm] + % coll : Collective pitch, [deg] + % speed : Axial velocity, [m/s] + % + % Outputs: + % filtered : Result instance with only one instance for leishman, indfact, indevl and stahlhut + % properties. + % idx : Index of the simulation corresponding to the operating point + % + % Example: + % ResRot.filter( 0, 0, 1250, 5) + % + % See also: rotare, Result, template. + % + % <a href="https://gitlab.uliege.be/rotare/documentation">Complete documentation (online)</a> + + % ---------------------------------------------------------------------------------------------- + % (c) Copyright 2022-2023 University of Liege + % Author: Thomas Lambert <t.lambert@uliege.be> + % ULiege - Aeroelasticity and Experimental Aerodynamics + % MIT License + % Repo: https://gitlab.uliege.be/rotare/rotare + % Docs: https://gitlab.uliege.be/rotare/documentation + % Issues: https://gitlab.uliege.be/rotare/rotare/-/issues + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % Defaults and constants + DEF.ALLOWED_SOLVERS = {'leishman', 'indfact', 'indvel', 'stahlhut'}; + + % Input validation + validateattributes(alt, {'numeric'}, {'scalar'}); + validateattributes(speed, {'numeric'}, {'scalar'}); + validateattributes(rpm, {'numeric'}, {'scalar'}); + validateattributes(coll, {'numeric'}, {'scalar'}); + + function idx = getidx(type, val) + idx = self.operPts.(type) == val | isnan(val); + end + + iAlt = getidx('altitude', alt); + iSpeed = getidx('speed', speed); + iRpm = getidx('rpm', rpm); + iColl = getidx('collective', coll); + + idx = iAlt & iColl & iRpm & iSpeed; + + % Filter for the solvers only (rest is useless or redundant here) + for iSolv = 1:length(DEF.ALLOWED_SOLVERS) + thissolv = DEF.ALLOWED_SOLVERS{iSolv}; + if ~isempty(self.(thissolv)) + filtered.(thissolv) = self.(thissolv)(1, idx); + else + filtered.(thissolv) = self.(thissolv); + end + end + +end