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"
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 #define ID_MASSBALANCE "$Id$"
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 /** Models weight, balance and moment of inertia information. Maintains a vector
64 of point masses. Sums the contribution of all, and provides this to FGPropagate.
65 Loads the \<mass_balance> section of the aircraft configuration file.
67 <h3>Configuration File Format:</h3>
70 <ixx unit="{SLUG*FT2 | KG*M2}"> {number} </ixx>
71 <iyy unit="{SLUG*FT2 | KG*M2}"> {number} </iyy>
72 <izz unit="{SLUG*FT2 | KG*M2}"> {number} </izz>
73 <ixy unit="{SLUG*FT2 | KG*M2}"> {number} </ixy>
74 <ixz unit="{SLUG*FT2 | KG*M2}"> {number} </ixz>
75 <iyz unit="{SLUG*FT2 | KG*M2}"> {number} </iyz>
76 <emptywt unit="{LBS | KG"> {number} </emptywt>
77 <location name="CG" unit="{IN | M}">
82 <pointmass name="{string}">
83 <weight unit="{LBS | KG}"> {number} </weight>
84 <location name="POINTMASS" unit="{IN | M}">
90 ... other point masses ...
95 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
99 class FGMassBalance : public FGModel
103 FGMassBalance(FGFDMExec*);
106 bool Load(Element* el);
107 bool InitModel(void);
110 double GetMass(void) const {return Mass;}
111 double GetWeight(void) const {return Weight;}
112 FGColumnVector3& GetXYZcg(void) {return vXYZcg;}
113 double GetXYZcg(int axis) const {return vXYZcg(axis);}
114 FGColumnVector3& GetDeltaXYZcg(void) {return vDeltaXYZcg;}
115 double GetDeltaXYZcg(int axis) const {return vDeltaXYZcg(axis);}
117 /** Computes the inertia contribution of a pointmass.
118 Computes and returns the inertia matrix of a pointmass of mass
119 slugs at the given vector r in the structural frame. The units
120 should be for the mass in slug and the vector in the structural
121 frame as usual in inches.
122 @param slugs the mass of this single pointmass given in slugs
123 @param r the location of this single pointmass in the structural frame
125 FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
127 FGColumnVector3 v = StructuralToBody( r );
128 FGColumnVector3 sv = slugs*v;
129 double xx = sv(1)*v(1);
130 double yy = sv(2)*v(2);
131 double zz = sv(3)*v(3);
132 double xy = -sv(1)*v(2);
133 double xz = -sv(1)*v(3);
134 double yz = -sv(2)*v(3);
135 return FGMatrix33( yy+zz, xy, xz,
140 /** Conversion from the structural frame to the body frame.
141 Converts the location given in the structural frame
142 coordinate system to the body frame. The units of the structural
143 frame are assumed to be in inches. The unit of the result is in
145 @param r vector coordinate in the structural reference frame (X positive
146 aft, measurements in inches).
147 @return vector coordinate in the body frame, in feet.
149 FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
151 inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
152 inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
154 void AddPointMass(Element* el);
155 double GetTotalPointMassWeight(void);
157 FGColumnVector3& GetPointMassMoment(void);
158 FGMatrix33& GetJ(void) {return mJ;}
159 FGMatrix33& GetJinv(void) {return mJinv;}
160 void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
170 FGColumnVector3 vXYZcg;
171 FGColumnVector3 vLastXYZcg;
172 FGColumnVector3 vDeltaXYZcg;
173 FGColumnVector3 vDeltaXYZcgBody;
174 FGColumnVector3 vXYZtank;
175 FGColumnVector3 vbaseXYZcg;
176 FGColumnVector3 vPMxyz;
177 FGColumnVector3 PointMassCG;
178 FGMatrix33& CalculatePMInertias(void);
181 PointMass(double w, FGColumnVector3& vXYZ) {
185 FGColumnVector3 Location;
187 double GetPointMassLocation(int axis) const {return Location(axis);}
188 void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
189 void SetPointMassWeight(double wt) {Weight = wt;}
190 double GetPointMassWeight(void) const {return Weight;}
192 void bind(FGPropertyManager* PropertyManager, int num);
195 std::vector <struct PointMass*> PointMasses;
198 void Debug(int from);
201 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%