JSBSim Flight Dynamics Model 1.3.3 (16 Oct 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
52FGBuoyantForces::FGBuoyantForces(FGFDMExec* FDMExec) : FGModel(FDMExec, "FGBuoyantForces")
53{
54 NoneDefined = true;
55
56 vTotalForces.InitMatrix();
57 vTotalMoments.InitMatrix();
58
59 gasCellJ.InitMatrix();
60
61 Debug(0);
62}
63
64//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65
67{
68 for (unsigned int i=0; i<Cells.size(); i++) delete Cells[i];
69 Cells.clear();
70
71 Debug(1);
72}
73
74//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76bool FGBuoyantForces::InitModel(void)
77{
78 if (!FGModel::InitModel()) return false;
79
80 vTotalForces.InitMatrix();
81 vTotalMoments.InitMatrix();
82
83 return true;
84}
85
86//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87
88bool FGBuoyantForces::Run(bool Holding)
89{
90 if (FGModel::Run(Holding)) return true;
91 if (Holding) return false; // if paused don't execute
92 if (NoneDefined) return true;
93
94 RunPreFunctions();
95
96 vTotalForces.InitMatrix();
97 vTotalMoments.InitMatrix();
98
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();
103 }
104
105 RunPostFunctions();
106
107 return false;
108}
109
110//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111
113{
114 Element *gas_cell_element;
115
116 Debug(2);
117
118 // Perform base class Pre-Load
119 if (!FGModel::Upload(document, true))
120 return false;
121
122 gas_cell_element = document->FindElement("gas_cell");
123 while (gas_cell_element) {
124 NoneDefined = false;
125 Cells.push_back(new FGGasCell(FDMExec, gas_cell_element, Cells.size(), in));
126 gas_cell_element = document->FindNextElement("gas_cell");
127 }
128
129 PostLoad(document, FDMExec);
130
131 if (!NoneDefined) {
132 bind();
133 }
134
135 return true;
136}
137
138//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139
141{
142 double Gw = 0.0;
143
144 for (unsigned int i = 0; i < Cells.size(); i++) {
145 Gw += Cells[i]->GetMass();
146 }
147
148 return Gw;
149}
150
151//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152
154{
155 vXYZgasCell_arm.InitMatrix();
156 for (unsigned int i = 0; i < Cells.size(); i++) {
157 vXYZgasCell_arm += Cells[i]->GetMassMoment();
158 }
159 return vXYZgasCell_arm;
160}
161
162//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163
165{
166 size_t size = Cells.size();
167
168 if (size == 0) return gasCellJ;
169
170 gasCellJ.InitMatrix();
171
172 for (unsigned int i=0; i < size; i++) {
173 gasCellJ += Cells[i]->GetInertia();
174 }
175
176 return gasCellJ;
177}
178
179//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180
181string FGBuoyantForces::GetBuoyancyStrings(const string& delimeter)
182{
183 string CoeffStrings = "";
184/*
185 bool firstime = true;
186 for (sd = 0; sd < variables.size(); sd++) {
187 if (firstime) {
188 firstime = false;
189 } else {
190 CoeffStrings += delimeter;
191 }
192 CoeffStrings += variables[sd]->GetName();
193 }
194
195 for (axis = 0; axis < 6; axis++) {
196 for (sd = 0; sd < AeroFunctions[axis].size(); sd++) {
197 if (firstime) {
198 firstime = false;
199 } else {
200 CoeffStrings += delimeter;
201 }
202 CoeffStrings += AeroFunctions[axis][sd]->GetName();
203 }
204 }
205*/
206 return CoeffStrings;
207}
208
209//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210
211string FGBuoyantForces::GetBuoyancyValues(const string& delimeter)
212{
213 string SDValues = "";
214/*
215 bool firstime = true;
216 for (sd = 0; sd < variables.size(); sd++) {
217 if (firstime) {
218 firstime = false;
219 } else {
220 SDValues += delimeter;
221 }
222 SDValues += variables[sd]->GetValueAsString();
223 }
224
225 for (unsigned int axis = 0; axis < 6; axis++) {
226 for (unsigned int sd = 0; sd < AeroFunctions[axis].size(); sd++) {
227 if (firstime) {
228 firstime = false;
229 } else {
230 SDValues += delimeter;
231 }
232 SDValues += AeroFunctions[axis][sd]->GetValueAsString();
233 }
234 }
235*/
236 return SDValues;
237}
238
239//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240
241void FGBuoyantForces::bind(void)
242{
243 using PSF = void (FGBuoyantForces::*)(int, double);
244 PropertyManager->Tie("moments/l-buoyancy-lbsft", this, eL,
245 &FGBuoyantForces::GetMoments, (PSF)nullptr);
246 PropertyManager->Tie("moments/m-buoyancy-lbsft", this, eM,
247 &FGBuoyantForces::GetMoments, (PSF)nullptr);
248 PropertyManager->Tie("moments/n-buoyancy-lbsft", this, eN,
249 &FGBuoyantForces::GetMoments, (PSF)nullptr);
250 PropertyManager->Tie("forces/fbx-buoyancy-lbs", this, eX,
251 &FGBuoyantForces::GetForces, (PSF)nullptr);
252 PropertyManager->Tie("forces/fby-buoyancy-lbs", this, eY,
253 &FGBuoyantForces::GetForces, (PSF)nullptr);
254 PropertyManager->Tie("forces/fbz-buoyancy-lbs", this, eZ,
255 &FGBuoyantForces::GetForces, (PSF)nullptr);
256}
257
258//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259// The bitmasked value choices are as follows:
260// unset: In this case (the default) JSBSim would only print
261// out the normally expected messages, essentially echoing
262// the config files as they are read. If the environment
263// variable is not set, debug_lvl is set to 1 internally
264// 0: This requests JSBSim not to output any messages
265// whatsoever.
266// 1: This value explicity requests the normal JSBSim
267// startup messages
268// 2: This value asks for a message to be printed out when
269// a class is instantiated
270// 4: When this value is set, a message is displayed when a
271// FGModel object executes its Run() method
272// 8: When this value is set, various runtime state variables
273// are printed out periodically
274// 16: When set various parameters are sanity checked and
275// a message is printed out when they go out of bounds
276
277void FGBuoyantForces::Debug(int from)
278{
279 if (debug_lvl <= 0) return;
280
281 if (debug_lvl & 1) { // Standard console startup message output
282 if (from == 2) { // Loader
283 FGLogging log(LogLevel::DEBUG);
284 log << "\n Buoyant Forces: \n";
285 }
286 }
287 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
288 FGLogging log(LogLevel::DEBUG);
289 if (from == 0) log << "Instantiated: FGBuoyantForces\n";
290 if (from == 1) log << "Destroyed: FGBuoyantForces\n";
291 }
292 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
293 }
294 if (debug_lvl & 8 ) { // Runtime state variables
295 }
296 if (debug_lvl & 16) { // Sanity checking
297 }
298 if (debug_lvl & 64) {
299 if (from == 0) { // Constructor
300 }
301 }
302}
303
304} // 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:557
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:79
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition FGModel.cpp:101
bool Upload(Element *el, bool preLoad)
Uploads this model in memory.
Definition FGModel.cpp:123
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:73