]> git.mxchange.org Git - flightgear.git/commitdiff
Sync. with JSBSim CVS
authorErik Hofman <erik@ehofman.com>
Sun, 19 Sep 2010 09:18:13 +0000 (11:18 +0200)
committerErik Hofman <erik@ehofman.com>
Sun, 19 Sep 2010 09:18:13 +0000 (11:18 +0200)
src/FDM/JSBSim/math/FGModelFunctions.cpp [new file with mode: 0755]
src/FDM/JSBSim/math/FGModelFunctions.h [new file with mode: 0755]

diff --git a/src/FDM/JSBSim/math/FGModelFunctions.cpp b/src/FDM/JSBSim/math/FGModelFunctions.cpp
new file mode 100755 (executable)
index 0000000..62a7e26
--- /dev/null
@@ -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 <string>
+
+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; i<interface_properties.size(); i++) delete interface_properties[i];
+  interface_properties.clear();
+
+  for (unsigned int i=0; i<PreFunctions.size(); i++) delete PreFunctions[i];
+  for (unsigned int i=0; i<PostFunctions.size(); i++) delete PostFunctions[i];
+
+  if (debug_lvl & 2) cout << "Destroyed:    FGModelFunctions" << endl;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+bool FGModelFunctions::Load(Element* el, FGPropertyManager* PM, string prefix)
+{
+  // Interface properties are all stored in the interface properties array.
+  string interface_property_string = "";
+
+  Element *property_element = el->FindElement("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 <FGFunction*>::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 <FGFunction*>::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 (executable)
index 0000000..f98f2b4
--- /dev/null
@@ -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 <vector>
+#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 <FGFunction*> PreFunctions;
+  std::vector <FGFunction*> PostFunctions;
+  std::vector <double*> interface_properties;
+};
+
+} // namespace JSBSim
+
+#endif