Introduction

In the past years, strict standards and laws have been considered in relation to the effluent of wastewater treatment plants (WWTPs) with the aim of protecting the environment and improving the quality of water resources (Chen et al. 2020; Lu et al. 2019; Qu et al. 2019; Xu et al. 2020). Despite the available standards, a significant percentage of WWTPs are not able to meet them in practice, and due to the growth of urban areas and the increase in wastewater production, and they are usually overloaded in developed countries (Rustum 2009). The construction of a WWTP is very expensive and time-consuming, while improving its performance, if done properly, in addition to improving the quality of effluent and meeting standards, leads to a reduction in operation costs (Ye et al. 2019; Olsson and Newell 2005).

Due to the complexities of WWTP operation, improving the operation and control of wastewater treatment systems will not be possible with usual management methods and decisions based on experience (Pu and Hung 1995). Therefore, in recent years, the use of mathematical models to simulate WWTP processes has become common. Modeling is an important tool to design, operation, and optimization of a WWTP (Muoio et al. 2019; Mu’azu et al. 2020). The objectives of WWTP modeling include design, analysis, forecasting, optimization, and control (Hulsbeek et al. 2002; Petersen et al. 2002; Szilveszter et al. 2010). By using modeling, the mechanisms that occur in wastewater treatment processes are well understood (Muoio et al. 2019), and it is possible to analyze and predict the behavior of WWTP for different design scenarios and operation strategies without any need to conduct physical model (Hvala et al. 2018; Muoio et al. 2019; Olsson and Newell 2005; Szilveszter et al. 2010). Therefore, by using the model and analysis of different operation strategies, it is possible to respond quickly to changes in influent characteristics and processes and choose the best possible operation strategy to improve the quality of effluent and at the same time reduce the operation costs (Rivas et al. 2008; Araromi et al. 2018).

Proper management and operation of wastewater treatment plants are necessary to achieve the sustainable goals of WWTPs (Silva et al. 2014). For this reason, various studies have been conducted in recent years to analyze and optimize the performance of wastewater treatment systems. The issue that has been considered more in the evaluation of the performance of WWTPs is the efficiency of removing pollutants such as chemical oxygen demand (COD), total suspended solids (TSS), and nutrients. Mines et al. (2014) studied 24 WWTPs with an influent of more than 38,000 m3/day over a period of 1 year. In this study, the removal efficiency of pollutants was determined for each WWTP based on the collected qualitative data and the operating conditions of the system. There are other similar studies that have used the removal efficiency of qualitative parameters to evaluate system performance (Rodriguez-Garcia et al. 2011; Li et al. 2012; Özkan et al. 2012).

Borzooei et al.)2019) simulated the water and sludge lines of a WWTP in GPS-X software, and optimized its performance. In this study, to evaluate the performance of the WWTP under different scenarios, two criteria were considered: the quality of the effluent and the amount of energy consumed. Qiao and Zhang)2018) used aeration energy, pumping energy, and effluent quality criteria for dynamic optimization of a WWTP and adjusting the dissolved oxygen (DO) and nitrogen levels in the system. Canete et al.)2021) proposed a control strategy based on machine learning to optimize the consumption and the number of violations in a WWTP. In this study, they used two criteria of effluent quality index and operational cost function for optimization. Tejaswini et al. (2021) used performance index (PI) controllers to achieve better effluent quality with minimum operation costs, and Benchmark Simulation Model No. 1 (BSM1) was used as the working platform. In this study, the system is optimized considering effluent quality and operation cost criteria.

In a different approach, some researchers used overall efficiency indicators (Colmenarejo et al. 2006) or integrated efficiency (Jamwal et al. 2009) to compare the performance of WWTPs. In this approach, instead of determining the removal efficiency for different quality parameters separately, the average removal efficiency of these parameters is used. Muga and Mihelcic (2008) and Balmér and Hellström (2012) developed a PI system for WWTPs that included the removal efficiency of key quality parameters such as TSS, COD, nutrients, and pathogens.

