Jump to content

Everything I've been told about atmospheric pressure in KSP is wrong.


acalculus

Recommended Posts

I was failing to get an SSTO craft to orbit. I decided to make a nice chart for myself of aerodynamic drag. I figured I could either dig up a formula to calculate the air pressure at each altitude, or I could do it the Jeb way, and launch a spacecraft with a barometer, and record measurements at different altitudes. Of course I had to do it Jeb's way.

To my great surprise, the values I measured were up to 300% off the published formulas of pres = 2.718^((0-altitude)/5000).

muteexah.png

This means there is actually a lot more drag loss over a launch than previous math would have shown.

Method:

Create any spacecraft. Add a barometer. Add a KOS computer from the KOS mod, with code below. Launch from KSP at any angle, altitude, or speed.

SET NextAlt TO 0.
SWITCH TO ARCHIVE.
UNTIL FALSE {
WAIT UNTIL NextAlt < SHIP:ALTITUDE.
PRINT SHIP:ALTITUDE + " " + SHIP:SENSORS:PRES.
LOG SHIP:ALTITUDE + " " + SHIP:SENSORS:PRES TO "kerbin_pressure.txt".
SET NextAlt TO NextAlt + 1000.
}

Things I've tried to invalidate my data:

- Multiple launches (no change)

- Different vertical velocities at various altitudes (no change)

- Different angles (no change)

- Barometer on top of bottom of launcher (no change)

Here's a sample of my data over a couple launches. (/snipped/)

Update - 5/25/20015:

KSP no longer uses a simple formula for atmospheric pressure. Rather it uses a bunch of spline points, picked to roughly matched a scaled down version of the earths atmosphere. This means that the only way to really know atmospheric pressure is to look it up in a table, or to calculate it from the spline points.

Here's an accurate table of experimentally verified altitudes and pressures: https://gist.github.com/DanielVF/1d6fcb9d7db7a36100a5

Edited by acalculus
Link to comment
Share on other sites

It's not wrong, it's just old - there was a better thread on this topic that directly infers the formula by looking at the UnityCurve parameters - though I cannot find it now, I should've marked it somewhere myself...

Link to comment
Share on other sites

Looks like something d / (k*a^2)

where a is the altitude and d and k are some yet to be determined values. Which would basically be the (simplified) real world formula for air pressure.

Link to comment
Share on other sites

Two, that doesn't seem to work for me. It isn't possible to match the shape. Given the two humped nature of the pressure shape on a log scale, it does seem likely to be coming from some kind of defined unity curve.

Link to comment
Share on other sites

I played with your data a little bit, and found a reasonable match for atmospheric calculations with the assumption of linear decrease of temperature (The exponential law from the the "old atmo" assumes constant temperature).

The German wiki has a lot of information and math, unfortunately I did not find the corresponding info on the English wikipedia:

http://de.wikipedia.org/wiki/Barometrische_H%C3%B6henformel#Internationale_H.C3.B6henformel

If I use 100% pressure at sea level, the temperature of 288 K at KSC, I get a reasonable agreement with your data for up to 15000 m (I use 0.006 and 7.2 as coefficients). The relative deviation is not very big, so the formula is propably not too far off.

hurPNF2.png

The model does not work for your data in greater heights, I assume that we could try to work in the actual temperature, I guess it does not decrease linearly. I did not have those data available for this quick test.

Edited by RocketPropelledGiraffe
Link to comment
Share on other sites

I played with your data a little bit, and found a reasonable match for atmospheric calculations with the assumption of linear decrease of temperature (The exponential law from the the "old atmo" assumes constant temperature).

The German wiki has a lot of information and math, unfortunately I did not find the corresponding info on the English wikipedia:

http://de.wikipedia.org/wiki/Barometrische_H%C3%B6henformel#Internationale_H.C3.B6henformel

If I use 100% pressure at sea level, the temperature of 288 K at KSC, I get a reasonable agreement with your data for up to 15000 m (I use 0.006 and 7.2 as coefficients). The relative deviation is not very big, so the formula is propably not too far off.

http://i.imgur.com/hurPNF2.png

