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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49 #include "FGCoefficient.h"
51 #include "FGFDMExec.h"
52 #include "FGPropertyManager.h"
55 # if defined(sgi) && !defined(__GNUC__)
66 static const char *IdSrc = "$Id$";
67 static const char *IdHdr = ID_COEFFICIENT;
69 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
73 FGCoefficient::FGCoefficient( FGFDMExec* fdex )
76 State = FDMExec->GetState();
79 PropertyManager = FDMExec->GetPropertyManager();
82 LookupR = LookupC = 0;
103 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 FGCoefficient::~FGCoefficient()
107 if (Table) delete Table;
111 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 bool FGCoefficient::Load(FGConfigFile *AC_cfg)
119 name = AC_cfg->GetValue("NAME");
120 method = AC_cfg->GetValue("TYPE");
121 AC_cfg->GetNextConfigLine();
122 *AC_cfg >> description;
123 if (method == "EQUATION") type = EQUATION;
124 else if (method == "TABLE") type = TABLE;
125 else if (method == "VECTOR") type = VECTOR;
126 else if (method == "VALUE") type = VALUE;
129 if (type == VECTOR || type == TABLE) {
133 Table = new FGTable(rows, columns);
135 Table = new FGTable(rows);
138 *AC_cfg >> multparmsRow;
139 LookupR = PropertyManager->GetNode( multparmsRow );
143 *AC_cfg >> multparmsCol;
145 LookupC = PropertyManager->GetNode( multparmsCol );
148 // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
149 // where each non-dimensionalizing parameter for this coefficient is
150 // separated by a | character
152 string line=AC_cfg->GetCurrentLine();
155 for(unsigned i=0;i<line.length(); i++ ) {
156 if( !isspace(line[i]) ) {
161 tmp[j]='\0'; multparms=tmp;
162 end = multparms.length();
164 n = multparms.find("|");
166 if (multparms != string("none")) {
167 while (n < end && n >= 0) {
169 mult = multparms.substr(start,n);
170 multipliers.push_back( resolveSymbol( mult ) );
172 n = multparms.find("|",start);
174 mult = multparms.substr(start,n);
175 multipliers.push_back( resolveSymbol( mult ) );
176 // End of non-dimensionalizing parameter read-in
178 AC_cfg->GetNextConfigLine();
180 *AC_cfg >> StaticValue;
181 } else if (type == VECTOR || type == TABLE) {
184 cerr << "Unimplemented coefficient type: " << type << endl;
187 AC_cfg->GetNextConfigLine();
188 FGCoefficient::Debug(2);
198 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 double FGCoefficient::Value(double rVal, double cVal)
205 SD = Value = gain*Table->GetValue(rVal, cVal) + bias;
207 for (midx=0; midx < multipliers.size(); midx++) {
208 Value *= multipliers[midx]->getDoubleValue();
213 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 double FGCoefficient::Value(double Val)
219 SD = Value = gain*Table->GetValue(Val) + bias;
221 for (unsigned int midx=0; midx < multipliers.size(); midx++)
222 Value *= multipliers[midx]->getDoubleValue();
227 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 double FGCoefficient::Value(void)
233 SD = Value = gain*StaticValue + bias;
235 for (unsigned int midx=0; midx < multipliers.size(); midx++)
236 Value *= multipliers[midx]->getDoubleValue();
241 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 double FGCoefficient::TotalValue(void)
252 totalValue = Value();
256 totalValue = Value( LookupR->getDoubleValue() );
260 totalValue = Value( LookupR->getDoubleValue(),
261 LookupC->getDoubleValue() );
271 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273 void FGCoefficient::DisplayCoeffFactors(void)
277 cout << " Non-Dimensionalized by: ";
279 if (multipliers.size() == 0) {
280 cout << "none" << endl;
282 for (i=0; i<multipliers.size(); i++)
283 cout << multipliers[i]->getName() << " ";
288 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 string FGCoefficient::GetSDstring(void)
295 sprintf(buffer,"%9.6f",SD);
296 value = string(buffer);
300 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 void FGCoefficient::bind(FGPropertyManager *parent)
307 node = parent->GetNode(name,true);
309 node->SetString("description",description);
310 if (LookupR) node->SetString("row-parm",LookupR->getName() );
311 if (LookupC) node->SetString("column-parm",LookupC->getName() );
314 if (multipliers.size() == 0)
317 for (i=0; i<multipliers.size(); i++) {
318 mult += multipliers[i]->getName();
319 if ( i < multipliers.size()-1 ) mult += " ";
321 node->SetString("multipliers",mult);
323 node->Tie("SD-norm",this,&FGCoefficient::GetSD );
324 node->Tie("value-lbs",this,&FGCoefficient::GetValue );
326 node->Tie("bias", this, &FGCoefficient::getBias,
327 &FGCoefficient::setBias );
329 node->Tie("gain", this, &FGCoefficient::getGain,
330 &FGCoefficient::setGain );
334 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 void FGCoefficient::unbind(void)
338 node->Untie("SD-norm");
339 node->Untie("value-lbs");
344 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346 FGPropertyManager* FGCoefficient::resolveSymbol(string name)
348 FGPropertyManager* tmpn;
350 tmpn = PropertyManager->GetNode(name,false);
352 cerr << "Coefficient multipliers cannot create properties, check spelling?" << endl;
358 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
359 // The bitmasked value choices are as follows:
360 // unset: In this case (the default) JSBSim would only print
361 // out the normally expected messages, essentially echoing
362 // the config files as they are read. If the environment
363 // variable is not set, debug_lvl is set to 1 internally
364 // 0: This requests JSBSim not to output any messages
366 // 1: This value explicity requests the normal JSBSim
368 // 2: This value asks for a message to be printed out when
369 // a class is instantiated
370 // 4: When this value is set, a message is displayed when a
371 // FGModel object executes its Run() method
372 // 8: When this value is set, various runtime state variables
373 // are printed out periodically
374 // 16: When set various parameters are sanity checked and
375 // a message is printed out when they go out of bounds
377 void FGCoefficient::Debug(int from)
379 if (debug_lvl <= 0) return;
381 if (debug_lvl & 1) { // Standard console startup message output
383 if (from == 2) { // Loading
384 cout << "\n " << highint << underon << name << underoff << normint << endl;
385 cout << " " << description << endl;
386 cout << " " << method << endl;
388 if (type == VECTOR || type == TABLE) {
389 cout << " Rows: " << rows << " ";
391 cout << "Cols: " << columns;
393 cout << endl << " Row indexing parameter: " << LookupR->getName() << endl;
397 cout << " Column indexing parameter: " << LookupC->getName() << endl;
401 cout << " Value = " << StaticValue << endl;
402 } else if (type == VECTOR || type == TABLE) {
406 DisplayCoeffFactors();
409 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
410 if (from == 0) cout << "Instantiated: FGCoefficient" << endl;
411 if (from == 1) cout << "Destroyed: FGCoefficient" << endl;
413 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
415 if (debug_lvl & 8 ) { // Runtime state variables
417 if (debug_lvl & 16) { // Sanity checking
419 if (debug_lvl & 64) {
420 if (from == 0) { // Constructor
421 cout << IdSrc << endl;
422 cout << IdHdr << endl;
427 } // namespace JSBSim