]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAerodynamics.cpp
Synced with latest JSBSim cvs.
[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     vMoments(3),
53     vForces(3),
54     vFs(3),
55     vLastFs(3),
56     vDXYZcg(3)
57 {
58   Name = "FGAerodynamics";
59
60   AxisIdx["DRAG"]  = 0;
61   AxisIdx["SIDE"]  = 1;
62   AxisIdx["LIFT"]  = 2;
63   AxisIdx["ROLL"]  = 3;
64   AxisIdx["PITCH"] = 4;
65   AxisIdx["YAW"]   = 5;
66
67   Coeff = new CoeffArray[6];
68
69   if (debug_lvl & 2) cout << "Instantiated: FGAerodynamics" << endl;
70 }
71
72 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73
74 FGAerodynamics::~FGAerodynamics()
75 {
76   unsigned int i,j;
77   for (i=0; i<6; i++) {
78     for (j=0; j<Coeff[i].size(); j++) {
79       delete Coeff[i][j];
80     }
81   }
82   delete[] Coeff;
83
84   if (debug_lvl & 2) cout << "Destroyed:    FGAerodynamics" << endl;
85 }
86
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
89 bool FGAerodynamics::Run(void)
90 {
91   unsigned int axis_ctr,ctr;
92
93   if (!FGModel::Run()) {
94
95     vLastFs = vFs;
96     vFs.InitMatrix();
97
98     for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
99       for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
100         vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
101       }
102     }
103
104     vForces = State->GetTs2b()*vFs;
105
106     vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX) 
107                       - MassBalance->GetXYZcg(eX))*inchtoft;
108     vDXYZcg(eY) =  (Aircraft->GetXYZrp(eY) 
109                       - MassBalance->GetXYZcg(eY))*inchtoft;
110     vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ) 
111                       - MassBalance->GetXYZcg(eZ))*inchtoft;
112
113     vMoments = vDXYZcg*vForces; // M = r X F
114
115     for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
116       for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
117         vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
118       }
119     }
120     return false;
121   } else {
122     return true;
123   }
124 }
125
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
128 bool FGAerodynamics::Load(FGConfigFile* AC_cfg)
129 {
130   string token, axis;
131
132   AC_cfg->GetNextConfigLine();
133
134   while ((token = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
135     if (token == "AXIS") {
136       CoeffArray ca;
137       axis = AC_cfg->GetValue("NAME");
138       AC_cfg->GetNextConfigLine();
139       while ((token = AC_cfg->GetValue()) != string("/AXIS")) {
140         if( token == "COEFFICIENT" ) {
141           ca.push_back( new FGCoefficient(FDMExec) );
142           ca.back()->Load(AC_cfg);
143         } else if ( token == "GROUP" ) {
144           ca.push_back( new FGFactorGroup(FDMExec) );
145           ca.back()->Load(AC_cfg);
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   char buffer[10];
183   bool firstime = true;
184
185   for (unsigned int axis = 0; axis < 6; axis++) {
186     for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
187       if (firstime) {
188         firstime = false;
189       } else {
190         SDValues += ", ";
191       }
192       SDValues += Coeff[axis][sd]->GetCoefficientValues();
193     }
194   }
195
196   return SDValues;
197 }
198
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200
201 double FGAerodynamics::GetNlf(void)
202 {
203   if (fabs(Position->GetGamma()) < 1.57) {
204     return (vFs(eZ)/(MassBalance->GetWeight()*cos(Position->GetGamma())));
205   } else {
206     return 0.0;
207   }
208 }
209
210 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211
212 double FGAerodynamics::GetLoD(void)
213 {
214   double LoD;
215
216   if (vFs(1) != 0.00) return vFs(3)/vFs(1);
217   else                return 0.00;
218 }
219
220 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221
222 void FGAerodynamics::Debug(void)
223 {
224     //TODO: Add your source code here
225 }
226