Optimization is one of the most important factors in the optimal management of the WWTP, which is achieved by searching for the optimal condition of processes (Muoio et al. 2019). Guerrero et al. (2011) simulated the WWTP with the A2O (anaerobic/anoxic/oxic) process on a laboratory scale with the ASM2d (Activated Sludge Model No. 2d) model (one of the ASM family models with the ability to model the removal of phosphorus and nitrogen) and improved the performance of system by optimizing the amount of nitrate return to anoxic tank and the amount of DO in the aeration tank. In this study, the removal efficiency of carbon and nutrient compounds was considered as the goal of improving performance, and various control strategies were investigated to optimize the performance. In Khan et al. (2019), the performance of column-SBR (sequencing batch reactor) in paper and pulp wastewater treatment was optimized and analyzed for maximizing COD and AOX (adsorbable organohalides) removal. In this study, the process parameters viz; pH, initial COD, cycle time, and mixed liquor suspended solids (MLSS) were optimized, and their effects on response variables including COD removal efficiency, AOX removal efficiency, and SVI (Sludge volume index) were investigated. Descoins et al. (2012) studied the optimization of activated sludge and aerobic digester process in a WWTP. The treatment process was statically simulated. The energy consumption of physical units was evaluated as well as the relationship between biological activities and the amount of energy produced and consumed in the system. Finally, by examining the effective factors, approaches were proposed for making the WWTP independent in terms of energy. Zhang et al. (2014) using a multi-criteria optimization algorithm, optimized the effluent quality and operating costs of a WWTP in China. In this study, system simulation was done based on several sets of effluent quality and operation cost decision variables. The results indicated that the optimization of the system by considering a set of decision variables gives better results, compared to the state that it is optimized based on each qualitative variable. Various operation parameters that have been considered in past studies to optimization of the WWTP are summarized in Table 1.

Table 1 Operation parameters that have been used in literature for optimization of WWTPs

The influent characteristics are one of the effective factors in the performance of WWTP. In literature, the majority of studies have focused on the evaluation of the system’s ability to meet the effluent standards, and less has been done on the effect of influent characteristics such as flow rate, ammonium, and COD on the performance of WWTP. Thus, the main goal of this research is to develop a scheme for considering the influent condition in system operation control. For this purpose, a new approach has been presented to optimize the WWTP performance in the face of various conditions of influent by modeling and evaluating the performance of different units of WWTP. In the proposed approach, the influent condition is recognized based on predefined groups and the appropriate strategies of system operation are applied regarding it. This will highly improve the WWTP effluent quality in addition to making it easier for WWTP operators to determine the optimal system operation.

Case study

South of Tehran WWTP located in Tehran, the capital of Iran has been considered as a case study. South of Tehran WWTP is designed to treat a part of Tehran city wastewater in 8 modules covering about 4.2 million people. The first four modules of this WWTP have been investigated in this research that covers a population of 2.1 million people with an influent of 450,000 m3/day. The wastewater treatment system of the South of Tehran WWTP is activated sludge with nitrogen removal (Tabesh et al. 2018). The process units of South of Tehran WWTP include primary treatment, biological treatment, sludge treatment, and treatment of produced biogas in digesters. The schematic layout of the South of Tehran WWTP is presented in Fig. 1.

Fig. 1
figure 1

The schematic layout of the South of Tehran WWTP

Data collection

For the modeling and calibration of the WWTP simulation model, various data such as design and operation data, stoichiometric parameters, and qualitative and quantitative data of influent and effluent are needed (Petersen et al. 2002). Table 2 shows the details of sampling and qualitative tests during the data collection periods. In Table 3, total and soluble COD values of influent and effluent are presented. Using the COD values and according to the STOWA (Foundation for Applied Water Research) protocol (Hulsbeek et al. 2002), different components of COD are calculated. COD components and the organic nitrogen conversion factors (based on the coefficients presented in the STOWA protocol) are presented in Table 3. The STOWA protocol is one of the common protocols for simulating the wastewater treatment process and model calibration. STOWA has been used in modeling the process of more than 100 WWTPs (Roeleveld and Loosdrecht 2002).

Table 2 The details of sampling and qualitative tests during the data collection periods
Table 3 COD values of influent and effluent;, the proportions of COD components and the organic nitrogen conversion factors

Methodology

The modeling of WWTP processes consists of several steps (Hulsbeek et al. 2002; Rieger et al. 2013). The steps considered in this research based on the developed approach, are presented in Fig. 2. To ensure the acceptable performance of the simulation model, the mentioned steps should be followed sequentially considering the system characteristics as well as study objectives. Based on the proposed framework, the goal of the research is determined first, then the boundaries of the system for simulation are determined. After that, by choosing the appropriate software for simulating WWTP, proper modeling theories are selected for different units of WWTP based on the modeling goals and available data. In the next step, to make it possible for the simulation model to well simulate the behavior of the system in different operational conditions, the model calibration is done based on the STOWA protocol. After calibration and validation of the model, in order to determine the appropriate operation strategy of the WWTP, it is necessary to distinguish different situations that the WWTP faces. Therefore, the influent is classified based on its characteristics using the k-means method. In the last step, optimization models are used to determine the optimal values of operational parameters that maximize system performance regarding different classes of influent.

