]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAerodynamics.cpp
JSBSim tweaks.
[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
41 static const char *IdSrc = "$Id$";
42 static const char *IdHdr = ID_AERODYNAMICS;
43
44 extern short debug_lvl;
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   float alpha, beta;
92   unsigned int axis_ctr,ctr;
93
94   if (!FGModel::Run()) {
95
96     alpha = Translation->Getalpha();
97     beta = Translation->Getbeta();
98
99     vLastFs = vFs;
100     vFs.InitMatrix();
101
102     for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
103       for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
104         vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
105       }
106     }
107
108     vForces = State->GetTs2b(alpha, beta)*vFs;
109
110     // see http://home.earthlink.net/~apeden/jsbsim_moments_due_to_forces.txt
111     // for details on this
112
113     vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX) - MassBalance->GetXYZcg(eX))/12.0;
114     vDXYZcg(eY) =  (Aircraft->GetXYZrp(eY) - MassBalance->GetXYZcg(eY))/12.0;
115     vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ) - MassBalance->GetXYZcg(eZ))/12.0;
116
117     vMoments(eL) = vForces(eZ)*vDXYZcg(eY) - vForces(eY)*vDXYZcg(eZ);
118     vMoments(eM) = vForces(eX)*vDXYZcg(eZ) - vForces(eZ)*vDXYZcg(eX);
119     vMoments(eN) = vForces(eY)*vDXYZcg(eX) - vForces(eX)*vDXYZcg(eY);
120
121     for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
122       for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
123         vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
124       }
125     }
126     return false;
127   } else {
128     return true;
129   }
130 }
131
132 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133
134 bool FGAerodynamics::LoadAerodynamics(FGConfigFile* AC_cfg)
135 {
136   string token, axis;
137
138   AC_cfg->GetNextConfigLine();
139
140   while ((token = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
141     if (token == "AXIS") {
142       CoeffArray ca;
143       axis = AC_cfg->GetValue("NAME");
144       AC_cfg->GetNextConfigLine();
145       while ((token = AC_cfg->GetValue()) != string("/AXIS")) {
146         ca.push_back(new FGCoefficient(FDMExec, AC_cfg));
147         if (debug_lvl > 0) DisplayCoeffFactors(ca.back()->Getmultipliers());
148       }
149       Coeff[AxisIdx[axis]] = ca;
150       AC_cfg->GetNextConfigLine();
151     }
152   }
153
154   return true;
155 }
156
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158
159 void FGAerodynamics::DisplayCoeffFactors(vector <eParam> multipliers)
160 {
161   unsigned int i;
162
163   cout << "   Non-Dimensionalized by: ";
164
165   for (i=0; i<multipliers.size();i++) cout << State->paramdef[multipliers[i]];
166
167   cout << endl;
168 }
169
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171
172 string FGAerodynamics::GetCoefficientStrings(void)
173 {
174   string CoeffStrings = "";
175   bool firstime = true;
176   unsigned int axis, sd;
177
178   for (axis = 0; axis < 6; axis++) {
179     for (sd = 0; sd < Coeff[axis].size(); sd++) {
180       if (firstime) {
181         firstime = false;
182       } else {
183         CoeffStrings += ", ";
184       }
185       CoeffStrings += Coeff[axis][sd]->Getname();
186     }
187   }
188
189   return CoeffStrings;
190 }
191
192 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193
194 string FGAerodynamics::GetCoefficientValues(void)
195 {
196   string SDValues = "";
197   char buffer[10];
198   bool firstime = true;
199
200   for (unsigned int axis = 0; axis < 6; axis++) {
201     for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
202       if (firstime) {
203         firstime = false;
204       } else {
205         SDValues += ", ";
206       }
207       sprintf(buffer, "%9.6f", Coeff[axis][sd]->GetSD());
208       SDValues += string(buffer);
209     }
210   }
211
212   return SDValues;
213 }
214
215 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216
217 float FGAerodynamics::GetNlf(void)
218 {
219   if (fabs(Position->GetGamma()) < 1.57) {
220     return (vFs(eZ)/(MassBalance->GetWeight()*cos(Position->GetGamma())));
221   } else {
222     return 0.0;
223   }
224 }
225
226 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227
228 float FGAerodynamics::GetLoD(void)
229 {
230   float LoD;
231
232   if (vFs(1) != 0.00) return vFs(3)/vFs(1);
233   else                return 0.00;
234 }
235
236 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237
238 void FGAerodynamics::Debug(void)
239 {
240     //TODO: Add your source code here
241 }
242