Heated tank example
===

1. Determine system boundary. Identify inputs and outputs.
Inputs: electric current $i(t)$, environment temperature $\vartheta_\text E(t)$
Outputs: liquid temperature $\vartheta_\text L(t)$
States: liquid temperature $\vartheta_\text L(t)$, heater temperature $\vartheta_\text H(t)$, (wall temperature $\vartheta_\text H(t)$)
2. Determine which effects have to be modelled
What are the conserved quantities of interest?
3. Divide system into compartments

- we will (at first) neglect the effect of the wall of the tank

4. Set up balance equations for each compartment and each conserved quantity
$\dfrac{\text dB_i(t)}{\text dt} =\sum\limits_{k=1, k\neq i}^{n_\text{comp}}\dot B_{ki}(t) - \sum\limits_{l=1}^{n_\text{src}}\dot S_{l}(t)$
- $i$ – index of the compartment
- $\dot B_{ki}$ -- flow from the compartment $k$ to the compartment $i$, it holds that $\dot B_{ki} = -\dot B_{ik}$
- $\dot S_{l}$ source term of the quantity in the compartment
- assuming constant pressure (energy balance $\to$ enthalpic balance):
Balance equations:
liquid (L): $\begin{Bmatrix}\text{heat}\\\text{accumulation}\\\text{in liquid} \end{Bmatrix} = \begin{Bmatrix}\text{heat flow}\\\text{from heater}\\\text{to liquid} \end{Bmatrix} + \begin{Bmatrix}\text{heat flow}\\\text{from environment}\\\text{to liquid} \end{Bmatrix}$
heater (H): $\begin{Bmatrix}\text{heat}\\\text{accumulation}\\\text{in heater} \end{Bmatrix} = \begin{Bmatrix}\text{heat flow}\\\text{from liquid}\\\text{to heater} \end{Bmatrix} + \begin{Bmatrix}\text{heat generation}\\\text{in heater} \end{Bmatrix}$
liquid (L): $\dfrac{\text dQ_\text L(t)}{\text dt} = \dot Q_{\text{LH}}(t) + \dot Q_{\text{LE}}(t)$
heater (H): $\dfrac{\text dQ_\text H(t)}{\text dt}(t) = \dot Q_{\text{HL}}(t) + \dot Q_{\text{el}}(t)\qquad$ note: $\dot Q_{\text{HL}}(t) = - \dot Q_{\text{LH}}(t)$
\
Balance equations (if wall is considered):
liquid (L): $\dfrac{\text dQ_\text L(t)}{\text dt} = \dot Q_{\text{LH}}(t) + \dot Q_{\text{LW}}(t) + \dot Q_{\text{LE}}(t)$
wall (W): $\dfrac{\text dQ_\text W(t)}{\text dt} = \dot Q_{\text{WL}}(t) + \dot Q_{\text{WE}}(t)$
heater (H): $\dfrac{\text dQ_\text H(t)}{\text dt} = \dot Q_{\text{HL}}(t) + \dot Q_{\text{el}}(t)$
5. Specify the terms on the right-hand side of differential equations using
a. constitutive equations (physical/mathematical laws) e.g.: $p = \rho gh$, $m=\rho 𝑉$, $Q=mc_p(\vartheta-\vartheta_\text{ref})$
b. descriptive/empirical equations e.g.: $\dot Q=\alpha A \Delta\vartheta$ (heat transfer, $\alpha$ is a heat transfer coefficient)
Flow and source terms are expressed by intensive quantities (potentials), e.g. temperature, concentration, pressure.
\
liquid (L): $\dfrac{\text d\left[m_\text L(t)c_{p,\text L}(\vartheta_\text L(t))(\vartheta_\text L(t)-\vartheta_\text{ref})\right]}{\text dt} =$
$\qquad\qquad=\alpha_\text{LH}(\vartheta_\text L(t), \vartheta_\text H(t))A_\text{H}(\vartheta_\text H(t)-\vartheta_\text L(t)) + \alpha_\text{LE}(\vartheta_\text L(t), \vartheta_\text E(t))A_\text{L}(\vartheta_\text E(t)-\vartheta_\text L(t))$
heater (H): $\dfrac{\text d\left[m_\text Hc_{p,\text H}(\vartheta_\text H(t))(\vartheta_\text H(t)-\vartheta_\text{ref})\right]}{\text dt} = \alpha_\text{LH}(\vartheta_\text L(t), \vartheta_\text H(t))A_\text{H}(\vartheta_\text L(t)-\vartheta_\text H(t)) + \dot Q_{\text{el}}(t)$
-- $\dot Q_{\text{el}}(t)=\dot Q_{\text{el}}(t)$ if general (unspecified) heater is used
-- $\dot Q_{\text{el}}(t)=RI^2(t)$ if electric heater
-- $\dot Q_{\text{el}}(t)=\alpha_\text{sH}(\vartheta_\text s(t), \vartheta_\text H(t))A_\text{sH}(\vartheta_\text s(t)-\vartheta_\text H(t))$ if steam heater (with $q_\text s(t)$, $\rho_\text s(t)$, $\vartheta_\text s(t)$ as steam flowrate, density, and temperature, respectively)
- assuming constant liquid hold up, liquid density, heater mass, and liquid/heater specific heat capacity, we get:
liquid (L): $m_\text L c_{p,\text L}\dfrac{\text d\vartheta_\text L(t)}{\text dt}=\alpha_\text{LH}A_\text{H}(\vartheta_\text H(t)-\vartheta_\text L(t)) + \alpha_\text{LE}A_\text{L}(\vartheta_\text E(t)-\vartheta_\text L(t))$
heater (H): $m_\text Hc_{p,\text H}\dfrac{\text d\vartheta_\text H(t)}{\text dt} = \alpha_\text{LH}A_\text{H}(\vartheta_\text L(t)-\vartheta_\text H(t)) + \dot Q_{\text{el}}(t)$
-- resulting model: 2 differential equations, 10 parameters ($m_\text L$, $c_{p,\text L}$, $\alpha_\text{LH}$, $A_\text{H}$, $\alpha_\text{LE}$, $A_\text{L}$, $m_\text H$, $c_{p,\text H}$, $\alpha_\text{LH}$, $A_\text{H}$)
- regrouping the terms
liquid (L): $m_\text L c_{p,\text L}\dfrac{\text d\vartheta_\text L(t)}{\text dt}=-(\alpha_\text{LH}A_\text{H}+\alpha_\text{LE}A_\text{L})\vartheta_\text L(t) + \alpha_\text{LH}A_\text{H}\vartheta_\text H(t) + \alpha_\text{LE}A_\text{L}\vartheta_\text E(t)$
heater (H): $m_\text Hc_{p,\text H}\dfrac{\text d\vartheta_\text H(t)}{\text dt} = -\alpha_\text{LH}A_\text{H} \vartheta_\text H(t) + \alpha_\text{LH}A_\text{H} \vartheta_\text L(t) + \dot Q_{\text{el}}(t)$
- defining time constants and static gains
liquid (L): $\underbrace{\dfrac{m_\text L c_{p,\text L}}{\alpha_\text{LH}A_\text{H}+\alpha_\text{LE}A_\text{L}}}_{T_\text L}\dfrac{\text d\vartheta_\text L(t)}{\text dt}=-\vartheta_\text L(t) + \underbrace{\dfrac{\alpha_\text{LH}A_\text{H}}{\alpha_\text{LH}A_\text{H}+\alpha_\text{LE}A_\text{L}}}_{K_{\text H\to \text L}}\vartheta_\text H(t) + \underbrace{\dfrac{\alpha_\text{LE}A_\text{L}}{\alpha_\text{LH}A_\text{H}+\alpha_\text{LE}A_\text{L}}}_{K_{\text E\to \text L}}\vartheta_\text E(t)$
heater (H): $\underbrace{\dfrac{m_\text Hc_{p,\text H}}{\alpha_\text{LH}A_\text{H}}}_{T_\text H}\dfrac{\text d\vartheta_\text H(t)}{\text dt} = -\vartheta_\text H(t) + \vartheta_\text L(t) + \underbrace{\dfrac{1}{\alpha_\text{LH}A_\text{H}}}_{K_{\text el\to\text H}}\dot Q_{\text{el}}(t)$
- steady state calculation
$\begin{pmatrix}1 & -K_{\text H\to \text L}\\-1 & 1\end{pmatrix}
\begin{pmatrix}\vartheta_\text L^{\text s}\\ \vartheta_\text H^{\text s}\end{pmatrix}=\begin{pmatrix}K_{\text E\to \text L}\vartheta_\text E^{\text s}\\K_{\text el\to\text H}\dot Q^{\text s}_{\text{el}}\end{pmatrix}$
- steady state (calculation of $\dot Q^{\text{s, ref}}_{\text{el}}$ for a desired $\vartheta_\text L^{\text{s, ref}}$)
$\begin{pmatrix}0 & -K_{\text H\to\text L}\\-K_{\text el\to\text H} & 1\end{pmatrix}
\begin{pmatrix}\dot Q^{\text{s, ref}}_{\text{el}}\\ \vartheta_\text H^{\text s}\end{pmatrix}=\begin{pmatrix}K_{\text E\to \text L}\vartheta_\text E^{\text s}-\vartheta_\text L^{\text{s, ref}}\\\vartheta_\text L^{\text{s, ref}}\end{pmatrix}$
-- or alternatively:
(L): $\vartheta_\text L^{\text{s, ref}} = K_{\text H\to \text L}\vartheta_\text H^\text{s} + K_{\text E\to \text L}\vartheta_\text E^\text{s} \ \to \ \vartheta_\text H^\text{s} = (\vartheta_\text L^{\text{s, ref}}-K_{\text E\to \text L}\vartheta_\text E^\text{s})/K_{\text H\to \text L}$
(H): $\vartheta_\text H^\text{s} = \vartheta_\text L^{\text{s, ref}} + K_{\text el\to\text H}\dot Q_{\text{el}}^\text{s, ref}\ \to\ \dot Q_{\text{el}}^\text{s, ref} = (\vartheta_\text H^\text{s} - \vartheta_\text L^{\text{s, ref}})/K_{\text el\to\text H}$
(H): $\dot Q_{\text{el}}^\text{s, ref} = [(\vartheta_\text L^{\text{s, ref}}-K_{\text E\to \text L}\vartheta_\text E^\text{s})/K_{\text H\to \text L} - \vartheta_\text L^{\text{s, ref}}]/K_{\text el\to\text H}$
- proportional controller
$\dot Q_{\text{el}}(t) = \dot Q^{\text{s, ref}}_{\text{el}} + K_C(\vartheta_\text L^{\text{s, ref}}-\vartheta_\text L(t))$
$\underbrace{\dot Q_{\text{el}}(t) - \dot Q^{\text{s, ref}}_{\text{el}}}_{u(t)}= K_C[\underbrace{(\vartheta_\text L^{\text{s, ref}}-\vartheta_\text L^{\text{s}})}_{w(t)}-\underbrace{(\vartheta_\text L(t)-\vartheta_\text L^{\text{s}})}_{y(t)})] \ \to \ u(t)= K_C(w(t)-y(t))$
- model of a controlled system
liquid (L): $T_\text L\dfrac{\text d\vartheta_\text L(t)}{\text dt}=-\vartheta_\text L(t) + K_{\text H\to \text L}\vartheta_\text H(t) + K_{\text E\to \text L}\vartheta_\text E(t)$
heater (H): $T_\text H\dfrac{\text d\vartheta_\text H(t)}{\text dt} = -\vartheta_\text H(t) + \vartheta_\text L(t) + K_{\text el\to\text H}\left[\dot Q^{\text{s, ref}}_{\text{el}} + K_C(\vartheta_\text L^{\text{s, ref}}-\vartheta_\text L(t))\right]$
-- (new) inputs: $\vartheta_\text L^{\text{s, ref}}$, $\dot Q_{\text{el}}(t)$ is no longer an input
-- (new) parameters: $\dot Q^{\text{s, ref}}_{\text{el}}$, $K_C$
-- actually $Q^{\text{s, ref}}_{\text{el}}=Q^{\text{s, ref}}_{\text{el}}(\vartheta_\text L^{\text{s, ref}}, \vartheta_\text E^{\text s})$ -- using a (steady-state) model, we can set up a feedforward compensation of the controller $Q^{\text{s, ref}}_{\text{el}}$
- steady state of the controlled system
$\begin{pmatrix}1 & -K_{\text H\to \text L}\\-1 & 1\end{pmatrix}
\begin{pmatrix}\vartheta_\text L^{\text s}\\ \vartheta_\text H^{\text s}\end{pmatrix}=\begin{pmatrix}K_{\text E\to \text L}\vartheta_\text E^{\text s}\\K_{\text el\to\text H}\dot Q^{\text s}_{\text{el}}\end{pmatrix}$