% Delivered to the Government in Accordance with Contract FA8650-10-C-7080
% 
%  (c) 2011 United Technologies Corp.
% Developed with the sponsorship of the Defense Advanced Research Projects Agency (DARPA).
%  
% Permission is hereby granted, free of charge, to any person obtaining a copy of this data, including any software or models in source or binary form, as well as any drawings, specifications, and documentation (collectively "the Data"), to deal in the Data without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Data, and to permit persons to whom the Data is furnished to do so, subject to the following conditions:
%  
% The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Data.
%  
% THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, SPONSORS, DEVELOPERS, CONTRIBUTORS, OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DATA OR THE USE OR OTHER DEALINGS IN THE DATA.
% 

% This function computes the design and off design steady state performance
% of the HPT

function [T2, P2, G, Speed, Power] = HPT(T1, P1, w, Beta, Mass_HPT_Tr,PR_HPT_Tr, Efficiency_HPT_Tr, D_HPT)

% format long
% T1
% P1
% w
% Beta
% format short

% Declare Global Viariable Data
gam_hot = 1.3;
R = 287;
cp_hot = 1244;

% HPT Design Parameters
Speed_design_HPT = D_HPT(1);
Mass_design_HPT = D_HPT(2);
PR_design_HPT = D_HPT(3);
Efficiency_design_HPT = D_HPT(4);
T_design_HPT = D_HPT(6);
P_design_HPT = D_HPT(7);

% HPT equations
Speed = w/Speed_design_HPT*sqrt(T_design_HPT./T1) ;                     % Relative Corrected Speed         

% T1
% T_design_HPT
% Beta

Mass_nd = Mass_HPT_Tr(Beta*ones(length(T1),1), Speed)  ;                                   % Relative Corrected Mass Flow
PR_nd = PR_HPT_Tr(Beta*ones(length(T1),1), Speed);                                         % Pressure Ratio
Efficiency_nd = Efficiency_HPT_Tr(Beta*ones(length(T1),1), Speed);                         % Efficiency 



G = Mass_nd*Mass_design_HPT.*(sqrt(T_design_HPT./T1).*(P1/P_design_HPT));  % Mass Flow  
P2 = P1./(PR_nd*PR_design_HPT);                                          % Pressure
T2s = T1.*(P2./P1).^((gam_hot-1)/gam_hot);                                 % Isentropic Temperature        
T2 = T1+(T2s-T1).*(Efficiency_nd*Efficiency_design_HPT);                 % True Temperature
Power = G*cp_hot.*(T1-T2);

end