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 PropertyManager->Tie("forces/fbx-aero-lbs", this,1,
229 &FGAerodynamics::GetForces);
230 PropertyManager->Tie("forces/fby-aero-lbs", this,2,
231 &FGAerodynamics::GetForces);
232 PropertyManager->Tie("forces/fbz-aero-lbs", this,3,
233 &FGAerodynamics::GetForces);
234 PropertyManager->Tie("moments/l-aero-lbsft", this,1,
235 &FGAerodynamics::GetMoments);
236 PropertyManager->Tie("moments/m-aero-lbsft", this,2,
237 &FGAerodynamics::GetMoments);
238 PropertyManager->Tie("moments/n-aero-lbsft", this,3,
239 &FGAerodynamics::GetMoments);
240 PropertyManager->Tie("forces/fwx-aero-lbs", this,1,
241 &FGAerodynamics::GetvFs);
242 PropertyManager->Tie("forces/fwy-aero-lbs", this,2,
243 &FGAerodynamics::GetvFs);
244 PropertyManager->Tie("forces/fwz-aero-lbs", this,3,
245 &FGAerodynamics::GetvFs);
246 PropertyManager->Tie("forces/lod-norm", this,
247 &FGAerodynamics::GetLoD);
248 PropertyManager->Tie("aero/cl-squared-norm", this,
249 &FGAerodynamics::GetClSquared);
252 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254 void FGAerodynamics::bindModel(void)
257 FGPropertyManager* node;
258 string axis_node_name;
259 node = PropertyManager->GetNode("aero/buildup",true);
260 for (i=0;i<NAxes;i++) {
261 node = node->GetNode( string(AxisNames[i]),true );
262 for (j=0; j < Coeff[i].size(); j++) {
263 Coeff[i][j]->bind(node);
265 node = (FGPropertyManager*)node->getParent();
269 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 void FGAerodynamics::unbind(void)
275 PropertyManager->Untie("forces/fbx-aero-lbs");
276 PropertyManager->Untie("forces/fby-aero-lbs");
277 PropertyManager->Untie("forces/fbz-aero-lbs");
278 PropertyManager->Untie("moments/l-aero-lbsft");
279 PropertyManager->Untie("moments/m-aero-lbsft");
280 PropertyManager->Untie("moments/n-aero-lbsft");
281 PropertyManager->Untie("forces/fwx-aero-lbs");
282 PropertyManager->Untie("forces/fwy-aero-lbs");
283 PropertyManager->Untie("forces/fwz-aero-lbs");
284 PropertyManager->Untie("forces/lod-norm");
285 PropertyManager->Untie("aero/cl-squared-norm");
287 for ( i=0; i<NAxes; i++ ) {
288 for ( j=0; j < Coeff[i].size(); j++ ) {
289 Coeff[i][j]->unbind();
295 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 // The bitmasked value choices are as follows:
297 // unset: In this case (the default) JSBSim would only print
298 // out the normally expected messages, essentially echoing
299 // the config files as they are read. If the environment
300 // variable is not set, debug_lvl is set to 1 internally
301 // 0: This requests JSBSim not to output any messages
303 // 1: This value explicity requests the normal JSBSim
305 // 2: This value asks for a message to be printed out when
306 // a class is instantiated
307 // 4: When this value is set, a message is displayed when a
308 // FGModel object executes its Run() method
309 // 8: When this value is set, various runtime state variables
310 // are printed out periodically
311 // 16: When set various parameters are sanity checked and
312 // a message is printed out when they go out of bounds
314 void FGAerodynamics::Debug(int from)
316 if (debug_lvl <= 0) return;
318 if (debug_lvl & 1) { // Standard console startup message output
319 if (from == 0) { // Constructor
323 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
324 if (from == 0) cout << "Instantiated: FGAerodynamics" << endl;
325 if (from == 1) cout << "Destroyed: FGAerodynamics" << endl;
327 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
329 if (debug_lvl & 8 ) { // Runtime state variables
331 if (debug_lvl & 16) { // Sanity checking
333 if (debug_lvl & 64) {
334 if (from == 0) { // Constructor
335 cout << IdSrc << endl;
336 cout << IdHdr << endl;