Fig. 2
figure 2

The proposed method for optimal operation of WWTP considering the changes in influent

Step 1: determining the goals

The main goal of this study is to present a model for the optimal operation of the WWTP considering the quantitative and qualitative changes of the influent. In this study, improving the quality of the effluent by reducing the COD, NH4, and NO3 is considered a measure of performance efficiency. For this purpose, operational parameters that affect the system performance will be optimized to reach the best effluent quality. In this study, according to operation parameters that have been used in literature for the optimization of WWTPs (Table 1), the concentration of DO in the aeration tank, the amount of sludge removed from the system, and the ratio of the supernatant flow rate of the sludge dewatering unit to the effluent flow rate, which have been commonly used in previous studies for WWTP operation optimization are considered as operating parameters that need optimization.

Step 2: selection of model boundaries

SUMO WWTP simulation software

In this study, SUMO software was used to simulate WWTP. SUMO is officially presented by Dynamita company in 2017. In addition to the usual wastewater treatment models such as the ASM family models, there are more advanced models focusing on the removal of various compounds such as nitrogen, sulfur, and phosphorus in this software. Also, models with the capability of plant-wide simulation of the WWTP (water and sludge line at the same time) have been presented in the form of sumo1 and sumo2 models. High speed in program running and the possibility of communicating with different programming languages are considered important advantages of this software, compared to other existing software (Liang et al. 2021).

Model boundary

According to the objectives of this study, the water line and the sludge line were considered in the simulation procedure while the biogas line was omitted. Since the design of modules 1 to 4 of WWTP are similar and they are operated in the same way, only one module is used for simulation, and this approach is also used in other studies such as Roeleveld and Loosdrecht (2002). This increases the speed of SUMO software in the simulation of WWTP. Also, at this stage, the placement and connection of wastewater treatment units, influent, effluent, and internal flows in the system are determined. The plan of the South of Tehran WWTP and the connection of units in SUMO software are presented in Fig. 3.

Fig. 3
figure 3

The plan of South of Tehran WWTP and the connection of different units in SUMO software

Step 3: selection of the process models

The appropriate process models for the operational units of WWTP are selected, considering the modeling objectives and available laboratory data among available models in SUMO. SUMO software has presented sumo1 and sumo2 models for simulation of activated sludge process and sludge stabilization in an anaerobic digester. Effective microorganisms in the processes of removal of organic compounds, nitrification, and denitrification, which is one of the modeling goals of this study, are the same for sumo1 and ASM1 models (Dynamita 2016). Therefore, sumo1 model has been used to simulate the process of activated sludge and stabilization of sludge in an anaerobic digester.

In this study, the simulated model of the WWTP is also evaluated in critical conditions such as increasing the influent. Therefore, it is necessary to accurately simulate the sedimentation process in primary and secondary settling units. On the other hand, the Takacs sedimentation model (Takacs et al. 1991) is the most widely used in studies related to the design and operational optimization of the secondary settler unit and has very good accuracy (Vanrolleghem et al. 1996; Hreiz et al. 2015). Therefore, in this study, the Takacs sedimentation model is used. Also, in this study, as (Vrecko et al. 2006), the model that is selected for gravity and mechanical thickeners and sludge dewatering is the ideal point-settler.

In the initial version of SUMO software, there is no trickling filter unit, whose process is the type of attached growth and biofilm. For this reason, MBBR (moving bed biofilm reactor) has been used to simulate the trickling filter unit. The use of MBBR unit instead of the trickling filter unit has been confirmed in correspondence with the SUMO software developers. In order to use the MBBR instead of the trickling filter, changes have been made to the MBBR characteristics. For example, the filling material characteristics of the trickling filter have been used in MBBR.

Step 4: calibration and validation

