1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Header: FGMassBalance.h
5 Date started: 09/12/2000
7 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) --------------
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
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
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.
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.
27 --------------------------------------------------------------------------------
28 09/12/2000 JSB Created
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34 #ifndef FGMASSBALANCE_H
35 #define FGMASSBALANCE_H
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 #include "math/FGColumnVector3.h"
43 #include "math/FGMatrix33.h"
44 #include "input_output/FGXMLElement.h"
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 #define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.21 2010/08/12 04:07:11 jberndt Exp $"
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 /** Models weight, balance and moment of inertia information. Maintains a vector
67 of point masses. Sums the contribution of all, and provides this to FGPropagate.
68 Loads the \<mass_balance> section of the aircraft configuration file. There
69 can be any number of <pointmasses>. Each can also have a shape which - if
70 present - causes an associated moment of inertia to be calculated based on
71 the shape. Note that a cylinder is solid, a tube is hollow, a ball is solid
72 and a sphere is hollow.
74 <h3>Configuration File Format:</h3>
77 <ixx unit="{SLUG*FT2 | KG*M2}"> {number} </ixx>
78 <iyy unit="{SLUG*FT2 | KG*M2}"> {number} </iyy>
79 <izz unit="{SLUG*FT2 | KG*M2}"> {number} </izz>
80 <ixy unit="{SLUG*FT2 | KG*M2}"> {number} </ixy>
81 <ixz unit="{SLUG*FT2 | KG*M2}"> {number} </ixz>
82 <iyz unit="{SLUG*FT2 | KG*M2}"> {number} </iyz>
83 <emptywt unit="{LBS | KG"> {number} </emptywt>
84 <location name="CG" unit="{IN | FT | M}">
89 [<pointmass name="{string}">
90 <form shape="{tube | cylinder | sphere | ball}">
91 <radius unit="{IN | FT | M}"> {number} </radius>
92 <length unit="{IN | FT | M}"> {number} </length>
94 <weight unit="{LBS | KG}"> {number} </weight>
95 <location name="{string}" unit="{IN | FT | M}">
101 ... other point masses ...]
106 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
110 class FGMassBalance : public FGModel
114 FGMassBalance(FGFDMExec*);
117 bool Load(Element* el);
118 bool InitModel(void);
121 double GetMass(void) const {return Mass;}
122 double GetWeight(void) const {return Weight;}
123 double GetEmptyWeight(void) const {return EmptyWeight;}
124 const FGColumnVector3& GetXYZcg(void) const {return vXYZcg;}
125 double GetXYZcg(int axis) const {return vXYZcg(axis);}
126 const FGColumnVector3& GetDeltaXYZcg(void) const {return vDeltaXYZcg;}
127 double GetDeltaXYZcg(int axis) const {return vDeltaXYZcg(axis);}
129 /** Computes the inertia contribution of a pointmass.
130 Computes and returns the inertia matrix of a pointmass of mass
131 slugs at the given vector r in the structural frame. The units
132 should be for the mass in slug and the vector in the structural
133 frame as usual in inches.
134 @param slugs the mass of this single pointmass given in slugs
135 @param r the location of this single pointmass in the structural frame
137 FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
139 FGColumnVector3 v = StructuralToBody( r );
140 FGColumnVector3 sv = slugs*v;
141 double xx = sv(1)*v(1);
142 double yy = sv(2)*v(2);
143 double zz = sv(3)*v(3);
144 double xy = -sv(1)*v(2);
145 double xz = -sv(1)*v(3);
146 double yz = -sv(2)*v(3);
147 return FGMatrix33( yy+zz, xy, xz,
152 /** Conversion from the structural frame to the body frame.
153 Converts the location given in the structural frame
154 coordinate system to the body frame. The units of the structural
155 frame are assumed to be in inches. The unit of the result is in
157 @param r vector coordinate in the structural reference frame (X positive
158 aft, measurements in inches).
159 @return vector coordinate in the body frame, in feet.
161 FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
163 inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
164 inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
166 void AddPointMass(Element* el);
167 double GetTotalPointMassWeight(void);
169 FGColumnVector3& GetPointMassMoment(void);
170 FGMatrix33& GetJ(void) {return mJ;}
171 FGMatrix33& GetJinv(void) {return mJinv;}
172 void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
173 void GetMassPropertiesReport(void) const;
183 FGColumnVector3 vXYZcg;
184 FGColumnVector3 vLastXYZcg;
185 FGColumnVector3 vDeltaXYZcg;
186 FGColumnVector3 vDeltaXYZcgBody;
187 FGColumnVector3 vXYZtank;
188 FGColumnVector3 vbaseXYZcg;
189 FGColumnVector3 vPMxyz;
190 FGColumnVector3 PointMassCG;
191 FGMatrix33& CalculatePMInertias(void);
194 /** The PointMass structure encapsulates a point mass object, moments of inertia
195 mass, location, etc. */
197 PointMass(double w, FGColumnVector3& vXYZ) {
200 mPMInertia.InitMatrix();
205 void CalculateShapeInertia(void) {
208 mPMInertia(1,1) = (Weight/(slugtolb))*Radius*Radius; // mr^2
209 mPMInertia(2,2) = (Weight/(slugtolb*12))*(6*Radius*Radius + Length*Length);
210 mPMInertia(3,3) = mPMInertia(2,2);
213 mPMInertia(1,1) = (Weight/(slugtolb*2))*Radius*Radius; // 0.5*mr^2
214 mPMInertia(2,2) = (Weight/(slugtolb*12))*(3*Radius*Radius + Length*Length);
215 mPMInertia(3,3) = mPMInertia(2,2);
218 mPMInertia(1,1) = (Weight/(slugtolb*3))*Radius*Radius*2; // (2mr^2)/3
219 mPMInertia(2,2) = mPMInertia(1,1);
220 mPMInertia(3,3) = mPMInertia(1,1);
222 mPMInertia(1,1) = (Weight/(slugtolb*5))*Radius*Radius*2; // (2mr^2)/5
223 mPMInertia(2,2) = mPMInertia(1,1);
224 mPMInertia(3,3) = mPMInertia(1,1);
231 enum esShape {esUnspecified, esTube, esCylinder, esSphere, esBall} eShapeType;
232 FGColumnVector3 Location;
233 double Weight; /// Weight in pounds.
234 double Radius; /// Radius in feet.
235 double Length; /// Length in feet.
237 FGMatrix33 mPMInertia;
239 double GetPointMassLocation(int axis) const {return Location(axis);}
240 double GetPointMassWeight(void) const {return Weight;}
241 esShape GetShapeType(void) {return eShapeType;}
242 FGColumnVector3 GetLocation(void) {return Location;}
243 FGMatrix33 GetPointMassInertia(void) {return mPMInertia;}
244 string GetName(void) {return Name;}
246 void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
247 void SetPointMassWeight(double wt) {Weight = wt;}
248 void SetPointMassShapeType(esShape st) {eShapeType = st;}
249 void SetRadius(double r) {Radius = r;}
250 void SetLength(double l) {Length = l;}
251 void SetName(string name) {Name = name;}
252 double GetPointMassMoI(int r, int c) {return mPMInertia(r,c);}
254 void bind(FGPropertyManager* PropertyManager, int num);
257 std::vector <struct PointMass*> PointMasses;
260 void Debug(int from);
263 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%