1
0
Fork 0

Fixed uninitialized variables in FGPiston.

Some members were used before being initialized in FGPiston which could randomly generate invalid floating point values that could propagate to many places in JSBSim.
As a cure to the problem, all variables are now initialized to valid default values in the header (as allowed by C++11). The constructor is only expected to set the members to meaningful values.
This commit is contained in:
Bertrand Coconnier 2020-04-30 15:10:30 +02:00
parent 4a485adcf3
commit 7f319d69ca

View file

@ -252,14 +252,14 @@ public:
protected: protected:
private: private:
int crank_counter; int crank_counter = 0;
double IndicatedHorsePower; double IndicatedHorsePower = 0.0;
//double IndicatedPower; //double IndicatedPower;
double PMEP; double PMEP = 0.0;
double FMEP; double FMEP = 0.0;
double FMEPDynamic; double FMEPDynamic = 0.0;
double FMEPStatic; double FMEPStatic = 0.0;
//double T_Intake; //double T_Intake;
void doEngineStartup(void); void doEngineStartup(void);
@ -294,102 +294,102 @@ private:
// //
// Configuration // Configuration
// //
double MinManifoldPressure_inHg; // Inches Hg double MinManifoldPressure_inHg = 0.0; // Inches Hg
double MaxManifoldPressure_inHg; // Inches Hg double MaxManifoldPressure_inHg = 0.0; // Inches Hg
//double MaxManifoldPressure_Percent; // MaxManifoldPressure / 29.92 //double MaxManifoldPressure_Percent; // MaxManifoldPressure / 29.92
double ManifoldPressureLag; // Manifold Pressure delay in seconds. double ManifoldPressureLag = 0.0; // Manifold Pressure delay in seconds.
double Displacement; // cubic inches double Displacement = 0.0; // cubic inches
double displacement_SI; // cubic meters double displacement_SI = 0.0; // cubic meters
double MaxHP; // horsepower double MaxHP = 0.0; // horsepower
double StaticFriction_HP; // horsepower: amount subtracted from final engine power double StaticFriction_HP = 0.0; // horsepower: amount subtracted from final engine power
double SparkFailDrop; // drop of power due to spark failure double SparkFailDrop = 0.0; // drop of power due to spark failure
double Cycles; // cycles/power stroke double Cycles = 0.0; // cycles/power stroke
double IdleRPM; // revolutions per minute double IdleRPM = 0.0; // revolutions per minute
double MaxRPM; // revolutions per minute double MaxRPM = 0.0; // revolutions per minute
double Bore; // inches double Bore = 0.0; // inches
double Stroke; // inches double Stroke = 0.0; // inches
double Cylinders; // number double Cylinders = 0.0; // number
double CylinderHeadMass; // kilograms double CylinderHeadMass = 0.0; // kilograms
double CompressionRatio; // number double CompressionRatio = 0.0; // number
double Z_airbox; // number representing intake impediance before the throttle double Z_airbox = 0.0; // number representing intake impediance before the throttle
double Z_throttle; // number representing slope of throttle impediance double Z_throttle = 0.0; // number representing slope of throttle impediance
double PeakMeanPistonSpeed_fps; // ft/sec speed where intake valves begin to choke. Typically 33-50 fps double PeakMeanPistonSpeed_fps = 0.0; // ft/sec speed where intake valves begin to choke. Typically 33-50 fps
double RatedMeanPistonSpeed_fps; // ft/sec derived from MaxRPM and stroke. double RatedMeanPistonSpeed_fps = 0.0; // ft/sec derived from MaxRPM and stroke.
double Ram_Air_Factor; // number double Ram_Air_Factor = 0.0; // number
double StarterTorque;// Peak Torque of the starter motor double StarterTorque = 0.0;// Peak Torque of the starter motor
double StarterRPM; // Peak RPM of the starter motor double StarterRPM = 0.0; // Peak RPM of the starter motor
double StarterGain; // control the torque of the starter motor. double StarterGain = 0.0; // control the torque of the starter motor.
int BoostSpeeds; // Number of super/turbocharger boost speeds - zero implies no turbo/supercharging. int BoostSpeeds = 0; // Number of super/turbocharger boost speeds - zero implies no turbo/supercharging.
int BoostSpeed; // The current boost-speed (zero-based). int BoostSpeed = 0; // The current boost-speed (zero-based).
bool Boosted; // Set true for boosted engine. bool Boosted = false; // Set true for boosted engine.
int BoostManual; // The raw value read in from the config file - should be 1 or 0 - see description below. int BoostManual = 0; // The raw value read in from the config file - should be 1 or 0 - see description below.
bool bBoostManual; // Set true if pilot must manually control the boost speed. bool bBoostManual = false; // Set true if pilot must manually control the boost speed.
int BoostOverride; // The raw value read in from the config file - should be 1 or 0 - see description below. int BoostOverride = 0; // The raw value read in from the config file - should be 1 or 0 - see description below.
bool bBoostOverride; // Set true if pilot override of the boost regulator was fitted. bool bBoostOverride = false; // Set true if pilot override of the boost regulator was fitted.
// (Typically called 'war emergency power'). // (Typically called 'war emergency power').
bool bTakeoffBoost; // Set true if extra takeoff / emergency boost above rated boost could be attained. bool bTakeoffBoost = false; // Set true if extra takeoff / emergency boost above rated boost could be attained.
// (Typically by extra throttle movement past a mechanical 'gate'). // (Typically by extra throttle movement past a mechanical 'gate').
double TakeoffBoost; // Sea-level takeoff boost in psi. (if fitted). double TakeoffBoost = 0.0; // Sea-level takeoff boost in psi. (if fitted).
double RatedBoost[FG_MAX_BOOST_SPEEDS]; // Sea-level rated boost in psi. double RatedBoost[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Sea-level rated boost in psi.
double RatedAltitude[FG_MAX_BOOST_SPEEDS]; // Altitude at which full boost is reached (boost regulation ends) double RatedAltitude[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Altitude at which full boost is reached (boost regulation ends)
// and at which power starts to fall with altitude [ft]. // and at which power starts to fall with altitude [ft].
double RatedRPM[FG_MAX_BOOST_SPEEDS]; // Engine speed at which the rated power for each boost speed is delivered [rpm]. double RatedRPM[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Engine speed at which the rated power for each boost speed is delivered [rpm].
double RatedPower[FG_MAX_BOOST_SPEEDS]; // Power at rated throttle position at rated altitude [HP]. double RatedPower[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Power at rated throttle position at rated altitude [HP].
double BoostSwitchAltitude[FG_MAX_BOOST_SPEEDS - 1]; // Altitude at which switchover (currently assumed automatic) double BoostSwitchAltitude[FG_MAX_BOOST_SPEEDS - 1] = {0.0, 0.0}; // Altitude at which switchover (currently assumed automatic)
// from one boost speed to next occurs [ft]. // from one boost speed to next occurs [ft].
double BoostSwitchPressure[FG_MAX_BOOST_SPEEDS - 1]; // Pressure at which boost speed switchover occurs [Pa] double BoostSwitchPressure[FG_MAX_BOOST_SPEEDS - 1] = {0.0, 0.0}; // Pressure at which boost speed switchover occurs [Pa]
double BoostMul[FG_MAX_BOOST_SPEEDS]; // Pressure multipier of unregulated supercharger double BoostMul[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Pressure multiplier of unregulated supercharger
double RatedMAP[FG_MAX_BOOST_SPEEDS]; // Rated manifold absolute pressure [Pa] (BCV clamp) double RatedMAP[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Rated manifold absolute pressure [Pa] (BCV clamp)
double TakeoffMAP[FG_MAX_BOOST_SPEEDS]; // Takeoff setting manifold absolute pressure [Pa] (BCV clamp) double TakeoffMAP[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Takeoff setting manifold absolute pressure [Pa] (BCV clamp)
double BoostSwitchHysteresis; // Pa. double BoostSwitchHysteresis = 0.0; // Pa.
double BoostLossFactor; // multiplier for HP consumed by the supercharger double BoostLossFactor = 0.0; // multiplier for HP consumed by the supercharger
double minMAP; // Pa double minMAP = 0.0; // Pa
double maxMAP; // Pa double maxMAP = 0.0; // Pa
double MAP; // Pa double MAP = 0.0; // Pa
double TMAP; // Pa - throttle manifold pressure e.g. before the supercharger boost double TMAP = 0.0; // Pa - throttle manifold pressure e.g. before the supercharger boost
double ISFC; // Indicated specific fuel consumption [lbs/horsepower*hour double ISFC = 0.0; // Indicated specific fuel consumption [lbs/horsepower*hour
// //
// Inputs (in addition to those in FGEngine). // Inputs (in addition to those in FGEngine).
// //
double p_amb; // Pascals double p_amb = 0.0; // Pascals
double p_ram; // Pascals double p_ram = 0.0; // Pascals
double T_amb; // degrees Kelvin double T_amb = 0.0; // degrees Kelvin
double RPM; // revolutions per minute double RPM = 0.0; // revolutions per minute
double IAS; // knots double IAS = 0.0; // knots
double Cooling_Factor; // normal double Cooling_Factor = 0.0; // normal
bool Magneto_Left; bool Magneto_Left = false;
bool Magneto_Right; bool Magneto_Right = false;
int Magnetos; int Magnetos = 0;
double Oil_Press_Relief_Valve; double Oil_Press_Relief_Valve = 0.0;
double Oil_Press_RPM_Max; double Oil_Press_RPM_Max = 0.0;
double Design_Oil_Temp; // degK double Design_Oil_Temp = 0.0; // degK
double Oil_Viscosity_Index; double Oil_Viscosity_Index = 0.0;
// //
// Outputs (in addition to those in FGEngine). // Outputs (in addition to those in FGEngine).
// //
double rho_air; double rho_air = 0.0;
double volumetric_efficiency; double volumetric_efficiency = 0.0;
double volumetric_efficiency_reduced; double volumetric_efficiency_reduced = 0.0;
//double map_coefficient; //double map_coefficient;
double m_dot_air; double m_dot_air = 0.0;
double v_dot_air; double v_dot_air = 0.0;
double equivalence_ratio; double equivalence_ratio = 0.0;
double m_dot_fuel; double m_dot_fuel = 0.0;
double HP; double HP = 0.0;
double BoostLossHP; double BoostLossHP = 0.0;
double combustion_efficiency; double combustion_efficiency = 0.0;
double ExhaustGasTemp_degK; double ExhaustGasTemp_degK = 0.0;
double EGT_degC; double EGT_degC = 0.0;
double ManifoldPressure_inHg; double ManifoldPressure_inHg = 0.0;
double CylinderHeadTemp_degK; double CylinderHeadTemp_degK = 0.0;
double OilPressure_psi; double OilPressure_psi = 0.0;
double OilTemp_degK; double OilTemp_degK = 0.0;
double MeanPistonSpeed_fps; double MeanPistonSpeed_fps = 0.0;
void Debug(int from); void Debug(int from);
}; };