-
Notifications
You must be signed in to change notification settings - Fork 0
/
gravity.py
71 lines (52 loc) · 1.86 KB
/
gravity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
import numpy as np
from scipy.interpolate import UnivariateSpline
from dataHandling.modelS import loadModelS
import constants as c
def volumeOfSphericalLayer(
topRadius: float | np.ndarray, width: float | np.ndarray
) -> float | np.ndarray:
"""
volume of a spherical layer which's (??english?) top boundary has radius r and the top boundary has radius r+width
"""
return (
4
/ 3
* np.pi
* (
topRadius * topRadius * topRadius
- (topRadius - width) * (topRadius - width) * (topRadius - width)
)
)
modelS = loadModelS()
modelSZs = modelS.zs
modelRhosBottomUp = modelS.derivedQuantities["rhos"][::-1]
del modelS
centerOfTheSun = modelSZs[-1]
modelRsBottomUp = (centerOfTheSun - modelSZs)[::-1]
widthsOfLayers = np.diff(modelRsBottomUp, prepend=0)
volumesOfLayers = volumeOfSphericalLayer(modelRsBottomUp, widthsOfLayers)
massesOfLayers = volumesOfLayers * modelRhosBottomUp
massesBelowR = np.cumsum(massesOfLayers)
mBelowZSpline = UnivariateSpline(modelSZs, massesBelowR[::-1], s=0, k=1, ext=3)
def massBelowZ(z: float | np.ndarray) -> np.ndarray:
"""
Sun's mass z meters below the surface
"""
return np.array(mBelowZSpline(z))
gravitationalAccelerations = c.G * massesBelowR[1:] / (modelRsBottomUp[1:] * modelRsBottomUp[1:])
gravitationalAccelerationsInZs = gravitationalAccelerations[::-1]
gSpline = UnivariateSpline(modelSZs[:-1], gravitationalAccelerationsInZs, s=0, k=1, ext=3)
def g(z: float | np.ndarray) -> np.ndarray:
"""
gravitational acceleration in m/s^2 z meters below the surface
uses the model S
"""
return np.array(gSpline(z))
def main():
"""debug function for the gravity code"""
import matplotlib.pyplot as plt
plt.plot(modelSZs[:-1], gravitationalAccelerations)
plt.show()
if __name__ == "__main__":
main()