<?xml version="1.0"?>
<!--
        Description: F14 hydraulics system
        Notes: Supports engine and emergency pumps, with bidi transfer
               (1) no electrical modelling so will always have hyd pressure
               (2) Flight controls require hyds and will not function if no pressure
               (3) pump failure supported (no pressure depending on pump/configuration of other pumps)
        Author: Richard Harrison (rjh@zaretto.com)
        References: F14-AAD-1 p2-68 to p2-76
    -->

<system name="hydraulic">

  <property value="3022">systems/hydraulics/normal-pressure</property>
  <property value="2100">systems/hydraulics/bidi-activation</property>
  <property value="2500">systems/hydraulics/bidi-normal-pressure</property>
<!-- the min pressure is really for when no hydraulic fluid and the pressure has been at that level
     for more than 10 seconds, so for now we will not model this as there is no way for fluid to be depleted -->
  <property value="-500">systems/hydraulics/bidi-cutoff-min-pressure</property>
  <property value="25">systems/hydraulics/reservoir-quantity</property>
  <property value="0">emerg-flyt-hyd-switch</property>
  <property value="2100">systems/hydraulics/emerg-pump-auto-activation</property>
  <property value="2400">systems/hydraulics/emerg-pump-auto-deactivation</property>
  <property value="0">systems/hydraulics/emerg-system-pump-failed</property>
  <property value="0">systems/hydraulics/flight-system-pump-failed</property>
  <property value="0">systems/hydraulics/combined-system-pump-failed</property>
  <property value="0">systems/hydraulics/emerg-flyt-hyd-switch</property>
  <property value="1">systems/hydraulics/hyd-transfer-pump-switch</property>

  <channel name="flight">
    <switch name="systems/hydraulics/flight-system-pressure">
          <default value="0"/>
          <test  logic="AND" value="1">
                systems/hydraulics/flight-system-psi ge 1800
          </test>
    </switch>
<!-- 
Sufficient  hydraulic  pressure  for smooth flight control inputs should
be available with one engine windmilling  at  18  percent  rpm  or  two
engines at 11 percent rpm.
-->

     <scheduled_gain name="systems/hydraulics/flight-system-pump-psi">
      <input>propulsion/engine[1]/n2</input>
      <table>
        <independentVar lookup="row">propulsion/engine[1]/n2</independentVar>
        <independentVar lookup="column">systems/hydraulics/flight-system-pump-failed</independentVar>
         <tableData>
                    0      1
            0       0      0
            18    130      0
         </tableData>
      </table>
      <clipto>
        <min> 0 </min>
        <max><property>systems/hydraulics/normal-pressure</property></max>
      </clipto>
     </scheduled_gain>

    <switch name="systems/hydraulics/bidi-combined-to-flight-system-factor">
          <default value="0"/>
          <test  logic="AND" value="0.83">
                systems/hydraulics/hyd-transfer-pump-switch ne 0
                systems/hydraulics/combined-system-psi ge systems/hydraulics/bidi-activation
                systems/hydraulics/flight-system-pump-psi le systems/hydraulics/bidi-activation
                systems/hydraulics/flight-system-psi ge systems/hydraulics/bidi-cutoff-min-pressure
                systems/hydraulics/combined-system-psi ge systems/hydraulics/bidi-cutoff-min-pressure
          </test>
    </switch>

    <switch name="systems/hydraulics/emerg-pump-low-speed-psi">
          <default value="0"/>
          <test  logic="AND" value="2001">