In this study, the calibration of the WWTP model is done automatically using an optimization algorithm. Therefore, a connection is established between the simulation model of the wastewater treatment process and the AMOEA-MAP (archived-based multi-objective evolutionary algorithm with memory-based adaptive partitioning) optimization algorithm which is used here (Ahmadi et al. 2016; Ahmadi 2016), and the process of calibration and validation of the model is done according to the framework presented in Fig. 4. The reason for using this optimization algorithm is the high convergence speed of this method in determining optimal solutions (Ahmadi 2016). For calibration evaluation, various variables were selected according to the STOWA guideline (Takacs et al. 1991), which include the amount of sludge produced in the system, COD, NO3, and NH4 in the effluent. In the next step, the effective parameters in the calibration of the processes and their range of changes, are determined based on relevant literature (Boltz et al. 2011; Rieger et al. 2013; Petersen et al. 2002). In Table 4, calibration objectives, effective parameters on calibration goals, and their range of variation are presented.

Fig. 4
figure 4

Process of calibration and validation of the WWTP model

Table 4 Calibration variables, effective parameters and range of changes of these parameters

In this study, the system calibration is considered a single-objective optimization problem, and its goal is to adjust the model parameters in such a way that the difference between simulation results and observed data is minimized. After the completion of the calibration, the model is validated.

Static calibration

In a static state, the average values measured during an intensive period of sampling and testing (input values, operating parameters such as DO and flow rates) are used as model inputs. In this study, the purpose of static calibration is to adjust the parameters of the simulation model including primary sludge and secondary sludge concentrations as well as biomass concentration in the aeration tank. According to the sedimentation equations Eqs. (1) and (2) presented in Dynamita(2016), the rh, \({r}_{compr}\), and \({compr}_{on}\) are used for TSS of primary sludge calibration.

$${V}_{S}(X)=\mathrm{max}[0, \mathrm{min}\left\{{V}_{S,\mathrm{max}},{comor}_{corr}{V}_{0}({e}^{-{r}_{h}(X-{X}_{\mathrm{min}})}-{e}^{-{r}_{P}(X-{X}_{\mathrm{min}})})\right\}]$$
(1)
$${comor}_{corr}=\mathrm{min} \left[1.0,{e}^{({r}_{compr}(-TSS+{compr}_{on}))}\right]$$
(2)

where \({V}_{0}\) is boundary sedimentation velocity (m/day); \({r}_{h}\) is the hindered zone settling parameter (m3/g); \({V}_{S,\mathrm{max}}\) is the maximal settling velocity (m/day); \({r}_{P}\) is the flocculant one settling parameter; \({X}_{\mathrm{min}}\) is the minimum concentration below which non-settleable particles are present; \({comor}_{corr}\) is the compression correction factor; \({r}_{compr}\) is the coefficient for compression (m3/g); and \({compr}_{on}\) is the boundary compression concentration (g/m3).

To calibrate the performance of the secondary settling unit, the TSS of the effluent has been used as the calibration objective and two parameters of Takacs sedimentation model (\({r}_{P}\) and \({f}_{ns}\)) are considered effective parameters. Then, the amount of MLSS of the aeration tank and the concentration of the secondary sludge are simultaneously considered calibration objectives, and the performance of this unit is calibrated by setting the secondary settling parameter (\({r}_{h}\)). The optimal values of effective parameters on calibration objectives are determined using AMOEA-MAP optimization algorithm (3.1.6.2).

For static calibration according to Eq. (3), the error percentage between the value obtained from the simulation and the observed value is used as a criterion for evaluating the performance of the calibration process. \({N}_{o}\) and \({N}_{m}\) are observed and simulation values, respectively.

$$error\;\left(\%\right)=\frac{{N}_{o}-{N}_{m}}{{N}_{o}}\times 100$$
(3)

Dynamic calibration

In the dynamic calibration of WWTP model, the primary settling unit, activated sludge process, and trickling filter are considered. The dynamic calibration of the primary settling model is done with the aim of adjusting the simulated outflow COD with the observed value. Therefore, according to the sedimentation Eq. (4) presented in Cadet et al. (2015), the rp parameter is considered for the calibration of low concentrations in sedimentation.

$${V}_{S}(X)=\mathrm{max}[0, \mathrm{min}\left\{{V}_{S,\mathrm{max}},{V}_{0}({e}^{-{r}_{h}(X-{X}_{\mathrm{min}})}-{e}^{-{r}_{P}(X-{X}_{\mathrm{min}})})\right\}]$$
(4)

