Efﬁcient Double-Tee Junction Mixing Assessment by Machine Learning

: A new approach in modeling of mixing phenomena in double-Tee pipe junctions based on machine learning is presented in this paper. Machine learning represents a paradigm shift that can be efﬁciently used to calculate needed mixing parameters. Usually, these parameters are obtained either by experiment or by computational ﬂuid dynamics (CFD) numerical modeling. A machine learning approach is used together with a CFD model. The CFD model was calibrated with experimental data from a previous study and it served as a generator of input data for the machine learning metamodels—Artiﬁcial Neural Network (ANN) and Support Vector Regression (SVR). Metamodel input variables are deﬁned as inlet pipe ﬂow ratio, outlet pipe ﬂow ratio, and the distance between the pipe junctions, with the output parameter being the branch pipe outlet to main inlet pipe mixing ratio. A comparison of ANN and SVR models showed that ANN outperforms SVR in accuracy for a given problem. Consequently, ANN proved to be a viable way to model mixing phenomena in double-Tee junctions also because its mixing prediction time is extremely efﬁcient (compared to CFD time). Because of its high computational efﬁciency, the machine learning metamodel can be directly incorporated into pipe network numerical models in future studies.


Introduction
The mixing of fluids in water distribution networks is a complex phenomenon that has been extensively subjected to research as it is relevant to several specific areas of application such as water distribution quality and safety [1][2][3], pollution source detection systems (both large [4,5] and small networks [6]), and optimal pollution sensor placement in a water distribution network [7][8][9][10]. The elements that form water distribution networks are pipes and junctions. When modeling mixing in a complex system, a correct mixing model must be applied to accurately describe the contaminant transport through the network due to the fact that a wrong solution could present a hazard to a great number of network users.
Usually, mixing in a pipe network is modeled as either complete mixing or bulk mixing. Complete mixing can be described as an even split of contamination at a network junction. Complete mixing models such as the one developed in the hydraulic analysis software EPANET are implemented by calculating the flow-weighted concentrations at the inlet pipes of a junction and then assuming an even split in the outlet pipes. The complete mixing model can be assumed correct only if there is a single outlet at a junction and if the distance between two junctions is great enough. For certain distances [11,12], it does not describe the physical process of mixing correctly.
Bulk mixing is an idealized mixing in which the flow between two inlet pipes is not interacting and the diffusive behavior between the inlet pipe streams is ignored (the streams are only touching at an interface). To model the bulk mixing, the flow momentum in the inlet pipes is calculated, and it determines how the concentration splits between the outlets. The inlet pipe with the higher momentum will dominate in concentration transfer into the outlet pipe, which follows the same direction as the inlet pipe. The inlet pipe with lower flow momentum will only transfer the concentration into its neighboring outlet pipe. This kind of mixing behavior is usually specific to cross junctions. The bulk mixing model is implemented in the software EPANET-BAM [13] (which can be considered as an extension of EPANET). If the expected mixing behavior is neither complete nor bulk, an experimentally-calibrated mixing model parameter can be used, by which type of mixing is defined.
In research by McKenna et al. [14], it is shown that, for a cross junction (which is a special case of a double-Tee junction in which the distance between converging and diverging pipes is equal to zero), a strong deviation from complete mixing occurs when the Reynolds number at each inlet and outlet pipe is equal. On the other hand, stronger turbulence can also create a considerable unpredictability of mixing in cross junctions [15]. The mixing that occurs at two sequential Tee junctions is especially complex due to increased chaotic eddying of flow, which in turn increases the diffusion between the streams. It is proved in several studies [12,16,17] that the length between double-Tee junctions is important since it determines the behavior of mixing of fluids or rather the transport of contaminant into each diverging pipe. In addition, variation of flows at both inlet and outlet pipes causes the mixing behavior to vary [11,12]. Another property of a pipe system that can cause an incomplete mixing behavior are uneven pipe diameters, where a large difference between pipe diameters can produce a more complete mixing [18]. The orientation of pipes for a double-Tee junction also affects the mixing behavior, and it is shown that mixing for a case when the pipes are at a opposite side compared to the case where they are at the same side, behaves differently [11,12] (assuming planar configuration). It is also shown that transitional and laminar flows in pipes exhibit a specific mixing behavior [19].
Instead of an experimental approach to studying mixing behavior in double-Tee junctions, computational fluid dynamics (CFD) can also be used. A species transport model coupled with RANS turbulence models yields good results [12,16] that can be used to further enhance simpler 1D mixing models (such as EPANET-BAM). Additionally, a high fidelity LES turbulence model can also be used to study mixing with more detail [20]. The problem with CFD simulations and the contaminant transport model is that they need to be calibrated as they are dependant on the turbulent Schmidt number, the value of which is very much case-specific [21,22] and has been differently reported in several studies regarding CFD analysis of mixing in double-Tee junctions [12,23,24]. Furthermore, CFD simulations are computationally expensive and producing results for a range of combinations of mixing scenarios (varying inlet and outlet flow, distance between junctions, and even pipe diameters) is quite impractical. Alternatively, mixing behavior can be predicted by use of data analysis (i.e., interpolation on a fixed previously produced dataset), as was done in a previous study [25] where Kriging and Delaunay triangulation were combined to describe mixing for different Reynolds numbers.
Recently, machine learning (ML) algorithms used in hydrology and hydraulics include Artificial Neural Networks (ANN) and variations [26,27], Random Forest [28], and Support Vector Machine [29]. ML has been previously successfully implemented in pipe flow systems. A selection of ML algorithms such as Random Forest, Bagging Algorithm, and Regression Tree were used to predict various characteristics of a wastewater pipe system and it was found that Regression Trees are most successful [30]. Several ML algorithms were also used to predict pressure gradients, liquid holdup, and flow pattern identification of multiphase flow on a pipe segment (where data were generated by CFD) and, for some of the characteristics, the Gradient Boosting algorithm and Support Vector Machine yielded best results [31]. Deep learning (i.e., ANN) was successfully applied to produce the best valve scheduling scenario in the case of pipe network contamination instead of searching for a contamination source [32]. Similarly, Support Vector Regression (SVR) was used to detect anomalies in a pipe network system [33] and a modified ANN approach was used for pipe network management [34].
A ML approach can be also used to evaluate the mixing behavior based on previously obtained data (either by experiment or by CFD). In this study, two ML algorithms-SVR and ANN-were tested in predicting mixing behavior for a combination of different inlet and outlet pipe flow ratios and different distances between double-Tee junctions, on one pipe configuration. Training data were generated by 3D CFD that was calibrated on an experiment presented in a previous study [12]. A supercomputer was used for CFD modeling due to its high computational demand and need to generate as many data as possible for better ML training.

