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];
76 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 FGAerodynamics::~FGAerodynamics()
85 for (j=0; j<Coeff[i].size(); j++) {
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 bool FGAerodynamics::Run(void)
98 unsigned int axis_ctr,ctr;
100 if (!FGModel::Run()) {
105 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
106 for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
107 //Coeff[axis_ctr][ctr]->Run();
108 vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
109 //cout << Coeff[axis_ctr][ctr]->Getname() << "= "
110 // << Coeff[axis_ctr][ctr]->TotalValue() << endl;
113 //correct signs of drag and lift to wind axes convention
114 //positive forward, right, down
115 if ( Translation->Getqbar() > 0) {
116 clsq = vFs(eLift) / (Aircraft->GetWingArea()*Translation->Getqbar());
119 if ( vFs(eDrag) > 0) {
120 lod = vFs(eLift) / vFs(eDrag);
123 //correct signs of drag and lift to wind axes convention
124 //positive forward, right, down
125 vFs(eDrag)*=-1; vFs(eLift)*=-1;
126 //cout << "Aircraft::vFs: " << vFs << endl;
127 vForces = State->GetTs2b()*vFs;
129 vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX)
130 - MassBalance->GetXYZcg(eX))*inchtoft;
131 vDXYZcg(eY) = (Aircraft->GetXYZrp(eY)
132 - MassBalance->GetXYZcg(eY))*inchtoft;
133 vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ)
134 - MassBalance->GetXYZcg(eZ))*inchtoft;
136 vMoments = vDXYZcg*vForces; // M = r X F
138 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
139 for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
140 //Coeff[axis_ctr+3][ctr]->Run();
141 vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
150 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 bool FGAerodynamics::Load(FGConfigFile* AC_cfg)
156 AC_cfg->GetNextConfigLine();
158 while ((token = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
159 if (token == "AXIS") {
161 axis = AC_cfg->GetValue("NAME");
162 AC_cfg->GetNextConfigLine();
163 while ((token = AC_cfg->GetValue()) != string("/AXIS")) {
164 if ( token == "COEFFICIENT" ) {
165 ca.push_back( new FGCoefficient(FDMExec) );
166 ca.back()->Load(AC_cfg);
167 } else if ( token == "GROUP" ) {
168 ca.push_back( new FGFactorGroup(FDMExec) );
169 ca.back()->Load(AC_cfg);
172 Coeff[AxisIdx[axis]] = ca;
173 AC_cfg->GetNextConfigLine();
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 string FGAerodynamics::GetCoefficientStrings(void)
186 string CoeffStrings = "";
187 bool firstime = true;
188 unsigned int axis, sd;
190 for (axis = 0; axis < 6; axis++) {
191 for (sd = 0; sd < Coeff[axis].size(); sd++) {
195 CoeffStrings += ", ";
197 CoeffStrings += Coeff[axis][sd]->GetCoefficientStrings();
203 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 string FGAerodynamics::GetCoefficientValues(void)
207 string SDValues = "";
208 bool firstime = true;
210 for (unsigned int axis = 0; axis < 6; axis++) {
211 for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
217 SDValues += Coeff[axis][sd]->GetCoefficientValues();
224 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 void FGAerodynamics::bind(void)
228 typedef double (FGAerodynamics::*PMF)(int) const;
230 PropertyManager->Tie("forces/fbx-aero-lbs", this,1,
231 (PMF)&FGAerodynamics::GetForces);
232 PropertyManager->Tie("forces/fby-aero-lbs", this,2,
233 (PMF)&FGAerodynamics::GetForces);
234 PropertyManager->Tie("forces/fbz-aero-lbs", this,3,
235 (PMF)&FGAerodynamics::GetForces);
236 PropertyManager->Tie("moments/l-aero-lbsft", this,1,
237 (PMF)&FGAerodynamics::GetMoments);
238 PropertyManager->Tie("moments/m-aero-lbsft", this,2,
239 (PMF)&FGAerodynamics::GetMoments);
240 PropertyManager->Tie("moments/n-aero-lbsft", this,3,
241 (PMF)&FGAerodynamics::GetMoments);
242 PropertyManager->Tie("forces/fwx-aero-lbs", this,1,
243 (PMF)&FGAerodynamics::GetvFs);
244 PropertyManager->Tie("forces/fwy-aero-lbs", this,2,
245 (PMF)&FGAerodynamics::GetvFs);
246 PropertyManager->Tie("forces/fwz-aero-lbs", this,3,
247 (PMF)&FGAerodynamics::GetvFs);
248 PropertyManager->Tie("forces/lod-norm", this,
249 &FGAerodynamics::GetLoD);
250 PropertyManager->Tie("aero/cl-squared-norm", this,
251 &FGAerodynamics::GetClSquared);
254 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 void FGAerodynamics::bindModel(void)
259 FGPropertyManager* node;
260 string axis_node_name;
261 node = PropertyManager->GetNode("aero/buildup",true);
262 for (i=0;i<NAxes;i++) {
263 node = node->GetNode( string(AxisNames[i]),true );
264 for (j=0; j < Coeff[i].size(); j++) {
265 Coeff[i][j]->bind(node);
267 node = (FGPropertyManager*)node->getParent();
271 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273 void FGAerodynamics::unbind(void)
277 PropertyManager->Untie("forces/fbx-aero-lbs");
278 PropertyManager->Untie("forces/fby-aero-lbs");
279 PropertyManager->Untie("forces/fbz-aero-lbs");
280 PropertyManager->Untie("moments/l-aero-lbsft");
281 PropertyManager->Untie("moments/m-aero-lbsft");
282 PropertyManager->Untie("moments/n-aero-lbsft");
283 PropertyManager->Untie("forces/fwx-aero-lbs");
284 PropertyManager->Untie("forces/fwy-aero-lbs");
285 PropertyManager->Untie("forces/fwz-aero-lbs");
286 PropertyManager->Untie("forces/lod-norm");
287 PropertyManager->Untie("aero/cl-squared-norm");
289 for ( i=0; i<NAxes; i++ ) {
290 for ( j=0; j < Coeff[i].size(); j++ ) {
291 Coeff[i][j]->unbind();
297 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 // The bitmasked value choices are as follows:
299 // unset: In this case (the default) JSBSim would only print
300 // out the normally expected messages, essentially echoing
301 // the config files as they are read. If the environment
302 // variable is not set, debug_lvl is set to 1 internally
303 // 0: This requests JSBSim not to output any messages
305 // 1: This value explicity requests the normal JSBSim
307 // 2: This value asks for a message to be printed out when
308 // a class is instantiated
309 // 4: When this value is set, a message is displayed when a
310 // FGModel object executes its Run() method
311 // 8: When this value is set, various runtime state variables
312 // are printed out periodically
313 // 16: When set various parameters are sanity checked and
314 // a message is printed out when they go out of bounds
316 void FGAerodynamics::Debug(int from)
318 if (debug_lvl <= 0) return;
320 if (debug_lvl & 1) { // Standard console startup message output
321 if (from == 0) { // Constructor
325 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
326 if (from == 0) cout << "Instantiated: FGAerodynamics" << endl;
327 if (from == 1) cout << "Destroyed: FGAerodynamics" << endl;
329 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
331 if (debug_lvl & 8 ) { // Runtime state variables
333 if (debug_lvl & 16) { // Sanity checking
335 if (debug_lvl & 64) {
336 if (from == 0) { // Constructor
337 cout << IdSrc << endl;
338 cout << IdHdr << endl;