]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGMassBalance.h
Merge branch 'next' of gitorious.org:fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / 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 "FGModel.h"
42 #include "math/FGColumnVector3.h"
43 #include "math/FGMatrix33.h"
44 #include "input_output/FGXMLElement.h"
45 #include <vector>
46 #include <string>
47
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 DEFINITIONS
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52 #define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.20 2010/02/04 13:09:26 jberndt Exp $"
53
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 FORWARD DECLARATIONSS
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57
58 using std::string;
59
60 namespace JSBSim {
61
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 CLASS DOCUMENTATION
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65
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.
69
70     <h3>Configuration File Format:</h3>
71 @code
72     <mass_balance>
73         <ixx unit="{SLUG*FT2 | KG*M2}"> {number} </ixx>
74         <iyy unit="{SLUG*FT2 | KG*M2}"> {number} </iyy>
75         <izz unit="{SLUG*FT2 | KG*M2}"> {number} </izz>
76         <ixy unit="{SLUG*FT2 | KG*M2}"> {number} </ixy>
77         <ixz unit="{SLUG*FT2 | KG*M2}"> {number} </ixz>
78         <iyz unit="{SLUG*FT2 | KG*M2}"> {number} </iyz>
79         <emptywt unit="{LBS | KG"> {number} </emptywt>
80         <location name="CG" unit="{IN | M}">
81             <x> {number} </x>
82             <y> {number} </y>
83             <z> {number} </z>
84         </location>
85         <pointmass name="{string}">
86             <weight unit="{LBS | KG}"> {number} </weight>
87             <location name="POINTMASS" unit="{IN | M}">
88                 <x> {number} </x>
89                 <y> {number} </y>
90                 <z> {number} </z>
91             </location>
92         </pointmass>
93         ... other point masses ...
94     </mass_balance>
95 @endcode
96   */
97
98 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 CLASS DECLARATION
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
101
102 class FGMassBalance : public FGModel
103 {
104
105 public:
106   FGMassBalance(FGFDMExec*);
107   ~FGMassBalance();
108
109   bool Load(Element* el);
110   bool InitModel(void);
111   bool Run(void);
112
113   double GetMass(void) const {return Mass;}
114   double GetWeight(void) const {return Weight;}
115   double GetEmptyWeight(void) const {return EmptyWeight;}
116   const FGColumnVector3& GetXYZcg(void) const {return vXYZcg;}
117   double GetXYZcg(int axis) const  {return vXYZcg(axis);}
118   const FGColumnVector3& GetDeltaXYZcg(void) const {return vDeltaXYZcg;}
119   double GetDeltaXYZcg(int axis) const  {return vDeltaXYZcg(axis);}
120
121   /** Computes the inertia contribution of a pointmass.
122       Computes and returns the inertia matrix of a pointmass of mass
123       slugs at the given vector r in the structural frame. The units
124       should be for the mass in slug and the vector in the structural
125       frame as usual in inches.
126       @param slugs the mass of this single pointmass given in slugs
127       @param r the location of this single pointmass in the structural frame
128    */
129   FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
130   {
131     FGColumnVector3 v = StructuralToBody( r );
132     FGColumnVector3 sv = slugs*v;
133     double xx = sv(1)*v(1);
134     double yy = sv(2)*v(2);
135     double zz = sv(3)*v(3);
136     double xy = -sv(1)*v(2);
137     double xz = -sv(1)*v(3);
138     double yz = -sv(2)*v(3);
139     return FGMatrix33( yy+zz, xy, xz,
140                        xy, xx+zz, yz,
141                        xz, yz, xx+yy );
142   }
143
144   /** Conversion from the structural frame to the body frame.
145       Converts the location given in the structural frame
146       coordinate system to the body frame. The units of the structural
147       frame are assumed to be in inches. The unit of the result is in
148       ft.
149       @param r vector coordinate in the structural reference frame (X positive
150                aft, measurements in inches).
151       @return vector coordinate in the body frame, in feet.
152    */
153   FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
154
155   inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
156   inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
157
158   void AddPointMass(Element* el);
159   double GetTotalPointMassWeight(void);
160
161   FGColumnVector3& GetPointMassMoment(void);
162   FGMatrix33& GetJ(void) {return mJ;}
163   FGMatrix33& GetJinv(void) {return mJinv;}
164   void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
165   void GetMassPropertiesReport(void) const;
166   
167 private:
168   double Weight;
169   double EmptyWeight;
170   double Mass;
171   FGMatrix33 mJ;
172   FGMatrix33 mJinv;
173   FGMatrix33 pmJ;
174   FGMatrix33 baseJ;
175   FGColumnVector3 vXYZcg;
176   FGColumnVector3 vLastXYZcg;
177   FGColumnVector3 vDeltaXYZcg;
178   FGColumnVector3 vDeltaXYZcgBody;
179   FGColumnVector3 vXYZtank;
180   FGColumnVector3 vbaseXYZcg;
181   FGColumnVector3 vPMxyz;
182   FGColumnVector3 PointMassCG;
183   FGMatrix33& CalculatePMInertias(void);
184
185
186   /** The PointMass structure encapsulates a point mass object, moments of inertia
187      mass, location, etc. */
188   struct PointMass {
189     PointMass(double w, FGColumnVector3& vXYZ) {
190       Weight = w;
191       Location = vXYZ;
192       mPMInertia.InitMatrix();
193       Radius = 0.0;
194       Length = 0.0;
195     }
196
197     void CalculateShapeInertia(void) {
198       switch(eShapeType) {
199         case esTube:
200           mPMInertia(1,1) = (Weight/(32.16))*Radius*Radius; // mr^2
201           mPMInertia(2,2) = (Weight/(32.16*12))*(6*Radius*Radius + Length*Length);
202           mPMInertia(3,3) = mPMInertia(2,2);
203           break;
204         case esCylinder:
205           mPMInertia(1,1) = (Weight/(32.16*2))*Radius*Radius; // 0.5*mr^2
206           mPMInertia(2,2) = (Weight/(32.16*12))*(3*Radius*Radius + Length*Length);
207           mPMInertia(3,3) = mPMInertia(2,2);
208           break;
209         default:
210           break;
211       }
212     }
213
214     enum esShape {esUnspecified, esTube, esCylinder, esSphere} eShapeType;
215     FGColumnVector3 Location;
216     double Weight; /// Weight in pounds.
217     double Radius; /// Radius in feet.
218     double Length; /// Length in feet.
219     string Name;
220     FGMatrix33 mPMInertia;
221
222     double GetPointMassLocation(int axis) const {return Location(axis);}
223     double GetPointMassWeight(void) const {return Weight;}
224     esShape GetShapeType(void) {return eShapeType;}
225     FGColumnVector3 GetLocation(void) {return Location;}
226     FGMatrix33 GetPointMassInertia(void) {return mPMInertia;}
227     string GetName(void) {return Name;}
228
229     void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
230     void SetPointMassWeight(double wt) {Weight = wt;}
231     void SetPointMassShapeType(esShape st) {eShapeType = st;}
232     void SetRadius(double r) {Radius = r;}
233     void SetLength(double l) {Length = l;}
234     void SetName(string name) {Name = name;}
235     double GetPointMassMoI(int r, int c) {return mPMInertia(r,c);}
236
237     void bind(FGPropertyManager* PropertyManager, int num);
238   };
239
240   std::vector <struct PointMass*> PointMasses;
241
242   void bind(void);
243   void Debug(int from);
244 };
245 }
246 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 #endif