Problem Description
Mixing prediction was performed for a previously reported experiment [12], in which the setup includes varying distances between double-Tee junctions and varying inflows in pipes. Figure 1 shows the pipe configuration used. Branch pipes are on the opposite sides and the arrows represent the flow direction. Tap water (T) (which was used as a tracer) enters the main inlet pipe 1 while distilled water (D) enters the branch inlet pipe 2 causing the mixture (M) of tap and distilled water to exit both the main outlet pipe 3 and the branch outlet pipe 4. The electrical conductivity of tap water in the experiment was measured to be around 200 µS/cm 2 while the distilled water conductivity was around 2 µS/cm 2 at pipe inlets 1 and 2, respectively. This difference of electrical conductivity of the fluids was used to determine the mixing process in the double-Tee junctions since they differed by a factor of 100. The electrical conductivity of the mixture that leaves pipe outlets 3 and 4 was measured and was always constrained between the inlet tap water and inlet distilled water electrical conductivity. The rate of mixing or the electrical conductivity of the mixture at outlets depends on the flow conditions in the inlet and outlet pipes. The measure of mixing taken from experimental data and used for further investigation of mixing was the branch outlet pipe 4 to main inlet pipe 1 (see Figure 1) conductivity ratio, which is defined as where c 4 represents the conductivity at outlet pipe 4, while c 1 is the conductivity at inlet pipe 1. This ratio was chosen due to its usage in previous studies [13,35] as it can be used in mixing prediction for simpler 1D models (EPANET-BAM). The inlet pipe flow ratio was also varied in the experiment and it is defined as where Q 1 defines the flow at inlet pipe 1 and Q 2 the flow at inlet pipe 2. The values of Q 1 and Q 2 were controlled with valves in the experiment until a steady state behavior was achieved and then the measurement of the electrical conductivity at each outlet pipe was made. The inflow pipe ratios R q in used in the experiment were 0.333, 0.5, 1, 2, and 3, while the flow at both outlet pipes was the same. One of the purposes of this study was to examine the behavior of mixing when R q in is not equal to 1 while the flow at both outlet pipes is also being varied since there is a lack of previous research regarding these combinations (which in a realistic case are most probable). Another important characteristic of the experiment is the distance between the double-Tee junction that was varied as 5.6D, 10D, and 15D (where D is the diameter of the pipes). All of the relevant specifications of the experiment are summarized in Table 1.

