Skip to content

Commit

Permalink
LVD: Added settings to LvdData and populated the various functions wi…
Browse files Browse the repository at this point in the history
…th calls to those settings.
  • Loading branch information
Arrowstar committed Oct 14, 2018
1 parent 3a1cd4b commit 7739f04
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
initStateModel InitialStateModel
optimizer LvdOptimization
validation LaunchVehicleDataValidation
settings LvdSettings

celBodyData struct
ksptotVer(1,:) char
Expand All @@ -21,6 +22,7 @@
methods(Access = private)
function obj = LvdData()
obj.validation = LaunchVehicleDataValidation(obj);
obj.settings = LvdSettings();
end
end

Expand Down Expand Up @@ -63,7 +65,7 @@

simMaxDur = 20000;
minAltitude = -1;
simDriver = LaunchVehicleSimulationDriver(simMaxDur, minAltitude, celBodyData);
simDriver = LaunchVehicleSimulationDriver(lvdData);

%Set Up Initial Launch Vehicle
lv = LaunchVehicle.createDefaultLaunchVehicle(lvdData);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
classdef LvdOptimAlgorithmEnum < matlab.mixin.SetGet
%LvdOptimAlgorithmEnum Summary of this class goes here
% Detailed explanation goes here

enumeration
InteriorPoint('interior-point');
SQP('sqp');
ActiveSet('active-set');
end

properties
algoName(1,:) char
end

methods
function obj = LvdOptimAlgorithmEnum(algoName)
obj.algoName = algoName;
end
end
end

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function optimize(obj, writeOutput)
typicalX = obj.vars.getTypicalXVector();
nonlcon = @(x) obj.constraints.evalConstraints(x);

optimAlg = 'interior-point';
usePara = true;
optimAlg = obj.lvdData.settings.optAlgo.algoName;
usePara = obj.lvdData.settings.optUsePara;
options = optimoptions('fmincon','Algorithm',optimAlg, 'Diagnostics','on', 'Display','iter-detailed','TolFun',1E-10,'TolX',1E-10,'TolCon',1E-10,'ScaleProblem','obj-and-constr','TypicalX',typicalX,'MaxIter',500,'UseParallel',usePara,'OutputFcn',[],'HonorBounds',true,'MaxFunctionEvaluations',3000, 'FunValCheck','on');
problem = createOptimProblem('fmincon', 'objective',objFuncWrapper, 'x0', x0All, 'lb', lbAll, 'ub', ubAll, 'nonlcon', nonlcon, 'options', options);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
classdef LvdSettings < matlab.mixin.SetGet
%LvdSettings Summary of this class goes here
% Detailed explanation goes here

properties
%integration
intAbsTol(1,1) double = 1E-6;
intRelTol(1,1) double = 1E-6;
minAltitude(1,1) double = -1; %km
simMaxDur(1,1) double = 20000; %sec

%optimization
optUsePara(1,1) logical = false;
optAlgo LvdOptimAlgorithmEnum = LvdOptimAlgorithmEnum.InteriorPoint
end

methods
function obj = LvdSettings()

end
end
end
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
classdef LaunchVehicleSimulationDriver < matlab.mixin.SetGet
%LaunchVehicleSimulationDrive Summary of this class goes here
%LaunchVehicleSimulationDriver Summary of this class goes here
% Detailed explanation goes here

properties
forceModel(1,1) AbstractForceModel = TotalForceModel();
integrator(1,1) function_handle = @ode45;

simMaxDur(1,1) double = 600; %sec
minAltitude = -1; %km

lvdData LvdData
end

properties(Dependent)
relTol(1,1) double
absTol(1,1) double
simMaxDur(1,1) double
minAltitude(1,1) double
celBodyData(1,1) struct
end

methods
function obj = LaunchVehicleSimulationDriver(simMaxDur, minAltitude, celBodyData)
obj.simMaxDur = simMaxDur;
obj.minAltitude = minAltitude;
obj.celBodyData = celBodyData;
function obj = LaunchVehicleSimulationDriver(lvdData)
obj.lvdData = lvdData;
end

function value = get.relTol(obj)
value = obj.lvdData.settings.intRelTol;
end

function value = get.absTol(obj)
value = obj.lvdData.settings.intAbsTol;
end

function value = get.simMaxDur(obj)
value = obj.lvdData.settings.simMaxDur;
end

function value = get.minAltitude(obj)
value = obj.lvdData.settings.minAltitude;
end

function value = get.celBodyData(obj)
value = obj.lvdData.celBodyData;
end

function [t,y,newStateLogEntries] = integrateOneEvent(obj, event, eventInitStateLogEntry)
Expand All @@ -30,7 +53,7 @@
odefun = @(t,y) obj.odefun(t,y, obj, eventInitStateLogEntry, dryMass);
odeEventsFun = @(t,y) obj.odeEvents(t,y, obj, eventInitStateLogEntry, event.termCond.getEventTermCondFuncHandle());
odeOutputFun = @(t,y,flag) obj.odeOutput(t,y,flag, now()*86400);
options = odeset('RelTol',1E-6, 'AbsTol',1E-6, 'NonNegative',tankStateInds, 'Events',odeEventsFun, 'NormControl','on', 'OutputFcn',odeOutputFun);
options = odeset('RelTol',obj.relTol, 'AbsTol',obj.absTol, 'NonNegative',tankStateInds, 'Events',odeEventsFun, 'NormControl','on', 'OutputFcn',odeOutputFun);

