1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGCoefficient.cpp
6 Purpose: Encapsulates the stability derivative class FGCoefficient;
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class models the stability derivative coefficient lookup tables or
31 equations. Note that the coefficients need not be calculated each delta-t.
33 Note that the values in a row which index into the table must be the same value
34 for each column of data, so the first column of numbers for each altitude are
35 seen to be equal, and there are the same number of values for each altitude.
37 See the header file FGCoefficient.h for the values of the identifiers.
40 --------------------------------------------------------------------------------
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #include "FGCoefficient.h"
49 #include "FGFDMExec.h"
52 # include <iomanip.h>
\r
54 # include STL_IOMANIP
\r
57 static const char *IdSrc = "$Id$";
58 static const char *IdHdr = "ID_COEFFICIENT";
60 extern char highint[5];
61 extern char halfint[5];
62 extern char normint[6];
64 extern char underon[5];
65 extern char underoff[6];
66 extern char fgblue[6];
67 extern char fgcyan[6];
69 extern char fggreen[6];
72 extern short debug_lvl;
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
78 FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg)
84 State = FDMExec->GetState();
88 name = AC_cfg->GetValue("NAME");
89 method = AC_cfg->GetValue("TYPE");
91 AC_cfg->GetNextConfigLine();
92 *AC_cfg >> description;
94 cout << "\n " << highint << underon << name << underoff << normint << endl;
95 cout << " " << description << endl;
96 cout << " " << method << endl;
98 if (method == "EQUATION") type = EQUATION;
99 else if (method == "TABLE") type = TABLE;
100 else if (method == "VECTOR") type = VECTOR;
101 else if (method == "VALUE") type = VALUE;
104 if (type == VECTOR || type == TABLE) {
106 cout << " Rows: " << rows << " ";
109 cout << "Cols: " << columns;
110 Table = new FGTable(rows, columns);
112 Table = new FGTable(rows);
117 *AC_cfg >> multparms;
118 LookupR = State->GetParameterIndex(multparms);
119 cout << " Row indexing parameter: " << multparms << endl;
123 *AC_cfg >> multparms;
124 LookupC = State->GetParameterIndex(multparms);
125 cout << " Column indexing parameter: " << multparms << endl;
128 // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
129 // where each non-dimensionalizing parameter for this coefficient is
130 // separated by a | character
132 *AC_cfg >> multparms;
134 end = multparms.length();
135 n = multparms.find("|");
138 while (n < end && n >= 0) {
140 multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
142 n = multparms.find("|",start);
145 multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
147 // End of non-dimensionalizing parameter read-in
151 *AC_cfg >> StaticValue;
152 cout << " Value = " << StaticValue << endl;
162 cerr << "Unimplemented coefficient type: " << type << endl;
165 AC_cfg->GetNextConfigLine();
167 if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 FGCoefficient::~FGCoefficient()
174 if (Table) delete Table;
175 if (debug_lvl & 2) cout << "Destroyed: FGCoefficient" << endl;
178 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 float FGCoefficient::Value(float rVal, float cVal)
185 SD = Value = Table->GetValue(rVal, cVal);
187 for (midx=0; midx < multipliers.size(); midx++) {
188 Value *= State->GetParameter(multipliers[midx]);
193 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 float FGCoefficient::Value(float Val)
199 SD = Value = Table->GetValue(Val);
201 for (unsigned int midx=0; midx < multipliers.size(); midx++)
202 Value *= State->GetParameter(multipliers[midx]);
207 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 float FGCoefficient::Value(void)
213 SD = Value = StaticValue;
215 for (unsigned int midx=0; midx < multipliers.size(); midx++)
216 Value *= State->GetParameter(multipliers[midx]);
221 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 float FGCoefficient::TotalValue()
232 return (Value(State->GetParameter(LookupR)));
234 return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC)));
241 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 void FGCoefficient::DumpSD(void)
245 cout << " " << name << ": " << SD << endl;
248 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 void FGCoefficient::Debug(void)
252 //TODO: Add your source code here