1
0
Fork 0
flightgear/src/FDM/JSBSim/FGCoefficient.cpp

287 lines
7.9 KiB
C++
Raw Normal View History

2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
Module: FGCoefficient.cpp
Author: Jon S. Berndt
Date started: 12/28/98
Purpose: Encapsulates the stability derivative class FGCoefficient;
Called by: FGAircraft
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA.
Further information about the GNU General Public License can also be found on
the world wide web at http://www.gnu.org.
FUNCTIONAL DESCRIPTION
--------------------------------------------------------------------------------
This class models the stability derivative coefficient lookup tables or
equations. Note that the coefficients need not be calculated each delta-t.
Note that the values in a row which index into the table must be the same value
for each column of data, so the first column of numbers for each altitude are
seen to be equal, and there are the same number of values for each altitude.
See the header file FGCoefficient.h for the values of the identifiers.
HISTORY
--------------------------------------------------------------------------------
12/28/98 JSB Created
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
INCLUDES
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-02-05 21:26:01 +00:00
#include "FGCoefficient.h"
#include "FGState.h"
#include "FGFDMExec.h"
1999-02-05 21:26:01 +00:00
#ifndef FGFS
# if defined(sgi) && !defined(__GNUC__)
# include <iomanip.h>
# else
# include <iomanip>
# endif
#else
# include STL_IOMANIP
#endif
2000-11-14 20:31:58 +00:00
2001-03-30 01:04:50 +00:00
static const char *IdSrc = "$Id$";
static const char *IdHdr = ID_COEFFICIENT;
2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-02-05 21:26:01 +00:00
FGCoefficient::FGCoefficient( FGFDMExec* fdex )
1999-02-05 21:26:01 +00:00
{
2001-03-30 01:04:50 +00:00
FDMExec = fdex;
State = FDMExec->GetState();
Table = 0;
if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGCoefficient::~FGCoefficient()
{
if (Table) delete Table;
if (debug_lvl & 2) cout << "Destroyed: FGCoefficient" << endl;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bool FGCoefficient::Load(FGConfigFile *AC_cfg) {
int start, end, n;
string multparms, mult;
2000-04-24 23:49:06 +00:00
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;
}
1999-02-05 21:26:01 +00:00
2000-04-24 23:49:06 +00:00
if (method == "EQUATION") type = EQUATION;
else if (method == "TABLE") type = TABLE;
else if (method == "VECTOR") type = VECTOR;
else if (method == "VALUE") type = VALUE;
else type = UNKNOWN;
if (type == VECTOR || type == TABLE) {
*AC_cfg >> rows;
if (debug_lvl > 0) cout << " Rows: " << rows << " ";
if (type == TABLE) {
2000-04-24 23:49:06 +00:00
*AC_cfg >> columns;
if (debug_lvl > 0) cout << "Cols: " << columns;
2001-03-30 01:04:50 +00:00
Table = new FGTable(rows, columns);
} else {
Table = new FGTable(rows);
}
if (debug_lvl > 0) cout << endl;
2000-04-24 23:49:06 +00:00
*AC_cfg >> multparms;
2000-10-02 23:07:30 +00:00
LookupR = State->GetParameterIndex(multparms);
if (debug_lvl > 0) cout << " Row indexing parameter: " << multparms << endl;
2000-04-24 23:49:06 +00:00
}
2000-04-24 23:49:06 +00:00
if (type == TABLE) {
*AC_cfg >> multparms;
2000-10-02 23:07:30 +00:00
LookupC = State->GetParameterIndex(multparms);
if (debug_lvl > 0) cout << " Column indexing parameter: " << multparms << endl;
2000-04-24 23:49:06 +00:00
}
2000-04-24 23:49:06 +00:00
// 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
// separated by a | character
1999-02-05 21:26:01 +00:00
2000-04-24 23:49:06 +00:00
*AC_cfg >> multparms;
1999-05-08 03:19:08 +00:00
2000-04-24 23:49:06 +00:00
end = multparms.length();
n = multparms.find("|");
2000-10-02 23:07:30 +00:00
start = 0;
1999-05-08 03:19:08 +00:00
if(multparms != "FG_NONE") {
while (n < end && n >= 0) {
n -= start;
mult = multparms.substr(start,n);
multipliers.push_back( State->GetParameterIndex(mult) );
start += n+1;
n = multparms.find("|",start);
}
2000-10-02 23:07:30 +00:00
multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
// End of non-dimensionalizing parameter read-in
2000-04-24 23:49:06 +00:00
}
2000-10-02 23:07:30 +00:00
2000-04-24 23:49:06 +00:00
switch(type) {
case VALUE:
*AC_cfg >> StaticValue;
if (debug_lvl > 0) cout << " Value = " << StaticValue << endl;
2000-04-24 23:49:06 +00:00
break;
case VECTOR:
case TABLE:
2001-03-30 01:04:50 +00:00
*Table << *AC_cfg;
if (debug_lvl > 0) Table->Print();
2000-04-24 23:49:06 +00:00
break;
2000-10-02 23:07:30 +00:00
case EQUATION:
case UNKNOWN:
cerr << "Unimplemented coefficient type: " << type << endl;
2001-03-30 01:04:50 +00:00
break;
1999-02-05 21:26:01 +00:00
}
2000-04-24 23:49:06 +00:00
AC_cfg->GetNextConfigLine();
if (debug_lvl > 0) DisplayCoeffFactors();
return true;
} else {
return false;
}
1999-02-05 21:26:01 +00:00
}
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
float FGCoefficient::Value(float rVal, float cVal)
{
2001-03-30 01:04:50 +00:00
float Value;
unsigned int midx;
1999-02-05 21:26:01 +00:00
2001-03-30 01:04:50 +00:00
SD = Value = Table->GetValue(rVal, cVal);
1999-02-05 21:26:01 +00:00
2000-10-02 23:07:30 +00:00
for (midx=0; midx < multipliers.size(); midx++) {
2001-03-30 01:04:50 +00:00
Value *= State->GetParameter(multipliers[midx]);
1999-02-05 21:26:01 +00:00
}
return Value;
}
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
float FGCoefficient::Value(float Val)
{
2001-03-30 01:04:50 +00:00
float Value;
SD = Value = Table->GetValue(Val);
2000-10-02 23:07:30 +00:00
2001-03-30 01:04:50 +00:00
for (unsigned int midx=0; midx < multipliers.size(); midx++)
Value *= State->GetParameter(multipliers[midx]);
2000-10-02 23:07:30 +00:00
1999-02-05 21:26:01 +00:00
return Value;
}
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
1999-05-08 03:19:08 +00:00
float FGCoefficient::Value(void)
{
float Value;
2000-04-24 23:49:06 +00:00
2001-03-30 01:04:50 +00:00
SD = Value = StaticValue;
1999-05-08 03:19:08 +00:00
2001-03-30 01:04:50 +00:00
for (unsigned int midx=0; midx < multipliers.size(); midx++)
2000-10-02 23:07:30 +00:00
Value *= State->GetParameter(multipliers[midx]);
1999-05-08 03:19:08 +00:00
return Value;
}
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000-04-24 23:49:06 +00:00
1999-05-08 03:19:08 +00:00
float FGCoefficient::TotalValue()
1999-02-05 21:26:01 +00:00
{
2001-03-30 01:04:50 +00:00
1999-02-05 21:26:01 +00:00
switch(type) {
case 0:
return -1;
case 1:
1999-05-08 03:19:08 +00:00
return (Value());
1999-02-05 21:26:01 +00:00
case 2:
2000-04-24 23:49:06 +00:00
return (Value(State->GetParameter(LookupR)));
1999-02-05 21:26:01 +00:00
case 3:
2000-04-24 23:49:06 +00:00
return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC)));
1999-02-05 21:26:01 +00:00
case 4:
return 0.0;
}
return 0;
}
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGCoefficient::DumpSD(void)
{
2000-04-24 23:49:06 +00:00
cout << " " << name << ": " << SD << endl;
}
2000-04-24 23:49:06 +00:00
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000-04-24 23:49:06 +00:00
2001-03-30 01:04:50 +00:00
void FGCoefficient::Debug(void)
{
//TODO: Add your source code here
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGCoefficient::DisplayCoeffFactors(void)
{
unsigned int i;
cout << " Non-Dimensionalized by: ";
if( multipliers.size() == 0) {
cout << "none" << endl;
} else {
for (i=0; i<multipliers.size();i++)
cout << FDMExec->GetState()->paramdef[multipliers[i]];
}
cout << endl;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGCoefficient::GetCoefficientValues(void) {
char buffer[10];
string value;
sprintf(buffer,"%9.6f",SD);
value = string(buffer);
return value;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%