]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/FGBuoyantForces.cpp
Sync. with JSBSim CVS
[flightgear.git] / src / FDM / JSBSim / models / FGBuoyantForces.cpp
index 505c803468debdcd029dcde924837ce29de53a86..b3808d70fa71581b348a1f83d8943135670cf3e4 100644 (file)
@@ -5,8 +5,8 @@
  Date started: 01/21/08
  Purpose:      Encapsulates the buoyant forces
 
- ------------- Copyright (C) 2008  Anders Gidenstam               -------------
- ------------- Copyright (C) 2008  Jon S. Berndt (jsb@hal-pc.org) -------------
+ ------------- Copyright (C) 2008 - 2010  Anders Gidenstam        -------------
+ ------------- Copyright (C) 2008  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
@@ -38,11 +38,14 @@ INCLUDES
 
 #include "FGBuoyantForces.h"
 #include "FGMassBalance.h"
-#include <input_output/FGPropertyManager.h>  // Need?
+#include "input_output/FGPropertyManager.h"
+#include <iostream>
+
+using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGBuoyantForces.cpp,v 1.14 2010/11/18 12:38:06 jberndt Exp $";
 static const char *IdHdr = ID_BUOYANTFORCES;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -60,8 +63,6 @@ FGBuoyantForces::FGBuoyantForces(FGFDMExec* FDMExec) : FGModel(FDMExec)
 
   gasCellJ.InitMatrix();
 
-  bind();
-
   Debug(0);
 }
 
@@ -72,8 +73,6 @@ FGBuoyantForces::~FGBuoyantForces()
   for (unsigned int i=0; i<Cells.size(); i++) delete Cells[i];
   Cells.clear();
 
-  unbind();
-
   Debug(1);
 }
 
@@ -94,6 +93,8 @@ bool FGBuoyantForces::Run(void)
   if (FDMExec->Holding()) return false; // if paused don't execute
   if (NoneDefined) return true;
 
+  RunPreFunctions();
+
   vTotalForces.InitMatrix();
   vTotalMoments.InitMatrix();
 
@@ -103,6 +104,8 @@ bool FGBuoyantForces::Run(void)
     vTotalMoments += Cells[i]->GetMoments();
   }
 
+  RunPostFunctions();
+
   return false;
 }
 
@@ -116,9 +119,6 @@ bool FGBuoyantForces::Load(Element *element)
   Debug(2);
 
   string separator = "/";
-#ifdef macintosh
-  separator = ";";
-#endif
 
   fname = element->GetAttributeValue("file");
   if (!fname.empty()) {
@@ -128,6 +128,8 @@ bool FGBuoyantForces::Load(Element *element)
     document = element;
   }
 
+  FGModel::Load(element); // Perform base class Load
+
   gas_cell_element = document->FindElement("gas_cell");
   while (gas_cell_element) {
     NoneDefined = false;
@@ -135,6 +137,12 @@ bool FGBuoyantForces::Load(Element *element)
     gas_cell_element = document->FindNextElement("gas_cell");
   }
   
+  PostLoad(element, PropertyManager);
+
+  if (!NoneDefined) {
+    bind();
+  }
+
   return true;
 }
 
@@ -153,7 +161,7 @@ double FGBuoyantForces::GetGasMass(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-FGColumnVector3& FGBuoyantForces::GetGasMassMoment(void)
+const FGColumnVector3& FGBuoyantForces::GetGasMassMoment(void)
 {
   vXYZgasCell_arm.InitMatrix();
   for (unsigned int i = 0; i < Cells.size(); i++) {
@@ -164,7 +172,7 @@ FGColumnVector3& FGBuoyantForces::GetGasMassMoment(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-FGMatrix33& FGBuoyantForces::GetGasMassInertia(void)
+const FGMatrix33& FGBuoyantForces::GetGasMassInertia(void)
 {
   const unsigned int size = Cells.size();
   
@@ -173,7 +181,7 @@ FGMatrix33& FGBuoyantForces::GetGasMassInertia(void)
   gasCellJ = FGMatrix33();
 
   for (unsigned int i=0; i < size; i++) {
-    FGColumnVector3 v = MassBalance->StructuralToBody( Cells[i]->GetXYZ() );
+    FGColumnVector3 v = FDMExec->GetMassBalance()->StructuralToBody( Cells[i]->GetXYZ() );
     // Body basis is in FT. 
     const double mass = Cells[i]->GetMass();
     
@@ -193,8 +201,8 @@ FGMatrix33& FGBuoyantForces::GetGasMassInertia(void)
 string FGBuoyantForces::GetBuoyancyStrings(string delimeter)
 {
   string CoeffStrings = "";
-  bool firstime = true;
 /*
+  bool firstime = true;
   for (sd = 0; sd < variables.size(); sd++) {
     if (firstime) {
       firstime = false;
@@ -223,8 +231,8 @@ string FGBuoyantForces::GetBuoyancyStrings(string delimeter)
 string FGBuoyantForces::GetBuoyancyValues(string delimeter)
 {
   string SDValues = "";
-  bool firstime = true;
 /*
+  bool firstime = true;
   for (sd = 0; sd < variables.size(); sd++) {
     if (firstime) {
       firstime = false;
@@ -252,12 +260,19 @@ string FGBuoyantForces::GetBuoyancyValues(string delimeter)
 
 void FGBuoyantForces::bind(void)
 {
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-void FGBuoyantForces::unbind(void)
-{
+  typedef double (FGBuoyantForces::*PMF)(int) const;
+  PropertyManager->Tie("moments/l-buoyancy-lbsft", this, eL,
+                       (PMF)&FGBuoyantForces::GetMoments);
+  PropertyManager->Tie("moments/m-buoyancy-lbsft", this, eM,
+                       (PMF)&FGBuoyantForces::GetMoments);
+  PropertyManager->Tie("moments/n-buoyancy-lbsft", this, eN,
+                       (PMF)&FGBuoyantForces::GetMoments);
+  PropertyManager->Tie("forces/fbx-buoyancy-lbs", this, eX,
+                       (PMF)&FGBuoyantForces::GetForces);
+  PropertyManager->Tie("forces/fby-buoyancy-lbs", this, eY,
+                       (PMF)&FGBuoyantForces::GetForces);
+  PropertyManager->Tie("forces/fbz-buoyancy-lbs", this, eZ,
+                       (PMF)&FGBuoyantForces::GetForces);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%