42#include "FGPropeller.h"
45#include "input_output/FGXMLElement.h"
55FGEngine::FGEngine(
int engine_number,
struct Inputs& input)
56 : in(input), EngineNumber(engine_number)
77void FGEngine::ResetToIC(
void)
81 Starved = Running = Cranking =
false;
88 Thruster->ResetToIC();
93double FGEngine::CalcFuelNeed(
void)
95 FuelFlowRate = SLFuelFlowMax*PctPower;
96 FuelExpended = FuelFlowRate*in.TotalDeltaT;
97 if (!Starved) FuelUsedLbs += FuelExpended;
103unsigned int FGEngine::GetSourceTank(
unsigned int i)
const
105 if (i < SourceTanks.size()) {
106 return SourceTanks[i];
108 throw(
"No such source tank is available for this engine");
114double FGEngine::GetThrust(
void)
const
116 return Thruster->GetThrust();
121const FGColumnVector3& FGEngine::GetBodyForces(
void)
123 return Thruster->GetBodyForces();
128const FGColumnVector3& FGEngine::GetMoments(
void)
130 return Thruster->GetMoments();
135void FGEngine::LoadThrusterInputs()
137 Thruster->in.TotalDeltaT = in.TotalDeltaT;
138 Thruster->in.H_agl = in.H_agl;
139 Thruster->in.PQRi = in.PQRi;
140 Thruster->in.AeroPQR = in.AeroPQR;
141 Thruster->in.AeroUVW = in.AeroUVW;
142 Thruster->in.Density = in.Density;
143 Thruster->in.Pressure = in.Pressure;
144 Thruster->in.Soundspeed = in.Soundspeed;
145 Thruster->in.Alpha = in.alpha;
146 Thruster->in.Beta = in.beta;
147 Thruster->in.Vt = in.Vt;
152void FGEngine::LoadThruster(FGFDMExec* exec, Element *thruster_element)
154 if (thruster_element->FindElement(
"propeller")) {
155 Element *document = thruster_element->FindElement(
"propeller");
156 Thruster =
new FGPropeller(exec, document, EngineNumber);
157 }
else if (thruster_element->FindElement(
"nozzle")) {
158 Element *document = thruster_element->FindElement(
"nozzle");
159 Thruster =
new FGNozzle(exec, document, EngineNumber);
160 }
else if (thruster_element->FindElement(
"rotor")) {
161 Element *document = thruster_element->FindElement(
"rotor");
162 Thruster =
new FGRotor(exec, document, EngineNumber);
163 }
else if (thruster_element->FindElement(
"direct")) {
164 Element *document = thruster_element->FindElement(
"direct");
165 Thruster =
new FGThruster(exec, document, EngineNumber);
167 cerr << thruster_element->ReadFrom() <<
" Unknown thruster type" << endl;
168 throw(
"Failed to load the thruster");
176bool FGEngine::Load(FGFDMExec *exec, Element *engine_element)
178 Element* parent_element = engine_element->GetParent();
179 Element* local_element;
180 FGColumnVector3 location, orientation;
182 auto PropertyManager = exec->GetPropertyManager();
184 Name = engine_element->GetAttributeValue(
"name");
187 FGModelFunctions::Load(engine_element, exec, to_string((
int)EngineNumber));
191 local_element = parent_element->FindElement(
"location");
193 cerr << local_element->ReadFrom()
194 <<
"Engine location ignored, only thruster location is used." << endl;
196 local_element = parent_element->FindElement(
"orient");
198 cerr << local_element->ReadFrom()
199 <<
"Engine orientation ignored, only thruster orientation is used." << endl;
202 local_element = parent_element->FindElement(
"thruster");
205 LoadThruster(exec, local_element);
206 }
catch (std::string& str) {
207 throw(
"Error loading engine " + Name +
". " + str);
210 cerr <<
"No thruster definition supplied with engine definition." << endl;
216 local_element = parent_element->FindElement(
"feed");
217 while (local_element) {
218 int tankID = (int)local_element->GetDataAsNumber();
219 SourceTanks.push_back(tankID);
220 local_element = parent_element->FindNextElement(
"feed");
223 string property_name, base_property_name;
224 base_property_name = CreateIndexedPropertyName(
"propulsion/engine", EngineNumber);
226 property_name = base_property_name +
"/set-running";
227 PropertyManager->Tie( property_name.c_str(),
this, &FGEngine::GetRunning, &FGEngine::SetRunning );
228 property_name = base_property_name +
"/thrust-lbs";
229 PropertyManager->Tie( property_name.c_str(), Thruster, &FGThruster::GetThrust);
230 property_name = base_property_name +
"/fuel-flow-rate-pps";
231 PropertyManager->Tie( property_name.c_str(),
this, &FGEngine::GetFuelFlowRate);
232 property_name = base_property_name +
"/fuel-flow-rate-gph";
233 PropertyManager->Tie( property_name.c_str(),
this, &FGEngine::GetFuelFlowRateGPH);
234 property_name = base_property_name +
"/fuel-used-lbs";
235 PropertyManager->Tie( property_name.c_str(),
this, &FGEngine::GetFuelUsedLbs);
237 PostLoad(engine_element, exec, to_string((
int)EngineNumber));
263void FGEngine::Debug(
int from)
265 if (debug_lvl <= 0)
return;
272 cout <<
" X = " << Thruster->GetLocationX() << endl;
273 cout <<
" Y = " << Thruster->GetLocationY() << endl;
274 cout <<
" Z = " << Thruster->GetLocationZ() << endl;
275 cout <<
" Pitch = " << radtodeg*Thruster->GetAnglesToBody(ePitch) <<
" degrees" << endl;
276 cout <<
" Yaw = " << radtodeg*Thruster->GetAnglesToBody(eYaw) <<
" degrees" << endl;
279 if (debug_lvl & 2 ) {
280 if (from == 0) cout <<
"Instantiated: FGEngine" << endl;
281 if (from == 1) cout <<
"Destroyed: FGEngine" << endl;
283 if (debug_lvl & 4 ) {
285 if (debug_lvl & 8 ) {
287 if (debug_lvl & 16) {
289 if (debug_lvl & 64) {