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"
50 #include "FGPropertyManager.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 PropertyManager = FDMExec->GetPropertyManager();
81 LookupR = LookupC = 0;
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)
104 name = AC_cfg->GetValue("NAME");
105 method = AC_cfg->GetValue("TYPE");
106 AC_cfg->GetNextConfigLine();
107 *AC_cfg >> description;
109 if (method == "EQUATION") type = EQUATION;
110 else if (method == "TABLE") type = TABLE;
111 else if (method == "VECTOR") type = VECTOR;
112 else if (method == "VALUE") type = VALUE;
115 if (type == VECTOR || type == TABLE) {
119 Table = new FGTable(rows, columns);
121 Table = new FGTable(rows);
124 *AC_cfg >> multparmsRow;
125 prop = State->GetPropertyName( State->GetParameterIndex(multparmsRow) );
126 LookupR = PropertyManager->GetNode( prop );
130 *AC_cfg >> multparmsCol;
131 prop = State->GetPropertyName( State->GetParameterIndex(multparmsCol) );
133 LookupC = PropertyManager->GetNode( prop );
136 // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
137 // where each non-dimensionalizing parameter for this coefficient is
138 // separated by a | character
140 *AC_cfg >> multparms;
142 end = multparms.length();
143 n = multparms.find("|");
146 if (multparms != string("FG_NONE")) {
147 while (n < end && n >= 0) {
149 mult = multparms.substr(start,n);
150 prop= State->GetPropertyName( State->GetParameterIndex(mult) );
151 multipliers.push_back( PropertyManager->GetNode(prop) );
153 n = multparms.find("|",start);
155 prop=State->GetPropertyName(
156 State->GetParameterIndex( multparms.substr(start,n) ) );
157 mult = multparms.substr(start,n);
158 multipliers.push_back( PropertyManager->GetNode(prop) );
159 // End of non-dimensionalizing parameter read-in
163 *AC_cfg >> StaticValue;
164 } else if (type == VECTOR || type == TABLE) {
167 cerr << "Unimplemented coefficient type: " << type << endl;
170 AC_cfg->GetNextConfigLine();
171 FGCoefficient::Debug(2);
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 double FGCoefficient::Value(double rVal, double cVal)
188 SD = Value = gain*Table->GetValue(rVal, cVal) + bias;
191 for (midx=0; midx < multipliers.size(); midx++) {
192 Value *= multipliers[midx]->getDoubleValue();
197 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 double FGCoefficient::Value(double Val)
203 SD = Value = gain*Table->GetValue(Val) + bias;
205 for (unsigned int midx=0; midx < multipliers.size(); midx++)
206 Value *= multipliers[midx]->getDoubleValue();
211 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 double FGCoefficient::Value(void)
217 SD = Value = gain*StaticValue + bias;
219 for (unsigned int midx=0; midx < multipliers.size(); midx++)
220 Value *= multipliers[midx]->getDoubleValue();
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 double FGCoefficient::TotalValue(void)
237 totalValue=Value( LookupR->getDoubleValue() );
240 totalValue=Value( LookupR->getDoubleValue(),
241 LookupC->getDoubleValue() );
250 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 void FGCoefficient::DumpSD(void)
254 cout << " " << name << ": " << SD << endl;
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 << multipliers[i]->getName() << " ";
274 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 string FGCoefficient::GetCoefficientValues(void)
281 sprintf(buffer,"%9.6f",SD);
282 value = string(buffer);
286 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288 void FGCoefficient::bind(FGPropertyManager *node) {
292 FGCoefficient::node=node;
294 node->SetString("description",description);
295 if(LookupR) node->SetString("row-parm",LookupR->getName() );
296 if(LookupC) node->SetString("column-parm",LookupC->getName() );
299 for (i=0; i<multipliers.size(); i++) {
300 mult += multipliers[i]->getName();
301 if( i < multipliers.size()-1 ) mult += "|";
303 node->SetString("multipliers",mult);
305 node->Tie("SD-norm",this,&FGCoefficient::GetSD );
306 node->Tie("value-lbs",this,&FGCoefficient::GetValue );
308 node->Tie("bias", this, &FGCoefficient::getBias,
309 &FGCoefficient::setBias );
311 node->Tie("gain", this, &FGCoefficient::getGain,
312 &FGCoefficient::setGain );
316 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318 void FGCoefficient::unbind(void) {
319 node->Untie("SD-norm");
320 node->Untie("value-lbs");
324 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 // The bitmasked value choices are as follows:
326 // unset: In this case (the default) JSBSim would only print
327 // out the normally expected messages, essentially echoing
328 // the config files as they are read. If the environment
329 // variable is not set, debug_lvl is set to 1 internally
330 // 0: This requests JSBSim not to output any messages
332 // 1: This value explicity requests the normal JSBSim
334 // 2: This value asks for a message to be printed out when
335 // a class is instantiated
336 // 4: When this value is set, a message is displayed when a
337 // FGModel object executes its Run() method
338 // 8: When this value is set, various runtime state variables
339 // are printed out periodically
340 // 16: When set various parameters are sanity checked and
341 // a message is printed out when they go out of bounds
343 void FGCoefficient::Debug(int from)
345 if (debug_lvl <= 0) return;
347 if (debug_lvl & 1) { // Standard console startup message output
349 if (from == 2) { // Loading
350 cout << "\n " << highint << underon << name << underoff << normint << endl;
351 cout << " " << description << endl;
352 cout << " " << method << endl;
354 if (type == VECTOR || type == TABLE) {
355 cout << " Rows: " << rows << " ";
357 cout << "Cols: " << columns;
359 cout << endl << " Row indexing parameter: " << LookupR->getName() << endl;
363 cout << " Column indexing parameter: " << LookupC->getName() << endl;
367 cout << " Value = " << StaticValue << endl;
368 } else if (type == VECTOR || type == TABLE) {
372 DisplayCoeffFactors();
375 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
376 if (from == 0) cout << "Instantiated: FGCoefficient" << endl;
377 if (from == 1) cout << "Destroyed: FGCoefficient" << endl;
379 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
381 if (debug_lvl & 8 ) { // Runtime state variables
383 if (debug_lvl & 16) { // Sanity checking
385 if (debug_lvl & 64) {
386 if (from == 0) { // Constructor
387 cout << IdSrc << endl;
388 cout << IdHdr << endl;