]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAerodynamics.cpp
Removed FGMatrix.* because it is no longer used by JSBSim.
[flightgear.git] / src / FDM / JSBSim / FGAerodynamics.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGAerodynamics.cpp
4  Author:       Jon S. Berndt
5  Date started: 09/13/00
6  Purpose:      Encapsulates the aerodynamic forces (gear and collision)
7
8  ------------- Copyright (C) 2000  Jon S. Berndt (jsb@hal-pc.org) -------------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 HISTORY
31 --------------------------------------------------------------------------------
32 09/13/00   JSB   Created
33 04/22/01   JSB   Moved code into here from FGAircraft
34
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 INCLUDES
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39 #include "FGAerodynamics.h"
40 #include "FGFactorGroup.h"
41 #include "FGCoefficient.h"
42
43 static const char *IdSrc = "$Id$";
44 static const char *IdHdr = ID_AERODYNAMICS;
45
46 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 CLASS IMPLEMENTATION
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49
50
51 FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec)
52 {
53   Name = "FGAerodynamics";
54
55   AxisIdx["DRAG"]  = 0;
56   AxisIdx["SIDE"]  = 1;
57   AxisIdx["LIFT"]  = 2;
58   AxisIdx["ROLL"]  = 3;
59   AxisIdx["PITCH"] = 4;
60   AxisIdx["YAW"]   = 5;
61
62   Coeff = new CoeffArray[6];
63
64   Debug(0);
65 }
66
67 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68
69 FGAerodynamics::~FGAerodynamics()
70 {
71   unsigned int i,j;
72   for (i=0; i<6; i++) {
73     for (j=0; j<Coeff[i].size(); j++) {
74       delete Coeff[i][j];
75     }
76   }
77   delete[] Coeff;
78
79   Debug(1);
80 }
81
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84 bool FGAerodynamics::Run(void)
85 {
86   unsigned int axis_ctr,ctr;
87
88   if (!FGModel::Run()) {
89
90     vLastFs = vFs;
91     vFs.InitMatrix();
92
93     for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
94       for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
95         vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
96       }
97     }
98     //correct signs of drag and lift to wind axes convention
99     //positive forward, right, down
100     vFs(1)*=-1; vFs(3)*=-1;
101     //cout << "Aircraft::vFs: " << vFs << endl;
102     vForces = State->GetTs2b()*vFs;
103
104     vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX) 
105                       - MassBalance->GetXYZcg(eX))*inchtoft;
106     vDXYZcg(eY) =  (Aircraft->GetXYZrp(eY) 
107                       - MassBalance->GetXYZcg(eY))*inchtoft;
108     vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ) 
109                       - MassBalance->GetXYZcg(eZ))*inchtoft;
110
111     vMoments = vDXYZcg*vForces; // M = r X F
112
113     for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
114       for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
115         vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
116       }
117     }
118     return false;
119   } else {
120     return true;
121   }
122 }
123
124 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125
126 bool FGAerodynamics::Load(FGConfigFile* AC_cfg)
127 {
128   string token, axis;
129
130   AC_cfg->GetNextConfigLine();
131
132   while ((token = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
133     if (token == "AXIS") {
134       CoeffArray ca;
135       axis = AC_cfg->GetValue("NAME");
136       AC_cfg->GetNextConfigLine();
137       while ((token = AC_cfg->GetValue()) != string("/AXIS")) {
138         if( token == "COEFFICIENT" ) {
139           ca.push_back( new FGCoefficient(FDMExec) );
140           ca.back()->Load(AC_cfg);
141           cm[ca.back()->Getname()]=ca.back();
142         } else if ( token == "GROUP" ) {
143           ca.push_back( new FGFactorGroup(FDMExec) );
144           ca.back()->Load(AC_cfg);
145           cm[ca.back()->Getname()]=ca.back();
146         }
147       }
148       Coeff[AxisIdx[axis]] = ca;
149       AC_cfg->GetNextConfigLine();
150     }
151   }
152
153   return true;
154 }
155
156 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157
158 string FGAerodynamics::GetCoefficientStrings(void)
159 {
160   string CoeffStrings = "";
161   bool firstime = true;
162   unsigned int axis, sd;
163
164   for (axis = 0; axis < 6; axis++) {
165     for (sd = 0; sd < Coeff[axis].size(); sd++) {
166       if (firstime) {
167         firstime = false;
168       } else {
169         CoeffStrings += ", ";
170       }
171       CoeffStrings += Coeff[axis][sd]->GetCoefficientStrings();
172     }
173   }
174   return CoeffStrings;
175 }
176
177 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178
179 string FGAerodynamics::GetCoefficientValues(void)
180 {
181   string SDValues = "";
182   bool firstime = true;
183
184   for (unsigned int axis = 0; axis < 6; axis++) {
185     for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
186       if (firstime) {
187         firstime = false;
188       } else {
189         SDValues += ", ";
190       }
191       SDValues += Coeff[axis][sd]->GetCoefficientValues();
192     }
193   }
194
195   return SDValues;
196 }
197
198 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199
200 double FGAerodynamics::GetLoD(void)
201 {
202   if (vFs(1) != 0.00) return vFs(3)/vFs(1);
203   else                return 0.00;
204 }
205 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 //    The bitmasked value choices are as follows:
207 //    unset: In this case (the default) JSBSim would only print
208 //       out the normally expected messages, essentially echoing
209 //       the config files as they are read. If the environment
210 //       variable is not set, debug_lvl is set to 1 internally
211 //    0: This requests JSBSim not to output any messages
212 //       whatsoever.
213 //    1: This value explicity requests the normal JSBSim
214 //       startup messages
215 //    2: This value asks for a message to be printed out when
216 //       a class is instantiated
217 //    4: When this value is set, a message is displayed when a
218 //       FGModel object executes its Run() method
219 //    8: When this value is set, various runtime state variables
220 //       are printed out periodically
221 //    16: When set various parameters are sanity checked and
222 //       a message is printed out when they go out of bounds
223
224 void FGAerodynamics::Debug(int from)
225 {
226   if (debug_lvl <= 0) return;
227
228   if (debug_lvl & 1) { // Standard console startup message output
229     if (from == 0) { // Constructor
230
231     }
232   }
233   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
234     if (from == 0) cout << "Instantiated: FGAerodynamics" << endl;
235     if (from == 1) cout << "Destroyed:    FGAerodynamics" << endl;
236   }
237   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
238   }
239   if (debug_lvl & 8 ) { // Runtime state variables
240   }
241   if (debug_lvl & 16) { // Sanity checking
242   }
243   if (debug_lvl & 64) {
244     if (from == 0) { // Constructor
245       cout << IdSrc << endl;
246       cout << IdHdr << endl;
247     }
248   }
249 }
250