JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGBuoyantForces.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGBuoyantForces.cpp
4 Authors: Anders Gidenstam, Jon S. Berndt
5 Date started: 01/21/08
6 Purpose: Encapsulates the buoyant forces
7
8 ------------- Copyright (C) 2008 - 2011 Anders Gidenstam -------------
9 ------------- Copyright (C) 2008 Jon S. Berndt (jon@jsbsim.org) -------------
10
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
13 Software Foundation; either version 2 of the License, or (at your option) any
14 later version.
15
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
19 details.
20
21 You should have received a copy of the GNU Lesser General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc., 59
23 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 Further information about the GNU Lesser General Public License can also be
26 found on the world wide web at http://www.gnu.org.
27
28FUNCTIONAL DESCRIPTION
29--------------------------------------------------------------------------------
30
31HISTORY
32--------------------------------------------------------------------------------
3301/21/08 JSB Created
34
35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36INCLUDES
37%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39#include "FGFDMExec.h"
40#include "FGBuoyantForces.h"
41#include "input_output/FGXMLElement.h"
42#include "input_output/FGLog.h"
43
44using namespace std;
45
46namespace JSBSim {
47
48/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49CLASS IMPLEMENTATION
50%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
53{
54 Name = "FGBuoyantForces";
55
56 NoneDefined = true;
57
58 vTotalForces.InitMatrix();
59 vTotalMoments.InitMatrix();
60
61 gasCellJ.InitMatrix();
62
63 Debug(0);
64}
65
66//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
69{
70 for (unsigned int i=0; i<Cells.size(); i++) delete Cells[i];
71 Cells.clear();
72
73 Debug(1);
74}
75
76//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77
78bool FGBuoyantForces::InitModel(void)
79{
80 if (!FGModel::InitModel()) return false;
81
82 vTotalForces.InitMatrix();
83 vTotalMoments.InitMatrix();
84
85 return true;
86}
87
88//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89
90bool FGBuoyantForces::Run(bool Holding)
91{
92 if (FGModel::Run(Holding)) return true;
93 if (Holding) return false; // if paused don't execute
94 if (NoneDefined) return true;
95
96 RunPreFunctions();
97
98 vTotalForces.InitMatrix();
99 vTotalMoments.InitMatrix();
100
101 for (unsigned int i=0; i<Cells.size(); i++) {
102 Cells[i]->Calculate(FDMExec->GetDeltaT());
103 vTotalForces += Cells[i]->GetBodyForces();
104 vTotalMoments += Cells[i]->GetMoments();
105 }
106
107 RunPostFunctions();
108
109 return false;
110}
111
112//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
115{
116 Element *gas_cell_element;
117
118 Debug(2);
119
120 // Perform base class Pre-Load
121 if (!FGModel::Upload(document, true))
122 return false;
123
124 gas_cell_element = document->FindElement("gas_cell");
125 while (gas_cell_element) {
126 NoneDefined = false;
127 Cells.push_back(new FGGasCell(FDMExec, gas_cell_element, Cells.size(), in));
128 gas_cell_element = document->FindNextElement("gas_cell");
129 }
130
131 PostLoad(document, FDMExec);
132
133 if (!NoneDefined) {
134 bind();
135 }
136
137 return true;
138}
139
140//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141
143{
144 double Gw = 0.0;
145
146 for (unsigned int i = 0; i < Cells.size(); i++) {
147 Gw += Cells[i]->GetMass();
148 }
149
150 return Gw;
151}
152
153//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154
156{
157 vXYZgasCell_arm.InitMatrix();
158 for (unsigned int i = 0; i < Cells.size(); i++) {
159 vXYZgasCell_arm += Cells[i]->GetMassMoment();
160 }
161 return vXYZgasCell_arm;
162}
163
164//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165
167{
168 size_t size = Cells.size();
169
170 if (size == 0) return gasCellJ;
171
172 gasCellJ.InitMatrix();
173
174 for (unsigned int i=0; i < size; i++) {
175 gasCellJ += Cells[i]->GetInertia();
176 }
177
178 return gasCellJ;
179}
180
181//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182
183string FGBuoyantForces::GetBuoyancyStrings(const string& delimeter)
184{
185 string CoeffStrings = "";
186/*
187 bool firstime = true;
188 for (sd = 0; sd < variables.size(); sd++) {
189 if (firstime) {
190 firstime = false;
191 } else {
192 CoeffStrings += delimeter;
193 }
194 CoeffStrings += variables[sd]->GetName();
195 }
196
197 for (axis = 0; axis < 6; axis++) {
198 for (sd = 0; sd < AeroFunctions[axis].size(); sd++) {
199 if (firstime) {
200 firstime = false;
201 } else {
202 CoeffStrings += delimeter;
203 }
204 CoeffStrings += AeroFunctions[axis][sd]->GetName();
205 }
206 }
207*/
208 return CoeffStrings;
209}
210
211//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212
213string FGBuoyantForces::GetBuoyancyValues(const string& delimeter)
214{
215 string SDValues = "";
216/*
217 bool firstime = true;
218 for (sd = 0; sd < variables.size(); sd++) {
219 if (firstime) {
220 firstime = false;
221 } else {
222 SDValues += delimeter;
223 }
224 SDValues += variables[sd]->GetValueAsString();
225 }
226
227 for (unsigned int axis = 0; axis < 6; axis++) {
228 for (unsigned int sd = 0; sd < AeroFunctions[axis].size(); sd++) {
229 if (firstime) {
230 firstime = false;
231 } else {
232 SDValues += delimeter;
233 }
234 SDValues += AeroFunctions[axis][sd]->GetValueAsString();
235 }
236 }
237*/
238 return SDValues;
239}
240
241//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242
243void FGBuoyantForces::bind(void)
244{
245 using PSF = void (FGBuoyantForces::*)(int, double);
246 PropertyManager->Tie("moments/l-buoyancy-lbsft", this, eL,
247 &FGBuoyantForces::GetMoments, (PSF)nullptr);
248 PropertyManager->Tie("moments/m-buoyancy-lbsft", this, eM,
249 &FGBuoyantForces::GetMoments, (PSF)nullptr);
250 PropertyManager->Tie("moments/n-buoyancy-lbsft", this, eN,
251 &FGBuoyantForces::GetMoments, (PSF)nullptr);
252 PropertyManager->Tie("forces/fbx-buoyancy-lbs", this, eX,
253 &FGBuoyantForces::GetForces, (PSF)nullptr);
254 PropertyManager->Tie("forces/fby-buoyancy-lbs", this, eY,
255 &FGBuoyantForces::GetForces, (PSF)nullptr);
256 PropertyManager->Tie("forces/fbz-buoyancy-lbs", this, eZ,
257 &FGBuoyantForces::GetForces, (PSF)nullptr);
258}
259
260//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261// The bitmasked value choices are as follows:
262// unset: In this case (the default) JSBSim would only print
263// out the normally expected messages, essentially echoing
264// the config files as they are read. If the environment
265// variable is not set, debug_lvl is set to 1 internally
266// 0: This requests JSBSim not to output any messages
267// whatsoever.
268// 1: This value explicity requests the normal JSBSim
269// startup messages
270// 2: This value asks for a message to be printed out when
271// a class is instantiated
272// 4: When this value is set, a message is displayed when a
273// FGModel object executes its Run() method
274// 8: When this value is set, various runtime state variables
275// are printed out periodically
276// 16: When set various parameters are sanity checked and
277// a message is printed out when they go out of bounds
278
279void FGBuoyantForces::Debug(int from)
280{
281 if (debug_lvl <= 0) return;
282
283 if (debug_lvl & 1) { // Standard console startup message output
284 if (from == 2) { // Loader
285 FGLogging log(LogLevel::DEBUG);
286 log << "\n Buoyant Forces: \n";
287 }
288 }
289 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
290 FGLogging log(LogLevel::DEBUG);
291 if (from == 0) log << "Instantiated: FGBuoyantForces\n";
292 if (from == 1) log << "Destroyed: FGBuoyantForces\n";
293 }
294 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
295 }
296 if (debug_lvl & 8 ) { // Runtime state variables
297 }
298 if (debug_lvl & 16) { // Sanity checking
299 }
300 if (debug_lvl & 64) {
301 if (from == 0) { // Constructor
302 }
303 }
304}
305
306} // namespace JSBSim
Element * FindElement(const std::string &el="")
Searches for a specified element.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
Encapsulates the Buoyant forces calculations.
const FGColumnVector3 & GetMoments(void) const
Gets the total Buoyancy moment vector.
~FGBuoyantForces() override
Destructor.
bool Load(Element *element) override
Loads the Buoyant forces model.
FGBuoyantForces(FGFDMExec *Executive)
Constructor.
std::string GetBuoyancyStrings(const std::string &delimeter)
Gets the strings for the current set of gas cells.
const FGMatrix33 & GetGasMassInertia(void)
Gets the total moments of inertia for the gas mass in the body frame.
bool Run(bool Holding) override
Runs the Buoyant forces model; called by the Executive Can pass in a value indicating if the executiv...
double GetGasMass(void) const
Gets the total gas mass.
std::string GetBuoyancyValues(const std::string &delimeter)
Gets the coefficient values.
const FGColumnVector3 & GetGasMassMoment(void)
Gets the total moment from the gas mass.
const FGColumnVector3 & GetForces(void) const
Gets the total Buoyant force vector.
This class implements a 3 element column vector.
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
double GetDeltaT(void) const
Returns the simulation delta T.
Definition FGFDMExec.h:553
Models a gas cell.
Definition FGGasCell.h:167
Handles matrix math operations.
Definition FGMatrix33.h:70
void InitMatrix(void)
Initialize the matrix.
Base class for all scheduled JSBSim models.
Definition FGModel.h:70
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition FGModel.cpp:90
bool Upload(Element *el, bool preLoad)
Uploads this model in memory.
Definition FGModel.cpp:111
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71