[value,isterminal,~] = odeEventsFun(tspan(1), y0);
if(any(abs(value)<=1E-6))
Expand Down
Binary file modified kspTOT_MissionArchitect/LaunchVehicleDesigner/ma_LvdMainGUI.fig
Binary file not shown.
202 changes: 199 additions & 3 deletions kspTOT_MissionArchitect/LaunchVehicleDesigner/ma_LvdMainGUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

% Edit the above text to modify the response to help ma_LvdMainGUI

% Last Modified by GUIDE v2.5 14-Oct-2018 14:43:52
% Last Modified by GUIDE v2.5 14-Oct-2018 15:17:09

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
Expand Down Expand Up @@ -895,31 +895,227 @@ function optimSettingsMenu_Callback(hObject, eventdata, handles)
% hObject handle to optimSettingsMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
lvdData = getappdata(handles.ma_LvdMainGUI,'lvdData');

parallelOptim = lvdData.settings.optUsePara;
if(parallelOptim==true)
set(handles.optUseParaMenu, 'Checked', 'on');
else
set(handles.optUseParaMenu, 'Checked', 'off');
end

% --------------------------------------------------------------------
function optAlgorithmMenu_Callback(hObject, eventdata, handles)
% hObject handle to optAlgorithmMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
lvdData = getappdata(handles.ma_LvdMainGUI,'lvdData');

optAlgo = lvdData.settings.optAlgo;
switch optAlgo
case LvdOptimAlgorithmEnum.InteriorPoint
set(handles.optInteriorPointAlgoMenu, 'Checked', 'on');
set(handles.optSqpAlgoMenu, 'Checked', 'off');
set(handles.optActiveSetAlgoMenu, 'Checked', 'off');
case LvdOptimAlgorithmEnum.SQP
set(handles.optInteriorPointAlgoMenu, 'Checked', 'off');
set(handles.optSqpAlgoMenu, 'Checked', 'on');
set(handles.optActiveSetAlgoMenu, 'Checked', 'off');
case LvdOptimAlgorithmEnum.ActiveSet
set(handles.optInteriorPointAlgoMenu, 'Checked', 'off');
set(handles.optSqpAlgoMenu, 'Checked', 'off');
set(handles.optActiveSetAlgoMenu, 'Checked', 'on');
otherwise
error('Unknown optimization algorithm when setting menu checkmark.');
end

% --------------------------------------------------------------------
function optUseParaMenu_Callback(hObject, eventdata, handles)
% hObject handle to optUseParaMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

lvdData = getappdata(handles.ma_LvdMainGUI,'lvdData');
writeOutput = getappdata(handles.ma_LvdMainGUI,'write_to_output_func');

if strcmp(get(gcbo, 'Checked'),'on')
set(gcbo, 'Checked', 'off');
lvdData.settings.optUsePara = false;
writeOutput('Parallel optimization mode disabled.','append');
else
set(gcbo, 'Checked', 'on');
lvdData.settings.optUsePara = true;

drawnow;
p = gcp('nocreate');
if(isempty(p))
try
h = msgbox('Attempting to start parallel computing workers. Please wait...');
pp=parpool('local',feature('numCores'));
pp.IdleTimeout = 99999; %we don't want the pool to shutdown
if(isvalid(h))
close(h);
end
writeOutput('Parallel optimization mode enabled.','append');
catch ME %#ok<NASGU>
if(ishandle(h))
close(h);
end
msgbox('Parallel mode start failed. Optimization will run in serial.');
end
else
writeOutput('Parallel optimization mode enabled.','append');
end
end

% --------------------------------------------------------------------
function integrationAbsTolMenu_Callback(hObject, eventdata, handles)
% hObject handle to integrationAbsTolMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

lvdData = getappdata(handles.ma_LvdMainGUI,'lvdData');
writeOutput = getappdata(handles.ma_LvdMainGUI,'write_to_output_func');

input_str = sprintf(['Enter the desired integration absolute error tolerance:\n',...
'(Minimum = 1E-14, Maximum = 1E-2)\n',...
'(This will influence script execution speed.)']);
str = inputdlg(input_str, 'Absolute Error Tolerance', [1 75], {num2str(lvdData.settings.intAbsTol,'%6.6E')});
if(isempty(str))
return;
end

str = str{1};

if(checkStrIsNumeric(str) && str2double(str) >= 1E-14 && str2double(str) <= 1E-2)
writeOutput(sprintf('Setting integration absolute error tolerance to %s.', str),'append');

lvdData.settings.intAbsTol = str2double(str);

runScript(handles, lvdData);
lvd_processData(handles);
else
writeOutput(sprintf('Could not set the desired integration absolute error tolerance. "%s" is an invalid entry.', str),'append');
beep;
end

