]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGCoefficient.cpp
- fixed fuel-need calculations
[flightgear.git] / src / FDM / JSBSim / FGCoefficient.cpp
index 4d36094ddc59d52e66ef918947d5b88442ca2d28..fa6973a65d9206ad762db94d224c67af38607a2c 100644 (file)
@@ -44,7 +44,6 @@ HISTORY
 INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#include "FGDefs.h"
 #include "FGCoefficient.h"
 #include "FGState.h"
 #include "FGFDMExec.h"
@@ -72,6 +71,9 @@ FGCoefficient::FGCoefficient( FGFDMExec* fdex )
   FDMExec = fdex;
   State   = FDMExec->GetState();
   Table   = 0;
+  
+  bias=0;
+  gain=1;
 
   if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
 }
@@ -86,20 +88,16 @@ FGCoefficient::~FGCoefficient()
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-bool FGCoefficient::Load(FGConfigFile *AC_cfg) {
+bool FGCoefficient::Load(FGConfigFile *AC_cfg)
+{
   int start, end, n;
-  string multparms, mult;
+  string mult;
 
   if (AC_cfg) {
     name = AC_cfg->GetValue("NAME");
     method = AC_cfg->GetValue("TYPE");
     AC_cfg->GetNextConfigLine();
     *AC_cfg >> description;
-    if (debug_lvl > 0) {
-      cout << "\n   " << highint << underon << name << underoff << normint << endl;
-      cout << "   " << description << endl;
-      cout << "   " << method << endl;
-    }
 
     if      (method == "EQUATION") type = EQUATION;
     else if (method == "TABLE")    type = TABLE;
@@ -109,26 +107,20 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg) {
 
     if (type == VECTOR || type == TABLE) {
       *AC_cfg >> rows;
-      if (debug_lvl > 0) cout << "   Rows: " << rows << " ";
       if (type == TABLE) {
         *AC_cfg >> columns;
-        if (debug_lvl > 0) cout << "Cols: " << columns;
         Table = new FGTable(rows, columns);
       } else {
         Table = new FGTable(rows);
       }
 
-      if (debug_lvl > 0) cout << endl;
-
-      *AC_cfg >> multparms;
-      LookupR = State->GetParameterIndex(multparms);
-      if (debug_lvl > 0) cout << "   Row indexing parameter: " << multparms << endl;
+      *AC_cfg >> multparmsRow;
+      LookupR = State->GetParameterIndex(multparmsRow);
     }
 
     if (type == TABLE) {
-      *AC_cfg >> multparms;
-      LookupC = State->GetParameterIndex(multparms);
-      if (debug_lvl > 0) cout << "   Column indexing parameter: " << multparms << endl;
+      *AC_cfg >> multparmsCol;
+      LookupC = State->GetParameterIndex(multparmsCol);
     }
 
     // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
@@ -141,7 +133,7 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg) {
     n     = multparms.find("|");
     start = 0;
 
-    if(multparms != "FG_NONE") {
+    if (multparms != string("FG_NONE")) {
       while (n < end && n >= 0) {
         n -= start;
         mult = multparms.substr(start,n);
@@ -153,23 +145,17 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg) {
       // End of non-dimensionalizing parameter read-in
     }
 
-    switch(type) {
-    case VALUE:
+    if (type == VALUE) {
       *AC_cfg >> StaticValue;
-      if (debug_lvl > 0) cout << "      Value = " << StaticValue << endl;
-      break;
-    case VECTOR:
-    case TABLE:
+    } else if (type == VECTOR || type == TABLE) {
       *Table << *AC_cfg;
-      if (debug_lvl > 0) Table->Print();
-      break;
-    case EQUATION:
-    case UNKNOWN:
+    } else {
       cerr << "Unimplemented coefficient type: " << type << endl;
-      break;
     }
+
     AC_cfg->GetNextConfigLine();
-    if (debug_lvl > 0) DisplayCoeffFactors();
+    FGCoefficient::Debug(2);
+
     return true;
   } else {
     return false;
@@ -180,12 +166,13 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg) {
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-float FGCoefficient::Value(float rVal, float cVal)
+double FGCoefficient::Value(double rVal, double cVal)
 {
-  float Value;
+  double Value;
   unsigned int midx;
 
-  SD = Value = Table->GetValue(rVal, cVal);
+  SD = Value = gain*Table->GetValue(rVal, cVal) + bias;
+  
 
   for (midx=0; midx < multipliers.size(); midx++) {
       Value *= State->GetParameter(multipliers[midx]);
@@ -195,11 +182,11 @@ float FGCoefficient::Value(float rVal, float cVal)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-float FGCoefficient::Value(float Val)
+double FGCoefficient::Value(double Val)
 {
-  float Value;
+  double Value;
 
-  SD = Value = Table->GetValue(Val);
+  SD = Value = gain*Table->GetValue(Val) + bias;
   
   for (unsigned int midx=0; midx < multipliers.size(); midx++) 
       Value *= State->GetParameter(multipliers[midx]);
@@ -209,11 +196,11 @@ float FGCoefficient::Value(float Val)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-float FGCoefficient::Value(void)
+double FGCoefficient::Value(void)
 {
-       float Value;
+       double Value;
 
-  SD = Value = StaticValue;
+  SD = Value = gain*StaticValue + bias;
 
   for (unsigned int midx=0; midx < multipliers.size(); midx++)
     Value *= State->GetParameter(multipliers[midx]);
@@ -223,9 +210,8 @@ float FGCoefficient::Value(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-float FGCoefficient::TotalValue()
+double FGCoefficient::TotalValue()
 {
-  
   switch(type) {
   case 0:
     return -1;
@@ -250,23 +236,16 @@ void FGCoefficient::DumpSD(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGCoefficient::Debug(void)
-{
-    //TODO: Add your source code here
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
 void FGCoefficient::DisplayCoeffFactors(void)
 {
   unsigned int i;
 
   cout << "   Non-Dimensionalized by: ";
 
-  ifmultipliers.size() == 0) {
+  if (multipliers.size() == 0) {
     cout << "none" << endl;
   } else {
-    for (i=0; i<multipliers.size();i++) 
+    for (i=0; i<multipliers.size(); i++) 
         cout << FDMExec->GetState()->paramdef[multipliers[i]];
   }
   cout << endl;
@@ -274,7 +253,8 @@ void FGCoefficient::DisplayCoeffFactors(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGCoefficient::GetCoefficientValues(void) {
+string FGCoefficient::GetCoefficientValues(void)
+{
   char buffer[10];
   string value;
 
@@ -284,4 +264,71 @@ string FGCoefficient::GetCoefficientValues(void) {
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+//    The bitmasked value choices are as follows:
+//    unset: In this case (the default) JSBSim would only print
+//       out the normally expected messages, essentially echoing
+//       the config files as they are read. If the environment
+//       variable is not set, debug_lvl is set to 1 internally
+//    0: This requests JSBSim not to output any messages
+//       whatsoever.
+//    1: This value explicity requests the normal JSBSim
+//       startup messages
+//    2: This value asks for a message to be printed out when
+//       a class is instantiated
+//    4: When this value is set, a message is displayed when a
+//       FGModel object executes its Run() method
+//    8: When this value is set, various runtime state variables
+//       are printed out periodically
+//    16: When set various parameters are sanity checked and
+//       a message is printed out when they go out of bounds
+
+void FGCoefficient::Debug(int from)
+{
+  if (debug_lvl <= 0) return;
+
+  if (debug_lvl & 1) { // Standard console startup message output
+    
+    if (from == 2) { // Loading
+      cout << "\n   " << highint << underon << name << underoff << normint << endl;
+      cout << "   " << description << endl;
+      cout << "   " << method << endl;
+
+      if (type == VECTOR || type == TABLE) {
+        cout << "   Rows: " << rows << " ";
+        if (type == TABLE) {
+          cout << "Cols: " << columns;
+        }
+        cout << endl << "   Row indexing parameter: " << multparmsRow << endl;
+      }
+
+      if (type == TABLE) {
+        cout << "   Column indexing parameter: " << multparmsCol << endl;
+      }
+
+      if (type == VALUE) {
+        cout << "      Value = " << StaticValue << endl;
+      } else if (type == VECTOR || type == TABLE) {
+        Table->Print();
+      }
+
+      DisplayCoeffFactors();
+    }
+  }
+  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
+    if (from == 0) cout << "Instantiated: FGCoefficient" << endl;
+    if (from == 1) cout << "Destroyed:    FGCoefficient" << endl;
+  }
+  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
+  }
+  if (debug_lvl & 8 ) { // Runtime state variables
+  }
+  if (debug_lvl & 16) { // Sanity checking
+  }
+  if (debug_lvl & 64) {
+    if (from == 0) { // Constructor
+      cout << IdSrc << endl;
+      cout << IdHdr << endl;
+    }
+  }
+}