Calibration of the activated sludge process is performed considering COD removal, ammonium removal (nitrification process), and nitrate removal (denitrification process) as its objectives. Effective parameters considered for COD, ammonium, and nitrate removal is (µH, Kh, and KS), (µA, KNH, KOA, and bA), and (ηg, KOH, KNO, and ηh), respectively. Based on the method presented for calibrating biological growth processes in Boltz et al. (2011), marginal layer thickness (LL) is an effective parameter in calibrating the nitrification process of attached growth models. The thickness of this layer is chosen in such a way that the calibration variable of the trickling filter matches the observed data (Brockmann et al. 2013; Eldyasti et al. 2012). In this way, to match the nitrate output of the trickling filter with the observed data, optimization of the marginal layer thickness parameter is used.

Dynamic calibration has been done for five calibration parameters (Table 4). In this process, firstly, the calibration of the COD of the primary and secondary settling effluent of the system has been done. Then, the calibration parameters of the model have been calibrated to match the simulation results of nitrification and denitrification processes with observed data.

In dynamic calibration, NSE (Nash–Sutcliffe Efficiency) function (Nash and Sutcliffe 1970) has been used as a criterion for evaluating the performance of calibration process, which shows the degree of conformity of model results with the observed data. NSE function is presented in Eq. (5) (Moriasi et al. 2007):

$$NSE=1-\sum_{i=1}^{n}\frac{{\left({M}_{m}\left(i\right)-{M}_{o}\left(i\right)\right)}^{2}}{{\left({M}_{o}\left(i\right)-\overline{M }\right)}^{2}}$$
(5)

where n is the number of observed samples; \({M}_{m}\left(i\right)\) is the \(i\) th simulated value; \({M}_{o}\left(i\right)\) is the \(i\) th observed value; and \(\overline{M }\) is the average of observed values. The range of NSE variation is between − ∞ and 1. The value of one is considered as an optimal value. Values between zero and one are generally considered acceptable ranges, and values smaller than zero indicate inappropriate model performance (Nash and Sutcliffe 1970).

The sludge retention time in the activated sludge process and the sludge treatment processes are more than the time considered for the intensive sampling period; for this reason, it is not possible to calibrate sludge treatment units with the data obtained in this period of time. Also, in this study, it will not be possible to increase the time of the intensive sampling period due to the large number of tests needed for this purpose and limitations on access to the WWTP site. On the other hand, due to the relationship between the processes of wastewater treatment and sludge treatment in the WWTP and the influence of these two systems on each other performance, it is important to consider sludge treatment for the correct modeling of the WWTP. Therefore, the default parameters of the sumo1 model have been used to simulate the sludge stabilization process in an anaerobic digester.

Step 5: influent clustering

Clustering is used to distinguish different possible conditions of influent. In data clustering, available data are divided into clusters so that the similarity between the data of each cluster is maximized and the similarity between the data of different clusters is minimized. In this study, the k-means clustering method is used to classify the influent. In this study, according to the characteristics of the WWTP model, the variables of COD, ammonium, flow rate, and temperature of the influent are used to determine different states of the influent. Activated sludge process models are based on COD. Therefore, COD is selected for determining the characteristics of influent in the model. Ammonium, which is measured directly in the influent of the WWTP, constitutes the largest percentage of nitrogen in the influent and will have a great impact on the performance of the system in removing nitrogenous compounds. Since the reaction rate of the activated sludge process is affected by temperature, therefore temperature is also considered for influent clustering. The flow rate of influent has an important effect on the hydraulic retention time and the amount of pollution load entering the system, hence it is included in determining the clusters of the influent in the model. These variables are used as input for k-means clustering analysis. It should be mentioned that the daily average data of WWTP are used for clustering.

Step 6: determining optimal strategies for clusters

By clustering WWTP influent, the best operating strategy for improving the quality of the effluent is determined for each cluster using the optimization approach. For this purpose, according to the WWTP design and the existing process units, operation parameters affecting the performance of the system are determined which include (1) dissolved oxygen (DO) in the aeration tank, (2) waste activated sludge flow rate (QWAS), and (3) the ratio of the supernatant flow rate of the sludge dewatering unit to the effluent flow rate (Qd/Qe). Then, the best values for the operating parameters are obtained using AMOEA-MAP optimization algorithm. To simulate different influent clusters, first, the model is statically simulated with the average data of each cluster in order to obtain the appropriate initial conditions. Then, the dynamic simulation of each cluster is done. In a dynamic simulation, the data from the first 7 days have been used for the warm-up of the model.

