JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
FGMassBalance.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGMassBalance.h
4  Author: Jon S. Berndt
5  Date started: 09/12/2000
6 
7  ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) --------------
8 
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free
11  Software Foundation; either version 2 of the License, or (at your option) any
12  later version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17  details.
18 
19  You should have received a copy of the GNU Lesser General Public License along
20  with this program; if not, write to the Free Software Foundation, Inc., 59
21  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be
24  found on the world wide web at http://www.gnu.org.
25 
26 HISTORY
27 --------------------------------------------------------------------------------
28 09/12/2000 JSB Created
29 
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33 
34 #ifndef FGMASSBALANCE_H
35 #define FGMASSBALANCE_H
36 
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 
41 #include "FGModel.h"
42 #include "math/FGMatrix33.h"
43 
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 FORWARD DECLARATIONSS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 
48 namespace JSBSim {
49 
50 class FGPropagate;
51 class FGGroundReactions;
52 
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 CLASS DOCUMENTATION
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 
118 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 CLASS DECLARATION
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
121 
122 class FGMassBalance : public FGModel
123 {
124 
125 public:
126  explicit FGMassBalance(FGFDMExec*);
127  ~FGMassBalance();
128 
129  bool Load(Element* el) override;
130  bool InitModel(void) override;
139  bool Run(bool Holding) override;
140 
141  double GetMass(void) const {return Mass;}
142  double GetWeight(void) const {return Weight;}
143  double GetEmptyWeight(void) const {return EmptyWeight;}
146  const FGColumnVector3& GetXYZcg(void) const {return vXYZcg;}
147  double GetXYZcg(int axis) const {return vXYZcg(axis);}
148  const FGColumnVector3& GetDeltaXYZcg(void) const {return vDeltaXYZcg;}
149  double GetDeltaXYZcg(int axis) const {return vDeltaXYZcg(axis);}
150 
159  FGMatrix33 GetPointmassInertia(double mass_sl, const FGColumnVector3& r) const
160  {
162  FGColumnVector3 sv = mass_sl*v;
163  double xx = sv(1)*v(1);
164  double yy = sv(2)*v(2);
165  double zz = sv(3)*v(3);
166  double xy = -sv(1)*v(2);
167  double xz = -sv(1)*v(3);
168  double yz = -sv(2)*v(3);
169  return FGMatrix33( yy+zz, xy, xz,
170  xy, xx+zz, yz,
171  xz, yz, xx+yy );
172  }
173 
184 
185  void SetEmptyWeight(double EW) { EmptyWeight = EW;}
186  void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
187 
188  void AddPointMass(Element* el);
189  double GetTotalPointMassWeight(void) const;
190 
191  const FGColumnVector3& GetPointMassMoment(void);
193  const FGMatrix33& GetJ(void) const {return mJ;}
195  const FGMatrix33& GetJinv(void) const {return mJinv;}
196  void SetAircraftBaseInertias(const FGMatrix33& BaseJ) {baseJ = BaseJ;}
197  void GetMassPropertiesReport(int i);
198 
199  struct Inputs {
200  double GasMass;
201  double TanksWeight;
202  FGColumnVector3 GasMoment;
203  FGMatrix33 GasInertia;
204  FGColumnVector3 TanksMoment;
205  FGMatrix33 TankInertia;
206  bool WOW;
207  } in;
208 
209 private:
210  FGPropagate* Propagate;
211  double Weight;
212  double EmptyWeight;
213  double Mass;
214  FGMatrix33 mJ;
215  FGMatrix33 mJinv;
216  FGMatrix33 pmJ;
217  FGMatrix33 baseJ;
218  FGColumnVector3 vXYZcg;
219  FGColumnVector3 vLastXYZcg;
220  FGColumnVector3 vDeltaXYZcg;
221  FGColumnVector3 vDeltaXYZcgBody;
222  FGColumnVector3 vXYZtank;
223  FGColumnVector3 vbaseXYZcg;
224  FGColumnVector3 vPMxyz;
225  FGColumnVector3 PointMassCG;
226  const FGMatrix33& CalculatePMInertias(void);
227  double GetIxx(void) const { return mJ(1,1); }
228  double GetIyy(void) const { return mJ(2,2); }
229  double GetIzz(void) const { return mJ(3,3); }
230  double GetIxy(void) const { return -mJ(1,2); }
231  double GetIxz(void) const { return mJ(1,3); }
232  double GetIyz(void) const { return -mJ(2,3); }
233 
236  struct PointMass {
237  PointMass(double w, FGColumnVector3& vXYZ) :
238  eShapeType(esUnspecified), Location(vXYZ), Weight(w), Radius(0.0),
239  Length(0.0) {}
240 
241  void CalculateShapeInertia(void) {
242  switch(eShapeType) {
243  case esTube:
244  mPMInertia(1,1) = (Weight/(slugtolb))*Radius*Radius; // mr^2
245  mPMInertia(2,2) = (Weight/(slugtolb*12))*(6*Radius*Radius + Length*Length);
246  mPMInertia(3,3) = mPMInertia(2,2);
247  break;
248  case esCylinder:
249  mPMInertia(1,1) = (Weight/(slugtolb*2))*Radius*Radius; // 0.5*mr^2
250  mPMInertia(2,2) = (Weight/(slugtolb*12))*(3*Radius*Radius + Length*Length);
251  mPMInertia(3,3) = mPMInertia(2,2);
252  break;
253  case esSphere:
254  mPMInertia(1,1) = (Weight/(slugtolb*3))*Radius*Radius*2; // (2mr^2)/3
255  mPMInertia(2,2) = mPMInertia(1,1);
256  mPMInertia(3,3) = mPMInertia(1,1);
257  break;
258  case esBall:
259  mPMInertia(1,1) = (Weight/(slugtolb*5))*Radius*Radius*2; // (2mr^2)/5
260  mPMInertia(2,2) = mPMInertia(1,1);
261  mPMInertia(3,3) = mPMInertia(1,1);
262  break;
263  default:
264  break;
265  }
266  }
267 
268  enum esShape {esUnspecified, esTube, esCylinder, esSphere, esBall} eShapeType;
269  FGColumnVector3 Location;
270  double Weight;
271  double Radius;
272  double Length;
273  std::string Name;
274  FGMatrix33 mPMInertia;
275 
276  double GetPointMassLocation(int axis) const {return Location(axis);}
277  double GetPointMassWeight(void) const {return Weight;}
278  esShape GetShapeType(void) {return eShapeType;}
279  const FGColumnVector3& GetLocation(void) {return Location;}
280  const FGMatrix33& GetPointMassInertia(void) {return mPMInertia;}
281  const std::string& GetName(void) {return Name;}
282 
283  void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
284  void SetPointMassWeight(double wt) {
285  Weight = wt;
286  CalculateShapeInertia();
287  }
288  void SetPointMassShapeType(esShape st) {eShapeType = st;}
289  void SetRadius(double r) {Radius = r;}
290  void SetLength(double l) {Length = l;}
291  void SetName(const std::string& name) {Name = name;}
292  void SetPointMassMoI(const FGMatrix33& MoI) { mPMInertia = MoI; }
293  double GetPointMassMoI(int r, int c) {return mPMInertia(r,c);}
294 
295  void bind(FGPropertyManager* PropertyManager, unsigned int num);
296  };
297 
298  std::vector <struct PointMass*> PointMasses;
299 
300  void bind(void);
301  void Debug(int from) override;
302 };
303 }
304 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 #endif
JSBSim::FGFDMExec
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:185
JSBSim::FGColumnVector3
This class implements a 3 element column vector.
Definition: FGColumnVector3.h:63
JSBSim::FGModel
Base class for all scheduled JSBSim models.
Definition: FGModel.h:68
JSBSim::FGMassBalance::Inputs
Definition: FGMassBalance.h:199
JSBSim::FGMassBalance::StructuralToBody
FGColumnVector3 StructuralToBody(const FGColumnVector3 &r) const
Conversion from the structural frame to the body frame.
Definition: FGMassBalance.cpp:364
JSBSim::FGMassBalance
Models weight, balance and moment of inertia information.
Definition: FGMassBalance.h:122
JSBSim::FGMassBalance::GetJinv
const FGMatrix33 & GetJinv(void) const
Returns the inverse of the inertia matrix expressed in the body frame.
Definition: FGMassBalance.h:195
JSBSim::FGMatrix33
Handles matrix math operations.
Definition: FGMatrix33.h:69
JSBSim::FGJSBBase::slugtolb
static constexpr double slugtolb
Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can a...
Definition: FGJSBBase.h:366
JSBSim::FGPropagate
Models the EOM and integration/propagation of state.
Definition: FGPropagate.h:93
JSBSim::FGMassBalance::Run
bool Run(bool Holding) override
Runs the Mass Balance model; called by the Executive Can pass in a value indicating if the executive ...
Definition: FGMassBalance.cpp:181
JSBSim::FGMassBalance::GetXYZcg
const FGColumnVector3 & GetXYZcg(void) const
Returns the coordinates of the center of gravity expressed in the structural frame.
Definition: FGMassBalance.h:146
JSBSim::FGMassBalance::GetJ
const FGMatrix33 & GetJ(void) const
Returns the inertia matrix expressed in the body frame.
Definition: FGMassBalance.h:193
JSBSim::FGMassBalance::GetPointmassInertia
FGMatrix33 GetPointmassInertia(double mass_sl, const FGColumnVector3 &r) const
Computes the inertia contribution of a pointmass.
Definition: FGMassBalance.h:159
JSBSim::Element
Definition: FGXMLElement.h:143