From 08a42cb1645df68fee75937e3ca4b79fe24fd981 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Sun, 19 Sep 2010 11:18:13 +0200 Subject: [PATCH] Sync. with JSBSim CVS --- src/FDM/JSBSim/math/FGModelFunctions.cpp | 166 +++++++++++++++++++++++ src/FDM/JSBSim/math/FGModelFunctions.h | 85 ++++++++++++ 2 files changed, 251 insertions(+) create mode 100755 src/FDM/JSBSim/math/FGModelFunctions.cpp create mode 100755 src/FDM/JSBSim/math/FGModelFunctions.h diff --git a/src/FDM/JSBSim/math/FGModelFunctions.cpp b/src/FDM/JSBSim/math/FGModelFunctions.cpp new file mode 100755 index 000000000..62a7e26f8 --- /dev/null +++ b/src/FDM/JSBSim/math/FGModelFunctions.cpp @@ -0,0 +1,166 @@ +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + Module: FGModelFunctions.cpp + Author: Jon S. Berndt + Date started: August 2010 + + ------- Copyright (C) 2010 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 + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA. + + Further information about the GNU Lesser General Public License can also be found on + the world wide web at http://www.gnu.org. + +FUNCTIONAL DESCRIPTION +-------------------------------------------------------------------------------- + +HISTORY +-------------------------------------------------------------------------------- + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +COMMENTS, REFERENCES, and NOTES +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +INCLUDES +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +#include "FGModelFunctions.h" +#include + +using namespace std; + +namespace JSBSim { + +static const char *IdSrc = "$Id: FGModelFunctions.cpp,v 1.4 2010/09/07 00:40:03 jberndt Exp $"; +static const char *IdHdr = ID_MODELFUNCTIONS; + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +CLASS IMPLEMENTATION +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +FGModelFunctions::~FGModelFunctions() +{ + for (unsigned int i=0; iFindElement("property"); + if (property_element && debug_lvl > 0) cout << endl << " Declared properties" + << endl << endl; + while (property_element) { + interface_property_string = property_element->GetDataLine(); + if (PM->HasNode(interface_property_string)) { + cerr << " Property " << interface_property_string + << " is already defined." << endl; + } else { + double value=0.0; + if ( ! property_element->GetAttributeValue("value").empty()) + value = property_element->GetAttributeValueAsNumber("value"); + interface_properties.push_back(new double(value)); + PM->Tie(interface_property_string, interface_properties.back()); + if (debug_lvl > 0) + cout << " " << interface_property_string << " (initial value: " + << value << ")" << endl << endl; + } + property_element = el->FindNextElement("property"); + } + + // End of interface property loading logic + + PreLoad(el, PM, prefix); + + return true; // TODO: Need to make this value mean something. +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGModelFunctions::PreLoad(Element* el, FGPropertyManager* PM, string prefix) +{ + // Load model post-functions, if any + + Element *function = el->FindElement("function"); + + while (function) { + if (function->GetAttributeValue("type") == "pre") { + PreFunctions.push_back(new FGFunction(PM, function, prefix)); + } else if (function->GetAttributeValue("type").empty()) { // Assume pre-function + string funcname = function->GetAttributeValue("name"); + if (funcname.find("IdleThrust") == string::npos && // Do not process functions that are + funcname.find("MilThrust") == string::npos && // already pre-defined turbine engine + funcname.find("AugThrust") == string::npos && // functions. These are loaded within + funcname.find("Injection") == string::npos ) // the Turbine::Load() method. + { + PreFunctions.push_back(new FGFunction(PM, function, prefix)); + } + } + function = el->FindNextElement("function"); + } +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGModelFunctions::PostLoad(Element* el, FGPropertyManager* PM, string prefix) +{ + // Load model post-functions, if any + + Element *function = el->FindElement("function"); + while (function) { + if (function->GetAttributeValue("type") == "post") { + PostFunctions.push_back(new FGFunction(PM, function, prefix)); + } + function = el->FindNextElement("function"); + } +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// Tell the Functions to cache values, so when the function values +// are being used in the model, the functions do not get +// calculated each time, but instead use the values that have already +// been calculated for this frame. + +void FGModelFunctions::RunPreFunctions(void) +{ + vector ::iterator it; + for (it = PreFunctions.begin(); it != PreFunctions.end(); it++) + (*it)->cacheValue(true); +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// Tell the Functions to cache values, so when the function values +// are being used in the model, the functions do not get +// calculated each time, but instead use the values that have already +// been calculated for this frame. + +void FGModelFunctions::RunPostFunctions(void) +{ + vector ::iterator it; + for (it = PostFunctions.begin(); it != PostFunctions.end(); it++) + (*it)->GetValue(); +} + +} diff --git a/src/FDM/JSBSim/math/FGModelFunctions.h b/src/FDM/JSBSim/math/FGModelFunctions.h new file mode 100755 index 000000000..f98f2b4bf --- /dev/null +++ b/src/FDM/JSBSim/math/FGModelFunctions.h @@ -0,0 +1,85 @@ +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +Header: FGModelFunctions.h +Author: Jon Berndt +Date started: August 2010 + + ------------- Copyright (C) 2010 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 + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA. + + Further information about the GNU Lesser General Public License can also be found on + the world wide web at http://www.gnu.org. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +SENTRY +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +#ifndef FGMODELFUNCTIONS_H +#define FGMODELFUNCTIONS_H + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +INCLUDES +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +#include "FGJSBBase.h" +#include +#include "math/FGFunction.h" +#include "input_output/FGPropertyManager.h" +#include "input_output/FGXMLElement.h" + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +DEFINITIONS +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +#define ID_MODELFUNCTIONS "$Id: FGModelFunctions.h,v 1.2 2010/08/24 10:30:14 jberndt Exp $" + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +FORWARD DECLARATIONS +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +namespace JSBSim { + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +CLASS DOCUMENTATION +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +/** +@author Jon Berndt +*/ + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +DECLARATION: FGModelFunctions +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + + class FGModelFunctions : public FGJSBBase +{ +public: + ~FGModelFunctions(); + void RunPreFunctions(void); + void RunPostFunctions(void); + bool Load(Element* el, FGPropertyManager* PropertyManager, std::string prefix=""); + void PreLoad(Element* el, FGPropertyManager* PropertyManager, std::string prefix=""); + void PostLoad(Element* el, FGPropertyManager* PropertyManager, std::string prefix=""); + +protected: + std::vector PreFunctions; + std::vector PostFunctions; + std::vector interface_properties; +}; + +} // namespace JSBSim + +#endif -- 2.39.5