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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 #include "FGCoefficient.h"
50 #include "FGFDMExec.h"
53 # if defined(sgi) && !defined(__GNUC__)
62 static const char *IdSrc = "$Id$";
63 static const char *IdHdr = ID_COEFFICIENT;
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 FGCoefficient::FGCoefficient( FGFDMExec* fdex )
73 State = FDMExec->GetState();
76 if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 FGCoefficient::~FGCoefficient()
83 if (Table) delete Table;
84 if (debug_lvl & 2) cout << "Destroyed: FGCoefficient" << endl;
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 bool FGCoefficient::Load(FGConfigFile *AC_cfg) {
91 string multparms, mult;
94 name = AC_cfg->GetValue("NAME");
95 method = AC_cfg->GetValue("TYPE");
96 AC_cfg->GetNextConfigLine();
97 *AC_cfg >> description;
99 cout << "\n " << highint << underon << name << underoff << normint << endl;
100 cout << " " << description << endl;
101 cout << " " << method << endl;
104 if (method == "EQUATION") type = EQUATION;
105 else if (method == "TABLE") type = TABLE;
106 else if (method == "VECTOR") type = VECTOR;
107 else if (method == "VALUE") type = VALUE;
110 if (type == VECTOR || type == TABLE) {
112 if (debug_lvl > 0) cout << " Rows: " << rows << " ";
115 if (debug_lvl > 0) cout << "Cols: " << columns;
116 Table = new FGTable(rows, columns);
118 Table = new FGTable(rows);
121 if (debug_lvl > 0) cout << endl;
123 *AC_cfg >> multparms;
124 LookupR = State->GetParameterIndex(multparms);
125 if (debug_lvl > 0) cout << " Row indexing parameter: " << multparms << endl;
129 *AC_cfg >> multparms;
130 LookupC = State->GetParameterIndex(multparms);
131 if (debug_lvl > 0) cout << " Column indexing parameter: " << multparms << endl;
134 // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
135 // where each non-dimensionalizing parameter for this coefficient is
136 // separated by a | character
138 *AC_cfg >> multparms;
140 end = multparms.length();
141 n = multparms.find("|");
144 if(multparms != "FG_NONE") {
145 while (n < end && n >= 0) {
147 mult = multparms.substr(start,n);
148 multipliers.push_back( State->GetParameterIndex(mult) );
150 n = multparms.find("|",start);
152 multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
153 // End of non-dimensionalizing parameter read-in
158 *AC_cfg >> StaticValue;
159 if (debug_lvl > 0) cout << " Value = " << StaticValue << endl;
164 if (debug_lvl > 0) Table->Print();
168 cerr << "Unimplemented coefficient type: " << type << endl;
171 AC_cfg->GetNextConfigLine();
172 if (debug_lvl > 0) DisplayCoeffFactors();
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 float FGCoefficient::Value(float rVal, float cVal)
188 SD = Value = Table->GetValue(rVal, cVal);
190 for (midx=0; midx < multipliers.size(); midx++) {
191 Value *= State->GetParameter(multipliers[midx]);
196 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 float FGCoefficient::Value(float Val)
202 SD = Value = Table->GetValue(Val);
204 for (unsigned int midx=0; midx < multipliers.size(); midx++)
205 Value *= State->GetParameter(multipliers[midx]);
210 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 float FGCoefficient::Value(void)
216 SD = Value = StaticValue;
218 for (unsigned int midx=0; midx < multipliers.size(); midx++)
219 Value *= State->GetParameter(multipliers[midx]);
224 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 float FGCoefficient::TotalValue()
235 return (Value(State->GetParameter(LookupR)));
237 return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC)));
244 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 void FGCoefficient::DumpSD(void)
248 cout << " " << name << ": " << SD << endl;
251 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 void FGCoefficient::Debug(void)
255 //TODO: Add your source code here
258 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260 void FGCoefficient::DisplayCoeffFactors(void)
264 cout << " Non-Dimensionalized by: ";
266 if( multipliers.size() == 0) {
267 cout << "none" << endl;
269 for (i=0; i<multipliers.size();i++)
270 cout << FDMExec->GetState()->paramdef[multipliers[i]];
275 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 string FGCoefficient::GetCoefficientValues(void) {
281 sprintf(buffer,"%9.6f",SD);
282 value = string(buffer);
286 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%