% 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.
start = tic;
global D_Fan D_LPC D_HPC D_HPT D_IPT D_LPT D_N D_BN G_design_fuel  
% Design Pressure, Temperature and Mach number
P_amb = 22729;                  
T_amb = 216.15;                 
Mach  = 0.8;                        

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

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

% Design Data for Fan
Speed_design_Fan = 1500;         % Design Speed
Mass_design_Fan = 500;           % Design Mass Flow
PR_design_Fan = 1.2;             % Design Pressure Ratio
Efficiency_design_Fan = 0.9;     % Design Efficiency
Beta_Fan = 0.5;                  % Design Beta Value

D_Tiny_Fan = [Mass_design_Fan PR_design_Fan Efficiency_design_Fan];

% Design Data for Low Pressure Compressor
Speed_design_LPC = 2000;         % Design Speed
Mass_design_LPC = 50;        % Design Mass Flow
PR_design_LPC = 4;               % Design Pressure Ratio
Efficiency_design_LPC = 0.9;     % Design Efficiency
Beta_LPC = 0.5;                  % Design Beta Value

D_Tiny_LPC = [Mass_design_LPC PR_design_LPC Efficiency_design_LPC];


% Design Data for High Pressure Compressor
Speed_design_HPC = 3000;         % Design Speed
Mass_design_HPC = 50;        % Design Mass Flow
PR_design_HPC = 14;              % Design Pressure Ratio
Efficiency_design_HPC = 0.9;     % Design Efficiency
Beta_HPC = 0.5;                  % Design Beta Value

D_Tiny_HPC = [Mass_design_HPC PR_design_HPC Efficiency_design_Fan];

% Burner Maximum Temperature
T4 = 1600;                       % Kelvin 
PR_Burner= 0.9;                  % Burner Pressure Ratio

% Hot Section

%Design Data for High Pressure Turbine
Speed_design_HPT = 3000;         % Design Speed
Mass_design_HPT = 50;        % Design Mass Flow
Efficiency_design_HPT = 0.9;     % Design Efficiency
Beta_HPT = 0.5;                  % Design Beta Value

D_Tiny_HPT = [Efficiency_design_HPT];

% Design Data for Intermediate Pressure Turbine
Speed_design_IPT = 2000;         % Design Speed
Mass_design_IPT = 50;        % Design Mass Flow
Efficiency_design_IPT = 0.9;     % Design Efficiency
Beta_IPT = 0.5;                  % Design Beta Value

D_Tiny_IPT = [Efficiency_design_IPT];

% Design Data for Low Pressure Turbine
Speed_design_LPT = 1500;         % Design Speed
Mass_design_LPT = 50;        % Design Mass Flow
Efficiency_design_LPT = 0.9;     % Design Efficiency
Beta_LPT = 0.5;                  % Design Beta Value

D_Tiny_LPT = [Efficiency_design_LPT];

% Nozzle
% 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, D_Tiny_Fan);

% LPC
[T2, P2, G2, Power_2] = Design_LPC(T1, P1, D_Tiny_LPC);

% HPC
[T3, P3, G3, Power_3] = Design_HPC(T2, P2, D_Tiny_HPC);

Power_spool_1 = Power_1;                % Low Spool Power
Power_spool_2 = Power_2;                % Intermediate Spool Power
Power_spool_3 = Power_3;                % High Spool Power

% Burner
[G_design_fuel, P4] = Design_Burner(T3, T4, P3, G2, PR_Burner);

% HPT
[T5, P5, PR_design_HPT] = Design_HPT(T4, P4, G2, Power_spool_3, D_Tiny_HPT);

%IPT
[T6, P6, PR_design_IPT] = Design_IPT(T5, P5, G2, Power_spool_2, D_Tiny_IPT);

% LPT
[T7, P7, PR_design_LPT] = Design_LPT(T6, P6, G2, Power_spool_1, D_Tiny_LPT);

% Nozzle          
[T_core,P_core A_Core] = Design_Nozzle(T7,P7,P_amb, G2);

% Bypass Nozzle
[T_bypass, P_bypass, A_Bypass] = Design_Bypass_Nozzle(T1,P1,P_amb, G1-G2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Design Output

% Fan
% Design Data for Fan
D_Fan(1) = 1500;          % Design Speed
D_Fan(2) = 500;           % Design Mass Flow
D_Fan(3) = 1.2;           % Design Pressure Ratio
D_Fan(4) = 0.9;           % Design Efficiency
D_Fan(5) = 0.5;           % Design Beta Values
D_Fan(6) = T0;            % Design Temperatures
D_Fan(7) = P0;            % Design Pressures 

% LPC
D_LPC(1) = 2000;          % Design Speed
D_LPC(2) = 50;        % Design Mass Flow
D_LPC(3) = 4;             % Design Pressure Ratio
D_LPC(4) = 0.9;           % Design Efficiency
D_LPC(5) = 0.5;           % Design Beta Value
D_LPC(6) = T1;            % Design Temperatures
D_LPC(7) = P1;            % Design Pressures 

% HPC
D_HPC(1) = 3000;          % Design Speed
D_HPC(2) = 50;        % Design Mass Flow
D_HPC(3) = 14;            % Design Pressure Ratio
D_HPC(4) = 0.9;           % Design Efficiency
D_HPC(5) = 0.5;           % Design Beta Value
D_HPC(6) = T2;            % Design Temperature
D_HPC(7) = P2;            % Design Pressure 

% Burner
D_Burner(1)= 0.9;         % Burner Pressure Ratio

% HPT
D_HPT(1) = 3000;          % Design Speed
D_HPT(2) = 50;        % Design Mass Flow
D_HPT(3) = PR_design_HPT; % Design Pressure Ratio
D_HPT(4) = 0.9;           % Design Efficiency
D_HPT(5) = 0.5;           % Design Beta Value
D_HPT(6) = T4;            % Design Temperature
D_HPT(7) = P4;            % Design Pressure 

% IPT
D_IPT(1) = 2000;          % Design Speed
D_IPT(2) = 50;        % Design Mass Flow
D_IPT(3) = PR_design_IPT; % Design Pressure Ratio
D_IPT(4) = 0.9;           % Design Efficiency
D_IPT(5) = 0.5;           % Design Beta Value
D_IPT(6) = T5;            % Design Temperature 
D_IPT(7) = P5;            % Design Pressure

% LPT
D_LPT(1) = 1500;          % Design Speed
D_LPT(2) = 50;        % Design Mass Flow
D_LPT(3) = PR_design_LPT; % Design Pressure Ratio
D_LPT(4) = 0.9;           % Design Efficiency
D_LPT(5) = 0.5;           % Design Beta Value
D_LPT(6) = T6;            % Design Temperature
D_LPT(7) = P6;            % Design Pressure


% Core Nozzle
D_N(1) = A_Core;

% Bypass Nozzle 
D_BN(1) = A_Bypass;

end_time = toc(start);
Vac = Mach*sqrt(1.4*287*T_amb);
Thrust = G2*(sqrt(2*1245*(T7-T_core))-Vac)+(G1-G2)*(sqrt(2*1005*(T1-T_bypass))-Vac);
 

%clear('G1', 'G2', 'G3', 'R', 'gam_hot', 'gam_cold', 'cp_hot', 'cp_cold')
%clear('Power_1', 'Power_2', 'Power_3')
%clear('T0', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7')
%clear('P0', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7')
%clear('Beta_Fan', 'Beta_LPC', 'Beta_HPC', 'Beta_HPT', 'Beta_LPT'); 