From eb8921893427d12d3e4761c710e6615ed7e4e639 Mon Sep 17 00:00:00 2001 From: Mauco03 <marco.gaibotti@skywarder.eu> Date: Sun, 20 Apr 2025 15:19:39 +0200 Subject: [PATCH] [coeff-transpot] Added total coefficients --- classes/misc/Coefficient.m | 70 +++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/classes/misc/Coefficient.m b/classes/misc/Coefficient.m index a230fbf..4af9ad6 100644 --- a/classes/misc/Coefficient.m +++ b/classes/misc/Coefficient.m @@ -10,7 +10,7 @@ classdef Coefficient % - name: (optional) coefficient name. Used when dynamic % derivatives are also needed % - % Coefficients are retrieved from DM in the following format: + % Coefficients are retrieved from DATCOM in the following format: % Coefficient matrix: double (15, nAlpha, nMach, nBeta, nAlt, nAbk, nXcg) % Where the 15 coefficients are % - CA Axial force @@ -44,9 +44,7 @@ classdef Coefficient % dimension, instead of the first, to improve performance properties(Dependent) - static double % Static coefficients: [CA, CY, CN, Cl, Cm, Cn] - dynamic double % Dynamic derivatives: [Clp, Cmad, Cmq, Cnr, Cnp] - + total double % Coefficients stored in DATCOM format geometry struct % Reference geometry state struct % Flight envelope end @@ -55,14 +53,19 @@ classdef Coefficient finsCN double % Fins-only CN end + properties(Dependent, SetAccess = private) + static double % Static coefficients: [CA, CY, CN, Cl, Cm, Cn] + dynamic double % Dynamic derivatives: [Clp, Cmad, Cmq, Cnr, Cnp] + end + + properties(SetAccess = private) isReady (1, 1) logical % Whether all coefficients are loaded and of the right size isDynamic (1, 1) logical % Whether to load dynamic derivatives. Adds XCG dependece end properties(Access = private) - STATIC % Cached variable for static coefficients - DYNAMIC % Cached variable for dynamic derivatives + TOTAL % Cached variable for total GEOMETRY % Cached variable for geometry STATE % Cached variable for state end @@ -75,9 +78,11 @@ classdef Coefficient methods function obj = Coefficient(filePath, name) arguments - filePath (1, :) char + filePath (1, :) char = '' name (1, :) char = 'generic' end + + if isempty(filePath), return; end obj = obj.loadData(filePath, name); obj.isReady = obj.checkProperties(); @@ -128,12 +133,17 @@ classdef Coefficient end methods % Getters + function value = get.total(obj) + value = obj.TOTAL; + end + function value = get.static(obj) - value = obj.STATIC; + value = obj.TOTAL([1, 3, 5, 6, 9, 13], :, :, :, :, :, 1); end function value = get.dynamic(obj) - value = obj.DYNAMIC; + if ~obj.isDynamic, value = []; return; end + value = obj.TOTAL([7, 10, 11, 14, 15], :, :, :, :, :, :); end function value = get.geometry(obj) @@ -146,16 +156,11 @@ classdef Coefficient end methods % Setters - function obj = set.static(obj, value) - obj.STATIC = value(:, :, :, :, :, :, 1); - obj.isReady = obj.checkProperties(); - obj = obj.updateInterpolants(); - end - - function obj = set.dynamic(obj, value) - obj.DYNAMIC = value(:, :, :, :, :, :, :); - obj.isReady = obj.checkProperties(); - obj = obj.updateInterpolants(); + function obj = set.total(obj, value) + obj.TOTAL = value; + obj.isDynamic = size(value, 7) ~= 1; + obj.isReady = obj.checkProperties(); + obj = obj.updateInterpolants(); end function obj = set.geometry(obj, value) @@ -190,25 +195,19 @@ classdef Coefficient if ~isfield(dataCoeffs, name), return; end dataCoeffs = dataCoeffs.(name); - obj.isDynamic = ~strcmp(name, 'generic'); obj.finsCN = dataCoeffs.finsCN; obj.GEOMETRY = dataCoeffs.geometry; obj.STATE = dataCoeffs.state; - % Load CA, CY, CN, Cl, Cm, Cn - obj.STATIC = dataCoeffs.total([1, 3, 5, 6, 9, 13], :, :, :, :, :, :); - - if obj.isDynamic - % Load Clp, Cmad, Cmq, Cnr, Cnp - obj.DYNAMIC = dataCoeffs.total([7, 10, 11, 14, 15], :, :, :, :, :, :); - end + % Load coefficients + obj.total = dataCoeffs.total; end function ready = checkProperties(obj) % Check if STATIC, DYNAMIC, GEOMETRY, and STATE are non-empty - ready = ~isempty(obj.STATIC) && ... + ready = ~isempty(obj.static) && ... ~isempty(obj.GEOMETRY) && ~isempty(obj.STATE) && ... - ~(isempty(obj.DYNAMIC) && obj.isDynamic); + ~(isempty(obj.dynamic) && obj.isDynamic); if ~ready, return; end @@ -223,14 +222,7 @@ classdef Coefficient dims = cellfun(@(x) length(x), gridVecs); dims(dims == 0) = 1; % Empty case is the same as scalar case - staticDimsReady = all(size(obj.STATIC, 2:6) == dims(1:end-1)); - dynamicDimsReady = true; - - if obj.isDynamic - dynamicDimsReady = all(size(obj.DYNAMIC, 2:7) == dims); - end - - ready = ready && staticDimsReady && dynamicDimsReady; + ready = all(size(obj.total, 2:7) == dims); end function obj = updateInterpolants(obj) @@ -255,7 +247,7 @@ classdef Coefficient gridVecs(singletonDims) = deal({[0, 1]}); %% Create interpolants - staticCoeffs = permute(obj.STATIC, [2, 3, 4, 5, 6, 1]); + staticCoeffs = permute(obj.static, [2, 3, 4, 5, 6, 1]); staticCoeffs = repmat(staticCoeffs, singletonDims(1:end-1) + 1); % Exclude xcg for static coefficients obj.staticInterpolant = griddedInterpolant(gridVecs(1:end-1), staticCoeffs, 'linear', 'nearest'); @@ -263,7 +255,7 @@ classdef Coefficient if ~obj.isDynamic, return; end %% Handle dynamic derivatives - dynamicCoeffs = permute(obj.DYNAMIC, [2, 3, 4, 5, 6, 7, 1]); + dynamicCoeffs = permute(obj.dynamic, [2, 3, 4, 5, 6, 7, 1]); % Flip xcg in case of descending order if ~isscalar(xcg) && xcg(2) < xcg(1) -- GitLab