Skip to content

Commit

Permalink
Fixed the aero functions such that they now cache their result when t…
Browse files Browse the repository at this point in the history
…hey are executed. This is to make sure that their output to CSV is the same than the result that has been actually used for computations. The issue arose in particular for induced drag which is computed from aero/cl-squared which is modified between the moment where the induced drag is computed and the output to CSV is run. In some cases these 2 values can be very different.
  • Loading branch information
bcoconni committed May 22, 2016
1 parent 1d72958 commit 18c143a
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/models/FGAerodynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ using namespace std;

namespace JSBSim {

IDENT(IdSrc,"$Id: FGAerodynamics.cpp,v 1.57 2015/01/31 14:56:21 bcoconni Exp $");
IDENT(IdSrc,"$Id: FGAerodynamics.cpp,v 1.58 2016/05/22 17:02:13 bcoconni Exp $");
IDENT(IdHdr,ID_AERODYNAMICS);

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -144,7 +144,7 @@ bool FGAerodynamics::Run(bool Holding)
if (FGModel::Run(Holding)) return true;
if (Holding) return false; // if paused don't execute

unsigned int axis_ctr, ctr;
unsigned int axis_ctr;
const double twovel=2*in.Vt;

RunPreFunctions();
Expand Down Expand Up @@ -179,15 +179,23 @@ bool FGAerodynamics::Run(bool Holding)
vFnative.InitMatrix();
vFnativeAtCG.InitMatrix();

for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
for (ctr=0; ctr < AeroFunctions[axis_ctr].size(); ctr++) {
vFnative(axis_ctr+1) += AeroFunctions[axis_ctr][ctr]->GetValue();
for (axis_ctr = 0; axis_ctr < 3; ++axis_ctr) {
AeroFunctionArray::iterator f;

AeroFunctionArray* array = &AeroFunctions[axis_ctr];
for (f=array->begin(); f != array->end(); ++f) {
// Tell the Functions to cache values, so when the function values are
// being requested for output, the functions do not get calculated again
// in a context that might have changed, but instead use the values that
// have already been calculated for this frame.
(*f)->cacheValue(true);
vFnative(axis_ctr+1) += (*f)->GetValue();
}
}

for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
for (ctr=0; ctr < AeroFunctionsAtCG[axis_ctr].size(); ctr++) {
vFnativeAtCG(axis_ctr+1) += AeroFunctionsAtCG[axis_ctr][ctr]->GetValue();
array = &AeroFunctionsAtCG[axis_ctr];
for (f=array->begin(); f != array->end(); ++f) {
(*f)->cacheValue(true); // Same as above
vFnativeAtCG(axis_ctr+1) += (*f)->GetValue();
}
}

Expand Down Expand Up @@ -264,8 +272,14 @@ bool FGAerodynamics::Run(bool Holding)
vMomentsMRC.InitMatrix();

for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
for (ctr = 0; ctr < AeroFunctions[axis_ctr+3].size(); ctr++) {
vMomentsMRC(axis_ctr+1) += AeroFunctions[axis_ctr+3][ctr]->GetValue();
AeroFunctionArray* array = &AeroFunctions[axis_ctr+3];
for (AeroFunctionArray::iterator f=array->begin(); f != array->end(); ++f) {
// Tell the Functions to cache values, so when the function values are
// being requested for output, the functions do not get calculated again
// in a context that might have changed, but instead use the values that
// have already been calculated for this frame.
(*f)->cacheValue(true);
vMomentsMRC(axis_ctr+1) += (*f)->GetValue();
}
}
vMoments = vMomentsMRC + vDXYZcg*vForces; // M = r X F
Expand All @@ -283,7 +297,7 @@ bool FGAerodynamics::Run(bool Holding)

bool FGAerodynamics::Load(Element *document)
{
string parameter, axis, scratch;
string axis;
string scratch_unit="";
Element *temp_element, *axis_element, *function_element;

Expand Down Expand Up @@ -333,15 +347,15 @@ bool FGAerodynamics::Load(Element *document)
if (!apply_at_cg) {
try {
ca.push_back( new FGFunction(PropertyManager, function_element) );
} catch (string const str) {
} catch (const string& str) {
cerr << endl << fgred << "Error loading aerodynamic function in "
<< current_func_name << ":" << str << " Aborting." << reset << endl;
return false;
}
} else {
try {
ca_atCG.push_back( new FGFunction(PropertyManager, function_element) );
} catch (string const str) {
} catch (const string& str) {
cerr << endl << fgred << "Error loading aerodynamic function in "
<< current_func_name << ":" << str << " Aborting." << reset << endl;
return false;
Expand Down

0 comments on commit 18c143a

Please sign in to comment.