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 pathbase_classes.py
136 lines (102 loc) · 3.99 KB
/
base_classes.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from dataclasses import dataclass
import numpy.typing as npt
import numpy as np
@dataclass
class ThermalLink:
conductance: float
def get_conductance(self, self_temp, other_temp):
"""
Gets conductance as a result of self temperature and other temperature
"""
return self.conductance
@dataclass
class ThermalSwitch(ThermalLink):
cool_limit: float
heat_limit: float
attenuation_factor: float
def get_conductance(self, self_temp, other_temp):
"""
Gets conductance as a result of self temperature and other temperature
Shuts off thermal link (decreasing its conductance) when it's either too
hot or too cold
"""
if other_temp > self_temp and self_temp > self.heat_limit:
return self.conductance / self.attenuation_factor
elif other_temp < self_temp and self_temp < self.cool_limit:
return self.conductance / self.attenuation_factor
else:
return self.conductance
@dataclass
class HeatPump:
"""
A heat pump is a device that moves heat from one place to another
Generic base class, pumps zero heat
"""
electrical_power: float # W
cop: float # coefficient of performance
set_temp: float # K, heat pump turns off above this temperature
def get_power(self, self_temp: float) -> float:
return 0
@dataclass
class Refrigerator(HeatPump):
"""
Subclass of heat pump that pumps heat from a cold place to a hot place
"""
def get_power(self, self_temp: float) -> float:
"""
Gets power as a result of self temperature and other temperature
Continually pumps heat as long as it's not too cold
"""
if self_temp > self.set_temp:
# thermal power = electrical power * cop
return self.electrical_power * self.cop
else:
return 0
@dataclass
class Heater:
power: float # W
set_temp: float # K, heater turns off above this temperature
@dataclass
class ThermalComponent:
mass: float # mass [kg]
shc: float # specific heat capacity [J/(kg*K)]
rad_area: float # radiative area [m^2]
emissivity: float # 0 to 1, emissivity
temp: float # temperature [K]
illumination_factor: float # 0 to 1; how much of the radiative area is lit by the Sun?
innate_power: float # intrinsic power generation factor, either from heaters or otherwise (W)
heater: Heater # electric heater used to keep the device warm
@property
def thermal_inertia(self) -> float:
return self.mass * self.shc
# power produced by electronics during operations
def electronics_power(self, t: float) -> float:
return 0
@dataclass
class ThermalArchitecture:
components: list[ThermalComponent]
conductivity_matrix: list[list[ThermalLink]]
heat_pump_matrix: list[list[HeatPump]]
def to_state(self) -> npt.NDArray[np.floating]:
# Turns the spacecraft thermal architecture into a state form
# (just the temperatures)
return np.array([component.temp for component in self.components])
def update_from_state(self, temps: npt.NDArray[np.floating]):
# Update state to spacecraft properties
for idx, component in enumerate(self.components):
component.temp = temps[idx]
@property
def component_thermal_inertias(self) -> npt.NDArray[np.floating]:
return np.array([component.thermal_inertia for component in self.components])
@dataclass
class EnvironmentalConditions:
name: str
sunlit_radiative_flux: float # W/m^2
background_temp: float # K, usually the temperature of space, 2.7 K
orbital_period: float
sunlit_period: float
def incident_radiative_flux(self, t: float):
if t % self.orbital_period < self.sunlit_period:
return self.sunlit_radiative_flux
else:
return 0