% --------------------------------------------------------------------
function integrationRelTolMenu_Callback(hObject, eventdata, handles)
% hObject handle to integrationRelTolMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
lvdData = getappdata(handles.ma_LvdMainGUI,'lvdData');
writeOutput = getappdata(handles.ma_LvdMainGUI,'write_to_output_func');

input_str = sprintf(['Enter the desired integration relative error tolerance:\n',...
'(Minimum = 1E-14, Maximum = 1E-2)\n',...
'(This will influence script execution speed.)']);
str = inputdlg(input_str, 'Relative Error Tolerance', [1 75], {num2str(lvdData.settings.intRelTol,'%6.6E')});
if(isempty(str))
return;
end

str = str{1};

if(checkStrIsNumeric(str) && str2double(str) >= 1E-14 && str2double(str) <= 1E-2)
writeOutput(sprintf('Setting integration relative error tolerance to %s.', str),'append');

lvdData.settings.intRelTol = str2double(str);

runScript(handles, lvdData);
lvd_processData(handles);
else
writeOutput(sprintf('Could not set the desired integration relative error tolerance. "%s" is an invalid entry.', str),'append');
beep;
end

% --------------------------------------------------------------------
function intMinAltitudeMenu_Callback(hObject, eventdata, handles)
% hObject handle to intMinAltitudeMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
lvdData = getappdata(handles.ma_LvdMainGUI,'lvdData');
writeOutput = getappdata(handles.ma_LvdMainGUI,'write_to_output_func');

input_str = sprintf(['Enter the desired minimum integration altitude (km):\n',...
'(Minimum = -Inf km, Maximum = 0 km)\n', ...
'(Script execution stops if the vehicle reaches this altitude.)']);
str = inputdlg(input_str, 'Minimum Integration Altitude', [1 75], {fullAccNum2Str(lvdData.settings.minAltitude)});
if(isempty(str))
return;
end

str = str{1};

if(checkStrIsNumeric(str) && str2double(str) >= -Inf && str2double(str) <= 0.0)
writeOutput(sprintf('Setting minimum integration altitude to %s km.', str),'append');

lvdData.settings.minAltitude = str2double(str);

runScript(handles, lvdData);
lvd_processData(handles);
else
writeOutput(sprintf('Could not set the desired minimum integration altitude. "%s" is an invalid entry.', str),'append');
beep;
end

% --------------------------------------------------------------------
function intMaxSimTimeMenu_Callback(hObject, eventdata, handles)
% hObject handle to intMaxSimTimeMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
lvdData = getappdata(handles.ma_LvdMainGUI,'lvdData');
writeOutput = getappdata(handles.ma_LvdMainGUI,'write_to_output_func');

input_str = sprintf(['Enter the desired maximum simulation time (sec):\n',...
'(Minimum = 0.0 sec, Maximum = Inf sec)\n', ...
'(Script execution stops if the duration of the mission exceeds this value.)']);
str = inputdlg(input_str, 'Maximum Simulation Time', [1 75], {fullAccNum2Str(lvdData.settings.simMaxDur)});
if(isempty(str))
return;
end

str = str{1};

if(checkStrIsNumeric(str) && str2double(str) >= 0 && str2double(str) <= Inf)
writeOutput(sprintf('Setting maximum simulation time to %s sec.', str),'append');

lvdData.settings.simMaxDur = str2double(str);

runScript(handles, lvdData);
lvd_processData(handles);
else
writeOutput(sprintf('Could not set the desired maximum simulation time. "%s" is an invalid entry.', str),'append');
beep;
end

% --------------------------------------------------------------------
function optInteriorPointAlgoMenu_Callback(hObject, eventdata, handles)
% hObject handle to optInteriorPointAlgoMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
lvdData = getappdata(handles.ma_LvdMainGUI,'lvdData');
writeOutput = getappdata(handles.ma_LvdMainGUI,'write_to_output_func');

lvdData.settings.optAlgo = LvdOptimAlgorithmEnum.InteriorPoint;
writeOutput('Optimization algorithm changed to interior point.','append');

% --------------------------------------------------------------------
function optSqpAlgoMenu_Callback(hObject, eventdata, handles)
% hObject handle to optSqpAlgoMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
lvdData = getappdata(handles.ma_LvdMainGUI,'lvdData');
writeOutput = getappdata(handles.ma_LvdMainGUI,'write_to_output_func');

lvdData.settings.optAlgo = LvdOptimAlgorithmEnum.SQP;
writeOutput('Optimization algorithm changed to SQP.','append');

% --------------------------------------------------------------------
function optActiveSetAlgoMenu_Callback(hObject, eventdata, handles)
% hObject handle to optActiveSetAlgoMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
lvdData = getappdata(handles.ma_LvdMainGUI,'lvdData');
writeOutput = getappdata(handles.ma_LvdMainGUI,'write_to_output_func');

lvdData.settings.optAlgo = LvdOptimAlgorithmEnum.ActiveSet;
writeOutput('Optimization algorithm changed to active set.','append');

0 comments on commit 7739f04

Please sign in to comment.