]> git.mxchange.org Git - flightgear.git/blob - JSBsim/FGEngine.cpp
Added initial support for native SGI compilers.
[flightgear.git] / 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
35 ********************************************************************************
36 INCLUDES
37 *******************************************************************************/
38
39 #include <fstream.h>
40
41 #include "FGEngine.h"
42 #include "FGState.h"
43 #include "FGFDMExec.h"
44 #include "FGAtmosphere.h"
45 #include "FGFCS.h"
46 #include "FGAircraft.h"
47 #include "FGTranslation.h"
48 #include "FGRotation.h"
49 #include "FGPosition.h"
50 #include "FGAuxiliary.h"
51 #include "FGOutput.h"
52
53 /*******************************************************************************
54 ************************************ CODE **************************************
55 *******************************************************************************/
56
57
58 FGEngine::FGEngine(FGFDMExec* fdex, string enginePath, string engineName, 
59                    int num)
60 {
61   string fullpath;
62   string tag;
63
64   FDMExec = fdex;
65
66   State       = FDMExec->GetState();
67   Atmosphere  = FDMExec->GetAtmosphere();
68   FCS         = FDMExec->GetFCS();
69   Aircraft    = FDMExec->GetAircraft();
70   Translation = FDMExec->GetTranslation();
71   Rotation    = FDMExec->GetRotation();
72   Position    = FDMExec->GetPosition();
73   Auxiliary   = FDMExec->GetAuxiliary();
74   Output      = FDMExec->GetOutput();
75
76   Name = engineName;
77   fullpath = enginePath + "/" + engineName + ".dat";
78   ifstream enginefile(fullpath.c_str());
79
80   if (enginefile) {
81     enginefile >> tag;
82
83     if      (tag == "ROCKET")    Type = etRocket;
84     else if (tag == "PISTON")    Type = etPiston;
85     else if (tag == "TURBOPROP") Type = etTurboProp;
86     else if (tag == "TURBOJET")  Type = etTurboJet;
87     else                         Type = etUnknown;
88
89     enginefile >> X;
90     enginefile >> Y;
91     enginefile >> Z;
92     enginefile >> SLThrustMax;
93     enginefile >> VacThrustMax;
94     enginefile >> MaxThrottle;
95     enginefile >> MinThrottle;
96     enginefile >> SLFuelFlowMax;
97     if (Type == 1)
98       enginefile >> SLOxiFlowMax;
99     enginefile.close();
100   } else {
101     cerr << "Unable to open engine definition file " << engineName << endl;
102   }
103
104   EngineNumber = num;
105   Thrust = 0.0;
106   Starved = Flameout = false;
107 }
108
109
110 FGEngine::~FGEngine(void)
111 {
112 }
113
114
115 float FGEngine::CalcRocketThrust(void)
116 {
117   float lastThrust;
118
119   Throttle = FCS->GetThrottle(EngineNumber);
120   lastThrust = Thrust;                 // last actual thrust
121
122   if (Throttle < MinThrottle || Starved) {
123     PctPower = Thrust = 0.0; // desired thrust
124     Flameout = true;
125   } else {
126     PctPower = Throttle / MaxThrottle;
127     Thrust = PctPower*((1.0 - Atmosphere->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) +
128                                SLThrustMax); // desired thrust
129     Flameout = false;
130   }
131
132   Thrust += 0.8*(Thrust - lastThrust); // actual thrust
133
134   return Thrust;
135 }
136
137
138 float FGEngine::CalcPistonThrust(void)
139 {
140   return Thrust;
141 }
142
143
144 float FGEngine::CalcThrust(void)
145 {
146   switch(Type) {
147   case etRocket:
148     return CalcRocketThrust();
149     // break;
150   case etPiston:
151     return CalcPistonThrust();
152     // break;
153   default:
154     return 9999.0;
155     // break;
156   }
157 }
158
159 float FGEngine::CalcFuelNeed() {
160   FuelNeed = SLFuelFlowMax*PctPower;
161   return FuelNeed;
162 }
163
164
165 float FGEngine::CalcOxidizerNeed() {
166   OxidizerNeed = SLOxiFlowMax*PctPower;
167   return OxidizerNeed;
168 }
169