% 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
global G_fuel_design

% 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 Fan
global Speed_design_Fan;         % Design Speed
global Mass_design_Fan;          % Design Mass Flow
global PR_design_Fan;            % Design Pressure Ratio
global Efficiency_design_Fan;    % Design Efficiency

Speed_design_Fan = 1500;         % Design Speed
Mass_design_Fan = 220;           % Design Mass Flow
PR_design_Fan = 1.2;             % Design Pressure Ratio
Efficiency_design_Fan = 0.9;     % Design Efficiency
Beta_design_Fan = 0.5;           % Design Beta Value


% Design Data for Low Pressure Compressor 1
global Speed_design_LPC_1;         % Design Speed
global Mass_design_LPC_1;          % Design Mass Flow
global PR_design_LPC_1;            % Design Pressure Ratio
global Efficiency_design_LPC_1;    % Design Efficiency

Speed_design_LPC_1 = 2000;         % Design Speed
Mass_design_LPC_1 = 15.134;        % Design Mass Flow
PR_design_LPC_1 = 2;               % Design Pressure Ratio
Efficiency_design_LPC_1 = 0.9;     % Design Efficiency
Beta_design_LPC_1 = 0.5;           % Design Beta Value

% Design Data for Low Pressure Compressor 2
global Speed_design_LPC_2;         % Design Speed
global Mass_design_LPC_2;          % Design Mass Flow
global PR_design_LPC_2;            % Design Pressure Ratio
global Efficiency_design_LPC_2;    % Design Efficiency

Speed_design_LPC_2 = 2500;         % Design Speed
Mass_design_LPC_2 = 15.134;        % Design Mass Flow
PR_design_LPC_2 = 2;              % Design Pressure Ratio
Efficiency_design_LPC_2 = 0.9;     % Design Efficiency
Beta_design_LPC_2 = 0.5;           % Design Beta Value

% Design Data for Low Pressure Compressor 3
global Speed_design_LPC_3;         % Design Speed
global Mass_design_LPC_3;          % Design Mass Flow
global PR_design_LPC_3;            % Design Pressure Ratio
global Efficiency_design_LPC_3;    % Design Efficiency

Speed_design_LPC_3 = 3000;         % Design Speed
Mass_design_LPC_3 = 15.134;        % Design Mass Flow
PR_design_LPC_3 = 2;               % Design Pressure Ratio
Efficiency_design_LPC_3 = 0.9;     % Design Efficiency
Beta_design_LPC_3 = 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 = 3500;         % Design Speed
Mass_design_HPC = 15.134;        % Design Mass Flow
PR_design_HPC = 3;               % Design Pressure Ratio
Efficiency_design_HPC = 0.9;     % Design Efficiency
Beta_design_HPC = 0.5;           % Design Beta Value


% Burner Maximum Temperature
global PR_Burner

T6 = 1600;                       % Kelvin 
PR_Burner= 0.9;                  % Burner Pressure Ratio

% Hot Section

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

Speed_design_HPT = 3500;         % Design Speed
Mass_design_HPT = 15.134;        % Design Mass Flow
Efficiency_design_HPT = 0.9;     % Design Efficiency
Beta_design_HPT = 0.5;           % Design Beta Value

% Design Data for Intermediate Pressure Turbine 1
global Speed_design_IPT_3;       % Design Speed
global PR_design_IPT_3;          % Design PR 
global Mass_design_IPT_3;        % Design Mass Flow
global Efficiency_design_IPT_3;  % Design Efficiency

Speed_design_IPT_3 = 3000;       % Design Speed
Mass_design_IPT_3 = 15.134;      % Design Mass Flow
Efficiency_design_IPT_3 = 0.9;   % Design Efficiency
Beta_design_IPT_3 = 0.5;         % Design Beta Value

% Design Data for Intermediate Pressure Turbine 2
global Speed_design_IPT_2;         % Design Speed
global PR_design_IPT_2;            % Design PR
global Mass_design_IPT_2;          % Design Mass Flow
global Efficiency_design_IPT_2;    % Design Efficiency

Speed_design_IPT_2 = 2500;         % Design Speed
Mass_design_IPT_2 = 15.134;        % Design Mass Flow
Efficiency_design_IPT_2 = 0.9;     % Design Efficiency
Beta_design_IPT_2 = 0.5;           % Design Beta Value

% Design Data for Intermediate Pressure Turbine 3
global Speed_design_IPT_1;         % Design Speed
global PR_design_IPT_1;            % Design PR
global Mass_design_IPT_1;          % Design Mass Flow
global Efficiency_design_IPT_1;    % Design Efficiency

