DOI: 10.3303/CET2291082 Paper Received: 8 February 2022; Revised: 1 April 2022; Accepted: 13 May 2022 Please cite this article as: Tarcsay B.L., Nemeth S., Chovan T., Barkanyi A., 2022, Development of CFD Based Compartment Models for Analysing High Risk Processes, Chemical Engineering Transactions, 91, 487-492 DOI:10.3303/CET2291082 CHEMICAL ENGINEERING TRANSACTIONS VOL. 91, 2022 A publication of The Italian Association of Chemical Engineering Online at www.cetjournal.it Guest Editors: Valerio Cozzani, Bruno Fabiano, Genserik Reniers Copyright © 2022, AIDIC Servizi S.r.l. ISBN 978-88-95608-89-1; ISSN 2283-9216 Development of CFD based Compartment Models for Analysing High Risk Processes Bálint Levente Tarcsay*, Sándor Németh, Tibor Chován, Ágnes Bárkányi Department of Process Engineering, University of Pannonia, 10 Egyetem str., 8200 Veszprém, Hungary tarcsayb@fmt.uni-pannon.hu In recent years the fault detection and isolation (FDI) problems have garnered increasing interest due to concerns of environmental protection, stricter regulations and optimization of processes within industrial settings. The use of data-based methods such as Neural Networks (NNs) for purposes of FDI has received significant research interest in the scientific community. However while these data-driven methods present relatively robust and sensitive means of fault detection and isolation they require large amounts of process data for their training so they can work reliably. Within the chemical industry rather than experimental investigations various modeling techniques such as computational fluid dynamics (CFD) may be used to generate this training data. However many of these methods are computationally expensive and less efficient for producing large data sets. In this paper we wish to present an identification algorithm for the development of compartment models (CM) based on CFD results which can be used to reliably generate process data for FDI purposes in a computationally more efficient way. 1. Introduction In recent decades the optimization of safety conditions and reliable operation of processes even under disturbances has become a focal point of academic research. Proper safety is critical for highly hazardous systems which are for example prone to thermal runaway or highly sensitive to changes in process parameters such as biological systems. Fezai et al. (2021) describe a data-based FDI method to supervise biological systems. Their technique utilizes a Gaussian process regression model to describe system behaviour and abnormalities are detected using generalized likelihood ratio tests. Tarcsay et al (2021a) developed an FDI scheme based on parity relations and fuzzy logic for the isolation of parametric and additive faults within a distillation system. Ait-Izem et al. (2018) explored the use of interval principal component analysis (PCA) for the supervision of a distillation column based on process data. FDI based on statistical methods such as PCA or Neural Networks (NNs) based on the use of process data have gained increased popularity over the years due to their flexibility and easy application. However the necessary amount of data to reliably train these methods is not always available. In such cases process models, in the chemical industry in particular computational fluid dynamics (CFD) methods may be useful to generate the training data. While CFD methods can be used to characterize system behaviour (velocity fields, temperature and concentration gradients, etc.) in explicit detail they are usually computationally expensive and inefficient at generating large amounts of process data. Compartment models (CM) on the other hand are models that approximate the characteristics of a system through a superposition of idealized models thus they are computationally less expensive. However the identification of the CM structure is often times less rigorous, being simply based on the residence time distribution (RTD) function of a unit. To alleviate this in recent years many researchers have begun developing more rigorous approaches to the identification of CM structures, based on CFD results. Examples of this include the work of Krychowska et al. (2020) who created a CFD based CM (CFD-CM) for the description of a bioreactor and validated their model through experimental means. Yang et al. (2019) utilized an identified CFD-CM for optimization of reaction selectivity within a stirred unit. Massmann et al. (2020) used a CFD-CM for the investigation of crystallization in a multi-phase reactor, and identified the CM structure with regards to the population balance model of the crystallization process. The method proposed within this paper is a further developed version of the algorithm proposed by the authors within a 487 previous publication (Tarcsay, 2021b). The method explores the identification of a CFD-CM in a wastewater treatment tank. The process utilizes a segmentation of the explored systems volume and evaluates the flow behavior of the segmented volumes by utilizing fuzzy logic and as a novelty compared to the previous version of the algorithm clustering techniques. Idealized flow characteristics are assigned to the segmented volumes and the individual volumes are later aggregated into compartments with idealized flow behavior through the use of image segmentation techniques. The behavior of the system is then approximated through the network of interconnected compartments with idealized flow behavior. The advantage of the method is twofold. It allows users to integrate empirical knowledge about the systems flow behavior through the fuzzy logic component but also decreases the arbitrary nature of compartmentalization through the clustering process. 2. The proposed algorithm The white-box model of a unit is represented by the mass, component, impulse and heat balance equations of the system. For chemical equipment these balance equations can be simplified for systems with idealized flow behavior such as continuous stirred units (CSTR) or units with plug flow (PFR). These idealized units have unique responses to specific input signals such as the Heaviside (H) or Dirac delta functions. These responses for the Heaviside function are shown in Figure 1.a where t and t* denote time and signal initialization time respectively. Figure 1: Step responses of systems with idealized flow behavior (a), and CFD-CM identification algorithm (b) In developing CMs for various equipment units with idealized flow behavior are connected into a network to produce a system with a step response similar to the original equipment. This however does not take local flow behavior within the system into account. The aim of this work is to elaborate a more rigorous method for the identification of CFD-CMs. The algorithm proposed is a further developed version of an earlier algorithm devised by the authors (Tarcsay, 2021b). Since the newly developed algorithm is being compared to the results of the old version figures utilized for comparison are all referencing the original publication. Figure 1.b displays the steps of the CFD-CM identification algorithm within the previous work (I.) and the currently updated method (II.). While improving the algorithm three goals have been taken into consideration. The first one was the creation of a general algorithm for CFD-CM identification where each compartment can be assigned to a distinct volume of the investigated unit and accurately describes the local velocity field. The second one was to decrease empirical inputs of the model developer and make the method more rigorous and applicable to many different systems. The third one was to develop a reliable means of CM identification that retains the white box characteristics of CFD methods while being computationally inexpensive for data generation to train models for data-based FDI methods. The previous method “I” discussed in the original article, displayed in Figure 1.b utilizes CFD methods to acquire a steady-state velocity field of a unit under known process conditions. Based on the grid used within CFD a set of control volumes with uniform size referred to as elementary cells (EC) were defined and in each of these the local velocity field is evaluated. Quantifiers such as the mean velocity, variance of velocity vectors, etc. have been utilized as inputs to a fuzzy logic rule to measure the CSTR, PFR or dead volume (DV) flow tendency of singular ECs. In the original algorithm each EC was later categorized into one of the three idealized model categories manually based on the weighted average of the three flow behavior measures obtained through fuzzy logic. The ECs with idealized flow behavior were later agglomerated into different compartments within the unit and their volumes were estimated. Crossflow rates between different compartments were optimized through minimizing the 5.II.) Use clustering to determine EC behavior 1.) Steady- state velocity field data 2.) Define Elementary Cells (EC) 3.) Calculate relative velocity moments Algorithm I. or II.? 5.I.) Define manual threshholds for behavior and aggregate ECs 6.) Aggregate compartments using image segmentation Determine flow rates using CFD data 4.) Evaluate measure through fuzzy logic to determine measure of idelalized behvaior I. II. 488 squared difference between the step response of the CFD model and obtained CM structure. In the revised algorithm instead of manual classification of ECs through empirical limits clustering algorithms were applied to determine the idealized flow behavior within each EC. The agglomeration of ECs into clusters was conducted using image segmentation techniques resulting in a more accurate CM structure which is less dependent on the model developer’s expertise. 3. The investigated system To demonstrate the updated algorithm and compare it to its previous version the model system introduced in the original article is used as reference. This is a slightly modified version of a test problem found in the COMSOL Multiphysics 5.2a CFD software (COMSOL, 2016) library. The investigated system is a wastewater treatment tank whose construction can be seen in Figure 2.a. Through CFD methods the velocity field and concentration field within the unit has been approximated for steady state parameters provided in the original article, this is displayed in Figure 2.b. The boundary and initial conditions belonging to the observed steady- state are shown in Table 1. The calculations have been conducted under isothermal operating conditions, with the observed flow medium being water and an isotropic diffusion coefficient of 10-4 m s-2. During the calculations only convective and conductive flow has been taken into account. Figure 2: Geometry of the investigated system (a), velocity field (m s-1) within the investigated system (b) Table 1: Initial and boundary conditions within the system Initial velocity within the unit (m s-1) Initial tracer concentration (mol m-3) Inlet velocity (m s-1) Inlet tracer concentration (mol m-3) Outlet boundary pressure (kPa) 0 0 0.1 2 101.3 4. Results The updated algorithm was tested and compared to the original version. The results will be displayed in the following. The steps up to generating the fuzzy measure for classification are the same for both algorithms and are performed according to the original article where the results are visualized. The next step in the new algorithm included characterizing each EC as one of the pure idealized flow model categories PFR, CSTR or DV based on the measures obtained from fuzzy logic through the use of clustering. The clustering was conducted in MATLAB R2021b. Various distance measures have been tested to classify the ECs and their performances have been compared. To evaluate which distance measure is best suited for the classification of the ECs into the three categories the average silhouette value of the clustering for each measure has been calculated. The silhouette score of a data point during clustering is a metric used to characterize the goodness of fit of a given point into its assigned cluster. This is done in accordance with Eq(2) where s(i) is the silhouette value of a given data point i. 𝑠 𝑖 = 𝑔(𝑖) − 𝑓(𝑖) 𝑚𝑎𝑥 𝑔 𝑖 , 𝑓(𝑖) , 𝑖𝑓 𝐶𝐼 > 1 0, 𝑖𝑓 𝐶𝐼 = 1 (2) The terms g(i) and f(i) refer to the mean distance of data point i from the points within its closest neighbouring cluster and data points of its own cluster respectively, where CI is the number of points within the cluster of the observed point i. The silhouette score has a range of [-1,1], where a value of “-1” denotes a point which lies close to its neighbouring cluster and relatively far from points of its own cluster while a score of “1” means that 489 the point i is on average far from the points of its neighbouring cluster and close to its own clusters points. The average of the silhouette scores was calculated for four methods available within the MATLAB R2021b framework. Based on the results the “sqeuclidean” distance metric which uses standardized Euclidean distance for clustering has the best performance with an average silhouette score of 0.79. The clustering of the points is visualized in Figure 3.a, while the silhouette plot of the clustering can be seen in Figure 3.b with clusters “0”, “1” and “2” corresponding to idealized DV, CSTR and PFR behavior respectively. Figure 3: Clusters of idealized behavior (a) and silhouette values for the clustering (b) It can be seen in Figure 3.a that the clustering can reliably separate the different ECs based on the flow behavior they exhibit. The idealized EC structure within the tank obtained through clustering can be observed in Figure 4.a while Figure 4.b shows the idealized EC structure based on the limit checking approach used in the previous algorithm for comparison. Figure 4: EC structure based on the updated (a) and the original algorithm (b) By comparing the idealized EC structure for the two methods the following conclusions can be drawn. It can be seen that the general EC structure in both cases is similar for areas with large dead-volumes present and for areas with clear mixed or plug flow characteristics especially near the inlet and outlet positions. Major differences however can be observed in the area between the two bafflers where the updated algorithm classifies the flow as mostly plug flow, while the old algorithm approximates regimes with strong mixed flow. The results of the updated algorithm are more in accordance with the flow behavior that can be observed in Figure 2.b. A unidirectional flow can be seen between the two bafflers which connects the inlet and outlet boundaries that shows stronger PFR than CSTR tendencies. The next step is the agglomeration of individual ECs into continuous compartments with uniform, idealized flow behavior. In the previous version of the algorithm this process was done in a purely manual fashion. After the update the agglomeration step is conducted automatically by using image segmentation techniques on the obtained figure representing the idealized behavior of ECs (Figure 4.a). The three characteristic colors denoting each flow behavior (PFR- yellow, CSTR-green, DV-blue) have been identified based on color thresholds and segmented from the rest of the regions. For each ideal flow type the volumes where the currently observed flow type is present have been identified and ordered into clusters. The volume of each of these compartments has been calculated based on the total number of pixels within the defined cluster. It can be observed in Figure 4.a that there are ECs which stand alone, in order to avoid denoting these as individual compartments the resulting compartment structure was checked. If a compartment had a small volume compared to the total liquid volume within the tank 490 (less than 5% of the volume) the respective compartment is merged into the closest compartment with a valid volume that has the same idealized flow characteristic. The contour image of the idealized flow behavior can be seen in Figure 5.a, while the image segmentation for the DV volumes can be seen in Figure 5.b. The individual compartments are denoted by red circles, where the effective volume of the compartments is proportional to the radii of the circles drawn around the compartment centroids. Figure 5: Contour plot of the EC structure (a), the segmented images of the DV regions (b) Through the image segmentation procedure the compartment structure was obtained and evaluated. The optimal structure was determined to contain five compartments, three DV, one PFR and one CSTR compartment. This is a decrease in number of compartments compared to the results of the previous algorithm where seven compartments were deemed necessary for the approximation. The connections between different compartments have been evaluated based on the effective radii of the evaluated compartments and their centroid locations. Figure 6.b shows the CM structure based on the old algorithm, while Figure 6.a shows the structure based on the new algorithm. Figure 6: CM structures based on the new (a) and old algorithms (b) In the new algorithm the CM structure includes fewer compartments than in the original version that allows for easier and more compact model with reduced calculation times. To calculate the cross flow rates between different compartments (α) similarly to the previous version of the algorithm an optimization process was used. The CM structure has been built in Simulink environment and the idealized units have been represented through their differential equations. The resulting system of partial differential equations was solved numerically by the Rosenbrock algorithm. The step response of the system has been obtained through CFD methods and through the use of CM and the α parameters have been optimized through the method of interior points with regards to minimizing the squared difference between the step responses of the CFD and CM. The results of the optimization and the calculated α parameters for the new algorithm are shown in Figure 7.a., the step response of the system for CFD methods and the CMs obtained both for the new and old algorithms are shown in Figure 7.b. 491 Figure 7: The results of the optimization process (a) and the step response function of the system based on the CFD method and the original (I) and updated algorithm (II) (b) As can be seen in Figure 7 the new CM structure results after optimization leads to a similar result for approximating the step response of the system compared to the older algorithm while having a smaller compartment number and thus being computationally less expensive. The squared sum of differences between the step response of the CFD and CM for the updated algorithm was 8% less compared to the original method. This shows that the new algorithm produces a CM with less compartments, more realistic structure along a better fit to the CFD methods. 5. Conclusions In this paper an updated version of an algorithm has been introduced which can be utilized to generate a CFD-CM for a physical system. The original algorithm evaluated arbitrarily small volumes (EC) within the unit. In the previous iteration of the algorithm the identified ECs were classified into an idealized flow pattern based on limit checking of the average of the idealized flow measures obtained through fuzzy logic then agglomerated manually and a compartment structure was established based on visual inspection. In the new algorithm the EC classification was done using a clustering algorithm, the agglomeration of ECs was conducted through the use of image segmentation techniques to reduce subjectivity within the CM development. The updated algorithm had several advantages, including smaller compartment number for the approximation with one less compartment than the previous version, 8% better fit of the step response to the CFD data and 6% decreased calculation time. Acknowledgments This work was supported by the TKP2020-NKA-10 project financed under the 2020-4.1.1-TKP2020 Thematic Excellence Programme by the National Research, Development and Innovation Fund of Hungary. References Ait-Izem T., Harkat M. F., Djeghaba M., Kratz F., 2018, On the application of interval PCA to process monitoring: A robust strategy for sensor FDI with new efficient control statistics, Journal of Process Control, 63, 29-46. COMSOL Multiphysics v 5.2a, 2016, COMSOL < comsol.com/release/5.2a> accessed 17.02.2022. Fezai R., Abodayeh K., Mansouri M., Nounou H., Nounou M., 2021, Fault diagnosis of biological systems using improved machine learning technique, International Journal of Machine Learning and Cybernetics, 12(2), 515-528. Krychowska A., Kordas M., Konopacki M., Grygorcewicz B., Musik D., Wójcik K., Rakoczy, R., 2020, Mathematical Modeling of Hydrodynamics in Bioreactor by Means of CFD-Based Compartment Model, Processes, 8(10), 1301. Massmann T., Kocks C., Parakenings L., Weber B., Jupke A., 2020, Two-Dimensional CFD based compartment modeling for dynamic simulation of semi-batch crystallization processes in stirred tank reactors, Computers & Chemical Engineering, 140, 106933. Tarcsay B. L., Németh S., Chován T., Bárkányi Á., 2021, Hybrid Fault Detection Method for a Distillation Unit, Chemical Engineering Transactions, 88, 391-396. Tarcsay B. L., Bárkányi Á., Chován T., Németh S., 2021, Development of Compartment Models for Diagnostic Purposes, Hungarian Journal of Industry and Chemistry, 49(1), 47-58. Yang S., Kiang S., Farzan P., Ierapetritou M., 2019, Optimization of reaction selectivity using CFD-based compartmental modeling and surrogate-based optimization, Processes, 7(1), 9. 492 130tarcsay.pdf Development of CFD based Compartment Models for Analysing High Risk Processes