]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGPhysicalProperty.h
Additional changes including updates to JSBSim to try to get interface and
[flightgear.git] / src / WeatherCM / FGPhysicalProperty.h
1 /*****************************************************************************
2
3  Header:       FGPhysicalProperty.h     
4  Author:       Christian Mayer
5  Date started: 28.05.99
6
7  -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
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 FUNCTIONAL DESCRIPTION
27 ------------------------------------------------------------------------------
28 Define the simulated physical property of the weather in one point
29
30 HISTORY
31 ------------------------------------------------------------------------------
32 28.05.1999 Christian Mayer      Created
33 16.06.1999 Durk Talsma          Portability for Linux
34 20.06.1999 Christian Mayer      Changed struct to class
35 20.06.1999 Christian Mayer      added lots of consts
36 30.06.1999 Christian Mayer      STL portability
37 11.10.1999 Christian Mayer      changed set<> to map<> on Bernie Bright's 
38                                 suggestion
39 19.10.1999 Christian Mayer      change to use PLIB's sg instead of Point[2/3]D
40                                 and lots of wee code cleaning
41 *****************************************************************************/
42
43 /****************************************************************************/
44 /* SENTRY                                                                   */
45 /****************************************************************************/
46 #ifndef FGPhysicalProperty_H
47 #define FGPhysicalProperty_H
48
49 /****************************************************************************/
50 /* INCLUDES                                                                 */
51 /****************************************************************************/
52
53 #ifdef HAVE_CONFIG_H
54 #  include <config.h>
55 #endif
56
57 #include <simgear/compiler.h>
58
59 #ifdef HAVE_WINDOWS_H
60 #  include <windows.h>
61 #endif
62
63 #include <vector>
64
65 #include <plib/sg.h>
66
67 #include "FGWeatherDefs.h"
68 #include "FGPhysicalProperties.h"
69
70 SG_USING_STD(vector);
71 SG_USING_NAMESPACE(std);
72
73 /****************************************************************************/
74 /* used for output:                                                         */
75 /****************************************************************************/
76 class FGPhysicalProperty;
77 bool operator == (const FGPhysicalProperty& a, const FGPhysicalProperty& b);  // p1 == p2?
78
79 class FGPhysicalProperty
80 {
81 private:
82 protected:
83 public:
84     sgVec3           Wind;              //Wind vector
85     sgVec3           Turbulence;        //Turbulence vector
86     WeatherPrecision Temperature;       //in deg. Kelvin (I *only* accept SI!)
87     WeatherPrecision AirPressure;       //in Pascal (I *only* accept SI!)
88     WeatherPrecision VaporPressure;     //in Pascal (I *only* accept SI!)
89
90     FGPhysicalProperty();   //consructor to fill it with FG standart weather
91     FGPhysicalProperty(const FGPhysicalProperties& p, const WeatherPrecision altitude);
92
93     //allow calculations for easier handling such as interpolating
94     FGPhysicalProperty& operator =  ( const FGPhysicalProperty& p );    // assignment of a FGPhysicalProperty
95     FGPhysicalProperty& operator += ( const FGPhysicalProperty& p );    // incrementation by a FGPhysicalProperty
96     FGPhysicalProperty& operator -= ( const FGPhysicalProperty& p );    // decrementation by a FGPhysicalProperty
97     FGPhysicalProperty& operator *= ( const double d );                 // multiplication by a constant
98     FGPhysicalProperty& operator /= ( const double d );                 // division by a constant
99
100     friend FGPhysicalProperty operator - (const FGPhysicalProperty& p);                 // -p1
101     friend bool operator == (const FGPhysicalProperty& a, const FGPhysicalProperty& b); // p1 == p2?
102 };
103
104 class FGPhysicalProperty3D : public FGPhysicalProperty
105 {
106 private:
107 protected:
108 public:
109     sgVec3 p;       //position of the property (lat/lon/alt)
110 };
111
112 typedef vector<FGPhysicalProperty>               FGPhysicalPropertyVector;
113 typedef FGPhysicalPropertyVector::iterator       FGPhysicalPropertyVectorIt;
114 typedef FGPhysicalPropertyVector::const_iterator FGPhysicalPropertyVectorConstIt;
115
116 typedef vector<FGPhysicalProperty3D>               FGPhysicalProperty3DVector;
117 typedef FGPhysicalProperty3DVector::iterator       FGPhysicalProperty3DVectorIt;
118 typedef FGPhysicalProperty3DVector::const_iterator FGPhysicalProperty3DVectorConstIt;
119
120 inline FGPhysicalProperty& FGPhysicalProperty::operator = ( const FGPhysicalProperty& p )
121 {
122     sgCopyVec3(Wind, p.Wind); 
123     sgCopyVec3(Turbulence, p.Turbulence); 
124     Temperature = p.Temperature; 
125     AirPressure = p.AirPressure; 
126     VaporPressure = p.VaporPressure; 
127     return *this;
128 }
129
130 inline FGPhysicalProperty& FGPhysicalProperty::operator += ( const FGPhysicalProperty& p )
131 {
132     sgAddVec3(Wind, p.Wind); 
133     sgAddVec3(Turbulence, p.Turbulence); 
134     Temperature += p.Temperature; 
135     AirPressure += p.AirPressure; 
136     VaporPressure += p.VaporPressure; 
137     return *this;
138 }
139
140 inline FGPhysicalProperty& FGPhysicalProperty::operator -= ( const FGPhysicalProperty& p )
141 {
142     sgSubVec3(Wind, p.Wind); 
143     sgSubVec3(Turbulence, p.Turbulence); 
144     Temperature -= p.Temperature; 
145     AirPressure -= p.AirPressure; 
146     VaporPressure -= p.VaporPressure; 
147     return *this;
148 }
149
150 inline FGPhysicalProperty& FGPhysicalProperty::operator *= ( const double d )
151 {
152     sgScaleVec3(Wind, d); 
153     sgScaleVec3(Turbulence, d); 
154     Temperature *= d; 
155     AirPressure *= d; 
156     VaporPressure *= d; 
157     return *this;
158 }
159
160 inline FGPhysicalProperty& FGPhysicalProperty::operator /= ( const double d )
161 {
162     sgScaleVec3(Wind, 1.0 / d); 
163     sgScaleVec3(Turbulence, 1.0 / d); 
164     Temperature /= d; 
165     AirPressure /= d; 
166     VaporPressure /= d; 
167     return *this;
168 }
169
170 inline  FGPhysicalProperty operator - (const FGPhysicalProperty& p)
171 {
172     FGPhysicalProperty x;
173     sgNegateVec3(x.Wind, p.Wind); 
174     sgNegateVec3(x.Turbulence, p.Turbulence); 
175     x.Temperature = -p.Temperature; 
176     x.AirPressure = -p.AirPressure; 
177     x.VaporPressure = -p.VaporPressure; 
178     return x;
179 }
180
181 inline bool operator == (const FGPhysicalProperty& a, const FGPhysicalProperty& b)
182 {
183     return (
184     sgEqualVec3(a.Wind, b.Wind) &&
185     sgEqualVec3(a.Turbulence, b.Turbulence) && 
186     (a.Temperature == b.Temperature) && 
187     (a.AirPressure == b.AirPressure) && 
188     (a.VaporPressure == b.VaporPressure)); 
189 }
190
191 inline bool operator != (const FGPhysicalProperty& a, const FGPhysicalProperty& b)
192 {
193     return !(a == b);
194 }
195
196 inline FGPhysicalProperty operator + (const FGPhysicalProperty& a, const FGPhysicalProperty& b)
197 {
198     return FGPhysicalProperty(a) += b;
199 }
200
201 inline FGPhysicalProperty operator - (const FGPhysicalProperty& a, const FGPhysicalProperty& b)
202 {
203     return FGPhysicalProperty(a) -= b;
204 }
205
206 inline FGPhysicalProperty operator * (const FGPhysicalProperty& a, const WeatherPrecision b)
207 {
208     return FGPhysicalProperty(a) *= b;
209 }
210
211 inline FGPhysicalProperty operator * (const WeatherPrecision b, const FGPhysicalProperty& a)
212 {
213     return FGPhysicalProperty(a) *= b;
214 }
215
216 inline FGPhysicalProperty operator / (const FGPhysicalProperty& a, const WeatherPrecision b)
217 {
218     return FGPhysicalProperty(a) *= (1.0/b);
219 }
220
221 /****************************************************************************/
222 #endif /*FGPhysicalProperty_H*/