CFD Model
A CFD approach was used as both a comparison of efficiency with the ML approach and a dataset generator for ML algorithms. The open-source CFD toolbox OpenFOAM [36] was used to model the mixing phenomena as it was previously proven to work well for the given problem. The isothermal 3D steady Reynolds-Averaged Navier-Stokes (RANS) equations with the passive scalar transport model and the k-Epsilon (k-) turbulence model were solved, where k represents the turbulence kinetic energy and is the turbulence energy dissipation. The passive scalar transport model is defined as: In Equation (3), parameter c represents a dimensionless scalar value, set as c = 0 for distilled water and c = 1 for tap water as it represents the tracer in pipes; D t is the turbulent diffusivity defined by Equation (4); and v represents the advection velocity vector. Equation (3) can be physically interpreted as transport of a scalar quantity c by the fluid flow, which is resolved by the coupled RANS/(k-) model. The additional passive scalar transport model in Equation (3) was coupled with the steady-state turbulent OpenFOAM solver simpleFoam making it a new fluid flow solver referred to as tracerFoam. Equation (4) is essential for modeling mixing phenomena as the turbulent Schmidt number S ct needs to be calibrated. According to the results of the previous study [12], S ct was defined as S ct = 0.5. As for other parameters, D mol is the molecular diffusivity of water (set as D mol = 1.7 × 10 −9 m 2 /s [37]), ν t represents the kinematic eddy viscosity, and the constant C µ was set to C µ = 0.09.
A bounded second-order upwind-biased scheme was used for the divergence terms of the model, while for the gradient terms the central difference scheme was used. The fluid used for all simulation runs was water with kinematic viscosity of ν = 1 × 10 −6 m 2 /s.
A uniform value for velocity v was defined at pipe inlets and outlets and a no-slip boundary condition was defined at the pipe walls. The values of v were set at the pipe inlets and pipe outlets to form an exact ratio of both R q in and R q out for all cases (0.333, 0.5, 1, and 2). Pressure p = 0 was defined at outlet pipe 4 and zero pressure gradient in the normal direction was defined on the inlets, outlet pipe 3, and pipe walls. The concentration c was fixed at the inlets (c = 1 for inlet pipe 1 and c = 0 for inlet pipe 2), while, at the outlets and pipe walls, the derivative of concentration in the normal direction was set to zero. Additionally, the value of c was monitored at outlet pipe 3, and, to achieve a steady state regime, it had a convergence criterion of 10 −5 . For the (k-) turbulence model, the values of k and at inlets and outlets were defined the same way as for c except at the pipe walls, where turbulence wall functions were used. Boundary conditions used in the numerical model are summarized in Table 2. Table 2. Boundary conditions for the passive scalar model.

Variable
Inlets Firstly, to use it as a dataset generator, the CFD model was validated with the previously obtained experimental data. A mesh independence study was done to find the optimal mesh sizes for data generation. Each distance between the double-Tee junctions yielded a differently sized mesh, with greater distances requiring more cells. The CFD approach mesh independence was validated with R q in equal to 1 and with equal flow at outlet pipes (R q out equal to 1) for all of the above-mentioned distances ( Table 1). The grid convergence residual criterion was set to 10 −5 for Equation (3). Meshes used in the mesh independence study can be seen in Table 3 where the average cell size ranged from 1.2 to 0.5 mm, while the summary of the mesh independence study is presented in Table 4 where R c is the branch outlet pipe to main inlet pipe conductivity ratio. For ML model data generation, the fine mesh was chosen.

