]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.cpp
fe0aca43b4f50aad149af8fa625d96868fec80ec
[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 static const char *IdSrc = "$Id$";
60 static const char *IdHdr = ID_ENGINE;
61
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 CLASS IMPLEMENTATION
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65
66
67 FGEngine::FGEngine(FGFDMExec* exec) {
68   FDMExec     = exec;
69   State       = FDMExec->GetState();
70   Atmosphere  = FDMExec->GetAtmosphere();
71   FCS         = FDMExec->GetFCS();
72   Propulsion  = FDMExec->GetPropulsion();
73   Aircraft    = FDMExec->GetAircraft();
74   Translation = FDMExec->GetTranslation();
75   Rotation    = FDMExec->GetRotation();
76   Position    = FDMExec->GetPosition();
77   Auxiliary   = FDMExec->GetAuxiliary();
78   Output      = FDMExec->GetOutput();
79
80   Mixture = 1.0;                // FIXME: get actual value\r
81   Thrust = PctPower = 0.0;
82   Starved = Flameout = false;
83   Running = true;
84
85   if (debug_lvl & 2) cout << "Instantiated: FGEngine" << endl;
86   TrimMode = false;
87 }
88
89 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90
91 FGEngine::~FGEngine()
92 {
93   if (debug_lvl & 2) cout << "Destroyed:    FGEngine" << endl;
94 }
95
96 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 // This base class function should be called from within the
98 // derived class' Calculate() function before any other calculations are done.
99 // This base class method removes fuel from the fuel tanks as appropriate,
100 // and sets the starved flag if necessary.
101
102 void FGEngine::ConsumeFuel(void) {
103   float Fshortage, Oshortage;
104   FGTank* Tank;
105
106   if (TrimMode) return;
107
108   Fshortage = Oshortage = 0.0;
109   for (unsigned int i=0; i<SourceTanks.size(); i++) {
110     Tank = Propulsion->GetTank(i);
111     if (Tank->GetType() == FGTank::ttFUEL) {
112       Fshortage += Tank->Reduce(CalcFuelNeed()/Propulsion->GetnumSelectedFuelTanks());
113     } else {
114       Oshortage += Tank->Reduce(CalcOxidizerNeed()/Propulsion->GetnumSelectedOxiTanks());
115     }
116   }
117
118   if (Fshortage < 0.00 || Oshortage < 0.00) Starved = true;
119   else Starved = false;
120 }
121
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123
124 float FGEngine::CalcFuelNeed(void) {
125   FuelNeed = SLFuelFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();
126   return FuelNeed;
127 }
128
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130
131 float FGEngine::CalcOxidizerNeed(void) {
132   OxidizerNeed = SLOxiFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();
133   return OxidizerNeed;
134 }
135
136 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137
138 void FGEngine::SetPlacement(float x, float y, float z, float pitch, float yaw) {
139   X = x;
140   Y = y;
141   Z = z;
142   EnginePitch = pitch;
143   EngineYaw = yaw;
144 }
145
146 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147
148 void FGEngine::AddFeedTank(int tkID)
149 {
150   SourceTanks.push_back(tkID);
151 }
152
153 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154
155 void FGEngine::Debug(void)
156 {
157     //TODO: Add your source code here
158 }
159