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"
43 static const char *IdSrc = "$Id$";
44 static const char *IdHdr = ID_AERODYNAMICS;
46 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec),
58 Name = "FGAerodynamics";
67 Coeff = new CoeffArray[6];
69 if (debug_lvl & 2) cout << "Instantiated: FGAerodynamics" << endl;
72 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 FGAerodynamics::~FGAerodynamics()
78 for (j=0; j<Coeff[i].size(); j++) {
84 if (debug_lvl & 2) cout << "Destroyed: FGAerodynamics" << endl;
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 bool FGAerodynamics::Run(void)
91 unsigned int axis_ctr,ctr;
93 if (!FGModel::Run()) {
98 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
99 for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
100 vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
103 //correct signs of drag and lift to wind axes convention
104 //positive forward, right, down
105 vFs(1)*=-1; vFs(3)*=-1;
106 //cout << "Aircraft::vFs: " << vFs << endl;
107 vForces = State->GetTs2b()*vFs;
109 vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX)
110 - MassBalance->GetXYZcg(eX))*inchtoft;
111 vDXYZcg(eY) = (Aircraft->GetXYZrp(eY)
112 - MassBalance->GetXYZcg(eY))*inchtoft;
113 vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ)
114 - MassBalance->GetXYZcg(eZ))*inchtoft;
116 vMoments = vDXYZcg*vForces; // M = r X F
118 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
119 for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
120 vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 bool FGAerodynamics::Load(FGConfigFile* AC_cfg)
135 AC_cfg->GetNextConfigLine();
137 while ((token = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
138 if (token == "AXIS") {
140 axis = AC_cfg->GetValue("NAME");
141 AC_cfg->GetNextConfigLine();
142 while ((token = AC_cfg->GetValue()) != string("/AXIS")) {
143 if( token == "COEFFICIENT" ) {
144 ca.push_back( new FGCoefficient(FDMExec) );
145 ca.back()->Load(AC_cfg);
146 } else if ( token == "GROUP" ) {
147 ca.push_back( new FGFactorGroup(FDMExec) );
148 ca.back()->Load(AC_cfg);
151 Coeff[AxisIdx[axis]] = ca;
152 AC_cfg->GetNextConfigLine();
159 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 string FGAerodynamics::GetCoefficientStrings(void)
163 string CoeffStrings = "";
164 bool firstime = true;
165 unsigned int axis, sd;
167 for (axis = 0; axis < 6; axis++) {
168 for (sd = 0; sd < Coeff[axis].size(); sd++) {
172 CoeffStrings += ", ";
174 CoeffStrings += Coeff[axis][sd]->GetCoefficientStrings();
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 string FGAerodynamics::GetCoefficientValues(void)
184 string SDValues = "";
185 bool firstime = true;
187 for (unsigned int axis = 0; axis < 6; axis++) {
188 for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
194 SDValues += Coeff[axis][sd]->GetCoefficientValues();
201 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 double FGAerodynamics::GetLoD(void)
205 if (vFs(1) != 0.00) return vFs(3)/vFs(1);
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 void FGAerodynamics::Debug(void)
213 //TODO: Add your source code here