]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/FGPropulsion.cpp
Merge branch 'next' of git@gitorious.org:fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / FGPropulsion.cpp
index ed066b26c3ecf2fce85daa4b7f6cefff87737166..bd3b09f0a2868906ec1bac6eb66ef2bb594e20b0 100644 (file)
@@ -45,19 +45,27 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGPropulsion.h"
-#include <models/propulsion/FGRocket.h>
-#include <models/propulsion/FGTurbine.h>
-#include <models/propulsion/FGPiston.h>
-#include <models/propulsion/FGElectric.h>
-#include <models/propulsion/FGTurboProp.h>
-#include <input_output/FGPropertyManager.h>
-#include <input_output/FGXMLParse.h>
-#include <math/FGColumnVector3.h>
+#include "models/FGFCS.h"
+#include "models/FGMassBalance.h"
+#include "models/propulsion/FGThruster.h"
+#include "models/propulsion/FGRocket.h"
+#include "models/propulsion/FGTurbine.h"
+#include "models/propulsion/FGPiston.h"
+#include "models/propulsion/FGElectric.h"
+#include "models/propulsion/FGTurboProp.h"
+#include "models/propulsion/FGTank.h"
+#include "input_output/FGPropertyManager.h"
+#include "input_output/FGXMLParse.h"
+#include "math/FGColumnVector3.h"
+#include <iostream>
 #include <sstream>
+#include <cstdlib>
+
+using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGPropulsion.cpp,v 1.39 2010/02/25 05:21:36 jberndt Exp $";
 static const char *IdHdr = ID_PROPULSION;
 
 extern short debug_lvl;
@@ -138,7 +146,9 @@ bool FGPropulsion::Run(void)
   if (FGModel::Run()) return true;
   if (FDMExec->Holding()) return false;
 
-  double dt = State->Getdt();
+  RunPreFunctions();
+
+  double dt = FDMExec->GetDeltaT();
 
   vForces.InitMatrix();
   vMoments.InitMatrix();
@@ -160,6 +170,8 @@ bool FGPropulsion::Run(void)
   if (refuel) DoRefuel( dt * rate );
   if (dump) DumpFuel( dt * rate );
 
+  RunPostFunctions();
+
   return false;
 }
 
@@ -255,6 +267,20 @@ bool FGPropulsion::Load(Element* el)
 
   FGModel::Load(el); // Perform base class Load.
 
+  // Process tank definitions first to establish the number of fuel tanks
+
+  Element* tank_element = el->FindElement("tank");
+  while (tank_element) {
+    Tanks.push_back(new FGTank(FDMExec, tank_element, numTanks));
+    if (Tanks.back()->GetType() == FGTank::ttFUEL) numFuelTanks++;
+    else if (Tanks.back()->GetType() == FGTank::ttOXIDIZER) numOxiTanks++;
+    else {cerr << "Unknown tank type specified." << endl; return false;}
+    numTanks++;
+    tank_element = el->FindNextElement("tank");
+  }
+  numSelectedFuelTanks = numFuelTanks;
+  numSelectedOxiTanks  = numOxiTanks;
+
   Element* engine_element = el->FindElement("engine");
   while (engine_element) {
     engine_filename = engine_element->GetAttributeValue("file");
@@ -303,20 +329,6 @@ bool FGPropulsion::Load(Element* el)
     ResetParser();
   }
 
-  // Process tank definitions
-
-  Element* tank_element = el->FindElement("tank");
-  while (tank_element) {
-    Tanks.push_back(new FGTank(FDMExec, tank_element, numTanks));
-    if (Tanks.back()->GetType() == FGTank::ttFUEL) numFuelTanks++;
-    else if (Tanks.back()->GetType() == FGTank::ttOXIDIZER) numOxiTanks++;
-    else {cerr << "Unknown tank type specified." << endl; return false;}
-    numTanks++;
-    tank_element = el->FindNextElement("tank");
-  }
-  numSelectedFuelTanks = numFuelTanks;
-  numSelectedOxiTanks  = numOxiTanks;
-
   CalculateTankInertias();
   if (!ThrottleAdded) FCS->AddThrottle(); // need to have at least one throttle
 
@@ -324,13 +336,14 @@ bool FGPropulsion::Load(Element* el)
   if (el->FindElement("dump-rate"))
     DumpRate = el->FindElementValueAsNumberConvertTo("dump-rate", "LBS/MIN");
 
+  FGModel::PostLoad(el);
 
   return true;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGPropulsion::FindEngineFullPathname(string engine_filename)
+string FGPropulsion::FindEngineFullPathname(const string& engine_filename)
 {
   string fullpath, localpath;
   string enginePath = FDMExec->GetEnginePath();
@@ -358,7 +371,7 @@ string FGPropulsion::FindEngineFullPathname(string engine_filename)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-ifstream* FGPropulsion::FindEngineFile(string engine_filename)
+ifstream* FGPropulsion::FindEngineFile(const string& engine_filename)
 {
   string fullpath, localpath;
   string enginePath = FDMExec->GetEnginePath();
@@ -383,7 +396,7 @@ ifstream* FGPropulsion::FindEngineFile(string engine_filename)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGPropulsion::GetPropulsionStrings(string delimeter)
+string FGPropulsion::GetPropulsionStrings(const string& delimiter)
 {
   unsigned int i;
 
@@ -393,13 +406,13 @@ string FGPropulsion::GetPropulsionStrings(string delimeter)
 
   for (i=0; i<Engines.size(); i++) {
     if (firstime)  firstime = false;
-    else           PropulsionStrings += delimeter;
+    else           PropulsionStrings += delimiter;
 
-    PropulsionStrings += Engines[i]->GetEngineLabels(delimeter);
+    PropulsionStrings += Engines[i]->GetEngineLabels(delimiter);
   }
   for (i=0; i<Tanks.size(); i++) {
-    if (Tanks[i]->GetType() == FGTank::ttFUEL) buf << delimeter << "Fuel Tank " << i;
-    else if (Tanks[i]->GetType() == FGTank::ttOXIDIZER) buf << delimeter << "Oxidizer Tank " << i;
+    if (Tanks[i]->GetType() == FGTank::ttFUEL) buf << delimiter << "Fuel Tank " << i;
+    else if (Tanks[i]->GetType() == FGTank::ttOXIDIZER) buf << delimiter << "Oxidizer Tank " << i;
   }
 
   return PropulsionStrings;
@@ -407,7 +420,7 @@ string FGPropulsion::GetPropulsionStrings(string delimeter)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGPropulsion::GetPropulsionValues(string delimeter)
+string FGPropulsion::GetPropulsionValues(const string& delimiter)
 {
   unsigned int i;
 
@@ -417,12 +430,12 @@ string FGPropulsion::GetPropulsionValues(string delimeter)
 
   for (i=0; i<Engines.size(); i++) {
     if (firstime)  firstime = false;
-    else           PropulsionValues += delimeter;
+    else           PropulsionValues += delimiter;
 
-    PropulsionValues += Engines[i]->GetEngineValues(delimeter);
+    PropulsionValues += Engines[i]->GetEngineValues(delimiter);
   }
   for (i=0; i<Tanks.size(); i++) {
-    buf << delimeter;
+    buf << delimiter;
     buf << Tanks[i]->GetContents();
   }