Air Density Calculations

227 views
Skip to first unread message

Robert James Liguori

unread,
Jan 21, 2017, 2:49:20 PM1/21/17
to golden-cheetah-users
Was your air density calculations done in C++? I'm trying to do the same with Java:


Can you provide me the link to your source code for Air Density Calculations


Mark Liversedge

unread,
Jan 21, 2017, 2:51:02 PM1/21/17
to golden-cheetah-users

Robert Chung

unread,
Jan 21, 2017, 7:20:38 PM1/21/17
to golden-cheetah-users


On Saturday, January 21, 2017 at 11:51:02 AM UTC-8, Mark Liversedge wrote:
On Saturday, 21 January 2017 19:49:20 UTC, Robert James Liguori wrote:



I'm afraid I don't write C++ so I've never been able to submit a patch for this.

The rho calculator in GC uses what's called "station pressure", which is the actual air pressure at the location. However, "official" air pressure is usually standardized to sea level so if you are using the pressure given by an airport or official weather station you need to adjust the rho for the elevation. That is, if you're at or near sea level, station pressure and official pressure are the same; but if you're in Denver at a mile above sea level you either should be using station pressure or else adjust the official barometric pressure to an elevation of 1600 meters.

I calculate my own rho when I test.

Mark Liversedge

unread,
Jan 22, 2017, 4:04:55 AM1/22/17
to golden-cheetah-users
If you have it as a spreadsheet or whatever, send it across and I'll update to C++ ?

Thanks

Mark 

Robert Chung

unread,
Jan 23, 2017, 9:25:21 PM1/23/17
to golden-cheetah-users


On Sunday, January 22, 2017 at 1:04:55 AM UTC-8, Mark Liversedge wrote:
If you have it as a spreadsheet or whatever, send it across and I'll update to C++ ?

Mark:

I don't have it in a spreadsheet, but I have an R function. Because it was for my own use, it uses metric inputs and relative humidity (rather than dew point). I use a couple of approximations but I've checked with a few online air density calculators and my approximations agree with theirs to usually around the 3rd (or sometimes 4th) decimal place.

===

rho.calc = function(hPa=1023,Tc=21,RH=70, h=0) {
  # Need:
  # Barometric pressure at sea level (hPa)
  # air temp in celsius (Tc)
  # relative humidity (RH) in percent (e.g., 60% = 60)
  # height ASL (h, in meters)
  # Example: rho.calc(hPa=1015,Tc=20, RH=65, h=100)

  # Note: if using station pressure (aka absolute pressure) then set h=0
  # That is, think of h as the difference between your altitude and wherever
  # the barometric pressure is standardized to

  g = 9.80665  #gravity m/sec^2
  Md = 0.0289644 # Molar mass of dry air in kg/mol
  Mv = 0.018016 # Molar mass of water vapor in kg/mol
  R = 8.31432 # Universal gas constant in J/(mol*K)
  Rd = R/Md # gas constant dry air in J/(kg*K) = 287.05
  Rv = R/Mv # gas constant water vapor in J/(kg*K) = 461.495
  L = 0.0065 # temperature lapse rate in deg K/m
  Tk = Tc + 273.15 # deg kelvin = celsius + 273.15

  # Altitude correction
  hPa.corrected = hPa * ((1-(L*h)/Tk)^((g*Md)/(R*L))) #corrected for altitude

  # Using humidity Teten's approximation; alternatively use Wobus' formula 
  PVsat = 6.1078 * 10^(7.5 * Tc/(237.3 + Tc)) # Saturation vapor pressure in mbars (Teten's formula)
  PV = PVsat * RH/100 # Humidity corrected
 
  Tv = Tk/(1-(0.378*PV/hPa.corrected)) # Virtual temperature (kelvin)
  rho = 100*hPa.corrected/(Rd*Tv)
  rho = round(rho,3)
  return(rho)
  }

Reply all
Reply to author
Forward
0 new messages