<?xml version="1.0"?>

<!--
        Description: SNECMA M53 for Mirage 2000. Based on F-15 F-100 engines
        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 
        3. NASA TP-1228 Altitude calibration of an F100 Engine S/N p680063, Turbofan Engine. Thomas J.  Biesiadny,  Douglas  Lee,  and Jose  R.  Rodriguez 
        
        Currently this is calculating the EGT and Burn thru only; using the JSBSim model for the rest.
    -->

<system name="ENGINES">
    
    <property value="0">propulsion/engine[0]/augmentation-alight</property>
    <property value="0.01"> propulsion/engine[0]/c-oil-temperature-lag </property>
    <property value="0"> propulsion/engine[0]/oil-temperature-R </property>

    <channel name="Engines SNECMA M53">
        <fcs_function name="propulsion/engine[0]/c-egt-lead">
            <description>EGT LEAD N1 %</description>
            <function>
                <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>
            </function>
        </fcs_function >
        <fcs_function name="propulsion/engine[0]/c-egt-lag">
            <description>EGT LAG N1 %</description>
            <function>
              <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>
            </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>
                <min>0</min>
                <max>1.43</max>
            </clipto>
        </fcs_function>

        <fcs_function name="propulsion/engine[0]/EGT-C-dmd">
            <description>Engine 0 EGT Degrees C</description>
            <function>
              <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>
            </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>
              <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.00000	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
                      99	3.84257	2.77040	2.65959	2.47341	2.37448	2.38255	2.26065	2.26065
                      102	4.15840	2.84159	2.72792	2.53697	2.43549	2.44376	2.31873	2.31873
                  </tableData>
              </table>
            </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>
                <property>propulsion/engine[0]/augmentation-alight</property>
            </function>
        </fcs_function>
        <!-- EGT equations -->
        <fcs_function name="propulsion/engine[0]/EGTaug-C-dmd">
            <description>Engine 0 EGT increment due to augmentation</description>
            <function>
                    <table>
                        <independentVar lookup="row">propulsion/engine[0]/augmentation-stage</independentVar>
                        <tableData>
                            0.00	0
                            1.00	86
                            5.00	171
                        </tableData>
                    </table>
            </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 >
        <fcs_function name="func/rankine_convert">
            <function>
                <description>Convert Rankine into Celsuis (T(°R) - 491.67) × 5/9</description>
                <product>
                    <difference>
                        <p>propulsion/engine[0]/EGT-R</p>
                        <v>491.67</v>
                    </difference>
                    <v>0.5555</v>
                </product>
            </function>
            <output>propulsion/engine[0]/EGT-C</output>
        </fcs_function>

        <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>
                  <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>
            </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
                propulsion/engine[0]/n2 lt 47
            </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>
        <fcs_function name="propulsion/engine[0]/alt/augmentation-normalized">
            <function>
                <description>Augmentation normalized 0..1 </description>
                <quotient>
                    <p>propulsion/engine[0]/augmentation-alight</p>
                    <v>5</v>
                </quotient>>
            </function>
            <output>/sim/multiplay/generic/float[14]</output>
        </fcs_function>
    </channel>

    <channel name="Oil SNECMA M53">
        <fcs_function name="func/oil-temperature-delta-R-dmd">
            <function>
                <description>Oil temperature increment from ambient based on N1</description>
                    <table>
                        <independentVar lookup="row">position/h-sl-ft</independentVar>
                        <independentVar lookup="column">propulsion/engine[0]/n1</independentVar>
                        <tableData>
                            0  	20	60	90	110	120
                            0	27	175	185	211	229	229
                            5000	9	191	191	211	229	229
                            20000	-45	236	198	203	223	223
                            30000	-79	248	207	203	223	223
                            45000	-102	270	234	221	234	234
                        </tableData>
                    </table>
            </function>
            <output>propulsion/engine[0]/oil-temperature-delta-R-dmd</output>
        </fcs_function>
        <lag_filter>
            <input>propulsion/engine[0]/oil-temperature-delta-R-dmd</input>
            <c1> propulsion/engine[0]/c-oil-temperature-lag </c1>
            <output>propulsion/engine[0]/oil-temperature-R-delta</output>
        </lag_filter>
        <summer>
            <input>propulsion/engine[0]/oil-temperature-R-delta</input>
            <input>atmosphere/T-R</input>
            <output>propulsion/engine[0]/oil-temperature-R</output>
        </summer>
        <fcs_function name="funcs/engine[0]/oil-temperature-C">
            <function>
                <description>Convert Rankine into Celsuis (T(°R) - 491.67) × 5/9</description>
                <product>
                    <difference>
                        <p>propulsion/engine[0]/oil-temperature-R</p>
                        <v>491.67</v>
                    </difference>
                    <v>0.5555</v>
                </product>
            </function>
            <output>propulsion/engine[0]/oil-temperature-C</output>
        </fcs_function>
        <fcs_function name="funcs/engine[0]/oil-pressure-psi">
            <function>
                <description>OIL pressure </description>
                    <table>
                        <independentVar lookup="row">propulsion/engine[0]/n2</independentVar>
                        <tableData>
                            0   0
                            22  12
                            50  30
                            100 48
                        </tableData>
                    </table>
            </function>
            <output>propulsion/engine[0]/oil-pressure-psi</output>
        </fcs_function>

        <fcs_function name="propulsion/engine[0]/rpm">
            <function>
                <description>N1 rotor RPM</description>
                <product>
                    <property>propulsion/engine[0]/n1</property>
                    <value>100</value>
                </product>
            </function>
        </fcs_function>

    </channel>
</system>