46 #include "FGPropeller.h" 49 #include "input_output/FGXMLElement.h" 50 #include "math/FGColumnVector3.h" 56 IDENT(IdSrc,
"$Id: FGEngine.cpp,v 1.67 2015/09/27 09:54:21 bcoconni Exp $");
57 IDENT(IdHdr,ID_ENGINE);
63 FGEngine::FGEngine(
int engine_number,
struct Inputs& input)
64 : in(input), EngineNumber(engine_number)
68 EnginePitch = EngineYaw = 0.0;
91 Starved = Running = Cranking =
false;
98 Thruster->ResetToIC();
105 FuelFlowRate = SLFuelFlowMax*PctPower;
106 FuelExpended = FuelFlowRate*in.TotalDeltaT;
107 if (!Starved) FuelUsedLbs += FuelExpended;
113 unsigned int FGEngine::GetSourceTank(
unsigned int i)
const 115 if (i < SourceTanks.size()) {
116 return SourceTanks[i];
118 throw(
"No such source tank is available for this engine");
130 EnginePitch = orientation(ePitch);
131 EngineYaw = orientation (eYaw);
136 double FGEngine::GetThrust(
void)
const 138 return Thruster->GetThrust();
145 return Thruster->GetBodyForces();
152 return Thruster->GetMoments();
157 void FGEngine::LoadThrusterInputs()
159 Thruster->in.TotalDeltaT = in.TotalDeltaT;
160 Thruster->in.H_agl = in.H_agl;
161 Thruster->in.PQRi = in.PQRi;
162 Thruster->in.AeroPQR = in.AeroPQR;
163 Thruster->in.AeroUVW = in.AeroUVW;
164 Thruster->in.Density = in.Density;
165 Thruster->in.Pressure = in.Pressure;
166 Thruster->in.Soundspeed = in.Soundspeed;
167 Thruster->in.Alpha = in.alpha;
168 Thruster->in.Beta = in.beta;
169 Thruster->in.Vt = in.Vt;
178 Thruster =
new FGPropeller(exec, document, EngineNumber);
179 }
else if (thruster_element->
FindElement(
"nozzle")) {
181 Thruster =
new FGNozzle(exec, document, EngineNumber);
182 }
else if (thruster_element->
FindElement(
"rotor")) {
184 Thruster =
new FGRotor(exec, document, EngineNumber);
185 }
else if (thruster_element->
FindElement(
"direct")) {
187 Thruster =
new FGThruster(exec, document, EngineNumber);
189 cerr << thruster_element->
ReadFrom() <<
" Unknown thruster type" << endl;
190 throw(
"Failed to load the thruster");
208 FGModelFunctions::Load(engine_element, PropertyManager, to_string((
int)EngineNumber));
212 local_element = parent_element->
FindElement(
"location");
217 local_element = parent_element->
FindElement(
"orient");
225 local_element = parent_element->
FindElement(
"thruster");
228 LoadThruster(exec, local_element);
229 }
catch (std::string& str) {
230 throw(
"Error loading engine " + Name +
". " + str);
233 cerr <<
"No thruster definition supplied with engine definition." << endl;
239 local_element = parent_element->
FindElement(
"feed");
240 while (local_element) {
242 SourceTanks.push_back(tankID);
246 string property_name, base_property_name;
247 base_property_name = CreateIndexedPropertyName(
"propulsion/engine", EngineNumber);
249 property_name = base_property_name +
"/set-running";
250 PropertyManager->
Tie( property_name.c_str(),
this, &FGEngine::GetRunning, &FGEngine::SetRunning );
251 property_name = base_property_name +
"/thrust-lbs";
252 PropertyManager->
Tie( property_name.c_str(), Thruster, &FGThruster::GetThrust);
253 property_name = base_property_name +
"/fuel-flow-rate-pps";
254 PropertyManager->
Tie( property_name.c_str(),
this, &FGEngine::GetFuelFlowRate);
255 property_name = base_property_name +
"/fuel-flow-rate-gph";
256 PropertyManager->
Tie( property_name.c_str(),
this, &FGEngine::GetFuelFlowRateGPH);
257 property_name = base_property_name +
"/fuel-used-lbs";
258 PropertyManager->
Tie( property_name.c_str(),
this, &FGEngine::GetFuelUsedLbs);
260 PostLoad(engine_element, PropertyManager, to_string((
int)EngineNumber));
286 void FGEngine::Debug(
int from)
288 if (debug_lvl <= 0)
return;
295 cout <<
" X = " << Thruster->GetLocationX() << endl;
296 cout <<
" Y = " << Thruster->GetLocationY() << endl;
297 cout <<
" Z = " << Thruster->GetLocationZ() << endl;
298 cout <<
" Pitch = " << radtodeg*Thruster->GetAnglesToBody(ePitch) <<
" degrees" << endl;
299 cout <<
" Yaw = " << radtodeg*Thruster->GetAnglesToBody(eYaw) <<
" degrees" << endl;
302 if (debug_lvl & 2 ) {
303 if (from == 0) cout <<
"Instantiated: FGEngine" << endl;
304 if (from == 1) cout <<
"Destroyed: FGEngine" << endl;
306 if (debug_lvl & 4 ) {
308 if (debug_lvl & 8 ) {
310 if (debug_lvl & 16) {
312 if (debug_lvl & 64) {
314 cout << IdSrc << endl;
315 cout << IdHdr << endl;
Element * GetParent(void)
Returns a pointer to the parent of an element.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
FGPropeller models a propeller given the tabular data for Ct (thrust) and Cp (power), indexed by the advance ratio "J".
Element * FindElement(const std::string &el="")
Searches for a specified element.
Base class for specific thrusting devices such as propellers, nozzles, etc.
Models a helicopter rotor.
virtual double CalcFuelNeed(void)
The fuel need is calculated based on power levels and flow rate for that power level.
FGPropertyManager * GetPropertyManager(void)
Returns a pointer to the property manager object.
void Tie(const std::string &name, bool *pointer, bool useDefault=true)
Tie a property to an external bool variable.
double GetDataAsNumber(void)
Converts the element data to a number.
This class implements a 3 element column vector.
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
virtual void SetPlacement(const FGColumnVector3 &location, const FGColumnVector3 &orientation)
Sets engine placement information.
Encapsulates the JSBSim simulation executive.
FGColumnVector3 FindElementTripletConvertTo(const std::string &target_units)
Composes a 3-element column vector for the supplied location or orientation.
virtual void ResetToIC(void)
Resets the Engine parameters to the initial conditions.