]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGCoefficient.cpp
JSBSim tweaks.
[flightgear.git] / src / FDM / JSBSim / FGCoefficient.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGCoefficient.cpp
4  Author:       Jon S. Berndt
5  Date started: 12/28/98
6  Purpose:      Encapsulates the stability derivative class FGCoefficient;
7  Called by:    FGAircraft
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10
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
14  version.
15
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
19  details.
20
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.
24
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
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.
32
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.
36
37 See the header file FGCoefficient.h for the values of the identifiers.
38
39 HISTORY
40 --------------------------------------------------------------------------------
41 12/28/98   JSB   Created
42
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 INCLUDES
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #include "FGCoefficient.h"
48 #include "FGState.h"
49 #include "FGFDMExec.h"
50
51 #ifndef FGFS
52 #  include <iomanip>
53 #else
54 #  include STL_IOMANIP
55 #endif
56
57 static const char *IdSrc = "$Id$";
58 static const char *IdHdr = ID_COEFFICIENT;
59
60 extern char highint[5];
61 extern char halfint[5];
62 extern char normint[6];
63 extern char reset[5];
64 extern char underon[5];
65 extern char underoff[6];
66 extern char fgblue[6];
67 extern char fgcyan[6];
68 extern char fgred[6];
69 extern char fggreen[6];
70 extern char fgdef[6];
71
72 extern short debug_lvl;
73
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 CLASS IMPLEMENTATION
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77
78 FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg)
79 {
80   int start, end, n;
81   string multparms;
82
83   FDMExec = fdex;
84   State   = FDMExec->GetState();
85   Table   = 0;
86
87   if (AC_cfg) {
88     name = AC_cfg->GetValue("NAME");
89     method = AC_cfg->GetValue("TYPE");
90
91     AC_cfg->GetNextConfigLine();
92     *AC_cfg >> description;
93
94     if (debug_lvl > 0) {
95       cout << "\n   " << highint << underon << name << underoff << normint << endl;
96       cout << "   " << description << endl;
97       cout << "   " << method << endl;
98     }
99
100     if      (method == "EQUATION") type = EQUATION;
101     else if (method == "TABLE")    type = TABLE;
102     else if (method == "VECTOR")   type = VECTOR;
103     else if (method == "VALUE")    type = VALUE;
104     else                           type = UNKNOWN;
105
106     if (type == VECTOR || type == TABLE) {
107       *AC_cfg >> rows;
108       if (debug_lvl > 0) cout << "   Rows: " << rows << " ";
109       if (type == TABLE) {
110         *AC_cfg >> columns;
111         if (debug_lvl > 0) cout << "Cols: " << columns;
112         Table = new FGTable(rows, columns);
113       } else {
114         Table = new FGTable(rows);
115       }
116
117       if (debug_lvl > 0) cout << endl;
118
119       *AC_cfg >> multparms;
120       LookupR = State->GetParameterIndex(multparms);
121       if (debug_lvl > 0) cout << "   Row indexing parameter: " << multparms << endl;
122     }
123
124     if (type == TABLE) {
125       *AC_cfg >> multparms;
126       LookupC = State->GetParameterIndex(multparms);
127       if (debug_lvl > 0) cout << "   Column indexing parameter: " << multparms << endl;
128     }
129
130     // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
131     // where each non-dimensionalizing parameter for this coefficient is
132     // separated by a | character
133
134     *AC_cfg >> multparms;
135
136     end   = multparms.length();
137     n     = multparms.find("|");
138     start = 0;
139
140     while (n < end && n >= 0) {
141       n -= start;
142       multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
143       start += n+1;
144       n = multparms.find("|",start);
145     }
146
147     multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
148
149     // End of non-dimensionalizing parameter read-in
150
151     switch(type) {
152     case VALUE:
153       *AC_cfg >> StaticValue;
154       if (debug_lvl > 0) cout << "      Value = " << StaticValue << endl;
155       break;
156     case VECTOR:
157     case TABLE:
158       *Table << *AC_cfg;
159       if (debug_lvl > 0) Table->Print();
160       break;
161     case EQUATION:
162     case UNKNOWN:
163       cerr << "Unimplemented coefficient type: " << type << endl;
164       break;
165     }
166     AC_cfg->GetNextConfigLine();
167   }
168   if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
169 }
170
171 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172
173 FGCoefficient::~FGCoefficient()
174 {
175   if (Table) delete Table;
176   if (debug_lvl & 2) cout << "Destroyed:    FGCoefficient" << endl;
177 }
178
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180
181 float FGCoefficient::Value(float rVal, float cVal)
182 {
183   float Value;
184   unsigned int midx;
185
186   SD = Value = Table->GetValue(rVal, cVal);
187
188   for (midx=0; midx < multipliers.size(); midx++) {
189       Value *= State->GetParameter(multipliers[midx]);
190   }
191   return Value;
192 }
193
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195
196 float FGCoefficient::Value(float Val)
197 {
198   float Value;
199
200   SD = Value = Table->GetValue(Val);
201   
202   for (unsigned int midx=0; midx < multipliers.size(); midx++) 
203       Value *= State->GetParameter(multipliers[midx]);
204   
205   return Value;
206 }
207
208 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209
210 float FGCoefficient::Value(void)
211 {
212         float Value;
213
214   SD = Value = StaticValue;
215
216   for (unsigned int midx=0; midx < multipliers.size(); midx++)
217     Value *= State->GetParameter(multipliers[midx]);
218
219   return Value;
220 }
221
222 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223
224 float FGCoefficient::TotalValue()
225 {
226   
227   switch(type) {
228   case 0:
229     return -1;
230   case 1:
231     return (Value());
232   case 2:
233     return (Value(State->GetParameter(LookupR)));
234   case 3:
235     return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC)));
236   case 4:
237     return 0.0;
238   }
239   return 0;
240 }
241
242 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243
244 void FGCoefficient::DumpSD(void)
245 {
246   cout << "   " << name << ": " << SD << endl;
247 }
248
249 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250
251 void FGCoefficient::Debug(void)
252 {
253     //TODO: Add your source code here
254 }
255