JSBSim Flight Dynamics Model  1.0 (02 March 2017)
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 Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  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 with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be found on
24  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 <vector>
42 #include <string>
43 #include "FGModel.h"
44 #include "math/FGColumnVector3.h"
45 #include "math/FGMatrix33.h"
46 
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 DEFINITIONS
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 
51 #define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.38 2016/12/21 08:08:32 ehofman Exp $"
52 
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 FORWARD DECLARATIONSS
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 
57 namespace JSBSim {
58 
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 CLASS DOCUMENTATION
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 
103 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 CLASS DECLARATION
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
106 
107 class FGMassBalance : public FGModel
108 {
109 
110 public:
112  ~FGMassBalance();
113 
114  bool Load(Element* el);
115  bool InitModel(void);
123  bool Run(bool Holding);
124 
125  double GetMass(void) const {return Mass;}
126  double GetWeight(void) const {return Weight;}
127  double GetEmptyWeight(void) const {return EmptyWeight;}
128  const FGColumnVector3& GetXYZcg(void) const {return vXYZcg;}
129  double GetXYZcg(int axis) const {return vXYZcg(axis);}
130  const FGColumnVector3& GetDeltaXYZcg(void) const {return vDeltaXYZcg;}
131  double GetDeltaXYZcg(int axis) const {return vDeltaXYZcg(axis);}
132 
141  FGMatrix33 GetPointmassInertia(double mass_sl, const FGColumnVector3& r) const
142  {
144  FGColumnVector3 sv = mass_sl*v;
145  double xx = sv(1)*v(1);
146  double yy = sv(2)*v(2);
147  double zz = sv(3)*v(3);
148  double xy = -sv(1)*v(2);
149  double xz = -sv(1)*v(3);
150  double yz = -sv(2)*v(3);
151  return FGMatrix33( yy+zz, xy, xz,
152  xy, xx+zz, yz,
153  xz, yz, xx+yy );
154  }
155 
166 
167  void SetEmptyWeight(double EW) { EmptyWeight = EW;}
168  void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
169 
170  void AddPointMass(Element* el);
171  double GetTotalPointMassWeight(void) const;
172 
173  const FGColumnVector3& GetPointMassMoment(void);
174  const FGMatrix33& GetJ(void) const {return mJ;}
175  const FGMatrix33& GetJinv(void) const {return mJinv;}
176  void SetAircraftBaseInertias(const FGMatrix33& BaseJ) {baseJ = BaseJ;}
177  void GetMassPropertiesReport(int i);
178 
179  struct Inputs {
180  double GasMass;
181  double TanksWeight;
182  FGColumnVector3 GasMoment;
183  FGMatrix33 GasInertia;
184  FGColumnVector3 TanksMoment;
185  FGMatrix33 TankInertia;
186  } in;
187 
188 private:
189  double Weight;
190  double EmptyWeight;
191  double Mass;
192  FGMatrix33 mJ;
193  FGMatrix33 mJinv;
194  FGMatrix33 pmJ;
195  FGMatrix33 baseJ;
196  FGColumnVector3 vXYZcg;
197  FGColumnVector3 vLastXYZcg;
198  FGColumnVector3 vDeltaXYZcg;
199  FGColumnVector3 vDeltaXYZcgBody;
200  FGColumnVector3 vXYZtank;
201  FGColumnVector3 vbaseXYZcg;
202  FGColumnVector3 vPMxyz;
203  FGColumnVector3 PointMassCG;
204  const FGMatrix33& CalculatePMInertias(void);
205  double GetIxx(void) const { return mJ(1,1); }
206  double GetIyy(void) const { return mJ(2,2); }
207  double GetIzz(void) const { return mJ(3,3); }
208  double GetIxy(void) const { return -mJ(1,2); }
209  double GetIxz(void) const { return -mJ(1,3); }
210  double GetIyz(void) const { return -mJ(2,3); }
211 
214  struct PointMass {
215  PointMass(double w, FGColumnVector3& vXYZ) {
216  Weight = w;
217  Location = vXYZ;
218  mPMInertia.InitMatrix();
219  Radius = 0.0;
220  Length = 0.0;
221  }
222 
223  void CalculateShapeInertia(void) {
224  switch(eShapeType) {
225  case esTube:
226  mPMInertia(1,1) = (Weight/(slugtolb))*Radius*Radius; // mr^2
227  mPMInertia(2,2) = (Weight/(slugtolb*12))*(6*Radius*Radius + Length*Length);
228  mPMInertia(3,3) = mPMInertia(2,2);
229  break;
230  case esCylinder:
231  mPMInertia(1,1) = (Weight/(slugtolb*2))*Radius*Radius; // 0.5*mr^2
232  mPMInertia(2,2) = (Weight/(slugtolb*12))*(3*Radius*Radius + Length*Length);
233  mPMInertia(3,3) = mPMInertia(2,2);
234  break;
235  case esSphere:
236  mPMInertia(1,1) = (Weight/(slugtolb*3))*Radius*Radius*2; // (2mr^2)/3
237  mPMInertia(2,2) = mPMInertia(1,1);
238  mPMInertia(3,3) = mPMInertia(1,1);
239  break;
240  case esBall:
241  mPMInertia(1,1) = (Weight/(slugtolb*5))*Radius*Radius*2; // (2mr^2)/5
242  mPMInertia(2,2) = mPMInertia(1,1);
243  mPMInertia(3,3) = mPMInertia(1,1);
244  break;
245  default:
246  break;
247  }
248  }
249 
250  enum esShape {esUnspecified, esTube, esCylinder, esSphere, esBall} eShapeType;
251  FGColumnVector3 Location;
252  double Weight;
253  double Radius;
254  double Length;
255  std::string Name;
256  FGMatrix33 mPMInertia;
257 
258  double GetPointMassLocation(int axis) const {return Location(axis);}
259  double GetPointMassWeight(void) const {return Weight;}
260  esShape GetShapeType(void) {return eShapeType;}
261  const FGColumnVector3& GetLocation(void) {return Location;}
262  const FGMatrix33& GetPointMassInertia(void) {return mPMInertia;}
263  const std::string& GetName(void) {return Name;}
264 
265  void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
266  void SetPointMassWeight(double wt) {
267  Weight = wt;
268  CalculateShapeInertia();
269  }
270  void SetPointMassShapeType(esShape st) {eShapeType = st;}
271  void SetRadius(double r) {Radius = r;}
272  void SetLength(double l) {Length = l;}
273  void SetName(const std::string& name) {Name = name;}
274  void SetPointMassMoI(const FGMatrix33& MoI) { mPMInertia = MoI; }
275  double GetPointMassMoI(int r, int c) {return mPMInertia(r,c);}
276 
277  void bind(FGPropertyManager* PropertyManager, unsigned int num);
278  };
279 
280  std::vector <struct PointMass*> PointMasses;
281 
282  void bind(void);
283  void Debug(int from);
284 };
285 }
286 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 #endif
Base class for all scheduled JSBSim models.
Definition: FGModel.h:74
FGMatrix33 GetPointmassInertia(double mass_sl, const FGColumnVector3 &r) const
Computes the inertia contribution of a pointmass.
This class implements a 3 element column vector.
Handles matrix math operations.
Definition: FGMatrix33.h:92
bool Load(Element *el)
Loads this model.
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189
Models weight, balance and moment of inertia information.
bool Run(bool Holding)
Runs the Mass Balance model; called by the Executive Can pass in a value indicating if the executive ...
FGColumnVector3 StructuralToBody(const FGColumnVector3 &r) const
Conversion from the structural frame to the body frame.