From 80ece6a5225073d8e1220d33d5e5ddd9bee3699b Mon Sep 17 00:00:00 2001 From: Arrowstar Date: Sun, 6 Jan 2019 14:03:47 -0600 Subject: [PATCH] 1) LVD: Added total thrust constraint 2) Adjusted all altitude constraints to have an allowable lower bound of -Inf --- .../@ConstraintEnum/ConstraintEnum.m | 2 + .../TotalThrustConstraint.m | 135 ++++++++++++++++++ .../misc/computeTWRatio.m | 11 ++ .../ma_getConstraintStaticDetails.m | 6 +- 4 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/constraints/@TotalThrustConstraint/TotalThrustConstraint.m create mode 100644 helper_methods/ksptot_ma/launch_vehicle_designer/misc/computeTWRatio.m diff --git a/helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/constraints/@ConstraintEnum/ConstraintEnum.m b/helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/constraints/@ConstraintEnum/ConstraintEnum.m index 93febaeb7..93202b940 100644 --- a/helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/constraints/@ConstraintEnum/ConstraintEnum.m +++ b/helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/constraints/@ConstraintEnum/ConstraintEnum.m @@ -64,6 +64,8 @@ InertialBankAngle('Inertial Bank Angle','InertialBankAngleConstraint',[]); InertialSideSlipAngle('Inertial Side Slip Angle','InertialSideSlipAngleConstraint',[]); + TotalThrust('Total Thrust','TotalThrustConstraint',[]); + StopwatchValue('Stopwatch Value','StopwatchValueConstraint',[]); end diff --git a/helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/constraints/@TotalThrustConstraint/TotalThrustConstraint.m b/helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/constraints/@TotalThrustConstraint/TotalThrustConstraint.m new file mode 100644 index 000000000..965103a59 --- /dev/null +++ b/helper_methods/ksptot_ma/launch_vehicle_designer/classes/Optimization/constraints/@TotalThrustConstraint/TotalThrustConstraint.m @@ -0,0 +1,135 @@ +classdef TotalThrustConstraint < AbstractConstraint + %TotalThrustConstraint Summary of this class goes here + % Detailed explanation goes here + + properties + normFact = 1; + event(1,:) LaunchVehicleEvent + + lb(1,1) double = 0; + ub(1,1) double = 0; + end + + methods + function obj = TotalThrustConstraint(event, lb, ub) + obj.event = event; + obj.lb = lb; + obj.ub = ub; + + obj.id = rand(); + end + + function [lb, ub] = getBounds(obj) + lb = obj.lb; + ub = obj.ub; + end + + function [c, ceq, value, lwrBnd, uprBnd, type, eventNum] = evalConstraint(obj, stateLog, celBodyData) + type = obj.getConstraintType(); + stateLogEntry = stateLog.getLastStateLogForEvent(obj.event); + + ut = stateLogEntry.time; + rVect = stateLogEntry.position; + vVect = stateLogEntry.velocity; + + bodyInfo = stateLogEntry.centralBody; + tankStates = stateLogEntry.getAllActiveTankStates(); + stageStates = stateLogEntry.stageStates; + lvState = stateLogEntry.lvState; + + dryMass = stateLogEntry.getTotalVehicleDryMass(); + tankStatesMasses = [tankStates.tankMass]'; + + throttleModel = stateLogEntry.throttleModel; + steeringModel = stateLogEntry.steeringModel; + + altitude = norm(rVect) - bodyInfo.radius; + pressure = getPressureAtAltitude(bodyInfo, altitude); + + throttle = throttleModel.getThrottleAtTime(ut, rVect, vVect, tankStatesMasses, dryMass, stageStates, lvState, tankStates, bodyInfo); + + [~, totalThrust, ~] = LaunchVehicleStateLogEntry.getTankMassFlowRatesDueToEngines(tankStates, tankStatesMasses, stageStates, throttle, lvState, pressure, ut, rVect, vVect, bodyInfo, steeringModel); + + value = totalThrust; + + if(obj.lb == obj.ub) + c = []; + ceq(1) = value - obj.ub; + else + c(1) = obj.lb - value; + c(2) = value - obj.ub; + ceq = []; + end + c = c/obj.normFact; + ceq = ceq/obj.normFact; + + lwrBnd = obj.lb; + uprBnd = obj.ub; + + eventNum = obj.event.getEventNum(); + end + + function sF = getScaleFactor(obj) + sF = obj.normFact; + end + + function setScaleFactor(obj, sF) + obj.normFact = sF; + end + + function tf = usesStage(obj, stage) + tf = false; + end + + function tf = usesEngine(obj, engine) + tf = false; + end + + function tf = usesTank(obj, tank) + tf = false; + end + + function tf = usesEngineToTankConn(obj, engineToTank) + tf = false; + end + + function tf = usesEvent(obj, event) + tf = obj.event == event; + end + + function tf = usesStopwatch(obj, stopwatch) + tf = false; + end + + function event = getConstraintEvent(obj) + event = obj.event; + end + + function type = getConstraintType(obj) + type = 'Total Thrust'; + end + + function name = getName(obj) + name = sprintf('%s - Event %i', obj.getConstraintType(), obj.event.getEventNum()); + end + + function [unit, lbLim, ubLim, usesLbUb, usesCelBody, usesRefSc] = getConstraintStaticDetails(obj) + unit = 'kN'; + lbLim = 0; + ubLim = Inf; + usesLbUb = true; + usesCelBody = false; + usesRefSc = false; + end + + function addConstraintTf = openEditConstraintUI(obj, lvdData) + addConstraintTf = lvd_EditGenericMAConstraintGUI(obj, lvdData); + end + end + + methods(Static) + function constraint = getDefaultConstraint(~) + constraint = TotalThrustConstraint(LaunchVehicleEvent.empty(1,0),0,0); + end + end +end \ No newline at end of file diff --git a/helper_methods/ksptot_ma/launch_vehicle_designer/misc/computeTWRatio.m b/helper_methods/ksptot_ma/launch_vehicle_designer/misc/computeTWRatio.m new file mode 100644 index 000000000..be2c8d5f0 --- /dev/null +++ b/helper_methods/ksptot_ma/launch_vehicle_designer/misc/computeTWRatio.m @@ -0,0 +1,11 @@ +function twRatio = computeTWRatio(throttle, ut, rVect, vVect, tankMasses, dryMass, stgStates, lvState, tankStates, bodyInfo) + altitude = norm(rVect) - bodyInfo.radius; + presskPa = getPressureAtAltitude(bodyInfo, altitude); + + [~, totalThrust]= LaunchVehicleStateLogEntry.getTankMassFlowRatesDueToEngines(tankStates, tankMasses, stgStates, throttle, lvState, presskPa, ut, rVect, vVect, bodyInfo, []); + + totalMass = (dryMass + sum(tankMasses))*1000; %kg + totalThrust = totalThrust * 1000; % N + + twRatio = computeSLThrustToWeight(bodyInfo, totalThrust, totalMass); +end \ No newline at end of file diff --git a/helper_methods/ksptot_ma/optimization/ma_getConstraintStaticDetails.m b/helper_methods/ksptot_ma/optimization/ma_getConstraintStaticDetails.m index 5506a88f7..8c0f96752 100644 --- a/helper_methods/ksptot_ma/optimization/ma_getConstraintStaticDetails.m +++ b/helper_methods/ksptot_ma/optimization/ma_getConstraintStaticDetails.m @@ -233,7 +233,7 @@ usesRefSc = false; case 'Altitude of Apoapsis' unit = 'km'; - lbLim = 0; + lbLim = -Inf; ubLim = Inf; lbVal = 0; ubVal = 0; @@ -245,7 +245,7 @@ usesRefSc = false; case 'Altitude of Periapsis' unit = 'km'; - lbLim = 0; + lbLim = -Inf; ubLim = Inf; lbVal = 0; ubVal = 0; @@ -553,7 +553,7 @@ usesRefSc = false; case 'Altitude' unit = 'km'; - lbLim = 0; + lbLim = -Inf; ubLim = Inf; lbVal = 0; ubVal = 0;