/* Main loop model I/O */

digraph G {
  rankdir = LR;
  ranksep=1.4;
  // size = "17, 11";
  concentrate=true;

  {
    node [shape = box, fillcolor=grey, style=filled, group=model];
    Propagate [fillcolor=red];
    Input;
    Inertial [fillcolor=green];
    Atmosphere [fillcolor=green];
    Winds [fillcolor=green];
    "Control Systems"; 
    Propulsion [fillcolor=gold];
    MassBalance;
    Aerodynamics [fillcolor=gold]; 
    GroundReactions [fillcolor=gold];
    ExternalReactions [fillcolor=gold];
    BuoyantForces [fillcolor=gold];
    Aircraft;
    Accelerations;
    Auxiliary;
    Output;
  };

  Executive  [shape = box, fillcolor=yellow, style=filled];
  
  /* Order of execution of main loop models */
  {
  node [shape = box, fillcolor=grey, style=filled, group=model];
  Propagate ->
  Input ->  
  Inertial ->
  Atmosphere ->
  Winds ->
  "Control Systems" ->
  MassBalance ->
  Auxiliary ->
  Propulsion ->
  Aerodynamics ->
  GroundReactions ->
  ExternalReactions ->
  BuoyantForces ->
  Aircraft ->
  Accelerations->
  Output [color=blue, style=bold];
  }
  /*
  subgraph cluster0 {
    label="Environment Models";
    Atmosphere;
    Winds;
    Inertial;
  };
  
  subgraph cluster1 {
    label="Force Models";
    Propulsion; Aerodynamics; GroundReactions; ExternalReactions; BuoyantForces;
  };
  */
  {
    node [shape=plaintext];
    AltitudeASL;
    Tl2b;
    Tb2l;
    Ti2b;
    Tb2i;
    Tec2b;
    Tec2l;
    Tb2w;
    Tw2b;
    Vtotal;
    RadiusToVehicle;
    Latitude;
    "Delta T";
    Mass;
    EmptyWeight;
    Force_w;
    Forces;
    Gravity;
    GravityJ2;
    J;
    Jinv;
    Moments;
    DistanceAGL;
    PQR;
    PQRi;
    UVW;
    InertialPosition;
    QuaternionECI;
    VelocityNED;
    BodyAccel;
    Location;
    LocationBody;
    CosTheta;
    SinTheta;
    CosPhi;
    SinPhi;
    Psi;
    ThrottlePos;
    TakeoffThrottle
    MixturePos;
    ThrottleCmd;
    MixtureCmd;
    PropAdvance;
    PropFeather;
    BrakePos;
    SteerPosDeg;
    FCSGearPos;
    LagrangeMultipliersList;
    TerrainVelocity;
    TerrainAngularVelocity;
}
/* Alignment blocks */
{
    node [shape=plaintext];
    rank=same;
//    GroundReactions;
    PQRdot;
    PQRidot;
    UVWdot;
    UVWidot;
    Quaterniondot;
}
{
    rank=same;
 //   Executive;
    Propagate;
    Input;
}
{
    rank=same;
    PQRi;
    UVW;
    PQR;
    InertialPosition;
    Ti2b;
    Tb2i;
    Tec2b;
    Tl2b;
    QuaternionECI;
}
{
    node [shape=plaintext];
    rank=same;
    GasMassInertia;
    GasMass;
    GasMassMoment;
    TanksInertia;
    TanksWeight;
    TanksMoment;
}
{
    node [shape=plaintext];
    rank=same;
    Alpha;
    Beta;
    qbar;
    Vtotal;
    Vground;
    Vcalibrated;
    TotalTemperature;
    TotalPressure;
    TAT;
    AeroUVW;
    AeroPQR;
}
{
    node [shape=plaintext];
    rank=same;
    TotalWindNED;
    TurbPQR;
    WindPsi;
    Vwind;
}
{
    node [shape=plaintext];
    rank=same;
    VRPBody;
    RPBody;
    EyePtBody;
}
{
    node [shape=plaintext];
    rank=same;
    "Buoyant Forces";
    "Buoyant Moments";
    "External Forces";
    "External Moments";
    "Ground Forces";
    "Ground Moments";
    "Aero Forces";
    "Aero Moments";
    "Prop Forces";
    "Prop Moments";
}
{
    node [shape=plaintext];
    rank=same;
    Pressure;
    Density;
    Temperature;
    PressureSL;
    DensitySL;
    DensityRatio;
    SoundSpeed;
    KinematicViscosity;
}

  // Propagate
  Accelerations -> PQRidot -> Propagate [color=orange, style=bold];
  Accelerations -> Quaterniondot -> Propagate [color=orange, style=bold];
  Accelerations -> UVWidot -> Propagate [color=orange, style=bold];
  Executive -> "Delta T" -> Propagate;

  // Atmosphere & Winds
  Propagate -> AltitudeASL -> Atmosphere;

  // Winds
  Propagate -> AltitudeASL -> Winds;
  Propagate -> DistanceAGL -> Winds;
  Propagate -> Tl2b -> Winds;
  Executive -> "Delta T" -> Winds;
  Auxiliary -> Tw2b -> Winds;
  Auxiliary -> Vtotal -> Winds [color=orange, style=bold];

  // Auxiliary
  Atmosphere -> Pressure -> Auxiliary;
  Atmosphere -> Density -> Auxiliary;
  Atmosphere -> DensitySL -> Auxiliary;
  Atmosphere -> PressureSL -> Auxiliary;
  Atmosphere -> Temperature -> Auxiliary;
  Atmosphere -> SoundSpeed -> Auxiliary;
  Atmosphere -> KinematicViscosity -> Auxiliary;
  Propagate -> DistanceAGL -> Auxiliary;
  MassBalance -> Mass -> Auxiliary;
  Propagate -> Tl2b -> Auxiliary;
  Propagate -> Tb2l ->Auxiliary;
  Propagate -> PQR -> Auxiliary;
  Propagate -> PQRi -> Auxiliary;
  Accelerations -> PQRidot -> Auxiliary;
  Propagate -> UVW -> Auxiliary;
  Accelerations -> UVWdot -> Auxiliary;
  Propagate -> VelocityNED -> Auxiliary;
  Propagate -> BodyAccel -> Auxiliary;
  MassBalance -> EyePtBody -> Auxiliary;
  MassBalance -> VRPBody -> Auxiliary;
  MassBalance -> RPBody -> Auxiliary;
  Aerodynamics -> Force_w -> Auxiliary [color=orange, style=bold];
  Propagate -> Location -> Auxiliary;
  Propagate -> CosTheta -> Auxiliary;
  Propagate -> SinTheta -> Auxiliary;
  Propagate -> CosPhi -> Auxiliary;
  Propagate -> SinPhi -> Auxiliary;
  Propagate -> Psi -> Auxiliary;
  Winds -> TotalWindNED -> Auxiliary;
  Winds -> TurbPQR -> Auxiliary;
  Winds -> WindPsi -> Auxiliary;
  Winds -> Vwind -> Auxiliary;
  Aircraft -> "Pitot Angle" -> Auxiliary;

  // Propulsion
  Atmosphere -> PressureSL -> Propulsion;
  Atmosphere -> Pressure -> Propulsion;
  Atmosphere -> PressureRatio -> Propulsion;
  Atmosphere -> Temperature -> Propulsion;
  Atmosphere -> Density -> Propulsion;
  Atmosphere -> DensityRatio -> Propulsion;
  Atmosphere -> SoundSpeed -> Propulsion;
  Auxiliary -> TotalPressure -> Propulsion;
  Auxiliary -> TotalTemperature -> Propulsion;
  Auxiliary -> Vcalibrated -> Propulsion;
  Auxiliary -> Vtotal -> Propulsion;
  Auxiliary -> qbar -> Propulsion;
  Auxiliary -> Alpha -> Propulsion;
  Auxiliary -> Beta -> Propulsion;
  Auxiliary -> TAT -> Propulsion;
  Auxiliary -> AeroUVW -> Propulsion;
  Auxiliary -> AeroPQR -> Propulsion;
  Executive -> "Delta T" -> Propulsion;
  "Control Systems" -> ThrottlePos -> Propulsion;
  "Control Systems" -> MixturePos -> Propulsion;
  "Control Systems" -> ThrottleCmd -> Propulsion;
  "Control Systems" -> MixtureCmd -> Propulsion;
  "Control Systems" -> PropAdvance -> Propulsion;
  "Control Systems" -> PropFeather -> Propulsion;
  Propagate -> DistanceAGL -> Propulsion;
  Propagate -> PQR -> Propulsion;

  // Aerodynamics
  Auxiliary -> Alpha -> Aerodynamics;
  Auxiliary -> Beta -> Aerodynamics;
  Auxiliary -> Tb2w -> Aerodynamics;
  Auxiliary -> Tw2b -> Aerodynamics;
  Auxiliary -> qbar -> Aerodynamics;
  Auxiliary -> Vtotal -> Aerodynamics;
  Auxiliary -> RPBody -> Aerodynamics;

  // Ground Reactions
  Auxiliary -> Vground -> GroundReactions;
  Auxiliary -> Vcalibrated -> GroundReactions;
  Atmosphere -> Temperature -> GroundReactions;
  "Control Systems" -> TakeoffThrottle -> GroundReactions;
  "Control Systems" -> SteerPosDeg -> GroundReactions;
  "Control Systems" -> BrakePos -> GroundReactions;
  "Control Systems" -> FCSGearPos -> GroundReactions;
  MassBalance -> EmptyWeight -> GroundReactions;
  Propagate -> Tb2l -> GroundReactions;
  Propagate -> Tec2l -> GroundReactions;
  Propagate -> Tec2b -> GroundReactions;
  Propagate -> PQR -> GroundReactions;
  Propagate -> UVW -> GroundReactions;
  Propagate -> AltitudeASL -> GroundReactions;
  Propagate -> DistanceAGL -> GroundReactions;
  Executive -> "Delta T" -> GroundReactions;
  Propagate -> Location -> GroundReactions;
  MassBalance -> LocationBody -> GroundReactions;

  // Buoyant Forces
  Atmosphere -> Pressure -> BuoyantForces
  Atmosphere -> Density -> BuoyantForces
  Atmosphere -> Temperature -> BuoyantForces
  Inertial -> Gravity -> BuoyantForces

  // MassBalance
  BuoyantForces -> GasMassInertia -> MassBalance;
  BuoyantForces -> GasMass -> MassBalance;
  BuoyantForces -> GasMassMoment -> MassBalance;
  Propulsion -> TanksInertia -> MassBalance;
  Propulsion -> TanksWeight -> MassBalance;
  Propulsion -> TanksMoment -> MassBalance;

  // Aircraft
  Aerodynamics -> "Aero Forces" -> Aircraft;
  Propulsion -> "Prop Forces" -> Aircraft;
  GroundReactions -> "Ground Forces" -> Aircraft;
  ExternalReactions -> "External Forces" -> Aircraft;
  BuoyantForces -> "Buoyant Forces" -> Aircraft;
  Aerodynamics -> "Aero Moments" -> Aircraft;
  Propulsion -> "Prop Moments" -> Aircraft;
  GroundReactions -> "Ground Moments" -> Aircraft;
  ExternalReactions -> "External Moments" -> Aircraft;
  BuoyantForces -> "Buoyant Moments" -> Aircraft;

  // Inertial
  Propagate -> RadiusToVehicle -> Inertial;
  Propagate -> Latitude -> Inertial;

  // Accelerations
  MassBalance -> J -> Accelerations;
  MassBalance -> Jinv -> Accelerations;
  MassBalance -> Mass -> Accelerations;
  Propagate -> Ti2b -> Accelerations;
  Propagate -> Tb2i -> Accelerations;
  Propagate -> Tec2b -> Accelerations;
  Propagate -> Tl2b -> Accelerations;
  Propagate -> QuaternionECI -> Accelerations;
  Aircraft -> Moments -> Accelerations;
  Aircraft -> Forces -> Accelerations;
  GroundReactions -> "Ground Forces" -> Accelerations;
  GroundReactions -> "Ground Moments" -> Accelerations;
  GroundReactions -> LagrangeMultipliersList -> Accelerations;
  Inertial -> Gravity -> Accelerations;
  Inertial -> GravityJ2 -> Accelerations;
  Propagate -> PQRi -> Accelerations;
  Propagate -> PQR -> Accelerations;
  Propagate -> UVW -> Accelerations;
  Propagate -> InertialPosition -> Accelerations;
  Propagate -> TerrainVelocity -> Accelerations;
  Propagate -> TerrainAngularVelocity -> Accelerations;
  Executive -> "Delta T" -> Accelerations;
}