The model does not work for your data in greater heights, I assume that we could try to work in the actual temperature, I guess it does not decrease linearly. I did not have those data available for this quick test.

Could we have a basic pressure-to-altitude graph?

Link to comment
Share on other sites

Anything you wish for:

I made a plot for low and high altitude. The blue dots are acalculus' data, red line the basic exponential law p=p0*Exp(-h/5000) as in Beta.

The blue line represents the model for linear temperature decrease p=p0*(1-0.006*h/T0)^7.2

p0=100 kPa and T0=288 K were measured in game at KSC.

http://i.imgur.com/OQPgIbY.png

http://i.imgur.com/28SMxeJ.png

Very very useful.

+Rep.

Link to comment
Share on other sites

Given that we've tracked this down to it being defined in game as a Unity AnimationCurve, could anyone dig up the raw curves points/tangents for kerbin from the game's data? I wasn't able to find it in a quick look through the configs. Where are the bodies defined? Is that outside of config files? If so, would anyone be up for pulling that data out through a c# plugin?

Link to comment
Share on other sites

It's an 80% Earth atmosphere (as boiled down into a floatcurve). See this thread.

Note that pressure is invariant, but density (which depends on both pressure and temperature) will vary based on latitude and time of day.

By 80% I mean "pressure at 8km on Kerbin is the same as at 10km on Earth".

Here's a calculator: http://www.digitaldutch.com/atmoscalc/

Link to comment
Share on other sites

This is enlightening. Pressure drops below 10% of SLP at around 13km and 1% at around 25km! My ascents are waaaay too steep.

Hence the fondness for ultra-flat ascents amongst the spaceplane crew. Once you crack 20,000m, you're virtually in space: time to light the nukes and cruise to circularisation.

Link to comment
Share on other sites

You can still get lots of friction above 20km, however you need to go really fast to be slowed down noticeably. Most engines won't accelerate you fast enough to break something like 800 m/s at 40km height, but if you for example put the Twin-Boar under some light load at full thrust, it can even cause your equipment to melt on the way up.

I personally found it easiest to ascend with ~200-300 m/s velocity, flat enough that when the fuel runs out I just hit about 75km maximum height, so I can switch to a vacuum engine shortly before AP.

Link to comment
Share on other sites

I find that 300-400m/s vertical velocity is a happy medium for ascents to space, reducing throttle to reduce gravity losses, until pitched to 15° at which point 100% throttle is restored.

Link to comment
Share on other sites

I usually consider the atmospheric drag to be noticeable until 35km, after that it's like you're in space already. But reading these statements on ascending angles, I should probably limit the thrust on my rocket to prevent them from going 800m/s at 30km :D

Link to comment
Share on other sites

Its a little more complicated now. OhioBob has also fit some exponential equations to the floatcurves NathanKell mentioned over here.

The equations I provide in the post referenced above estimate temperature and pressure pretty well. Another way to calculate it is to use the equations of the U.S. Standard Atmosphere (USSA), given below:

[TABLE=class: grid, width: 750]

[TR]

[TD=bgcolor: transparent, colspan: 3]

U.S. Standard Atmosphere, 0 to 86 km

[/TD]

[/TR]

[TR]

[TD=bgcolor: transparent]

Geopotential

Altitude, h

