]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGCoefficient.cpp
Latest jsbsim updates.
[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\r
52 #  include <iomanip.h>\r
53 #else\r
54 #  include STL_IOMANIP\r
55 #endif\r
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     cout << "\n   " << highint << underon << name << underoff << normint << endl;
95     cout << "   " << description << endl;
96     cout << "   " << method << endl;
97
98     if      (method == "EQUATION") type = EQUATION;
99     else if (method == "TABLE")    type = TABLE;
100     else if (method == "VECTOR")   type = VECTOR;
101     else if (method == "VALUE")    type = VALUE;
102     else                           type = UNKNOWN;
103
104     if (type == VECTOR || type == TABLE) {
105       *AC_cfg >> rows;
106       cout << "   Rows: " << rows << " ";
107       if (type == TABLE) {
108         *AC_cfg >> columns;
109         cout << "Cols: " << columns;
110         Table = new FGTable(rows, columns);
111       } else {
112         Table = new FGTable(rows);
113       }
114
115       cout << endl;
116
117       *AC_cfg >> multparms;
118       LookupR = State->GetParameterIndex(multparms);
119       cout << "   Row indexing parameter: " << multparms << endl;
120     }
121
122     if (type == TABLE) {
123       *AC_cfg >> multparms;
124       LookupC = State->GetParameterIndex(multparms);
125       cout << "   Column indexing parameter: " << multparms << endl;
126     }
127
128     // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
129     // where each non-dimensionalizing parameter for this coefficient is
130     // separated by a | character
131
132     *AC_cfg >> multparms;
133
134     end   = multparms.length();
135     n     = multparms.find("|");
136     start = 0;
137
138     while (n < end && n >= 0) {
139       n -= start;
140       multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
141       start += n+1;
142       n = multparms.find("|",start);
143     }
144
145     multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
146
147     // End of non-dimensionalizing parameter read-in
148
149     switch(type) {
150     case VALUE:
151       *AC_cfg >> StaticValue;
152       cout << "      Value = " << StaticValue << endl;
153       break;
154     case VECTOR:
155     case TABLE:
156       *Table << *AC_cfg;
157       Table->Print();
158
159       break;
160     case EQUATION:
161     case UNKNOWN:
162       cerr << "Unimplemented coefficient type: " << type << endl;
163       break;
164     }
165     AC_cfg->GetNextConfigLine();
166   }
167   if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
168 }
169
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171
172 FGCoefficient::~FGCoefficient()
173 {
174   if (Table) delete Table;
175   if (debug_lvl & 2) cout << "Destroyed:    FGCoefficient" << endl;
176 }
177
178 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179
180 float FGCoefficient::Value(float rVal, float cVal)
181 {
182   float Value;
183   unsigned int midx;
184
185   SD = Value = Table->GetValue(rVal, cVal);
186
187   for (midx=0; midx < multipliers.size(); midx++) {
188       Value *= State->GetParameter(multipliers[midx]);
189   }
190   return Value;
191 }
192
193 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194
195 float FGCoefficient::Value(float Val)
196 {
197   float Value;
198
199   SD = Value = Table->GetValue(Val);
200   
201   for (unsigned int midx=0; midx < multipliers.size(); midx++) 
202       Value *= State->GetParameter(multipliers[midx]);
203   
204   return Value;
205 }
206
207 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208
209 float FGCoefficient::Value(void)
210 {
211         float Value;
212
213   SD = Value = StaticValue;
214
215   for (unsigned int midx=0; midx < multipliers.size(); midx++)
216     Value *= State->GetParameter(multipliers[midx]);
217
218   return Value;
219 }
220
221 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222
223 float FGCoefficient::TotalValue()
224 {
225   
226   switch(type) {
227   case 0:
228     return -1;
229   case 1:
230     return (Value());
231   case 2:
232     return (Value(State->GetParameter(LookupR)));
233   case 3:
234     return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC)));
235   case 4:
236     return 0.0;
237   }
238   return 0;
239 }
240
241 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242
243 void FGCoefficient::DumpSD(void)
244 {
245   cout << "   " << name << ": " << SD << endl;
246 }
247
248 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249
250 void FGCoefficient::Debug(void)
251 {
252     //TODO: Add your source code here
253 }
254