1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGAerodynamics.cpp
6 Purpose: Encapsulates the aerodynamic forces (gear and collision)
8 ------------- Copyright (C) 2000 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
31 --------------------------------------------------------------------------------
33 04/22/01 JSB Moved code into here from FGAircraft
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 #include "FGAerodynamics.h"
40 #include "FGPropagate.h"
41 #include "FGAircraft.h"
43 #include "FGMassBalance.h"
44 #include "FGFactorGroup.h"
45 #include "FGPropertyManager.h"
49 static const char *IdSrc = "$Id$";
50 static const char *IdHdr = ID_AERODYNAMICS;
52 const unsigned NAxes=6;
53 const char* AxisNames[] = { "drag", "side-force", "lift", "rolling-moment",
54 "pitching-moment","yawing-moment" };
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec)
63 Name = "FGAerodynamics";
72 Coeff = new CoeffArray[6];
74 impending_stall = stall_hyst = 0.0;
75 alphaclmin = alphaclmax = 0.0;
76 alphahystmin = alphahystmax = 0.0;
79 bi2vel = ci2vel = 0.0;
85 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 FGAerodynamics::~FGAerodynamics()
94 for (j=0; j<Coeff[i].size(); j++) {
103 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 bool FGAerodynamics::Run(void)
107 unsigned int axis_ctr,ctr;
108 double alpha, twovel;
110 if (!FGModel::Run()) {
112 twovel = 2*Auxiliary->GetVt();
114 bi2vel = Aircraft->GetWingSpan() / twovel;
115 ci2vel = Aircraft->Getcbar() / twovel;
118 alphaw = Auxiliary->Getalpha() + Aircraft->GetWingIncidence();
120 alpha = Auxiliary->Getalpha();
122 if (alphaclmax != 0) {
123 if (alpha > 0.85*alphaclmax) {
124 impending_stall = 10*(alpha/alphaclmax - 0.85);
130 if (alphahystmax != 0.0 && alphahystmin != 0.0) {
131 if (alpha > alphahystmax) {
133 } else if (alpha < alphahystmin) {
141 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
142 for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
143 vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
147 //correct signs of drag and lift to wind axes convention
148 //positive forward, right, down
149 if ( Auxiliary->Getqbar() > 0) {
150 clsq = vFs(eLift) / (Aircraft->GetWingArea()*Auxiliary->Getqbar());
153 if ( vFs(eDrag) > 0) {
154 lod = vFs(eLift) / vFs(eDrag);
157 //correct signs of drag and lift to wind axes convention
158 //positive forward, right, down
159 vFs(eDrag)*=-1; vFs(eLift)*=-1;
161 vForces = State->GetTs2b()*vFs;
163 vDXYZcg = MassBalance->StructuralToBody(Aircraft->GetXYZrp());
165 vMoments = vDXYZcg*vForces; // M = r X F
167 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
168 for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
169 vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 bool FGAerodynamics::Load(FGConfigFile* AC_cfg)
183 string parameter, axis, scratch;
185 AC_cfg->GetNextConfigLine();
187 while ((parameter = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
188 if (parameter == "AXIS") {
190 axis = AC_cfg->GetValue("NAME");
191 AC_cfg->GetNextConfigLine();
192 while ((parameter = AC_cfg->GetValue()) != string("/AXIS")) {
193 if ( parameter == "COEFFICIENT" ) {
194 ca.push_back( new FGCoefficient(FDMExec) );
195 ca.back()->Load(AC_cfg);
196 } else if ( parameter == "GROUP" ) {
197 ca.push_back( new FGFactorGroup(FDMExec) );
198 ca.back()->Load(AC_cfg);
201 Coeff[AxisIdx[axis]] = ca;
202 AC_cfg->GetNextConfigLine();
203 } else if (parameter == "AC_ALPHALIMITS") {
204 *AC_cfg >> scratch >> alphaclmin >> alphaclmax;
205 if (debug_lvl > 0) cout << " Maximum Alpha: " << alphaclmax
206 << " Minimum Alpha: " << alphaclmin
208 } else if (parameter == "AC_HYSTLIMITS") {
209 *AC_cfg >> scratch >> alphahystmin >> alphahystmax;
210 if (debug_lvl > 0) cout << " Hysteresis Start: " << alphahystmax
211 << " Hysteresis End: " << alphahystmin
221 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 string FGAerodynamics::GetCoefficientStrings(string delimeter)
225 string CoeffStrings = "";
226 bool firstime = true;
227 unsigned int axis, sd;
229 for (axis = 0; axis < 6; axis++) {
230 for (sd = 0; sd < Coeff[axis].size(); sd++) {
234 CoeffStrings += delimeter;
236 CoeffStrings += Coeff[axis][sd]->GetCoefficientName();
242 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 string FGAerodynamics::GetCoefficientValues(string delimeter)
246 string SDValues = "";
247 bool firstime = true;
249 for (unsigned int axis = 0; axis < 6; axis++) {
250 for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
254 SDValues += delimeter;
256 SDValues += Coeff[axis][sd]->GetSDstring();
263 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 void FGAerodynamics::bind(void)
267 typedef double (FGAerodynamics::*PMF)(int) const;
269 PropertyManager->Tie("forces/fbx-aero-lbs", this,1,
270 (PMF)&FGAerodynamics::GetForces);
271 PropertyManager->Tie("forces/fby-aero-lbs", this,2,
272 (PMF)&FGAerodynamics::GetForces);
273 PropertyManager->Tie("forces/fbz-aero-lbs", this,3,
274 (PMF)&FGAerodynamics::GetForces);
275 PropertyManager->Tie("moments/l-aero-lbsft", this,1,
276 (PMF)&FGAerodynamics::GetMoments);
277 PropertyManager->Tie("moments/m-aero-lbsft", this,2,
278 (PMF)&FGAerodynamics::GetMoments);
279 PropertyManager->Tie("moments/n-aero-lbsft", this,3,
280 (PMF)&FGAerodynamics::GetMoments);
281 PropertyManager->Tie("forces/fwx-aero-lbs", this,1,
282 (PMF)&FGAerodynamics::GetvFs);
283 PropertyManager->Tie("forces/fwy-aero-lbs", this,2,
284 (PMF)&FGAerodynamics::GetvFs);
285 PropertyManager->Tie("forces/fwz-aero-lbs", this,3,
286 (PMF)&FGAerodynamics::GetvFs);
287 PropertyManager->Tie("forces/lod-norm", this,
288 &FGAerodynamics::GetLoD);
289 PropertyManager->Tie("aero/cl-squared-norm", this,
290 &FGAerodynamics::GetClSquared);
291 PropertyManager->Tie("aero/alpha-max-deg", this,
292 &FGAerodynamics::GetAlphaCLMax,
293 &FGAerodynamics::SetAlphaCLMax,
295 PropertyManager->Tie("aero/alpha-min-deg", this,
296 &FGAerodynamics::GetAlphaCLMin,
297 &FGAerodynamics::SetAlphaCLMin,
299 PropertyManager->Tie("aero/bi2vel", this,
300 &FGAerodynamics::GetBI2Vel);
301 PropertyManager->Tie("aero/ci2vel", this,
302 &FGAerodynamics::GetCI2Vel);
303 PropertyManager->Tie("aero/alpha-wing-rad", this,
304 &FGAerodynamics::GetAlphaW);
305 PropertyManager->Tie("systems/stall-warn-norm", this,
306 &FGAerodynamics::GetStallWarn);
307 PropertyManager->Tie("aero/stall-hyst-norm", this,
308 &FGAerodynamics::GetHysteresisParm);
311 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 void FGAerodynamics::bindModel(void)
316 FGPropertyManager* node;
317 string axis_node_name;
318 node = PropertyManager->GetNode("aero/buildup",true);
319 for (i=0;i<NAxes;i++) {
320 node = node->GetNode( string(AxisNames[i]),true );
321 for (j=0; j < Coeff[i].size(); j++) {
322 Coeff[i][j]->bind(node);
324 node = (FGPropertyManager*)node->getParent();
328 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330 void FGAerodynamics::unbind(void)
334 PropertyManager->Untie("forces/fbx-aero-lbs");
335 PropertyManager->Untie("forces/fby-aero-lbs");
336 PropertyManager->Untie("forces/fbz-aero-lbs");
337 PropertyManager->Untie("moments/l-aero-lbsft");
338 PropertyManager->Untie("moments/m-aero-lbsft");
339 PropertyManager->Untie("moments/n-aero-lbsft");
340 PropertyManager->Untie("forces/fwx-aero-lbs");
341 PropertyManager->Untie("forces/fwy-aero-lbs");
342 PropertyManager->Untie("forces/fwz-aero-lbs");
343 PropertyManager->Untie("forces/lod-norm");
344 PropertyManager->Untie("aero/cl-squared-norm");
345 PropertyManager->Untie("aero/alpha-max-deg");
346 PropertyManager->Untie("aero/alpha-min-deg");
347 PropertyManager->Untie("aero/bi2vel");
348 PropertyManager->Untie("aero/ci2vel");
349 PropertyManager->Untie("aero/alpha-wing-rad");
350 PropertyManager->Untie("aero/stall-hyst-norm");
351 PropertyManager->Untie("systems/stall-warn-norm");
353 for ( i=0; i<NAxes; i++ ) {
354 for ( j=0; j < Coeff[i].size(); j++ ) {
355 Coeff[i][j]->unbind();
361 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
362 // The bitmasked value choices are as follows:
363 // unset: In this case (the default) JSBSim would only print
364 // out the normally expected messages, essentially echoing
365 // the config files as they are read. If the environment
366 // variable is not set, debug_lvl is set to 1 internally
367 // 0: This requests JSBSim not to output any messages
369 // 1: This value explicity requests the normal JSBSim
371 // 2: This value asks for a message to be printed out when
372 // a class is instantiated
373 // 4: When this value is set, a message is displayed when a
374 // FGModel object executes its Run() method
375 // 8: When this value is set, various runtime state variables
376 // are printed out periodically
377 // 16: When set various parameters are sanity checked and
378 // a message is printed out when they go out of bounds
380 void FGAerodynamics::Debug(int from)
382 if (debug_lvl <= 0) return;
384 if (debug_lvl & 1) { // Standard console startup message output
385 if (from == 0) { // Constructor
389 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
390 if (from == 0) cout << "Instantiated: FGAerodynamics" << endl;
391 if (from == 1) cout << "Destroyed: FGAerodynamics" << endl;
393 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
395 if (debug_lvl & 8 ) { // Runtime state variables
397 if (debug_lvl & 16) { // Sanity checking
399 if (debug_lvl & 64) {
400 if (from == 0) { // Constructor
401 cout << IdSrc << endl;
402 cout << IdHdr << endl;
407 } // namespace JSBSim