CFD Data Generation
After the mesh independence study was completed and the numerical model was validated, CFD was used to generate data for ML. As it was defined in the experiment, the value of the inlet pipe flow ratio in Equation (2) was varied with the outlet pipe flow ratio, which is defined in Equation (6), where Q 3 is the main pipe 3 outlet flow and Q 4 is the branch pipe 4 outlet flow.
For an array of R q in and R q out , the value of R c was obtained (R c CFD ). The ratios were all possible combinations of 0.333, 0.5, 1, 2, and 3 between the inlet pipes and the outlet pipes (e.g., R q in set as 2 and R q out as 0.333, R q in = 1 and R q out = 2, or R q in = 0.333 and R q out = 0.5).
This was conducted for all distances (5.6D, 10D, and 15D), comprising a total of 75 simulations on the fine mesh (25 simulations per distance).

Artificial Neural Networks
Both an Artificial Neural Network (ANN) and Support Vector Regression (SVR) were used to train a model which predicts the behavior of mixing in a double-Tee junction case. For both methods, the input and output data were split as 70% for model training and 30% for model accuracy testing.
Generally, ANNs are a type of ML algorithms that are used to model complex phenomena, which are not as easy to model using conventional data analysis methods. The type of ANNs used in this study are Feedforward Multilayer Perceptron Neural Networks. This type of ANN is constructed using an input layer, which is usually data that cause the emergence of complex phenomena modeled, one or more hidden layers, and one output layer, which is usually the outcome of the complex phenomena. Layers consist of artificial neurons and a link exists between every layer of the ANN. Training an ANN is the process of fitting the weights of the artificial neuron links so that for each input datum a path of links is made to a certain output. Further information on ANNs can be found in the literature [38].
In this study, three hidden layers were added between the input and output layers and between every layer a dense connection was defined. The input layer consisted of three different data, the inlet pipe flow ratio R q in , the outlet pipe flow ratio R q out , and distance between the double-Tee junctions (5.6D, 10D, and 15D). The first hidden layer consisted of 50 neurons, both the second and third hidden layer consisted of 25 neurons, and all hidden layers used the rectifier activation function. The output layer was the value of Equation (1) or R c ANN . The sigmoid activation function was used at the output layer. The layer configuration is summarized in Table 5.
The ANN was trained using the ADAM optimizer [39] for 500 epochs with the binary cross-entropy loss function for error modeling. Initial weights of each layer link was randomized. The ANN was implemented in the Python Neural Network library Keras [40].

Support Vector Regression
SVR can be considered as a special case of Support Vector Machine (SVM) models. SVMs can be used for both classification and regression problems and SVR would obviously belong to a family of algorithms used to create regression models. The SVR model is given training data in the form of inputs and outputs and it learns the relationship between the data. The inputs are n-dimensional vectors and the outputs are continuous values (unlike in classification problems). The input-output dependency or mapping is approximated using kernel functions and weights. Similar to in ANNs where the link weights are being fitted, the weights in SVR models are also fitted. In the process of learning, a hyperplane is created between the n-dimensional data along with error planes. The main goal is to find the data (or the support vectors) that are within the error margin. A further description of SVR can be found in the literature [41].
The data input and output values were the same as the ones for the ANN (defined in Section 2.3.1). A fifth-degree radial basis function (RBF) kernel was used for the model, a tolerance of 0.001 (which is the model fitting stopping criterion), an of 0.0001 (which specifies the error margin), and a penalty parameter equal to 3 (which is enforced for values outside the error margin). SVR was implemented in the Python ML library Scikit-learn [42].

