Application of Leibniz's Integral Rule Consider the following image showing the temperature of a metal pipe:

The temperature $T(z,t)$ is a function of the length coordinate $z$ and time $t$. Integrating the partial derivative of $T$ with respect to $t$, $\frac{\partial T}{\partial t}$ over the entire length of the pipe (from $z=a$ to $z=b$) and applying Leibniz's rule, we should get
$$\int_{z=a}^{z=b}\frac{\partial}{\partial t}T(z,t)dz=\frac{d}{dt}\int_{z=a}^{z=b}T(z,t)dz-T(b,t)\frac{db}{dt}+T(a,t)\frac{da}{at}.$$
In a paper (eqs. (21) and (22)), the result is reported as follows:
$$\int_{z=a}^{z=b}\frac{\partial}{\partial t}T(z,t)dz=(b-a)\frac{d}{dt}T_\mathrm{avg}(t)+\big(T(a,t)-T_\mathrm{avg}(t)\big)\frac{da}{dt}+\big(T_\mathrm{avg}(t)-T(b,t)\big)\frac{db}{dt},$$
where
$$T_\mathrm{avg}(t)=\frac{1}{2}\big(T(a,t)+T(b,t)\big).$$
Are the two equivalent? If not, which one is correct? I'm not able to see the equivalence, or understand how the second result could be valid. Any help and elaboration will be greatly appreciated!
Note: The integral in this question is only a portion of a larger integration problem in the energy balance, not reported for brevity. Equations (21) and (22) in the reference describe the complete energy balance.
 A: I don't see it either. What is always true is$\newcommand{\avg}{\text{avg}}$
\begin{align}
\int_a^b \partial_t T dz &= \int_a^b \partial_t T_{\avg} dz + \int_a^b \partial_t (T-T_{\avg}) dz  
\\
&= \int_a^b \partial_t T_{\avg} dz + \frac{d}{dt}\int_a^b(T-T_\avg)dz -(T(a)-T_\avg)\frac{da}{dt} + (T(b)-T_\avg)\frac{db}{dt}
\end{align}
The last two terms appear in what you want. Further, $\partial_t T_\avg $ does not depend on $z$, so
$$  \int_a^b \partial_t T_{\avg} dz = (b-a) \partial_t T_{\avg}. $$
So, ignoring the notation choice of $\partial_t$ vs $d/dt$, it seems that we need
$$  \frac{d}{dt}\int_a^b(T-T_\avg)dz = 0 $$
Perhaps this is something implied by what previously appears in the paper. I can't decipher the notation of the paper, and can't deduce what you wrote from (21), (22) so I hope you can finish from here.
A: This answer is based on the original answer by Calvin Khor. Some supplemental details relevant to the problem are added.
Referring to the original problem, let $T(z,t)$ vary with $z$ as shown in the following figure:

As proposed in the original solution, integrating integral of the partial derivative of $T$ from $a$ to $b$ and applying Leibniz's Rule:
\begin{align}
\int_{a}^{b}\frac{\partial}{\partial t}T(z,t)dz&=\int_{a}^{b}\frac{\partial}{\partial t}\big(T(z,t)-T_\mathrm{avg}(t)+T_\mathrm{avg}(t)\big)dz\\
&=\int_{a}^{b}\frac{\partial}{\partial t}T_\mathrm{avg}(t)dz + \underbrace{\int_{a}^{b}\frac{\partial}{\partial t}\big(T(z,t)-T_\mathrm{avg}(t)\big)dz}_\text{apply Leibniz Rule}\\
&=(b-a)\frac{d}{dt}T_\mathrm{avg}(t)\\
&\quad+\underbrace{\frac{d}{dt}\int_{a}^{b}\big(T(z,t)-T_\mathrm{avg}(t)\big)dz+\big(T(a,t)-T_\mathrm{avg}(t)\big)\frac{da}{dt}+\big(T_\mathrm{avg}(t)-T(b,t)\big)\frac{db}{dt}.}_\text{Leibniz's Rule applied}
\end{align}
The area under the curve in the figure (shaded green) can be found using the integral $\int_{a}^{b}T(z,t)dz$. Approximating the curve with a straight line, we can write
\begin{align}
\int_{a}^{b}T(z,t)dz&\approx\underbrace{\frac{1}{2}(b-a)\big(T(b,t)-T(a,t)\big)}_\text{area of top triangle}+\underbrace{T(a,t)(b-a)}_\text{area of bottom rectangle}\\
&=\frac{1}{2}\big(T(a,t)+T(b,t)\big)(b-a)=(b-a)T_\mathrm{avg}(t).
\end{align}
Thus, the second term in the third equality of the first equation vanishes, and the desired result is obtained:
$$\int_{a}^{b}\frac{\partial}{\partial t}T(z,t)dz\approx(b-a)\frac{d}{dt}T_\mathrm{avg}(t)+\big(T(a,t)-T_\mathrm{avg}(t)\big)\frac{da}{dt}+\big(T_\mathrm{avg}(t)-T(b,t)\big)\frac{db}{dt}.$$
