From 0494a9bf254447acbd9e78f4d75bd8b3f9eaed04 Mon Sep 17 00:00:00 2001 From: Thomas Lambert <t.lambert@uliege.be> Date: Tue, 30 May 2023 22:35:17 +0200 Subject: [PATCH] feat(Result): add filter --- CHANGELOG.md | 1 + src/classes/@Result/Result.m | 1 + src/classes/@Result/filter.m | 70 ++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 src/classes/@Result/filter.m diff --git a/CHANGELOG.md b/CHANGELOG.md index e1018e4..ca86f91 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 4fa4f0e..5230a0e 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 0000000..436858f --- /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 -- GitLab