fgpiston.cpp

来自「6 DOF Missle Simulation」· C++ 代码 · 共 910 行 · 第 1/3 页

CPP
910
字号
//  double AFR = 10+(12*(1-Mixture));// mixture 10:1 to 22:1//  m_dot_fuel = m_dot_air / AFR;  m_dot_fuel = (m_dot_air * equivalence_ratio) / 14.7;  FuelFlow_gph = m_dot_fuel    * 3600            // seconds to hours    * 2.2046            // kg to lb    / 6.0;            // lb to gal_us of gasoline//    / 6.6;            // lb to gal_us of kerosene}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/** * Calculate the power produced by the engine. * * Currently, the JSBSim propellor model does not allow the * engine to produce enough RPMs to get up to a high horsepower. * When tested with sufficient RPM, it has no trouble reaching * 200HP. * * Inputs: ManifoldPressure_inHg, p_amb, RPM, T_amb, *   Mixture_Efficiency_Correlation, Cycles, MaxHP * * Outputs: Percentage_Power, HP */void FGPiston::doEnginePower(void){  if (Running) {    double T_amb_degF = KelvinToFahrenheit(T_amb);    double T_amb_sea_lev_degF = KelvinToFahrenheit(288);    // FIXME: this needs to be generalized    double ME, friction, percent_RPM, power;  // Convienience term for use in the calculations    ME = Mixture_Efficiency_Correlation->GetValue(m_dot_fuel/m_dot_air);    percent_RPM = RPM/MaxRPM;    friction = 1 - (percent_RPM * percent_RPM * percent_RPM * percent_RPM/10);    if (friction < 0 ) friction = 0;    power = friction;    if ( Magnetos != 3 ) power *= SparkFailDrop;    HP = (FuelFlow_gph * 6.0 / BSFC )* ME * suction_loss * power;  } else {    // Power output when the engine is not running    if (Cranking) {      if (RPM < 10) {        HP = StarterHP;      } else if (RPM < IdleRPM*0.8) {        HP = StarterHP + ((IdleRPM*0.8 - RPM) / 8.0);        // This is a guess - would be nice to find a proper starter moter torque curve      } else {        HP = StarterHP;      }    } else {      // Quick hack until we port the FMEP stuff      if (RPM > 0.0)        HP = -1.5;      else        HP = 0.0;    }  }  Percentage_Power = HP / MaxHP ;//  cout << "Power = " << HP << "  RPM = " << RPM << "  Running = " << Running << "  Cranking = " << Cranking << endl;}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/** * Calculate the exhaust gas temperature. * * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel, *   Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, Percentage_Power * * Outputs: combustion_efficiency, ExhaustGasTemp_degK */void FGPiston::doEGT(void){  double delta_T_exhaust;  double enthalpy_exhaust;  double heat_capacity_exhaust;  double dEGTdt;  if ((Running) && (m_dot_air > 0.0)) {  // do the energy balance    combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);    enthalpy_exhaust = m_dot_fuel * calorific_value_fuel *                              combustion_efficiency * 0.33;    heat_capacity_exhaust = (Cp_air * m_dot_air) + (Cp_fuel * m_dot_fuel);    delta_T_exhaust = enthalpy_exhaust / heat_capacity_exhaust;    ExhaustGasTemp_degK = T_amb + delta_T_exhaust;    ExhaustGasTemp_degK *= 0.444 + ((0.544 - 0.444) * Percentage_Power);  } else {  // Drop towards ambient - guess an appropriate time constant for now    combustion_efficiency = 0;    dEGTdt = (RankineToKelvin(Atmosphere->GetTemperature()) - ExhaustGasTemp_degK) / 100.0;    delta_T_exhaust = dEGTdt * dt;    ExhaustGasTemp_degK += delta_T_exhaust;  }}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/** * Calculate the cylinder head temperature. * * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel, *   combustion_efficiency, RPM, MaxRPM * * Outputs: CylinderHeadTemp_degK */void FGPiston::doCHT(void){  double h1 = -95.0;  double h2 = -3.95;  double h3 = -140.0; // -0.05 * 2800 (default maxrpm)  double arbitary_area = 1.0;  double CpCylinderHead = 800.0;  double MassCylinderHead = 8.0;  double temperature_difference = CylinderHeadTemp_degK - T_amb;  double v_apparent = IAS * 0.5144444;  double v_dot_cooling_air = arbitary_area * v_apparent;  double m_dot_cooling_air = v_dot_cooling_air * rho_air;  double dqdt_from_combustion =    m_dot_fuel * calorific_value_fuel * combustion_efficiency * 0.33;  double dqdt_forced = (h2 * m_dot_cooling_air * temperature_difference) +    (h3 * RPM * temperature_difference / MaxRPM);  double dqdt_free = h1 * temperature_difference;  double dqdt_cylinder_head = dqdt_from_combustion + dqdt_forced + dqdt_free;  double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;  CylinderHeadTemp_degK +=    (dqdt_cylinder_head / HeatCapacityCylinderHead) * dt;}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/** * Calculate the oil temperature. * * Inputs: CylinderHeadTemp_degK, T_amb, OilPressure_psi. * * Outputs: OilTemp_degK */void FGPiston::doOilTemperature(void){  double idle_percentage_power = 0.023;        // approximately  double target_oil_temp;        // Steady state oil temp at the current engine conditions  double time_constant;          // The time constant for the differential equation  double efficiency = 0.667;     // The aproximate oil cooling system efficiency // FIXME: may vary by engine//  Target oil temp is interpolated between ambient temperature and Cylinder Head Tempurature//  target_oil_temp = ( T_amb * efficiency ) + (CylinderHeadTemp_degK *(1-efficiency)) ;  target_oil_temp = CylinderHeadTemp_degK + efficiency * (T_amb - CylinderHeadTemp_degK) ;  if (OilPressure_psi > 5.0 ) {    time_constant = 5000 / OilPressure_psi; // Guess at a time constant for circulated oil.                                            // The higher the pressure the faster it reaches					    // target temperature.  Oil pressure should be about					    // 60 PSI yielding a TC of about 80.  } else {    time_constant = 1000;  // Time constant for engine-off; reflects the fact                           // that oil is no longer getting circulated  }  double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;  OilTemp_degK += (dOilTempdt * dt);}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/** * Calculate the oil pressure. * * Inputs: RPM, MaxRPM, OilTemp_degK * * Outputs: OilPressure_psi */void FGPiston::doOilPressure(void){  double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine  double Oil_Press_RPM_Max = MaxRPM * 0.75;    // 75% of max rpm FIXME: may vary by engine  double Design_Oil_Temp = 358;          // degK; FIXME: may vary by engine  double Oil_Viscosity_Index = 0.25;  OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;  if (OilPressure_psi >= Oil_Press_Relief_Valve) {    OilPressure_psi = Oil_Press_Relief_Valve;  }  OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index * OilPressure_psi / Oil_Press_Relief_Valve;}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%string FGPiston::GetEngineLabels(string delimeter){  std::ostringstream buf;  buf << Name << " Power Available (engine " << EngineNumber << " in HP)" << delimeter      << Name << " HP (engine " << EngineNumber << ")" << delimeter      << Name << " equivalent ratio (engine " << EngineNumber << ")" << delimeter      << Name << " MAP (engine " << EngineNumber << ")" << delimeter      << Thruster->GetThrusterLabels(EngineNumber, delimeter);  return buf.str();}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%string FGPiston::GetEngineValues(string delimeter){  std::ostringstream buf;  buf << PowerAvailable << delimeter << HP << delimeter      << equivalence_ratio << delimeter << MAP << delimeter      << Thruster->GetThrusterValues(EngineNumber, delimeter);  return buf.str();}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%////    The bitmasked value choices are as follows://    unset: In this case (the default) JSBSim would only print//       out the normally expected messages, essentially echoing//       the config files as they are read. If the environment//       variable is not set, debug_lvl is set to 1 internally//    0: This requests JSBSim not to output any messages//       whatsoever.//    1: This value explicity requests the normal JSBSim//       startup messages//    2: This value asks for a message to be printed out when//       a class is instantiated//    4: When this value is set, a message is displayed when a//       FGModel object executes its Run() method//    8: When this value is set, various runtime state variables//       are printed out periodically//    16: When set various parameters are sanity checked and//       a message is printed out when they go out of boundsvoid FGPiston::Debug(int from){  if (debug_lvl <= 0) return;  if (debug_lvl & 1) { // Standard console startup message output    if (from == 0) { // Constructor      cout << "\n    Engine Name: "         << Name << endl;      cout << "      MinManifoldPressure: " << MinManifoldPressure_inHg << endl;      cout << "      MaxManifoldPressure: " << MaxManifoldPressure_inHg << endl;      cout << "      MinMaP (Pa):         " << minMAP << endl;      cout << "      MaxMaP (Pa): "         << maxMAP << endl;      cout << "      Displacement: "        << Displacement             << endl;      cout << "      MaxHP: "               << MaxHP                    << endl;      cout << "      Cycles: "              << Cycles                   << endl;      cout << "      IdleRPM: "             << IdleRPM                  << endl;      cout << "      MaxThrottle: "         << MaxThrottle              << endl;      cout << "      MinThrottle: "         << MinThrottle              << endl;      cout << endl;      cout << "      Combustion Efficiency table:" << endl;      Lookup_Combustion_Efficiency->Print();      cout << endl;      cout << endl;      cout << "      Power Mixture Correlation table:" << endl;      Power_Mixture_Correlation->Print();      cout << endl;      cout << endl;      cout << "      Mixture Efficiency Correlation table:" << endl;      Mixture_Efficiency_Correlation->Print();      cout << endl;    }  }  if (debug_lvl & 2 ) { // Instantiation/Destruction notification    if (from == 0) cout << "Instantiated: FGPiston" << endl;    if (from == 1) cout << "Destroyed:    FGPiston" << endl;  }  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects  }  if (debug_lvl & 8 ) { // Runtime state variables  }  if (debug_lvl & 16) { // Sanity checking  }  if (debug_lvl & 64) {    if (from == 0) { // Constructor      cout << IdSrc << endl;      cout << IdHdr << endl;    }  }}} // namespace JSBSim

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?