1 /*******-*- Mode: C++ -*-************************************************************
3 Header: FGPhysicalProperties.h
4 Author: Christian Mayer
7 ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ----------
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
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
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.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
26 FUNCTIONAL DESCRIPTION
27 ------------------------------------------------------------------------------
28 Define the simulated physical properties of the weather
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
39 *****************************************************************************/
41 /****************************************************************************/
43 /****************************************************************************/
44 #ifndef FGPhysicalProperties_H
45 #define FGPhysicalProperties_H
47 /****************************************************************************/
49 /****************************************************************************/
50 #include <Include/compiler.h>
56 FG_USING_NAMESPACE(std);
58 #include <Math/point3d.hxx>
59 #include <Voronoi/point2d.h>
60 #include "FGWeatherDefs.h"
62 #include "FGAirPressureItem.h"
64 #include "FGCloudItem.h"
65 #include "FGSnowRain.h"
67 class FGPhysicalProperties
70 typedef WeatherPrecition Altitude;
72 map<Altitude,Point3D> Wind; //all Wind vectors
73 map<Altitude,Point3D> Turbulence; //all Turbulence vectors
74 map<Altitude,WeatherPrecition> Temperature; //in deg. Kelvin (I *only* accept SI!)
75 FGAirPressureItem AirPressure; //in Pascal (I *only* accept SI!)
76 map<Altitude,WeatherPrecition> VaporPressure; //in Pascal (I *only* accept SI!)
78 map<Altitude,FGCloudItem> Clouds; //amount of covering and type
80 WeatherPrecition SnowRainIntensity; //this also stands for hail, snow,...
81 SnowRainType snowRainType;
82 WeatherPrecition LightningProbability;
84 FGPhysicalProperties(); //consructor to fill it with FG standart weather
86 //return values at specified altitudes
87 Point3D WindAt(const WeatherPrecition& a) const;
88 Point3D TurbulenceAt(const WeatherPrecition& a) const;
89 WeatherPrecition TemperatureAt(const WeatherPrecition& a) const;
90 WeatherPrecition AirPressureAt(const WeatherPrecition& a) const;
91 WeatherPrecition VaporPressureAt(const WeatherPrecition& a) const;
93 //for easier access to the cloud stuff:
94 unsigned int getNumberOfCloudLayers(void) const;
95 FGCloudItem getCloudLayer(unsigned int nr) const;
97 FGPhysicalProperties& operator = ( const FGPhysicalProperties& p );
98 FGPhysicalProperties& operator *= ( const WeatherPrecition& d );
99 FGPhysicalProperties& operator += ( const FGPhysicalProperties& p);
100 FGPhysicalProperties& operator -= ( const FGPhysicalProperties& p);
103 typedef vector<FGPhysicalProperties> FGPhysicalPropertiesVector;
104 typedef FGPhysicalPropertiesVector::iterator FGPhysicalPropertiesVectorIt;
105 typedef FGPhysicalPropertiesVector::const_iterator FGPhysicalPropertiesVectorConstIt;
107 class FGPhysicalProperties2D;
108 ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p );
110 class FGPhysicalProperties2D : public FGPhysicalProperties
113 Point2D p; //position of the property (lat/lon)
114 friend ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p );
116 FGPhysicalProperties2D() {}
118 FGPhysicalProperties2D(const FGPhysicalProperties& prop, const Point2D& pos)
120 Wind = prop.Wind; Turbulence = prop.Turbulence; Temperature = prop.Temperature;
121 AirPressure = prop.AirPressure; VaporPressure = prop.VaporPressure; p = pos;
125 typedef vector<FGPhysicalProperties2D> FGPhysicalProperties2DVector;
126 typedef FGPhysicalProperties2DVector::iterator FGPhysicalProperties2DVectorIt;
127 typedef FGPhysicalProperties2DVector::const_iterator FGPhysicalProperties2DVectorConstIt;
129 inline ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p )
131 typedef map<FGPhysicalProperties::Altitude, Point3D >::const_iterator vector_iterator;
132 typedef map<FGPhysicalProperties::Altitude, WeatherPrecition>::const_iterator scalar_iterator;
134 out << "Position: " << p.p << endl;
136 out << "Stored Wind: ";
137 for (vector_iterator WindIt = p.Wind.begin();
138 WindIt != p.Wind.end();
140 out << "(" << WindIt->first << ") at " << WindIt->second << "m; ";
143 out << "Stored Turbulence: ";
144 for (vector_iterator TurbulenceIt = p.Turbulence.begin();
145 TurbulenceIt != p.Turbulence.end();
147 out << "(" << TurbulenceIt->first << ") at " << TurbulenceIt->second << "m; ";
150 out << "Stored Temperature: ";
151 for (scalar_iterator TemperatureIt = p.Temperature.begin();
152 TemperatureIt != p.Temperature.end();
154 out << TemperatureIt->first << " at " << TemperatureIt->second << "m; ";
157 out << "Stored AirPressure: ";
158 out << p.AirPressure.getValue(0) << " at " << 0.0 << "m; ";
161 out << "Stored VaporPressure: ";
162 for (scalar_iterator VaporPressureIt = p.VaporPressure.begin();
163 VaporPressureIt != p.VaporPressure.end();
165 out << VaporPressureIt->first << " at " << VaporPressureIt->second << "m; ";
172 inline FGPhysicalProperties& FGPhysicalProperties::operator = ( const FGPhysicalProperties& p )
175 Turbulence = p.Turbulence;
176 Temperature = p.Temperature;
177 AirPressure = p.AirPressure;
178 VaporPressure = p.VaporPressure;
182 inline FGPhysicalProperties& FGPhysicalProperties::operator *= ( const WeatherPrecition& d )
184 typedef map<FGPhysicalProperties::Altitude, Point3D >::iterator vector_iterator;
185 typedef map<FGPhysicalProperties::Altitude, WeatherPrecition>::iterator scalar_iterator;
187 for (vector_iterator WindIt = Wind.begin();
188 WindIt != Wind.end();
192 for (vector_iterator TurbulenceIt = Turbulence.begin();
193 TurbulenceIt != Turbulence.end();
195 TurbulenceIt->second *= d;
197 for (scalar_iterator TemperatureIt = Temperature.begin();
198 TemperatureIt != Temperature.end();
200 TemperatureIt->second *= d;
204 for (scalar_iterator VaporPressureIt = VaporPressure.begin();
205 VaporPressureIt != VaporPressure.end();
207 VaporPressureIt->second *= d;
212 inline FGPhysicalProperties& FGPhysicalProperties::operator += (const FGPhysicalProperties& p)
214 typedef map<FGPhysicalProperties::Altitude, Point3D >::const_iterator vector_iterator;
215 typedef map<FGPhysicalProperties::Altitude, WeatherPrecition>::const_iterator scalar_iterator;
217 for (vector_iterator WindIt = p.Wind.begin();
218 WindIt != p.Wind.end();
220 if (!Wind.insert(*WindIt).second) //when it's not inserted => it's already existing
221 Wind[WindIt->first] += WindIt->second; //=> add the value
223 for (vector_iterator TurbulenceIt = p.Turbulence.begin();
224 TurbulenceIt != p.Turbulence.end();
226 if (!Turbulence.insert(*TurbulenceIt).second)
227 Turbulence[TurbulenceIt->first] += TurbulenceIt->second;
229 for (scalar_iterator TemperatureIt = p.Temperature.begin();
230 TemperatureIt != p.Temperature.end();
232 if (!Temperature.insert(*TemperatureIt).second)
233 Temperature[TemperatureIt->first] += TemperatureIt->second;
235 AirPressure += p.AirPressure.getValue(0.0);
237 for (scalar_iterator VaporPressureIt = p.VaporPressure.begin();
238 VaporPressureIt != p.VaporPressure.end();
240 if (!VaporPressure.insert(*VaporPressureIt).second)
241 VaporPressure[VaporPressureIt->first] += VaporPressureIt->second;
246 inline FGPhysicalProperties& FGPhysicalProperties::operator -= (const FGPhysicalProperties& p)
248 typedef map<FGPhysicalProperties::Altitude, Point3D >::const_iterator vector_iterator;
249 typedef map<FGPhysicalProperties::Altitude, WeatherPrecition>::const_iterator scalar_iterator;
251 for (vector_iterator WindIt = p.Wind.begin();
252 WindIt != p.Wind.end();
254 if (!Wind.insert( make_pair(WindIt->first, -WindIt->second) ).second) //when it's not inserted => it's already existing
255 Wind[WindIt->first] -= WindIt->second; //=> substract the value
257 for (vector_iterator TurbulenceIt = p.Turbulence.begin();
258 TurbulenceIt != p.Turbulence.end();
260 if (!Turbulence.insert( make_pair(TurbulenceIt->first, -TurbulenceIt->second) ).second)
261 Turbulence[TurbulenceIt->first] -= TurbulenceIt->second;
263 for (scalar_iterator TemperatureIt = p.Temperature.begin();
264 TemperatureIt != p.Temperature.end();
266 if (!Temperature.insert( make_pair(TemperatureIt->first, -TemperatureIt->second) ).second)
267 Temperature[TemperatureIt->first] -= TemperatureIt->second;
269 AirPressure -= p.AirPressure.getValue(0.0);
271 for (scalar_iterator VaporPressureIt = p.VaporPressure.begin();
272 VaporPressureIt != p.VaporPressure.end();
274 if (!VaporPressure.insert( make_pair(VaporPressureIt->first, -VaporPressureIt->second) ).second)
275 VaporPressure[VaporPressureIt->first] -= VaporPressureIt->second;
282 inline Point3D FGPhysicalProperties::WindAt(const WeatherPrecition& a) const
284 typedef map<FGPhysicalProperties::Altitude, Point3D>::const_iterator vector_iterator;
286 vector_iterator it = Wind.lower_bound(a);
287 vector_iterator it2 = it;
290 //now I've got it->alt < a < it2->alt so I can interpolate
291 return ( (it2->second - it->second)/(it2->first - it->first) ) * (a - it2->first) + it2->second;
294 inline Point3D FGPhysicalProperties::TurbulenceAt(const WeatherPrecition& a) const
296 typedef map<FGPhysicalProperties::Altitude, Point3D>::const_iterator vector_iterator;
298 vector_iterator it = Turbulence.lower_bound(a);
299 vector_iterator it2 = it;
302 //now I've got it->alt < a < it2->alt so I can interpolate
303 return ( (it2->second - it->second)/(it2->first - it->first) ) * (a - it2->first) + it2->second;
306 inline WeatherPrecition FGPhysicalProperties::TemperatureAt(const WeatherPrecition& a) const
308 typedef map<FGPhysicalProperties::Altitude, WeatherPrecition>::const_iterator scalar_iterator;
310 scalar_iterator it = Temperature.lower_bound(a);
311 scalar_iterator it2 = it;
314 //now I've got it->alt < a < it2->alt so I can interpolate
315 return ( (it2->second - it->second)/(it2->first - it->first) ) * (a - it2->first) + it2->second;
318 inline WeatherPrecition FGPhysicalProperties::AirPressureAt(const WeatherPrecition& a) const
320 return AirPressure.getValue(a);
323 inline WeatherPrecition FGPhysicalProperties::VaporPressureAt(const WeatherPrecition& a) const
325 typedef map<FGPhysicalProperties::Altitude, WeatherPrecition>::const_iterator scalar_iterator;
327 scalar_iterator it = VaporPressure.lower_bound(a);
328 scalar_iterator it2 = it;
331 //now I've got it->alt < a < it2->alt so I can interpolate
332 return ( (it2->second - it->second)/(it2->first - it->first) ) * (a - it2->first) + it2->second;
336 inline FGPhysicalProperties operator * (FGPhysicalProperties a, const WeatherPrecition& b)
341 inline FGPhysicalProperties operator * (const WeatherPrecition& b, FGPhysicalProperties a)
346 inline FGPhysicalProperties operator + (FGPhysicalProperties a, const FGPhysicalProperties& b)
351 inline FGPhysicalProperties operator - (FGPhysicalProperties a, const FGPhysicalProperties& b)
356 /****************************************************************************/
357 #endif /*FGPhysicalProperties_H*/