diff --git a/classes/Bay.m b/classes/Bay.m index d051373340d27bb26cd40496b53e1e422021437d..b7e177537439bdf53a6a95443e04992d00bc8022 100644 --- a/classes/Bay.m +++ b/classes/Bay.m @@ -10,7 +10,7 @@ classdef Bay < Component & matlab.mixin.Heterogeneous xCg % [m] Cg relative to bay upper side end - methods (Static,Sealed,Access=protected) + methods (Static, Sealed, Access=protected) function default = getDefaultScalarElement default = Payload; end diff --git a/classes/Component.m b/classes/Component.m index 554d155a7472aa558f8d523c1b48a79b859e2bed..5d90bc927821f77d9a7383c8da51a1ac5eebc18d 100644 --- a/classes/Component.m +++ b/classes/Component.m @@ -28,48 +28,12 @@ classdef Component < Config varName = strtok(fileName, 'C'); end - [m, n] = size(varsIn.(varName)); - objMatrix(m,n) = obj; - - for i = 1:m - for j = 1:n - varIn.(varName) = varsIn.(varName)(i,j); - objMatrix(i,j).loadConfig(varIn); - end - end - obj = objMatrix; + [varsIn.(varName).mission] = deal(mission); + obj = varsIn.(varName); end end - + methods(Access = protected) - function loadConfig(obj, varargin) - % This method loads desired configs into calling component. - % The component can chose between: - % - Only specifying the configName (name of the config file): - % The loader will look for a variable named like the - % config file. - % - Specifying both the configName and the variableName: - % Useful for when you want to group multiple small - % objects into a larger config file - % - % Syntax: - % obj.loadConfig() - To load from a config file - % obj.loadConfig(vars) - To load from given variables - - fileName = obj.configName; - varName = obj.variableName; - if isempty(varName), varName = strtok(fileName, 'C'); end - - if nargin == 2, configObj = varargin{end}.(varName); - else, configObj = obj.getConfig(); end - - fields = obj.getProperties('writable'); - for j = 1:size(fields, 2) - if isempty(configObj.(fields{j})), continue; end - obj.(fields{j}) = configObj.(fields{j}); - end - end - function outputVariables = getConfig(obj) fileName = obj.configName; filePath = obj.mission.configPath; diff --git a/classes/Rocket.m b/classes/Rocket.m index 85593264572dbba5a471f5b6234c101d8a445f06..517f74842064b5d7205c8807f23ffd04d205a241 100644 --- a/classes/Rocket.m +++ b/classes/Rocket.m @@ -229,12 +229,13 @@ classdef Rocket < Component options.checkGeometry logical = true end obj@Component(mission, varIn); - obj.mission = mission; %% Loading data if nargin == 0 return; end + obj.mission = mission; + vars = obj.getConfig(); % Load config once and apply to other bays obj.payload = Payload(mission, vars); obj.recovery = Recovery(mission, vars); diff --git a/classes/bays/Motor.m b/classes/bays/Motor.m index 3f1598b0ee18b1a993f1a08718b1eb09aa2740cb..909d992560f8dd1557db59cca6b55bcf2eae166d 100644 --- a/classes/bays/Motor.m +++ b/classes/bays/Motor.m @@ -30,7 +30,7 @@ classdef Motor < Bay ae double % [Pa] Eflux Area end - properties(Dependent) + properties mass % [kg] Total Motor mass fuselageXCg double % [m] xcg of the engine fuselage only from tank tip end @@ -53,20 +53,19 @@ classdef Motor < Bay end obj@Bay(mission, varIn); obj.loadData(); + obj.updateAll(); end function set.name(obj, name) obj.name = name; obj.loadData(); + obj.updateAll(); end - function mass = get.mass(obj) - mass = obj.propellantMass + obj.structureMass; - end - - function fuselageXCg = get.fuselageXCg(obj) - fuselageXCg = (obj.length - ... + function updateAll(obj) + obj.fuselageXCg = (obj.length - ... obj.tankLength)/2 + obj.tankLength; + obj.mass = obj.propellantMass + obj.structureMass; end end diff --git a/classes/components/Environment.m b/classes/components/Environment.m index cbdc0e72aaa6e71d493b60d64f6283aafeed5a6f..4c6806100c2b9d00047b6260938f8d2b0cefdb89 100644 --- a/classes/components/Environment.m +++ b/classes/components/Environment.m @@ -56,15 +56,19 @@ classdef Environment < Component obj.omega = deg2rad(obj.omega); obj.phi = deg2rad(obj.phi); - obj.updateG0; - obj.updatePinDistance; - obj.updateRamp; - obj.updateLocal; + obj.updateAll(); end end % Updaters methods + function updateAll(obj) + obj.updateG0; + obj.updatePinDistance; + obj.updateRamp; + obj.updateLocal; + end + function obj = updateG0(obj) obj.g0 = gravitywgs84(obj.z0, obj.lat0); end diff --git a/classes/components/WindCustom.m b/classes/components/WindCustom.m index af8f0f86ca96467b782264dbdb3cc0b370bbb9d3..99d26ba500d01891a7ca153c383c10281282ed64 100644 --- a/classes/components/WindCustom.m +++ b/classes/components/WindCustom.m @@ -38,7 +38,7 @@ classdef WindCustom < Component varIn = [] end obj@Component(mission, varIn); - obj.setData(); + obj.updateAll(); end function [uw, vw, ww] = getVels(obj, z) @@ -57,7 +57,7 @@ classdef WindCustom < Component end end - function obj = setData(obj) + function updateAll(obj) s = length(obj.altitudes); magVector = nan(1,s); azVector = nan(1,s); diff --git a/functions/eventFunctions/eventLanding.m b/functions/eventFunctions/eventLanding.m index 3df933fa1c07402bc5e62e70801c16696d0a66bd..fc7aa9db5a49887a143eba7ac5bfdb185de48c20 100644 --- a/functions/eventFunctions/eventLanding.m +++ b/functions/eventFunctions/eventLanding.m @@ -1,4 +1,4 @@ -function [value, isterminal, direction] = eventLanding(~, Y, ~, ~, ~, ~) +function [value, isterminal, direction] = eventLanding(~, Y, varargin) %{ eventLanding - Event function to stop simulation at landing checking when a value tends to zero; the value taken is to account is the