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 extern short debug_lvl;
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec),
60 Name = "FGAerodynamics";
69 Coeff = new CoeffArray[6];
71 if (debug_lvl & 2) cout << "Instantiated: FGAerodynamics" << endl;
74 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 FGAerodynamics::~FGAerodynamics()
80 for (j=0; j<Coeff[i].size(); j++) {
86 if (debug_lvl & 2) cout << "Destroyed: FGAerodynamics" << endl;
89 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 bool FGAerodynamics::Run(void)
94 unsigned int axis_ctr,ctr;
96 if (!FGModel::Run()) {
98 alpha = Translation->Getalpha();
99 beta = Translation->Getbeta();
104 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
105 for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
106 vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
110 vForces = State->GetTs2b(alpha, beta)*vFs;
112 // see http://home.earthlink.net/~apeden/jsbsim_moments_due_to_forces.txt
113 // for details on this
115 vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX) - MassBalance->GetXYZcg(eX))/12.0;
116 vDXYZcg(eY) = (Aircraft->GetXYZrp(eY) - MassBalance->GetXYZcg(eY))/12.0;
117 vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ) - MassBalance->GetXYZcg(eZ))/12.0;
119 vMoments(eL) = vForces(eZ)*vDXYZcg(eY) - vForces(eY)*vDXYZcg(eZ);
120 vMoments(eM) = vForces(eX)*vDXYZcg(eZ) - vForces(eZ)*vDXYZcg(eX);
121 vMoments(eN) = vForces(eY)*vDXYZcg(eX) - vForces(eX)*vDXYZcg(eY);
123 for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
124 for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
125 vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
134 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 bool FGAerodynamics::Load(FGConfigFile* AC_cfg)
140 AC_cfg->GetNextConfigLine();
142 while ((token = AC_cfg->GetValue()) != "/AERODYNAMICS") {
143 if (token == "AXIS") {
145 axis = AC_cfg->GetValue("NAME");
146 AC_cfg->GetNextConfigLine();
147 while ((token = AC_cfg->GetValue()) != "/AXIS") {
148 if( token == "COEFFICIENT" ) {
149 ca.push_back( new FGCoefficient(FDMExec) );
150 ca.back()->Load(AC_cfg);
151 } else if ( token == "GROUP" ) {
152 ca.push_back( new FGFactorGroup(FDMExec) );
153 ca.back()->Load(AC_cfg);
156 Coeff[AxisIdx[axis]] = ca;
157 AC_cfg->GetNextConfigLine();
164 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 string FGAerodynamics::GetCoefficientStrings(void)
168 string CoeffStrings = "";
169 bool firstime = true;
170 unsigned int axis, sd;
172 for (axis = 0; axis < 6; axis++) {
173 for (sd = 0; sd < Coeff[axis].size(); sd++) {
177 CoeffStrings += ", ";
179 CoeffStrings += Coeff[axis][sd]->GetCoefficientStrings();
185 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 string FGAerodynamics::GetCoefficientValues(void)
189 string SDValues = "";
191 bool firstime = true;
193 for (unsigned int axis = 0; axis < 6; axis++) {
194 for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
200 SDValues += Coeff[axis][sd]->GetCoefficientValues();
207 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 float FGAerodynamics::GetNlf(void)
211 if (fabs(Position->GetGamma()) < 1.57) {
212 return (vFs(eZ)/(MassBalance->GetWeight()*cos(Position->GetGamma())));
218 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 float FGAerodynamics::GetLoD(void)
224 if (vFs(1) != 0.00) return vFs(3)/vFs(1);
228 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 void FGAerodynamics::Debug(void)
232 //TODO: Add your source code here