% 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 script sizes turbines based on the design of the cold section
% The assumption is that design point performance occurs at beta = 0.5
% A more accurate description of this will be provided using Dr. Joachim
% Kurzke's Smooth T8.2 and Smooth C8.2 map scaling softwares.

% Design Pressure, Temperature and Mach number
P_amb = 22729;                   % Cruise Ambient Pressure at 36000ft (Pascals)
T_amb = 216.5;                   % Cruise Ambient Temperature at 36000ft (Kelvin)
Mach  = 0.8;                     % Cruise Mach Number
Mass = 15.134;                   % Cruise Mass Flow (kg/s)

% Gas Properties
global cp_cold cp_hot R gam_cold gam_hot
cp_cold = 1045;
cp_hot = 1244;
R = 287;
gam_cold= 1.4;
gam_hot = 1.3;



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Cold Section

% Design Data for Low Pressure Compressor
global Speed_design_LPC;         % Design Speed
global Mass_design_LPC;          % Design Mass Flow
global PR_design_LPC;            % Design Pressure Ratio
global Efficiency_design_LPC;    % Design Efficiency

Speed_design_LPC = 1500;         % Design Speed
Mass_design_LPC = 15.134;        % Design Mass Flow
PR_design_LPC = 4;               % Design Pressure Ratio
Efficiency_design_LPC = 1;       % Design Efficiency
Beta_LPC = 0.5;                  % Design Beta Value



% Design Data for High Pressure Compressor
global Speed_design_HPC;         % Design Speed
global Mass_design_HPC;          % Design Mass Flow
global PR_design_HPC;            % Design Pressure Ratio
global Efficiency_design_HPC;    % Design Efficiency

Speed_design_HPC = 2900;         % Design Speed
Mass_design_HPC = 15.134;        % Design Mass Flow
PR_design_HPC = 7;               % Design Pressure Ratio
Efficiency_design_HPC = 1;       % Design Efficiency
Beta_HPC = 0.5;                  % Design Beta Value


% Burner Maximum Temperature
T_max = 1600;                    % Kelvin                   

% Hot Section

%Design Data for High Pressure Turbine
global Speed_design_HPT;         % Design Speed
global Mass_design_HPT;          % Design Mass Flow
global Efficiency_design_HPT;    % Design Efficiency

Speed_design_HPT = 2900;          % Design Speed
Mass_design_HPT = 15.134;        % Design Mass Flow
Efficiency_design_HPT = 1;       % Design Efficiency
Beta_HPT = 0.5;                  % Design Beta Value

% Hot Section
global Speed_design_LPT;         % Design Speed
global Mass_design_LPT;          % Design Mass Flow
global Efficiency_design_LPT;    % Design Efficiency

Speed_design_LPT = 1500;          % Design Speed
Mass_design_LPT = 15.134;        % Design Mass Flow
Efficiency_design_LPT = 1;       % Design Efficiency
Beta_HPT = 0.5;                  % Design Beta Value


% Nozzle
% Area will be calculated Automatically

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Size Hot Section to Match Cold Section

% Diffuser
[T1, P1] = Design_Diffuser(T_amb,P_amb, Mach);

% LPC
[T2, P2, G1] = Design_LPC(T1, P1);

% HPC
[T3, P3, G2] = Design_HPC(T2, P2);

% Burner
[G_fuel_design, P4] = Design_Burner(T3, T_max, P3, G1);

% HPT
[T5, P5, PR_design_HPT] = Design_HPT(T2, T3, T_max, P4);

% LPT
[T6, P6, PR_design_LPT] = Design_LPT(T1, T2, T5, P5);

% Nozzle          
[T7, A_val] = Design_Nozzle(T6,P6,P_amb, Mass_design_HPC);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Design Output

% LPC
T_design_LPC = T1;
P_design_LPC = P1;

% HPC
T_design_HPC = T2;
P_design_HPC = P2;


% Burner

% HPT
T_design_HPT = T_max;
P_design_HPT = P4;

% LPT
T_design_LPT = T5;
P_design_LPT = P5;

% Nozzle 