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"
53 static const char *IdSrc = "$Id$";
54 static const char *IdHdr = "ID_COEFFICIENT";
56 extern char highint[5];
57 extern char halfint[5];
58 extern char normint[6];
60 extern char underon[5];
61 extern char underoff[6];
62 extern char fgblue[6];
63 extern char fgcyan[6];
65 extern char fggreen[6];
68 extern short debug_lvl;
70 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74 FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg)
80 State = FDMExec->GetState();
84 name = AC_cfg->GetValue("NAME");
85 method = AC_cfg->GetValue("TYPE");
87 AC_cfg->GetNextConfigLine();
88 *AC_cfg >> description;
90 cout << "\n " << highint << underon << name << underoff << normint << endl;
91 cout << " " << description << endl;
92 cout << " " << method << endl;
94 if (method == "EQUATION") type = EQUATION;
95 else if (method == "TABLE") type = TABLE;
96 else if (method == "VECTOR") type = VECTOR;
97 else if (method == "VALUE") type = VALUE;
100 if (type == VECTOR || type == TABLE) {
102 cout << " Rows: " << rows << " ";
105 cout << "Cols: " << columns;
106 Table = new FGTable(rows, columns);
108 Table = new FGTable(rows);
113 *AC_cfg >> multparms;
114 LookupR = State->GetParameterIndex(multparms);
115 cout << " Row indexing parameter: " << multparms << endl;
119 *AC_cfg >> multparms;
120 LookupC = State->GetParameterIndex(multparms);
121 cout << " Column indexing parameter: " << multparms << endl;
124 // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
125 // where each non-dimensionalizing parameter for this coefficient is
126 // separated by a | character
128 *AC_cfg >> multparms;
130 end = multparms.length();
131 n = multparms.find("|");
134 while (n < end && n >= 0) {
136 multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
138 n = multparms.find("|",start);
141 multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
143 // End of non-dimensionalizing parameter read-in
147 *AC_cfg >> StaticValue;
148 cout << " Value = " << StaticValue << endl;
158 cerr << "Unimplemented coefficient type: " << type << endl;
161 AC_cfg->GetNextConfigLine();
163 if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
166 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 FGCoefficient::~FGCoefficient()
170 if (Table) delete Table;
171 if (debug_lvl & 2) cout << "Destroyed: FGCoefficient" << endl;
174 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 float FGCoefficient::Value(float rVal, float cVal)
181 SD = Value = Table->GetValue(rVal, cVal);
183 for (midx=0; midx < multipliers.size(); midx++) {
184 Value *= State->GetParameter(multipliers[midx]);
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 float FGCoefficient::Value(float Val)
195 SD = Value = Table->GetValue(Val);
197 for (unsigned int midx=0; midx < multipliers.size(); midx++)
198 Value *= State->GetParameter(multipliers[midx]);
203 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 float FGCoefficient::Value(void)
209 SD = Value = StaticValue;
211 for (unsigned int midx=0; midx < multipliers.size(); midx++)
212 Value *= State->GetParameter(multipliers[midx]);
217 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 float FGCoefficient::TotalValue()
228 return (Value(State->GetParameter(LookupR)));
230 return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC)));
237 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 void FGCoefficient::DumpSD(void)
241 cout << " " << name << ": " << SD << endl;
244 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 void FGCoefficient::Debug(void)
248 //TODO: Add your source code here