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 # if defined(sgi) && !defined(__GNUC__)
61 static const char *IdSrc = "$Id$";
62 static const char *IdHdr = ID_COEFFICIENT;
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 FGCoefficient::FGCoefficient( FGFDMExec* fdex )
72 State = FDMExec->GetState();
75 if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 FGCoefficient::~FGCoefficient()
82 if (Table) delete Table;
83 if (debug_lvl & 2) cout << "Destroyed: FGCoefficient" << endl;
86 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 bool FGCoefficient::Load(FGConfigFile *AC_cfg) {
90 string multparms, mult;
93 name = AC_cfg->GetValue("NAME");
94 method = AC_cfg->GetValue("TYPE");
95 AC_cfg->GetNextConfigLine();
96 *AC_cfg >> description;
98 cout << "\n " << highint << underon << name << underoff << normint << endl;
99 cout << " " << description << endl;
100 cout << " " << method << endl;
103 if (method == "EQUATION") type = EQUATION;
104 else if (method == "TABLE") type = TABLE;
105 else if (method == "VECTOR") type = VECTOR;
106 else if (method == "VALUE") type = VALUE;
109 if (type == VECTOR || type == TABLE) {
111 if (debug_lvl > 0) cout << " Rows: " << rows << " ";
114 if (debug_lvl > 0) cout << "Cols: " << columns;
115 Table = new FGTable(rows, columns);
117 Table = new FGTable(rows);
120 if (debug_lvl > 0) cout << endl;
122 *AC_cfg >> multparms;
123 LookupR = State->GetParameterIndex(multparms);
124 if (debug_lvl > 0) cout << " Row indexing parameter: " << multparms << endl;
128 *AC_cfg >> multparms;
129 LookupC = State->GetParameterIndex(multparms);
130 if (debug_lvl > 0) cout << " Column indexing parameter: " << multparms << endl;
133 // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
134 // where each non-dimensionalizing parameter for this coefficient is
135 // separated by a | character
137 *AC_cfg >> multparms;
139 end = multparms.length();
140 n = multparms.find("|");
143 if (multparms != string("FG_NONE")) {
144 while (n < end && n >= 0) {
146 mult = multparms.substr(start,n);
147 multipliers.push_back( State->GetParameterIndex(mult) );
149 n = multparms.find("|",start);
151 multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
152 // End of non-dimensionalizing parameter read-in
157 *AC_cfg >> StaticValue;
158 if (debug_lvl > 0) cout << " Value = " << StaticValue << endl;
163 if (debug_lvl > 0) Table->Print();
167 cerr << "Unimplemented coefficient type: " << type << endl;
170 AC_cfg->GetNextConfigLine();
171 if (debug_lvl > 0) DisplayCoeffFactors();
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 double FGCoefficient::Value(double rVal, double cVal)
187 SD = Value = Table->GetValue(rVal, cVal);
189 for (midx=0; midx < multipliers.size(); midx++) {
190 Value *= State->GetParameter(multipliers[midx]);
195 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 double FGCoefficient::Value(double Val)
201 SD = Value = Table->GetValue(Val);
203 for (unsigned int midx=0; midx < multipliers.size(); midx++)
204 Value *= State->GetParameter(multipliers[midx]);
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 double FGCoefficient::Value(void)
215 SD = Value = StaticValue;
217 for (unsigned int midx=0; midx < multipliers.size(); midx++)
218 Value *= State->GetParameter(multipliers[midx]);
223 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225 double FGCoefficient::TotalValue()
234 return (Value(State->GetParameter(LookupR)));
236 return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC)));
243 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 void FGCoefficient::DumpSD(void)
247 cout << " " << name << ": " << SD << endl;
250 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 void FGCoefficient::Debug(void)
254 //TODO: Add your source code here
257 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 void FGCoefficient::DisplayCoeffFactors(void)
263 cout << " Non-Dimensionalized by: ";
265 if( multipliers.size() == 0) {
266 cout << "none" << endl;
268 for (i=0; i<multipliers.size();i++)
269 cout << FDMExec->GetState()->paramdef[multipliers[i]];
274 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 string FGCoefficient::GetCoefficientValues(void) {
280 sprintf(buffer,"%9.6f",SD);
281 value = string(buffer);
285 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%