X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWeatherCM%2FFGPhysicalProperties.h;h=2e39d5b6b82d5d557eeba91d16fb5a41ab3915da;hb=8199ece7dcca6b45237fab8647205effa6e38bcf;hp=9e62be9e8365c77dad603dd745af366b9b61bde1;hpb=eddea671a276ea5337867d09699730876fce7085;p=flightgear.git diff --git a/src/WeatherCM/FGPhysicalProperties.h b/src/WeatherCM/FGPhysicalProperties.h index 9e62be9e8..2e39d5b6b 100644 --- a/src/WeatherCM/FGPhysicalProperties.h +++ b/src/WeatherCM/FGPhysicalProperties.h @@ -1,10 +1,10 @@ -/*******-*- Mode: C++ -*-************************************************************ +/***************************************************************************** Header: FGPhysicalProperties.h Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -36,6 +36,12 @@ HISTORY 30.06.1999 Christian Mayer STL portability 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning +15.12.1999 Christian Mayer changed the air pressure calculation to a much + more realistic formula. But as I need for that + the temperature I moved the code to + FGPhysicalProperties *****************************************************************************/ /****************************************************************************/ @@ -47,126 +53,130 @@ HISTORY /****************************************************************************/ /* INCLUDES */ /****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#ifdef HAVE_WINDOWS_H +# include +#endif + +#include STL_IOSTREAM #include #include -FG_USING_STD(vector); -FG_USING_STD(map); -FG_USING_NAMESPACE(std); +#include -#include -#include #include "FGWeatherDefs.h" #include "FGAirPressureItem.h" +#include "FGWindItem.h" +#include "FGTurbulenceItem.h" #include "FGCloudItem.h" #include "FGSnowRain.h" +SG_USING_STD(vector); +SG_USING_STD(map); +SG_USING_NAMESPACE(std); + +/****************************************************************************/ +/* FOREWARD DEFINITIONS */ +/****************************************************************************/ +class FGPhysicalProperties2D; +ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p ); + class FGPhysicalProperties { public: - typedef WeatherPrecition Altitude; + typedef WeatherPrecision Altitude; - map Wind; //all Wind vectors - map Turbulence; //all Turbulence vectors - map Temperature; //in deg. Kelvin (I *only* accept SI!) - FGAirPressureItem AirPressure; //in Pascal (I *only* accept SI!) - map VaporPressure; //in Pascal (I *only* accept SI!) + map Wind; //all Wind vectors + map Turbulence; //all Turbulence vectors + map Temperature; //in deg. Kelvin (I *only* accept SI!) + FGAirPressureItem AirPressure; //in Pascal (I *only* accept SI!) + map VaporPressure; //in Pascal (I *only* accept SI!) - map Clouds; //amount of covering and type + map Clouds; //amount of covering and type - WeatherPrecition SnowRainIntensity; //this also stands for hail, snow,... - SnowRainType snowRainType; - WeatherPrecition LightningProbability; + WeatherPrecision SnowRainIntensity; //this also stands for hail, snow,... + SnowRainType snowRainType; + WeatherPrecision LightningProbability; //in lightnings per second FGPhysicalProperties(); //consructor to fill it with FG standart weather //return values at specified altitudes - Point3D WindAt(const WeatherPrecition& a) const; - Point3D TurbulenceAt(const WeatherPrecition& a) const; - WeatherPrecition TemperatureAt(const WeatherPrecition& a) const; - WeatherPrecition AirPressureAt(const WeatherPrecition& a) const; - WeatherPrecition VaporPressureAt(const WeatherPrecition& a) const; + void WindAt (sgVec3 ret, const WeatherPrecision a) const; + void TurbulenceAt (sgVec3 ret, const WeatherPrecision a) const; + WeatherPrecision TemperatureAt (const WeatherPrecision a) const; + WeatherPrecision AirPressureAt (const WeatherPrecision x) const; //x is used here instead of a on purpose + WeatherPrecision VaporPressureAt(const WeatherPrecision a) const; //for easier access to the cloud stuff: unsigned int getNumberOfCloudLayers(void) const; - FGCloudItem getCloudLayer(unsigned int nr) const; + FGCloudItem getCloudLayer(unsigned int nr) const; - FGPhysicalProperties& operator = ( const FGPhysicalProperties& p ); - FGPhysicalProperties& operator *= ( const WeatherPrecition& d ); - FGPhysicalProperties& operator += ( const FGPhysicalProperties& p); - FGPhysicalProperties& operator -= ( const FGPhysicalProperties& p); + FGPhysicalProperties& operator = ( const FGPhysicalProperties& p ); + FGPhysicalProperties& operator *= ( const WeatherPrecision d ); + FGPhysicalProperties& operator += ( const FGPhysicalProperties& p ); + FGPhysicalProperties& operator -= ( const FGPhysicalProperties& p ); + + //for easy binding to the property system + WeatherPrecision getWind_x( int number ) const; + WeatherPrecision getWind_y( int number ) const; + WeatherPrecision getWind_z( int number ) const; + WeatherPrecision getWind_a( int number ) const; + void setWind_x( int number, WeatherPrecision x); + void setWind_y( int number, WeatherPrecision y); + void setWind_z( int number, WeatherPrecision z); + void setWind_a( int number, WeatherPrecision a); + WeatherPrecision getTurbulence_x( int number ) const; + WeatherPrecision getTurbulence_y( int number ) const; + WeatherPrecision getTurbulence_z( int number ) const; + WeatherPrecision getTurbulence_a( int number ) const; + void setTurbulence_x( int number, WeatherPrecision x); + void setTurbulence_y( int number, WeatherPrecision y); + void setTurbulence_z( int number, WeatherPrecision z); + void setTurbulence_a( int number, WeatherPrecision a); + WeatherPrecision getTemperature_x( int number ) const; + WeatherPrecision getTemperature_a( int number ) const; + void setTemperature_x( int number, WeatherPrecision x); + void setTemperature_a( int number, WeatherPrecision a); + WeatherPrecision getVaporPressure_x( int number ) const; + WeatherPrecision getVaporPressure_a( int number ) const; + void setVaporPressure_x( int number, WeatherPrecision x); + void setVaporPressure_a( int number, WeatherPrecision a); }; -typedef vector FGPhysicalPropertiesVector; -typedef FGPhysicalPropertiesVector::iterator FGPhysicalPropertiesVectorIt; -typedef FGPhysicalPropertiesVector::const_iterator FGPhysicalPropertiesVectorConstIt; - -class FGPhysicalProperties2D; -ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p ); - class FGPhysicalProperties2D : public FGPhysicalProperties { public: - Point2D p; //position of the property (lat/lon) + sgVec2 p; //position of the property (lat/lon) friend ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p ); FGPhysicalProperties2D() {} - FGPhysicalProperties2D(const FGPhysicalProperties& prop, const Point2D& pos) + FGPhysicalProperties2D(const FGPhysicalProperties& prop, const sgVec2& pos) { - Wind = prop.Wind; Turbulence = prop.Turbulence; Temperature = prop.Temperature; - AirPressure = prop.AirPressure; VaporPressure = prop.VaporPressure; p = pos; + Wind = prop.Wind; + Turbulence = prop.Turbulence; + Temperature = prop.Temperature; + AirPressure = prop.AirPressure; + VaporPressure = prop.VaporPressure; + sgCopyVec2(p, pos); } }; -typedef vector FGPhysicalProperties2DVector; -typedef FGPhysicalProperties2DVector::iterator FGPhysicalProperties2DVectorIt; -typedef FGPhysicalProperties2DVector::const_iterator FGPhysicalProperties2DVectorConstIt; +typedef vector FGPhysicalPropertiesVector; +typedef FGPhysicalPropertiesVector::iterator FGPhysicalPropertiesVectorIt; +typedef FGPhysicalPropertiesVector::const_iterator FGPhysicalPropertiesVectorConstIt; -inline ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p ) -{ - typedef map::const_iterator vector_iterator; - typedef map::const_iterator scalar_iterator; +typedef vector FGPhysicalProperties2DVector; +typedef FGPhysicalProperties2DVector::iterator FGPhysicalProperties2DVectorIt; +typedef FGPhysicalProperties2DVector::const_iterator FGPhysicalProperties2DVectorConstIt; - out << "Position: " << p.p << endl; - - out << "Stored Wind: "; - for (vector_iterator WindIt = p.Wind.begin(); - WindIt != p.Wind.end(); - WindIt++) - out << "(" << WindIt->first << ") at " << WindIt->second << "m; "; - out << endl; - - out << "Stored Turbulence: "; - for (vector_iterator TurbulenceIt = p.Turbulence.begin(); - TurbulenceIt != p.Turbulence.end(); - TurbulenceIt++) - out << "(" << TurbulenceIt->first << ") at " << TurbulenceIt->second << "m; "; - out << endl; - - out << "Stored Temperature: "; - for (scalar_iterator TemperatureIt = p.Temperature.begin(); - TemperatureIt != p.Temperature.end(); - TemperatureIt++) - out << TemperatureIt->first << " at " << TemperatureIt->second << "m; "; - out << endl; - - out << "Stored AirPressure: "; - out << p.AirPressure.getValue(0) << " at " << 0.0 << "m; "; - out << endl; - - out << "Stored VaporPressure: "; - for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); - VaporPressureIt != p.VaporPressure.end(); - VaporPressureIt++) - out << VaporPressureIt->first << " at " << VaporPressureIt->second << "m; "; - out << endl; - - return out << endl; -} inline FGPhysicalProperties& FGPhysicalProperties::operator = ( const FGPhysicalProperties& p ) @@ -179,31 +189,32 @@ inline FGPhysicalProperties& FGPhysicalProperties::operator = ( const FGPhysical return *this; } -inline FGPhysicalProperties& FGPhysicalProperties::operator *= ( const WeatherPrecition& d ) +inline FGPhysicalProperties& FGPhysicalProperties::operator *= ( const WeatherPrecision d ) { - typedef map::iterator vector_iterator; - typedef map::iterator scalar_iterator; - - for (vector_iterator WindIt = Wind.begin(); - WindIt != Wind.end(); - WindIt++) - WindIt->second *= d; - - for (vector_iterator TurbulenceIt = Turbulence.begin(); - TurbulenceIt != Turbulence.end(); - TurbulenceIt++) - TurbulenceIt->second *= d; - - for (scalar_iterator TemperatureIt = Temperature.begin(); - TemperatureIt != Temperature.end(); - TemperatureIt++) + typedef map::iterator wind_iterator; + typedef map::iterator turbulence_iterator; + typedef map::iterator scalar_iterator; + + for (wind_iterator WindIt = Wind.begin(); + WindIt != Wind.end(); + WindIt++) + WindIt->second*= d; + + for (turbulence_iterator TurbulenceIt = Turbulence.begin(); + TurbulenceIt != Turbulence.end(); + TurbulenceIt++) + TurbulenceIt->second *= d; + + for (scalar_iterator TemperatureIt = Temperature.begin(); + TemperatureIt != Temperature.end(); + TemperatureIt++) TemperatureIt->second *= d; AirPressure *= d; - for (scalar_iterator VaporPressureIt = VaporPressure.begin(); - VaporPressureIt != VaporPressure.end(); - VaporPressureIt++) + for (scalar_iterator VaporPressureIt = VaporPressure.begin(); + VaporPressureIt != VaporPressure.end(); + VaporPressureIt++) VaporPressureIt->second *= d; return *this; @@ -211,101 +222,150 @@ inline FGPhysicalProperties& FGPhysicalProperties::operator *= ( const WeatherPr inline FGPhysicalProperties& FGPhysicalProperties::operator += (const FGPhysicalProperties& p) { - typedef map::const_iterator vector_iterator; - typedef map::const_iterator scalar_iterator; + typedef map::const_iterator wind_iterator; + typedef map::const_iterator turbulence_iterator; + typedef map::const_iterator scalar_iterator; - for (vector_iterator WindIt = p.Wind.begin(); - WindIt != p.Wind.end(); - WindIt++ ) + for (wind_iterator WindIt = p.Wind.begin(); + WindIt != p.Wind.end(); + WindIt++) if (!Wind.insert(*WindIt).second) //when it's not inserted => it's already existing Wind[WindIt->first] += WindIt->second; //=> add the value - for (vector_iterator TurbulenceIt = p.Turbulence.begin(); - TurbulenceIt != p.Turbulence.end(); - TurbulenceIt++) + for (turbulence_iterator TurbulenceIt = p.Turbulence.begin(); + TurbulenceIt != p.Turbulence.end(); + TurbulenceIt++) if (!Turbulence.insert(*TurbulenceIt).second) Turbulence[TurbulenceIt->first] += TurbulenceIt->second; - - for (scalar_iterator TemperatureIt = p.Temperature.begin(); - TemperatureIt != p.Temperature.end(); - TemperatureIt++) + + for (scalar_iterator TemperatureIt = p.Temperature.begin(); + TemperatureIt != p.Temperature.end(); + TemperatureIt++) if (!Temperature.insert(*TemperatureIt).second) Temperature[TemperatureIt->first] += TemperatureIt->second; - AirPressure += p.AirPressure.getValue(0.0); + AirPressure += p.AirPressure.getValue(); - for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); - VaporPressureIt != p.VaporPressure.end(); - VaporPressureIt++) + for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); + VaporPressureIt != p.VaporPressure.end(); + VaporPressureIt++) if (!VaporPressure.insert(*VaporPressureIt).second) VaporPressure[VaporPressureIt->first] += VaporPressureIt->second; return *this; } +// slightly modified version that also makes the Mac happy inline FGPhysicalProperties& FGPhysicalProperties::operator -= (const FGPhysicalProperties& p) { - typedef map::const_iterator vector_iterator; - typedef map::const_iterator scalar_iterator; + typedef map::const_iterator wind_iterator; + typedef map::const_iterator turbulence_iterator; + typedef map::const_iterator scalar_iterator; + + // types to replace make_pair + typedef map::value_type wind_type; + typedef map::value_type turb_type; + typedef map::value_type weather_type; + + for (wind_iterator WindIt = p.Wind.begin(); + WindIt != p.Wind.end(); + WindIt++) + if (!Wind.insert( wind_type(WindIt->first, -WindIt->second) ).second) + // when it's not inserted => it's already existing + Wind[WindIt->first] -= WindIt->second; //=> substract the value + + for (turbulence_iterator TurbulenceIt = p.Turbulence.begin(); + TurbulenceIt != p.Turbulence.end(); + TurbulenceIt++) + if (!Turbulence.insert( turb_type(TurbulenceIt->first, -TurbulenceIt->second) ).second) + Turbulence[TurbulenceIt->first] -= TurbulenceIt->second; + + for (scalar_iterator TemperatureIt = p.Temperature.begin(); + TemperatureIt != p.Temperature.end(); + TemperatureIt++) + if (!Temperature.insert( weather_type(TemperatureIt->first, -TemperatureIt->second) ).second) + Temperature[TemperatureIt->first] -= TemperatureIt->second; + + AirPressure -= p.AirPressure.getValue(); + + for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); + VaporPressureIt != p.VaporPressure.end(); + VaporPressureIt++) + if (!VaporPressure.insert( weather_type(VaporPressureIt->first, -VaporPressureIt->second) ).second) + VaporPressure[VaporPressureIt->first] -= VaporPressureIt->second; - for (vector_iterator WindIt = p.Wind.begin(); - WindIt != p.Wind.end(); - WindIt++ ) + return *this; +} + +#if 0 // old version +inline FGPhysicalProperties& FGPhysicalProperties::operator -= (const FGPhysicalProperties& p) +{ + typedef map::const_iterator wind_iterator; + typedef map::const_iterator turbulence_iterator; + typedef map::const_iterator scalar_iterator; + + for (wind_iterator WindIt = p.Wind.begin(); + WindIt != p.Wind.end(); + WindIt++) if (!Wind.insert( make_pair(WindIt->first, -WindIt->second) ).second) //when it's not inserted => it's already existing Wind[WindIt->first] -= WindIt->second; //=> substract the value - for (vector_iterator TurbulenceIt = p.Turbulence.begin(); - TurbulenceIt != p.Turbulence.end(); - TurbulenceIt++) + for (turbulence_iterator TurbulenceIt = p.Turbulence.begin(); + TurbulenceIt != p.Turbulence.end(); + TurbulenceIt++) if (!Turbulence.insert( make_pair(TurbulenceIt->first, -TurbulenceIt->second) ).second) Turbulence[TurbulenceIt->first] -= TurbulenceIt->second; - for (scalar_iterator TemperatureIt = p.Temperature.begin(); - TemperatureIt != p.Temperature.end(); - TemperatureIt++) + for (scalar_iterator TemperatureIt = p.Temperature.begin(); + TemperatureIt != p.Temperature.end(); + TemperatureIt++) if (!Temperature.insert( make_pair(TemperatureIt->first, -TemperatureIt->second) ).second) Temperature[TemperatureIt->first] -= TemperatureIt->second; - AirPressure -= p.AirPressure.getValue(0.0); + AirPressure -= p.AirPressure.getValue(); - for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); - VaporPressureIt != p.VaporPressure.end(); - VaporPressureIt++) + for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); + VaporPressureIt != p.VaporPressure.end(); + VaporPressureIt++) if (!VaporPressure.insert( make_pair(VaporPressureIt->first, -VaporPressureIt->second) ).second) VaporPressure[VaporPressureIt->first] -= VaporPressureIt->second; return *this; } +#endif - -inline Point3D FGPhysicalProperties::WindAt(const WeatherPrecition& a) const +inline void FGPhysicalProperties::WindAt(sgVec3 ret, const WeatherPrecision a) const { - typedef map::const_iterator vector_iterator; + typedef map::const_iterator vector_iterator; vector_iterator it = Wind.lower_bound(a); vector_iterator it2 = it; it--; //now I've got it->alt < a < it2->alt so I can interpolate - return ( (it2->second - it->second)/(it2->first - it->first) ) * (a - it2->first) + it2->second; + sgSubVec3(ret, *it2->second.getValue(), *it->second.getValue()); + sgScaleVec3(ret, (a - it2->first) / (it2->first - it->first)); + sgAddVec3(ret, *it2->second.getValue()); } -inline Point3D FGPhysicalProperties::TurbulenceAt(const WeatherPrecition& a) const +inline void FGPhysicalProperties::TurbulenceAt(sgVec3 ret, const WeatherPrecision a) const { - typedef map::const_iterator vector_iterator; + typedef map::const_iterator vector_iterator; vector_iterator it = Turbulence.lower_bound(a); vector_iterator it2 = it; it--; //now I've got it->alt < a < it2->alt so I can interpolate - return ( (it2->second - it->second)/(it2->first - it->first) ) * (a - it2->first) + it2->second; + sgSubVec3(ret, *it2->second.getValue(), *it->second.getValue()); + sgScaleVec3(ret, (a - it2->first) / (it2->first - it->first)); + sgAddVec3(ret, *it2->second.getValue()); } -inline WeatherPrecition FGPhysicalProperties::TemperatureAt(const WeatherPrecition& a) const +inline WeatherPrecision FGPhysicalProperties::TemperatureAt(const WeatherPrecision a) const { - typedef map::const_iterator scalar_iterator; + typedef map::const_iterator scalar_iterator; scalar_iterator it = Temperature.lower_bound(a); scalar_iterator it2 = it; @@ -315,14 +375,12 @@ inline WeatherPrecition FGPhysicalProperties::TemperatureAt(const WeatherPreciti return ( (it2->second - it->second)/(it2->first - it->first) ) * (a - it2->first) + it2->second; } -inline WeatherPrecition FGPhysicalProperties::AirPressureAt(const WeatherPrecition& a) const -{ - return AirPressure.getValue(a); -} +//inline WeatherPrecision FGPhysicalProperties::AirPressureAt(const WeatherPrecision x) const +//moved to FGPhysicalProperties.cpp as it got too complex to inline -inline WeatherPrecition FGPhysicalProperties::VaporPressureAt(const WeatherPrecition& a) const +inline WeatherPrecision FGPhysicalProperties::VaporPressureAt(const WeatherPrecision a) const { - typedef map::const_iterator scalar_iterator; + typedef map::const_iterator scalar_iterator; scalar_iterator it = VaporPressure.lower_bound(a); scalar_iterator it2 = it; @@ -333,12 +391,12 @@ inline WeatherPrecition FGPhysicalProperties::VaporPressureAt(const WeatherPreci } -inline FGPhysicalProperties operator * (FGPhysicalProperties a, const WeatherPrecition& b) +inline FGPhysicalProperties operator * (FGPhysicalProperties a, const WeatherPrecision b) { return a *= b; } -inline FGPhysicalProperties operator * (const WeatherPrecition& b, FGPhysicalProperties a) +inline FGPhysicalProperties operator * (const WeatherPrecision b, FGPhysicalProperties a) { return a *= b; }