module Atmosphere.Atmosphere( Atmos(..)
, siAtmosphere
, usAtmosphere
, siAtmosphere'
, usAtmosphere'
, atmosphere
) where
import Atmosphere.Constants
data Atmos a = Atmos { atmosTemperature :: a
, atmosPressure :: a
, atmosDensity :: a
, atmosSpeedOfSound :: a
, atmosViscosity :: a
, atmosKinematicViscosity :: a
}
siAtmosphere :: (Floating a, Ord a) => a -> (a,a,a,a,a,a)
siAtmosphere alt_m = (temp, pressure, density, asound, viscosity, kinematicViscosity)
where
alt_km = 0.001*alt_m
(sigma, delta, theta) = atmosphere alt_km
temp = _TZERO * theta
pressure = _PZERO * delta
density = _RHOZERO * sigma
asound = _AZERO * sqrt theta
viscosity = metricViscosity theta
kinematicViscosity = viscosity/density
usAtmosphere :: (Floating a, Ord a) => a -> (a,a,a,a,a,a)
usAtmosphere alt_ft = (temp, pressure, density, asound, viscosity, kinematicViscosity)
where
alt_km = 0.001*_FT2METERS*alt_ft
(sigma, delta, theta) = atmosphere alt_km
temp = _KELVIN2RANKINE*_TZERO*theta
pressure = _PZERO*delta/47.88
density = _RHOZERO*sigma/515.379
asound = (_AZERO/_FT2METERS)*sqrt theta
viscosity=(1.0/_PSF2NSM)*metricViscosity theta
kinematicViscosity = viscosity/density
metricViscosity :: (Floating a, Ord a) => a -> a
metricViscosity theta = _BETAVISC*sqrt(t*t*t)/(t+_SUTH)
where
t = theta * _TZERO
siAtmosphere' :: (Floating a, Ord a) => a -> Atmos a
siAtmosphere' alt = Atmos temp pressure density asound viscosity kinematicViscosity
where
(temp, pressure, density, asound, viscosity, kinematicViscosity) = siAtmosphere alt
usAtmosphere' :: (Floating a, Ord a) => a -> Atmos a
usAtmosphere' alt = Atmos temp pressure density asound viscosity kinematicViscosity
where
(temp, pressure, density, asound, viscosity, kinematicViscosity) = usAtmosphere alt
atmosphere :: (Floating a, Ord a) => a -> (a,a,a)
atmosphere alt = (sigma, delta, theta)
where
_REARTH = 6369.0
_GMR = 34.163195
h = alt*_REARTH/(alt+_REARTH)
(htabI, tbase, ptabI, tgradI) = getI htpgTable
where
getI [htab'] = htab'
getI (htab0:htab1@(h',_,_,_):htabs)
| h > h' = getI (htab1:htabs)
| otherwise = htab0
getI [] = error "something went wrong"
deltah = h htabI
tlocal = tbase + tgradI*deltah
theta = tlocal/_TZERO
delta
| 0.0 == tgradI = ptabI*exp(_GMR*deltah/tbase)
| otherwise = ptabI*(tbase/tlocal)**(_GMR/tgradI)
sigma = delta/theta