TCLab Convective Heat Transfer

Objective: Simulate an energy balance model with convective heat transfer.

A basic energy balance model of the Temperature Control Lab (TCLab) assumes that there is one uniform temperature in the control volume and that all heat loss is through natural convection with U=10 W/m2-K. The relationship between the heater and the power output is given by `\alpha`=0.01 W/%.

$$m \, c_p \, \frac{dT}{dt} = U\,A\, \left(T_a-T\right) + \alpha \, Q$$

With the temperature initially at ambient temperature (`T_a`), simulate the change in temperature over the 5 minutes when heater Q is adjusted to 50%. Use values of m=0.004 kg, A=0.0012 m2, `c_p`=500 J/kg-K, and `T_a`=23 oC. Compare the simulated temperature response to data from the TCLab. Add a simulation prediction to the script below to compare with the TCLab data.

TCLab Step Response

import numpy as np
import matplotlib.pyplot as plt
import tclab
import time

n = 300  # Number of second time points (5 min)
tm = np.linspace(0,n,n+1) # Time values

# data
lab = tclab.TCLab()
T1 = [lab.T1]
lab.Q1(50)
for i in range(n):
    time.sleep(1)
    print(lab.T1)
    T1.append(lab.T1)
lab.close()

# Plot results
plt.figure(1)
plt.plot(tm,T1,'r.',label='Measured')
plt.ylabel('Temperature (degC)')
plt.xlabel('Time (sec)')
plt.legend()
plt.show()

Solutions

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import tclab
import time

n = 300  # Number of second time points (5 min)
tm = np.linspace(0,n,n+1) # Time values

# data
lab = tclab.TCLab()
T1 = [lab.T1]
lab.Q1(50)
for i in range(n):
    time.sleep(1.0)
    print(lab.T1)
    T1.append(lab.T1)
lab.close()

# simulation
def labsim(TC,t):
    U = 10.0
    A = 0.0012
    Cp = 500
    m = 0.004
    alpha = 0.01
    Ta = 23
    dTCdt = (U*A*(Ta-TC) + alpha*50)/(m*Cp)
    return dTCdt
Tsim = odeint(labsim,23,tm)

# Plot results
plt.figure(1)
plt.plot(tm,Tsim,'b-',label='Simulated')
plt.plot(tm,T1,'r.',label='Measured')
plt.ylabel('Temperature (degC)')
plt.xlabel('Time (sec)')
plt.legend()
plt.show()

import numpy as np
import matplotlib.pyplot as plt
import tclab
import time
# pip install gekko
from gekko import GEKKO

n = 300  # Number of second time points (5 min)

# data
lab = tclab.TCLab()
T1 = [lab.T1]
lab.Q1(50)
for i in range(n):
    time.sleep(1)
    print(lab.T1)
    T1.append(lab.T1)
lab.close()

# simulation
m = GEKKO()
m.time = np.linspace(0,n,n+1)
U = 10.0; A = 0.0012; Cp = 500
mass = 0.004; alpha = 0.01; Ta = 23
TC = m.Var(23)
m.Equation(mass*Cp*TC.dt()==U*A*(Ta-TC)+alpha*50)
m.options.IMODE = 4 # dynamic simulation
m.solve(disp=False)

# Plot results
plt.figure(1)
plt.plot(m.time,TC,'b-',label='Simulated')
plt.plot(m.time,T1,'r.',label='Measured')
plt.ylabel('Temperature (degC)')
plt.xlabel('Time (sec)')
plt.legend()
plt.show()