<!--                systems/hydraulics/emerg-flyt-hyd-switch eq 0  -->
                systems/hydraulics/emerg-system-pump-failed eq 0
                systems/hydraulics/flight-system-psi lt systems/hydraulics/emerg-pump-auto-activation
                systems/hydraulics/combined-system-psi lt systems/hydraulics/emerg-pump-auto-activation
                systems/electrics/ac-right-main-bus gt 5
          </test>
          <test  logic="AND" value="0">
                systems/hydraulics/emerg-pump-low-speed-psi ge 1800
                systems/hydraulics/emerg-system-pump-failed ne 0
                systems/hydraulics/flight-system-psi gt systems/hydraulics/emerg-pump-auto-deactivation
                systems/hydraulics/combined-system-psi gt systems/hydraulics/emerg-pump-auto-deactivation
          </test>
    </switch>

    <pure_gain name="systems/hydraulics/bidi-combined-available-psi">
          <input>systems/hydraulics/combined-system-psi</input>
          <gain>systems/hydraulics/bidi-combined-to-flight-system-factor</gain>
    </pure_gain>

    <summer name="systems/hydraulics/bidi-transfer-combined-to-flight-system-psi">
        <input>systems/hydraulics/bidi-combined-available-psi</input>
        <input>-systems/hydraulics/flight-system-pump-psi</input>
      <clipto>
        <min> 0 </min>
        <max><property>systems/hydraulics/bidi-normal-pressure</property></max>
      </clipto>
    </summer>

    <summer name="systems/hydraulics/emerg-transfer-to-flight-system-psi">
        <input>systems/hydraulics/emerg-pump-low-speed-psi</input>
        <input>-systems/hydraulics/bidi-transfer-combined-to-flight-system-psi</input>
        <input>-systems/hydraulics/flight-system-pump-psi</input>
      <clipto>
        <min> 0 </min>
        <max><property>systems/hydraulics/bidi-normal-pressure</property></max>
      </clipto>
    </summer>

    <summer name="systems/hydraulics/flight-system-psi">
        <input>systems/hydraulics/emerg-transfer-to-flight-system-psi</input>
        <input>systems/hydraulics/bidi-transfer-combined-to-flight-system-psi</input>
        <input>systems/hydraulics/flight-system-pump-psi</input>
     </summer>
  </channel>

  <channel name="Combined">
    <switch name="systems/hydraulics/combined-system-pressure">
          <default value="0"/>
          <test  logic="AND" value="1">
                systems/hydraulics/combined-system-psi ge 2000
          </test>
    </switch>
     <scheduled_gain name="systems/hydraulics/combined-system-pump-psi">
      <input>propulsion/engine[0]/n2</input>
      <table>
        <independentVar lookup="row">propulsion/engine[0]/n2</independentVar>
        <independentVar lookup="column">systems/hydraulics/combined-system-pump-failed</independentVar>
         <tableData>
                    0      1
            0       0      0
            18    130      0
         </tableData>
      </table>
      <clipto>
        <min> 0 </min>
        <max><property>systems/hydraulics/normal-pressure</property></max>
      </clipto>
     </scheduled_gain>


    <switch name="systems/hydraulics/bidi-flight-to-combined-system-factor">
          <default value="0"/>
          <test  logic="AND" value="0.83">
                systems/hydraulics/hyd-transfer-pump-switch ne 0
                systems/hydraulics/flight-system-psi ge systems/hydraulics/bidi-activation
                systems/hydraulics/combined-system-pump-psi le systems/hydraulics/bidi-activation
                systems/hydraulics/flight-system-psi ge systems/hydraulics/bidi-cutoff-min-pressure
                systems/hydraulics/combined-system-psi ge systems/hydraulics/bidi-cutoff-min-pressure
          </test>
    </switch>

    <pure_gain name="systems/hydraulics/bidi-flight-available-psi">
          <input>systems/hydraulics/flight-system-psi</input>
          <gain>systems/hydraulics/bidi-flight-to-combined-system-factor</gain>
    </pure_gain>

    <summer name="systems/hydraulics/bidi-transfer-flight-to-combined-system-psi">
        <input>systems/hydraulics/bidi-flight-available-psi</input>
        <input>-systems/hydraulics/combined-system-pump-psi</input>
      <clipto>
        <min> 0 </min>
        <max><property>systems/hydraulics/bidi-normal-pressure</property></max>
      </clipto>
    </summer>

    <summer name="systems/hydraulics/emerg-transfer-to-combined-system-psi">
        <input>systems/hydraulics/emerg-pump-low-speed-psi</input>
        <input>-systems/hydraulics/bidi-transfer-flight-to-combined-system-psi</input>
        <input>-systems/hydraulics/combined-system-pump-psi</input>
      <clipto>
        <min> 0 </min>
        <max><property>systems/hydraulics/bidi-normal-pressure</property></max>
      </clipto>
    </summer>


     <summer name="systems/hydraulics/combined-system-psi">
        <input>systems/hydraulics/emerg-transfer-to-combined-system-psi</input>
        <input>systems/hydraulics/bidi-transfer-flight-to-combined-system-psi</input>
        <input>systems/hydraulics/combined-system-pump-psi</input>
     </summer>
  </channel>

</system>
