Wednesday, July 7, 2021

Python Library for Calculation of Balloon Properties

I have now put up a python library with numerical implementations of the fundamental relationships for pressure, volume, mass, etc. of a gravity balloon.

https://github.com/AlanCoding/gravitational-balloon-mathematics

The old work on this blog was done largely in an Excel spreadsheet with macros. In terms of the library of methods, I feel that the python version is now better and more correct. Some library methods haven't yet been converted, but the important ones will, and that should go quite fast.

Doing this allows me to put work in Juypter notebooks, which is much better for sharing my work down to the numerical implementation. For a demo, I have re-done the graphs for the PR and PV curve.


These are showing the same thing as the prior post did:

https://gravitationalballoon.blogspot.com/2013/03/gravity-balloon-pressure-volume-curve.html

That had some errors in it, and I'm now confident those are corrected.

The python library is much much easier to understand and modify, and any further improvements will become considerably faster.

Friday, July 2, 2021

A More Detailed Run-through of the Pressure-Volume Relationship

I've enabled MathJax on this blog and started repairing numerous equations, after a few years of the equations not rendering. Some parts have still not been recovered, but I've also realized that some parts are unclear.

So there will be value in running through the basic equations of the gravity balloon with fresh eyes.

Objective

The equations here will relate multiple quantities. At different times we are interested in different quantities. The most common is to seek pressure (P) and volume (V), given values for all the others. Given that a gravity balloon is to be built out of some asteroid, then available mass and density of rock is fixed.

Mass

We will temporarily introduce variables for dimensions. The big R is used for the radius of the inner volume of air - the inner surface of the rock. The little t is used for the thickness of the rock. Thus, the outer surface of the inflated gravity balloon would be (R+t). Less commonly, the original radius of the asteroid (assuming spherical) will be denoted $R_0$. Using those, we will use the general formula for volume of a sphere both before turning into a gravity balloon and after.

$$ M = \rho V = \rho \frac{4}{3} \pi R_0^3 = \rho \frac{4}{3} \pi \left( (R + t)^3 - R^3 \right) $$

Gravitational Field

Consider any homogeneous spherical planet, we have a simple $1/r^2$ formula for gravity on the surface. I'm keeping M, the mass of the planet, in there as an independent variable of the function, as this will be important.

Spherical Planet Field Surface and Beyond

$$ g_{space}(r, M) = G M \frac{1}{r^2} $$

As you consider the interior, Gauss' law dictates that we can use that same formula, if we include all the mass below the radius of consideration.

Spherical Planet Field Interior, not for Gravity Balloon

$$ g_{interior}(r) = G M_{inside} \frac{1}{r^2} = G \rho \frac{4}{3} \pi r^3 \frac{1}{r^2} = G \rho \pi \frac{4}{3} r $$

These are universal expressions for field inside and outside a solid sphere. I don't want to make them out to be anymore than that, because the important thing is how they get reused in for the gravity balloon.

Gravity Balloon Gravitational Field

The gravity balloon has 3 distinct regions:

  • livable air on the inside
  • rock walls
  • space outside

I will write the gravitational field for the gravity balloon as a piecewise function covering all 3 regions here.

$$ g_{gb}(r) = \begin{cases} 0 & r > R \\ g_{rock}(r) & R < r < R + t \\ G M \frac{1}{r^2} & r > R + t \\ \end{cases} $$

As you can imagine, the hard part is that $g_{rock}(r)$, and that is what the rest of the work here is for. The right way is to use $g_{interior}(r)$ to find the field contributions from the rock, but this isn't valid by itself. Instead, we pretend that this is a solid planet of radius $(R+t)$, and write $g_{interior}(r)$ for that, but then subtract the field you would get from the air volume if it were made of rock. This subtraction ("superposition" if you will) is valid for Newtonian field calculations.

$$ g_{rock}(r) = g_{interior}(r) - g_{space}(r, M_{\text{air as rock}}) \\ = g_{interior}(r) - g_{space}(r, \rho \pi \frac{4}{3} R^3) $$

