1
0
Fork 0
flightgear/src/WeatherCM/FGPhysicalProperties.h

347 lines
13 KiB
C
Raw Normal View History

1999-10-20 22:19:07 +00:00
/*****************************************************************************
1999-08-10 03:40:34 +00:00
Header: FGPhysicalProperties.h
Author: Christian Mayer
Date started: 28.05.99
1999-10-20 22:19:07 +00:00
-------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
1999-08-10 03:40:34 +00:00
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
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA.
Further information about the GNU General Public License can also be found on
the world wide web at http://www.gnu.org.
FUNCTIONAL DESCRIPTION
------------------------------------------------------------------------------
Define the simulated physical properties of the weather
HISTORY
------------------------------------------------------------------------------
28.05.1999 Christian Mayer Created
16.06.1999 Durk Talsma Portability for Linux
20.06.1999 Christian Mayer Changed struct to class
20.06.1999 Christian Mayer added lots of consts
30.06.1999 Christian Mayer STL portability
11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
suggestion
1999-10-20 22:19:07 +00:00
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
1999-08-10 03:40:34 +00:00
*****************************************************************************/
/****************************************************************************/
/* SENTRY */
/****************************************************************************/
#ifndef FGPhysicalProperties_H
#define FGPhysicalProperties_H
/****************************************************************************/
/* INCLUDES */
/****************************************************************************/
1999-10-23 04:19:25 +00:00
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
1999-08-10 03:40:34 +00:00
#include <Include/compiler.h>
1999-10-20 22:19:07 +00:00
1999-10-23 04:19:25 +00:00
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
1999-10-20 22:19:07 +00:00
#include <iostream>
1999-08-10 03:40:34 +00:00
#include <vector>
#include <map>
1999-08-10 03:40:34 +00:00
2000-02-04 22:50:04 +00:00
#include <plib/sg.h>
1999-08-10 03:40:34 +00:00
#include "FGWeatherDefs.h"
#include "FGAirPressureItem.h"
1999-10-20 22:19:07 +00:00
#include "FGWindItem.h"
#include "FGTurbulenceItem.h"
1999-08-10 03:40:34 +00:00
#include "FGCloudItem.h"
#include "FGSnowRain.h"
1999-10-20 22:19:07 +00:00
FG_USING_STD(vector);
FG_USING_STD(map);
FG_USING_NAMESPACE(std);
/****************************************************************************/
/* FOREWARD DEFINITIONS */
/****************************************************************************/
class FGPhysicalProperties2D;
ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p );
1999-08-10 03:40:34 +00:00
class FGPhysicalProperties
{
public:
1999-10-20 22:19:07 +00:00
typedef WeatherPrecision Altitude;
1999-10-20 22:19:07 +00:00
map<Altitude,FGWindItem> Wind; //all Wind vectors
map<Altitude,FGTurbulenceItem> Turbulence; //all Turbulence vectors
map<Altitude,WeatherPrecision> Temperature; //in deg. Kelvin (I *only* accept SI!)
FGAirPressureItem AirPressure; //in Pascal (I *only* accept SI!)
map<Altitude,WeatherPrecision> VaporPressure; //in Pascal (I *only* accept SI!)
1999-10-20 22:19:07 +00:00
map<Altitude,FGCloudItem> Clouds; //amount of covering and type
1999-08-10 03:40:34 +00:00
1999-11-03 18:06:52 +00:00
WeatherPrecision SnowRainIntensity; //this also stands for hail, snow,...
1999-10-20 22:19:07 +00:00
SnowRainType snowRainType;
1999-11-03 18:06:52 +00:00
WeatherPrecision LightningProbability; //in lightnings per second
1999-08-10 03:40:34 +00:00
FGPhysicalProperties(); //consructor to fill it with FG standart weather
//return values at specified altitudes
1999-10-20 22:19:07 +00:00
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
1999-10-20 22:19:07 +00:00
WeatherPrecision VaporPressureAt(const WeatherPrecision a) const;
//for easier access to the cloud stuff:
unsigned int getNumberOfCloudLayers(void) const;
1999-10-20 22:19:07 +00:00
FGCloudItem getCloudLayer(unsigned int nr) const;
1999-08-10 03:40:34 +00:00
1999-10-20 22:19:07 +00:00
FGPhysicalProperties& operator = ( const FGPhysicalProperties& p );
FGPhysicalProperties& operator *= ( const WeatherPrecision d );
FGPhysicalProperties& operator += ( const FGPhysicalProperties& p );
FGPhysicalProperties& operator -= ( const FGPhysicalProperties& p );
1999-08-10 03:40:34 +00:00
};
class FGPhysicalProperties2D : public FGPhysicalProperties
{
public:
1999-10-20 22:19:07 +00:00
sgVec2 p; //position of the property (lat/lon)
1999-08-10 03:40:34 +00:00
friend ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p );
FGPhysicalProperties2D() {}
1999-10-20 22:19:07 +00:00
FGPhysicalProperties2D(const FGPhysicalProperties& prop, const sgVec2& pos)
1999-08-10 03:40:34 +00:00
{
1999-10-20 22:19:07 +00:00
Wind = prop.Wind;
Turbulence = prop.Turbulence;
Temperature = prop.Temperature;
AirPressure = prop.AirPressure;
VaporPressure = prop.VaporPressure;
sgCopyVec2(p, pos);
1999-08-10 03:40:34 +00:00
}
};
1999-10-20 22:19:07 +00:00
typedef vector<FGPhysicalProperties> FGPhysicalPropertiesVector;
typedef FGPhysicalPropertiesVector::iterator FGPhysicalPropertiesVectorIt;
typedef FGPhysicalPropertiesVector::const_iterator FGPhysicalPropertiesVectorConstIt;
typedef vector<FGPhysicalProperties2D> FGPhysicalProperties2DVector;
typedef FGPhysicalProperties2DVector::iterator FGPhysicalProperties2DVectorIt;
1999-08-10 03:40:34 +00:00
typedef FGPhysicalProperties2DVector::const_iterator FGPhysicalProperties2DVectorConstIt;
inline FGPhysicalProperties& FGPhysicalProperties::operator = ( const FGPhysicalProperties& p )
{
Wind = p.Wind;
Turbulence = p.Turbulence;
Temperature = p.Temperature;
AirPressure = p.AirPressure;
VaporPressure = p.VaporPressure;
return *this;
}
1999-10-20 22:19:07 +00:00
inline FGPhysicalProperties& FGPhysicalProperties::operator *= ( const WeatherPrecision d )
1999-08-10 03:40:34 +00:00
{
1999-10-20 22:19:07 +00:00
typedef map<FGPhysicalProperties::Altitude, FGWindItem >::iterator wind_iterator;
typedef map<FGPhysicalProperties::Altitude, FGTurbulenceItem>::iterator turbulence_iterator;
typedef map<FGPhysicalProperties::Altitude, WeatherPrecision>::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;
1999-08-10 03:40:34 +00:00
AirPressure *= d;
1999-10-20 22:19:07 +00:00
for (scalar_iterator VaporPressureIt = VaporPressure.begin();
VaporPressureIt != VaporPressure.end();
VaporPressureIt++)
VaporPressureIt->second *= d;
1999-08-10 03:40:34 +00:00
return *this;
}
inline FGPhysicalProperties& FGPhysicalProperties::operator += (const FGPhysicalProperties& p)
{
1999-10-20 22:19:07 +00:00
typedef map<FGPhysicalProperties::Altitude, FGWindItem >::const_iterator wind_iterator;
typedef map<FGPhysicalProperties::Altitude, FGTurbulenceItem>::const_iterator turbulence_iterator;
typedef map<FGPhysicalProperties::Altitude, WeatherPrecision>::const_iterator scalar_iterator;
1999-10-20 22:19:07 +00:00
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
1999-08-10 03:40:34 +00:00
1999-10-20 22:19:07 +00:00
for (turbulence_iterator TurbulenceIt = p.Turbulence.begin();
TurbulenceIt != p.Turbulence.end();
TurbulenceIt++)
if (!Turbulence.insert(*TurbulenceIt).second)
Turbulence[TurbulenceIt->first] += TurbulenceIt->second;
1999-10-20 22:19:07 +00:00
for (scalar_iterator TemperatureIt = p.Temperature.begin();
TemperatureIt != p.Temperature.end();
TemperatureIt++)
if (!Temperature.insert(*TemperatureIt).second)
Temperature[TemperatureIt->first] += TemperatureIt->second;
1999-08-10 03:40:34 +00:00
AirPressure += p.AirPressure.getValue();
1999-08-10 03:40:34 +00:00
1999-10-20 22:19:07 +00:00
for (scalar_iterator VaporPressureIt = p.VaporPressure.begin();
VaporPressureIt != p.VaporPressure.end();
VaporPressureIt++)
if (!VaporPressure.insert(*VaporPressureIt).second)
VaporPressure[VaporPressureIt->first] += VaporPressureIt->second;
1999-08-10 03:40:34 +00:00
return *this;
}
inline FGPhysicalProperties& FGPhysicalProperties::operator -= (const FGPhysicalProperties& p)
{
1999-10-20 22:19:07 +00:00
typedef map<FGPhysicalProperties::Altitude, FGWindItem >::const_iterator wind_iterator;
typedef map<FGPhysicalProperties::Altitude, FGTurbulenceItem>::const_iterator turbulence_iterator;
typedef map<FGPhysicalProperties::Altitude, WeatherPrecision>::const_iterator scalar_iterator;
1999-10-20 22:19:07 +00:00
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
1999-08-10 03:40:34 +00:00
1999-10-20 22:19:07 +00:00
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;
1999-08-10 03:40:34 +00:00
1999-10-20 22:19:07 +00:00
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;
1999-08-10 03:40:34 +00:00
AirPressure -= p.AirPressure.getValue();
1999-08-10 03:40:34 +00:00
1999-10-20 22:19:07 +00:00
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;
1999-08-10 03:40:34 +00:00
return *this;
}
1999-10-20 22:19:07 +00:00
inline void FGPhysicalProperties::WindAt(sgVec3 ret, const WeatherPrecision a) const
1999-08-10 03:40:34 +00:00
{
1999-10-20 22:19:07 +00:00
typedef map<FGPhysicalProperties::Altitude, FGWindItem>::const_iterator vector_iterator;
vector_iterator it = Wind.lower_bound(a);
vector_iterator it2 = it;
1999-08-10 03:40:34 +00:00
it--;
//now I've got it->alt < a < it2->alt so I can interpolate
1999-10-20 22:19:07 +00:00
sgSubVec3(ret, *it2->second.getValue(), *it->second.getValue());
sgScaleVec3(ret, (a - it2->first) / (it2->first - it->first));
sgAddVec3(ret, *it2->second.getValue());
1999-08-10 03:40:34 +00:00
}
1999-10-20 22:19:07 +00:00
inline void FGPhysicalProperties::TurbulenceAt(sgVec3 ret, const WeatherPrecision a) const
1999-08-10 03:40:34 +00:00
{
1999-10-20 22:19:07 +00:00
typedef map<FGPhysicalProperties::Altitude, FGTurbulenceItem>::const_iterator vector_iterator;
vector_iterator it = Turbulence.lower_bound(a);
vector_iterator it2 = it;
1999-08-10 03:40:34 +00:00
it--;
//now I've got it->alt < a < it2->alt so I can interpolate
1999-10-20 22:19:07 +00:00
sgSubVec3(ret, *it2->second.getValue(), *it->second.getValue());
sgScaleVec3(ret, (a - it2->first) / (it2->first - it->first));
sgAddVec3(ret, *it2->second.getValue());
1999-08-10 03:40:34 +00:00
}
1999-10-20 22:19:07 +00:00
inline WeatherPrecision FGPhysicalProperties::TemperatureAt(const WeatherPrecision a) const
1999-08-10 03:40:34 +00:00
{
1999-10-20 22:19:07 +00:00
typedef map<FGPhysicalProperties::Altitude, WeatherPrecision>::const_iterator scalar_iterator;
scalar_iterator it = Temperature.lower_bound(a);
scalar_iterator it2 = it;
1999-08-10 03:40:34 +00:00
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;
1999-08-10 03:40:34 +00:00
}
//inline WeatherPrecision FGPhysicalProperties::AirPressureAt(const WeatherPrecision x) const
//moved to FGPhysicalProperties.cpp as it got too complex to inline
1999-08-10 03:40:34 +00:00
1999-10-20 22:19:07 +00:00
inline WeatherPrecision FGPhysicalProperties::VaporPressureAt(const WeatherPrecision a) const
1999-08-10 03:40:34 +00:00
{
1999-10-20 22:19:07 +00:00
typedef map<FGPhysicalProperties::Altitude, WeatherPrecision>::const_iterator scalar_iterator;
scalar_iterator it = VaporPressure.lower_bound(a);
scalar_iterator it2 = it;
1999-08-10 03:40:34 +00:00
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;
1999-08-10 03:40:34 +00:00
}
1999-10-20 22:19:07 +00:00
inline FGPhysicalProperties operator * (FGPhysicalProperties a, const WeatherPrecision b)
1999-08-10 03:40:34 +00:00
{
return a *= b;
1999-08-10 03:40:34 +00:00
}
1999-10-20 22:19:07 +00:00
inline FGPhysicalProperties operator * (const WeatherPrecision b, FGPhysicalProperties a)
1999-08-10 03:40:34 +00:00
{
return a *= b;
1999-08-10 03:40:34 +00:00
}
inline FGPhysicalProperties operator + (FGPhysicalProperties a, const FGPhysicalProperties& b)
1999-08-10 03:40:34 +00:00
{
return a += b;
1999-08-10 03:40:34 +00:00
}
inline FGPhysicalProperties operator - (FGPhysicalProperties a, const FGPhysicalProperties& b)
1999-08-10 03:40:34 +00:00
{
return a -= b;
1999-08-10 03:40:34 +00:00
}
/****************************************************************************/
#endif /*FGPhysicalProperties_H*/