]> git.mxchange.org Git - flightgear.git/blob - src/FDM/IO360.hxx
Fix a segfault on exit. Introduces a small memory leak if the instrument
[flightgear.git] / src / FDM / IO360.hxx
1 // Module:        10520c.c
2 //  Author:       Phil Schubert
3 //  Date started: 12/03/99
4 //  Purpose:      Models a Continental IO-520-M Engine
5 //  Called by:    FGSimExec
6 // 
7 //  Copyright (C) 1999  Philip L. Schubert (philings@ozemail.com.au)
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 // 02111-1307, USA.
23 //
24 // Further information about the GNU General Public License can also
25 // be found on the world wide web at http://www.gnu.org.
26 //
27 // FUNCTIONAL DESCRIPTION
28 // ------------------------------------------------------------------------
29 // Models a Continental IO-520-M engine. This engine is used in Cessna
30 // 210, 310, Beechcraft Bonaza and Baron C55. The equations used below
31 // were determined by a first and second order curve fits using Excel. 
32 // The data is from the Cessna Aircraft Corporations Engine and Flight
33 // Computer for C310. Part Number D3500-13
34 // 
35 // ARGUMENTS
36 // ------------------------------------------------------------------------
37 // 
38 // 
39 // HISTORY
40 // ------------------------------------------------------------------------
41 // 12/03/99     PLS     Created
42 // 07/03/99     PLS     Added Calculation of Density, and Prop_Torque
43 // 07/03/99     PLS     Restructered Variables to allow easier implementation
44 //                      of Classes
45 // 15/03/99     PLS     Added Oil Pressure, Oil Temperature and CH Temp
46 // ------------------------------------------------------------------------
47 // INCLUDES
48 // ------------------------------------------------------------------------
49
50 #ifndef _IO360_HXX_
51 #define _IO360_HXX_
52
53 #include <simgear/compiler.h>
54
55 #include <math.h>
56
57 #include STL_IOSTREAM
58 #include STL_FSTREAM
59
60 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
61 SG_USING_STD(ofstream);
62 #endif
63
64 class FGNewEngine {
65
66 private:
67
68     float CONVERT_HP_TO_WATTS;
69     float CONVERT_CUBIC_INCHES_TO_METERS_CUBED;
70
71     // Control and environment inputs
72     float IAS;
73     // 0 = Closed, 100 = Fully Open
74     float Throttle_Lever_Pos;
75     // 0 = Full Course 100 = Full Fine
76     float Propeller_Lever_Pos;
77     // 0 = Idle Cut Off 100 = Full Rich
78     float Mixture_Lever_Pos;
79
80     // Engine Specific Variables used by this program that have limits.
81     // Will be set in a parameter file to be read in to create
82     // and instance for each engine.
83     float Max_Manifold_Pressure;  //will be lower than ambient pressure for a non turbo/super charged engine due to losses through the throttle.  This is the sea level full throttle value.
84     float Min_Manifold_Pressure;  //Closed throttle valueat idle - governed by the idle bypass valve
85     float Max_RPM;
86     float Min_RPM;
87     float Max_Fuel_Flow;
88     float Mag_Derate_Percent;
89     float MaxHP;
90     float Gear_Ratio;
91
92     // Initialise Engine Variables used by this instance
93     float Percentage_Power;     // Power output as percentage of maximum power output
94     float Manifold_Pressure;    // Inches
95     float RPM;
96     float Fuel_Flow_gals_hr;    // gals/hour
97     float Torque;
98     float CHT;                  // Cylinder head temperature deg K
99     float CHT_degF;             // Ditto in deg Fahrenheit
100     float EGT;                  // Exhaust gas temperature deg K
101     float EGT_degF;             // Exhaust gas temperature deg Fahrenheit
102     float Mixture;
103     float Oil_Pressure;         // PSI
104     float Oil_Temp;             // Deg C
105     float HP;                   // Current power output in HP
106     float Power_SI;             // Current power output in Watts
107     float Torque_SI;            // Torque in Nm
108     float RPS;
109     float Torque_Imbalance;
110     bool  started;              //flag to indicate the engine is running self sustaining
111     bool  cranking;             //flag to indicate the engine is being cranked
112
113     //DCL
114     float volumetric_efficiency;
115     float combustion_efficiency;
116     float equivalence_ratio;
117     float v_dot_air;
118     float m_dot_air;
119     float m_dot_fuel;
120     float swept_volume;
121     float True_Manifold_Pressure;   //in Hg
122     float rho_air_manifold;
123     float R_air;
124     float p_amb_sea_level;      // Pascals
125     float p_amb;                // Pascals
126     float T_amb;                // deg Kelvin
127     float calorific_value_fuel;
128     float rho_air;
129     float rho_fuel;             // kg/m^3
130     float thi_sea_level;
131     float delta_T_exhaust;
132     float displacement;         // Engine displacement in cubic inches - to be read in from config file for each engine
133     float displacement_SI;      // ditto in meters cubed
134     float Cp_air;               // J/KgK
135     float Cp_fuel;              // J/KgK
136     float heat_capacity_exhaust;
137     float enthalpy_exhaust;
138     float Percentage_of_best_power_mixture_power;
139     float abstract_mixture;     //temporary hack
140     float engine_inertia;       //kg.m^2
141     float prop_inertia;         //kg.m^2
142     float angular_acceleration; //rad/s^2
143     double time_step;
144
145     // Propellor Variables
146     float FGProp1_Thrust;
147     float FGProp1_RPS;
148     float FGProp1_Blade_Angle;
149     float prop_torque;          // Nm
150     float prop_thrust;          // Newtons
151     float blade_length;         // meters
152     float forward_velocity;             // m/s
153     float angular_velocity_SI;          // rad/s
154     float prop_power_consumed_SI;       // Watts
155     float prop_power_consumed_HP;       // HP
156     double prop_diameter;               // meters
157     double J;                           // advance ratio - dimensionless
158     double Cp_20;                   // coefficient of power for 20 degree blade angle
159     double Cp_25;                   // coefficient of power for 25 degree blade angle
160     double Cp;                      // Our actual coefficient of power
161     double blade_angle;             // degrees
162     double neta_prop_20;
163     double neta_prop_25;
164     double neta_prop;               // prop efficiency
165
166     // Calculate Engine RPM based on Propellor Lever Position
167     float Calc_Engine_RPM(float Position);
168
169     // Calculate Manifold Pressure based on throttle lever position
170     // Note that this is simplistic and needs altering to include engine speed effects
171     float Calc_Manifold_Pressure( float LeverPosn, float MaxMan, float MinMan);
172
173     // Calculate combustion efficiency based on equivalence ratio
174     float Lookup_Combustion_Efficiency(float thi_actual);
175
176     // Calculate percentage of best power mixture power based on equivalence ratio
177     float Power_Mixture_Correlation(float thi_actual);
178
179     // Calculate exhaust gas temperature rise
180     float Calculate_Delta_T_Exhaust(void);
181
182     // Calculate Oil Temperature
183     float Calc_Oil_Temp (float Fuel_Flow, float Mixture, float IAS);
184     
185     // Calculate Oil Pressure
186     float Calc_Oil_Press (float Oil_Temp, float Engine_RPM);
187
188 public:
189
190     ofstream outfile;
191
192     //constructor
193     FGNewEngine() {
194 //      outfile.open("FGNewEngine.dat", ios::out|ios::trunc);
195     }
196
197     //destructor
198     ~FGNewEngine() {
199 //      outfile.close();
200     }
201
202     // set initial default values
203     void init(double dt);
204
205     // update the engine model based on current control positions
206     void update();
207
208     inline void set_IAS( float value ) { IAS = value; }
209     inline void set_Throttle_Lever_Pos( float value ) {
210         Throttle_Lever_Pos = value;
211     }
212     inline void set_Propeller_Lever_Pos( float value ) {
213         Propeller_Lever_Pos = value;
214     }
215     inline void set_Mixture_Lever_Pos( float value ) {
216         Mixture_Lever_Pos = value;
217     }
218     // set ambient pressure - takes pounds per square foot
219     inline void set_p_amb( float value ) { 
220         p_amb = value * 47.88026;
221         // Convert to Pascals
222     }
223     // set ambient temperature - takes degrees Rankine
224     inline void set_T_amb( float value ) { 
225         T_amb = value * 0.555555555556;
226         // Convert to degrees Kelvin
227     }
228
229     // accessors
230     inline float get_RPM() const { return RPM; }
231     inline float get_Manifold_Pressure() const { return True_Manifold_Pressure; }
232     inline float get_FGProp1_Thrust() const { return FGProp1_Thrust; }
233     inline float get_FGProp1_Blade_Angle() const { return FGProp1_Blade_Angle; }
234
235  //   inline float get_Rho() const { return Rho; }
236     inline float get_MaxHP() const { return MaxHP; }
237     inline float get_Percentage_Power() const { return Percentage_Power; }
238     inline float get_EGT() const { return EGT_degF; }    // Returns EGT in Fahrenheit
239     inline float get_CHT() const { return CHT_degF; }    // Note this returns CHT in Fahrenheit
240     inline float get_prop_thrust_SI() const { return prop_thrust; }
241     inline float get_prop_thrust_lbs() const { return (prop_thrust * 0.2248); }
242     inline float get_fuel_flow_gals_hr() const { return (Fuel_Flow_gals_hr); }
243 };
244
245
246 #endif // _IO360_HXX_