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;
74 bi2vel = ci2vel = 0.0;
80 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 FGAerodynamics::~FGAerodynamics()
89 for (j=0; j<Coeff[i].size(); j++) {
98 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 bool FGAerodynamics::Run(void)
102 unsigned int axis_ctr,ctr;
103 double alpha, twovel;
105 if (!FGModel::Run()) {
107 twovel = 2*Translation->GetVt();
109 bi2vel = Aircraft->GetWingSpan() / twovel;
110 ci2vel = Aircraft->Getcbar() / twovel;
113 alphaw = Translation->Getalpha() + Aircraft->GetWingIncidence();
115 alpha = Translation->Getalpha();
117 if (alphaclmax != 0) {
118 if (alpha > 0.85*alphaclmax) {
119 impending_stall = 10*(alpha/alphaclmax - 0.85);
125 if (alphahystmax != 0.0 && alphahystmin != 0.0) {
126 if (alpha > alphahystmax) {
128 } else if (alpha < alphahystmin) {
136 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
137 for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
138 vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
142 //correct signs of drag and lift to wind axes convention
143 //positive forward, right, down
144 if ( Translation->Getqbar() > 0) {
145 clsq = vFs(eLift) / (Aircraft->GetWingArea()*Translation->Getqbar());
148 if ( vFs(eDrag) > 0) {
149 lod = vFs(eLift) / vFs(eDrag);
152 //correct signs of drag and lift to wind axes convention
153 //positive forward, right, down
154 vFs(eDrag)*=-1; vFs(eLift)*=-1;
156 vForces = State->GetTs2b()*vFs;
158 vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX)
159 - MassBalance->GetXYZcg(eX))*inchtoft;
160 vDXYZcg(eY) = (Aircraft->GetXYZrp(eY)
161 - MassBalance->GetXYZcg(eY))*inchtoft;
162 vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ)
163 - MassBalance->GetXYZcg(eZ))*inchtoft;
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(void)
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 += ", ";
236 CoeffStrings += Coeff[axis][sd]->GetCoefficientName();
242 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 string FGAerodynamics::GetCoefficientValues(void)
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++) {
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("systems/stall-warn-norm");
352 for ( i=0; i<NAxes; i++ ) {
353 for ( j=0; j < Coeff[i].size(); j++ ) {
354 Coeff[i][j]->unbind();
360 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361 // The bitmasked value choices are as follows:
362 // unset: In this case (the default) JSBSim would only print
363 // out the normally expected messages, essentially echoing
364 // the config files as they are read. If the environment
365 // variable is not set, debug_lvl is set to 1 internally
366 // 0: This requests JSBSim not to output any messages
368 // 1: This value explicity requests the normal JSBSim
370 // 2: This value asks for a message to be printed out when
371 // a class is instantiated
372 // 4: When this value is set, a message is displayed when a
373 // FGModel object executes its Run() method
374 // 8: When this value is set, various runtime state variables
375 // are printed out periodically
376 // 16: When set various parameters are sanity checked and
377 // a message is printed out when they go out of bounds
379 void FGAerodynamics::Debug(int from)
381 if (debug_lvl <= 0) return;
383 if (debug_lvl & 1) { // Standard console startup message output
384 if (from == 0) { // Constructor
388 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
389 if (from == 0) cout << "Instantiated: FGAerodynamics" << endl;
390 if (from == 1) cout << "Destroyed: FGAerodynamics" << endl;
392 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
394 if (debug_lvl & 8 ) { // Runtime state variables
396 if (debug_lvl & 16) { // Sanity checking
398 if (debug_lvl & 64) {
399 if (from == 0) { // Constructor
400 cout << IdSrc << endl;
401 cout << IdHdr << endl;