1
0
Fork 0
mirror of https://github.com/Findus23/collision-analyisis-and-interpolation.git synced 2024-09-19 15:13:50 +02:00

improve cli.py (old code)

This commit is contained in:
Lukas Winkler 2020-11-30 11:52:12 +01:00
parent 5ba154f4f8
commit 5b09fdae46
Signed by: lukas
GPG key ID: 54DE4D798D244853

19
cli.py
View file

@ -9,6 +9,7 @@ from simulation_list import SimulationList
def clamp(n, smallest, largest):
assert smallest < largest
return max(smallest, min(n, largest))
@ -29,8 +30,8 @@ with open(sys.argv[1]) as f:
argalpha, argvelocity, argmp, argmt = map(float, entries)
solar_mass = 1.98847542e+30 # kg
ice_density = 0.917 / 1000 * 100 ** 3
basalt_density = 2.7 / 1000 * 100 ** 3
ice_density = 0.917 / 1000 * 100 ** 3 # kg/m^3
basalt_density = 2.7 / 1000 * 100 ** 3 # kg/m^3
water_fraction = 0.15
alpha = argalpha
@ -56,12 +57,10 @@ def total_radius(total_mass, water_fraction, density, inner_radius):
target_core_radius = core_radius(target_mass, target_water_fraction, basalt_density)
target_radius = total_radius(target_mass, target_water_fraction, ice_density, target_core_radius)
projectile_core_radius = core_radius(projectile_mass, projectile_water_fraction, basalt_density)
projectile_radius = total_radius(projectile_mass, projectile_water_fraction, ice_density, projectile_core_radius)
escape_velocity = sqrt(2 * G * (target_mass + projectile_mass) / (target_radius + projectile_radius))
velocity_original = argvelocity
const = 365.256 / (2 * pi) # ~58.13
@ -76,10 +75,12 @@ if gamma > 1:
gamma = 1 / gamma
alpha = clamp(alpha, 0, 60)
velocity = clamp(velocity, 1, 5)
m_ceres = 9.393e+20
m_earth = 5.9722e+24
projectile_mass = clamp(projectile_mass, 2 * m_ceres, 2 * m_earth)
gamma = clamp(gamma, 1, 1 / 10)
gamma = clamp(gamma, 1 / 10, 1)
simulations = SimulationList.jsonlines_load()
scaler = CustomScaler()
@ -91,9 +92,17 @@ mass_interpolator = RbfInterpolator(scaled_data, simulations.Y_mass)
testinput = [alpha, velocity, projectile_mass, gamma,
target_water_fraction, projectile_water_fraction]
with open("xl3", "w") as f:
f.write("# alpha velocity projectile_mass gamma target_water_fraction projectile_water_fraction\n")
f.write(" ".join(map(str, testinput)))
scaled_input = list(scaler.transform_parameters(testinput))
water_retention = water_interpolator.interpolate(*scaled_input)
mass_retention = mass_interpolator.interpolate(*scaled_input)
water_retention = clamp(water_retention, 0, 1)
mass_retention = clamp(mass_retention, 0, 1)
print(water_retention)
print(mass_retention)