## 3 Methodology
### Modeling of the Continuous Stirred-Tank Reactor
#### 3.2.3 Mass and Energy Balances for the CSTR  
The CSTR model was developed using usual mass and energy balances [37; 38], considering the following assumptions, which are close to the conditions in a real continuous reactor of biodiesel. (1) The chemical reactions of reactants in the input stream before entering the tank are not considered. (2) The reaction mixture can be considered pseudo-homogeneous due to an intense agitation (assumed) and the high temperature of reactor mixture (60 \({}^{\circ}\)C). (3) With these conditions, the mass transfer regimen is negligible and the reaction rate only depends on the activation energy and frequency factors of the kinetic constants associated with the fatty acids in the glycerides [26; 42; 43]. (4) The thermo-physical properties of the mixture components are constant within the system's temperature range because the change of temperature caused by the oil changes is negligible. (5) The thermo-physical properties of the input stream and the reactor mixture are the same. (6) The volume and thermo-physical properties of the cooling fluid are constant. (7) The reactor operates with a constant volume. (8) There is no heat transfer between reaction mixture and surroundings. Equations (16)-(25) present a compact form of the reactor model developed from mass and energy balances:  
Figure 2: Different reactions occurring in the reactor: (**a**) nominal operation with a type-i oil; (**b**) transitory period after an oil change when two different transesterification processes and cross-linking reactions occur in the reactor tank; and, (**c**) nominal operation with a type-j oil.  
\[V\frac{d}{dt}C_{TG,i} = F\left(C_{TG,in,i}-C_{TG,i}\right)+VG_{TG,i}, \tag{16}\] \[V\frac{d}{dt}C_{TG,ij} = -FC_{TG,ij}+VG_{TG,ij},\] (17) \[V\frac{d}{dt}C_{DG,i} = F\left(C_{DG,in,i}-C_{DG,i}\right)+VG_{DG,i}+\sum VG_{DG,i,j\mu},\] (18) \[V\frac{d}{dt}C_{DG,ij} = -FC_{DG,ij}+VG_{DG,ij},\] (19) \[V\frac{d}{dt}C_{MG,i} = -FC_{MC,i}+VG_{MG,i}+\sum VG_{MG,i,ij},\] (20) \[V\frac{d}{dt}C_{ME,i} = -FC_{ME,i}+VG_{ME,i,j\mu}+\sum VG_{ME,i,j\mu},\] (21) \[V\frac{d}{dt}C_{GL} = -FC_{GL}+\sum VG_{GL,i},\] (22) \[V\frac{d}{dt}C_{AL} = F\left(C_{AL,in}-C_{AL}\right)+\sum VG_{AL,i}+\sum VG_{AL,ij\mu},\] (23) \[\rho c_{p}V\frac{dT}{dt} = F\left(T_{in}-T\right)-\sum V\Delta H_{k,i}r_{k,i}-\sum V\Delta H _{k,i}r_{k,i}-U_{t}A_{t}\left(T-T_{c}\right),\] (24) \[\rho_{c}c_{p,i}V_{c}\frac{dT_{c}}{dt} = F_{c}\left(T_{in,i}-T_{c}\right)+U_{t}A_{t}\left(T-T_{c}\right), \tag{25}\]  
where \(V\) represents the total volume of the reaction mixture; \(F\) and \(F_{c}\) represent the volumetric flow rates in the feed and cooling coil streams; \(\rho\) and \(\rho_{c}\) are the density by reaction mixture and cooling coil, respectively; \(c_{p}\) and \(c_{p,c}\) are, respectively, the specific heat of the mixture in the tank and the water in the cooling coil; \(\Delta H_{k,i}\) represents the enthalpy of the \(k\)-th elementary reaction occurring during the transesterification of the vegetable oils and the cross-linking reactions; and, \(U_{t}\) and \(A_{t}\) are, respectively, the heat transfer coefficient and the area of heat transfer between both the cooler and the reactor. In the model, the terms \(G_{n,i}\) (generation term) represent the net rates of the \(n\)-th component inside the tank and are defined by Equations (26)-(37):  
\[G_{TG,i} = -r_{1,i}+r_{2,i}, \tag{26}\] \[G_{TG,ij} = r_{1,i}+r_{2,i}, \tag{27}\]