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
|
|
|
|
|
|
|
|
********************************************************************************
|
|
|
|
INCLUDES
|
|
|
|
*******************************************************************************/
|
|
|
|
|
1999-02-11 21:05:34 +00:00
|
|
|
#include "FGCoefficient.h"
|
|
|
|
#include "FGState.h"
|
|
|
|
#include "FGFDMExec.h"
|
1999-02-05 21:26:01 +00:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
************************************ CODE **************************************
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg)
|
1999-02-05 21:26:01 +00:00
|
|
|
{
|
1999-06-21 05:01:31 +00:00
|
|
|
int r, c, start, end, n;
|
1999-02-05 21:26:01 +00:00
|
|
|
float ftrashcan;
|
2000-04-24 23:49:06 +00:00
|
|
|
string multparms;
|
1999-06-21 05:01:31 +00:00
|
|
|
|
1999-02-11 21:05:34 +00:00
|
|
|
FDMExec = fdex;
|
|
|
|
State = FDMExec->GetState();
|
1999-06-21 05:01:31 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
if (AC_cfg) {
|
|
|
|
name = AC_cfg->GetValue("NAME");
|
|
|
|
method = AC_cfg->GetValue("TYPE");
|
1999-06-21 05:01:31 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
AC_cfg->GetNextConfigLine();
|
|
|
|
*AC_cfg >> description;
|
1999-06-21 05:01:31 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
cout << " " << name << 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;
|
|
|
|
cout << " Rows: " << rows << " ";
|
1999-03-02 01:02:51 +00:00
|
|
|
if (type == TABLE) {
|
2000-04-24 23:49:06 +00:00
|
|
|
*AC_cfg >> columns;
|
|
|
|
cout << "Cols: " << columns;
|
1999-06-21 05:01:31 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
*AC_cfg >> multparms;
|
|
|
|
if (multparms.substr(0,1) == "F") {
|
|
|
|
LookupR = State->GetParameterIndex(multparms);
|
|
|
|
cout << " Row indexing parameter: " << multparms << endl;
|
1999-06-21 05:01:31 +00:00
|
|
|
} else {
|
2000-04-24 23:49:06 +00:00
|
|
|
LookupR = atoi(multparms.c_str());
|
|
|
|
cout << " Row indexing parameter: " << LookupR << endl;
|
1999-02-05 21:26:01 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
}
|
1999-06-21 05:01:31 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
if (type == TABLE) {
|
|
|
|
*AC_cfg >> multparms;
|
|
|
|
if (multparms.substr(0,1) == "F") {
|
|
|
|
LookupR = State->GetParameterIndex(multparms);
|
|
|
|
cout << " Column indexing parameter: " << multparms << endl;
|
|
|
|
} else {
|
|
|
|
LookupC = atoi(multparms.c_str());
|
|
|
|
cout << " Column indexing parameter: " << LookupC << endl;
|
1999-02-05 21:26:01 +00:00
|
|
|
}
|
2000-04-24 23:49:06 +00:00
|
|
|
}
|
1999-06-21 05:01:31 +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("|");
|
|
|
|
start = mult_count = multipliers = 0;
|
1999-05-08 03:19:08 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
while(n < end && n >= 0) {
|
|
|
|
n -= start;
|
|
|
|
mult_idx[mult_count] = State->GetParameterIndex(multparms.substr(start,n));
|
|
|
|
multipliers += mult_idx[mult_count];
|
|
|
|
mult_count++;
|
|
|
|
start += n+1;
|
|
|
|
n = multparms.find("|",start);
|
|
|
|
}
|
|
|
|
mult_idx[mult_count] = State->GetParameterIndex(multparms.substr(start,n));
|
|
|
|
multipliers += mult_idx[mult_count];
|
|
|
|
mult_count++;
|
|
|
|
|
|
|
|
// End of non-dimensionalizing parameter read-in
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case VALUE:
|
|
|
|
*AC_cfg >> StaticValue;
|
|
|
|
cout << " Value = " << StaticValue << endl;
|
|
|
|
break;
|
|
|
|
case VECTOR:
|
|
|
|
Allocate(rows,2);
|
|
|
|
|
|
|
|
for (r=1;r<=rows;r++) {
|
|
|
|
*AC_cfg >> Table3D[r][0];
|
|
|
|
*AC_cfg >> Table3D[r][1];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (r=1;r<=rows;r++) {
|
|
|
|
cout << " ";
|
|
|
|
for (c=0;c<columns;c++) {
|
|
|
|
cout << Table3D[r][c] << " ";
|
1999-02-05 21:26:01 +00:00
|
|
|
}
|
2000-04-24 23:49:06 +00:00
|
|
|
cout << endl;
|
|
|
|
}
|
1999-05-08 03:19:08 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
break;
|
|
|
|
case TABLE:
|
|
|
|
Allocate(rows, columns);
|
|
|
|
|
|
|
|
Table3D[0][0] = 0.0;
|
|
|
|
for (c=1;c<=columns;c++) {
|
|
|
|
*AC_cfg >> Table3D[0][c];
|
|
|
|
for (r=1;r<=rows;r++) {
|
|
|
|
if ( c==1 ) *AC_cfg >> Table3D[r][0];
|
|
|
|
else *AC_cfg >> ftrashcan;
|
|
|
|
*AC_cfg >> Table3D[r][c];
|
1999-05-08 03:19:08 +00:00
|
|
|
}
|
2000-04-24 23:49:06 +00:00
|
|
|
}
|
1999-06-21 05:01:31 +00:00
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
for (r=0;r<=rows;r++) {
|
|
|
|
cout << " ";
|
|
|
|
for (c=0;c<=columns;c++) {
|
|
|
|
cout << Table3D[r][c] << " ";
|
|
|
|
}
|
|
|
|
cout << endl;
|
1999-02-05 21:26:01 +00:00
|
|
|
}
|
2000-04-24 23:49:06 +00:00
|
|
|
|
|
|
|
break;
|
1999-02-05 21:26:01 +00:00
|
|
|
}
|
2000-04-24 23:49:06 +00:00
|
|
|
AC_cfg->GetNextConfigLine();
|
1999-02-05 21:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
/******************************************************************************/
|
1999-02-05 21:26:01 +00:00
|
|
|
|
|
|
|
FGCoefficient::~FGCoefficient(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
/******************************************************************************/
|
1999-02-05 21:26:01 +00:00
|
|
|
|
|
|
|
bool FGCoefficient::Allocate(int r, int c)
|
|
|
|
{
|
|
|
|
rows = r;
|
|
|
|
columns = c;
|
|
|
|
Table3D = new float*[r+1];
|
|
|
|
for (int i=0;i<=r;i++) Table3D[i] = new float[c+1];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
/******************************************************************************/
|
1999-02-05 21:26:01 +00:00
|
|
|
|
|
|
|
bool FGCoefficient::Allocate(int n)
|
|
|
|
{
|
|
|
|
rows = n;
|
|
|
|
columns = 0;
|
|
|
|
Table2D = new float[n+1];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
/******************************************************************************/
|
1999-02-05 21:26:01 +00:00
|
|
|
|
|
|
|
float FGCoefficient::Value(float rVal, float cVal)
|
|
|
|
{
|
|
|
|
float rFactor, cFactor, col1temp, col2temp, Value;
|
|
|
|
int r, c, midx;
|
|
|
|
|
|
|
|
if (rows < 2 || columns < 2) return 0.0;
|
|
|
|
|
|
|
|
for (r=1;r<=rows;r++) if (Table3D[r][0] >= rVal) break;
|
|
|
|
for (c=1;c<=columns;c++) if (Table3D[0][c] >= cVal) break;
|
|
|
|
|
|
|
|
c = c < 2 ? 2 : (c > columns ? columns : c);
|
|
|
|
r = r < 2 ? 2 : (r > rows ? rows : r);
|
|
|
|
|
|
|
|
rFactor = (rVal - Table3D[r-1][0]) / (Table3D[r][0] - Table3D[r-1][0]);
|
|
|
|
cFactor = (cVal - Table3D[0][c-1]) / (Table3D[0][c] - Table3D[0][c-1]);
|
|
|
|
|
|
|
|
col1temp = rFactor*(Table3D[r][c-1] - Table3D[r-1][c-1]) + Table3D[r-1][c-1];
|
|
|
|
col2temp = rFactor*(Table3D[r][c] - Table3D[r-1][c]) + Table3D[r-1][c];
|
|
|
|
|
1999-12-30 18:01:59 +00:00
|
|
|
SD = Value = col1temp + cFactor*(col2temp - col1temp);
|
1999-06-21 05:01:31 +00:00
|
|
|
|
1999-02-05 21:26:01 +00:00
|
|
|
for (midx=0;midx<mult_count;midx++) {
|
2000-04-24 23:49:06 +00:00
|
|
|
Value *= State->GetParameter(mult_idx[midx]);
|
1999-02-05 21:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
/******************************************************************************/
|
1999-02-05 21:26:01 +00:00
|
|
|
|
|
|
|
float FGCoefficient::Value(float Val)
|
|
|
|
{
|
|
|
|
float Factor, Value;
|
|
|
|
int r, midx;
|
|
|
|
|
|
|
|
if (rows < 2) return 0.0;
|
1999-06-21 05:01:31 +00:00
|
|
|
|
1999-02-05 21:26:01 +00:00
|
|
|
for (r=1;r<=rows;r++) if (Table3D[r][0] >= Val) break;
|
|
|
|
r = r < 2 ? 2 : (r > rows ? rows : r);
|
|
|
|
|
|
|
|
// make sure denominator below does not go to zero.
|
|
|
|
if (Table3D[r][0] != Table3D[r-1][0]) {
|
|
|
|
Factor = (Val - Table3D[r-1][0]) / (Table3D[r][0] - Table3D[r-1][0]);
|
|
|
|
} else {
|
|
|
|
Factor = 1.0;
|
|
|
|
}
|
1999-05-08 03:19:08 +00:00
|
|
|
|
1999-12-30 18:01:59 +00:00
|
|
|
SD = Value = Factor*(Table3D[r][1] - Table3D[r-1][1]) + Table3D[r-1][1];
|
1999-02-05 21:26:01 +00:00
|
|
|
|
|
|
|
for (midx=0;midx<mult_count;midx++) {
|
2000-04-24 23:49:06 +00:00
|
|
|
Value *= State->GetParameter(mult_idx[midx]);
|
1999-02-05 21:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
|
2000-04-24 23:49:06 +00:00
|
|
|
/******************************************************************************/
|
1999-02-05 21:26:01 +00:00
|
|
|
|
1999-05-08 03:19:08 +00:00
|
|
|
float FGCoefficient::Value(void)
|
|
|
|
{
|
|
|
|
float Value;
|
|
|
|
int midx;
|
2000-04-24 23:49:06 +00:00
|
|
|
|
1999-12-30 18:01:59 +00:00
|
|
|
SD = Value = StaticValue;
|
1999-05-08 03:19:08 +00:00
|
|
|
|
|
|
|
for (midx=0;midx<mult_count;midx++) {
|
2000-04-24 23:49:06 +00:00
|
|
|
Value *= State->GetParameter(mult_idx[midx]);
|
1999-05-08 03:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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-04-24 23:49:06 +00:00
|
|
|
/******************************************************************************/
|
1999-12-30 18:01:59 +00:00
|
|
|
|
|
|
|
void FGCoefficient::DumpSD(void)
|
|
|
|
{
|
2000-04-24 23:49:06 +00:00
|
|
|
cout << " " << name << ": " << SD << endl;
|
1999-12-30 18:01:59 +00:00
|
|
|
}
|
2000-04-24 23:49:06 +00:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|