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__) && (_COMPILER_VERSION < 740)
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;
84 rows = columns = tables = 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 == "TABLE3D") type = TABLE3D;
126 else if (method == "VECTOR") type = VECTOR;
127 else if (method == "VALUE") type = VALUE;
130 if (type == VECTOR || type == TABLE || type == TABLE3D) {
132 if (type == TABLE3D) {
133 *AC_cfg >> rows >> columns >> tables;
134 Table = new FGTable(rows, columns, tables);
135 *AC_cfg >> multparmsRow >> multparmsCol >> multparmsTable;
136 LookupR = PropertyManager->GetNode( multparmsRow );
137 LookupC = PropertyManager->GetNode( multparmsCol );
138 LookupT = PropertyManager->GetNode( multparmsTable );
139 } else if (type == TABLE) {
140 *AC_cfg >> rows >> columns;
141 Table = new FGTable(rows, columns);
142 *AC_cfg >> multparmsRow >> multparmsCol;
143 LookupR = PropertyManager->GetNode( multparmsRow );
144 LookupC = PropertyManager->GetNode( multparmsCol );
147 Table = new FGTable(rows);
148 *AC_cfg >> multparmsRow;
149 LookupR = PropertyManager->GetNode( multparmsRow );
153 // Here, read in the line of the form:
154 // {property1} | {property2} | {property3}
155 // where each non-dimensionalizing property for this coefficient is
156 // separated by a | character
158 string line=AC_cfg->GetCurrentLine();
161 for(unsigned i=0;i<line.length(); i++ ) {
162 if( !isspace(line[i]) ) {
167 tmp[j]='\0'; multparms=tmp;
168 end = multparms.length();
170 n = multparms.find("|");
171 if (n == string::npos) n = end;
173 if (multparms != string("none")) {
174 while (n < end && n != string::npos) {
176 mult = multparms.substr(start,n);
177 multipliers.push_back( resolveSymbol( mult ) );
179 n = multparms.find("|",start);
181 mult = multparms.substr(start,n);
182 multipliers.push_back( resolveSymbol( mult ) );
183 // End of non-dimensionalizing parameter read-in
185 AC_cfg->GetNextConfigLine();
188 *AC_cfg >> StaticValue;
189 } else if (type == VECTOR || type == TABLE || type == TABLE3D) {
192 cerr << "Unimplemented coefficient type: " << type << endl;
195 AC_cfg->GetNextConfigLine();
196 FGCoefficient::Debug(2);
206 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 double FGCoefficient::Value(double rVal, double cVal, double tVal)
213 SD = Value = gain*Table->GetValue(rVal, cVal, tVal) + bias;
215 for (midx=0; midx < multipliers.size(); midx++) {
216 Value *= multipliers[midx]->getDoubleValue();
221 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 double FGCoefficient::Value(double rVal, double cVal)
228 SD = Value = gain*Table->GetValue(rVal, cVal) + bias;
230 for (midx=0; midx < multipliers.size(); midx++) {
231 Value *= multipliers[midx]->getDoubleValue();
236 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 double FGCoefficient::Value(double Val)
242 SD = Value = gain*Table->GetValue(Val) + bias;
244 for (unsigned int midx=0; midx < multipliers.size(); midx++)
245 Value *= multipliers[midx]->getDoubleValue();
250 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 double FGCoefficient::Value(void)
256 SD = Value = gain*StaticValue + bias;
258 for (unsigned int midx=0; midx < multipliers.size(); midx++)
259 Value *= multipliers[midx]->getDoubleValue();
264 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266 double FGCoefficient::TotalValue(void)
275 totalValue = Value();
279 totalValue = Value( LookupR->getDoubleValue() );
283 totalValue = Value( LookupR->getDoubleValue(),
284 LookupC->getDoubleValue() );
288 totalValue = Value( LookupR->getDoubleValue(),
289 LookupC->getDoubleValue(),
290 LookupT->getDoubleValue() );
300 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 void FGCoefficient::DisplayCoeffFactors(void)
306 cout << " Non-Dimensionalized by: ";
308 if (multipliers.size() == 0) {
309 cout << "none" << endl;
311 for (i=0; i<multipliers.size(); i++)
312 cout << multipliers[i]->getName() << " ";
317 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
319 string FGCoefficient::GetSDstring(void)
324 sprintf(buffer,"%9.6f",SD);
325 value = string(buffer);
329 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 void FGCoefficient::bind(FGPropertyManager *parent)
336 node = parent->GetNode(name,true);
338 node->SetString("description",description);
339 if (LookupR) node->SetString("row-parm",LookupR->getName() );
340 if (LookupC) node->SetString("column-parm",LookupC->getName() );
343 if (multipliers.size() == 0)
346 for (i=0; i<multipliers.size(); i++) {
347 mult += multipliers[i]->getName();
348 if ( i < multipliers.size()-1 ) mult += " ";
350 node->SetString("multipliers",mult);
352 node->Tie("SD-norm",this,&FGCoefficient::GetSD );
353 node->Tie("value-lbs",this,&FGCoefficient::GetValue );
355 node->Tie("bias", this, &FGCoefficient::getBias,
356 &FGCoefficient::setBias );
358 node->Tie("gain", this, &FGCoefficient::getGain,
359 &FGCoefficient::setGain );
363 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365 void FGCoefficient::unbind(void)
367 node->Untie("SD-norm");
368 node->Untie("value-lbs");
373 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375 FGPropertyManager* FGCoefficient::resolveSymbol(string name)
377 FGPropertyManager* tmpn;
379 tmpn = PropertyManager->GetNode(name,false);
381 cerr << "Coefficient multipliers cannot create properties, check spelling?" << endl;
387 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388 // The bitmasked value choices are as follows:
389 // unset: In this case (the default) JSBSim would only print
390 // out the normally expected messages, essentially echoing
391 // the config files as they are read. If the environment
392 // variable is not set, debug_lvl is set to 1 internally
393 // 0: This requests JSBSim not to output any messages
395 // 1: This value explicity requests the normal JSBSim
397 // 2: This value asks for a message to be printed out when
398 // a class is instantiated
399 // 4: When this value is set, a message is displayed when a
400 // FGModel object executes its Run() method
401 // 8: When this value is set, various runtime state variables
402 // are printed out periodically
403 // 16: When set various parameters are sanity checked and
404 // a message is printed out when they go out of bounds
406 void FGCoefficient::Debug(int from)
408 if (debug_lvl <= 0) return;
410 if (debug_lvl & 1) { // Standard console startup message output
412 if (from == 2) { // Loading
413 cout << "\n " << highint << underon << name << underoff << normint << endl;
414 cout << " " << description << endl;
415 cout << " " << method << endl;
417 if (type == VECTOR || type == TABLE || type == TABLE3D) {
418 cout << " Rows: " << rows << " indexed by: " << LookupR->getName() << endl;
419 if (type == TABLE || type == TABLE3D) {
420 cout << " Cols: " << columns << " indexed by: " << LookupC->getName() << endl;
421 if (type == TABLE3D) {
422 cout << " Tables: " << tables << " indexed by: " << LookupT->getName() << endl;
426 } else if (type == VALUE) {
427 cout << " Value = " << StaticValue << endl;
430 DisplayCoeffFactors();
433 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
434 if (from == 0) cout << "Instantiated: FGCoefficient" << endl;
435 if (from == 1) cout << "Destroyed: FGCoefficient" << endl;
437 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
439 if (debug_lvl & 8 ) { // Runtime state variables
441 if (debug_lvl & 16) { // Sanity checking
443 if (debug_lvl & 64) {
444 if (from == 0) { // Constructor
445 cout << IdSrc << endl;
446 cout << IdHdr << endl;
451 } // namespace JSBSim