<?xml version="1.0"?>

<!--
        Description: F-14 TF-30 engines
        
        Auxiliary model that sits alongside the JSBSim model and provides more accurate EGT, PB and augmenatation model and
        compressor stall.
        
        Derived from f-15-engines.xml
        Author: Richard Harrison (rjh@zaretto.com)
        References: 
        1. J79-15/-17 TURBOJET ENGINE ACCIDENT INVESTIGATION PROCEDURES ASD-TR-75-19
        2. NASA TM-86042 Minimum Time and Fuel Flight Profiles for an F-15 Airplane with a Highly Integrated Digital Electronic Control System. Edward A. Haering, Jr., and Frank W. Burcham, Jr.
        3. NASA TP-1069 Airflow and thrust calibration of an F100 Engine S/N p680059 at selected flight conditions. Thomas J.  Biesiadny,  Douglas  Lee,  and Jose  R.  Rodriguez 
        4. NASA TP-1228 Altitude calibration of an F100 Engine S/N p680063, Turbofan Engine. Thomas J.  Biesiadny,  Douglas  Lee,  and Jose  R.  Rodriguez 
        5. NASA TP-2461 Performance and Surge Limits of a TF30-P-3 Turbofan Engine/Axisymmetric Mixed-Compression Inlet Propulsion System at Mach 2.5, Joseph F. Wasserbauer, Harvey E. Neumann,
and Robert J. Shaw,  May 1985
        Currently this is calculating the Stall, Augmentation, EGT and Burn thru only; the JSBSim turbine is providing N1,N2,Thrust,FuelFlow
    -->

