DOI: 10.3303/CET24114110 Paper Received: 30 April 2024; Revised: 19 October 2024; Accepted: 19 November 2024 Please cite this article as: Snopkov D., Radelyuk I., Chin H.H., Tan R.R., Zhapargazinova K., 2024, A Python-Based Tool for Industrial Water Integration, Chemical Engineering Transactions, 114, 655-660 DOI:10.3303/CET24114110 CHEMICAL ENGINEERING TRANSACTIONS VOL. 114, 2024 A publication of The Italian Association of Chemical Engineering Online at www.cetjournal.it Guest Editors: Petar S. Varbanov, Min Zeng, Yee Van Fan, Xuechao Wang Copyright © 2024, AIDIC Servizi S.r.l. ISBN 979-12-81206-12-0; ISSN 2283-9216 A Python-Based Tool for Industrial Water Integration Dmitriy Snopkova, Ivan Radelyuka,*, Hon Huin Chinb, Raymond R. Tanc, Kulshat Zhapargazinovaa aDepartment of Chemistry and Chemical Technology, Toraighyrov University, Pavlodar 140000, Kazakhstan bSustainable Process Integration Laboratory (SPIL), NETME CENTRE, Faculty of Mechanical Engineering, Brno University of Technology – VUT Brno, Brno, Czech Republic cDepartment of Chemical Engineering, De La Salle University, Manila, Philippines radelyuk.i@tou.edu.kz The development and implementation of measures for pollution control and resource optimization play a crucial role in environmental resilience. This work is an attempt to create a standardized Python-based testing environment, which contributes to the challenges related to water conservation. The model is focused on diluting supplied freshwater by sending reused and regenerated water to a particular industrial unit. While existing approaches consider stationary concentrations of contaminants during mixing, our approach overcomes this drawback by the iterative calculation of a newly introduced parameter of “the conditional concentration”. This concept pertains to the efficiency of contaminant elimination within a regeneration unit quantified by the removal ratio. The model consists of two parts: first, it reveals the fixed value for the conditional concentration considering another novel parameter of “the coefficient of conditional concentration”. The coefficient depends on the quality of the reused or regenerated water and determines the appropriateness of a selected stream for the dilution. The second step aims to achieve maximal freshwater minimization by mixing optimal ratios of the selected streams. The model is tested on a real-world case study of the oil refinery in Kazakhstan using the single- contaminant approach. 1. Introduction Water Pinch Analysis, a crucial tool for optimizing water usage and wastewater generation in industrial processes, faces several challenges. Traditional Pinch Analysis, effective for steady-state processes, falls short in dynamic scenarios due to its focus on average values (Dinic and Sharma, 2019). Additionally, in water pinch analysis, addressing fixed concentration problems is vital for minimizing water usage and wastewater generation (Parand et al., 2014). One of the known approaches to tackle this issue is the utilization of the Extended Composite Table Algorithm and Composite Matrix Algorithm to target minimum freshwater, regenerated water flow rates, and wastewater flow rates while considering fixed post-regeneration concentrations (Foo, 2009). Limitations related to the fixed values of both flowrates and concentrations of contaminants still persist in water pinch analysis. The ratio of sink concentration to source concentration plays a crucial role in determining the preferred source ranking for a specific sink (Chin et al., 2020). Further research is needed to address scenarios where only one contaminant limit is reached for a sink, affecting the overall freshwater target (Chin et al., 2020). Addressing regeneration targeting from a fixed flow rate perspective also presents limitations (Foo, 2009), and a limited flow rate affects the achievement of minimum points in impurity constraints (Duhbaci et al., 2021). Future research may explore advanced methodologies for handling epistemic uncertainties (Pandey and Bandyopadhyay, 2023). Programming offers a promising avenue to adapt Water Pinch Analysis methodologies for optimizing water allocation networks (Tan and Aviso, 2022). This approach enables the visualization of complex water allocation problems and facilitates the synthesis of heat-integrated water networks through algorithmic solutions (Klemeš and Varbanov, 2016). Recent advancements in algorithmic methods for water integration have seen various approaches proposed to optimize water consumption, energy utilization, and regeneration processes (Francisco et al., 2022). 655 The current work aims to cover the gap considering the dynamic and iterative nature of industrial water use, unlike traditional static models with one-time solutions. We propose the model, which iteratively refines all the possible solutions encompassing contaminant concentrations throughout the entire industrial water cycle, including source water, regenerated water, and wastewater. The model extends beyond optimizing freshwater abstraction and provides a more holistic and adaptable solution for efficient and sustainable water management in industrial settings. This work is an attempt to create a standardized Python-based testing environment, which contributes to the described challenges and is tested on a real-world case study of the oil refinery in Kazakhstan using the single-contaminant approach. 2. Methodology The program optimization of streams was developed using a Python programming language and an iterative approach. This program aims to reduce the consumption of freshwater and the discharge of wastewater. The general principle of the program is based on mixing and/or diluting outgoing streams from industrial units and redirecting the diluted streams back to the units. The overall operational scheme of the model and the conceptual framework of the water use processes are presented in Figure 1. Figure 1: The framework of the developed model Key equations introduced into the model are described below. The first step of the model is to calculate the water balance and the contamination mass balance for each industrial unit using the system of Eq.1. The selection of the system of equations is considered based on case-specific conditions and data availability. Water network characteristics can vary significantly, as evidenced by Eqs. 4-7, which illustrate different scenarios. 𝐹𝑖𝑛 ∗ 𝐶𝑚𝑎𝑥 = ∑ 𝐹𝑠𝑢𝑚 𝑧 ∗ 𝐶𝑠𝑢𝑚 𝑧 𝑧 1 (1) 𝐹𝑖𝑛 = ∑ 𝐹𝑠𝑢𝑚 𝑧 𝑧 1 where Fin – required flow for each industrial unit (m3/h); Cmax – maximal allowable concentration for Fin (mg/L); Fz sum – total flow generated by all industrial units (m3/h); Cz sum – concentration in generated mixed wastewater flow (mg/L); z – number of mixed flows, supplied to an industrial unit. 656 The next step is a calculation of input and generated flows, which are mixed and sent for a particular industrial unit, using Equations 2 and 3. 𝐹𝑐𝑓 = 𝐹𝑖𝑛 ∙ (𝐶𝑚𝑎𝑥 − 𝐶𝑖,𝑜𝑢𝑡) 𝐶𝑐𝑓 − 𝐶𝑖,𝑜𝑢𝑡 (2) 𝐹𝑤𝑤 = 𝐹𝑖𝑛 − 𝐹𝑐𝑓 (3) where Fcf – considerably clean water supplied flow (m3/h), which may consist of freshwater, regenerated water, or mixed flows; Fww – generated wastewater flow after each particular unit (m3/h); Ccf – contaminant concentration in supplied water (mg/L); Cww – contaminant concentration in generated wastewater after each particular unit (mg/L). After the identification of initial data of concentrations and volumetric flowrates of the supplied freshwater, the algorithm repeatedly calculates the generated wastewater flow required for the filling of a particular industrial unit by mixing it with freshwater, achieving established parameters. This step is based on calculating Eqs. 4-7, where the only one of Eqs. (4) or (5) is chosen based on the conditions of the unit operation – is there a deficit or proficit of consumed/generated (waste)water? 𝐹𝑤𝑤 = 𝐹𝑐𝑓 ∙ (𝐶𝑐𝑓 − 𝐶𝑚𝑎𝑥) 𝐶𝑚𝑎𝑥 − 𝐶𝑖,𝑜𝑢𝑡 (4) 𝐹𝑐𝑓 = 𝐹𝑤𝑤 ∙ (𝐶𝑚𝑎𝑥 − 𝐶𝑖,𝑜𝑢𝑡) 𝐶𝑐𝑓 − 𝐶𝑚𝑎𝑥 (5) 𝐹𝑖𝑛 𝑛𝑐 = 𝐹𝑤𝑤 + 𝐹𝑐𝑓 (6) 𝑅𝑠𝑡 = 𝐹𝑖𝑛 − 𝐹𝑖𝑛 𝑛𝑐 (7) where Rst indicates the rest of the demanded flow for the operation of a unit in case the flow of mixed freshwater and wastewater flow does not meet the water quality requirements (represented as 𝐹𝑖𝑛 𝑛𝑐). The next step of the algorithm is to calculate the total flow with contamination load of wastewater generated by all industrial units, which is not sent for mixing and direct reuse and goes to the regeneration unit (Eqs. 8-12). The assumption is that the regeneration unit has a limited capacity, where the remaining flow is discharged into the environment. 𝐹𝑠𝑢𝑚,𝑑𝑐 = ∑ 𝐹𝑖 𝑚 𝑖=1 (8) 𝐶𝑠𝑢𝑚,𝑑𝑐 = ∑ 𝐹𝑖 ∗ 𝐶𝑖 𝑚 𝑖=1 𝐹𝑠𝑢𝑚,𝑑𝑐 (9) 𝐹𝑑𝑐 = 𝐹𝑠𝑢𝑚,𝑑𝑐 − 𝐹𝑖𝑛,𝑟𝑒 (10) 𝐶𝑜𝑢𝑡,𝑟𝑒 = 𝐶𝑖 ∙ 𝑘𝑟𝑒 (11) where Fi – the generated wastewater flow sent for regeneration for each industrial unit i; Ci – the concentration of a contaminant in the generated wastewater flow sent for regeneration for each industrial unit i; Fsum,dc – the total flow of generated wastewater; Csum,dc – the concentration of a contaminant in the total generated wastewater flow; m – the number of industrial units; Fdc – the wastewater flow sent for discharge; Fin,re -the wastewater flow sent to the regeneration unit; Сout,re -the concentration of a contaminant in regenerated water, or the conditional concentration; m – number of units; kre – the coefficient of conditional concentration, indicating the efficiency of the regeneration unit. For example, if the coefficient is equal to 0.1 it means that only 90 % of contamination is removed and only 10 % remains. 657 As a final step, the algorithm iteratively recalculates concentrations of the contaminant in all the acting flows according to Eq.12. The algorithm assumes two key points: (i) the concentration of the contaminant in the input flow should be close to the maximally allowable value, and (ii) the concentration of the contaminant in the wastewater sent for regeneration should achieve almost constant value, or the difference should be no more than 0.001% comparatively to previous two iterations of the algorithm performance. 𝐶𝑖,𝑜𝑢𝑡′ = 𝐶𝑖𝑛′ + 𝐶𝑖 (12) Where Ci,out’ – the concentration of the contaminant in the wastewater generated by a particular industrial unit after diluting the modeled flows; Cin’ – the concentration of the contaminant in the supplied mixed water for a particular industrial unit; Ci – the concentration of a contaminant generated during the industrial process. 3. Results The model has been tested using data from a real-world case study of an oil refinery located in the Pavlodar region of Kazakhstan. The historical contamination and legislative loopholes have led to severe contamination of the recipient pond for wastewater from the refinery and related extended groundwater pollution, which has likely existed for decades and spread out on a km scale (Radelyuk et al., 2021). The current wastewater treatment system of the refinery utilizes two parallel treatment lines employing outdated technology. These lines rely solely on a combination of on-site mechanical and biological treatment processes. The mechanical treatment includes oil and sand traps, and flotators facilitating flocculation-coagulation processes. The biological treatment utilizes the activated sludge method. This approach demonstrates limitations due to its inherent simplicity. The system exhibits inefficiencies in removing petroleum hydrocarbons due to their low biodegradability. The high salinity and toxicity of the wastewater further impede the efficacy of the biomass utilized in the activated sludge process. The water use scheme is based on the report by the refinery (POCR, 2023) and considers the maximal loading of the industrial process, corresponding to over 6 Mt/y of crude oil refined, or 685 t/h of crude oil. Detailed data on water quality throughout 2022 were provided by the industry, including average concentrations of specific contaminants in treated wastewater. However, the measurement of these parameters was constrained by a lack of flowmeters and measurement points within the refinery hindered the collection of real-time flow data for specific contaminants in the wastewater streams. To address this limitation, data from Alva-Argaez et al. (2007) and Al-Redhwan et al. (2005) were incorporated. The model optimized the water network for 3 iterations. Table 1 shows the final result displaying the water use data for the refinery’s processing units, including both inputs and outputs. Table 1 displays the water use data for the refinery’s processing units, including both inputs and outputs. Total petroleum hydrocarbons (TPH) were selected as the indicator of an emerging contaminant for the studied refinery (Radelyuk et al., 2019). The wastewater treatment unit can serve as a regeneration unit. Its capacity is assumed to be equal to 100 %, which means that generated wastewater from all industrial units is sent for regeneration during the first stage of the algorithm. As a final result, we obtain Cin,re equal to 3,100 mg/L. The resulting concentration of TPH in regenerated water (Сout,re) is equal to 3 mg/L. Table 1: Characteristics of water demand and contamination generated by industrial units of the studied refinery according to the model performance Unit Unit abbreviation Fin Cmax Cww’ Ffw Fre Atmospheric distillation ADU 38.4 20 1020.0 38.1 Hydrotreating HDS 70 20 319.9 69.6 Gas compression GC 39 100 900.0 37.7 Chimney stack 1 CHS 10 150 350.0 9.5 Vacuum distillation VDU 3.3 0 100.0 3.3 Chimney stack 2 CS 45 150 338.0 42.8 Delayed coking unit DCU 47 100 300.0 45.5 Gas junction GJU 80.1 100 164.9 77.5 Bitumen BU 180 100 3099.9 174.3 Industrial recycling unit RU 75.3 0 25.0 75.3 Drinking water DW 24.2 0 5.0 24.2 Pathways of redistributed flows are presented in Figure 2. As a result of the model performance, the freshwater consumption has been reduced by 83.2 % from 612.3 m3/h to 102.80 m3/h, or by 4,463.220 km3/y. The regenerated water provides 495 m3/h and the rest is supplied by the directly reused water from the bitumen 658 production unit, which consumes and generates the maximal amount of water for the industrial process. The freshwater is supplied to the units of vacuum distillation, industrial recycling unit, and drinking water, where the concentration of the contaminant should be equal to zero. Figure 2: Results of the model performance on the case study 4. Conclusions A Python-based tool for comprehensive optimization of real-world industrial water networks was developed. The iterative framework of the developed model facilitates multiple optimization iterations, effectively mitigating a significant challenge inherent in water integration: the fixed characteristics of processed water flows. As evidenced by the performance of the model, freshwater consumption in the studied case was reduced by 83.2 %. The established and validated water and contaminant mass balances affirm the practical applicability of the proposed algorithm. This result underscores the credibility and practicality of the model. Future work can focus on developing model extensions, such as incorporating its capability to address multiple-contaminant scenarios and integrating additional parameters for energy and cost optimization. Acknowledgments This research was funded by the Science Committee of the Ministry of Science and Higher Education of the Republic of Kazakhstan (Grant No. AP14972725). References Al-Redhwan S.A., Crittenden B.D., Lababidi H.M., 2005, Wastewater minimization under uncertain operational conditions. Computers & Chemical Engineering, 29(5), 1009-1021. Alva-Argáez A., Kokossis A.C., Smith R., 2007, The design of water-using systems in petroleum refining using a water-pinch decomposition. Chemical Engineering Journal, 128(1), 33-46. Pandey A.K., Bandyopadhyay S., 2023, Incorporation of Epistemic Uncertainties in Resource Conservation Networks with Multiple Resources. Chemical Engineering Transactions, 103, 235-240. Chin H.H., Varbanov P.S., Liew P.Y., Klemeš J.J., 2021, Pinch-based targeting methodology for multi- contaminant material recycle/reuse. Chemical Engineering Science, 230, 116129. Dinic J., Sharma V., 2019, Computational analysis of self-similar capillary-driven thinning and pinch-off dynamics during dripping using the volume-of-fluid method. Physics of Fluids, 31(2), 021211. Duhbacı T.B., Özel S., Bulkan S., 2021, Water and energy minimization in industrial processes through mathematical programming: A literature review. Journal of Cleaner Production, 284, 124752. Foo D.C.Y., 2009, State-of-the-art review of pinch analysis techniques for water network synthesis. Industrial & Engineering Chemistry Research, 48(11), 5125-5159. 659 Francisco F.S., Bavar M., Pessoa F.L., Queiroz E.M., Asgharnejad H., Sarrafzadeh M.H., 2022, Developing Water Source Diagram method for effective utilization of regeneration unit in water networks: Multiple- contaminant problems. Journal of Water Process Engineering, 47, 102758. Klemeš J.J., Varbanov P., 2016, Process Integration: Pinch Analysis and Mathematical Programming-Directions for Future Development. Computer Aided Chemical Engineering, 38, 2405-2406. Parand R., Yao H.M., Pareek V., Tadé M.O., 2014, Use of pinch concept to optimize the total water regeneration network. Industrial & Engineering Chemistry Research, 53(8), 3222-3235. POCR, 2023, Report for permissible discharges of POCR LLP for 2023-2025 (in Russian). , accessed 27.04.2024. Radelyuk I., Naseri-Rad M., Hashemi H., Persson M., Berndtsson R., Yelubay M., Tussupova K., 2021, Assessing data-scarce contaminated groundwater sites surrounding petrochemical industries. Environmental Earth Sciences, 80(9), 351. Radelyuk I., Tussupova K., Zhapargazinova K., Yelubay M., Persson M., 2019, Pitfalls of wastewater treatment in oil refinery enterprises in Kazakhstan – a system Approach. Sustainability, 11(6), 1618. Tan R. R., Aviso K. B., 2022, A Bilevel Mixed-Integer Linear Programming Model for Emissions Reduction. Chemical Engineering Transactions, 97, 355-360. 660 https://ecoportal.kz/Public/PubHearings/PublicHearingDetail?hearingId=12322