]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGMassBalance.h
merging in topic/makej
[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 (jsb@hal-pc.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
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 DEFINITIONS
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50
51 #define ID_MASSBALANCE "$Id$"
52
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 FORWARD DECLARATIONSS
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
57 namespace JSBSim {
58
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 CLASS DOCUMENTATION
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62
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.
66
67     <h3>Configuration File Format:</h3>
68 @code
69     <mass_balance>
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}">
78             <x> {number} </x>
79             <y> {number} </y>
80             <z> {number} </z>
81         </location>
82         <pointmass name="{string}">
83             <weight unit="{LBS | KG}"> {number} </weight>
84             <location name="POINTMASS" unit="{IN | M}">
85                 <x> {number} </x>
86                 <y> {number} </y>
87                 <z> {number} </z>
88             </location>
89         </pointmass>
90         ... other point masses ...
91     </mass_balance>
92 @endcode
93   */
94
95 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 CLASS DECLARATION
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
98
99 class FGMassBalance : public FGModel
100 {
101
102 public:
103   FGMassBalance(FGFDMExec*);
104   ~FGMassBalance();
105
106   bool Load(Element* el);
107   bool InitModel(void);
108   bool Run(void);
109
110   inline double GetMass(void) const {return Mass;}
111   inline double GetWeight(void) const {return Weight;}
112   inline FGColumnVector3& GetXYZcg(void) {return vXYZcg;}
113   inline double GetXYZcg(int axis) const  {return vXYZcg(axis);}
114
115   /** Computes the inertia contribution of a pointmass.
116       Computes and returns the inertia matrix of a pointmass of mass
117       slugs at the given vector r in the structural frame. The units
118       should be for the mass in slug and the vector in the structural
119       frame as usual in inches.
120       @param slugs the mass of this single pointmass given in slugs
121       @param r the location of this single pointmass in the structural frame
122    */
123   FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
124   {
125     FGColumnVector3 v = StructuralToBody( r );
126     FGColumnVector3 sv = slugs*v;
127     double xx = sv(1)*v(1);
128     double yy = sv(2)*v(2);
129     double zz = sv(3)*v(3);
130     double xy = -sv(1)*v(2);
131     double xz = -sv(1)*v(3);
132     double yz = -sv(2)*v(3);
133     return FGMatrix33( yy+zz, xy, xz,
134                        xy, xx+zz, yz,
135                        xz, yz, xx+yy );
136   }
137
138   /** Conversion from the structural frame to the body frame.
139       Converts the location given in the structural frame
140       coordinate system to the body frame. The units of the structural
141       frame are assumed to be in inches. The unit of the result is in
142       ft.
143       @param r vector coordinate in the structural reference frame (X positive
144                aft, measurements in inches).
145       @return vector coordinate in the body frame, in feet.
146    */
147   FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
148
149   inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
150   inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
151
152   void AddPointMass(Element* el);
153   double GetTotalPointMassWeight(void);
154
155   FGColumnVector3& GetPointMassMoment(void);
156   FGMatrix33& GetJ(void) {return mJ;}
157   FGMatrix33& GetJinv(void) {return mJinv;}
158   void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
159   
160 private:
161   double Weight;
162   double EmptyWeight;
163   double Mass;
164   FGMatrix33 mJ;
165   FGMatrix33 mJinv;
166   FGMatrix33 pmJ;
167   FGMatrix33 baseJ;
168   FGColumnVector3 vXYZcg;
169   FGColumnVector3 vXYZtank;
170   FGColumnVector3 vbaseXYZcg;
171   FGColumnVector3 vPMxyz;
172   FGColumnVector3 PointMassCG;
173   FGMatrix33& CalculatePMInertias(void);
174
175   struct PointMass {
176     PointMass(double w, FGColumnVector3& vXYZ) {
177       Weight = w;
178       Location = vXYZ;
179     }
180     FGColumnVector3 Location;
181     double Weight;
182     double GetPointMassLocation(int axis) const {return Location(axis);}
183     void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
184     void SetPointMassWeight(double wt) {Weight = wt;}
185     double GetPointMassWeight(void) const {return Weight;}
186
187     void bind(FGPropertyManager* PropertyManager, int num) {
188       string tmp = CreateIndexedPropertyName("inertia/pointmass-weight-lbs", num);
189       PropertyManager->Tie( tmp.c_str(), this, &PointMass::GetPointMassWeight,
190                                        &PointMass::SetPointMassWeight);
191
192       tmp = CreateIndexedPropertyName("inertia/pointmass-location-X-inches", num);
193       PropertyManager->Tie( tmp.c_str(), this, eX, &PointMass::GetPointMassLocation,
194                                            &PointMass::SetPointMassLocation);
195       tmp = CreateIndexedPropertyName("inertia/pointmass-location-Y-inches", num);
196       PropertyManager->Tie( tmp.c_str(), this, eY, &PointMass::GetPointMassLocation,
197                                            &PointMass::SetPointMassLocation);
198       tmp = CreateIndexedPropertyName("inertia/pointmass-location-Z-inches", num);
199       PropertyManager->Tie( tmp.c_str(), this, eZ, &PointMass::GetPointMassLocation,
200                                            &PointMass::SetPointMassLocation);
201     }
202   };
203
204   vector <struct PointMass*> PointMasses;
205
206   void bind(void);
207   void Debug(int from);
208 };
209 }
210 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 #endif