Date started: 09/13/00
Purpose: Encapsulates the aerodynamic forces
- ------------- Copyright (C) 2000 Jon S. Berndt (jsb@hal-pc.org) -------------
+ ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+#include <cstdlib>
+#include <FGFDMExec.h>
#include "FGAerodynamics.h"
#include "FGPropagate.h"
#include "FGAircraft.h"
#include "FGAuxiliary.h"
#include "FGMassBalance.h"
-#include <input_output/FGPropertyManager.h>
+#include "input_output/FGPropertyManager.h"
+
+using namespace std;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGAerodynamics.cpp,v 1.38 2011/05/20 03:18:36 jberndt Exp $";
static const char *IdHdr = ID_AERODYNAMICS;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
axisType = atNone;
- Coeff = new CoeffArray[6];
+ AeroFunctions = new AeroFunctionArray[6];
impending_stall = stall_hyst = 0.0;
alphaclmin = alphaclmax = 0.0;
unsigned int i,j;
for (i=0; i<6; i++)
- for (j=0; j<Coeff[i].size(); j++)
- delete Coeff[i][j];
-
- delete[] Coeff;
+ for (j=0; j<AeroFunctions[i].size(); j++)
+ delete AeroFunctions[i][j];
- for (i=0; i<variables.size(); i++)
- delete variables[i];
+ delete[] AeroFunctions;
delete AeroRPShift;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGAerodynamics::Run(void)
+bool FGAerodynamics::Run(bool Holding)
{
- unsigned int axis_ctr, ctr, i;
- double alpha, twovel;
- if (FGModel::Run()) return true;
- if (FDMExec->Holding()) return false; // if paused don't execute
+ if (FGModel::Run(Holding)) return true;
+ if (Holding) return false; // if paused don't execute
+
+ unsigned int axis_ctr, ctr;
+ const double alpha=FDMExec->GetAuxiliary()->Getalpha();
+ const double twovel=2*FDMExec->GetAuxiliary()->GetVt();
+ const double qbar = FDMExec->GetAuxiliary()->Getqbar();
+ const double wingarea = FDMExec->GetAircraft()->GetWingArea(); // TODO: Make these constants constant!
+ const double wingspan = FDMExec->GetAircraft()->GetWingSpan();
+ const double wingchord = FDMExec->GetAircraft()->Getcbar();
+ const double wingincidence = FDMExec->GetAircraft()->GetWingIncidence();
+ RunPreFunctions();
// calculate some oft-used quantities for speed
- twovel = 2*Auxiliary->GetVt();
if (twovel != 0) {
- bi2vel = Aircraft->GetWingSpan() / twovel;
- ci2vel = Aircraft->Getcbar() / twovel;
+ bi2vel = wingspan / twovel;
+ ci2vel = wingchord / twovel;
}
- alphaw = Auxiliary->Getalpha() + Aircraft->GetWingIncidence();
- alpha = Auxiliary->Getalpha();
- qbar_area = Aircraft->GetWingArea() * Auxiliary->Getqbar();
+ alphaw = alpha + wingincidence;
+ qbar_area = wingarea * qbar;
if (alphaclmax != 0) {
if (alpha > 0.85*alphaclmax) {
vFw.InitMatrix();
vFnative.InitMatrix();
- // Tell the variable functions to cache their values, so while the aerodynamic
- // functions are being calculated for each axis, these functions do not get
- // calculated each time, but instead use the values that have already
- // been calculated for this frame.
-
- for (i=0; i<variables.size(); i++) variables[i]->cacheValue(true);
-
for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
- for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
- vFnative(axis_ctr+1) += Coeff[axis_ctr][ctr]->GetValue();
+ for (ctr=0; ctr < AeroFunctions[axis_ctr].size(); ctr++) {
+ vFnative(axis_ctr+1) += AeroFunctions[axis_ctr][ctr]->GetValue();
}
}
}
// Calculate aerodynamic reference point shift, if any
- if (AeroRPShift) vDeltaRP(eX) = AeroRPShift->GetValue()*Aircraft->Getcbar()*12.0;
+ if (AeroRPShift) vDeltaRP(eX) = AeroRPShift->GetValue()*wingchord*12.0;
// Calculate lift coefficient squared
- if ( Auxiliary->Getqbar() > 0) {
- clsq = vFw(eLift) / (Aircraft->GetWingArea()*Auxiliary->Getqbar());
+ if ( qbar > 0) {
+ clsq = vFw(eLift) / (wingarea*qbar);
clsq *= clsq;
}
// Calculate lift Lift over Drag
if ( fabs(vFw(eDrag)) > 0.0) lod = fabs( vFw(eLift) / vFw(eDrag) );
- vDXYZcg = MassBalance->StructuralToBody(Aircraft->GetXYZrp() + vDeltaRP);
+ vDXYZcg = FDMExec->GetMassBalance()->StructuralToBody(FDMExec->GetAircraft()->GetXYZrp() + vDeltaRP);
vMoments = vDXYZcg*vForces; // M = r X F
for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
- for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
- vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->GetValue();
+ for (ctr = 0; ctr < AeroFunctions[axis_ctr+3].size(); ctr++) {
+ vMoments(axis_ctr+1) += AeroFunctions[axis_ctr+3][ctr]->GetValue();
}
}
+ RunPostFunctions();
+
return false;
}
{
double ca, cb, sa, sb;
- double alpha = Auxiliary->Getalpha();
- double beta = Auxiliary->Getbeta();
+ double alpha = FDMExec->GetAuxiliary()->Getalpha();
+ double beta = FDMExec->GetAuxiliary()->Getbeta();
ca = cos(alpha);
sa = sin(alpha);
cb = cos(beta);
sb = sin(beta);
- mTw2b(1,1) = ca*cb;
+ mTw2b(1,1) = ca*cb;
mTw2b(1,2) = -ca*sb;
mTw2b(1,3) = -sa;
- mTw2b(2,1) = sb;
- mTw2b(2,2) = cb;
- mTw2b(2,3) = 0.0;
- mTw2b(3,1) = sa*cb;
+ mTw2b(2,1) = sb;
+ mTw2b(2,2) = cb;
+ mTw2b(2,3) = 0.0;
+ mTw2b(3,1) = sa*cb;
mTw2b(3,2) = -sa*sb;
- mTw2b(3,3) = ca;
+ mTw2b(3,3) = ca;
return mTw2b;
}
double alpha,beta;
double ca, cb, sa, sb;
- alpha = Auxiliary->Getalpha();
- beta = Auxiliary->Getbeta();
+ alpha = FDMExec->GetAuxiliary()->Getalpha();
+ beta = FDMExec->GetAuxiliary()->Getbeta();
ca = cos(alpha);
sa = sin(alpha);
Element *temp_element, *axis_element, *function_element;
string separator = "/";
-#ifdef macintosh
- separator = ";";
-#endif
fname = element->GetAttributeValue("file");
if (!fname.empty()) {
document = element;
}
+ FGModel::Load(document); // Perform base class Pre-Load
+
DetermineAxisSystem(); // Detemine if Lift/Side/Drag, etc. is used.
Debug(2);
- if (temp_element = document->FindElement("alphalimits")) {
+ if ((temp_element = document->FindElement("alphalimits"))) {
scratch_unit = temp_element->GetAttributeValue("unit");
if (scratch_unit.empty()) scratch_unit = "RAD";
alphaclmin = temp_element->FindElementValueAsNumberConvertFromTo("min", scratch_unit, "RAD");
alphaclmax = temp_element->FindElementValueAsNumberConvertFromTo("max", scratch_unit, "RAD");
}
- if (temp_element = document->FindElement("hysteresis_limits")) {
+ if ((temp_element = document->FindElement("hysteresis_limits"))) {
scratch_unit = temp_element->GetAttributeValue("unit");
if (scratch_unit.empty()) scratch_unit = "RAD";
alphahystmin = temp_element->FindElementValueAsNumberConvertFromTo("min", scratch_unit, "RAD");
alphahystmax = temp_element->FindElementValueAsNumberConvertFromTo("max", scratch_unit, "RAD");
}
- if (temp_element = document->FindElement("aero_ref_pt_shift_x")) {
+ if ((temp_element = document->FindElement("aero_ref_pt_shift_x"))) {
function_element = temp_element->FindElement("function");
AeroRPShift = new FGFunction(PropertyManager, function_element);
}
- function_element = document->FindElement("function");
- while (function_element) {
- variables.push_back( new FGFunction(PropertyManager, function_element) );
- function_element = document->FindNextElement("function");
- }
-
axis_element = document->FindElement("axis");
while (axis_element) {
- CoeffArray ca;
+ AeroFunctionArray ca;
axis = axis_element->GetAttributeValue("name");
function_element = axis_element->FindElement("function");
while (function_element) {
- ca.push_back( new FGFunction(PropertyManager, function_element) );
+ string current_func_name = function_element->GetAttributeValue("name");
+ try {
+ ca.push_back( new FGFunction(PropertyManager, function_element) );
+ } catch (string const str) {
+ cerr << endl << fgred << "Error loading aerodynamic function in "
+ << current_func_name << ":" << str << " Aborting." << reset << endl;
+ return false;
+ }
function_element = axis_element->FindNextElement("function");
}
- Coeff[AxisIdx[axis]] = ca;
+ AeroFunctions[AxisIdx[axis]] = ca;
axis_element = document->FindNextElement("axis");
}
+ PostLoad(document, PropertyManager); // Perform base class Post-Load
+
return true;
}
string axis;
while (axis_element) {
axis = axis_element->GetAttributeValue("name");
- if (axis == "LIFT" || axis == "DRAG" || axis == "SIDE") {
+ if (axis == "LIFT" || axis == "DRAG") {
if (axisType == atNone) axisType = atLiftDrag;
else if (axisType != atLiftDrag) {
cerr << endl << " Mixed aerodynamic axis systems have been used in the"
- << " aircraft config file." << endl;
+ << " aircraft config file. (LIFT DRAG)" << endl;
+ }
+ } else if (axis == "SIDE") {
+ if (axisType != atNone && axisType != atLiftDrag && axisType != atAxialNormal) {
+ cerr << endl << " Mixed aerodynamic axis systems have been used in the"
+ << " aircraft config file. (SIDE)" << endl;
}
} else if (axis == "AXIAL" || axis == "NORMAL") {
if (axisType == atNone) axisType = atAxialNormal;
else if (axisType != atAxialNormal) {
cerr << endl << " Mixed aerodynamic axis systems have been used in the"
- << " aircraft config file." << endl;
+ << " aircraft config file. (NORMAL AXIAL)" << endl;
}
} else if (axis == "X" || axis == "Y" || axis == "Z") {
if (axisType == atNone) axisType = atBodyXYZ;
else if (axisType != atBodyXYZ) {
cerr << endl << " Mixed aerodynamic axis systems have been used in the"
- << " aircraft config file." << endl;
+ << " aircraft config file. (XYZ)" << endl;
}
} else if (axis != "ROLL" && axis != "PITCH" && axis != "YAW") { // error
cerr << endl << " An unknown axis type, " << axis << " has been specified"
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-string FGAerodynamics::GetCoefficientStrings(string delimeter)
+string FGAerodynamics::GetAeroFunctionStrings(const string& delimeter) const
{
- string CoeffStrings = "";
+ string AeroFunctionStrings = "";
bool firstime = true;
unsigned int axis, sd;
- for (sd = 0; sd < variables.size(); sd++) {
- if (firstime) {
- firstime = false;
- } else {
- CoeffStrings += delimeter;
- }
- CoeffStrings += variables[sd]->GetName();
- }
-
for (axis = 0; axis < 6; axis++) {
- for (sd = 0; sd < Coeff[axis].size(); sd++) {
+ for (sd = 0; sd < AeroFunctions[axis].size(); sd++) {
if (firstime) {
firstime = false;
} else {
- CoeffStrings += delimeter;
+ AeroFunctionStrings += delimeter;
}
- CoeffStrings += Coeff[axis][sd]->GetName();
+ AeroFunctionStrings += AeroFunctions[axis][sd]->GetName();
}
}
- return CoeffStrings;
+ return AeroFunctionStrings;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-string FGAerodynamics::GetCoefficientValues(string delimeter)
+string FGAerodynamics::GetAeroFunctionValues(const string& delimeter) const
{
- string SDValues = "";
- bool firstime = true;
- unsigned int sd;
-
- for (sd = 0; sd < variables.size(); sd++) {
- if (firstime) {
- firstime = false;
- } else {
- SDValues += delimeter;
- }
- SDValues += variables[sd]->GetValueAsString();
- }
+ ostringstream buf;
for (unsigned int axis = 0; axis < 6; axis++) {
- for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
- if (firstime) {
- firstime = false;
- } else {
- SDValues += delimeter;
- }
- SDValues += Coeff[axis][sd]->GetValueAsString();
+ for (unsigned int sd = 0; sd < AeroFunctions[axis].size(); sd++) {
+ if (buf.tellp() > 0) buf << delimeter;
+ buf << setw(9) << AeroFunctions[axis][sd]->GetValue();
}
}
- return SDValues;
+ return buf.str();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case (atBodyXYZ):
cout << endl << " Aerodynamics (X|Y|Z axes):" << endl << endl;
break;
+ case (atNone):
+ cout << endl << " Aerodynamics (undefined axes):" << endl << endl;
+ break;
}
}
}