CFD Results and Efficiency
The CFD analysis was done for 75 different scenarios by varying R q in , R q out , and three distances (5.6D, 10D, and 15D). The CFD simulation with R q in equal to 0.333, 0.5, 2, and 3 and R q out equal to 1 were compared with the experimental values to make sure that the procedure is valid and that a CFD model can be used as a data generator for ML (simulation results for R q in equal to 1 are previously given in Section 2.2.2). The results are summarized in Table 6. For the distance of 5.6D between double-Tee junctions, the root-mean-square error (RMSE) is 0.0214 with the minimum relative error being +0.3% and the maximum relative error −10% between the experimental and CFD values of R c . The distance of 10D had the RMSE of 0.0246, the minimum relative error of experimental and CFD R c as −3.05%, and the maximum relative error +11%. For the 15D distance, the RMSE is 0.013 with minimum relative error as 0.9% and maximum relative error 8.9%. The error results are summarized in Table 7. It can be seen that the error of the CFD model for the 15D distance is the lowest one. This can be attributed to a larger distance between double-Tees since the mixture is already averaged enough (and closer to complete mixing) across the pipe cross section before it is transported into the diverging pipes where, arguably, the most complex eddying of flow is happening. At smaller distances, that averaging of concentration before the diverging pipe is less visible. This can be seen in Figure 2 where Figure 2a is the concentration in the pipe cross section at 1.67D before the branch pipe 4 center-line for 5.6D distance, Figure 2b represents the same but for the 10D distance, and Figure 2c shows results for 15D. In Figure 2d, the modeled kinetic energy of turbulence is shown and it is the highest at the entrance of branch pipe 4, which could be the cause of a slightly higher error for smaller distances. Overall, the errors are acceptable and CFD proved to be a viable tool in modeling this phenomena. Even though the CFD method used provides a good model for mixing phenomena in double-Tee junctions, there is still a problem of computational efficiency. All simulations (for the fine mesh that ranged from approximately 1.8 to 3 million cells) were done using the BURA supercomputer resources at the University of Rijeka. All runs were executed in parallel on 8 Intel E5 nodes with 20 threads per node resulting in 160 processes in total. The computational run times (until the residual of Equation (3) fell below 10 −5 ) for each case is summarized in Table 8. Taking into account that these results were obtained with a supercomputer on 160 Intel E5 cores, this methodology is very inefficient if employed on an personal computer, especially since a lot of computation is necessary for a large variety of possible combinations of inlet pipe flows, outlet pipe flows, and distances between double-Tee junctions.

Models' Training and Testing
Of the 75 obtained simulation results, 70% were used for model training, and 30% were used for the purpose of model accuracy testing for both ANN and SVR since this train-to-test ratio provides that the training dataset should include all possible patterns used for defining the problem and should extend to the edge of the modeling domain. Both models were tested 10 times with randomly selected input data and the models with the minimum RMSE value of the test data were adopted and used further (both ML models RMSE varied for around 0.008 between the minimum and maximum value). The CFD obtained results were taken to be exact (since they exhibit a good agreement with the experimental results based on the average RMSE) and ANN and SVR model results were compared with them to examine their accuracy. For the same data inputs (R q in , R q out , and distance), the ANN model performed better than the SVR model regarding the accuracy of the testing data (predictions of R c ). The RMSE of ANN predictions was 0.0172 while for SVR it was 0.0361 with the maximum error of 0.0427 for ANN and 0.119 for SVR. The results of training data predictions are summarized in Table 9 while a detailed comparison of predicted data can be seen in Table 10. Table 9. Accuracy metrics of ANN and SVR models. The values of R c SVR (SVR predicted R c ) and R c ANN (ANN predicted R c ) in Table 10, which were obtained from the 30% of the input dataset, in bold better predict the CFD modeled values R c CFD , which serve as correct results of mixing behavior. ANN had a better prediction than SVR for 14 out of 23 input data values but for the other 9 predictions it was also quite close to the CFD modeled values. Overall, both models exhibit solid accuracy for predicting the input data even though ANN would obviously be a better choice for further examination.

R c Prediction for Other Double-Tee Distances
Another useful test was done on the ANN and SVR models, which is the prediction of R c for distances that were not in the input training data. The chosen distances were 7.5D and 12.5D since they are in between the training data values (5.6D, 10D, and 15D). The results of the 7.5D and 12.5D tests can be seen in Table 11 and again the results in bold are the ones that agree better with the CFD prediction. After testing the prediction on different double-Tee junction distances (which were not included in the training data), it is obvious that ANN greatly outperforms SVR on this task. Henceforth, further double-Tee mixing ML analysis (of a whole range of R q in and R q out values) was only done using ANN.

