]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGMassBalance.h
sync. with JSBSim v. 2.0
[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 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 General Public License for more
17  details.
18
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.
22
23  Further information about the GNU 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 and balance information.
64   */
65
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 CLASS DECLARATION
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69
70 class FGMassBalance : public FGModel
71 {
72
73 public:
74   FGMassBalance(FGFDMExec*);
75   ~FGMassBalance();
76
77   bool Load(Element* el);
78
79   bool Run(void);
80
81   inline double GetMass(void) const {return Mass;}
82   inline double GetWeight(void) const {return Weight;}
83   inline FGColumnVector3& GetXYZcg(void) {return vXYZcg;}
84   inline double GetXYZcg(int axis) const  {return vXYZcg(axis);}
85
86   /** Computes the inertia contribution of a pointmass.
87       Computes and returns the inertia matrix of a pointmass of mass
88       slugs at the given vector r in the structural frame. The units
89       should be for the mass in slug and the vector in the structural
90       frame as usual in inches.
91       @param slugs the mass of this single pointmass given in slugs
92       @param r the location of this single pointmass in the structural frame
93    */
94   FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
95   {
96     FGColumnVector3 v = StructuralToBody( r );
97     FGColumnVector3 sv = slugs*v;
98     double xx = sv(1)*v(1);
99     double yy = sv(2)*v(2);
100     double zz = sv(3)*v(3);
101     double xy = -sv(1)*v(2);
102     double xz = -sv(1)*v(3);
103     double yz = -sv(2)*v(3);
104     return FGMatrix33( yy+zz, xy, xz,
105                        xy, xx+zz, yz,
106                        xz, yz, xx+yy );
107   }
108
109   /** Conversion from the structural frame to the body frame.
110       Converts the location given in the structural frame
111       coordinate system to the body frame. The units of the structural
112       frame are assumed to be in inches. The unit of the result is in
113       ft.
114       @param r vector coordinate in the structural reference frame (X positive
115                aft, measurements in inches).
116       @return vector coordinate in the body frame, in feet.
117    */
118   FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
119
120   inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
121   inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
122
123   void AddPointMass(Element* el);
124   double GetPointMassWeight(void);
125   FGColumnVector3& GetPointMassMoment(void);
126   FGMatrix33& GetJ(void) {return mJ;}
127   FGMatrix33& GetJinv(void) {return mJinv;}
128   void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
129
130   void bind(void);
131   void unbind(void);
132
133 private:
134   double Weight;
135   double EmptyWeight;
136   double Mass;
137   FGMatrix33 mJ;
138   FGMatrix33 mJinv;
139   FGMatrix33 pmJ;
140   FGMatrix33 baseJ;
141   FGColumnVector3 vXYZcg;
142   FGColumnVector3 vXYZtank;
143   FGColumnVector3 vbaseXYZcg;
144   FGColumnVector3 vPMxyz;
145   FGColumnVector3 PointMassCG;
146   FGMatrix33& CalculatePMInertias(void);
147
148   struct PointMass {
149     PointMass(double w, double x, double y, double z) {
150       Weight = w;
151       Location.InitMatrix(x, y, z);
152     }
153     FGColumnVector3 Location;
154     double Weight;
155   };
156
157   vector <struct PointMass> PointMasses;
158
159   void Debug(int from);
160 };
161 }
162 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 #endif