The stop criteria of AMOEA-MAP optimization algorithm, which is used for complex and time-consuming optimization problems, is the number of calls of the objective function (Faria et al. 2016). According to the conditions of this problem, the number of objective function calls is considered equal to 200 based on trial and error, in order to reduce the optimization time and ensure the achievement of optimal results.

In this study, EQI Index (Moon et al. 2009) is used to select the best operation strategy. EQI is expressed as follows:

$$EQI=\frac{1}{1000T}\int \left({B}_{1} BOD\left(t\right)+{B}_{2} COD\left(t\right)+{B}_{3} TSS\left(t\right)+{B}_{4} TKN\left(t\right)+{B}_{5} {NO}_{3}\left(t\right)\right)Q\left(t\right)dt$$
(6)

Q (m3/day) is the effluent flow rate, and T is the number of system simulation days. The unit of all qualitative variables in the equation including COD, BOD, TSS, TKN, and NO3 is (kg/l). The Bi coefficients are experimental weights given by Vanrolleghem et al. (1996) and presented in Table 5. EQI index has been used in many optimization studies of WWTP models as a criterion for evaluating the quality of effluent (Guerrero et al. 2014; Tejaswini et al. 2021; Qiao and Zhang 2018; Canete et al. 2021). In this study, the average of system effluent characteristics in the calibration period has been used to determine the basic EQI value.

Table 5 The value of B1 coefficients (Vanrolleghem et al. 1996)

Algorithm for determining appropriate operational strategies

In order to determine the appropriate strategies for the operation of WWTP, firstly, it is necessary to determine the different conditions that WWTP faces. In this study, like the study of Moon et al. (2009), the k-means clustering method is used to determine the clusters, and discriminant analysis is used to determine the discriminant function of each cluster. Assigning new observations to each cluster is done based on discriminant functions. In this study, Fisher’s analysis is used to determine discriminant functions (Moon et al. 2009). The same inputs as k-means clustering are used for discriminant analysis. In Fig. 5, the optimal operation algorithm of the WWTP model is presented. According to this approach, for new measured data, the appropriate cluster is determined firstly based on the discriminant analysis. Then, according to the determined cluster, the optimal operating parameters are applied in the system.

Fig. 5
figure 5

The final algorithm of optimal operation of the WWTP model

AMOEA-MAP optimization algorithm

In general, evolutionary optimization algorithms face two main problems: low speed of convergence near-optimal solutions and a large number of objective function calls to achieve optimal results. In AMOEA-MAP optimization algorithm, it has been tried to solve these two main problems. Therefore, two general changes have been made in this algorithm, whose overall performance is based on the genetic algorithm (Ahmadi et al. 2016; Ahmadi 2016). First, in this method, an algorithm called MAP (memory-based adaptive partitioning) is used to determine the optimal areas of decision variables. By intelligently dividing the search space for each decision variable, this algorithm reduces the number of calling the objective function to achieve the optimal solution. The second change is using two populations at the same time. The purpose of this change is to achieve optimal results with fewer calls of the objective function. More details of AMOEA-MAP optimization algorithm are provided in Ahmadi (2016). Figure 6 shows the structure of AMOEA-MAP optimization algorithm.

Fig. 6
figure 6

Structure of AMOEA-MAP optimization algorithm

Results and discussion

Static calibration and validation

The static calibration objectives, calibration parameters, and the results of the model’s static calibration and validation are presented in Table 6. The obtained results show that the calibrated model is capable of properly simulating the effluent suspended solids as well as the concentration of primary and secondary sludges.

Table 6 Variables and parameters of static calibration of the model and the results of the static calibration and validation

For calibration of the effluent TSS, the difference between TSS simulation value and the observed value, in this case, was less than 1 mg/l. Also, the simulation and observed value of stabilized sludge VS in the anaerobic digester was almost equal (70%), which indicates the proper simulation of this unit by the sumo1 model despite using the default values of the model for this unit.

Dynamic calibration and validation

Dynamic calibration objectives, parameters affecting each process, and values obtained by optimization along with NSE values are presented in Table 7. The obtained NSE values for the calibration variables are between zero and 1, which indicates the appropriate results of the model in the operational simulation of the WWTP. Figure 7 shows the results of the dynamic calibration and validation of the primary settling tank. According to this figure, the behavior of the primary settling model in the simulation of COD output from this unit is consistent with the observed data.