(ASIDE: this is the critical step, and it is easy to get it wrong. I have gotten it wrong before, that, and lack of clarity in prior posts, is why I revive this now. Although I did eventually correct my actual numbers, I also had a habit of skipping a ton of steps, so I'm publicly taking it slowly here.)

With pretty good confidence in this established, let's expand it because it will be integrated.

$$ g_{rock}(r) = G \rho \pi \frac{4}{3} r  - G \rho \pi \frac{4}{3} R^3 \frac{1}{r^2}  = G \rho \pi \frac{4}{3} \left( r  - \frac{R^3}{r^2} \right) $$

This wraps up the gravitational field. The field is fully described by the expressions for $g_{gb}$ with the supporting $g_{rock}$. There are other tangents I can go on, like contributions from the gravity of the air itself, but this should not be interesting until numerical solutions come into play. I have little very interest in air gravitational contributions as a calculus problem.

Pressure

To get air pressure we integrate the gravitational field, and then multiply by density. This is justified by our intuition that pressure is $\rho g h$, which is (density)x(gravity)x(height). This is the integral form, specific to the gravity balloon.

$$ P = \rho \int_R^{R+t} g_{rock}(r) dr  = G \rho^2 \pi \frac{4}{3} \int_R^{R+t} \left( r  - \frac{R^3}{r^2} \right) dr $$

Now we perform the integral.

$$ P = G \rho^2 \pi \frac{4}{3} \left( \frac{1}{2} r^2 + \frac{R^3}{r} \right) \Big|_R^{R+t} \\ = G \rho^2 \pi \frac{4}{3} \left( \frac{1}{2} (R + t)^2 + \frac{R^3}{(R+t)} - \left( \frac{1}{2} R^2 + \frac{R^3}{R} \right) \right) $$

I feel like it is important to write everything out here so that people can follow. That will simplify a great deal, which I do here.

$$ P = G \rho^2 \pi \frac{4}{3} \left( \frac{1}{2} (R + t)^2 + \frac{R^3}{R+t} -  \frac{3}{2} R^2 \right) $$

Prepare to combine the fraction.

$$ P = G \rho^2 \pi \frac{4}{3} \left( \frac{(R + t)^3}{2 (R+t)}  + \frac{2 R^3}{2 (R+t)} -  \frac{3 R^2 (R + t)}{2 (R+t)} \right) \\ = G \rho^2 \pi \frac{4}{3} \left( \frac{(R + t)^3 + 2 R^3 - 3 R^3 - 3 R^2 t}{2 (R+t)}  \right) $$

The cubic expands into a lot of terms, but the $R^3$ power from it cancels out with other terms.

$$ P = G \rho^2 \pi \frac{4}{3} \left( \frac{ t ( 3 R^2 + t (3 R + t) ) - 3 R^2 t}{2 (R+t)}  \right) \\ = G \rho^2 \pi \frac{4}{3} \left( t \frac{  3 R^2 + t (3 R + t) - 3 R^2 }{2 (R+t)}  \right) \\ = G \rho^2 \pi \frac{2}{3} \left( t^2 \frac{ 3 R + t }{R+t}  \right) $$ 

Years ago, I know that I did this many times on paper. Now, I realize that I just don't want any of it to get lost. The pressure equation is slightly non-trivial, but it's still within the realm of basic college physics / calculus.

How you use the equations is the one other slightly non-trivial part.

Usage

The equations above should be thought about in terms of their independent variables. We have functions to give one variable in terms of other.

$$ P(R, t) \\ M(R, t) $$

Usually, we prefer to put things in terms of volume, and this can be swapped one-for-one with R in the relationships above, because the relationship between M and R is trivial and only involves those 2.

$$ V = \frac{4}{3} \pi R^3 $$

This can be done as a preprocessing step in a method numerically. So we can always freely swap V and R as independent variables. I have more commonly written:

$$ P(V, t) \\ M(V, t) $$

Referring back to their definitions, neither of these methods are trivial to invert symbolically, as they carry cubic terms. It can be done, but it's not the best for technical communication.

At this point, I stop with math.

We have 2 equations and 4 variables. That means that, somehow, a user has to specify 2 variables, and the other 2 can be calculated. The system is fully defined for any correctly-phrased question. In my younger days, I was inclined to go further into problem solving through math. Now, I am more than happy to let code solve the rest. The only challenge I have not addressed is selecting workable initial values.

 I have posted one demo method here:

https://github.com/AlanCoding/gravitational-balloon-mathematics/blob/master/gb/inflation.py

This is the rebooted form. I used Excel Visual Basic macros before. I have successfully converted those to python, which I will use to bootstrap some initial testing.