1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGBuoyantForces.cpp
4 Authors: Anders Gidenstam, Jon S. Berndt
6 Purpose: Encapsulates the buoyant forces
8 ------------- Copyright (C) 2008 - 2011 Anders Gidenstam -------------
9 ------------- Copyright (C) 2008 Jon S. Berndt (jon@jsbsim.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
32 --------------------------------------------------------------------------------
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 #include "FGBuoyantForces.h"
40 #include "FGMassBalance.h"
41 #include "input_output/FGPropertyManager.h"
48 static const char *IdSrc = "$Id: FGBuoyantForces.cpp,v 1.21 2011/10/31 14:54:41 bcoconni Exp $";
49 static const char *IdHdr = ID_BUOYANTFORCES;
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 FGBuoyantForces::FGBuoyantForces(FGFDMExec* FDMExec) : FGModel(FDMExec)
57 Name = "FGBuoyantForces";
61 vTotalForces.InitMatrix();
62 vTotalMoments.InitMatrix();
64 gasCellJ.InitMatrix();
69 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 FGBuoyantForces::~FGBuoyantForces()
73 for (unsigned int i=0; i<Cells.size(); i++) delete Cells[i];
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 bool FGBuoyantForces::InitModel(void)
86 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 bool FGBuoyantForces::Run(bool Holding)
90 if (FGModel::Run(Holding)) return true;
91 if (Holding) return false; // if paused don't execute
92 if (NoneDefined) return true;
96 vTotalForces.InitMatrix();
97 vTotalMoments.InitMatrix();
99 for (unsigned int i=0; i<Cells.size(); i++) {
100 Cells[i]->Calculate(FDMExec->GetDeltaT());
101 vTotalForces += Cells[i]->GetBodyForces();
102 vTotalMoments += Cells[i]->GetMoments();
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 bool FGBuoyantForces::Load(Element *element)
114 string fname="", file="";
115 Element *gas_cell_element;
119 string separator = "/";
121 fname = element->GetAttributeValue("file");
122 if (!fname.empty()) {
123 file = FDMExec->GetFullAircraftPath() + separator + fname;
124 document = LoadXMLDocument(file);
129 FGModel::Load(element); // Perform base class Load
131 gas_cell_element = document->FindElement("gas_cell");
132 while (gas_cell_element) {
134 Cells.push_back(new FGGasCell(FDMExec, gas_cell_element, Cells.size(), in));
135 gas_cell_element = document->FindNextElement("gas_cell");
138 PostLoad(element, PropertyManager);
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 double FGBuoyantForces::GetGasMass(void) const
153 for (unsigned int i = 0; i < Cells.size(); i++) {
154 Gw += Cells[i]->GetMass();
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 const FGColumnVector3& FGBuoyantForces::GetGasMassMoment(void)
164 vXYZgasCell_arm.InitMatrix();
165 for (unsigned int i = 0; i < Cells.size(); i++) {
166 vXYZgasCell_arm += Cells[i]->GetMassMoment();
168 return vXYZgasCell_arm;
171 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 const FGMatrix33& FGBuoyantForces::GetGasMassInertia(void)
175 const unsigned int size = Cells.size();
177 if (size == 0) return gasCellJ;
179 gasCellJ = FGMatrix33();
181 for (unsigned int i=0; i < size; i++) {
182 gasCellJ += Cells[i]->GetInertia();
188 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 string FGBuoyantForces::GetBuoyancyStrings(const string& delimeter)
192 string CoeffStrings = "";
194 bool firstime = true;
195 for (sd = 0; sd < variables.size(); sd++) {
199 CoeffStrings += delimeter;
201 CoeffStrings += variables[sd]->GetName();
204 for (axis = 0; axis < 6; axis++) {
205 for (sd = 0; sd < AeroFunctions[axis].size(); sd++) {
209 CoeffStrings += delimeter;
211 CoeffStrings += AeroFunctions[axis][sd]->GetName();
218 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 string FGBuoyantForces::GetBuoyancyValues(const string& delimeter)
222 string SDValues = "";
224 bool firstime = true;
225 for (sd = 0; sd < variables.size(); sd++) {
229 SDValues += delimeter;
231 SDValues += variables[sd]->GetValueAsString();
234 for (unsigned int axis = 0; axis < 6; axis++) {
235 for (unsigned int sd = 0; sd < AeroFunctions[axis].size(); sd++) {
239 SDValues += delimeter;
241 SDValues += AeroFunctions[axis][sd]->GetValueAsString();
248 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 void FGBuoyantForces::bind(void)
252 typedef double (FGBuoyantForces::*PGF)(int) const;
253 typedef void (FGBuoyantForces::*PSF)(int, double);
254 PropertyManager->Tie("moments/l-buoyancy-lbsft", this, eL,
255 (PGF)&FGBuoyantForces::GetMoments, (PSF)0, false);
256 PropertyManager->Tie("moments/m-buoyancy-lbsft", this, eM,
257 (PGF)&FGBuoyantForces::GetMoments, (PSF)0, false);
258 PropertyManager->Tie("moments/n-buoyancy-lbsft", this, eN,
259 (PGF)&FGBuoyantForces::GetMoments, (PSF)0, false);
260 PropertyManager->Tie("forces/fbx-buoyancy-lbs", this, eX,
261 (PGF)&FGBuoyantForces::GetForces, (PSF)0, false);
262 PropertyManager->Tie("forces/fby-buoyancy-lbs", this, eY,
263 (PGF)&FGBuoyantForces::GetForces, (PSF)0, false);
264 PropertyManager->Tie("forces/fbz-buoyancy-lbs", this, eZ,
265 (PGF)&FGBuoyantForces::GetForces, (PSF)0, false);
268 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 // The bitmasked value choices are as follows:
270 // unset: In this case (the default) JSBSim would only print
271 // out the normally expected messages, essentially echoing
272 // the config files as they are read. If the environment
273 // variable is not set, debug_lvl is set to 1 internally
274 // 0: This requests JSBSim not to output any messages
276 // 1: This value explicity requests the normal JSBSim
278 // 2: This value asks for a message to be printed out when
279 // a class is instantiated
280 // 4: When this value is set, a message is displayed when a
281 // FGModel object executes its Run() method
282 // 8: When this value is set, various runtime state variables
283 // are printed out periodically
284 // 16: When set various parameters are sanity checked and
285 // a message is printed out when they go out of bounds
287 void FGBuoyantForces::Debug(int from)
289 if (debug_lvl <= 0) return;
291 if (debug_lvl & 1) { // Standard console startup message output
292 if (from == 2) { // Loader
293 cout << endl << " Buoyant Forces: " << endl;
296 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
297 if (from == 0) cout << "Instantiated: FGBuoyantForces" << endl;
298 if (from == 1) cout << "Destroyed: FGBuoyantForces" << endl;
300 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
302 if (debug_lvl & 8 ) { // Runtime state variables
304 if (debug_lvl & 16) { // Sanity checking
306 if (debug_lvl & 64) {
307 if (from == 0) { // Constructor
308 cout << IdSrc << endl;
309 cout << IdHdr << endl;
314 } // namespace JSBSim