-
Notifications
You must be signed in to change notification settings - Fork 40
/
kettle.py
69 lines (55 loc) · 2.25 KB
/
kettle.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
import math
class Kettle(object):
"""A simulated brewing kettle.
Args:
diameter (float): Kettle diameter in centimeters.
volume (float): Content volume in liters.
temp (float): Initial content temperature in degree celsius.
density (float): Content density.
"""
# specific heat capacity of water: c = 4.182 kJ / kg * K
SPECIFIC_HEAT_CAP_WATER = 4.182
# thermal conductivity of steel: lambda = 15 W / m * K
THERMAL_CONDUCTIVITY_STEEL = 15
def __init__(self, diameter, volume, temp, density=1):
self._mass = volume * density
self._temp = temp
radius = diameter / 2
# height in cm
height = (volume * 1000) / (math.pi * math.pow(radius, 2))
# surface in m^2
self._surface = (2 * math.pi * math.pow(radius, 2) + 2 * math.pi * radius * height) / 10000
@property
def temperature(self):
"""Get the content's temperature"""
return self._temp
def heat(self, power, duration, efficiency=0.98):
"""Heat the kettle's content.
Args:
power (float): The power in kW.
duration (float): The duration in seconds.
efficiency (float): The efficiency as number between 0 and 1.
"""
self._temp += self._get_deltaT(power * efficiency, duration)
return self._temp
def cool(self, duration, ambient_temp, heat_loss_factor=1):
"""Make the content loose heat.
Args:
duration (float): The duration in seconds.
ambient_temp (float): The ambient temperature in degree celsius.
heat_loss_factor (float): Increase or decrease the heat loss by a
specified factor.
"""
# Q = k_w * A * (T_kettle - T_ambient)
# P = Q / t
power = ((Kettle.THERMAL_CONDUCTIVITY_STEEL * self._surface
* (self._temp - ambient_temp)) / duration)
# W to kW
power /= 1000
self._temp -= self._get_deltaT(power, duration) * heat_loss_factor
return self._temp
def _get_deltaT(self, power, duration):
# P = Q / t
# Q = c * m * delta T
# => delta(T) = (P * t) / (c * m)
return ((power * duration) / (Kettle.SPECIFIC_HEAT_CAP_WATER * self._mass))