Jump to content

Modeling Atmospheres in KSP


OhioBob

Recommended Posts

8 hours ago, The White Guardian said:

@OhioBob in the spreadsheet AtmoMoldel.xlsx the rows K,L,M and N appear to be empty, no functions have been entered. The rows are named Escape Velocity (m/s), Dynamic Pressure (Pa), n (deg), t (s). Is this supposed to be this way?

Scroll down, there are numbers there later down the page.  Remember, my time from periapsis was computed based on a trajectory with a periapsis altitude of 23,000 meters.  Therefore, at altitudes below 23,000, the formulas for true anomaly and time from periapsis produce errors, so I just left those cells blank.  You'll find formulas in cells K,L,M and N on the lines were the altitude is >23,000.

Link to comment
Share on other sites

17 hours ago, OhioBob said:

Scroll down, there are numbers there later down the page.

Oh, I feel so stupid now XD

Thanks a lot once again!

@OhioBob So in the example calc sheet AtmoModel, in what cells should I input the data of my own planet? Or change part of the function?

You see, I'm going to try to add a little 'input field' to the right in column Q so I can easily view the graph for different planets and make the 'ending an atmosphere' part a lot easier.

In other words: what values (density, pressure, etc) aren't calculated automatically by the spreadsheet? (Like radius, surface gravity, what functions have values like that hidden within them?)

Edited by The White Guardian
Link to comment
Share on other sites

My articles outlines the changes that are required to modify the spreadsheet.  Here it is again for your convenience:

Modifying the Spreadsheet

Should the spreadsheet be modified to compute the atmosphere of a different planet, please note that the following edits are required:

·  Change the radius in the formula in column C.

·  Change the formula in column D to the correct temperatureCurve.

·  Change the formula in column E to the correct temperatureSunMultCurve.

·  Change the diurnal variation in the formula in column F.

·  Change the molar mass in column G.

·  Change the surface gravity in the formula in column H.

·  Change the surface pressure in cell I5.

·  Change the gravitational parameter and radius in the formula in column K.

·  Change the semimajor axis (where a=100000·rp) and radius in the formula in column M.

·  Change the semimajor axis and gravitational parameter in the formula in column N.

Link to comment
Share on other sites

1 hour ago, OhioBob said:

My articles outlines the changes that are required to modify the spreadsheet.  Here it is again for your convenience:

Modifying the Spreadsheet

Should the spreadsheet be modified to compute the atmosphere of a different planet, please note that the following edits are required:

·  Change the radius in the formula in column C.

·  Change the formula in column D to the correct temperatureCurve.

·  Change the formula in column E to the correct temperatureSunMultCurve.

·  Change the diurnal variation in the formula in column F.

·  Change the molar mass in column G.

·  Change the surface gravity in the formula in column H.

·  Change the surface pressure in cell I5.

·  Change the gravitational parameter and radius in the formula in column K.

·  Change the semimajor axis (where a=100000·rp) and radius in the formula in column M.

·  Change the semimajor axis and gravitational parameter in the formula in column N.

How could I possibly have missed this? :o

Thank you!

Link to comment
Share on other sites

@OhioBob I think I got it. Here's how I developed my latest atmosphere model:

Firstly, I used a calculator I made myself to calculate the density and molar mass of an atmosphere with a given composition, this composition being 39% carbon dioxide, 26% nitrogen, 25% hydrogen, 7% sulphur dioxide and 3% chlorine.

This gives the following values:

staticPressureASL = 116.4070708 (or 1.148848466 atm)

staticDensityASL = 1.42344 kg per cubic metre

