% 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 a nozzle

function [T2, G] = Nozzle(T1, P1, P2)

% Declare Global Viariable Data
global gam_hot R cp_hot;

% Nozzle Design Parameters
A_val = 0.0645;                                         % Nozzle area

% Bypass Nozzle equations (choking is not possible)
if P1/P2 < 1.8939

T2 = T1*(P2/P1)^((gam_hot-1)/gam_hot);                  % Exit temperature                                       
ue = sqrt(2*cp_hot*(T1-T2));                            % Exit velocity
G  = P2/(R*T2)*ue*A_val;                                % Mass flow 

else

T2 = T1*(1+(gam_hot-1)/2)^(-1);
P2_throat = P1*(T2/T1)^(gam_hot/(gam_hot-1));  
ue = sqrt(gam_hot*R*T2);
G  = P2_throat/(R*T2)*ue*A_val;                        % Throat Mass flow 

end
end