Table 7 Dynamic calibrated value of parameters and NSE value
Fig. 7
figure 7

Comparison of the COD output from the primary settling model with observed data, a calibration period and b validation period

Figure 8 compares the quality of calibrated model effluent with the observed data for the calibration period. According to Fig. 8 (a), the maximum values of effluent COD have been better simulated in comparison with the minimum values. According to Fig. 8 (b), despite the difference between the model results and observed data, the calibrated model is able to predict the trend of ammonium changes in the effluent and has simulated the peak ammonium values well. The comparison of the simulation results of the denitrification process is presented in Fig. 8 (c). According to this figure, the calibrated model predicts nitrate changes well in the effluent during the calibration period. According to Fig. 8 (d), the correspondence between the nitrate changes in the MBBR model and the observed data of the trickling filter unit shows that using MBBR model instead of the trickling filter is acceptable.

Fig. 8
figure 8

Comparing the results of dynamic calibration of the model with the observed data, a effluent COD, b effluent NH4, c effluent NO3, and d NO3 of the trickling filter supernatant

The results obtained during the validation period of the model are presented in Fig. 9. According to Fig. 9 (a), the trend of COD changes in the observed data is similar to the model simulations. According to Fig. 9 (b), the maximum and minimum values of nitrate in the observed and simulated data are the same, but in terms of time, the model results are ahead of the observation results. The reason for this can be the difference between the hydraulic condition (such as hydraulic retention time) in the operating conditions of the WWTP and the simulation model. Since the flow regime in the reactors is considered ideal in the modeling of the activated sludge process, the existence of time differences between the model results and observed data is inevitable (Haq et al. 2022). According to Fig. 9(c–d), the changes scheme in the effluent ammonium and nitrate output from the MBBR unit is well simulated as in the calibration period, and the model results are consistent with the observed data.

Fig. 9
figure 9

Comparison of model validation results with observed data, a effluent COD, b effluent NH4, c effluent NO3, and d NO3 of the trickling filter supernatant

Clustering of the influent

By examining 3, 4, 5, and 6 clusters for k-means analysis of influent, the best number of clusters based on Akaike and Schwartz Bayesian (AIC and BIC) criteria is determined as 4. The centers of the clusters are presented in Fig. 10. According to this figure, there is a significant difference between the variables in different clusters, which indicates the appropriate classification of data. Also, based on the k-means method, the number of clusters 3 and 5 was not able to cluster the different states of the variables. The statistical characteristics of data in each cluster are presented in Table 8. The information and percentage of data assigned to each cluster are explained below:

Fig. 10
figure 10

The final centers of the clusters

  • The first cluster (36% of data belong to this cluster): The average influent flow rate in this cluster is higher than other clusters, which can decrease the hydraulic retention time and increase the input load to the system. On the other hand, the average amount of ammonium in this cluster is lower than the others.

  • The second cluster (39% of data belong to this cluster): This cluster can be considered as the basic condition of the system. In this cluster, all the parameters are close to their average value in the sampling time period. Also, this cluster contains the largest percentage of data.

  • The third cluster (21.5% of data belong to this cluster): The main characteristic of this cluster is a low influent flow rate, which increases the retention time in the system. For this reason, it is very important to check the aeration rate to prevent excess aeration.

  • The fourth cluster (2.5% of data belong to this cluster): This cluster represents a state of the system where the amount of ammonium in the influent is very high. In this situation, it is necessary to improve the quality of the effluent in terms of nitrogen compounds.

Table 8 The characteristics of the clusters, including the mean and standard deviation of the variables

Table 9 shows the optimal values of operating parameters of the WWTP for each of the influent classes and also EQI values obtained for optimal conditions. According to the results, in the first cluster, the amount of waste activated sludge flow (QWAS) over the 24 h is higher than other clusters because this cluster has the highest influent flow compared to others. Also, in the third cluster, dissolved oxygen (DO) concentration over 24 h is lower than in other clusters because it has the highest COD. The fourth cluster has the highest EQI index due to having the highest amount of TKN.

Table 9 Results of model optimization for different clusters of influents

