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 )
82 State = FDMExec->GetState();
85 if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
88 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 FGCoefficient::~FGCoefficient()
92 if (Table) delete Table;
93 if (debug_lvl & 2) cout << "Destroyed: FGCoefficient" << endl;
96 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 bool FGCoefficient::Load(FGConfigFile *AC_cfg) {
100 string multparms, mult;
103 name = AC_cfg->GetValue("NAME");
104 method = AC_cfg->GetValue("TYPE");
105 AC_cfg->GetNextConfigLine();
106 *AC_cfg >> description;
108 cout << "\n " << highint << underon << name << underoff << normint << endl;
109 cout << " " << description << endl;
110 cout << " " << method << endl;
113 if (method == "EQUATION") type = EQUATION;
114 else if (method == "TABLE") type = TABLE;
115 else if (method == "VECTOR") type = VECTOR;
116 else if (method == "VALUE") type = VALUE;
119 if (type == VECTOR || type == TABLE) {
121 if (debug_lvl > 0) cout << " Rows: " << rows << " ";
124 if (debug_lvl > 0) cout << "Cols: " << columns;
125 Table = new FGTable(rows, columns);
127 Table = new FGTable(rows);
130 if (debug_lvl > 0) cout << endl;
132 *AC_cfg >> multparms;
133 LookupR = State->GetParameterIndex(multparms);
134 if (debug_lvl > 0) cout << " Row indexing parameter: " << multparms << endl;
138 *AC_cfg >> multparms;
139 LookupC = State->GetParameterIndex(multparms);
140 if (debug_lvl > 0) cout << " Column indexing parameter: " << multparms << endl;
143 // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
144 // where each non-dimensionalizing parameter for this coefficient is
145 // separated by a | character
147 *AC_cfg >> multparms;
149 end = multparms.length();
150 n = multparms.find("|");
153 if(multparms != "FG_NONE") {
154 while (n < end && n >= 0) {
156 mult = multparms.substr(start,n);
157 multipliers.push_back( State->GetParameterIndex(mult) );
159 n = multparms.find("|",start);
161 multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
162 // End of non-dimensionalizing parameter read-in
167 *AC_cfg >> StaticValue;
168 if (debug_lvl > 0) cout << " Value = " << StaticValue << endl;
173 if (debug_lvl > 0) Table->Print();
177 cerr << "Unimplemented coefficient type: " << type << endl;
180 AC_cfg->GetNextConfigLine();
181 if (debug_lvl > 0) DisplayCoeffFactors();
190 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 float FGCoefficient::Value(float rVal, float cVal)
197 SD = Value = Table->GetValue(rVal, cVal);
199 for (midx=0; midx < multipliers.size(); midx++) {
200 Value *= State->GetParameter(multipliers[midx]);
205 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207 float FGCoefficient::Value(float Val)
211 SD = Value = Table->GetValue(Val);
213 for (unsigned int midx=0; midx < multipliers.size(); midx++)
214 Value *= State->GetParameter(multipliers[midx]);
219 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 float FGCoefficient::Value(void)
225 SD = Value = StaticValue;
227 for (unsigned int midx=0; midx < multipliers.size(); midx++)
228 Value *= State->GetParameter(multipliers[midx]);
233 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235 float FGCoefficient::TotalValue()
244 return (Value(State->GetParameter(LookupR)));
246 return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC)));
253 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255 void FGCoefficient::DumpSD(void)
257 cout << " " << name << ": " << SD << endl;
260 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 void FGCoefficient::Debug(void)
264 //TODO: Add your source code here
267 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 void FGCoefficient::DisplayCoeffFactors(void)
273 cout << " Non-Dimensionalized by: ";
275 if( multipliers.size() == 0) {
276 cout << "none" << endl;
278 for (i=0; i<multipliers.size();i++)
279 cout << FDMExec->GetState()->paramdef[multipliers[i]];
284 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286 string FGCoefficient::GetCoefficientValues(void) {
290 snprintf(buffer,10,"%9.6f",SD);
291 value += string(buffer);
295 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%