In many books of Engineering thermodynamics, the entropy balance equation is wrritten as
$\frac{dS}{dt}=\Pi_S+I_S$
$I_S=\sum_{j=1}\frac{\dot{Q}_{j}}{T_j}+\sum_{i=1}\dot{m}_is_i-\sum_{e=1}\dot{m}_es_e$
$\frac{dS}{dt}=\Pi_S+\sum_{j=1}\frac{\dot{Q}_{j}}{T_j}+\sum_{i=1}\dot{m}_is_i-\sum_{e=1}\dot{m}_es_e$
Where the term "$\Pi_S$" represents the entropy rate production, which is always postive or equal to zero, $\Pi_S\ge0$ , and the term $I_S$ means the entropy exchange rate. $\sum_{i=1}\dot{m}_is_i$, $\sum_{e=1}\dot{m}_es_e$ are the incoming and outgoing entropy respectively due to mass flow. Where $s_i$, $s_e$ are the intensive entropy per unit mass.
Where does the $\sum_{i=1}\dot{m}_is_i-\sum_{e=1}\dot{m}_es_e$ come from? How to derived it in a formal way? Other authors like Ansermet, can derived that in fact $I_S=\frac{\dot{Q}}{T}$ but no the entropy exchanged by mass flows
In the book "Principles of thermodynamics" by Jean Phillipe Ansermet, says that the entropy evolution in a macroscopic scale, can be described as follows:
$\frac{dS}{dt}=\Pi_S+I_S$
A few pages back, the author says that the internal energy evolution for a system can be described as
$\dot{U}=T\dot{S}-P\dot{V}+\sum_{i=1}^C\mu_i\dot{N_i}=P_Q+P_W+P_C$
Where $P_Q , P_W, P_C$ are the heat power, mechanical power and chemical power respectively. The heat power $P_Q$ is the same variable that $\dot{Q}_j$, so $P_Q=\dot{Q}_j$. We can re write the internal energy evolution equation in terms of $\dot{S}$.
$\dot{S}=\frac{1}{T}(P_Q+P_W+P_C+P\dot{V}-\sum_{i=1}^C\mu_i\dot{N_i})$
Entropy exchanges happens when exist heat transfer. Due to the above, we can rewrite the equation as follows:
$\dot{S}=\frac{1}{T}(P_W+P_C+P\dot{V}-\sum_{i=1}^C\mu_i\dot{N_i})+\frac{P_Q}{T}$
Therefore, when the process is reversible there is no entropy production $\Pi_S=0$ and there is no entropy exchage $I_S=0$. Then, we can deduce the reversible heat, mechanical work and chemical work
$\frac{1}{T}(P_W+P_C+P\dot{V}-\sum_{i=1}^C\mu_i\dot{N_i})=\Pi_S=0$ y $\frac{P_Q}{T}=I_S=0$
$P_W=-P\dot{V}\Rightarrow\delta W=P_Wdt=-PdV\Rightarrow W_{if}=\int_i^f\delta W=-\int_{V_i}^{V_f}PdV$
$P_C=\sum_{i=1}^C\mu_i\dot{N_i}\Rightarrow\delta C=P_Cdt=\sum_{i=1}^C\mu_idN_i\Rightarrow C_{if}=\int_i^f\delta C=\int_{N_{i_i}}^{N_{i_f}}\sum_{i=1}^C\mu_idN_i$
$P_Q=TI_S$
In reversible process, we can rewrite the internal energy equation in order to obtain another expression for $P_Q$
$\dot{U}=T\dot{S}-P\dot{V}+\sum_{i=1}^C\mu_i\dot{N_i}=P_Q+P_W+P_C\Rightarrow T\dot{S}-P\dot{V}+\sum_{i=1}^C\mu_i\dot{N_i}=P_Q-P\dot{V}+\sum_{i=1}^C\mu_i\dot{N_i} \Rightarrow P_Q=T\dot{S}$
$P_Q=T\dot{S}\Rightarrow \delta Q=P_Qdt=TdS\Rightarrow Q_{if}=\int_i^f\delta Q=\int_{S_i}^{S_f}TdS$
But, Ansermet cannot show where does the $\sum_{i=1}\dot{m}_is_i-\sum_{e=1}\dot{m}_es_e$ come from.
Also, how can we fit the term $\sum_{i=1}\dot{m}_is_i-\sum_{e=1}\dot{m}_es_e$ when we take the differential form of entropy $dS$?