temperatureSeaLevel = 300 Kelvin (since it's in a close Jool orbit around a white-ish star with a heavy greenhouse gas presence I set the temperature to about 300K)

atmosphereMolarMass = 0.03050108 kg/mol

I then entered these values into the calc sheet AtmoModel, which I modified to be more like an 'ending an atmosphere calculator', along with the values of 420,000 m for the in-game radius, 4,200,000 m for the 'realistic radius', and a gravity of 0.4G. This may change as I might compute the gravity scaled since it's a Marslike world by using Mars' average density. Point is, this resulted in a dynamic pressure of just over 150 Pa at an altitude of 36,400 meters and a time of 102.4 seconds. Using your rule of thumb I terminated the atmosphere at about 40,000 meters, corresponding to a time of 112.3 seconds.

The other curves used in the model, temperatureLatitudeBiasCurve, temperatureLatitudeSunMultCurve, temperatureAxialSunBiasCurve and temperatureEccentricityBiasCurve, were all computed with a calculator I developed, simply enter the desired temperature ranges and the calculator will pretty much plot the curve save for the derivs, which I have to do manually with a handy Unity curve editor tool.

For the eccentricity I simply multiply the eccentricity by 100 for a temperature variation baseline, resulting in a difference of 8.26 Kelvin.

I cannot thank you enough for teaching me all of this. Needless to say I'll soon be revising all of the atmospheres I have made for my planet packs. But creating an atmosphere with an actual composition rather than just guessing values is already a huge improvement for me. :wink:

Link to comment
Share on other sites

@The White Guardian, sounds like you've got it all figured out.  Congrats.  It can seem really confusing and intimidating at the start, but after you learn it, it's not so bad.  I does take time, however.  As many atmospheric models as I've written, I still refer back to this tutorial frequently for quick reference.

I've been thinking about trying to come up with some sort of program to automate the process.  The user would just answer some questions, and the program would develop a model and generate all the curves.  I don't know if I'll ever get around to it, however.  It's not real high on my to do list at the moment.  Developing an atmospheric model is greatly simplified when the temperature profile is broken down into line segments, like this

Spoiler

temperature.jpg

so that's probably the approach I'd take.  When the temperature is a straight line, pressure can be computed using an equation rather than having to use numerical integration.
 

Edited by OhioBob
Link to comment
Share on other sites

13 minutes ago, OhioBob said:

@The White Guardian, sounds like you've got it all figured out.  Congrats.  It can seem really confusing and intimidating at the start, but after you learn it, it's not so bad.  I does take time, however.  As many atmospheric models as I've written, I still refer back to this tutorial frequently for quick reference.

I've been thinking about trying to come up with some sort of program to automate the process.  The user would just answer some questions, and the program would develop a model and generate all the curves.  I don't know if I'll ever get around to it, however.  It's not real high on my to do list at the moment.  Developing an atmospheric model is greatly simplified when the temperature profile is broken down into line segments, like this

  Reveal hidden contents

temperature.jpg

so that's probably the approach I'd take.  When the temperature is a straight line, pressure can be computed using an equation rather than having to use numerical integration.
 

I just use a handy calculator created by @KillAshley that takes surface pressure in atmospheres, max atmosphere altitude and atmosphere temperature and automatically creates correct curves by scaling the stock ones, currently I'm mostly using Kerbin's because it's based off a real-life example. In any case, it works!

There seems to be something off though with the atmosphere I made earlier, it has a surface pressure of just over 1 atmospheres and terminates at 40000m, but has only 0.4G? I think I misread something there, but with another atmosphere I just created I made sure not to make the same mistake.

Glancing at your mod Realistic Atmospheres confirms my suspicion where you terminate Eve's atmosphere at around 50km due to it's crushing gravity, which the moon I mentioned earlier lacks. This planet, on the other hand, has a gravity computed to be relative to that of Kerbin with a little extra added because of the planet consisting of a denser material, giving it a radius of 624856.2 m and 1.17 G's, and an atmosphere termination of 49,600m, scaled to 50000m.

Also, here is an image of the planet I mentioned earlier in-game:

KcbYLeL.png

Since I'm not changing Jool's physical properties with this mod, is it okay if I give it it's atmosphere from your mod Realistic Atmospheres (given proper credit of course)?

Edited by The White Guardian
Link to comment
Share on other sites

 

44 minutes ago, The White Guardian said:

I just use a handy calculator created by @KillAshley that takes surface pressure in atmospheres, max atmosphere altitude and atmosphere temperature and automatically creates correct curves by scaling the stock ones, currently I'm mostly using Kerbin's because it's based off a real-life example. In any case, it works!

I've heard about KillAshley's calculator, but I've never actually seen it or used it.

44 minutes ago, The White Guardian said:

There seems to be something off though with the atmosphere I made earlier, it has a surface pressure of just over 1 atmospheres and terminates at 40000m, but has only 0.4G?

The ending point of an atmosphere can sometimes be higher or lower than you might think.  When the gravity is low, the atmosphere is going to naturally expand.  But with a lower gravity the entry speeds are less, so a craft has to descend into thicker air before the before the dynamic pressure builds up the magical 150 Pa.  Temperature can also make a big difference.  You can have half the gravity, but if you also have half the temperature, the air density is going to be the same.  You just have to work through the process to figure out where the right place to end is.

That being said, the situation you describe does sound like there might be something a bit off there.

44 minutes ago, The White Guardian said:

Glancing at your mod Realistic Atmospheres confirms my suspicion where you terminate Eve's atmosphere at around 50km due to it's crushing gravity ...

For Realistic Atmospheres I actually based Eve's atmosphere on a surface gravity of 1.2g rather than 1.7g.  At 1.7g the atmosphere was compressed into such a thin layer (around 35 km as I recall) that I thought it messed up gameplay too much.  I used 1.2g because I thought that was a more realistic value for a planet Eve's size.  A surface gravity of 1.7g gives Eve a density that seems unrealistically high to me.
 

Edited by OhioBob
Link to comment
Share on other sites

44 minutes ago, The White Guardian said:

Since I'm not changing Jool's physical properties with this mod, is it okay if I give it it's atmosphere from your mod Realistic Atmospheres (given proper credit of course)?

Sure, that would be OK with me.  Just make sure you download version 1.2.3.  Somebody recently discovered that I made a typo in my Jool config, inadvertently giving it a molar mass 10 times greater than it should have been.  The latest release fixes the error.

Link to comment
Share on other sites

2 minutes ago, The White Guardian said:

@OhioBob how does one enter new temperature curves into the AtmoModel calc sheet?

I just use @KillAshley's calculator for the curve shape but that only specifies the temperature for nine points on the curve, so how do I find out the temperature at each given altitude?

You have to convert your temperature curve into formulas that can be entered into Excel.  That's where I use my spreadsheet FloatCurve.xlsx.

The second sheet of that spreadsheet is designed to take a float curve and convert it into polynomial equations.  The grey cells are where you enter the curve data, and the blue cells are the resulting polynomials.  You can then enter the polynomial equations into the AtmoModel spreadsheet to compute temperature from altitude, etc.  The formula used to make the conversion comes from here.

Link to comment
Share on other sites

13 minutes ago, OhioBob said:

You have to convert your temperature curve into formulas that can be entered into Excel.  That's where I use my spreadsheet FloatCurve.xlsx.

The second sheet of that spreadsheet is designed to take a float curve and convert it into polynomial equations.  The grey cells are where you enter the curve data, and the blue cells are the resulting polynomials.  You can then enter the polynomial equations into the AtmoModel spreadsheet to compute temperature from altitude, etc.  The formula used to make the conversion comes from here.

So I go to the 'equations' tab and enter the info into the grey fields, but what I have to do next is unclear to me as the blue tab seems to spew gibberish compared to the example curve info listed in the AtmoModel sheet. Can you elaborate a bit more on that part?

Link to comment
Share on other sites

Each set of numbers in the temperature curve is connected to the next with a "spline".  The first line of blue cells contains the formula for the spline that connects to first two keys of the temperature curve.  t is the input variable and p is the output variable (those variables come from the web page that I linked to, I could have just as easily used x and y).  For a temperature curve, t = altitude, and p = temperature.

Let's say we want to take the first formula in FloatCurve and write a temperature formula in cell D5 of AtmoModel.  This formula would be,

=1.630154549E-11*B5^3-1.805200667E-07*B5^2-1.029338E-02*B5+4.2E+02

where cell B5 contains the altitude.

What complicates things is that each spline of the temperature curve has a different formula.  The first formula (the one we just wrote) is the one that connects the first two keys of the temperature curve; therefore, it is valid only for the range of altitudes from 0 to 15000 meters.  For the next range of altitude, 15000-50000 meters, we need to use the formula contained in the second line of blue cells.

We have to use an IF() statement to define when each formula is used.  If we have only two formulas, then we can amend the formula in cell D5 to read,

=IF(B5<15000,1.630154549E-11*B5^3-1.805200667E-07*B5^2-1.029338E-02*B5+4.2E+02,8.235483382E-13*B5^3-1.307540583E-08*B5^2-4.869071953E-03*B5+3.5319857E+02)

Here the first formula is used when B5<15000, and second is used when B5=>15000.

When we require additional formulas, we have to start nesting multiple IF() statements together.  For example,

=IF(B5<15000,...,IF(B5<50000,...,IF(B5<60000,...,IF(B5<70000,...,...))))

Unfortunately Excel allows no more than seven IF() statements to be nested together.  If we require more than that, then we have to add groups of nested IF() statements together.  For example, the previous statement can also be written as follows:

=IF(B5<15000,...,IF(B5<50000,...,IF(B5<60000,...,0)))+IF(B5<60000,0,IF(B5<70000,...,...))

In this case, if B5<60000, the first group of IF's returns a computed value while the second group returns 0.  But if B5=>60000, the first group of IF's returns 0 while the second group returns a computed value.

Note that the last formula is provided only to show how groups of nested IF() statement can be added together.  It is not necessary to do so in this particular example because we do not exceed the nested IF() limitation.  The limitation of seven IF() statements applies only when they are nested one inside of the other.  I know of no limitation when adding IF() statements together.

There is nothing here that is especially difficult as far as the math is concerned (we're just using simple polynomials), but making sure the formulas are written correctly can be a chore.  The strings can get rather long and confusing.
 

Edited by OhioBob
Link to comment
Share on other sites

3 hours ago, OhioBob said:

-snip-

Bloody hell, and I thought that that spreadsheet was complicated already. Guess I'm going to have to play this numbers game a whole lot longer before I can do this with relative ease. It may not be too hard but it sure is overwhelming at first sight. :confused:

Edited by The White Guardian
Link to comment
Share on other sites

7 minutes ago, The White Guardian said:

It may not be too hard but it sure is overwhelming at first sight. :confused:

I think that's the case for the whole process.  There is nothing about it that is particularly difficult in terms of the mathematics, I mean we're not deriving general relativity here, but there is definitely a lot to learn.  And no matter how well you learn it, it is still a time-consuming process with a lot of steps (that part never gets easier).

Link to comment
Share on other sites

2 hours ago, smokytehbear said:

Is axial tilt still not implemented in KSP? I could have sworn I saw a parameter titled just that while looking through various Kopernicus files. I weirdly can't seem to find it now however, not even for Earth or Uranus in RSS which seems the most obvious choice...

I've heard that axial tilt is coming in a future update, but at present it is still not implemented.  You probably saw a parameter for it in RSS, but it is commented out and not working.  This from the Earth config:

   // does nothing - axialTilt = 23.44

Link to comment
Share on other sites

10 hours ago, The White Guardian said:

It's still a bit unclear to me how I need to compile the results in the blue fields into a formula for Excel to work with, what blue cells do I need to enter and in what order?

Each row of blue cells forms is a single equation.  The values in columns K, M, O and Q are the coefficients for the t3, t2, t1 and t0 terms respectively.  The range over which each equation is valid is given by the values in columns F and H.  So the first equation,

p(t) = 1.630154519E-11 * t3 - 1.805200667E-07 * t2 - 1.029338000E-02 * t + 4.200000000E+2

is valid over the range of t = 0 to 15000.

The variables t and p can mean anything, there are just the input and output variables.  p(t) just means that p is a function of t.  When you have a float curve, each key has four numbers.  The first is the t value, and the second is the p value.  When you have a temperature curve, t is altitude and p is the temperature.

If you are writing a temperature formula to enter into cell D5 of AtmoModel.xlsx, the equation would look like the following.  However, the variables shown in red italics get there values from FloatCurve.xlsx.  Here you wouldn't type the variable name, but rather its numerical value.  For instance, you wouldn't type "H4", you would type the numerical value that is in cell H4 of FloatCurve.xlsx, i.e. 15000.

=IF(B5<H4,K4*B5^3+M4*B5^2+O4*B5+Q4,IF(B5<H5,K5*B5^3+M5*B5^2+O5*B5+Q5,IF(B5<H6,K6*B5^3+M6*B5^2+O6*B5+Q6,IF(B5<H7,K7*B5^3+M7*B5^2+O7*B5+Q7,K8*B5^3+M8*B5^2+O8*B5+Q8)

The above tells you were the numbers come from, but the actual formula that you enter into cell D5 of AtmoModel.xlsx would be:

=IF(B5<15000,1.630154519E-11*B5^3-1.805200667E-07*B5^2-1.029338E-02*B5+4.2E+02,IF(B5<50000,8.235483382E-13*B5^3-1.307540583E-08*B5^2-4.869071953E-03*B5+3.5319857E+02,IF(B5<60000,-2E-11*B5^3+3.3E-06*B5^2-1.8E-01*B5+3.43E+03,IF(B5<70000,6E-11*B5^3-1.17E-05*B5^2+7.56E-01*B5-1.601E+4,-7.7635275E-12*B5^3+2.010611325E-6*B5^2-1.673617313E-01*B5+4.686215628E+03)

Of course the values above are from the sample that comes with FloatCurve.xlsx.  Obviously you'd use that values from your actual temperature curve.  You may also have to increase or decrease the number of IF() statements depending on how many keys are in your temperature curve.
 

Edited by OhioBob
Link to comment
Share on other sites

Alright, thanks. I'll keep working on this, see if I can get it all to work smoothly.

I'm actually thinking about focusing the next Kopernicus tutorial on making better atmospheres for KSP. Stuff like ending an atmosphere realistically may be a bit far for most people considering the sheer amount of effort it takes, but temperatureLatitudeSunBiasCurve, temperatureLatitudeSunMultCurve, temperatureEccentricityBiasCurve, tempetarureAxialSunBiasCurve and temperatureAxialSunMultCurve seem pretty straightforward. I've actually already made a calculator that I'll be providing a link to that will ease the process to simply punching in the numbers and the curve comes rolling out. The derivs aren't automated as I have no idea what formula to use for those, but editing them in Unity is pretty easy and something I can explain clearly enough I believe.

Link to comment
Share on other sites

The curves are pretty straightforward, but I still have a hard time remembering which curve does what.  I frequently have to return to the tutorial for a refresher.  One of my main objectives in writing this tutorial was just to explain what the curves do, which is something that I believe is largely misunderstood. 

I agree that ending the atmosphere is the part I probably overcomplicated.  I just haven't been able to devised any other computational method that I'm happy with.  And even the method I propose is far from perfect.  The most important thing is to just get an atmosphere that feels right when playing the game.

As I mentioned early, the math to compute the pressure curve is simplified quite a bit when the temperature curve is made up of a series of connected line segments rather than a continuous curve.  I'm still strongly considering revising my techniques accordingly to produce something that would be easier for mod developers to understand and use.

Link to comment
Share on other sites

On 2/12/2017 at 8:46 PM, OhioBob said:

I've heard that axial tilt is coming in a future update, but at present it is still not implemented.  You probably saw a parameter for it in RSS, but it is commented out and not working.  This from the Earth config:

   // does nothing - axialTilt = 23.44

Yep that must have been it. Thought I was super clever in coming up with a fix for it, creating a "blank" parent planet with virtually no radius/mass and plopping it at the center, then turning the planet into a moon with an inclined orbit. But even with fuddling with those numbers to make it "revolve" around the imaginary body, I discovered that even at 90 degree inclination the planets are always upright, and if they spin they still spin along the solar plane perfectly, not their orbital plane.

My idea has probably even been tried before, so I'm basically just confirming what everyone pretty much already knew: right now axial tilt isn't possible for anything but the origin planet.

By the way, actually on topic, thank you for the guide, lots of good stuff in here.

Link to comment
Share on other sites

Yep, all the planets in a solar system have their axes pointing in the exact same direction, normal to the reference plane.  RSS was able to produce Earth's axial tilt by inclining it's orbit 23.44 degrees.  That worked for Earth, but all the other planets have their axes pointed the same direction.

I hope that when Squad does implement axial tilt, they do it right.  We just can't just specify the amount of tilt, we have to be able to specific the direction.  One way to do it would be to specific the ecliptic latitude and longitude toward which the north pole points.

Link to comment
Share on other sites

  • 4 weeks later...
19 minutes ago, EricL said:

Wait, how do you calculate the average molar mass?

Take the molar mass of each component of the atmosphere, times its fraction by volume.  There's your average molar mass.

Example:  Suppose you have a mix of 80% N2 (molar mass 28) and 20% O2 (molar mass 32).  (In other words, pretty similar to Earth's atmosphere.)

So, the average molar mass for that mixture would be (0.8 * 28) + (0.2 * 32) = 28.8.

 

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...