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"
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;
95 cout << "\n " << highint << underon << name << underoff << normint << endl;
96 cout << " " << description << endl;
97 cout << " " << method << endl;
100 if (method == "EQUATION") type = EQUATION;
101 else if (method == "TABLE") type = TABLE;
102 else if (method == "VECTOR") type = VECTOR;
103 else if (method == "VALUE") type = VALUE;
106 if (type == VECTOR || type == TABLE) {
108 if (debug_lvl > 0) cout << " Rows: " << rows << " ";
111 if (debug_lvl > 0) cout << "Cols: " << columns;
112 Table = new FGTable(rows, columns);
114 Table = new FGTable(rows);
117 if (debug_lvl > 0) cout << endl;
119 *AC_cfg >> multparms;
120 LookupR = State->GetParameterIndex(multparms);
121 if (debug_lvl > 0) cout << " Row indexing parameter: " << multparms << endl;
125 *AC_cfg >> multparms;
126 LookupC = State->GetParameterIndex(multparms);
127 if (debug_lvl > 0) cout << " Column indexing parameter: " << multparms << endl;
130 // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
131 // where each non-dimensionalizing parameter for this coefficient is
132 // separated by a | character
134 *AC_cfg >> multparms;
136 end = multparms.length();
137 n = multparms.find("|");
140 while (n < end && n >= 0) {
142 multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
144 n = multparms.find("|",start);
147 multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
149 // End of non-dimensionalizing parameter read-in
153 *AC_cfg >> StaticValue;
154 if (debug_lvl > 0) cout << " Value = " << StaticValue << endl;
159 if (debug_lvl > 0) Table->Print();
163 cerr << "Unimplemented coefficient type: " << type << endl;
166 AC_cfg->GetNextConfigLine();
168 if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
171 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 FGCoefficient::~FGCoefficient()
175 if (Table) delete Table;
176 if (debug_lvl & 2) cout << "Destroyed: FGCoefficient" << endl;
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 float FGCoefficient::Value(float rVal, float cVal)
186 SD = Value = Table->GetValue(rVal, cVal);
188 for (midx=0; midx < multipliers.size(); midx++) {
189 Value *= State->GetParameter(multipliers[midx]);
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 float FGCoefficient::Value(float Val)
200 SD = Value = Table->GetValue(Val);
202 for (unsigned int midx=0; midx < multipliers.size(); midx++)
203 Value *= State->GetParameter(multipliers[midx]);
208 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 float FGCoefficient::Value(void)
214 SD = Value = StaticValue;
216 for (unsigned int midx=0; midx < multipliers.size(); midx++)
217 Value *= State->GetParameter(multipliers[midx]);
222 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 float FGCoefficient::TotalValue()
233 return (Value(State->GetParameter(LookupR)));
235 return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC)));
242 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 void FGCoefficient::DumpSD(void)
246 cout << " " << name << ": " << SD << endl;
249 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 void FGCoefficient::Debug(void)
253 //TODO: Add your source code here