Figure 11 shows a comparison between basic and optimal effluent quality (COD, nitrate, and TKN) for cluster one. In this cluster, the influent is high, which increases the input load to the system. Therefore, according to Fig. 11 (a), the fluctuations of COD in the effluent are very high due to the increase in solid load to the secondary settling tank. Therefore, by increasing the flow rate of waste activated sludge from the system during peak flow times, it is possible to reduce the input load to the secondary settling tank. The results of these changes have led to the high removal of COD in the effluent. Based on the results obtained for the first cluster, the average COD of the basic and the optimal condition are equal to 35.1 mg/l and 20.7 mg/l, respectively, which is improved by 41% as a result of optimization. Although the amount of influent ammonium is low in this cluster, due to the high influent flow, the peak of ammonium in the effluent is significant. By optimizing, the ammonium peaks in the effluent have been reduced (Fig. 11(c)). Due to the low denitrification capacity of the model, based on Fig. 11 (b), there has been no significant change in the amount of nitrate in the effluent.

Fig. 11
figure 11

Comparing the qualitative variables of the effluent in the basic and optimal conditions for the first cluster, a COD, b NO3, and c TKN

In the second cluster, according to Fig. 12 (a), after optimization, COD has improved between 3 and 33% compared to the basic operating condition. Due to the amount of aeration in this cluster, the amount of nitrate in the effluent has decreased (Fig. 12(b)). However, the amount of ammonium in the optimal condition is almost the same as in the basic condition (Fig. 12(c)).

Fig. 12
figure 12

Comparing the quality of the effluent in the basic and the optimal conditions for the second cluster, a COD, b NO3, and c TKN

In the third cluster, due to the low influent, by increasing the aeration rate to its optimal value in the aeration tank, the nitrification process is intensifying and as a result, the amount of nitrate in effluent increases (Fig. 13(b)). Also, by decreasing the waste activated sludge rate from the secondary settling tank and increasing the concentration of biomass in the aeration tank, the removal of ammonium has increased slightly (Fig. 13(c)). The average nitrate concentrations in effluent in the basic and optimal conditions were 17.6 mg/l and 14.6 mg/l, respectively, which represents a 17% decrease in optimal operating conditions. Also, the fluctuations of peaks of ammonium concentration in effluents which can be seen in the basic condition show a significant reduction in the optimal state reducing from the maximum of 13 mg/l in the basic condition to 8 mg/l in optimum system operation.

Fig. 13
figure 13

Comparing the qualitative variables of the effluent in the basic and optimal conditions for the third cluster, a COD, b NO3, and c TKN

The main characteristic of the fourth cluster is high ammonium concentration in influents. Therefore, to reduce the amount of ammonium in the effluent, the concentration of dissolved oxygen in the aeration tank has been increased for this cluster. However, due to the low denitrification capacity of the WWTP, the amount of nitrate in the system has not decreased significantly. However, from 2 a.m. to 8 a.m., due to the decrease in DO, the amount of nitrate in the effluent has considerably decreased (Fig. 14(b)). According to Fig. 14 (c), the maximum TKN in the effluent also decreased by about 15% in this cluster and reached 16.4 mg/l.

Fig. 14
figure 14

Comparing the qualitative variables of the effluent in the basic and optimal conditions for the fourth cluster, a COD, b NO3, and c TKN

Conclusion

In this study, by determining the different states of the influent and determining the optimal solutions for each state, the performance of the WWTP has been improved in terms of the quality of the effluent. The proposed approach was implemented on a WWTP in Iran. In this regard, first, the desired WWTP was modeled in SUMO software. Then, in order to ensure the performance of the model, calibration and validation of the model were done. The percentage of calibration and validation error was less than 1 and 3% respectively, and in dynamic calibration, NSE values for all calibration parameters were obtained between 0 and 1 which indicates the proper performance of the model. For optimization of the system, dissolved oxygen (DO) in the aeration tank, waste activated sludge flow rate (QWAS), and the ratio of the supernatant flow rate of the sludge dewatering unit to the effluent flow rate (Qd/Qe) are considered as operation parameters affecting the performance of the system. According to the design and current operation of the considered WWTP, this system does not have the ability to remove nitrate well when the amount of ammonium at influent is high. To solve this issue, some changes in existing processes are needed. By using the strategies developed in this study, in times of considerable changes in influent such as increasing organic load and high or low flows to the system, it is possible to ensure the quality of the effluent in terms of the suspended solids and the amount of ammonium and COD of effluent are reduced. Generally, using this approach has improved the performance of the system in reducing COD, ammonium, and nitrate in the effluent by 11–41%, 17–20%, and 15–34%, respectively.