(km')

[/TD]

[TD=bgcolor: transparent]

Molecular-Scale

Temperature, TM

(K)

[/TD]

[TD=bgcolor: transparent]

Pressure, P

(Pa)

[/TD]

[/TR]

[TR]

[TD=bgcolor: transparent]

0-11

[/TD]

[TD=bgcolor: transparent]

288.15 – 6.5 × h

[/TD]

[TD=bgcolor: transparent]

101325.0 × [288.15 / (288.15 – 6.5 × h)] (34.1632 / –6.5)

[/TD]

[/TR]

[TR]

[TD=bgcolor: transparent]

11-20

[/TD]

[TD=bgcolor: transparent]

216.65

[/TD]

[TD=bgcolor: transparent]

22632.06 × EXP[–34.1632 × (h – 11) / 216.65]

[/TD]

[/TR]

[TR]

[TD=bgcolor: transparent]

20-32

[/TD]

[TD=bgcolor: transparent]

196.65 + h

[/TD]

[TD=bgcolor: transparent]

5474.889 × [216.65 / (216.65 + (h – 20))] (34.1632)

[/TD]

[/TR]

[TR]

[TD=bgcolor: transparent]

32-47

[/TD]

[TD=bgcolor: transparent]

139.05 + 2.8 × h

[/TD]

[TD=bgcolor: transparent]

868.0187 × [228.65 / (228.65 + 2.8 × (h – 32))] (34.1632 / 2.8)

[/TD]

[/TR]

[TR]

[TD=bgcolor: transparent]

47-51

[/TD]

[TD=bgcolor: transparent]

270.65

[/TD]

[TD=bgcolor: transparent]

110.9063 × EXP[–34.1632 × (h – 47) / 270.65]

[/TD]

[/TR]

[TR]

[TD=bgcolor: transparent]

51-71

[/TD]

[TD=bgcolor: transparent]

413.45 – 2.8 × h

[/TD]

[TD=bgcolor: transparent]

66.93887 × [270.65 / (270.65 – 2.8 × (h – 51))] (34.1632 / –2.8)

[/TD]

[/TR]

[TR]

[TD=bgcolor: transparent]

71-84.852

[/TD]

[TD=bgcolor: transparent]

356.65 – 2.0 × h

[/TD]

[TD=bgcolor: transparent]

3.956420 × [214.65 / (214.65 – 2 × (h – 71))] (34.1632 / –2)

[/TD]

[/TR]

[TR]

[TD=bgcolor: transparent, colspan: 3]

Density, ÃÂ (kg/m3) = P/(RTM)

Speed of sound, C (m/s) = (γRTM)1/2

Specific gas constant, R = 287.053 J/kg-K

Specific heat ratio, γ = 1.400

[/TD]

[/TR]

[/TABLE]

As has been explained, Kerbin's atmosphere is based on the USSA with the vertical height scale reduced 20%. In addition, the USSA uses geopotential height, h, rather than geometric height, z. Therefore, two conversions must be made. First, the geometric height used in KSP has to be multiplied by 1.25 to undo the 20% reduction, and then the result must be converted to geopotential height. This can be done in a single step using the following equation:

h = 7963.75*z / (6371 + 1.25*z)

Once h is calculated, the temperature, pressure, density, and speed of sound can be obtained using the equations in the table above.

The above method isn't exact but it will get you pretty close. The temperature equations are right on the money, but this is "base" temperature. The actual ambient air temperature at any location on Kerbin varies based on latitude and time of day. The pressure equations are very accurate at low altitudes, however some error starts to appear at higher altitudes. This is because the floatCurves used in KSP are only an approximation of the USSA. Furthermore, above z = 63.2 km (h = 78 km) the pressure equation breaks down because Kerbin's atmospheric pressure is forced to converge to zero at z = 70 km.

If you find the equations in the post reference by Cybersol easier to use, then use those. I post the above mainly so you can see the origin of the numbers used in KSP.

Edited by OhioBob
Link to comment
Share on other sites

Thanks guys (especially NathanKell, cybersol, and OhioBob)!

I was looking for a way to be very accurate for flight simulation purposes. Since KSP 1.0 does not have a single simple formula for pressure, accurate numbers either need to come from field work or table of real world measurements. Again, following the what-would-Jeb-do philosophy, I've built a table for every 100 meters of Kerbin's atmosphere by recording the values of several points within a few meters of each 100 meter mark, then linearly interpolating the measurements to the now bracketed 100 meter marks.

This should be the most precise table around. Here's the full data:

https://gist.github.com/DanielVF/1d6fcb9d7db7a36100a5

And here's the cheatsheet version:

0, 101.3250

5000, 45.6245

10000, 17.9329

15000, 6.7222

20000, 2.5461

25000, 0.989

30000, 0.4013

35000, 0.1745

40000, 0.079

45000, 0.0361

50000, 0.0156

55000, 0.0063

Edited by acalculus
Link to comment
Share on other sites

Be aware, though, as I did a kOS measurement myself before, that the measurement is not precise - I've seen non-monotonic data. So even the barometer readout can't be totally trusted - you need to treat as a real-life experiment.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...