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