<system name="ENGINES">
    <!-- mid compression bypass failure -->
    <property value="0"  >propulsion/engine[0]/mcb-failed</property>
    <!-- simple lag between compressor conditions met and compressor stall -->
    <property value="1.7">propulsion/engine[0]/P0-stall-lag</property>
    <property value="0.4">propulsion/engine[0]/compressor-stall-amount</property>

    <property value="0.4"  >propulsion/engine[1]/mcb-failed</property>
    <!-- simple lag between compressor conditions met and compressor stall the right engine is less likely to stall for no apparent reason-->
    <property value="2.1">propulsion/engine[1]/P0-stall-lag</property>
    <property value="0">propulsion/engine[1]/compressor-stall-amount</property>

    <channel name="engine-control">
        <!-- Throttles uses the APC value - which will either be the demanded for APC or the input value from throttle-cmd -->
        <scheduled_gain name="ThrottleL">
            <input>systems/apc/throttle-cmd[0]</input>
            <table>
                <independentVar>systems/apc/throttle-cmd[0]</independentVar>
                <tableData>
                    <!-- 5 stage non linear augmentation-->
                    0.00    0.0
                    0.8999  0.999
                    0.91    1.0
                    0.93    1.25
                    0.95    1.50
                    0.97    1.75
                    1.00    2.0
                </tableData>
            </table>
            <output>fcs/throttle-pos-norm[0]</output>
        </scheduled_gain>

        <scheduled_gain name="ThrottleR">
            <input>systems/apc/throttle-cmd[1]</input>
            <table>
                <independentVar>systems/apc/throttle-cmd[1]</independentVar>
                <tableData>
                    <!-- 5 stage non linear augmentation-->
                    0.00    0.0
                    0.8999  0.999
                    0.91    1.0
                    0.93    1.25
                    0.95    1.50
                    0.97    1.75
                    1.00    2.0
                </tableData>
            </table>
            <output>fcs/throttle-pos-norm[1]</output>
        </scheduled_gain>
    </channel>

    <channel name="F110-L">
        <!-- TF30 compressor stall stuff 
             Engine stall margin MCB system open idle 26, 26 mid. 82/83 %, 18% military

        refs: https://www.grc.nasa.gov/www/K-12/airplane/inleth.html

        F-14A NATOPS, pg IV-11-4, para 11.4.2.1 states  
           "The engines generally operate satisfactorily at extremely high positive or 
           negative AOA but are prone to compressor stalls if high AOA is combined with sideslip
           or throttle settings below 90 percent RPM. 
           Each of these conditions reduces the engine's compressor stall margin, which is already 
           reduced when operating at high AOA.  Excessive sideslip, even at low AOA, may result in
           compressor stalls anywhere in the aircraft flight envelope.
           There is no way to predict when a compressor stall will occur, but there is a 
           likelihood of inducing one by changing throttle settings at high AOA.
        F-14A NATOPS, pg IV-11-5, para 11.4.2.2 
            Subsonic compressor stalls are characterized by an RPM decrease and an increase in
            TIT.  They may produce an audible thump or bang, or they may be inaudible.
            
         So the way we model this is by having P0 (nominally inlet pressure taking into account turbulent air
         due to alpha,beta - and then using this to calculate the P3 effect - and if the difference of this
         falls outside the margin 

        P0,DP3 are both dimensionless

         k3 - constant factor for airflow - 
         k4 - stall margin - to be affected by mcb / stage bleed failures
        -->

        <!-- 7 stage (mid compression) bypass is used to push air to the front compressors to increase compressor stall margin -->
        <switch name="propulsion/engine[0]/mid-compression-bypass-active">
            <default value="1"/>
            <test value="0">
                velocities/mach gt 0.35
                propulsion/engine[0]/mcb-failed eq 0
            </test>
        </switch>
        <switch name="propulsion/engine[0]/P0-k4">
            <default value="1.0910913567364466"/>
            <test value="1.04913567364466">
                propulsion/engine[0]/mid-compression-bypass-active gt 0
            </test>
        </switch>
        <fcs_function name="propulsion/engine[0]/P0">
            <description>Inlet pressure P0(alpha,beta)</description>
            <function>
                <table>
                    <independentVar	lookup="row">aero/alpha-deg</independentVar>
                    <independentVar	lookup="column">aero/beta-deg</independentVar>
                    <tableData>
                        0	          5	         10	         15	         20	         25	         30	         35	         40	         45	         50	         55
                        -20	-0.04000000	-0.03900000	-0.03600000	-0.00850000	 0.00700000	 0.01700000	 0.02800000	 0.03150000	 0.02950000	 0.03150000	 0.02800000	 0.02200000
                        -15	-0.03050000	-0.03000000	-0.02570000	-0.00750000	 0.00400000	 0.00900000	 0.01800000	 0.02300000	 0.01900000	 0.02150000	 0.02050000	 0.01750000
                        -10	-0.00400000	-0.02150000	-0.01900000	-0.00600000	 0.00200000	 0.00450000	 0.01100000	 0.01450000	 0.00850000	 0.01300000	 0.01450000	 0.01450000
                        -5	-0.01000000	-0.01000000	-0.00950000	-0.00300000	 0.00000000	 0.00000000	 0.00000000	 0.00000000	 0.00000000	 0.00000000	 0.00000000	 0.00000000
                        0	 0.00000000	 0.00000000	-0.00600000	-0.01000000	-0.01200000	-0.02500000	-0.03100000	-0.02100000	 0.00850000	 0.01300000	 0.01450000	 0.01450000
                        5	 0.01000000	 0.01000000	 0.00950000	 0.00300000	-0.00400000	-0.00900000	-0.01800000	-0.02300000	-0.01900000	-0.02150000	-0.02050000	-0.01750000
                        10	 0.02150000	 0.02150000	 0.01900000	 0.00600000	-0.00700000	-0.01700000	-0.02800000	-0.03150000	-0.02950000	-0.03150000	-0.02800000	-0.02200000
                        15	 0.03050000	 0.03000000	 0.02750000	-0.00100000	-0.01000000	-0.02550000	-0.03800000	-0.04050000	-0.04050000	-0.04150000	-0.03600000	-0.02600000
                        20	 0.04000000	 0.03900000	 0.03600000	 0.01000000	 0.02550000	 0.03800000	 0.04050000	 0.04500000	 0.04150000	 0.03600000	 0.02600000	 0.00000000
                    </tableData>
                </table>
            </function>
        </fcs_function>

        <!-- Augmentation 
         The augmentation has a five stage burner; with high voltage ignition. Sufficient pressure at the ignitor is required and
         this is performed by the augmentation control system on the engine. As soon as there is sufficient pressure, regardless of the compressor
         rpm the augmentor can fire. 
      -->
        <fcs_function name="propulsion/engine[0]/PB">
            <description>Engine 0 SS Burner pressure ratio</description>
            <function>
                <sum>
                    <table>
                        <independentVar lookup="row">propulsion/engine[0]/n2</independentVar>
                        <independentVar lookup="column">velocities/mach</independentVar>
                        <tableData>
                            0.00000	0.20000	0.30000	0.45000	0.60000	0.80000	0.90000	3.00000
                            0	1.10000	0.93963	0.93963	0.93963	0.93963	0.93963	0.93963	0.93963
                            8	1.09966	0.93963	0.93963	0.93963	0.93963	0.93963	0.93963	0.93963
                            16	1.26926	0.97069	0.93186	0.93963	0.93963	0.93963	0.93963	0.93963
                            24	1.37453	0.99197	0.95229	0.92944	0.93963	0.93963	0.93963	0.93963
                            32	1.56636	1.00992	0.96952	0.92105	0.89341	0.93963	0.93963	0.93963
                            40	1.87550	1.03223	0.99094	0.94140	0.91316	0.91316	0.93963	0.93963
                            48	2.25353	1.06785	1.02514	0.95338	0.91524	0.91835	0.97369	0.97369
                            56	2.61381	1.12695	1.08188	1.00614	0.96590	0.96918	0.97369	0.97369
                            63	2.84760	1.22096	1.17212	1.09007	1.04647	1.05002	0.99630	0.99630
                            71	2.98150	1.34177	1.28810	1.19793	1.15002	1.15392	1.09488	1.09488
                            79	3.00594	1.53633	1.47488	1.37164	1.31677	1.32124	1.25365	1.25365
                            87	3.07269	1.80555	1.73333	1.61200	1.54752	1.55278	1.47333	1.47333
                            95	3.49481	2.16568	2.07905	1.93352	1.85618	1.86248	1.76719	1.76719
                            97	3.71122	2.63418	2.52881	2.35179	2.25772	2.26539	2.14949	2.14949
                            98	3.84257	2.77040	2.65959	2.47341	2.37448	2.38255	2.26065	2.26065
                            100	4.15840	2.84159	2.72792	2.53697	2.43549	2.44376	2.31873	2.31873
                        </tableData>
                    </table>
                </sum>
            </function>
        </fcs_function>
        <fcs_function name="propulsion/engine[0]/DP3">
            <description>Change	in	compressor	discharge	pressure	DP3(n1)	dP3/dWf</description>
            <function>
                <table>
                    <independentVar	lookup="row">propulsion/engine[0]/n1</independentVar>
                    <tableData>
                        60	0.15000000
                        65	0.20000000
                        70	0.24000000
                        79	0.32500000
                        80	0.35800000
                        85	0.36300000
                        90	0.38700000
                        95	0.38000000
                        100	0.35100000
                    </tableData>
                </table>
            </function>
        </fcs_function>

        <fcs_function name="propulsion/engine[0]/P0-k3">
            <description>N1 Compressor stall point</description>
            <function>
                <product>
                    <property>propulsion/engine[0]/compressor-stall-amount</property>
                    <value>17.32</value>
                </product>
            </function>
        </fcs_function>
        <fcs_function name="propulsion/engine[0]/P0-CPV">
            <description>N1 Compressor stall point</description>
            <function>
                <difference>
                    <property>propulsion/engine[0]/PB</property>
                    <product>
                        <property>propulsion/engine[0]/P0</property>
                        <property>propulsion/engine[0]/P0-k3</property>
                    </product>
                </difference>
            </function>
        </fcs_function>

        <switch name="propulsion/engine[0]/P0-stall-dmd">
            <default value="0"/>
            <test value="1" logic="AND">
                <!--propulsion/engine[0]/n1-->
                propulsion/engine[0]/P0-CPV lt propulsion/engine[0]/P0-k4
                gear/unit[2]/WOW eq 0
                gear/unit[1]/WOW eq 0
                fcs/throttle-pos-norm[0] gt 0.1 <!-- no stall in idle   -->
                sim-time-sec gt 10 <!-- otherwise it'll probably stall on the ground -->
                aero/alpha-deg gt 4 <!-- haven't actually got values in the P0 table for -ve alphas.-->
                propulsion/engine[0]/stalled eq 0
            </test>
        </switch>
        <lag_filter name="propulsion/engine[0]/P0-stall">
            <input>propulsion/engine[0]/P0-stall-dmd</input>
            <output>propulsion/engine[0]/P0-stall</output>
            <c1>propulsion/engine[0]/P0-stall-lag</c1>
        </lag_filter >

        <fcs_function name="propulsion/engine[0]/c-egt-lead">
            <description>EGT LEAD N1 %</description>
            <function>
                <sum>
                    <product>
                        <table>
                            <independentVar lookup="row">propulsion/engine[0]/n1</independentVar>
                            <tableData>
                                0	18.2
                                10	12.7
                                24	8.45
                                42	5.25
                                56	4.77
                                100	4.4
                            </tableData>
                        </table>
                    </product>
                </sum>
            </function>
        </fcs_function >
        <fcs_function name="propulsion/engine[0]/c-egt-lag">
            <description>EGT LAG N1 %</description>
            <function>
                <sum>
                    <product>
                        <table>
                            <independentVar lookup="row">propulsion/engine[0]/n1</independentVar>
                            <tableData>
                                0	3.20
                                10	2.15
                                24	0.99
                                42	0.56
                                56	0.25
                                100	0.21
                            </tableData>
                        </table>
                    </product>
                </sum>
            </function>
        </fcs_function >

        <fcs_function name="propulsion/engine[0]/fuel-flow-rate-norm">
            <description>Fuel Flow normalized</description>
            <function>
                <quotient>
                    <property>propulsion/engine[0]/fuel-flow-rate-pps</property>
                    <value>3</value>
                </quotient>
            </function>
            <clipto>
                <max>1.43</max>
            </clipto>
        </fcs_function>

        <fcs_function name="propulsion/engine[0]/EGT-C-dmd">
            <description>Engine 0 EGT Degrees C</description>
            <function>
                <sum>
                    <table>
                        <independentVar lookup="row">velocities/mach</independentVar>
                        <independentVar lookup="column">propulsion/engine[0]/fuel-flow-rate-norm</independentVar>
                        <tableData>
                            0	0.001	0.009	0.02	0.03	0.04	0.05	0.06	0.07	0.08	0.1	0.12	0.14	0.16	0.2	0.24	0.32	0.4	0.56	0.8	0.984
                            0	0	271	281	292	301	310	319	328	336	344	359	374	387	400	424	447	492	537	641	808	870
                            0.2	0	268	277	288	297	307	315	324	332	340	355	369	383	395	419	442	486	531	633	798	860
                            0.3	0	260	269	279	288	297	306	314	322	330	344	358	371	383	406	428	471	515	614	774	833
                            0.5	0	249	257	267	276	285	293	301	308	316	330	343	355	367	389	410	451	493	588	741	798
                            0.6	0	232	240	250	258	266	274	281	288	295	308	320	332	343	364	383	421	460	549	692	746
                            0.8	0	216	223	232	240	247	254	261	268	274	286	298	308	319	338	356	391	428	510	643	693
                            0.9	0	208	215	223	231	238	245	251	258	264	275	286	297	307	325	343	377	412	491	619	667
                        </tableData>
                    </table>
                </sum>
            </function>
        </fcs_function>

        <fcs_function name="propulsion/engine[0]/augmentation-stage">
            <function>
                <integer>
                    <sum>
                        <value>1.0</value>
                        <product>
                            <sum>
                                <property>fcs/throttle-pos-norm[0]</property>
                                <value>-1</value>
                            </sum>
                            <value>5</value>
                        </product>
                    </sum>
                </integer>
            </function>
            <clipto>
                <min>0</min>
                <max>5</max>
            </clipto>
        </fcs_function>
        <switch name="propulsion/engine[0]/augmentation-ignition">
            <default value="0"/>
            <test value="1">
                propulsion/engine[0]/PB gt 2.14
                propulsion/engine[0]/augmentation-stage gt 0
                propulsion/engine[0]/augmentation-alight eq 0
            </test>
        </switch>
        <switch name="propulsion/engine[0]/augmentation-igniting">
            <default value="0"/>
            <test value="1">
                propulsion/engine[0]/augmentation-ignition gt 0
                propulsion/engine[0]/augmentation-alight eq 0
            </test>
        </switch>

        <!--<lag_filter name="propulsion/engine[0]/augmentation-alight">
            <input></input>
            <output>propulsion/engine[0]/augmentation-alightC</output>
            <c1>0.001</c1>
        </lag_filter >-->
        <actuator name="propulsion/engine[0]/augmentation-ignition-sequence">
            <input> propulsion/engine[0]/augmentation-igniting </input>
            <rate_limit> 1.2 </rate_limit>
            <clipto>
                <min> 0 </min>
                <max>  1</max>
            </clipto>
        </actuator>

        <switch name="propulsion/engine[0]/augmentation-alight-dmd">
            <default value="0"/>
            <test value="propulsion/engine[0]/augmentation-stage">
                propulsion/engine[0]/augmentation-stage ne propulsion/engine[0]/augmentation-alight
                propulsion/engine[0]/augmentation-alight ne 0
                propulsion/engine[0]/thrust-lbs gt 100 <!-- engine alight -->
            </test>
            <test value="propulsion/engine[0]/augmentation-stage">
                propulsion/engine[0]/augmentation-ignition-sequence gt 0.9
                propulsion/engine[0]/thrust-lbs gt 100 <!-- engine alight -->
            </test>
            <test value="propulsion/engine[0]/augmentation-alight">
                propulsion/engine[0]/augmentation-stage gt 0
                propulsion/engine[0]/augmentation-alight ne 0
                propulsion/engine[0]/thrust-lbs gt 100 <!-- engine alight -->
            </test>
        </switch>
        <switch name="propulsion/engine[0]/augmentation-burner">
            <default value="0"/>
            <test value="1">
                propulsion/engine[0]/augmentation-alight ne 0
                propulsion/engine[0]/thrust-lbs gt 100 <!-- engine alight -->
            </test>
            <test value="propulsion/engine[0]/augmentation-ignition-sequence">
                propulsion/engine[0]/augmentation-ignition-sequence ne 0
                propulsion/engine[0]/thrust-lbs gt 100 <!-- engine alight -->
            </test>
        </switch>
        <!--<fcs_function name="propulsion/engine[0]/augmentation-alight-delta">
            <function>
                <difference>
                    <property>propulsion/engine[0]/augmentation-alight</property>
                    <property>propulsion/engine[0]/augmentation-alight-dmd</property>
                </difference>
            </function>
            <clipto>
                <min>0</min>
                <max>5</max>
            </clipto>
        </fcs_function>-->
        <actuator name="propulsion/engine[0]/augmentation-alight">
            <input> propulsion/engine[0]/augmentation-alight-dmd </input>
            <rate_limit> 10 </rate_limit>
            <clipto>
                <min> 0 </min>
                <max>  5</max>
            </clipto>
        </actuator>
        <fcs_function name="propulsion/engine[0]/augmentation-alight-v">
            <function>
                <sum>
                    <property>propulsion/engine[0]/augmentation-alight</property>
                </sum>
            </function>
        </fcs_function>
        <!-- EGT equations -->
        <fcs_function name="propulsion/engine[0]/EGTaug-C-dmd">
            <description>Engine 0 EGT increment due to augmentation</description>
            <function>
                <sum>
                    <table>
                        <independentVar lookup="row">propulsion/engine[0]/augmentation-stage</independentVar>
                        <tableData>
                            0.00	0
                            1.00	86
                            5.00	171
                        </tableData>
                    </table>
                </sum>
            </function>
        </fcs_function>

        <lag_filter name="propulsion/engine[0]/EGTaug-C">
            <input>propulsion/engine[0]/EGTaug-C-dmd</input>
            <output>propulsion/engine[0]/EGTaug-C</output>
            <c1>0.03</c1>
        </lag_filter >
        <fcs_function name="propulsion/engine[0]/EGT-R-dmd">
            <description>EGT Demand degrees R</description>
            <function>
                <product>
                    <sum>
                        <property>propulsion/engine[0]/EGT-C-dmd</property>
                        <property>propulsion/engine[0]/EGTaug-C</property>
                        <value>273</value>
                    </sum>
                    <value>1.8</value>
                </product>
            </function>
        </fcs_function>
        <fcs_function name="propulsion/engine[0]/pt">
            <description>Total Pressure</description>
            <function>
                <!--double pt = Math.Pow(pambient * (1.0 + 0.2 * velocities_mach * velocities_mach), 3.5);-->
                <pow>
                    <product>
                        <product>
                            <property>atmosphere/P-psf</property>
                            <value>144</value>
                        </product>
                        <sum>
                            <value>1.0</value>
                            <product>
                                <value>0.2</value>
                                <property>velocities/mach</property>
                                <property>velocities/mach</property>
                            </product>
                        </sum>
                    </product>
                    <value>3.5</value>
                </pow>
            </function>
        </fcs_function>
        <fcs_function name="propulsion/engine[0]/delta">
            <description>Delta</description>
            <function>
                <quotient>
                    <property>propulsion/engine[0]/pt</property>
                    <value>14.696</value>
                </quotient>
            </function>
        </fcs_function>

        <lead_lag_filter name="propulsion/engine[0]/EGT-R">
            <input>propulsion/engine[0]/EGT-R-dmd</input>
            <output>propulsion/engine[0]/EGT-R</output>
            <c1>propulsion/engine[0]/delta</c1>
            <c2>propulsion/engine[0]/c-egt-lead</c2>
            <c3>propulsion/engine[0]/delta</c3>
            <c4>propulsion/engine[0]/c-egt-lead</c4>
        </lead_lag_filter >
        <lag_filter name="propulsion/engine[0]/casing-temperature-R">
            <input>propulsion/engine[0]/EGT-R</input>
            <output>propulsion/engine[0]/casing-temperature-R</output>
            <c1>0.01</c1>
        </lag_filter>
        <switch name="propulsion/engine[0]/burn-thru">
            <default value="0"/>
            <test value="1">
                propulsion/engine[0]/casing-temperature-R gt 1965
            </test>
        </switch>
        <!-- augmentation -->
        <fcs_function name="propulsion/engine[0]/alt/nozzle-dmd-norm">
            <function>
                <description>PLA Vs Nozzle open area Exhaust Nozzle Control TO 15-15A-1 page 1-8 </description>
                <product>
                    <table>
                        <independentVar lookup="row">fcs/throttle-pos-norm[0]</independentVar>
                        <tableData>
                            0.0 	0.81807
                            0.2235	0.81807
                            1.0000	0.15248
                        </tableData>
                    </table>
                </product>
            </function>
        </fcs_function>

        <switch name="propulsion/engine[0]/alt/nozzle-cmd-norm">
            <default value="propulsion/engine[0]/alt/nozzle-dmd-norm"/>
            <test value="1.0" logic="OR">
                propulsion/engine[0]/augmentation-alight gt 0
                propulsion/engine[0]/augmentation-ignition gt 0.4
            </test>
        </switch>
        <kinematic name="propulsion/engine[0]/alt/nozzle-pos-norm">
            <input>propulsion/engine[0]/alt/nozzle-cmd-norm</input>
            <traverse>
                <setting>
                    <position>0</position>
                    <time>1</time>
                </setting>
                <setting>
                    <position>1</position>
                    <time>0.4</time>
                </setting>
            </traverse>
        </kinematic>
        <!-- a/b lighting envelope; use outside of this envelope will increase risk of blowout-->





    </channel>

    <channel name="F110-R">
        <switch name="propulsion/engine[1]/mid-compression-bypass-active">
            <default value="1"/>
            <test value="0">
                velocities/mach gt 0.35
                propulsion/engine[1]/mcb-failed eq 0
            </test>
        </switch>
        <switch name="propulsion/engine[1]/P0-k4">
            <default value="1.0910913567364466"/>
            <test value="1.04913567364466">
                propulsion/engine[1]/mid-compression-bypass-active gt 0
            </test>
        </switch>
        <fcs_function name="propulsion/engine[1]/P0">
            <description>Inlet pressure P0(alpha,beta)</description>
            <function>
                <table>
                    <independentVar lookup="row">aero/alpha-deg</independentVar>
                    <independentVar lookup="column">aero/beta-deg</independentVar>
                    <tableData>
                        0	          5	         10	         15	         20	         25	         30	         35	         40	         45	         50	         55
                        -20	-0.04000000	-0.03900000	-0.03600000	-0.00850000	 0.00700000	 0.01700000	 0.02800000	 0.03150000	 0.02950000	 0.03150000	 0.02800000	 0.02200000
                        -15	-0.03050000	-0.03000000	-0.02570000	-0.00750000	 0.00400000	 0.00900000	 0.01800000	 0.02300000	 0.01900000	 0.02150000	 0.02050000	 0.01750000
                        -10	-0.00400000	-0.02150000	-0.01900000	-0.00600000	 0.00200000	 0.00450000	 0.01100000	 0.01450000	 0.00850000	 0.01300000	 0.01450000	 0.01450000
                        -5	-0.01000000	-0.01000000	-0.00950000	-0.00300000 -0.00600000	-0.01000000	-0.01200000	-0.02500000	-0.03100000	-0.02100000	 0.00850000	 0.01300000
                        0	 0.00000000	 0.00000000	0.00000000	 0.00000000	 0.00000000	 0.00000000	 0.00000000	 0.00000000	 0.00000000	 0.00000000 0.00000000	 0.00000000
                        5	 0.01000000	 0.01000000	 0.00950000	 0.00300000	-0.00400000	-0.00900000	-0.01800000	-0.02300000	-0.01900000	-0.02150000	-0.02050000	-0.01750000
                        10	 0.02150000	 0.02150000	 0.01900000	 0.00600000	-0.00700000	-0.01700000	-0.02800000	-0.03150000	-0.02950000	-0.03150000	-0.02800000	-0.02200000
                        15	 0.03050000	 0.03000000	 0.02750000	-0.00100000	-0.01000000	-0.02550000	-0.03800000	-0.04050000	-0.04050000	-0.04150000	-0.03600000	-0.02600000
                        20	 0.04000000	 0.03900000	 0.03600000	 0.01000000	 0.02550000	 0.03800000	 0.04050000	 0.04500000	 0.04150000	 0.03600000	 0.02600000	 0.00000000
                    </tableData>
                </table>
            </function>
        </fcs_function>

        <fcs_function name="propulsion/engine[1]/DP3">
            <description>Change in compressor discharge pressure DP3(n1) dP3/dWf</description>
            <function>
                <table>
                    <independentVar lookup="row">propulsion/engine[1]/n1</independentVar>
                    <tableData>
                        60	0.15000000
                        65	0.20000000
                        70	0.24000000
                        79	0.32500000
                        80	0.35800000
                        85	0.36300000
                        90	0.38700000
                        95	0.38000000
                        100	0.35100000
                    </tableData>
                </table>
            </function>
        </fcs_function>
        <!--<switch name="propulsion/engine[1]/n1-lv">
            <default value="propulsion/engine[1]/n1"/>
            --><!--<test value="systems/ecs/windscreen-oat-k" logic="AND">
            systems/ecs/windscreen-heat-active eq 0
            systems/ecs/windscreen-lv-temperature eq 0
        </test>--><!--
        </switch>
        <fcs_function name="propulsion/engine[1]/n1-lv-delta">
            <description>Change in compressor discharge pressure DP3(n1) dP3/dWf</description>
            <function>
                <difference>
                    <property>propulsion/engine[1]/n1</property>
                    <property>propulsion/engine[1]/n1-lv</property>
                </difference>
            </function>
        </fcs_function>-->
        <!--<integrator name="propulsion/engine[1]/n1-lv-val">
            <input> propulsion/engine[1]/n1</input>
            <c1> 0.125 </c1>
        </integrator>-->
        <fcs_function name="propulsion/engine[1]/PB">
            <description>Engine 0 SS Burner pressure ratio</description>
            <function>
                <sum>
                    <table>
                        <independentVar lookup="row">propulsion/engine[1]/n2</independentVar>
                        <independentVar lookup="column">velocities/mach</independentVar>
                        <tableData>
                            0.00000	0.20000	0.30000	0.45000	0.60000	0.80000	0.90000	3.00000
                            0	1.10000	0.93963	0.93963	0.93963	0.93963	0.93963	0.93963	0.93963
                            8	1.09966	0.93963	0.93963	0.93963	0.93963	0.93963	0.93963	0.93963
                            16	1.26926	0.97069	0.93186	0.93963	0.93963	0.93963	0.93963	0.93963
                            24	1.37453	0.99197	0.95229	0.92944	0.93963	0.93963	0.93963	0.93963
                            32	1.56636	1.00992	0.96952	0.92105	0.89341	0.93963	0.93963	0.93963
                            40	1.87550	1.03223	0.99094	0.94140	0.91316	0.91316	0.93963	0.93963
                            48	2.25353	1.06785	1.02514	0.95338	0.91524	0.91835	0.97369	0.97369
                            56	2.61381	1.12695	1.08188	1.00614	0.96590	0.96918	0.97369	0.97369
                            63	2.84760	1.22096	1.17212	1.09007	1.04647	1.05002	0.99630	0.99630
                            71	2.98150	1.34177	1.28810	1.19793	1.15002	1.15392	1.09488	1.09488
                            79	3.00594	1.53633	1.47488	1.37164	1.31677	1.32124	1.25365	1.25365
                            87	3.07269	1.80555	1.73333	1.61200	1.54752	1.55278	1.47333	1.47333
                            95	3.49481	2.16568	2.07905	1.93352	1.85618	1.86248	1.76719	1.76719
                            97	3.71122	2.63418	2.52881	2.35179	2.25772	2.26539	2.14949	2.14949
                            98	3.84257	2.77040	2.65959	2.47341	2.37448	2.38255	2.26065	2.26065
                            100	4.15840	2.84159	2.72792	2.53697	2.43549	2.44376	2.31873	2.31873
                        </tableData>
                    </table>
                </sum>
            </function>
        </fcs_function>

        <fcs_function name="propulsion/engine[1]/P0-k3">
            <description>N1 Compressor stall point</description>
            <function>
                <product>
                    <property>propulsion/engine[1]/compressor-stall-amount</property>
                    <value>17.32</value>
                </product>
            </function>
        </fcs_function>
        <fcs_function name="propulsion/engine[1]/P0-CPV">
            <description>N1 Compressor stall point</description>
            <function>
                <difference>
                    <property>propulsion/engine[1]/PB</property>
                    <product>
                        <property>propulsion/engine[1]/P0</property>
                        <property>propulsion/engine[1]/P0-k3</property>
                    </product>
                </difference>
            </function>
        </fcs_function>

        <switch name="propulsion/engine[1]/P0-stall-dmd">
            <default value="0"/>
            <test value="1" logic="AND">
                <!--propulsion/engine[1]/n1-->
                propulsion/engine[1]/P0-CPV lt propulsion/engine[1]/P0-k4
                gear/unit[2]/WOW eq 0
                gear/unit[1]/WOW eq 0
                fcs/throttle-pos-norm[1] gt 0.1 <!-- no stall in idle   -->
                sim-time-sec gt 10 <!-- otherwise it'll probably stall on the ground -->
                aero/alpha-deg gt 4 <!-- haven't actually got values in the P0 table for -ve alphas.-->
                propulsion/engine[1]/stalled eq 0
            </test>
        </switch>
        <lag_filter name="propulsion/engine[1]/P0-stall">
            <input>propulsion/engine[1]/P0-stall-dmd</input>
            <output>propulsion/engine[1]/P0-stall</output>
            <c1>propulsion/engine[1]/P0-stall-lag</c1>
        </lag_filter >
        <fcs_function name="propulsion/engine[1]/c-egt-lead">
            <description>EGT LEAD N1 %</description>
            <function>
                <sum>
                    <product>
                        <table>
                            <independentVar lookup="row">propulsion/engine[1]/n1</independentVar>
                            <tableData>
                                0	18.2
                                10	12.7
                                24	8.45
                                42	5.25
                                56	4.77
                                100	4.4
                            </tableData>
                        </table>
                    </product>
                </sum>
            </function>
        </fcs_function >
        <fcs_function name="propulsion/engine[1]/c-egt-lag">
            <description>EGT LAG N1 %</description>
            <function>
                <sum>
                    <product>
                        <table>
                            <independentVar lookup="row">propulsion/engine[1]/n1</independentVar>
                            <tableData>
                                0	3.20
                                10	2.15
                                24	0.99
                                42	0.56
                                56	0.25
                                100	0.21
                            </tableData>
                        </table>
                    </product>
                </sum>
            </function>
        </fcs_function >

        <fcs_function name="propulsion/engine[1]/fuel-flow-rate-norm">
            <description>Fuel Flow normalized</description>
            <function>
                <quotient>
                    <property>propulsion/engine[1]/fuel-flow-rate-pps</property>
                    <value>3</value>
                </quotient>
            </function>
            <clipto>
                <max>1.43</max>
            </clipto>
        </fcs_function>

        <fcs_function name="propulsion/engine[1]/EGT-C-dmd">
            <description>Engine 0 EGT Degrees C</description>
            <function>
                <sum>
                    <table>
                        <independentVar lookup="row">velocities/mach</independentVar>
                        <independentVar lookup="column">propulsion/engine[1]/fuel-flow-rate-norm</independentVar>
                        <tableData>
                            0	0.001	0.009	0.02	0.03	0.04	0.05	0.06	0.07	0.08	0.1	0.12	0.14	0.16	0.2	0.24	0.32	0.4	0.56	0.8	0.984
                            0	0	271	281	292	301	310	319	328	336	344	359	374	387	400	424	447	492	537	641	808	870
                            0.2	0	268	277	288	297	307	315	324	332	340	355	369	383	395	419	442	486	531	633	798	860
                            0.3	0	260	269	279	288	297	306	314	322	330	344	358	371	383	406	428	471	515	614	774	833
                            0.5	0	249	257	267	276	285	293	301	308	316	330	343	355	367	389	410	451	493	588	741	798
                            0.6	0	232	240	250	258	266	274	281	288	295	308	320	332	343	364	383	421	460	549	692	746
                            0.8	0	216	223	232	240	247	254	261	268	274	286	298	308	319	338	356	391	428	510	643	693
                            0.9	0	208	215	223	231	238	245	251	258	264	275	286	297	307	325	343	377	412	491	619	667
                        </tableData>
                    </table>
                </sum>
            </function>
        </fcs_function>

        <!-- Augmentation 
         The augmentation has a five stage burner; with high voltage ignition. Sufficient pressure at the ignitor is required and
         this is performed by the augmentation control system on the engine. As soon as there is sufficient pressure, regardless of the compressor
         rpm the augmentor can fire. 
      -->
        <fcs_function name="propulsion/engine[1]/augmentation-stage">
            <function>
                <integer>
                    <sum>
                        <value>1.0</value>
                        <product>
                            <sum>
                                <property>fcs/throttle-pos-norm[1]</property>
                                <value>-1</value>
                            </sum>
                            <value>5</value>
                        </product>
                    </sum>
                </integer>
            </function>
            <clipto>
                <min>0</min>
                <max>5</max>
            </clipto>
        </fcs_function>
        <switch name="propulsion/engine[1]/augmentation-ignition">
            <default value="0"/>
            <test value="1">
                propulsion/engine[1]/PB gt 2.14
                propulsion/engine[1]/augmentation-stage gt 0
                propulsion/engine[1]/augmentation-alight eq 0
            </test>
        </switch>
        <switch name="propulsion/engine[1]/augmentation-igniting">
            <default value="0"/>
            <test value="1">
                propulsion/engine[1]/augmentation-ignition gt 0
                propulsion/engine[1]/augmentation-alight eq 0
            </test>
        </switch>

        <!--<lag_filter name="propulsion/engine[1]/augmentation-alight">
            <input></input>
            <output>propulsion/engine[1]/augmentation-alightC</output>
            <c1>0.001</c1>
        </lag_filter >-->
        <actuator name="propulsion/engine[1]/augmentation-ignition-sequence">
            <input> propulsion/engine[1]/augmentation-igniting </input>
            <rate_limit> 1.2 </rate_limit>
            <clipto>
                <min> 0 </min>
                <max>  1</max>
            </clipto>
        </actuator>

        <switch name="propulsion/engine[1]/augmentation-alight-dmd">
            <default value="0"/>
            <test value="propulsion/engine[1]/augmentation-stage">
                propulsion/engine[1]/augmentation-stage ne propulsion/engine[1]/augmentation-alight
                propulsion/engine[1]/augmentation-alight ne 0
                propulsion/engine[1]/thrust-lbs gt 100 <!-- engine alight -->
            </test>
            <test value="propulsion/engine[1]/augmentation-stage">
                propulsion/engine[1]/augmentation-ignition-sequence gt 0.9
                propulsion/engine[1]/thrust-lbs gt 100 <!-- engine alight -->
            </test>
            <test value="propulsion/engine[1]/augmentation-alight">
                propulsion/engine[1]/augmentation-stage gt 0
                propulsion/engine[1]/augmentation-alight ne 0
                propulsion/engine[1]/thrust-lbs gt 100 <!-- engine alight -->
            </test>
        </switch>
        <switch name="propulsion/engine[1]/augmentation-burner">
            <default value="0"/>
            <test value="1">
                propulsion/engine[1]/augmentation-alight ne 0
                propulsion/engine[1]/thrust-lbs gt 100 <!-- engine alight -->
            </test>
            <test value="propulsion/engine[1]/augmentation-ignition-sequence">
                propulsion/engine[1]/augmentation-ignition-sequence ne 0
                propulsion/engine[1]/thrust-lbs gt 100 <!-- engine alight -->
            </test>
        </switch>
        <!--<fcs_function name="propulsion/engine[1]/augmentation-alight-delta">
            <function>
                <difference>
                    <property>propulsion/engine[1]/augmentation-alight</property>
                    <property>propulsion/engine[1]/augmentation-alight-dmd</property>
                </difference>
            </function>
            <clipto>
                <min>0</min>
                <max>5</max>
            </clipto>
        </fcs_function>-->
        <actuator name="propulsion/engine[1]/augmentation-alight">
            <input> propulsion/engine[1]/augmentation-alight-dmd </input>
            <rate_limit> 10 </rate_limit>
            <clipto>
                <min> 0 </min>
                <max>  5</max>
            </clipto>
        </actuator>
        <fcs_function name="propulsion/engine[1]/augmentation-alight-v">
            <function>
                <sum>
                    <property>propulsion/engine[1]/augmentation-alight</property>
                </sum>
            </function>
        </fcs_function>
        <!-- EGT equations -->
        <fcs_function name="propulsion/engine[1]/EGTaug-C-dmd">
            <description>Engine 0 EGT increment due to augmentation</description>
            <function>
                <sum>
                    <table>
                        <independentVar lookup="row">propulsion/engine[1]/augmentation-stage</independentVar>
                        <tableData>
                            0.00	0
                            1.00	86
                            5.00	171
                        </tableData>
                    </table>
                </sum>
            </function>
        </fcs_function>

        <lag_filter name="propulsion/engine[1]/EGTaug-C">
            <input>propulsion/engine[1]/EGTaug-C-dmd</input>
            <output>propulsion/engine[1]/EGTaug-C</output>
            <c1>0.03</c1>
        </lag_filter >
        <fcs_function name="propulsion/engine[1]/EGT-R-dmd">
            <description>EGT Demand degrees R</description>
            <function>
                <product>
                    <sum>
                        <property>propulsion/engine[1]/EGT-C-dmd</property>
                        <property>propulsion/engine[1]/EGTaug-C</property>
                        <value>273</value>
                    </sum>
                    <value>1.8</value>
                </product>
            </function>
        </fcs_function>
        <fcs_function name="propulsion/engine[1]/pt">
            <description>Total Pressure</description>
            <function>
                <!--double pt = Math.Pow(pambient * (1.0 + 0.2 * velocities_mach * velocities_mach), 3.5);-->
                <pow>
                    <product>
                        <product>
                            <property>atmosphere/P-psf</property>
                            <value>144</value>
                        </product>
                        <sum>
                            <value>1.0</value>
                            <product>
                                <value>0.2</value>
                                <property>velocities/mach</property>
                                <property>velocities/mach</property>
                            </product>
                        </sum>
                    </product>
                    <value>3.5</value>
                </pow>
            </function>
        </fcs_function>
        <fcs_function name="propulsion/engine[1]/delta">
            <description>Delta</description>
            <function>
                <quotient>
                    <property>propulsion/engine[1]/pt</property>
                    <value>14.696</value>
                </quotient>
            </function>
        </fcs_function>

        <lead_lag_filter name="propulsion/engine[1]/EGT-R">
            <input>propulsion/engine[1]/EGT-R-dmd</input>
            <output>propulsion/engine[1]/EGT-R</output>
            <c1>propulsion/engine[1]/delta</c1>
            <c2>propulsion/engine[1]/c-egt-lead</c2>
            <c3>propulsion/engine[1]/delta</c3>
            <c4>propulsion/engine[1]/c-egt-lead</c4>
        </lead_lag_filter >
        <lag_filter name="propulsion/engine[1]/casing-temperature-R">
            <input>propulsion/engine[1]/EGT-R</input>
            <output>propulsion/engine[1]/casing-temperature-R</output>
            <c1>0.01</c1>
        </lag_filter>
        <switch name="propulsion/engine[1]/burn-thru">
            <default value="0"/>
            <test value="1">
                propulsion/engine[1]/casing-temperature-R gt 1965
            </test>
        </switch>
        <!-- augmentation -->
        <fcs_function name="propulsion/engine[1]/alt/nozzle-dmd-norm">
            <function>
                <description>PLA Vs Nozzle open area Exhaust Nozzle Control TO 15-15A-1 page 1-8 </description>
                <product>
                    <table>
                        <independentVar lookup="row">fcs/throttle-pos-norm[0]</independentVar>
                        <tableData>
                            0.0 	0.81807
                            0.2235	0.81807
                            1.0000	0.15248
                        </tableData>
                    </table>
                </product>
            </function>
        </fcs_function>

        <switch name="propulsion/engine[1]/alt/nozzle-cmd-norm">
            <default value="propulsion/engine[1]/alt/nozzle-dmd-norm"/>
            <test value="1.0" logic="OR">
                propulsion/engine[1]/augmentation-alight gt 0
                propulsion/engine[1]/augmentation-ignition gt 0.4
            </test>
        </switch>
        <kinematic name="propulsion/engine[1]/alt/nozzle-pos-norm">
            <input>propulsion/engine[1]/alt/nozzle-cmd-norm</input>
            <traverse>
                <setting>
                    <position>0</position>
                    <time>1</time>
                </setting>
                <setting>
                    <position>1</position>
                    <time>0.4</time>
                </setting>
            </traverse>
        </kinematic>

    </channel>
</system>

<!-- rudimentary figures based of N2 and using values from NAVAIR 01-F14AAD-1 -->
<!--<function name="propulsion/engine[0]/EGT-R">
    <description>Engine 0 EGT Rankine</description>
    <sum>
        <property>atmosphere/T-R</property>
        <table>
            <independentVar>propulsion/engine[0]/n1</independentVar>
            <tableData>
                0.0	0.0
                20.0	0.0
                30.0	541.7
                49.0	541.7
                62.0	631.7
                78.0	1171.7
                95.0	1405.7
                99.9	1684.7
                104.0	1684.7
            </tableData>
        </table>
    </sum>
</function>
<function name="propulsion/engine[1]/EGT-R">
    <description>Engine 1 EGT Rankine</description>
    <sum>
        <property>atmosphere/T-R</property>
        <table>
            <independentVar>propulsion/engine[1]/n1</independentVar>
            <tableData>
                0	0.0
                20	0.0
                30	541.7
                49	541.7
                62	631.7
                78	1171.7
                95	1405.7
                99.9  1684.7
                104	1684.7
            </tableData>
        </table>
    </sum>
</function>-->
