## 6 Results: Validation of the Simulator  
The validation of the simulator was divided into two stages with specific objectives. In a first stage, data from the Comsol CFD, considered as a reference computational fluid dynamics software, were contrasted with respect to the output of the simulator for conditions of advective flow, diffusion, and decay of chlorine. The objective of this phase was to verify the correct implementation and validation of the advection-diffusion-reaction model in the Simulink S-Function. In a second stage, the _estimateCD_ function was parameterized and implemented for the characteristics of the water treated by the DWTP, and data from the SCADA database were validated on the basis of this parameterization. Table 2 shows a comparison of values obtained from Comsol CFD with respect to those provided by the simulator for different decay constants and a flow rate of 3.7 m\({}^{3}\)/s. In any case, the relative error  
Figure 11: Simulator block diagram to compare simulation data and real data from SCADA. Figure 10: **Left:** decision tree for chlorine demand; **right**: correlation between ammonium concentration and chlorine demand (about \(R=0.93\)). in the sample is larger than 2% considering that chlorine meters have an absolute error of 0.04 ppm. This fact implies that the error made by the simulator would widely meet the requirements in terms of accuracy. Figure 12 shows graphically a comparison of data obtained with Comsol CFD and the simulator, with different water flows between 1.50 and 3.70 m\({}^{3}\)/s. On the basis of these results, the simulator gave excellent results. However, the most important validation of simulator was carried out with real data; this is perhaps the most effective way to demonstrate the power of a simulator. In this case, the experiments were performed with real data obtained from the plant in real situations. Most of the time, the plant has neither variation on the input flow nor the effluent where the water comes from, and thus the chlorine dosage is constant. Such situations are easy to model. However, when weather conditions are varying, such as in episodes of flooding or big storms, or even in large episodes of draught when the river flow in very low, the situation in the plant becomes exceptional. In such periods, the chlorine dosage has to abruptly change due the bad conditions of input flow to the plant. We focused our attention upon such \begin{table}
\begin{tabular}{c c c c c c c} \hline  & \multicolumn{6}{c}{**Chlorine Concentration (ppm) for a Flow Rate of 3.7 m\({}^{3}\)/s**} \\ \(k_{R}\) (s\({}^{-1}\)) & \multicolumn{2}{c}{**At 35 m from Tank 1 Inlet**} & \multicolumn{2}{c}{**At 70 m from Tank 1 Inlet**} \\ \hline  & Comsol CFD & Proposed & Relative & Comsol CFD & Proposed & Relative \\  & & Simulator & Error at 35 m & Simulator & Error at 70 m \\
0.0001 & 0.9180 & 0.9028 & \(-\)1.69\% & 0.8869 & 0.8802 & \(-\)0.76\% \\
0.0003 & 0.8620 & 0.8554 & \(-\)0.77\% & 0.7859 & 0.7859 & \(-\)0.01\% \\
0.0005 & 0.8107 & 0.8105 & \(-\)0.02\% & 0.6978 & 0.7016 & 0.55\% \\
0.0007 & 0.7634 & 0.7680 & 0.60\% & 0.6206 & 0.6264 & 0.93\% \\
0.0009 & 0.7198 & 0.7277 & 1.09\% & 0.5529 & 0.5593 & 1.15\% \\
0.0011 & 0.6794 & 0.6895 & 1.48\% & 0.4934 & 0.4994 & 1.21\% \\
0.0013 & 0.6419 & 0.6534 & 1.76\% & 0.4409 & 0.4459 & 1.13\% \\
0.0015 & 0.6071 & 0.6192 & 1.95\% & 0.3946 & 0.3982 & 0.91\% \\ \hline \end{tabular}
\end{table} 
Table 2: Comparison of chlorine decay between the simulator and the Comsol computational fluid dynamics (CFD). Figure 12: Results comparison between CFD Comsol data and simulator data for different flow rates (1.50, 2.00, 2.70, and 3.70 m\({}^{3}\)/s). residuals can be seen, except for flows close to 1.5 m\({}^{3}\)/s, which is multimodal. At large flow rates with high velocity (above from 1.5 m\({}^{3}\)/s), it is easier to predict errors and residuals closer to zero and with less dispersion, because the dispersion, either multimodal or unimodal, increases when the flow drops.