1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Header: FGMassBalance.h
5 Date started: 09/12/2000
7 ------------- Copyright (C) 2000 Jon S. Berndt (jsb@hal-pc.org) --------------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
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 General Public License for more
19 You should have received a copy of the GNU 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.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
27 --------------------------------------------------------------------------------
28 09/12/2000 JSB Created
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34 #ifndef FGMASSBALANCE_H
35 #define FGMASSBALANCE_H
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 #include "FGColumnVector3.h"
43 #include "FGMatrix33.h"
46 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 #define ID_MASSBALANCE "$Id$"
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 /** Models weight and balance information.
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 class FGMassBalance : public FGModel
73 FGMassBalance(FGFDMExec*);
78 inline double GetMass(void) const {return Mass;}
79 inline double GetWeight(void) const {return Weight;}
80 inline double GetEmptyWeight(void) const {return EmptyWeight;}
81 inline FGColumnVector3& GetXYZcg(void) {return vXYZcg;}
82 inline double GetXYZcg(int axis) const {return vXYZcg(axis);}
83 inline double GetbaseXYZcg(int axis) const {return vbaseXYZcg(axis);}
85 /** Computes the inertia contribution of a pointmass.
86 Computes and returns the inertia matrix of a pointmass of mass
87 slugs at the given vector r in the structural frame. The units
88 should be for the mass in slug and the vector in the structural
89 frame as usual in inches.
90 @param slugs the mass of this single pointmass given in slugs
91 @param r the location of this single pointmass in the structural frame
93 FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
95 FGColumnVector3 v = StructuralToBody( r );
96 FGColumnVector3 sv = slugs*v;
97 double xx = sv(1)*v(1);
98 double yy = sv(2)*v(2);
99 double zz = sv(3)*v(3);
100 double xy = -sv(1)*v(2);
101 double xz = -sv(1)*v(3);
102 double yz = -sv(2)*v(3);
103 return FGMatrix33( yy+zz, xy, xz,
108 /** Conversion from the structural frame to the body frame.
109 Converts the location given in the structural frame
110 coordinate system to the body frame. The units of the structural
111 frame are assumed to be in inches. The unit of the result is in
113 @param r vector coordinate in the structural reference frame (X positive
114 aft, measurements in inches).
115 @return vector coordinate in the body frame, in feet.
117 FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
119 inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
120 inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
122 void AddPointMass(double weight, double X, double Y, double Z);
123 double GetPointMassWeight(void);
124 FGColumnVector3& GetPointMassMoment(void);
125 FGMatrix33& GetJ(void) {return mJ;}
126 FGMatrix33& GetJinv(void) {return mJinv;}
127 void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
128 FGMatrix33& GetAircraftBaseInertias(void) {return baseJ;}
129 int GetNumPointMasses(void) {return PointMassLoc.size();}
130 FGColumnVector3& GetPointMassLoc(int i) {return PointMassLoc[i];}
131 double GetPointMassWeight(int i) {return PointMassWeight[i];}
144 FGColumnVector3 vXYZcg;
145 FGColumnVector3 vXYZtank;
146 FGColumnVector3 vbaseXYZcg;
147 FGColumnVector3 vPMxyz;
148 vector <FGColumnVector3> PointMassLoc;
149 vector <double> PointMassWeight;
150 FGColumnVector3 PointMassCG;
151 FGMatrix33& CalculatePMInertias(void);
153 void Debug(int from);
156 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%