R c Prediction for a Range of R q in and R q out with ANN
A prediction of a range of possible combinations of inlet pipe flow and outflow ratios was done, albeit on a range that is still inside the minimum and maximum values of R q in , R q out (from 0.333 to 3), and the distance of the training model, thus no extrapolation of data was done. The purpose of this test was to obtain the whole R q in -R q out surface for a given distance between the double-Tee junction. Before extracting the surface data from the ANN model, which show mixing behavior for the whole array of R q in and R q out , an additional check of validity of the ANN model was performed for a R q in = 1.3 and R q out = 1 since the testing data were done only for R q in and R q out of 0.333, 0.5, 1, 2, and 3. The CFD model result R c CFD was 0.706 while the R c ANN was 0.681, which corresponds to an error of +3.54% when R c CFD is considered to be the exact value. Figures 3-5 show the predicted values of R c by ANN for the distances 5.6D, 10D, and 15D, respectively. Values of R c ANN are represented by color and iso-lines. All three figures show continuous values of R c ANN instead of the discreet ones obtained by CFD and experiments. It can be noticed by comparing the figures that the gradient of R c ANN is smoother (the difference between the minimum and the maximum value is smaller) when the double-Tee distance is increased, which is logical since a much more complete mixing behavior is achieved with an increased distance. Another thing that can be noticed (for all distances) in the figures is that, when both R q in and R q out are increased, the value of R c ANN tends towards 1, which can be interpreted as, when simultaneously both the flow in the main inlet pipe and the main outlet pipe are increasing, the concentration in the main outlet pipe is also increasing, and therefore deviating more from complete mixing. A similar thing happens when both (R q in and R q out ) are decreasing, making the concentration R c ANN lower (it tends towards 0).
Additionally, in Figure 6, a 3D R c ANN plot that contains the surfaces for 5.6D, 10D, and 15D distances is presented to better depict the gradient or the steepness of the surfaces.

On ANN Efficiency
It is hard to quantify the efficiency of the ANN model since it is dependant on previously generated data (either by CFD or experiment) but if a task were to generate, with a trained ANN, the whole range of new values of R c from a range of input values, then it could be argued that ANN is extremely efficient since obtaining R c ANN for 23 input data lasted 0.18 s.

Summary and Conclusions
In this paper, a new methodology for double-Tee junctions mixing modeling is presented based on an experiment from the previous literature. A CFD model was calibrated with the experimental data to serve both as a computational efficiency benchmark and a data-generator for a ML approach for the presented double-Tee junction mixing phenomena assessment problem.
In total, 75 simulations were done by the calibrated CFD RANS kturbulence model and the data were used to train two different ML models. The input variables were defined as the inlet pipe flow ratio, the outlet pipe flow ratio, and distance between the double-Tee junction, while the output was the outlet branch pipe to main inlet pipe conductivity ratio, which is a relevant variable that describes the mixing behavior in a double-Tee junction.
The two tested ML algorithms were Support Vector Regression and Artificial Neural Network (specifically Feedforward Multilayer Perceptron), and, of the two, ANN outperformed SVR in accuracy. Empirical results obtained with the ANN model used show good approximation in predicting the mixing behavior for different distances between double-Tee junctions and inlet/outlet pipe flow ratios.
Besides the accuracy of ANN, it was determined that the computational efficiency of the ANN model is much greater than that of the CFD model, which makes it a great tool for modeling this kind of phenomena. Since many previous studies produced experimental data for a great number of different combinations (which include different Reynolds numbers ranges in pipes, varied pipe diameters, distances between double-Tees, pipe configuration, etc.), a further study could be done to create an ANN that takes into account all of these variables and produces all the relevant parameters to accurately model mixing. With its computational efficiency, a fast model such as ANN could be directly incorporated into complex water network supply pipe network models (such as EPANET and similar), which would greatly improve their accuracy and in turn make them a more powerful tool for predicting water network pollution dispersion and similar hazardous phenomena.