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 "FGFactorGroup.h"
41 #include "FGCoefficient.h"
42 #include "FGPropertyManager.h"
44 static const char *IdSrc = "$Id$";
45 static const char *IdHdr = ID_AERODYNAMICS;
47 const unsigned NAxes=6;
48 const char* AxisNames[] = { "drag", "side-force", "lift", "rolling-moment",
49 "pitching-moment","yawing-moment" };
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec)
58 Name = "FGAerodynamics";
67 Coeff = new CoeffArray[6];
69 impending_stall = stall_hyst = 0.0;
70 alphaclmin = alphaclmax = 0.0;
71 alphahystmin = alphahystmax = 0.0;
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 FGAerodynamics::~FGAerodynamics()
88 for (j=0; j<Coeff[i].size(); j++) {
97 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 bool FGAerodynamics::Run(void)
101 unsigned int axis_ctr,ctr;
102 double alpha, twovel;
104 if (!FGModel::Run()) {
106 twovel = 2*Translation->GetVt();
108 bi2vel = Aircraft->GetWingSpan() / twovel;
109 ci2vel = Aircraft->Getcbar() / twovel;
112 alphaw = Translation->Getalpha() + Aircraft->GetWingIncidence();
114 alpha = Translation->Getalpha();
116 if (alphaclmax != 0) {
117 if (alpha > 0.85*alphaclmax) {
118 impending_stall = 10*(alpha/alphaclmax - 0.85);
124 if (alphahystmax != 0.0 && alphahystmin != 0.0) {
125 if (alpha > alphahystmax) {
127 } else if (alpha < alphahystmin) {
135 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
136 for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
137 vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
141 //correct signs of drag and lift to wind axes convention
142 //positive forward, right, down
143 if ( Translation->Getqbar() > 0) {
144 clsq = vFs(eLift) / (Aircraft->GetWingArea()*Translation->Getqbar());
147 if ( vFs(eDrag) > 0) {
148 lod = vFs(eLift) / vFs(eDrag);
151 //correct signs of drag and lift to wind axes convention
152 //positive forward, right, down
153 vFs(eDrag)*=-1; vFs(eLift)*=-1;
155 vForces = State->GetTs2b()*vFs;
157 vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX)
158 - MassBalance->GetXYZcg(eX))*inchtoft;
159 vDXYZcg(eY) = (Aircraft->GetXYZrp(eY)
160 - MassBalance->GetXYZcg(eY))*inchtoft;
161 vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ)
162 - MassBalance->GetXYZcg(eZ))*inchtoft;
164 vMoments = vDXYZcg*vForces; // M = r X F
166 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
167 for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
168 vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
178 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 bool FGAerodynamics::Load(FGConfigFile* AC_cfg)
182 string parameter, axis, scratch;
184 AC_cfg->GetNextConfigLine();
186 while ((parameter = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
187 if (parameter == "AXIS") {
189 axis = AC_cfg->GetValue("NAME");
190 AC_cfg->GetNextConfigLine();
191 while ((parameter = AC_cfg->GetValue()) != string("/AXIS")) {
192 if ( parameter == "COEFFICIENT" ) {
193 ca.push_back( new FGCoefficient(FDMExec) );
194 ca.back()->Load(AC_cfg);
195 } else if ( parameter == "GROUP" ) {
196 ca.push_back( new FGFactorGroup(FDMExec) );
197 ca.back()->Load(AC_cfg);
200 Coeff[AxisIdx[axis]] = ca;
201 AC_cfg->GetNextConfigLine();
202 } else if (parameter == "AC_ALPHALIMITS") {
203 *AC_cfg >> scratch >> alphaclmin >> alphaclmax;
204 if (debug_lvl > 0) cout << " Maximum Alpha: " << alphaclmax
205 << " Minimum Alpha: " << alphaclmin
207 } else if (parameter == "AC_HYSTLIMITS") {
208 *AC_cfg >> scratch >> alphahystmin >> alphahystmax;
209 if (debug_lvl > 0) cout << " Hysteresis Start: " << alphahystmax
210 << " Hysteresis End: " << alphahystmin
220 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 string FGAerodynamics::GetCoefficientStrings(void)
224 string CoeffStrings = "";
225 bool firstime = true;
226 unsigned int axis, sd;
228 for (axis = 0; axis < 6; axis++) {
229 for (sd = 0; sd < Coeff[axis].size(); sd++) {
233 CoeffStrings += ", ";
235 CoeffStrings += Coeff[axis][sd]->GetCoefficientName();
241 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 string FGAerodynamics::GetCoefficientValues(void)
245 string SDValues = "";
246 bool firstime = true;
248 for (unsigned int axis = 0; axis < 6; axis++) {
249 for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
255 SDValues += Coeff[axis][sd]->GetSDstring();
262 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 void FGAerodynamics::bind(void)
266 typedef double (FGAerodynamics::*PMF)(int) const;
268 PropertyManager->Tie("forces/fbx-aero-lbs", this,1,
269 (PMF)&FGAerodynamics::GetForces);
270 PropertyManager->Tie("forces/fby-aero-lbs", this,2,
271 (PMF)&FGAerodynamics::GetForces);
272 PropertyManager->Tie("forces/fbz-aero-lbs", this,3,
273 (PMF)&FGAerodynamics::GetForces);
274 PropertyManager->Tie("moments/l-aero-lbsft", this,1,
275 (PMF)&FGAerodynamics::GetMoments);
276 PropertyManager->Tie("moments/m-aero-lbsft", this,2,
277 (PMF)&FGAerodynamics::GetMoments);
278 PropertyManager->Tie("moments/n-aero-lbsft", this,3,
279 (PMF)&FGAerodynamics::GetMoments);
280 PropertyManager->Tie("forces/fwx-aero-lbs", this,1,
281 (PMF)&FGAerodynamics::GetvFs);
282 PropertyManager->Tie("forces/fwy-aero-lbs", this,2,
283 (PMF)&FGAerodynamics::GetvFs);
284 PropertyManager->Tie("forces/fwz-aero-lbs", this,3,
285 (PMF)&FGAerodynamics::GetvFs);
286 PropertyManager->Tie("forces/lod-norm", this,
287 &FGAerodynamics::GetLoD);
288 PropertyManager->Tie("aero/cl-squared-norm", this,
289 &FGAerodynamics::GetClSquared);
290 PropertyManager->Tie("aero/alpha-max-deg", this,
291 &FGAerodynamics::GetAlphaCLMax,
292 &FGAerodynamics::SetAlphaCLMax,
294 PropertyManager->Tie("aero/alpha-min-deg", this,
295 &FGAerodynamics::GetAlphaCLMin,
296 &FGAerodynamics::SetAlphaCLMin,
298 PropertyManager->Tie("aero/bi2vel", this,
299 &FGAerodynamics::GetBI2Vel);
300 PropertyManager->Tie("aero/ci2vel", this,
301 &FGAerodynamics::GetCI2Vel);
302 PropertyManager->Tie("aero/alpha-wing-rad", this,
303 &FGAerodynamics::GetAlphaW);
304 PropertyManager->Tie("systems/stall-warn-norm", this,
305 &FGAerodynamics::GetStallWarn);
306 PropertyManager->Tie("aero/stall-hyst-norm", this,
307 &FGAerodynamics::GetHysteresisParm);
310 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 void FGAerodynamics::bindModel(void)
315 FGPropertyManager* node;
316 string axis_node_name;
317 node = PropertyManager->GetNode("aero/buildup",true);
318 for (i=0;i<NAxes;i++) {
319 node = node->GetNode( string(AxisNames[i]),true );
320 for (j=0; j < Coeff[i].size(); j++) {
321 Coeff[i][j]->bind(node);
323 node = (FGPropertyManager*)node->getParent();
327 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 void FGAerodynamics::unbind(void)
333 PropertyManager->Untie("forces/fbx-aero-lbs");
334 PropertyManager->Untie("forces/fby-aero-lbs");
335 PropertyManager->Untie("forces/fbz-aero-lbs");
336 PropertyManager->Untie("moments/l-aero-lbsft");
337 PropertyManager->Untie("moments/m-aero-lbsft");
338 PropertyManager->Untie("moments/n-aero-lbsft");
339 PropertyManager->Untie("forces/fwx-aero-lbs");
340 PropertyManager->Untie("forces/fwy-aero-lbs");
341 PropertyManager->Untie("forces/fwz-aero-lbs");
342 PropertyManager->Untie("forces/lod-norm");
343 PropertyManager->Untie("aero/cl-squared-norm");
344 PropertyManager->Untie("aero/alpha-max-deg");
345 PropertyManager->Untie("aero/alpha-min-deg");
346 PropertyManager->Untie("aero/bi2vel");
347 PropertyManager->Untie("aero/ci2vel");
348 PropertyManager->Untie("aero/alpha-wing-rad");
349 PropertyManager->Untie("systems/stall-warn-norm");
351 for ( i=0; i<NAxes; i++ ) {
352 for ( j=0; j < Coeff[i].size(); j++ ) {
353 Coeff[i][j]->unbind();
359 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360 // The bitmasked value choices are as follows:
361 // unset: In this case (the default) JSBSim would only print
362 // out the normally expected messages, essentially echoing
363 // the config files as they are read. If the environment
364 // variable is not set, debug_lvl is set to 1 internally
365 // 0: This requests JSBSim not to output any messages
367 // 1: This value explicity requests the normal JSBSim
369 // 2: This value asks for a message to be printed out when
370 // a class is instantiated
371 // 4: When this value is set, a message is displayed when a
372 // FGModel object executes its Run() method
373 // 8: When this value is set, various runtime state variables
374 // are printed out periodically
375 // 16: When set various parameters are sanity checked and
376 // a message is printed out when they go out of bounds
378 void FGAerodynamics::Debug(int from)
380 if (debug_lvl <= 0) return;
382 if (debug_lvl & 1) { // Standard console startup message output
383 if (from == 0) { // Constructor
387 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
388 if (from == 0) cout << "Instantiated: FGAerodynamics" << endl;
389 if (from == 1) cout << "Destroyed: FGAerodynamics" << endl;
391 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
393 if (debug_lvl & 8 ) { // Runtime state variables
395 if (debug_lvl & 16) { // Sanity checking
397 if (debug_lvl & 64) {
398 if (from == 0) { // Constructor
399 cout << IdSrc << endl;
400 cout << IdHdr << endl;