]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGCoefficient.cpp
Fix stall widths for the "auxilliary" (reverse flow) stalls so they
[flightgear.git] / src / FDM / JSBSim / FGCoefficient.cpp
index 801571f4f3ef1a73c126d8b01463a092ae132a6c..c003edd3d3be3b1f81465a3d7a16faef65d069ec 100644 (file)
@@ -44,13 +44,15 @@ HISTORY
 INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+#include <stdio.h>
+
 #include "FGCoefficient.h"
 #include "FGState.h"
 #include "FGFDMExec.h"
 #include "FGPropertyManager.h"
 
 #ifndef FGFS
-#  if defined(sgi) && !defined(__GNUC__)
+#  if defined(sgi) && !defined(__GNUC__) && (_COMPILER_VERSION < 740)
 #    include <iomanip.h>
 #  else
 #    include <iomanip>
@@ -59,6 +61,8 @@ INCLUDES
 #  include STL_IOMANIP
 #endif
 
+namespace JSBSim {
+
 static const char *IdSrc = "$Id$";
 static const char *IdHdr = ID_COEFFICIENT;
 
@@ -71,18 +75,20 @@ FGCoefficient::FGCoefficient( FGFDMExec* fdex )
   FDMExec = fdex;
   State   = FDMExec->GetState();
   Table   = 0;
-  
+  IsFactor = false;
+
   PropertyManager = FDMExec->GetPropertyManager();
-  
+
   Table = (FGTable*)0L;
   LookupR = LookupC = 0;
   numInstances = 0;
-  rows = columns = 0;
+  rows = columns = tables = 0;
 
   StaticValue  = 0.0;
   totalValue   = 0.0;
   bias = 0.0;
   gain = 1.0;
+  SD = 0.0;
 
   filename.erase();
   description.erase();
@@ -108,69 +114,80 @@ FGCoefficient::~FGCoefficient()
 bool FGCoefficient::Load(FGConfigFile *AC_cfg)
 {
   int start, end, n;
-  string mult,prop;
+  string mult;
 
   if (AC_cfg) {
     name = AC_cfg->GetValue("NAME");
     method = AC_cfg->GetValue("TYPE");
     AC_cfg->GetNextConfigLine();
     *AC_cfg >> description;
-
     if      (method == "EQUATION") type = EQUATION;
     else if (method == "TABLE")    type = TABLE;
+    else if (method == "TABLE3D")  type = TABLE3D;
     else if (method == "VECTOR")   type = VECTOR;
     else if (method == "VALUE")    type = VALUE;
     else                           type = UNKNOWN;
 
-    if (type == VECTOR || type == TABLE) {
-      *AC_cfg >> rows;
-      if (type == TABLE) {
-        *AC_cfg >> columns;
+    if (type == VECTOR || type == TABLE || type == TABLE3D) {
+
+      if (type == TABLE3D) {
+        *AC_cfg >> rows >> columns >> tables;
+        Table = new FGTable(rows, columns, tables);
+        *AC_cfg >> multparmsRow >> multparmsCol >> multparmsTable;
+        LookupR = PropertyManager->GetNode( multparmsRow );
+        LookupC = PropertyManager->GetNode( multparmsCol );
+        LookupT = PropertyManager->GetNode( multparmsTable );
+      } else if (type == TABLE) {
+        *AC_cfg >> rows >> columns;
         Table = new FGTable(rows, columns);
+        *AC_cfg >> multparmsRow >> multparmsCol;
+        LookupR = PropertyManager->GetNode( multparmsRow );
+        LookupC = PropertyManager->GetNode( multparmsCol );
       } else {
+        *AC_cfg >> rows;
         Table = new FGTable(rows);
+        *AC_cfg >> multparmsRow;
+        LookupR = PropertyManager->GetNode( multparmsRow );
       }
-
-      *AC_cfg >> multparmsRow;
-      prop = State->GetPropertyName( multparmsRow );
-      LookupR = PropertyManager->GetNode( prop );
     }
 
-    if (type == TABLE) {
-      *AC_cfg >> multparmsCol;
-      prop = State->GetPropertyName( multparmsCol );
-
-      LookupC = PropertyManager->GetNode( prop );
-    }
-
-    // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
-    // where each non-dimensionalizing parameter for this coefficient is
+    // Here, read in the line of the form:
+    // {property1} | {property2} | {property3}
+    // where each non-dimensionalizing property for this coefficient is
     // separated by a | character
 
-    *AC_cfg >> multparms;
+    string line=AC_cfg->GetCurrentLine();
+    unsigned j=0;
+    char tmp[255];
+    for(unsigned i=0;i<line.length(); i++ ) {
+      if( !isspace(line[i]) ) {
+        tmp[j]=line[i];
+        j++;
+      }
+    }
+    tmp[j]='\0'; multparms=tmp;
+    end = multparms.length();
 
-    end   = multparms.length();
-    n     = multparms.find("|");
+    n = multparms.find("|");
+    if (n == string::npos) n = end;
     start = 0;
-
-    if (multparms != string("FG_NONE")) {
-      while (n < end && n >= 0) {
+    if (multparms != string("none")) {
+      while (n < end && n != string::npos) {
         n -= start;
         mult = multparms.substr(start,n);
-        prop= State->GetPropertyName( mult );
-        multipliers.push_back( PropertyManager->GetNode(prop) );
+        multipliers.push_back( resolveSymbol( mult ) );
         start += n+1;
         n = multparms.find("|",start);
       }
-      prop=State->GetPropertyName( multparms.substr(start,n) );
       mult = multparms.substr(start,n);
-      multipliers.push_back( PropertyManager->GetNode(prop) );
+      multipliers.push_back( resolveSymbol( mult ) );
       // End of non-dimensionalizing parameter read-in
     }
+    AC_cfg->GetNextConfigLine();
 
     if (type == VALUE) {
       *AC_cfg >> StaticValue;
-    } else if (type == VECTOR || type == TABLE) {
+    } else if (type == VECTOR || type == TABLE || type == TABLE3D) {
       *Table << *AC_cfg;
     } else {
       cerr << "Unimplemented coefficient type: " << type << endl;
@@ -182,11 +199,26 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg)
     return true;
   } else {
     return false;
-  }  
+  }
 }
 
 
 
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGCoefficient::Value(double rVal, double cVal, double tVal)
+{
+  double Value;
+  unsigned int midx;
+
+  SD = Value = gain*Table->GetValue(rVal, cVal, tVal) + bias;
+
+  for (midx=0; midx < multipliers.size(); midx++) {
+      Value *= multipliers[midx]->getDoubleValue();
+  }
+  return Value;
+}
+
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 double FGCoefficient::Value(double rVal, double cVal)
@@ -209,10 +241,10 @@ double FGCoefficient::Value(double Val)
   double Value;
 
   SD = Value = gain*Table->GetValue(Val) + bias;
-  
-  for (unsigned int midx=0; midx < multipliers.size(); midx++) 
+
+  for (unsigned int midx=0; midx < multipliers.size(); midx++)
       Value *= multipliers[midx]->getDoubleValue();
-  
+
   return Value;
 }
 
@@ -220,7 +252,7 @@ double FGCoefficient::Value(double Val)
 
 double FGCoefficient::Value(void)
 {
-       double Value;
+  double Value;
 
   SD = Value = gain*StaticValue + bias;
 
@@ -250,7 +282,13 @@ double FGCoefficient::TotalValue(void)
 
   case TABLE:
     totalValue = Value( LookupR->getDoubleValue(),
-                      LookupC->getDoubleValue() );
+                        LookupC->getDoubleValue() );
+    break;
+
+  case TABLE3D:
+    totalValue = Value( LookupR->getDoubleValue(),
+                        LookupC->getDoubleValue(),
+                        LookupT->getDoubleValue() );
     break;
 
   case EQUATION:
@@ -271,7 +309,7 @@ void FGCoefficient::DisplayCoeffFactors(void)
   if (multipliers.size() == 0) {
     cout << "none" << endl;
   } else {
-    for (i=0; i<multipliers.size(); i++) 
+    for (i=0; i<multipliers.size(); i++)
       cout << multipliers[i]->getName() << "  ";
   }
   cout << endl;
@@ -281,7 +319,7 @@ void FGCoefficient::DisplayCoeffFactors(void)
 
 string FGCoefficient::GetSDstring(void)
 {
-  char buffer[10];
+  char buffer[20];
   string value;
 
   sprintf(buffer,"%9.6f",SD);
@@ -295,29 +333,29 @@ void FGCoefficient::bind(FGPropertyManager *parent)
 {
   string mult;
   unsigned i;
-  
-  node=parent->GetNode(name,true);
-  
+
+  node = parent->GetNode(name,true);
+
   node->SetString("description",description);
   if (LookupR) node->SetString("row-parm",LookupR->getName() );
   if (LookupC) node->SetString("column-parm",LookupC->getName() );
-  
+
   mult="";
-  if (multipliers.size() == 0) 
+  if (multipliers.size() == 0)
     mult="none";
-    
+
   for (i=0; i<multipliers.size(); i++) {
       mult += multipliers[i]->getName();
-      if ( i < multipliers.size()-1 ) mult += " "; 
+      if ( i < multipliers.size()-1 ) mult += " ";
   }
   node->SetString("multipliers",mult);
-  
+
   node->Tie("SD-norm",this,&FGCoefficient::GetSD );
   node->Tie("value-lbs",this,&FGCoefficient::GetValue );
-  
+
   node->Tie("bias", this, &FGCoefficient::getBias,
                           &FGCoefficient::setBias );
-                          
+
   node->Tie("gain", this, &FGCoefficient::getGain,
                           &FGCoefficient::setGain );
 
@@ -328,11 +366,91 @@ void FGCoefficient::bind(FGPropertyManager *parent)
 void FGCoefficient::unbind(void)
 {
   node->Untie("SD-norm");
-  node->Untie("value-lbs"); 
-  node->Untie("bias");  
+  node->Untie("value-lbs");
+  node->Untie("bias");
   node->Untie("gain");
 }
-  
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+FGPropertyManager* FGCoefficient::resolveSymbol(string name)
+{
+  FGPropertyManager* tmpn;
+
+  tmpn = PropertyManager->GetNode(name,false);
+  if ( !tmpn ) {
+    cerr << "Coefficient multipliers cannot create properties, check spelling?" << endl;
+    exit(1);
+  }
+  return tmpn;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGCoefficient::convert(string prop)
+{
+  if (IsFactor)
+    cout << "            <function name=\"aero/function/" << name << "\">" << endl;
+  else
+    cout << "            <function name=\"aero/coefficient/" << name << "\">" << endl;
+
+  cout << "                <description>" << description << "</description>" << endl;
+  cout << "                <product>" << endl;
+
+  for (int i=0; i<multipliers.size(); i++)
+    cout << "                    <property>" << (multipliers[i]->GetFullyQualifiedName()).substr(12) << "</property>" << endl;
+
+  if (!prop.empty())
+    cout << "                    <property>aero/function/" << prop << "</property>" << endl;
+
+  switch (type) {
+  case VALUE:
+  cout << "                    <value>" << StaticValue << "</value>" << endl;
+    break;
+
+  case VECTOR:
+    cout << "                      <table>" << endl;
+    cout << "                          <independentVar>" << (LookupR->GetFullyQualifiedName()).substr(12) << "</independentVar>" << endl;
+    cout << "                          <tableData>" << endl;
+    Table->Print(30);
+    cout << "                          </tableData>" << endl;
+    cout << "                      </table>" << endl;
+    break;
+
+  case TABLE:
+    cout << "                      <table>" << endl;
+    cout << "                          <independentVar lookup=\"row\">" << (LookupR->GetFullyQualifiedName()).substr(12) << "</independentVar>" << endl;
+    cout << "                          <independentVar lookup=\"column\">" << (LookupC->GetFullyQualifiedName()).substr(12) << "</independentVar>" << endl;
+    cout << "                          <tableData>" << endl;
+    Table->Print(30);
+    cout << "                          </tableData>" << endl;
+    cout << "                      </table>" << endl;
+    break;
+
+  case TABLE3D:
+    cout << "                      <table>" << endl;
+    cout << "                          <independentVar lookup=\"row\">" << (LookupR->GetFullyQualifiedName()).substr(12) << "</independentVar>" << endl;
+    cout << "                          <independentVar lookup=\"column\">" << (LookupC->GetFullyQualifiedName()).substr(12) << "</independentVar>" << endl;
+    cout << "                          <independentVar lookup=\"table\">" << (LookupT->GetFullyQualifiedName()).substr(12) << "</independentVar>" << endl;
+    cout << "                          <tableData>" << endl;
+    Table->Print(30);
+    cout << "                          </tableData>" << endl;
+    cout << "                      </table>" << endl;
+    break;
+
+  }
+
+  cout << "                </product>" << endl;
+  cout << "            </function>" << endl;
+
+  if (IsFactor) {
+  cout << " === MOVE THE ABOVE FACTOR " << name << " OUTSIDE OF AND BEFORE ANY <AXIS> DEFINITION ===" << endl;
+    for (int i=0; i<sum.size(); i++) {
+      sum[i]->convert(name);
+    }
+  }
+}
+
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 //    The bitmasked value choices are as follows:
 //    unset: In this case (the default) JSBSim would only print
@@ -357,28 +475,23 @@ 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;
+      if (type == VECTOR || type == TABLE || type == TABLE3D) {
+        cout << "   Rows: " << rows << " indexed by: " << LookupR->getName() << endl;
+        if (type == TABLE || type == TABLE3D) {
+          cout << "   Cols: " << columns << " indexed by: " << LookupC->getName() << endl;
+          if (type == TABLE3D) {
+            cout << "   Tables: " << tables << " indexed by: " << LookupT->getName() << endl;
+          }
         }
-        cout << endl << "   Row indexing parameter: " << LookupR->getName() << endl;
-      }
-
-      if (type == TABLE) {
-        cout << "   Column indexing parameter: " << LookupC->getName() << endl;
-      }
-
-      if (type == VALUE) {
-        cout << "      Value = " << StaticValue << endl;
-      } else if (type == VECTOR || type == TABLE) {
         Table->Print();
+      } else if (type == VALUE) {
+        cout << "      Value = " << StaticValue << endl;
       }
 
       DisplayCoeffFactors();
@@ -402,3 +515,4 @@ void FGCoefficient::Debug(int from)
   }
 }
 
+} // namespace JSBSim