]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/FGAerodynamics.cpp
Merge branch 'master' of git://gitorious.org/fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / FGAerodynamics.cpp
index cc7fd0d561ab3d81ce4323a6493c740c02e890f0..d8c66df201305a18858220a6d5e635b3168ec251 100644 (file)
@@ -36,6 +36,10 @@ HISTORY
 INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+#include <cstdlib>
 #include <FGFDMExec.h>
 #include "FGAerodynamics.h"
 #include "FGPropagate.h"
@@ -44,9 +48,11 @@ INCLUDES
 #include "FGMassBalance.h"
 #include "input_output/FGPropertyManager.h"
 
+using namespace std;
+
 namespace JSBSim {
 
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGAerodynamics.cpp,v 1.31 2009/11/28 14:30:11 andgi Exp $";
 static const char *IdHdr = ID_AERODYNAMICS;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -102,9 +108,6 @@ FGAerodynamics::~FGAerodynamics()
 
   delete[] Coeff;
 
-  for (i=0; i<variables.size(); i++)
-    delete variables[i];
-
   delete AeroRPShift;
 
   Debug(1);
@@ -131,12 +134,14 @@ bool FGAerodynamics::InitModel(void)
 
 bool FGAerodynamics::Run(void)
 {
-  unsigned int axis_ctr, ctr, i;
+  unsigned int axis_ctr, ctr;
   double alpha, twovel;
 
   if (FGModel::Run()) return true;
   if (FDMExec->Holding()) return false; // if paused don't execute
 
+  RunPreFunctions();
+
   // calculate some oft-used quantities for speed
 
   twovel = 2*Auxiliary->GetVt();
@@ -167,13 +172,6 @@ bool FGAerodynamics::Run(void)
   vFw.InitMatrix();
   vFnative.InitMatrix();
 
-  // Tell the variable functions to cache their values, so while the aerodynamic
-  // functions are being calculated for each axis, these functions do not get
-  // calculated each time, but instead use the values that have already
-  // been calculated for this frame.
-
-  for (i=0; i<variables.size(); i++) variables[i]->cacheValue(true);
-
   for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
     for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
       vFnative(axis_ctr+1) += Coeff[axis_ctr][ctr]->GetValue();
@@ -227,6 +225,8 @@ bool FGAerodynamics::Run(void)
     }
   }
 
+  RunPostFunctions();
+
   return false;
 }
 
@@ -318,7 +318,7 @@ bool FGAerodynamics::Load(Element *element)
     document = element;
   }
 
-  FGModel::Load(element); // Perform base class Load
+  FGModel::Load(document); // Perform base class Pre-Load
 
   DetermineAxisSystem(); // Detemine if Lift/Side/Drag, etc. is used.
 
@@ -343,12 +343,6 @@ bool FGAerodynamics::Load(Element *element)
     AeroRPShift = new FGFunction(PropertyManager, function_element);
   }
 
-  function_element = document->FindElement("function");
-  while (function_element) {
-    variables.push_back( new FGFunction(PropertyManager, function_element) );
-    function_element = document->FindNextElement("function");
-  }
-
   axis_element = document->FindElement("axis");
   while (axis_element) {
     CoeffArray ca;
@@ -362,6 +356,8 @@ bool FGAerodynamics::Load(Element *element)
     axis_element = document->FindNextElement("axis");
   }
 
+  FGModel::PostLoad(document); // Perform base class Post-Load
+
   return true;
 }
 
@@ -415,21 +411,12 @@ void FGAerodynamics::DetermineAxisSystem()
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGAerodynamics::GetCoefficientStrings(string delimeter)
+string FGAerodynamics::GetCoefficientStrings(const string& delimeter) const
 {
   string CoeffStrings = "";
   bool firstime = true;
   unsigned int axis, sd;
 
-  for (sd = 0; sd < variables.size(); sd++) {
-    if (firstime) {
-      firstime = false;
-    } else {
-      CoeffStrings += delimeter;
-    }
-    CoeffStrings += variables[sd]->GetName();
-  }
-
   for (axis = 0; axis < 6; axis++) {
     for (sd = 0; sd < Coeff[axis].size(); sd++) {
       if (firstime) {
@@ -445,33 +432,18 @@ string FGAerodynamics::GetCoefficientStrings(string delimeter)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGAerodynamics::GetCoefficientValues(string delimeter)
+string FGAerodynamics::GetCoefficientValues(const string& delimeter) const
 {
-  string SDValues = "";
-  bool firstime = true;
-  unsigned int sd;
-
-  for (sd = 0; sd < variables.size(); sd++) {
-    if (firstime) {
-      firstime = false;
-    } else {
-      SDValues += delimeter;
-    }
-    SDValues += variables[sd]->GetValueAsString();
-  }
+  ostringstream buf;
 
   for (unsigned int axis = 0; axis < 6; axis++) {
     for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
-      if (firstime) {
-        firstime = false;
-      } else {
-        SDValues += delimeter;
-      }
-      SDValues += Coeff[axis][sd]->GetValueAsString();
+      if (buf.tellp() > 0) buf << delimeter;
+      buf << setw(9) << Coeff[axis][sd]->GetValue();
     }
   }
 
-  return SDValues;
+  return buf.str();
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%