Skip to content
Snippets Groups Projects
Commit eb892189 authored by Marco Luigi Gaibotti's avatar Marco Luigi Gaibotti
Browse files

[coeff-transpot] Added total coefficients

parent b426f4da
Branches
No related tags found
1 merge request!21Implemented coefficient transport on rocket data
......@@ -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,10 +78,12 @@ 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();
obj = obj.updateInterpolants();
......@@ -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,14 +156,9 @@ 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(:, :, :, :, :, :, :);
function obj = set.total(obj, value)
obj.TOTAL = value;
obj.isDynamic = size(value, 7) ~= 1;
obj.isReady = obj.checkProperties();
obj = obj.updateInterpolants();
end
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment