Skip to content

Instantly share code, notes, and snippets.

@arcturusannamalai
Created March 15, 2021 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arcturusannamalai/fccb5d6571ea41d33ff6d7a4e35eb2ee to your computer and use it in GitHub Desktop.
Save arcturusannamalai/fccb5d6571ea41d33ff6d7a4e35eb2ee to your computer and use it in GitHub Desktop.
# Thaeneer/டீ/தேநீர்/Chai-making via Microwave assuming a simple 1000W microwave and a 300ml cup
# of dimensions 8.2cm diameter and 12cm height. Specific heat capacities of various
# milk and water are taken from standard tables.
#
# Copyright (C) 2021, Muthiah Annamalai
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
#
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from matplotlib import pyplot as plt
import numpy as np
# units of KJ/Kg * K
SPECIFIC_HEAT_CAPACITY = {
'milk': 3.9300,
'water': 4.1796
}
# in Kelvin
BP = {
'milk':95+273,
'water':100+273
}
DENSITY = {
'milk':1.033,
'water':1.0
}
def convert_F2K(t_f):
return convert_F2C(t_f)+273.0
def convert_F2C(t_f):
t_c = (t_f-32.0)*5.0/9.0
return t_c
def convert_C2F(t_c):
t_f = (t_c*9.0/5.0) + 32
return t_f
def convert_C2K(t_c):
return t_c + 273.0
rng=np.random.default_rng()
class Chai:
# volume in ML
# temperature in *F
# Tea bags themselves are not modeled; impurity is known to raise boiling point.
def __init__(self,milk,water,cup_volume,ambient_temperature,power=1000):
self.microwave_power = power/1e3 #k.watts
self.power_tx_coeff = 1.0 #scale factor
self.v_milk = milk*cup_volume/1e3
self.v_water = water*cup_volume/1e3
self.mass_milk = self.v_milk*DENSITY['milk']
self.mass_water = self.v_milk * DENSITY['water']
self.v_cup = cup_volume/1e3 #in litres
self.t_start = convert_F2K(ambient_temperature)
self.t_end = min(BP['milk'],BP['water'])
self.elapsed_time = 0
self.film_coeff_h = 1
self.cup_surface_area = np.pi*8.2e-2*12e-2 #cylinder = pi*diameter*height
self.milk_tau = None
self.water_tau = None
def __str__(self):
return f"A {self.v_cup*1e3} ml cup has {self.v_milk*1e3}ml milk and {self.v_water*1e3}ml water;\nwith " \
f"temperatue heated from {self.t_start}K->{self.t_end}K,\n and a heating duration of "\
f"{self.elapsed_time}\n to brew this cup to perfection!"
@staticmethod
def make_chai(milk,water,cup_volume,ambient_temperature,microwave_power):
assert milk+water <= 1.0,"fractions to add up"
return Chai(milk,water,cup_volume,ambient_temperature,microwave_power)
def brew(self,power_fluctuate=0.0):
t_curr = self.t_start
# Tau = (m*c)/(h*A)
self.milk_tau = (self.mass_milk)/(self.film_coeff_h*self.cup_surface_area)
self.water_tau = (self.mass_water)/(self.film_coeff_h*self.cup_surface_area)
#print("Milk,Water =>",self.milk_tau,self.water_tau)
# whoever is first to boil will break the surface of the cup
# Q = M.S.TempDelta - Newtons law of heating/cooling
Swater = SPECIFIC_HEAT_CAPACITY['water']
Smilk = SPECIFIC_HEAT_CAPACITY['milk']
deltaT = self.t_end-self.t_start
Qwater = self.mass_water*Swater*deltaT
Qmilk = self.mass_milk*Smilk*deltaT
net_heat_required = Qwater + Qmilk #KJ.
print(f'Net heat required for boiling point: {net_heat_required} kJ')
# assuming instantaneous heat equilibirium of milk+water due to third-law
microwave_power = rng.standard_normal()*power_fluctuate + self.microwave_power
self.elapsed_time = self.power_tx_coeff*net_heat_required/microwave_power
#print("{0} m, {1}s".format(self.elapsed_time//60,np.round(self.elapsed_time%60)))
return self.elapsed_time
milk = rng.standard_normal(100)*0.04 + 0.75
f_times = np.zeros((100,))
times = np.zeros((100,))
power_fluctuate=0.025
for idx in range(len(milk)):
water = 1.0 - milk[idx]
chai = Chai.make_chai(milk=milk[idx],water=water,cup_volume=300,ambient_temperature=60,microwave_power=1000)
f_times[idx] = chai.brew(power_fluctuate=power_fluctuate)
times[idx] = chai.brew(power_fluctuate=0.0)
plt.figure()
plt.subplot(211)
plt.plot(milk,times,'-r')
plt.text(0.65,150,'Heating w/o power fluctuations')
plt.subplot(212)
plt.plot(milk,f_times,'ob')
plt.title('Heating times for various Milk ratios in 1kW Microwave')
plt.ylabel('Brew Time (s)')
plt.xlabel('Milk-Water ratio in 300ml cup')
plt.text(0.65,150,f'Heating w/ {power_fluctuate*100}% power fluctuations')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment