of Chemical Engineering MODELING THE TWO-STAGE ANAEROBIC DIGESTION OF DOMESTIC WASTEWATER WITH THE DEVELOPMENT OF A MONITORING APPLICATION

The IWA Anaerobic Digestion Model No. 1 (ADM1) was chosen to simulate a two-stage anaerobic digestion lab-scale plant treating domestic wastewater. Initially, the model was preliminary tested using synthetic wastewater. The simulation results were satisfactorily compared to NH4 and chemical oxygen demand (COD) data for the first and second stages, respectively. A transformation method was then applied to estimate from the domestic wastewater composition the input variables to the ADM1. After proper calibration and further validation, the model was able to successfully predict the COD degradation from a varying influent, showing its practical applicability. Finally, a standalone application based on the validated model was developed to be used for monitoring purposes at the treatment plant. The developed application is suitable for direct implementation at a full-scale plant without the need of additional software or specialized assistance.


INTRODUCTION
Although in the past anaerobic treatment was considered to be suitable only for high-strength wastewater, the anaerobic treatment of domestic wastewater is nowadays an emerging technology.The use of anaerobic treatment as the main process for domestic wastewater can help to improve sustainability due to low energy consumption, production of methane gas, and the opportunity for recovery of compounds of interest (e.g., nitrogen and phosphorous) during post-treatment (Foresti et al., 2006).For this purpose, a two-stage anaerobic digestion process can be suitable.The splitting of the process into two different reactors (acidogenic and methanogenic) can be more advantageous than maintaining a single reactor since the different groups of microorganisms involved in the degradation process perform better under different operating conditions (e.g., pH, reactor type) (Anderson et al., 2003).Nevertheless, some disadvantages are also to be expected.Anaerobic digestion is a complex process that involves microorganisms which are highly sensitive to overloads or disturbances of the process (Olsson et al., 2005).Due to this complex nature, the use of mathematical modeling is recommended since a well defined mathematical model can be highly effective for assessment, optimization and design of existing or suggested processes (Batstone and Keller, 2003).However, despite the fact that modeling of anaerobic wastewater treatment is an established field, anaerobic digesters are usually designed on a combination Brazilian Journal of Chemical Engineering of hydraulic and chemical oxygen demand (COD) mass loading (Batstone, 2006).Moreover, control applied in most anaerobic treatment plants is restricted to local strategies such as keeping pH and temperature constant (Murnleitner et al., 2002).
In the specific case of anaerobic treatment of domestic wastewater, published modeling studies are limited in number when compared to primary, activated sludge and industrial wastewater, but are well directed at specific issues (Batstone, 2006).Examples are the work of Zakkour et al. (2001), where modeling was used to perform an analysis of the design of a low-temperature and low-strength twostage anaerobic treatment; or the work of Zaiat et al. (2000), where a mathematical model was implemented to design a horizontal-flow anaerobic immobilized biomass reactor.As in the previous examples, most of these studies have concentrated on design, with a general use of first-order models and steady state solutions.However, modeling for operational analysis and technology development requires more complex models such as the Anaerobic Digestion Model No. 1 (ADM1) (Batstone, 2006).
The ADM1 is a comprehensive well-structured model published by the International Water Association (IWA) that describes the anaerobic digestion process in a continuous stirred-tank reactor (CSTR) (Batstone et al., 2002).The model applicability has been successfully proven by several authors under different operating conditions, including complex reactor configurations such as re-actors with biofilms (Ramirez et al., 2009;Chen et al., 2009;Dereli et al., 2010) and two-stage systems (Blumensaat and Keller, 2005;Chen et al., 2009;Muha et al., 2013).Moreover, Bensmann et al. (2013) carried out a simulation analysis applying the ADM1 to different reactor configurations while fixing conditions such as substrate composition and microbial community.Nevertheless, most of the published studies refer to the treatment of high-strength wastewater (Blumensaat and Keller, 2005;Fezzani and Cheikh, 2008;Wichern et al., 2008;Chen et al., 2009;Dereli et al., 2010).For a comprehensive review regarding the current status of anaerobic digestion modeling, the reader is directed to the analysis made by Lauwers et al. (2013).
On the other hand, the implementation of complex models such as the ADM1 usually requires specialized mathematical software and the engagement of experts in the subject.Consequently, applications directly in the control system of a treatment plant are hard to achieve.This can be seen as a disadvantage since the use of mathematical modeling not only for simulation but also for control purposes is related to the further optimization of anaerobic digestion technology (Lauwers et al., 2013).A modeling application able to provide an integral view of the processes beforehand can help to improve the plant performance.
In the present study, the ADM1 was chosen to simulate the COD degradation during treatment of domestic wastewater in a two-stage anaerobic digestion lab-scale plant.Additionally, an application based on the implemented model was developed to be used for monitoring purposes at a full-scale plant.The developed application must be suitable for direct implementation in the control system of the treatment plant without the need of additional software (standalone) or specialized assistance.Overall, the following objectives were defined: i Since the components in domestic wastewater can be highly fluctuating (e.g.seasonal variations), the model was preliminarily tested using synthetic wastewater.
ii A method to estimate the input variables to the ADM1 from the domestic wastewater composition was selected and the resulting model calibrated.
iii The calibrated model was further validated with a new set of experimental data.iv Finally, the standalone application was developed.

Two-Stage Anaerobic Digestion Plant
A two-stage anaerobic lab-scale plant was used as the object of study.The lab-scale plant consisted of two separate reactors to carry out the anaerobic digestion process.A general scheme is given in Figure 1.
The first reactor (R1), or acidogenic reactor, was a sequencing batch reactor (SBR) with mechanical stirring, a total volume of 13 L and temperature and pH control (Benning et al., 2012).The reactor was stirred at 300 rpm.The set-points of the temperature and pH were set to 35 °C and 5.5, respectively.The reactor was inoculated with 4 L of sludge taken from the acidogenic reactor of a two-stage anaerobic digestion plant in Obermichelbach, Germany.The SBR was operated in batch mode and fed with 7 L of influent (11 L of reaction volume).The treatment time was 24 hours.Once the treatment time had been reached, the stirring was deactivated and a settling period of 0.25 hours was established to allow the biomass to settle.Afterwards, the effluent was pumped to the middle tank.The second reactor (R2), or methanogenic reactor, was a fixed bed reactor (FBR) with a coconut fiber mat as carrier, mechanical stirring, recirculation pump, total volume of 26 L and temperature and pH control (Benning et al., 2012).Additional to the recirculation flow, the stirring was included to assure a rapid mixing in the lower part of the FBR where the dosage system of the pH control was located.The reactor was stirred at 250 rpm and the recirculation flow had a flow rate of 400 mL/min.
The set-points of the temperature and pH were set to 35 °C and 7.0, respectively.The reactor was inoculated with 5 L of sludge coming from the methanogenic reactor of the previously mentioned plant in Obermichelbach, Germany.The FBR was operated in batch mode and fed with 14 L of the effluent of R1 coming from the middle tank (19 L of reaction volume).The outlet of the middle tank was located at the bottom and the content mixed before emptying it to R2.The treatment time in R2 was 48 hours (double of R1).

Experimental Measurements
In order to validate the model, NH 4 + and COD measurements were taken from the lab-scale plant.
The COD measurements were performed for samples taken from R1 and R2 using the analyzer QuickTOC ® from the company LAR AG, Berlin, Germany.
The NH 4 + measurements were taken from R1 using an NH 4 Dsc1000 ammonium sensor from the company Hach Lange GmbH, Du¨sseldorf, Germany.

Wastewater Characteristics
Before operating the lab-scale treatment plant with domestic wastewater, during the start-up process of the plant the reactors were fed with synthetic wastewater.This was done for the following two reasons: 1) to ensure the adaptation and enrichment of the inoculated sludge and 2) to test the performance of the model since the components in the synthetic wastewater could be well characterized and controlled.

Synthetic Wastewater Characteristics
For the preparation of the synthetic wastewater, a suitable mix for the microorganisms present in each reactor was accordingly prepared.The synthetic wastewater for R1 was prepared by adding sucrose (carbohydrate) and peptone (protein) as COD sources and a mix of trace elements as follows (g/L): NaHCO 3 0.  (Singh et al., 1995).The amounts of sucrose and peptone added accounted for a COD range between 750-2333 mg COD/L.
The synthetic mix for R2 was prepared according to Kuba et al. (1990)

Domestic Wastewater Characteristics
After testing the model with synthetic wastewater, the feeding of the plant was changed to the target wastewater, i.e., domestic wastewater.The wastewater was periodically collected from a sewage treatment plant in Erlangen, Germany, and preserved in a storage tank under 4 °C.Its characteristics are presented in Table 1.These values were taken from the laboratory analysis made weekly at the sewage plant and only recorded once after the wastewater was collected to reproduce full-scale "real life" conditions, where the monitoring parameters are only periodically measured.

Model Description
The model implemented in this study is the ADM1 (Batstone et al., 2002).The ADM1 is a COD basis structured model that describes the anaerobic digestion process through a set of biochemical and physicochemical processes in a CSTR.The biochemical processes included in the model are: disintegration of composites (X C ) to carbohydrates (X ch ), proteins (X pr ), lipids (X li ) and inerts (soluble, S I ; particulate, X I ), hydrolysis of carbohydrates, proteins and lipids to sugars (S su ), amino acids (S aa ) and long chain fatty acids (LCFA) (S fa ), respectively, acidogenesis from sugars and amino acids to volatile fatty acids (VFA) (valerate, S va; butyrate, S bu ; propionate, S pro ) and hydrogen, acetogenesis from LCFA and VFA to acetate (S ac ), separate methanogenesis from acetate and hydrogen/CO 2 , and the corresponding biomass decay processes (for sugars degraders, X su ; amino acids degraders, X aa ; LCFA degraders, X fa ; valerate and butyrate degraders, X c4 ; propionate degraders, X pro ; acetate degraders, X ac ; and hydrogen degraders, X h2 ).
These biochemical processes are described either by first-order rate equations or Monod-type growth kinetic equations.First-order rate equations are used to model disintegration, hydrolysis and decay processes.Monod-type growth kinetic equations are used to model substrate uptake in the acidogenic, acetogenic and methanogenic steps.The ADM1 stoichiometric matrices for the biochemical processes and their corresponding kinetic rate equations are presented in the Appendix.
On the other hand, the physicochemical processes included are non-biological processes that include six acid-base reactions and three liquid-gas transfer processes.The acid-base reactions are NH 4 + /NH 3 , CO 2(aq) /HCO 3 -, acetic acid/acetate, propionic acid/propionate, butyric acid/butyrate and valeric acid/valerate.Through the acid/base reactions the pH can be predicted by determining the hydrogen ion concentration.In the liquid-gas transfer processes CH 4 , CO 2 and H 2 are considered.Additionally, the model includes different inhibition functions for the biomass groups regarding pH, hydrogen, free ammonia and a secondary Monod kinetics function to prevent growth when nitrogen is limited.

Model Implementation
The ADM1 was implemented as a differential equations (DE) system (Batstone et al., 2002).The derived model consisted of a set of 32 dynamic concentration state variables.The mass balance equation for each dynamic state variable in the liquid phase is expressed as (Batstone et al., 2002): where S i is the concentration of soluble component i, S in,i its input concentration, q the flow in and out of the reactor, V liq the liquid reactor volume, and the term 19 , 1 j i j j ρ ν = ∑ refers to the sum (for all processes j) of the kinetic rate equation ρ j multiplied by the stoichiometric coefficient v i,j .
In a DE system implementation, the inorganic carbon and the inorganic nitrogen states are divided into two variables each (CO 2 /HCO 3 -and NH 4 + /NH 3 , re-spectively).As recommended by Blumensaat and Keller (2005) in the case of inorganic nitrogen, the biochemical rate equation terms were applied to ammonium rather than ammonia since ammonium is the quantitatively dominant form (see Table A.1).
The state variable for composite material is used in ADM1 as a sink for decayed biomass.However, the carbon content of composites (C C ) and the carbon content of biomass (C bac ) vary significantly.The same is found again in the case of nitrogen content of composites and biomass (N C and N bac , respectively) (Blumensaat and Keller, 2005).Therefore, as suggested in Blumensaat and Keller (2005), new balance terms were added in order to close the carbon and nitrogen balances.The stoichiometric term C bac −C C was added to each of the biomass decay processes for bicarbonate (inorganic carbon) (see Table A.1).Similarly, the stoichiometric term N bac − N C was added for ammonium (inorganic nitrogen) to all biomass decay processes (see Table A.1).
The software used for the model implementation was MATLAB/Simulink.Models like ADM1, which have a large range of time constants are considered to be stiff models (Rosen et al., 2006).Hence, the variable-step solver from MATLAB ode15s specifically recommended for this type of DE systems was chosen.

Model Modifications
Some modifications were made to the implemented ADM1 in order to make it suitable for the two-stage anaerobic digestion plant under study.First, since the anaerobic digestion process to be modeled was carried out in two distinct reactors, two separate models were implemented.In each model, the concentration of specific biomass groups was varied according to the processes taking place in the corresponding reactors.In the case of R1 (acidogenic reactor), it was assumed that mainly hydrolysis and acidogenesis took place.On the other hand, it was assumed that only acetogenesis and methanogenesis took place in R2 (methanogenic reactor) (Anderson et al., 2003).The resulting models were joined together and the output products from the acidogenesis in R1 (valerate, butyrate, propionate and acetate), together with the output HCO 3 -(S HCO3 ) and NH 4 + (S NH4 ), were linked as input to the processes taking place in R2.
As mentioned before, the two-stage lab-scale plant consisted of a SBR and a FBR operated in batch mode.Although the ADM1 was developed to be implemented for continuous operation in a CSTR, it is suggested in the original report (Batstone et al., 2002) that the biomass mass balance equations can be adjusted to account for a difference between the hydraulic retention time and the solids retention time when dealing with different reactor configurations.In the present study, no sludge was removed from the reactors during the collection of experimental data.Therefore, washout was only considered for any biomass being pumped out from R1 during the decant step due to excess sludge production or suspended biomass and, in the case of R2, for any detachment from the fixed bed.Since this was a batch operated process, no flow rate was applied (q = 0) and new initial conditions were calculated at the beginning of each batch period as indicated in the following equation: where t = a represents the integration time step at which the batch process is initiated, X i the concentration of the particulate biomass component i, X in,i the input concentration (only ≠ 0 at t = 0) and F the washout factor.This factor was deliberately set to consider only a 5% washout for both reactors.
On the other hand, the reactors were equipped with a pH-controller specially developed for the plant's concept (Benning et al., 2012).Due to this fact, a simplification made to the original ADM1 was establishing a fixed pH.The pH is a faster state variable compared to most of the other variables in the ADM1 which contributes, together with the hydrogen state, to the stiffness of the model (Rosen et al., 2006).According to the operating conditions, the simulated pH of R1 and R2 were fixed to 5.5 and 7.0, respectively.
In order to assure that the storage time in the middle tank when feeding domestic wastewater had no influence on the overall process, COD measurements were taken from the effluent of R1 and com-pared to the measurements taken from the middle tank before feeding R2.The average difference between these values was equal to 4.3% (±0.03).Therefore, it was assumed that the treatment time in R1 was long enough so that no further degradation could occur during storage.As a result, no additional changes were realized to the implemented model, since the minimal degradation that might have taken place in the middle tank did not justify increasing the model complexity.
Finally, an additional transformation method was implemented in order to be able to properly characterize the domestic wastewater for the input components required by the ADM1.The procedure fol-Brazilian Journal of Chemical Engineering lowed is described in the section below.
The simulated COD results compared to the experimental measurements to evaluate the performance of the model corresponded to the sum of the COD basis variables in ADM1 excluding the particulate biomass components.This was calculated for each reactor as follows: A proper characterization of the influent substrate is necessary for the successful application of the ADM1 (Zaher et al., 2009;Kleerebezem and Van Loosdrecht, 2006;Lu¨bken et al., 2007).For this purpose, practical measurements of the wastes can be used for characterization and estimation to give more detailed input to the model (Zaher et al., 2009;Kleerebezem and Van Loosdrecht, 2006).The transformation method to be applied in the present study must not add any additional costs to the treatment process (e.g., elaborate laboratory analysis).Therefore, only a minimum number of practical measurements were chosen as sources for the estimations.Furthermore, more importance was given to the estimation of the reported main components in domestic wastewater.According to Schlegel and Fuchs (2007), the organic fraction in domestic wastewater is mainly composed of 50% carbohydrates, 40% proteins and 10% lipids.As a result, the practical measurement COD was selected to be partitioned into the initial concentration of carbohydrates, proteins and lipids according to these proportions.Additionally, the practical measurements total ammonia-nitrogen (TAN) and total inorganic carbon (TIC) were chosen for the direct estimation of the initial concentrations of inorganic nitrogen (as NH 4 + ) and inorganic carbon (as HCO 3 -), respectively, by simply adjusting the units.

Parameter Estimation
All the stoichiometric coefficients, physicochemical and most of the kinetic parameters were taken without any modifications from the original ADM1 (Batstone et al., 2002).Only a set of 5 kinetic parameters were tested for calibration as they have been identified in several studies as the most sensitive parameters (Blumensaat and Keller, 2005;Fezzani and Cheikh, 2008;Feng et al., 2006;Wichern et al., 2008).These parameters are: disintegration constant (k dis ), maximum uptake rate for acetate degraders (k m,ac ), maximum uptake rate for propionate degraders (k m,pro ), ammonia inhibition constant for acetate degraders (K I,NH3,ac ) and hydrogen inhibition constant for propionate degraders (K I,H2,pro ).
The iterative method followed for parameter calibration is presented in Figure 2. First, an initial model run was executed using the default values taken from the literature.Subsequently, the simulated results regarding COD (S COD ; see Eq. ( 3)) were compared with the experimental COD measured from R2.After comparison, the parameters were manually adjusted.This process was repeated until achieving the best fit.The results of the parameter calibration including the initial and calibrated values for both synthetic and domestic wastewater are presented in Table 2.  † K I,H2,pro calibrated value for DWW modified to the one recommended by Blumensaat and Keller (2005).
In the case of synthetic wastewater, the estimated parameters k m,ac and k m,pro had to be set one order of magnitude smaller than the ones recommended in Batstone et al. (2002).However, these values are similar to the ones reported by Kuba et al. (1990) (k m,ac = 0.26 day -1 and k m,pro = 0.19 day -1 ) when treating the same synthetic mix.

Synthetic Wastewater
The implemented model was initially tested using the experimental data obtained when treating synthetic wastewater.As described before, each reactor was fed with a specific synthetic mix.More importance was given to monitor the COD in R2 where the methanogenesis took place and, as a result, most of the degradation occurred.Therefore, COD measurements were used to evaluate the simulation results of R2.On the other hand, NH 4 + measurements were chosen to evaluate the simulation results of R1.This was done since monitoring the ammonium concentration can be particularly interesting for systems with a considerable nitrogen load such as domestic wastewater plants (arising from the decomposition of proteins and urea).The performance of the simulations was evaluated after proper parameter calibration of the most sensitive parameters (see Table 2).The comparisons between measured and simulated values are shown in Figure 3 for both reactors.
The model predicted with good accuracy the changes in NH 4 + concentration (Figure 3a) from varying input data.These changes derived mainly from the increase or decrease of the input peptone (protein source) since the synthetic mix was made with a fixed NH 4 + concentration.On the other hand, the model predicted very well the COD degradation in R2 (Figure 3b) after feeding of a relatively constant influent.Feeding a synthetic medium to R2 (instead of the effluent from R1) facilitated the preliminary evaluation of the model performance by allowing an accurate characterization of the input variables.

Model Calibration
Once the preliminary model was successfully evaluated with synthetic wastewater, the modified model for the two-stage anaerobic digestion of domestic wastewater was calibrated after treatment of the domestic wastewater with the characteristics presented in Table 1.For the model calibration, COD measurements taken from R2 were used.The initial results were much higher in comparison with the measured input COD (data not shown).This higher prediction was due to the fact that a significant part of the COD was diffused in the fixed-bed immediately after filling R2 with the effluent of R1.Therefore, the further degradation of the diffused COD could no longer be quantified during sampling.Further experiments were made to determine the percentage of diffused COD.These experiments involved comparing the value measured from the effluent of R1 with the value of the sample taken immediately after R2 had been filled (time zero of a batch period for R2).The results showed an average reduction in COD to 46% (0.08 STD).
Since the diffusion phenomenon occurred at a high rate, the process velocity was assumed to be mainly controlled by the biochemical rates.As a result, new equations to account for diffusion rates were not included to the model.However, in order to account for the reduction in COD without significantly increasing the model complexity, the input COD basis variables to R2 (simulated output of R1 concerning valerate, butyrate, propionate and acetate) were divided into fixed and non-fixed components.This partitioning was performed using the experimentally calculated factor of 46% as follows: where S i,R1 is the simulated output from R1 of component i, and InS i,R2 and InS i,R2 , fixed the simulated input for the second stage of the anaerobic digestion process to take place in R2.The resulting fixed components (S i,R2,fixed ) were considered as independent from their non-fixed counterparts (S i,R2 ) with their own mass balance and kinetic rate equations.The kinetic parameters used for the additional equations were the same as the ones used for the corresponding non-fixed variables.It can occur that the reduction factor changes over time due to factors such as clogging of the biomass in the fixed-bed.If necessary, this factor can be easily adjusted for further simulations by measuring the influent and effluent COD of R2 in a small series of experiments.However, the effect of clogging is expected to be minimal as a result of biomass detachment caused by the hydrodynamic stress (Escudie et al., 2005), if the operating conditions regarding stirring and recirculation are maintained.Moreover, the reduction factor assures model flexibility since the equations can be easily adjusted in the case of new conditions such as a change of the fixed-bed or plant scale-up.
After the modifications were applied, the measured COD from R2 was used for parameter calibration (see Table 2).The comparison between the measured and the simulated COD is shown in Figure 4.The simulated results adjusted well to the measured values after proper parameter calibration.However, some deviations in the initial COD (first measured value in a batch period) were occasionally observed.These deviations may mainly come from the fact that the practical measurements of the domestic wastewater (model input) were only recorded once after the wastewater had been collected from the local sewage plant.This was done to evaluate if the model could adequately simulate the degradation process in the lab-scale plant following "real life" conditions, where the monitoring parameters are only periodically measured.Therefore, some of the characteristics of the domestic wastewater may have changed during storage since new wastewater was collected approximately every two weeks.Even so, the model was able to yield satisfactory results, showing its practical applicability.

Model Validation
After successful calibration of the model, the optimized parameters and a new set of experimental data were used for model validation.Again, COD measurements taken from R2 when treating the domestic wastewater were compared to the simulation results.The comparison between the measured and the simulated COD is shown in Figure 5.The model successfully predicted the degradation of COD in R2 from a varying influent without the need for further parameter optimization.Similar to Figure 4, some occasional deviations in the initial COD were observed.However, these deviations were neglected as more importance was given to the practical applicability of the model (as explained in the previous section), which was able to yield satisfactory results even though the input parameters were only periodically recorded.Additionally, the comparison between measured and simulated effluent COD from R1 is presented in Figure 6 together with the influent COD (measured from the domestic wastewater).The deviations observed between the measured and simulated effluent data were mainly due to the presence of suspended biomass in the samples taken from R1, since the measured effluent COD was repeatedly even higher than the measured influent.Nevertheless, the simulation results followed a congruent tendency when compared to the measured input COD since only a minimal degradation was expected to occur in R1.

STANDALONE APPLICATION
One of the objectives behind the implementation and validation of the ADM1 was to develop an application that could be used for process monitoring of a two-stage anaerobic full-scale plant treating domestic wastewater without the necessity of additional software.This standalone application was conceptualized to cover a complete process cycle of the twostage plant within each model run.A cycle was defined as two serial feedings of R1 and the successive feeding of R2 where the treatment time of R2 doubles the one of R1.
In order to develop the application, the Real-Time Workshop (RTW from MATLAB/Simulink was used.The RTW is a code generator that automatically generates C/C++ code from Simulink models.Additionally, the Visual Studio 2010 Professional Software was chosen to further develop the application.By selecting the Generic Real-Time (GRT) system target file in the RTW, a Visual Studio Solution including the generated C++ model code was automatically created.However, the GRT target cannot be used with a variable-step solver such as the previously applied ode15s.Therefore, the ode14x fixed-step solver from MATLAB was evaluated beforehand.The ode14x is an implicit fixed-step solver recommended as first choice when changing from a variable-step solver (Mathworks, 2013).
Consequently, before moving forward with the code generation, an analysis was made to determine if the solver ode14x could yield equivalent results to the solver ode15s.The simulation time for the comparison analysis matched a complete plant process cycle as the standalone application was conceptualized to cover.Two sets of practical measurements (model input) were given to comprise the process cycle.The input parameters were: Input 1: COD = 309 mg COD/L; TAN = 17 mg N/L; TIC = 74 mg C/L.
The simulation results of the COD degradation in R1 and R2 after applying the two different solvers are shown in Figure 7.The results did not differ significantly in both cases.Low mean absolute errors (MAE) of 1.23x10 −4 and 4.49x10 −4 were found for the simulated COD in R1 and R2, respectively.Hence, the solver ode14x was considered suitable for simulating one process cycle.
After successfully testing the fixed-step solver, the generated C++ code was further modified and an executable file (".exe") was created.The computing time of the program takes in total only a fraction of a second for a process cycle simulation time up to 10 days.Finally, a user-friendly platform was developed using again the Visual Studio software.From the interface the user is able to enter the practical measurements of the domestic wastewater, set the process cycle simulation time and run the model.After the model has been executed, the user obtains the graphs of the COD degradation in R1 and R2 displayed directly on the interface screen.Additionally, the output data is simultaneously stored into text files.
Once the application was fully terminated and running, its final output was compared to the results obtained during the previous analysis.As can be seen in Figure 7, no significant difference was found between the simulation results of the different implementations of the model and the results basically overlapped each other.As for the initial analysis, low MAE of 5.97x10 -4 and 4.62x10 -4 were found for the simulated COD in R1 and R2, respectively, when comparing the application output (using solver ode14x) with the results yielded by the original model implemented in MATLAB/Simulink (using the ode15s solver).Therefore, the standalone application was considered to be suitable for simulation of the plant process cycle.

CONCLUSIONS
The modified ADM1 applied in the present study was able to accurately predict the COD degradation process in the two-stage anaerobic digestion labscale plant.During the preliminary test with synthetic wastewater, the simulation results were satisfactorily compared to experimental data of NH4 + and COD concentrations for R1 and R2, respectively.The further modified model for the anaerobic digestion of domestic wastewater was subsequently calibrated and validated using COD measurements taken from R2.The input given to the model was a set of practical measurements usually used for process monitoring at full-scale treatment plants.The model was able to successfully predict the COD degradation from a varying influent proving its practical applicability, as the input measurements were only periodically recorded to simulate "real life" conditions.
Finally, a standalone application for process monitoring of a two-stage anaerobic digestion plant treating domestic wastewater was developed and will be tested in future work in a full-scale plant.Since the application was conceptualized to cover one process cycle with each model run, its implementation is thought to be suitable for plants working with stable conditions (with a stabilized biomass population).The application requires no additional software and the computing time can be considered minimum since it requires only a fraction of a second for a process cycle simulation time up to 10 days.Moreover, the user-friendly interface can be easily operated by untrained personal.This application represents a first attempt to make the implemented mathematical model accessible in the daily operation of a full-scale domestic wastewater treatment plant for control purposes.In future studies, it could be further modified according to the end-user's requirements to include any other desired variables from the wide range available in ADM1.For example, for systems with a significant nitrogen load such as in domestic wastewater treatment, the prediction of the NH 4 + concentration throughout the process could be included.Further improvements could include a data exchange package that would allow the standalone application to work as an on-line estimator.
The modified ADM1 implemented in this study can be used for design and start-up of a new plant as well as for the optimization of existing plants.On the other hand, the developed standalone application can be used for process monitoring of an established plant.Together, these tools represent different strategies of how mathematical modeling can help to improve biotechnological processes in general.

Figure 1 :
Figure 1: General scheme of the two-stage anaerobic digestion lab-scale plant.

Figure 2 :
Figure 2: Iterative method used for parameter calibration.

Figure 3 :
Figure 3: Comparison between measured and simulated results during treatment of synthetic wastewater after parameter calibration: (a)NH 4 -R1; (b) COD -R2.Error bars according to STD.

Figure 4 :
Figure 4: Comparison between measured and simulated COD of R2 when treating domestic wastewater after parameter calibration.Error bars according to STD.

Figure 5 :
Figure 5: Comparison between measured and simulated COD of R2 after treatment of domestic wastewater for model validation.Error bars according to STD.

Figure 6 :
Figure 6: Comparison between measured and simulated effluent COD of R1 together with the in-fluent COD measured from the domestic wastewater.Error bars according to STD.

Table 1 : Characteristics of the raw domestic waste- water.
* Average of 11 samples taken over a period of 105 days.