]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.cpp
Initialize some variables
[flightgear.git] / src / FDM / JSBSim / FGEngine.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  
3  Module:       FGEngine.cpp
4  Author:       Jon Berndt
5  Date started: 01/21/99
6  Called by:    FGAircraft
7  
8  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
9  
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14  
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19  
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23  
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26  
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29 See header file.
30  
31 HISTORY
32 --------------------------------------------------------------------------------
33 01/21/99   JSB   Created
34 09/03/99   JSB   Changed Rocket thrust equation to correct -= Thrust instead of
35                  += Thrust (thanks to Tony Peden)
36  
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #ifdef FGFS
42 #  include <simgear/compiler.h>
43 #  ifdef SG_HAVE_STD_INCLUDES
44 #    include <fstream>
45 #  else
46 #    include <fstream.h>
47 #  endif
48 #else
49 #  if defined(sgi) && !defined(__GNUC__)
50 #    include <fstream.h>
51 #  else
52 #    include <fstream>
53 #  endif
54 #endif
55
56 #include "FGEngine.h"
57 #include "FGTank.h"
58
59 namespace JSBSim {
60
61 static const char *IdSrc = "$Id$";
62 static const char *IdHdr = ID_ENGINE;
63
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 CLASS IMPLEMENTATION
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67
68
69 FGEngine::FGEngine(FGFDMExec* exec)
70   : Name(""),
71     Type(etUnknown),
72     X(0), Y(0), Z(0),
73     EnginePitch(0), EngineYaw(0),
74     SLFuelFlowMax(0), SLOxiFlowMax(0),
75     MaxThrottle(1.0), MinThrottle(0.0),
76     Thrust(0.0),
77     Throttle(0.0),
78     Mixture(1.0),
79     Magnetos(0),
80     Starter(false),
81     FuelNeed(0.0), OxidizerNeed(0.0),
82     Starved(false), Flameout(false), Running(false), Cranking(false),
83     Augmentation(false), Injection(false), Ignition(false),
84     Reversed(false), Cutoff(true), Nitrous(false),
85     PctPower(0.0),
86     EngineNumber(-1),
87     TrimMode(false),
88     FuelFlow_gph(0.0),
89     ManifoldPressure_inHg(0.0),
90     ExhaustGasTemp_degK(0.0),
91     CylinderHeadTemp_degK(0.0),
92     OilPressure_psi(0.0),
93     OilTemp_degK(0.0),
94     FuelFlow_pph(0.0),
95     N1(0.0), N2(0.0), EGT_degC(0.0),
96     InletPosition(0.0), NozzlePosition(0.0),
97     FDMExec(exec),
98     State(FDMExec->GetState()),
99     Atmosphere(FDMExec->GetAtmosphere()),
100     FCS(FDMExec->GetFCS()),
101     Propulsion(FDMExec->GetPropulsion()),
102     Aircraft(FDMExec->GetAircraft()),
103     Translation(FDMExec->GetTranslation()),
104     Rotation(FDMExec->GetRotation()),
105     Position(FDMExec->GetPosition()),
106     Auxiliary(FDMExec->GetAuxiliary()),
107     Output(FDMExec->GetOutput())
108 {
109   Debug(0);
110 }
111
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114 FGEngine::~FGEngine()
115 {
116   Debug(1);
117 }
118
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 // This base class function should be called from within the
121 // derived class' Calculate() function before any other calculations are done.
122 // This base class method removes fuel from the fuel tanks as appropriate,
123 // and sets the starved flag if necessary.
124
125 void FGEngine::ConsumeFuel(void)
126 {
127   double Fshortage, Oshortage;
128   FGTank* Tank;
129
130   if (TrimMode) return;
131   Fshortage = Oshortage = 0.0;
132   for (unsigned int i=0; i<SourceTanks.size(); i++) {
133     Tank = Propulsion->GetTank(i);
134     if (Tank->GetType() == FGTank::ttFUEL) {
135       Fshortage += Tank->Reduce(CalcFuelNeed()/Propulsion->GetnumSelectedFuelTanks());
136     } else {
137       Oshortage += Tank->Reduce(CalcOxidizerNeed()/Propulsion->GetnumSelectedOxiTanks());
138     }
139   }
140
141   if (Fshortage < 0.00 || Oshortage < 0.00) Starved = true;
142   else Starved = false;
143 }
144
145 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146
147 double FGEngine::CalcFuelNeed(void) {
148   FuelNeed = SLFuelFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();
149   return FuelNeed;
150 }
151
152 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153
154 double FGEngine::CalcOxidizerNeed(void) {
155   OxidizerNeed = SLOxiFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();
156   return OxidizerNeed;
157 }
158
159 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160
161 void FGEngine::SetPlacement(double x, double y, double z, double pitch, double yaw) {
162   X = x;
163   Y = y;
164   Z = z;
165   EnginePitch = pitch;
166   EngineYaw = yaw;
167 }
168
169 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170
171 void FGEngine::AddFeedTank(int tkID)
172 {
173   SourceTanks.push_back(tkID);
174 }
175
176 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 //    The bitmasked value choices are as follows:
178 //    unset: In this case (the default) JSBSim would only print
179 //       out the normally expected messages, essentially echoing
180 //       the config files as they are read. If the environment
181 //       variable is not set, debug_lvl is set to 1 internally
182 //    0: This requests JSBSim not to output any messages
183 //       whatsoever.
184 //    1: This value explicity requests the normal JSBSim
185 //       startup messages
186 //    2: This value asks for a message to be printed out when
187 //       a class is instantiated
188 //    4: When this value is set, a message is displayed when a
189 //       FGModel object executes its Run() method
190 //    8: When this value is set, various runtime state variables
191 //       are printed out periodically
192 //    16: When set various parameters are sanity checked and
193 //       a message is printed out when they go out of bounds
194
195 void FGEngine::Debug(int from)
196 {
197   if (debug_lvl <= 0) return;
198
199   if (debug_lvl & 1) { // Standard console startup message output
200     if (from == 0) { // Constructor
201
202     }
203   }
204   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
205     if (from == 0) cout << "Instantiated: FGEngine" << endl;
206     if (from == 1) cout << "Destroyed:    FGEngine" << endl;
207   }
208   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
209   }
210   if (debug_lvl & 8 ) { // Runtime state variables
211   }
212   if (debug_lvl & 16) { // Sanity checking
213   }
214   if (debug_lvl & 64) {
215     if (from == 0) { // Constructor
216       cout << IdSrc << endl;
217       cout << IdHdr << endl;
218     }
219   }
220 }
221 }