This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathodes.py
91 lines (73 loc) · 2.95 KB
/
odes.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import numpy as np
from base_classes import ThermalArchitecture, EnvironmentalConditions
from heat_transfer import (
incident_radiation_flux,
background_radiation_flux,
conduction_flux,
)
def thermal_ode(
t: float,
y: np.ndarray,
spacecraft: ThermalArchitecture,
environment: EnvironmentalConditions,
) -> np.ndarray:
"""
Computes heat transfer between components of the spacecraft and the environment
Parameters
----------
t: float
time (s)
y: np.ndarray
state vector, temperatures of the components in K
spacecraft: ThermalArchitecture
spacecraft thermal architecture
environment: EnvironmentalConditions
environmental conditions surrounding the spacecraft
Returns
-------
np.ndarray
derivative of the state vector, temperatures of the components in K/s
Math
----
dT/dt = (Q_in - Q_out) / (thermal inertia)
"""
num_components = len(spacecraft.components)
# Update temperatures
spacecraft.update_from_state(y[0:num_components])
# Get temperatures from spacecraft
temps = spacecraft.to_state()
assert np.allclose(temps, y[0:num_components])
fluxes = np.zeros_like(temps)
yp = np.zeros_like(y)
for i, component in enumerate(spacecraft.components):
# 1A. Innate power
fluxes[i] += component.innate_power
yp[num_components] += component.innate_power # recording
# 1B. Heaters
if component.temp < component.heater.set_temp:
fluxes[i] += component.heater.power
yp[num_components + 1] += component.heater.power # recording
# 1C. Electronics
fluxes[i] += component.electronics_power(t)
yp[num_components] += component.electronics_power(t) # recording
# 2A. Radiation flux
incident_flux = incident_radiation_flux(t, component, environment)
background_flux = background_radiation_flux(component, environment)
yp[num_components + 2] += incident_flux # recording
yp[num_components + 3] += background_flux # recording
fluxes[i] += incident_flux + background_flux
# 3. Conduction flux & pump flux
for j, other_component in enumerate(spacecraft.components):
fluxes[i] += conduction_flux(
other_component, component, spacecraft.conductivity_matrix[i][j]
)
# if component i has a heat pump to component j, we need to add the heat pump power
# to j, and subtract it from i
pump_flux = spacecraft.heat_pump_matrix[i][j].get_power(temps[i])
fluxes[i] -= pump_flux
fluxes[j] += pump_flux
yp[num_components + 1] += pump_flux # recording
# Divide fluxes by component inertia
yp[0:num_components] = fluxes / spacecraft.component_thermal_inertias
# power draw included in yp
return yp