# Atmospheric Model

The basis of our simulation is a model of Earth's atmosphere, of which there are several.  The [International Standard Atmosphere](https://en.wikipedia.org/wiki/International_Standard_Atmosphere) (ISA) is used by ICAO, is relatively simple, and accurate enough for our purposes.

The ISA is a mathematical model of the atmosphere that assumes a linear temperature gradient against altitude, and derives pressure and density from the [ideal gas law](https://en.wikipedia.org/wiki/Ideal_gas_law) and [hydrostatic equilibrium](https://en.wikipedia.org/wiki/Hydrostatic_equilibrium).

## Symbols used

Since the primary source upon which the models in this package are built from is the ISA, I will use the symbols defined in the paper that defined it.


```python
from preamble import *
symbol_table
## WIP
```




<table><tr><th>Symbol</th><th>Description</th></tr><tr><td>$A$</td><td>Area</td></tr><tr><td>$F$</td><td>Force</td></tr><tr><td>$g$</td><td>Acceleration due to gravity</td></tr><tr><td>$H$</td><td>Geopotential height</td></tr><tr><td>$h$</td><td>Geometric height</td></tr><tr><td>$P$</td><td>Pressure</td></tr><tr><td>$P_{b}$</td><td>Pressure at the base of an atmospheric layer</td></tr><tr><td>$M$</td><td>Molecular mass</td></tr><tr><td>$m$</td><td>Mass</td></tr><tr><td>$n$</td><td>Amount of substance</td></tr><tr><td>$R^{*}$</td><td>Universal gas constant</td></tr><tr><td>$R$</td><td>Specific gas constant</td></tr><tr><td>$T$</td><td>Thermodynamic temperature</td></tr><tr><td>$V$</td><td>Volume</td></tr><tr><td>$\rho$</td><td>Density</td></tr>



## Hydrostatic equation

Our model begins by noting that since the atmosphere is not floating away into space, nor sinking to the ground, it must be at equilibrium: all vertical forces must sum to zero. That is to say, it is at [hydrostatic equilibrium](https://en.wikipedia.org/wiki/Hydrostatic_equilibrium). For a column of air in the atmosphere, the 3 forces we'll model are from the surrounding air pressure - air pushing up from below, air pushing down from above - and the weight of the column of air itself:

$$
\require{action}
\texttip{math}{tip}
$$

$$
F_{below} + F_{above} + F_{weight} = 0
$$

Replacing with the definitions of pressure and weight gives us (For reasons that will become apparent, we will refer to the pressure at the base of the cylinder as $P_b$ and the pressure at the top simply as $P$):


```python
Eq((A*P_b) - (A*P) - (m*g), 0)
```




$\displaystyle - A P + A P_{b} - g m = 0$




```python
# The mass of a column of air is its volume multiplied by its density:
# m = V * rho
_.replace(m, V*rho)
```




$\displaystyle - A P + A P_{b} - V g \rho = 0$




```python
# The volume is its area multiplied by its height.
_.replace(V, A * h)
```




$\displaystyle - A P + A P_{b} - A g h \rho = 0$




```python
# We can simplify by removing the area:
_ / A
```




$\displaystyle P - P_{b} + g h \rho = 0$




```python
_.replace(P-P_b, diff(P))
```




$\displaystyle P - P_{b} + g h \rho = 0$




```python
_.solve(P)
```




$\displaystyle P = P_{b} - g h \rho$



### Ideal Gas Law

The first useful equation for us is the [ideal gas law](https://en.wikipedia.org/wiki/Ideal_gas_law), which relates the pressure and volume of an ideal gas to it's temperature. In short: as the temperature of a gas increases, it's pressure and/or volume must also increase.  It is commonly stated as $PV = nR^*T$, but since it can be hard to count the number of molecules in some volume of gas, it is useful to transform into the molar form through some simple substitutions. The molar form is convenient in atmoshpheric science as we can more easily measure air pressure, temperature, and density.


```python
# pV = nRT
ideal_gas_law = Eq(P * V, n * R_universal * T)
ideal_gas_law
```




$\displaystyle P V = R^{*} T n$




```python
# The amount of substance in a thing is equivalent to its mass / molecular mass:
# n = m / M
ideal_gas_law.subs(n, m / M)
```




$\displaystyle P V = \frac{R^{*} T m}{M}$




```python
# Density is defined as mass / volume:
# rho = m / V
_.solve(P).subs(m/V, rho)
```




$\displaystyle P = \frac{R^{*} T \rho}{M}$




```python
# Finally, the specific gas constant of a gas is defined as the universal gas constant / molecular mass:
# R_sp = R / M
molar_gas_law = _.subs(R_universal/M, R)
molar_gas_law
```




$\displaystyle P = R T \rho$



## Burst Altitude

The maximum diameter of a given balloon is given by its manufacturer.  If we know the volume of gas that we've put into the balloon, we can use the ideal gas law to determine the pressure at which the balloon will burst.




```python
r = symbols('r')

volume_of_sphere = Eq(V, Rational(4,3)*pi*r**3)
volume_of_sphere

foo = ideal_gas_law.subs(volume_of_sphere.lhs, volume_of_sphere.rhs)
display(foo)

solved = next(iter(solveset(foo, P)))

from sympy.printing.pycode import pycode

display(solved)
pycode(solved)
```


$\displaystyle \frac{4 \pi P r^{3}}{3} = R^{*} T n$



$\displaystyle \frac{3 R^{*} T n}{4 \pi r^{3}}$





    '(3/4)*R^**T*n/(math.pi*r**3)'




```python
from sympy import *

F_b, m, g = symbols('F_b m g')
rho, V, r = symbols('rho V r')
rho_air, rho_gas = symbols('rho_air rho_gas')

bouyancy = Eq(F_b, m*g)
bouyancy = bouyancy.subs({
    m: rho*V,
    rho: (rho_gas - rho_air),
    V: (Rational(4,3)*pi*r**3)
})

bouyancy
```




$\displaystyle F_{b} = V g \left(- \rho_{air} + \rho_{gas}\right)$



## References

* [Here](https://atoc.colorado.edu/~cassano/atoc5050/Lecture_Notes/wh_ch3_part1.pdf)
* [ICAO Standard Atmosphere](http://www.aviationchief.com/uploads/9/2/0/9/92098238/icao_doc_7488_-_manual_of_icao_standard_atmosphere_-_3rd_edition_-_1994.pdf)
* [ISO 2533-1975: Standard Atmosphere](https://cdn.standards.iteh.ai/samples/7472/c203e9121d4c40e5bdc98844b1a1e2f4/ISO-2533-1975.pdf)
* [Inspiration](https://github.com/cuspaceflight/cusf-burst-calc/blob/master/js/calc.js)
* [And](https://northstar-www.dartmouth.edu/~klynch/pmwiki-gc/uploads/BalloonCalulations.pdf)
* [And](https://amt.copernicus.org/articles/4/2235/2011/amt-4-2235-2011.pdf)



```python

```

2051cdd4410aec37946a14eb268e32faaa95451b
ipynb
Jupyter Notebook
docs/_sources/atmosphere.ipynb
sea7aero/pyhab
36d7eb4bef4403bb4b9ec3503f63a666dca42550
MIT
docs/_sources/atmosphere.ipynb
sea7aero/pyhab
36d7eb4bef4403bb4b9ec3503f63a666dca42550
MIT
docs/_sources/atmosphere.ipynb
sea7aero/pyhab
36d7eb4bef4403bb4b9ec3503f63a666dca42550
MIT
Qwen/Qwen-72B
1. YES
2. YES