Speed_design_IPT_1 = 2000;         % Design Speed
Mass_design_IPT_1 = 15.134;        % Design Mass Flow
Efficiency_design_IPT_1 = 0.9;     % Design Efficiency
Beta_design_IPT_1 = 0.5;           % Design Beta Value

% Design Data for Low Pressure Turbine
global Speed_design_LPT;           % Design Speed
global PR_design_LPT;              % Design PR
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 = 0.9;       % Design Efficiency
Beta_design_HPT = 0.5;             % Design Beta Value


% Nozzle
global A_Core

% Bypass Nozzle
global A_Bypass
% Area will be calculated Automatically

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

% Diffuser
[T0, P0] = Design_Diffuser(T_amb,P_amb, Mach);

% Fan
[T1, P1, G1, Power_1] = Design_Fan(T0, P0);

% LPC 1
[T2, P2, G2, Power_2] = Design_LPC_1(T1, P1);

% LPC 2
[T3, P3, G3, Power_3] = Design_LPC_2(T2, P2);

% LPC 3
[T4, P4, G4, Power_4] = Design_LPC_3(T3, P3);

% HPC
[T5, P5, G5, Power_5] = Design_HPC(T4, P4);

Power_spool_1 = Power_1;                % Low Spool Power
Power_spool_2 = Power_2;                % Intermediate Spool Power 1
Power_spool_3 = Power_3;                % Intermediate Spool Power 2
Power_spool_4 = Power_4;                % Intermediate Spool Power 3
Power_spool_5 = Power_5;                % High Spool Power

% Burner
[G_fuel_design, P6] = Design_Burner(T5, T6, P5, G2, PR_Burner);

% HPT
[T7, P7, PR_design_HPT] = Design_HPT(T6, P6, G2, Power_spool_5);

%IPT 1
[T8, P8, PR_design_IPT_3] = Design_IPT_3(T7, P7, G2, Power_spool_4);

%IPT 2
[T9, P9, PR_design_IPT_2] = Design_IPT_2(T8, P8, G2, Power_spool_3);

%IPT 3
[T10, P10, PR_design_IPT_1] = Design_IPT_1(T9, P9, G2, Power_spool_2);

% LPT
[T11, P11, PR_design_LPT] = Design_LPT(T10, P10, G2, Power_spool_1);

% Nozzle          
[T_Core,P_Core A_Core] = Design_Nozzle(T11,P11,P_amb, G2);

% Bypass Nozzle
[T_Bypass, P_Bypass, A_Bypass] = Design_Nozzle(T1,P1,P_amb, G1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Design Output

% Fan
global T_design_Fan
global P_design_Fan
T_design_Fan = T0;
P_design_Fan = P0;

% LPC 1
global T_design_LPC_1
global P_design_LPC_1
T_design_LPC_1 = T1;
P_design_LPC_1 = P1;

% LPC 2
global T_design_LPC_2
global P_design_LPC_2
T_design_LPC_2 = T2;
P_design_LPC_2 = P2;

% LPC 3
global T_design_LPC_3
global P_design_LPC_3
T_design_LPC_3 = T3;
P_design_LPC_3 = P3;

% HPC
global T_design_HPC
global P_design_HPC
T_design_HPC = T4;
P_design_HPC = P4;

% Burner

% HPT
global T_design_HPT
global P_design_HPT
T_design_HPT = T6;
P_design_HPT = P6;

% IPT 1
global T_design_IPT_3
global P_design_IPT_3
T_design_IPT_3 = T7;
P_design_IPT_3 = P7;

% IPT 2
global T_design_IPT_2
global P_design_IPT_2
T_design_IPT_2 = T8;
P_design_IPT_2 = P8;

% IPT 3
global T_design_IPT_1
global P_design_IPT_1
T_design_IPT_1 = T9;
P_design_IPT_1 = P9;

% LPT
global T_design_LPT
global P_design_LPT
T_design_LPT = T10;
P_design_LPT = P10;

% Nozzle
clear('G1', 'G2', 'G3', 'G4', 'G5', 'R', 'gam_hot', 'gam_cold', 'cp_hot', 'cp_cold')
clear('Mach', 'T_amb', 'T_Bypass', 'T_Core')
clear('P_amb', 'P_Bypass', 'P_Core')
clear('Power_1', 'Power_2', 'Power_3', 'Power_4', 'Power_5')
clear('T0', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'T9', 'T10', 'T11')
clear('P0', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'P10', 'P11')
