{'fraction_non_alphanumeric': 0.035072892457215295, 'fraction_numerical': 0.0156650870785669, 'mean_word_length': 4.766098155238427, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Wastewater Treatment Plant: Modelling and Validation of an Activated Sludge Process

The aim of the present paper is to develop a reliable and accurate model of the wastewater biochemical treatment process and to explore the behaviour through a general dynamic simulation environment, namely the INtegrated Simulation Environment Language (INSEL), for the analysis of the energy demand of the whole wastewater treatment plant. In particular, the presented model pays special attention to the chemical kinetics involved in the activated sludge process for the reduction of nitrogen and carbon compounds. According to the best practices, the plant configuration considered in this work includes the denitrification-nitrification process, performed by completely mixed reactors. In particular, the process analysed in this paper is based on the Ludzak-Ettinger process. The biological process is simulated according to the well-known method widely used in the literature, namely the Activated Sludge Model No 1 (ASM1). The model includes a set of equations for the calculation of aerobic growth of heterotrophs, anoxic growth of heterotrophs, aerobic growth of autotrophs, decay of autotrophs, ammonification of soluble nitrogen, hydrolysis of entrapped organics, and hydrolysis of entrapped organic nitrogen. All these equations, along with energy and mass balances, are solved by the explicit Euler method. The developed model is validated using literature data, showing a great accuracy (deviation below 1%). As for the temperature, results show that, between 15 and 25 ◦C, in the initial part of the process, transport effects dominate the consumption ones. When the temperature is higher than 30 ◦C, nitrate consumption is so fast that biomass growth is limited by this effect. Conversely, in case of low temperatures (5–10 ◦C), biomass growth is not limited by nitrate availability. Finally, results also showed that temperature significantly affects the denitrification process, whereas the effect on the oxygen is lower.


Introduction
The majority of Countries implemented several actions to avoid the disposal of wastes and wastewater without treatment in land and water bodies, since it determines harmful effects on the health of environment, humans and animals [1]. Conventional wastewater treatment plants are extremely intensive energy consumers [2], since their processes require large amounts of electrical and thermal energy. Data from Germany as well as from Italy show that electricity demand for wastewater treatment accounts for about 1% of total consumption of the country [3]. In particular, the high energy consumption in wastewater treatment plants is mainly due to their heavy mechanical systems, such as pumps and aeration systems, for moving and treating wastewater [4]. Therefore, due to the high energy consumption of the wastewater treatments plants, more sustainable and energy-efficient treatments have been developed [5]. For example the production of biological energy by-products, such as biogas or biomethane, is obtained by the conversion of wastewater into a stabilised waste [6]. Biomethane

Method
This section presents the analysis of wastewater biochemical treatments, paying special attention to the chemical kinetics involved in the activated sludge process for the reduction of nitrogen and carbon compounds. According to the best practices, the plant configuration considered in this work includes the denitrification-nitrification process, performed by completely mixed reactors. In particular, the process analysed here is based on the Ludzak-Ettinger process, where three stages are included: anoxic, aerobic and sedimentation. The biological process is simulated according to the well-known method widely used in literature, namely the Activated Sludge Model No 1 (ASM1) [13], by means of a user-developed code. The model, reported in the Appendix A, includes a set of equations for the calculation of aerobic growth of heterotrophs, anoxic growth of heterotrophs, aerobic growth of autotrophs, decay of autotrophs, ammonification of soluble nitrogen, hydrolysis of entrapped organics and hydrolysis of entrapped organic nitrogen. All these equations, along with energy and mass balances are solved by the explicit Euler method. This method has been preferred to the Ordinary Differential Equations (ODE) solver included in the MATLAB tool. The developed model evaluates the energy demand of the process and it is validated according to the plant configuration that the 624 action of the European Cooperation in Science and Technology proposes [17,18] (COST, a reference point for the comparison of the automatic treatment control systems). The COST Action 624 is dedicated to the optimisation of the performance and cost-effectiveness of wastewater management systems. Therefore, the action is focussing on increasing the knowledge of microbiological systems. The following subsections present system layout, model and validation procedure.

System Layout
The most widespread configuration based on the Ludzack-Ettinger process is investigated (Figure 1), which consists of: (i) an anoxic process, the denitrification process, where the heterotrophic bacteria convert nitrates (NO 3 ) into ammonia nitrogen (NH 3 and NH 4 + ), (ii) an aerobic process, the combined nitrification process, where the heterotrophic and autotrophic bacteria operate with dissolved oxygen in order to remove the carbonaceous substrate and ammonia nitrogen and (iii) the sedimentation process, for the removal and recirculation of the activated sludge. Two recirculation lines are needed. Because the inlet nitrates' concentration is negligible, in order to obtain sufficient concentration values for the development of the denitrification process, the first recirculation line R1 allows one to supply nitrates obtained by the combined nitrification process to the denitrification process. Note that the denitrification process can be performed only using carbon compounds. Therefore, by means of this process, the simultaneous reduction of the nitrate and carbon substrate concentrations is obtained. Note that the denitrification process is located before the combined nitrification process, to avoid adding further organic compounds (e.g., methanol) to the process. The second recirculation line R2 is mainly proportioned for the recirculation of bacteria, although it also sends nitrogen compounds.

Calibration and Validation Procedure
The calibration and validation procedure of the developed code is carried out by means of the COST simulation benchmark plant and data [16], in steady state condition. The aim of the work is to develop a suitable simulation code for the biological processes to be integrated in the energy commercial software INtegrated Simulation Environment Language (INSEL). In the COST benchmark, different data are available in terms of initial and boundary conditions as well as results obtained by means of several different commercial software. The benchmark simulation plant is reported in Figure 2.
This consists of 5 biological tanks-in-series with a secondary settler. The total biological volume is 5999 m 3 (tanks 1 and 2, each 1000 m 3 , and tanks 3, 4 and 5, each 1333 m 3 ). Tanks 1 and 2 are unaerated, but fully mixed. Tanks 3, 4 and 5 are aerated, with k La (oxygen transfer rate (day −1 ), provided by the blowers' manufacturers) of 10 hr −1 for tanks 3 and 4, and k La of 3.5 hr −1 for tank 5. The concentration of dissolved oxygen for tanks 3, 4 and 5 is 8 gm −3 [16]. A non-reactive secondary settler with a volume of 6000 m 3 (area of 1500 m 2 and a depth of 4 m) is subdivided into 10 layers, with a feed point at 2.2 m from the bottom (i.e., at the middle of the sixth layer). Two recirculation lines are expected: the nitrate internal recycle from the fifth to the first tank for a default flow rate of 55,338 m 3 /d, and the return-activated sludge (RAS) recycled from the first layer of the secondary settler to the tank 1 inlet for a default flow rate of 18,446 m 3 /d. Note that RAS is the settled biomass returned to the treatment process to provide organisms which will continue removing pollutants. Since this is a living and growing process, it will continue to build biomass. However, an uncontrolled biomass growth must be avoided. Therefore, the amount of biomass in the process is controlled by removing (wasting) a certain amount of it each day. This excess biomass removed from the secondary system is known as waste or waste-activated sludge (WAS). It is assumed that the waste is continuously pumped from the secondary settler for a default rate of 385 m 3 /d. The COST provides a data file including influent concentration values of 12 components of the model, reported for each 15-min interval for 14 days. As previously explained, pH is assumed neutral and, therefore, the alkalinity S alk is assumed equal to 7 mol m −3 each time step. The data include diurnal variations in flow and Chemical Oxygen Demand (COD) load and also take into account three disturbance weather events: dry weather, a storm and a rain event. In order to verify the code, the obtained results are compared with those provided by the COST after a simulation of 100-150 days, considering same boundary conditions and inputs.

Results and Discussion
In this section, results obtained from the numerical code are reported in order to show the model validation and the robustness analysis. The validation was carried out by considering the benchmark COST data obtained with other commercial software by taking into account the following boundary and initial conditions (Table 1). In particular, the validation of the anoxic tank and aerobic tank model, as well as the validation of the whole process, was performed on seven days of simulations, according to the available data. These data are included in a fully defined simulation protocol developed as a tool for evaluating activated sludge wastewater treatment control strategies. The COST simulation benchmark data are representative of three disturbances: dry weather, a storm event and a rain event. In this work, data related to a dry weather file is used. This considers normal diurnal variations in flow and COD load. The initial wastewater parameters refer to the wastewater after preliminary treatments (screenings, degritting, oil extraction and primary settling).
The results of the validation of the anoxic tank model are shown in Figure 3. The concentrations were compared with the benchmark data. The error about the inert suspended solids, S I , in the first tank is extremely low, below 10 −9 after 3 days of simulation (Figure 3a), since in the first anoxic tank, no production or consumption rate occurs. Although the oscillations reported in Figure 3b, seem to be large, for the particulate inert organic matter, X I , the error tends to zero, showing values lower than 10 −5 , after the seven days of available data (Figure 3b). The figure shows that the errors are definitively acceptable according to the typical accuracy of the engineering calculations. In addition, this error is significantly lower than any possible measurement errors regarding such variables. On the other hand, a certain instability of the solution can also be detected for day 1. However, this leads to some oscillations only in the error, not in the solution. In fact, Figure 3 displays the error for X I , not the variable X I itself. The error is in the order of magnitude 10 −5 . Therefore, the variable X I is only marginally affected by these fluctuations. Additional comments have been added in the text.   Table 2 reports a comparison of the effluent concentrations with commercial software after 150 days of simulation, a sufficient time to reach the steady state condition.
The total suspended solids (TSS) concentrations along the settler height are also compared by obtaining satisfying results (Table 3).
In the anoxic tank, a really low oxygen level is obtained, as expected, because the only oxygen supply comes from the internal recirculation line; therefore, a minimum level of oxygen is detected ( Figure 4). In the first seven days of simulation, the concentration of nitrite and nitrate grows due to the following reasons: (i) the nitrogen feed from sewage and (ii) the higher rate of recirculation than the consumption rate. The concentration of heterotrophic bacteria grows both for the recirculation and feed effect, but also for the production rate of the facultative bacteria capable to consume nitrates ( Figure 4). Optimal results in terms of percentage error with respect to the COST benchmark data were obtained for the aeration tank. In particular, in Figure 5, the concentration values of the dissolved oxygen, heterotrophic and autotrophic bacteria and carbon substrate obtained by the nitrification and carbon compounds' removal processes in the first aeration tank were reported. Due to the aerobic environment, the concentration of the dissolved oxygen is obviously high. In this tank, during the observed days, a remarkable growth of the heterotrophic bacteria concentration is obtained, from 2100 to 2425 gm −3 , and simultaneously, the removal of the carbon substrate from 1.45 to 1.23 gm −3 , according to a linear trend.
The nitrification process leads to the increase of the autotrophic bacteria concentration, from 70 to 102 gm −3 , and a reduction of ammonia nitrogen (Figure 6a). In fact, as reported in this figure, the process leads to the transformation of the ammonia nitrogen into nitrate and nitrite nitrogen.

Sensitivity Analysis
In order to prove the model robustness and the quality of the obtained results, a sensitivity analysis is performed by varying the most important kinetic-chemical parameters. For sake of brevity, the results only show the variation of: (i)μ A = the maximum autotrophic growth rate (day −1 ), (ii) K S = the substrate half saturation constant (gCOD m −3 ), (iii) K NO = the nitrate half saturation constant (g NO 3 -N m −3 ) and (iv) the temperature of the biological treatment. By varyingμ A from 0.35 and 0.65 day −1 (Figure 7a), the analysis showed that the autotrophs concentration in the second anoxic tank significantly decreases forμ A values lower than 0.45 day −1 (typical values of water treatment plants with inlet low ammonia concentrations or no-optimal pH values). As expected, for low values of K S , the concentration of heterotrophs in the last aerobic tank more rapidly reaches sufficiently high values (Figure 7b). The value of K NO can be used to assess if the environment where a process occurs is anoxic. In particular, when the nitrate concentration is higher enough than the nitrate half saturation constant and the dissolved oxygen concentration is smaller enough than the oxygen half saturation constant, the tank can be modelled as anoxic. In this case, the electron acceptor is the nitrate and the switching functions included in the model are able to simulate the denitrification process, and consequently, the possible heterotrophic growth. For the typical operating range of this constant, 0.1-0.5 gm −3 , no significant difference was detected. Conversely, by varying K NO from 0.001 to 10 gm −3 , slight differences are obtained (Figure 8). In particular, for high values of K NO , a decrease in the heterotrophs growth and an anoxic environment can occur. The temperature in the biological treatment is an important parameter affecting all the processes. In fact, according to the Arrhenius equation, the kinetics of the chemical reaction dramatically depends on the temperature, according to the following equation [20]: k T = k 20 θ (T−20) , where θ = 1.047 is the Arrhenius coefficient.
This parameter is varied from 5 to 35 • C, in order to simulate the potential variation of the influent temperature during the months of the year. In the anoxic tank, the study on the temperature effects is carried out by analysing the relation between the nitrates consumption ( Figure 9b) and heterotrophs growth (Figure 9a). For temperatures higher than 30 • C, the nitrates concentration goes almost to zero due to the high consumption rate. As a consequence, at high temperatures, the low nitrates concentration reduces the biomass growth and determines a low heterotrophic bacteria concentration. The trend at 20 • C is due to the following reasons: first, the nitrate feed prevails on the consumption rate of the heterotrophs, subsequently, up to 30 days, the heterotrophic bacteria concentration increases, and the consumption rate balances the nitrate feed and the stationary condition is reached. This trend is the same for temperatures between 15 and 20 • C. Conversely, for low temperatures, see isothermal curves at 5 and 10 • C, the nitrate consumption rate is low, and therefore, the biomass is featured by a minor limiting effect. This determines a high heterotrophic bacteria concentration and therefore, a great consumption of nitrates, which falls to zero after 20 days (Figure 9b). Subsequently, heterotrophic bacteria concentration reaches a stationary concentration value. This effect reflects the empirical result obtained in winter operation, when high heterotrophic bacteria concentrations are measured.
For the process occurring in the aerobic environment, the force causing the oxygen supply is the difference between the saturation oxygen concentration and the effective oxygen concentration. It is well known as the saturation oxygen concentration is temperature-dependent. In particular, the higher the temperature, the lower the saturation oxygen concentration. As it is shown, between 15 and 25 • C, the dissolved oxygen concentration is high enough to determine quite high heterotrophic bacteria concentrations and low carbonaceous substrate concentrations due to the high substrate removal ( Figure 10). For temperatures higher than 25 • C or lower than 15 • C, high substrate concentrations are obtained. In the first case, this is due to a low oxygen concentration, and in the second case, to low values of maximum velocity of substrate degradation.
In the aerobic environment, the ammonia nitrogen is degraded by autotrophic bacteria, operating only with sufficient dissolved oxygen concentration values. For low temperatures, ammonia nitrogen concentrations are high (Figure 11b), because although the dissolved oxygen is sufficient for both the nitrification and carbonaceous substrate removal, the maximum growth rate parameter of autotrophs is low (Figure 12). Conversely, for high temperatures, the dissolved oxygen decreases (Figure 11a), but the consumption rate is high from a kinetic point of view. As the temperature grows, an increase of the ammonia removal by the autotrophic bacteria is obtained.

Energy Analysis
This section presents the analyses of the effluent quality index (EQI) and the electric energy demand obtained by the simulations carried out using different volumes of anoxic (1000, 1250, 1500 and 2000 m 3 ) and aerated tanks (1333, 1666, 2000 and 2600 m 3 ). In order to evaluate the best possible solutions from the energy and environmental points of view, simulations are performed by taking into account the same layout (two anoxic tanks and three aerated tanks) and same input data used for the validation process. Results are analysed after the steady-state condition is reached. Table 4 shows the most interesting cases compared to the base case in terms of primary energy consumption of the aeration systems and CO 2 emissions. The best result is obtained using anoxic tanks of 1000 m 3 and aerobic tanks slightly larger than the reference case (1333 m 3 ), with a reduction of 13% of primary energy consumption and CO 2 emissions. Note that all the selected solutions respect the limit values of the concentrations TSS e , COD e , S Ntot (sum of S NKe and S NOe ) and BOD 5,e (the quantity of biodegradable organic matter contained, evaluated using the biochemical oxygen demand of microorganisms after five days) equal to 30, 100, 18 and 10 gm −3 , respectively. Therefore, EQI values are acceptable from an environmental point of view.

Conclusions
This work presented the development and the validation of a detailed model for the simulation of the activated sludges biological process in wastewater treatment plants. In particular, the developed model is validated according to the plant configuration that the 624 action of the European Cooperation in Science and Technology proposes (a reference point for the comparison of the automatic treatment control systems). In order to prove the model robustness and the quality of the obtained results, a sensitivity analysis was performed by varying the most important kinetic-chemical parameters and temperature. The developed model showed a great accuracy, presenting a deviation with respect to the benchmark data below 1%. Results showed that biomass growth is only slightly affected by the selection of the kinetic constant, which should increase from 0.001 to 10 gm −3 in order to detect a relevant effect on the growth of the biomass. As for the temperature, between 15 and 25 • C, in the initial part of the process, transport effects dominate the consumption ones. When the temperature is higher than 30 • C, nitrate consumption is so fast that biomass growth is limited by this effect. Conversely, in case of low temperatures (5-10 • C), biomass growth is not limited by nitrate availability. Finally, results also showed that temperature significantly affects the denitrification process, whereas the effect on the oxygen is lower. This is due to the fact that at high temperatures, ammonia is rapidly converted by the autotrophic bacteria.
The development of this model is only the first step of a longer research project on wastewater treatment plans. In fact, the final aim is the development of a comprehensive library of programming blocks for each process of the plant to be included in the INSEL energy simulation software, in order to evaluate the processes' energy demand and simulate the whole wastewater treatment plant coupled with renewable energy sources. In particular, the research project aims at investigating the integration of wastewater treatment plants in novel and/or existing district networks, considering the energy that can be produced by the biogas obtained by the wastewater plants. The biological model used is ASM1 in the final form, published in 1987 [21]. The model considers kinetic and stoichiometric coefficients and the concentrations of the 12 components. In Table A1, a description of the main components is reported.

9
S NO Nitrate and nitrite nitrogen: products obtained by autotrophic bacteria in aerobic condition and removed by heterotrophic bacteria in anoxic condition mgNl −3 10 S NH NH 4 + + NH 3 nitrogen: the soluble ammonia nitrogen, assumed to be the sum of the ionized (ammonium, NH 4 + ) and un-ionized form (ammonia, NH 3 ) mgNl −3

11
S ND Soluble biodegradable organic nitrogen: products formed by the hydrolysis of particular organic nitrogen by ammonification mgNl −3 12 X ND Particulate biodegradable organic nitrogen: products generated from decay of autotrophic and heterotrophic bacteria mgNl −3

13
S alk Alkalinity mol m −3 The adopted stoichiometric coefficients (describing the dependence between components concentrations) are: (i) Y A , the autotrophic yield, equal to 0.24 (g X BA COD formed (g N oxidized) −1 ), (ii) Y H , the heterotrophic yield, equal to 0.67 (g X BH COD formed (g COD oxidized) −1 ), (iii) f P , the fraction of biomass to particulate products, equal to 0.08 (-), (iv) i XB , the fraction of nitrogen in biomass, equal to 0.08 (g N (g COD) −1 in biomass (X BA and X BH )) and (v) i XP , the fraction of nitrogen in particulate products, equal to 0.26 (g N (g COD) −1 in X p ). Whereas, the kinetic coefficients, describing the dependence of the process rate on the component concentration, are as follows: µ H = the maximum heterotrophic growth rate, equal to 4.0 (day −1 ). K S = the saturation (heterotrophic growth), equal to 10.0 (g COD m −3 ). K O,H = the half saturation (heterotrophic oxygen), equal to 0.2 (g O 2 m −3 ). K NO = the half saturation (nitrate), equal to 0.5 (g NO 3 -Nm −3 ). b H = the heterotrophic decay rate, equal to 0.3 (day −1 ). η g = the anoxic growth rate correction factor, equal to 0.8 (-). η h = the anoxic hydrolysis rate correction factor, equal to 0.8 (-). k h = the maximum specific hydrolysis rate, equal to 3.0 (g, slowly biodegradable COD (g X BH COD day) −1 ). K X = the half saturation (hydrolysis), equal to 0.1 (g, slowly biodegradable COD (g X BH COD) −1 ). µ A = the maximum autotrophic growth rate, equal to 0.5 (day −1 ).
The previous units are expressed in COD (chemical oxygen demand), i.e., the amount of oxygen necessary to oxidize all of the organic carbon completely to CO 2 and H 2 O.
The previous Table A2 has to be read in the following way. S I and X I (column 1 and 3, respectively) are not involved in any conversion processes, but their concentration in considered because it is included into the effluent COD value. S S (column 2) is removed by the growth of heterotrophic bacteria (−1/Y H ) under aerobic or anoxic conditions (−1/Y H ) and is formed by the hydrolysis of particulate organic matter (+1). The slowly biodegradable substrate X S (column 4), is removed by hydrolysis (−1) and formed by decay of both heterotrophic and autotrophic biomass. The decay also transforms biomass into inert particulate products; therefore, the term f P (the fraction of biomass to particulate products) is included (1−f P ). As a consequence, the particulate products arising from biomass decay X P (column 7) are obtained by the decay of heterotrophic and autotrophic biomass. Note that the readily biodegradable material is considered to be the only substrate for growth of the heterotrophic biomass X B,H (column 5) obtained by the growth under aerobic (+1) or anoxic conditions (+1), whereas the growth of the autotrophs X B,A (column 6) only occurs under aerobic conditions (+1). The considered concentration of oxygen S O (column 8) only includes biological processes, i.e., the amount of oxygen which must be provided to meet the bacteria metabolic needs. Therefore, the oxygen utilization is associated only with aerobic growth of the heterotrophic (−(1 − Y H )/Y H ) and autotrophic biomass (−(4.57 − Y A )/Y A ), discarding the microbial decay. This assumption differs from the more traditional approaches. The net loss of biomass associated with decay is considered by the heterotrophic yield, lower than unity. The biomass grown obtained by the substrate removal must always be lower than the biomass loss. The term 4.57 is the stoichiometric coefficient for aerobic growth of autotrophs, i.e., the theoretical oxygen demand associated to the oxidation of ammonia nitrogen to nitrate nitrogen. The nitrate and nitrite nitrogen, S NO (column 9), is produced by aerobic growth of the autotrophic bacteria (+1/Y A ) and removed during the anoxic growth of the heterotrophic biomass (−(1 − Y H )/2.86Y H ). Note that the nitrite nitrogen is an intermediate obtained during the nitrification process, therefore, for the sake of simplicity, the model assumes that nitrate is the only oxidized form of nitrogen. The term 2.86 is the stoichiometric coefficient for anoxic growth of the heterotrophic biomass, i.e., the theoretical oxygen for the conversion of nitrate nitrogen to nitrogen gas (N 2 ). The soluble ammonia nitrogen, S NH (column 10), is formed by ammonification of soluble biodegradable organic nitrogen (+1) and is removed by growth of the biomass. The ammonia nitrogen is consumed for the aerobic growth of the autotrophic biomass (−1/Y A ). However, nitrogen is also incorporated into biomass during cell synthesis and a term is included (−i XB ) for the nitrogen used during growth of both heterotrophs and autotrophs. The soluble organic nitrogen, S ND (column 11), is formed by hydrolysis of particulate organic nitrogen (+1) and converted to ammonia nitrogen by ammonification (−1). The particulate biodegradable organic nitrogen, X ND (column 12), is generated from decay of both heterotrophic and autotrophic biomass (i XB ), minus the amount associated with the inert particulate products, and is lost by ammonification (− f P i XP ). pH of the process included in the column alkalinity, S alk (column 13), is considered about neutral, therefore, the model includes 12 mass balance equations to adequately simulate an activated sludge system performing carbon oxidation, nitrification and denitrification. For each process j of the previous table, the rate is defined in the last column of Table A2. This table represents a set of 13 differential equations (13 columns), each one including a time-variation term ( dS 1 dt ), an inlet flow ( q in V S 1in ), an outlet flow ( q out V S 1 ) and generation/decay terms, which are given by the sum of products of the coefficients given in the i-th column of the table (ν ji ) and the respective process rate, ρ j , as shown in the following equation: 12,13] (A1) All these equations are solved by implementing the explicit Euler method, forming a set of explicit algebraic equations. The numerical resolution of the model is based on the following differential equation: where C represents the concentration of a generic component and ∆t is the time step adopted so that the term C(t + ∆t) is not negative, i.e., the criterion adopted to define the maximum time step avoids obtaining physically impossible solutions: Combining the relative mass balances and condition (3) for each component, the time step is where ∆t i is the time step on component i, V is the tank volume, C i is the concentration of the i th component in the tank, O i is the outlet mass flow rate from the tank, K i is the mass flow rate consumed of the i th component for biological process and θ i is the mean residence time of the i th component in the tank, i.e., the amount of time that a component remains in the reactor. Equation (A4) demonstrates that the maximum allowable step size for each component may be different and depends on the mean residence time of the component. The numerical technique is organised so that it provides adequate accuracy for each component without wasting computational time. Finally, the settling system is simulated considering the double exponential settling velocity function, see the equations reported in Reference [22].

Appendix A.2. Aeration Energy Demand Evaluation
In order to evaluate the energy demand of the aeration process to maintain the optimal concentration of dissolved oxygen, So, step by step, the following control strategies are implemented.
The value ∆ is iteratively calculated by the code. The code calculates the value ∆ by itself within a certain number of cycles, in order to add or subtract to the k La coefficient and maintain the outlet concentration, So, from the aerobic process within the recommended range of 1-4 gm −3 . In particular, during each iteration, if So is less than or equal to the minimum value (S o,min = 1 gm −3 ), k La is increased by a certain value ∆, iteratively calculated in order to meet the criterion that So will be higher than 1 gm −3 . Conversely, if So is greater than or equal to the maximum value (S o,max = 4 gm −3 ), k La is decreased by a certain value ∆, iteratively calculated so that So will be lower than 4 gm −3 .
In this way, the optimal concentration of dissolved oxygen is step-by-step pursued, and the code reaches it by itself within a certain number of cycles.
According to the previous control strategy, to maintain So in the recommended range of 1-4 gm −3 in the tank the concentration, blowers have to provide an amount of oxygen greater than or equal to the amount evaluated as: The aeration power demand, AP (kW), is calculated from the k La according to the following relation [22], valid for Degrémont DP230 porous disks at an immersion depth of 4 m: The power needed for pumping, PP (kW), is calculated as: where Q int is the internal recirculation flow rate (m 3 d −1 ), Q r is the external recirculation flow rate (m 3 d −1 ) and Q w is the waste-activated sludge flow rate (m 3 d −1 ). The mixing power, MP (kW), is also considered. According to the COST benchmark, for all five tanks, the power is calculated only if k La is lower than 20 d −1 : where V is the volume of the tank (m 3 ). If the available power is greater than the demand (AP + PP + MP), k La remains equal to the previously calculated value. If the available power is lower than the demand, k La is instead recalculated, but in this case, the biological process is performed at lower effluent quality. For this reason, an effluent quality index (EQI) (kg pollutions d −1 ), based on a weighting of the compounds into effluent, e, having main influence on the quality of the receiving water, was evaluated in the model. It is defined as: (B TSS TSS e + B COD COD e + B NK S NK,e + B NO S NO,e + B BOD5 BOD 5,e ) Q e (A10) where B i are weighting factors, as deduced from Reference [23].