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