Improvement of Biogas Production Utilizing a Complex Anaerobic Digestion Model and Gradient-Based Optimization

: Anaerobic digestion (AD) is a promising technology for renewable energy production from organic waste. In order to maximize the produced biogas quantity and quality, this paper deals with the optimization of the AD process in a CSTR bioreactor of a full-scale biogas plant. For this purpose, a novel approach was adopted coupling, a highly complex BioModel for AD simulation, and a gradient-based optimization method. In order to improve AD performance, the dosages of various types of biological additives, the dosages of inorganic additives, and the temperature in the bioreactor were optimized in three different scenarios. The best biogas quality was obtained using multi-objective optimization, where the objective function involves the following two conflicting objectives: the maximization of biogas production and minimization of the needed heating energy. The obtained results show that, potentially, the content of CH 4 can be increased by 11%, while the contents of H 2 , H 2 S, and NH 3 can be reduced by 30%, 20%, and 81% when comparing the simulation results with the experimental data. The obtained results confirm the usefulness of the proposed approach, which can easily be adapted or upgraded for other bioreactor types.


Introduction
In the quest to reduce waste and produce energy, the anaerobic digestion (AD) process plays an important role [1,2].AD is a very complex process, including hydrolysis, acidogenesis, acetogenesis, and methanogenesis, where the activity of various types of microorganisms in an oxygen-free environment degrades carbohydrates, lipids, and proteins from organic wastes into biogas [3,4].Biogas production, as well as other important AD performances, depend on waste characteristics (waste types, composition of feeding complex substrate, chemical properties, waste pretreatment, etc.), additives (inoculum, trace elements, enzymes, etc.), and AD process conditions [5,6].Among others, this means that by simultaneously digesting two or more organic substrates, a more favorable composition of the substrate for the AD process can be obtained.Consequently, a more stable AD process, as well as enhanced biogas and CH 4 production, can be achieved.Furthermore, the AD process's parameters, such as temperature, pH value, and additives, highly influence the formation and quality of the produced biogas and digestate [1,2].The AD process can be performed under psychrophilic (10-25 • C), mesophilic (25-45 • C), and thermophilic (45-65 • C) temperature conditions [1,7].Temperature affects the microorganism community, processes stability, and AD products.Some investigations show that biogas production rises with increased temperature while the content of CH 4 in the produced biogas reduces [3].However, performing AD in mesophilic conditions enables the most stable AD process [3] and requires less energy to heat up the bioreactor [4].To determine the optimal temperature for a particular AD process in a full-scale biogas plant, the interaction Energies 2024, 17, 1279 2 of 17 between temperature and other parameters, such as pH value, nutrients, waste characteristics, and additives, should also be considered [5].The pH value in the bioreactor influences the growth and activities of microorganisms, the proportion of ionized and non-ionized forms of various compounds (excessive hydrogen sulfide, fatty acids, and ammonia are toxic in their non-ionized forms), and the quantity and quality of produced biogas [8].Each enzyme and bacteria type has its own optimum range of the pH value.For example, the optimum pH range for acidogenic bacteria is 5.5-6.5, while the pH from 6.5 to 8.2 is suitable for methanogenic bacteria [9].The pH value and its variation during the AD process depend on instantaneous ionic species concentrations in the bioreactor [10].To assure an adequate pH value, to overcome the inhibition of the microorganism's activity, and to enhance the AD process, adequate additives should be used [3].The most frequently used inorganic additives contain heavy metals, antifoaming reagents, and agents to enhance the AD process.Heavy metals may take part in various physico-chemical processes; they can form precipitates with sulfides, carbonates, and phosphates, and they can also form complexes with some AD intermediates [11].For example, Abarghaz et al. [12] reported that a concentration at CaCO 3 of around 1.5 gL −1 is recommended for the AD process.Heavy metals, which are necessary for enzyme activation, can be stimulatory, inhibitory, or even toxic in biochemical reactions, depending on their concentrations.Many investigations show that various inorganic additives have to be added very carefully.For example, Mudhoo et al. [13] reported that a concentration of Ca 2+ over 7 gL −1 can have an inhibitory effect on the AD process of synthetic waste.Guo et al. [14] showed that low concentrations of Cu 2+ (< 0.1 gL −1 ), Fe 2+ (< 4 gL −1 ), Ni 2+ (< 0.1 gL −1 ), and Zn 2+ (< 0.005 gL −1 ) promote biogas production, while higher concentrations of these heavy metals can inhibit the AD process.Furthermore, the proper addition of FeCl 2 can improve CH 4 content in the produced biogas [15] and reduce odor-causing H 2 S via the precipitation of FeS [16].In general, various inorganic additives comprise chemical reagents, minerals, and waste sources and are able to provide micronutrients and/or promote biomass immobilization.Furthermore, the addition of biological additives, enzymes, and microorganisms, as well as the selection or manipulation of particular groups of microorganisms within the bioreactor, can improve AD performance essentially [17].All these mentioned possibilities are investigated not only experimentally but also by numerical simulations, which provide a useful tool for AD process understanding and optimization.To better understand the AD process, reliable mechanistically inspired models for the numerical simulation of processes in an anaerobic bioreactor, based on ADM1 and BioModel, seem to be the preferred option [1,6,[18][19][20][21][22][23][24].So far, AD process optimization has been mostly performed using the genetic algorithm, particle swarm, and ant-colony algorithms [25][26][27], while gradient-based optimization methods were engaged relatively rarely [28,29].Elagroudy et al. [28] used a gradient-based optimization method in order to find the best empirical kinetic model for the simulation of biogas production; various kinetic and performance parameters of several models (modified Gompertz, logistic model, reaction curve-type, and exponential rise to maximum) were calibrated.Furthermore, a high number of model parameters in a mechanistically inspired BioModel were calibrated by an approximation-type gradient-based optimization method quite efficiently [1,6].A gradient-based algorithm also proved to be stable and efficient in determining AD process parameters (temperature and pH value) when using a simple mechanistically inspired model [29].However, to the best of the authors' knowledge, the coupling of complex mechanistically inspired mathematical models with a gradient-based algorithm in an optimization procedure of a full-scale biogas plant has not been adequately investigated and surely deserves some attention.More specifically, it is not known how a highly complex AD model would behave when engaged in gradient-based optimization.This includes unknown consequences resulting from the presumably very complicated feasible domain space of the optimization problem and the use of numerically obtained design derivatives.The novelty of this work is in trying to build such a scenario with the aim of obtaining more insight into possible difficulties and, more importantly, potential gains in developing future AD technologies.In this paper, attention is focused on the optimization of the AD process in a fullscale biogas plant by coupling a complex mechanistically inspired BioModel and an approximation-type gradient-based optimization method.In order to improve biogas quantity and quality, three different cases of AD optimization were performed, i.e., the objective functions and constraints were defined in three ways.In all cases, the temperature and the amount of various biological and inorganic additives were used as design variables.Note that by varying inorganic additives' dosages, one can influence the ionic species concentrations, as follows, from the corresponding acid-base equilibrium equations.In this way, the pH value is also effectively and indirectly optimized.

Biogas Plant Data
In order to obtain adequate experimental data, the AD process was observed in a full-scale biogas plant in Draženci (Slovenia) for a period of one year.This plant had two mesophilic and continuously mixed reactors (CSTRs).Each single-stage CSTR had a volume of 2500 m 3 , and there was one common gas storage facility with a volume of 2500 m 3 .
The measured yearly histories of the complex substrate (F-CS) loading rate, pH value, and temperature in the CSTRs are presented in Figure 1.The pH value throughout the AD process was 7.7 ± 0.1, while the temperature was 42.5 ± 2.1 • C. The retention time in the CSTRs was approximately 33 days, and the AD process took place at a pressure of 1.006 bar.
Energies 2024, 17, x FOR PEER REVIEW 3 of 18 such a scenario with the aim of obtaining more insight into possible difficulties and, more importantly, potential gains in developing future AD technologies.In this paper, attention is focused on the optimization of the AD process in a full-scale biogas plant by coupling a complex mechanistically inspired BioModel and an approximation-type gradient-based optimization method.In order to improve biogas quantity and quality, three different cases of AD optimization were performed, i.e., the objective functions and constraints were defined in three ways.In all cases, the temperature and the amount of various biological and inorganic additives were used as design variables.Note that by varying inorganic additives' dosages, one can influence the ionic species concentrations, as follows, from the corresponding acid-base equilibrium equations.In this way, the pH value is also effectively and indirectly optimized.

Biogas Plant Data
In order to obtain adequate experimental data, the AD process was observed in a full-scale biogas plant in Draženci (Slovenia) for a period of one year.This plant had two mesophilic and continuously mixed reactors (CSTRs).Each single-stage CSTR had a volume of 2500 m 3 , and there was one common gas storage facility with a volume of 2500 m 3 .
The measured yearly histories of the complex substrate (F-CS) loading rate, pH value, and temperature in the CSTRs are presented in Figure 1.The pH value throughout the AD process was 7.7 0.1, while the temperature was 42.5 2.1 °C.The retention time in the CSTRs was approximately 33 days, and the AD process took place at a pressure of 1.006 bar.The F-CS consists of the following: (i) food waste (FW) and poultry manure (PM) from a chicken farm; (ii) fat matter (FM) from a slaughterhouse; (iii) corn meal (CM) and corn silage (CS) from local farmers; and (iv) added water (W).The daily variations in FW, PM, and CS fractions in the F-CS are shown in Figure 2a for a period of one year, while the corresponding data for CM, FM, and W are presented in Figure 2b.The composition of each substrate of the F-CS, Table 1, was determined by the methods described in the corresponding standards [6].To determine the biogas composition, the IR Gas Analyzer GA2000 plus was used.The F-CS consists of the following: (i) food waste (FW) and poultry manure (PM) from a chicken farm; (ii) fat matter (FM) from a slaughterhouse; (iii) corn meal (CM) and corn silage (CS) from local farmers; and (iv) added water (W).The daily variations in FW, PM, and CS fractions in the F-CS are shown in Figure 2a for a period of one year, while the corresponding data for CM, FM, and W are presented in Figure 2b.The composition of each substrate of the F-CS, Table 1, was determined by the methods described in the corresponding standards [6].To determine the biogas composition, the IR Gas Analyzer GA2000 plus was used.
To improve the AD process in the observed biogas plant, prevent foaming, and reduce H 2 S content in the produced biogas, some inorganic (SensoPower Liquid, purchased from Phytobiotics Futterzusatzstoffe GmbH, Eltville, Germany and Kemira BDP-840, purchased from Kemira Oyj, Helsinki, Finland) and biological (SensoPower Flex, purchased from Phytobiotics Futterzusatzstoffe GmbH, Eltville, Germany) additives were daily added to the F-CS.The SensoPower Liquid (SPL) contains all essential trace elements (Ni, Co, Na, Cu, and Se), which are important for the healthy development of the microorganisms; furthermore, they enable efficient fermentation and prevent foam development.The Kemira BDP-840 (Kemira) contains FeCl 2 which reduces the production of H 2 S during the AD process.The SensoPower Flex (SPF) contains enzymes (cellulase, xylanase, endo-1,4, . ..) to enhance hydrolysis in the AD process.The amounts of the added SPL, Kemira, and SPF are 1.0 L day −1 , 100 L day −1 , and 1500 g day −1 , respectively.The measured total unrefined biogas volume in one year was about 4,370,000 m 3 .The produced biogas contained approximately 54% CH 4 , 45% CO 2 , 60 ppm of H 2 , 200 ppm of H 2 S, and 800 ppm of NH 3 .

Numerical Simulation of the AD Process
To simulate the AD process, an in-house developed complex BioModel, which is described in detail in [1,6], was used.To summarize briefly, this model takes into account chemical (acid-base reactions), biochemical (hydrolysis, acidogenesis, acetogenesis, and methanogenis), and physico-chemical (liquid-gas and liquid-solid mass transfers) processes, where carbohydrates, proteins, and lipids degrade into CH 4 and many other by-products.The model contains 184 model parameters, which were calibrated by an active set optimization procedure with respect to the experimental data obtained from a full-scale biogas plant [1,6].In this model, the pH value was treated as a state variable and determined by the corresponding algebraic and differential equations.
The general assumptions are as follows: (i) biogas, containing CH 4 , CO 2 , H 2 , H 2 S, NH 3 , and H 2 O vapor, follows the ideal gas behavior; (ii) system pressure is constant; (iii) H 2 O vapor in biogas is at a saturation state; (iv) extracellular biochemical reactions are based on modified Michaelis-Menten kinetics; (v) intracellular biochemical reactions are based on Monod kinetics, modified including non-competitive microbial growth inhibitions; (vi) acid-base recombinations occur instantaneously; (vii) the amounts of added extracellular enzymes, which affect the hydrolysis of carbohydrates, proteins, and lipids, are equal; and (viii) the characteristics of a particular feedstock substrate are constant.

Optimization of the AD Process
In order to achieve the best AD performances of the considered biogas plant with prescribed feeding substrate composition and feeding strategy during a time period of 365 days, the following AD process parameters can be optimized: (i) biological additives (initial concentrations of bacteria groups and dosages of enzymes), (ii) inorganic additives, which are involved in the physico-chemical processes and affect the pH value; and (iii) temperature in the bioreactor.
The considered optimization problem can be defined as follows: ming 0 (x, q) (1) where the vectors xϵ R n * and qϵ R m * assemble the design and state variables, respectively; the time derivatives of the state variables are denoted by .
qϵ R m * .The dependency of q on t and x is given by the state equation, Equation (3), which is defined by the whole BioModel.The symbols g 0 and g i denote the objective and constraint functions, respectively.These functions involve various AD performance quantities and process parameters.The symbols n * , k * , and m * denote the number of design variables, constraints, and state variables, respectively.
To gain a better insight into the AD optimization process, three different optimization tasks were defined; these tasks are denoted in the following as cases A, B, and C.
Case A. The goal in Case A was to maximize the biogas production.Since the initial concentration of the complete microbial consortium has to be limited, the maximal concentration of all microbial groups in the feeding substrate was constrained.Therefore, the objective function g 0 and one constraint function g 1 are defined as follows: where Q biogas denotes the biogas flow rate, K biogas is the corresponding normalization constant, t total represents the total time of the AD process observation, t stab is the AD process stabilization time, X i is the initial concentration of the ith bacteria group, i ∈ I bac , while X max bac represents the maximal initial concentration of the sum of all bacteria groups.Case B. Since the presence of H 2 S in the biogas produced by AD can be high (up to 30,000 ppm), it can lead to many problems in biogas storage and its further use (boilers, turbines, gas engines, dual-fuel diesel engines, full cells. ..) [4].Note that besides causing the corrosion of various components, H 2 S is also toxic to methanogenic microorganisms.Therefore, the content of H 2 S in the produced biogas has to be limited.The goal in Case B is to maximize the biogas production while imposing the limitation of the total concentration of all bacteria groups and the content of hydrogen sulfide in the produced biogas; the corresponding objective and constraint functions g 0 and g 1 are given by Equations ( 4) and ( 5), while the constraint function g 2 is defined as follows: where Q H 2 S denotes the flow rate of H 2 S, while φ H 2 S,max is the prescribed maximal content of H 2 S in the produced biogas.Case C. Achieving an adequate AD process temperature for maximal biogas production would typically require heating up the bioreactors substantially, which may not be economically justified [4].Furthermore, it is worth noting that low AD process temperatures improve the process stability and inactivation of the pathogens.Since the cost of heating the bioreactor is desired to be minimal, this needs to be reflected in the definition of the optimization problem.This means that there are the following two objectives: biogas production maximization and heating cost minimization.Consequently, a multiobjective optimization problem has to be addressed.This is usually conducted by solving an adequate single-objective problem, which is obtained by summing individual weighted objective functions.In this work, the single-objective function was defined as follows: where ψ 1 and ψ 2 are the weighing factors for biogas production and heating cost, T is the temperature of the AD process, and K T is the temperature normalization constant.The objective in Case C was to maximize the biogas flow rate and minimize the bioreactor heating energy, while satisfying seven constraints.The first constraint was related to the total concentration of all bacteria groups; Equation (5).The next three constraint functions, which were related to the maximum allowed fractions of H 2 S, H 2 , and NH 3 in the produced biogas, were defined by Equation ( 6) for H 2 S, Equation ( 8) for H 2 , and Equation ( 9) for NH 3 .
Due to the fact that the amount of CH 4 should represent the highest part of the produced biogas, the minimal allowed fraction of CH 4 in the produced biogas was involved into the constraint function, which is written as Equation (10).Finally, the pH values, which are dynamically computed in dependence of various physico-chemical processes during the AD process [1,6], are limited to be within the allowed interval by Equations ( 11) and ( 12).The constraints (3)-( 7) were defined as follows:

Results and Discussion
The BioModel and the optimization procedure were developed in-house and coded in the C# computer language.The system of differential equations was integrated by the Runge-Kutta method.The utilized optimizer was based on an approximation method [40], which generated a sequence of approximate optimization problems.These approximate problems are strictly convex and separable and can be solved rather efficiently for a sequence of approximate solutions.Since the conservativeness of the approximate objective and constraint functions is adjusted automatically, the solution to the process is usually fast and stable.A gradient-based optimizer clearly needs the design derivatives of the involved functions.Since analytical derivatives cannot be obtained easily and any further AD model updates would invalidate the derived formulas, numerical differentiation using forward differences was used in this work.Numerical differentiation can be computationally quite costly.Therefore, the computation of design derivatives was parallelized.By utilizing parallelization, one full optimization cycle took about 1 min of the processing time on an i7 CPU computer.

Numerical Simulation of the AD Process
The numerical simulation of the AD process was performed using the BioModel, which was thoroughly calibrated and validated in our previous work [1,6].Just to illustrate the performance of the model, a few comparisons of simulated and experimental data are shown in the following.Figure 3 shows the comparison of biogas and CH 4 flow rates, while the pH value as well as H 2 S and H 2 flow rates are shown in Figure 4.The differences between simulated and experimental average values (averaged over the whole period of the AD process) of biogas, CH 4 , H 2 , and H 2 S flow rates are all in the range between 0.6% and 2.2%.Furthermore, the average pH value differs negligibly, that is, less than 0.2%.period of the AD process) of biogas, CH , H , and H S flow rates are all in the range between 0.6% and 2.2%.Furthermore, the average pH value differs negligibly, that is, less than 0.2%.
Note that the AD model used in this work was also rigorously validated [1,6].For example, during validation, the simulated biogas production rate per unit of the bioreactor volume , root mean square error  , coefficient of determination  , and the relative index of agreement  , ) were satisfactory; for example, the relative index of agreement  , was about 0.95 for biogas and CH flow rates and about 0.75 for H and H S flow rates.According to the above discussion, one can reasonably assume that the highly complex BioModel, which involves 184 well-calibrated model parameters, represents a promising foundation for AD process optimization.

Optimization of the AD Process
The numerical optimization process was carefully observed in all considered cases.Numerical instabilities were not observed, and the optimization history was relatively smooth.Furthermore, there were no indications pointing to possible problems related to using finite differences in computing the design derivatives.All considered cases were solved successfully; the number of optimization cycles needed to obtain the optimum values of design variables was 63 in Case A, 47 in Case B, and 45 in Case C.
The prescribed values of limit parameters in the constraint functions were as follows: During optimization, the values of design variables  were allowed to vary between the prescribed lower  and upper  limits.These limits, initial values, and optimal values for Cases A, B, and C are collected in Table 2.The initial values of the concentrations of all microbial groups were determined previously by the calibration of BioModel parameters [1,6].The initial values of the amounts of additives were taken from the actual According to the above discussion, one can reasonably assume that the highly complex BioModel, which involves 184 well-calibrated model parameters, represents a promising foundation for AD process optimization.

Optimization of the AD Process
The numerical optimization process was carefully observed in all considered cases.Numerical instabilities were not observed, and the optimization history was relatively smooth.Furthermore, there were no indications pointing to possible problems related to using finite differences in computing the design derivatives.All considered cases were solved successfully; the number of optimization cycles needed to obtain the optimum values of design variables was 63 in Case A, 47 in Case B, and 45 in Case C.
During optimization, the values of design variables x i were allowed to vary between the prescribed lower x lo i and upper x up i limits.These limits, initial values, and optimal values for Cases A, B, and C are collected in Table 2.The initial values of the concentrations of all microbial groups were determined previously by the calibration of BioModel parameters [1,6].The initial values of the amounts of additives were taken from the actual data of the considered biogas plant.The initial value of temperature was taken as the average temperature in the bioreactor in an observed time period of 365 days.The AD performances obtained with the initial values of design variables (initial state) agree very well with the measured AD performances presented in Figures 3 and 4. With respect to the initial state, the obtained optimal values of the initial concentration of all bacteria were higher by 18%, 0.5%, and 8% in Cases A, B, and C, respectively.Furthermore, optimization delivered the highest differences in the initial concentration of methanogenic acetate degraders (X Mac,in ), followed by the acetogenic valerate degraders (X Ava,in ).With respect to the initial state, the optimized X Mac,in were higher by 87%, 77%, and 28% in Cases A, B, and C, respectively, while the optimized X Ava,in in Cases A, B, and C were higher by 29%, 16%, and 21%, respectively.The highest concentrations were obtained for the methanogenic acetate degraders in Cases A and B, where the objective function is related to biogas production only.
The obtained optimal bacteria composition of biological additive is presented in Figure 5, where the relative abundance of each bacterium as well as each bacteria group is presented.By comparing the relative abundance of each bacterium in the optimal states in Cases A, B, and C with the initial state, the highest differences were observed for methanogenic acetate degraders.The parts of individual bacteria in the acidogens, acetogens, and SRB groups varied within about 5% in all optimization cases.The dom-inant bacteria in the methanogenic group are methanogenic degraders of acetate (Mac), which at an initial state represent 72% of methanogenic bacteria.After optimization, the methanogenic degraders of acetate represent 80%, 82%, and 76% of methanogenic bacteria in Cases A, B, and C, respectively.By comparing the relative abundance of each bacteria group after the optimization, it was evident that the parts of all acidogens and SRB bacteria in all cases were lower than at their initial state, while the parts of all methanogens and acetogens were higher with respect to the initial state.An increase in methanogens and acetogens was expected since methanogens play a key role in biogas production during the AD process, while acetogens are essential to ensure process stability [41].
The obtained optimal bacteria composition of biological additive is presented in Figure 5, where the relative abundance of each bacterium as well as each bacteria group is presented.By comparing the relative abundance of each bacterium in the optimal states in Cases A, B, and C with the initial state, the highest differences were observed for methanogenic acetate degraders.The parts of individual bacteria in the acidogens, acetogens, and SRB groups varied within about 5% in all optimization cases.The dominant bacteria in the methanogenic group are methanogenic degraders of acetate (Mac), which at an initial state represent 72% of methanogenic bacteria.After optimization, the methanogenic degraders of acetate represent 80%, 82%, and 76% of methanogenic bacteria in Cases A, B, and C, respectively.By comparing the relative abundance of each bacteria group after the optimization, it was evident that the parts of all acidogens and SRB bacteria in all cases were lower than at their initial state, while the parts of all methanogens and acetogens were higher with respect to the initial state.An increase in methanogens and acetogens was expected since methanogens play a key role in biogas production during the AD process, while acetogens are essential to ensure process stability [41].The optimal dosages of the Kemira BDP-840 additive were, in all cases, higher than at the initial state (experimental data).This additive promotes biogas production (Case A) The optimal dosages of the Kemira BDP-840 additive were, in all cases, higher than at the initial state (experimental data).This additive promotes biogas production (Case A) as well as lower H 2 S content in the produced biogas (Cases B and C).The optimized dosage of the enzymes provided by the SPF additive is, in all cases, higher than that actually added in the real biogas plant, Figure 6.The optimal dosage of the inorganic additive SPL was the lowest in Case B, followed by Cases C and A. Because of the lowest optimized values of the amount of SPL, it can be concluded that the conditions in the bioreactor in Case B are the most beneficial for the AD process; note that higher concentrations of inorganic additives can inhibit the AD process [14].as well as lower H S content in the produced biogas (Cases B and C).The optimized dosage of the enzymes provided by the SPF additive is, in all cases, higher than that actually added in the real biogas plant, Figure 6.The optimal dosage of the inorganic additive SPL was the lowest in Case B, followed by Cases C and A. Because of the lowest optimized values of the amount of SPL, it can be concluded that the conditions in the bioreactor in Case B are the most beneficial for the AD process; note that higher concentrations of inorganic additives can inhibit the AD process [14].To estimate potential AD performance improvements, the quantity and quality of the produced biogas were analyzed in all cases by considering the impact of temperature, biological and inorganic additives, and their interactions.Some results with the most important findings are presented in the following.
In Cases A, B, and C, AD performances obtained by the optimized values of design variables were compared with those obtained by their initial values (initial state).The biogas flow rate for initial and optimal states is presented in Figure 7.The highest biogas flow rate reached Case A, where it increased by 30%.Meanwhile, in Cases B and C, the biogas production increased by about 14% and 1%, respectively.In Case A, the optimized temperature was increased to 60 °C .This high temperature is the main reason for increased biogas production, which is in accordance with the fact that thermophilic temperature can promote biogas production [4].The high optimized dosage  of the Kemira BDP-840 additive is another important reason for the highest biogas flow rate in Case A [42].In Case B, where H S production was limited, the obtained optimal value To estimate potential AD performance improvements, the quantity and quality of the produced biogas were analyzed in all cases by considering the impact of temperature, biological and inorganic additives, and their interactions.Some results with the most important findings are presented in the following.
In Cases A, B, and C, AD performances obtained by the optimized values of design variables were compared with those obtained by their initial values (initial state).The biogas flow rate for initial and optimal states is presented in Figure 7.The highest biogas flow rate reached Case A, where it increased by 30%.Meanwhile, in Cases B and C, the biogas production increased by about 14% and 1%, respectively.In Case A, the optimized temperature was increased to 60 • C.This high temperature is the main reason for increased biogas production, which is in accordance with the fact that thermophilic temperature can promote biogas production [4].The high optimized dosage c AddKem of the Kemira BDP-840 additive is another important reason for the highest biogas flow rate in Case A [42].In Case B, where H 2 S production was limited, the obtained optimal value of temperature was around 45 • C. In Case C, where the objective was to increase biogas production and reduce the bioreactor heating energy, the obtained optimal temperature was about 25 • C; consequently, the biogas production rate could not increase essentially with respect to the initial state.Anyhow, by optimizing the dosage of biological and inorganic additives, it was possible to preserve the initial biogas production rate while ensuring a substantial decrease in temperature (lower heating cost).The relative biogas production rate (the production rate with respect to bioreactor volume) was 2.41 LL −1 day −1 in Case C, while the highest value of 3.10 LL −1 day −1 was obtained in Case A.  The CH flow rate and CH content in biogas for initial and optimal states are presented in Figure 8.The highest CH production rate and content in biogas were reached in Case C. With respect to the initial state, the CH production rate was higher by 9%, 11%, and 12.5% in Cases A, B, and C, respectively.Figure 8 shows that there was no significant difference in CH flow rates among all three cases, but the content of CH in the produced biogas increased from Case A through Case B to Case C. The obtained results are in agreement with those presented by Cao et al. [43], who demonstrated that the highest content of CH could be reached at mesophilic temperature conditions.The best relative CH production rate of 1.4 LL day was reached in Case C. The H flow rate and H content in biogas for initial and optimal states are presented in Figure 9.The smallest H production was reached in Case C, where the relative H production rate was lower by about 29% with respect to the initial state.With respect to the initial state, the relative H production rate increased by about 11% in Case The CH 4 flow rate and CH 4 content in biogas for initial and optimal states are presented in Figure 8.The highest CH 4 production rate and content in biogas were reached in Case C. With respect to the initial state, the CH 4 production rate was higher by 9%, 11%, and 12.5% in Cases A, B, and C, respectively.Figure 8 shows that there was no significant difference in CH 4 flow rates among all three cases, but the content of CH 4 in the produced biogas increased from Case A through Case B to Case C. The obtained results are in agreement with those presented by Cao et al. [43], who demonstrated that the highest content of CH 4 could be reached at mesophilic temperature conditions.The best relative CH 4 production rate of 1.4 LL −1 day −1 was reached in Case C.  The CH flow rate and CH content in biogas for initial and optimal states are presented in Figure 8.The highest CH production rate and content in biogas were reached in Case C. With respect to the initial state, the CH production rate was higher by 9%, 11%, and 12.5% in Cases A, B, and C, respectively.Figure 8 shows that there was no significant difference in CH flow rates among all three cases, but the content of CH in the produced biogas increased from Case A through Case B to Case C. The obtained results are in agreement with those presented by Cao et al. [43], who demonstrated that the highest content of CH could be reached at mesophilic temperature conditions.The best relative CH production rate of 1.4 LL day was reached in Case C. The H flow rate and H content in biogas for initial and optimal states are presented in Figure 9.The smallest H production was reached in Case C, where the relative H production rate was lower by about 29% with respect to the initial state.With respect to the initial state, the relative H production rate increased by about 11% in Case The H 2 flow rate and H 2 content in biogas for initial and optimal states are presented in Figure 9.The smallest H 2 production was reached in Case C, where the relative H 2 production rate was lower by about 29% with respect to the initial state.With respect to the initial state, the relative H 2 production rate increased by about 11% in Case B and by about 87% in Case A. The highest relative H 2 production rate and the highest H 2 content in the produced biogas are obtained in Case A, where the optimized value of the temperature was the highest, and the optimized additives concentrations led to a low pH value.The obtained results are in agreement with Wang et al. [44], who reported that a thermophilic condition and low pH value lead to a higher hydrogen production rate.The variations in the production of biogas and its compounds at optimal states (Case A, B, and C) with respect to the initial state are presented in Figure 13.It can be seen that the increased biogas production in Case A is a consequence of the increase in all biogas compounds: CH , H , H S, NH , CO , and H O vapour.The main part of the produced biogas is CO .Furthermore, in Case A, the content of H O vapour is the highest (more than 10%), while in Case C, it represents only 3%.This is expected since biogas typically contains 10% by volume of H O vapour at 43 °C , 5% by volume at 32 °C , and 1% by volume at 4.5 °C [45].The constraint related to H S content in Cases B and C also influenced CH production, which increased with respect to CH production in Case A. By further adding constraints related to the contents of CH , H , and NH in the produced biogas (Case C), CH and biogas production increased by 12.3% and 1.1%, while the production of H , H S, and NH was reduced by 28.5%, 19.2%, and 80.9% with respect to the initial state.The variations in the production of biogas and its compounds at optimal states (Case A, B, and C) with respect to the initial state are presented in Figure 13.It can be seen that the increased biogas production in Case A is a consequence of the increase in all biogas compounds: CH , H , H S, NH , CO , and H O vapour.The main part of the produced biogas is CO .Furthermore, in Case A, the content of H O vapour is the highest (more than 10%), while in Case C, it represents only 3%.This is expected since biogas typically contains 10% by volume of H O vapour at 43 °C , 5% by volume at 32 °C , and 1% by volume at 4.5 °C [45].The constraint related to H S content in Cases B and C also influenced CH production, which increased with respect to CH production in Case A. By further adding constraints related to the contents of CH , H , and NH in the produced biogas (Case C), CH and biogas production increased by 12.3% and 1.1%, while the production of H , H S, and NH was reduced by 28.5%, 19.2%, and 80.9% with respect to the initial state.The variations in the production of biogas and its compounds at optimal states (Cases A, B, and C) with respect to the initial state are presented in Figure 13.It can be seen that the increased biogas production in Case A is a consequence of the increase in all biogas compounds: CH 4 , H 2 , H 2 S, NH 3 , CO 2 , and H 2 O vapour.The main part of the produced biogas is CO 2 .Furthermore, in Case A, the content of H 2 O vapour is the highest (more than 10%), while in Case C, it represents only 3%.This is expected since biogas typically contains 10% by volume of H 2 O vapour at 43 • C, 5% by volume at 32 • C, and 1% by volume at 4.5 • C [45].The constraint related to H 2 S content in Cases B and C also influenced CH 4 production, which increased with respect to CH 4 production in Case A. By further adding constraints related to the contents of CH 4 , H 2 , and NH 3 in the produced biogas (Case C), CH 4 and biogas production increased by 12.3% and 1.1%, while the production of H 2 , H 2 S, and NH 3 was reduced by 28.5%, 19.2%, and 80.9% with respect to the initial state.The variations in biogas compounds for optimized states (Case A, B, and C) with respect to the initial state are presented in Figure 14.It is evident that in Case C, the content of desired CH increased by 11.1%, while the contents of undesired H , H S, and NH reduced by 30%, 20%, and 81% when compared to the initial state.The presented results show that temperature, biological additives (bacteria, enzymes), and inorganic additives (which impact the pH value), as well as their interaction, play an important role in the improvement of the AD process.Furthermore, the analysis of the obtained results shows that the optimization of the AD process in Case A delivers maximal biogas production, while the optimization in Case C maximizes the quality of the produced biogas.

Conclusions
This work investigated the suitability and efficiency of coupling a complex BioModel and an approximation-type gradient-based optimization method into a numerical optimization procedure during the AD process.Numerical experience has shown that the proposed approach provides a reliable and stable numerical procedure capable of optimizing the AD process quite efficiently.Moreover, no problems could be observed by engaging a gradient-based optimizer in combination with design derivatives and obtained by finite differences.The variations in biogas compounds for optimized states (Cases A, B, and C) with respect to the initial state are presented in Figure 14.It is evident that in Case C, the content of desired CH 4 increased by 11.1%, while the contents of undesired H 2 , H 2 S, and NH 3 reduced by 30%, 20%, and 81% when compared to the initial state.The variations in biogas compounds for optimized states (Case A, B, and C) with respect to the initial state are presented in Figure 14.It is evident that in Case C, the content of desired CH increased by 11.1%, while the contents of undesired H , H S, and NH reduced by 30%, 20%, and 81% when compared to the initial state.The presented results show that temperature, biological additives (bacteria, enzymes), and inorganic additives (which impact the pH value), as well as their interaction, play an important role in the improvement of the AD process.Furthermore, the analysis of the obtained results shows that the optimization of the AD process in Case A delivers maximal biogas production, while the optimization in Case C maximizes the quality of the produced biogas.

Conclusions
This work investigated the suitability and efficiency of coupling a complex BioModel and an approximation-type gradient-based optimization method into a numerical optimization procedure during the AD process.Numerical experience has shown that the proposed approach provides a reliable and stable numerical procedure capable of optimizing the AD process quite efficiently.Moreover, no problems could be observed by engaging a gradient-based optimizer in combination with design derivatives and obtained by finite differences.The presented results show that temperature, biological additives (bacteria, enzymes), and inorganic additives (which impact the pH value), as well as their interaction, play an important role in the improvement of the AD process.Furthermore, the analysis of the obtained results shows that the optimization of the AD process in Case A delivers maximal biogas production, while the optimization in Case C maximizes the quality of the produced biogas.

Conclusions
This work investigated the suitability and efficiency of coupling a complex BioModel and an approximation-type gradient-based optimization method into a numerical optimization procedure during the AD process.Numerical experience has shown that the proposed approach provides a reliable and stable numerical procedure capable of optimizing the AD process quite efficiently.Moreover, no problems could be observed by engaging a gradient-based optimizer in combination with design derivatives and obtained by finite differences.
The best quality of biogas produced in reasonably large volumes at an acceptable cost can be reached by simultaneously maximizing biogas production and minimizing the heating energy needed.In this context, one must constrain the pH value, the maximal total initial concentrations of bacteria, minimal allowed content of CH 4 and maximal allowed contents of H 2 , H 2 S, and NH 3 in the produced biogas.In such an optimization case, in this work, the content of CH 4 in biogas increased by 11%, while the contents of H 2 , H 2 S, and NH 3 reduced by 30%, 20%, and 81%, respectively; in the optimized system, the bioreactor temperature was 25 • C and the pH value was 7.7.
Since the proposed optimization procedure has shown itself to be numerically stable and efficient, future work should be focused in two directions.Firstly, the AD model should be further improved by considering more precise and various bacterial growth and inhibition models.Secondly, it would be beneficial to widen the AD process's optimization possibilities by including parameters related to the feeding substrate and feeding strategy.

Figure 2 .
Figure 2. Measured fractions of (a) FW, PM, and CS and (b) CM, FM, and W.
(2.31 0.25 LL day ), pH value (7.70 0.02) , the CH content in biogas (54.4 0.88%) , H content (62.11 5.55 ppm) , and H S content (195.8919.92 ppm) were very close to the measured values.All statistical indicators (the mean absolute error

Figure 3 .
Figure 3. Biogas and methane flow rates.Figure 3. Biogas and methane flow rates.

Figure 4 .
Figure 4. Hydrogen and hydrogen sulfide flow rates; pH value.

Figure 4 .
Figure 4. Hydrogen and hydrogen sulfide flow rates; pH value.Note that the AD model used in this work was also rigorously validated[1,6].For example, during validation, the simulated biogas production rate per unit of the bioreactor volume 2.31 ± 0.25 LL −1 day −1 , pH value (7.70 ± 0.02), the CH 4 content in biogas (54.4 ± 0.88%), H 2 content (62.11 ± 5.55 ppm), and H 2 S content (195.89 ± 19.92 ppm) were very close to the measured values.All statistical indicators (the mean absolute error ε MAE , root mean square error ε RMSE , coefficient of determination R 2 , and the relative index of agreement I A,rel ) were satisfactory; for example, the relative index of agreement I A,rel was about 0.95 for biogas and CH 4 flow rates and about 0.75 for H 2 and H 2 S flow rates.According to the above discussion, one can reasonably assume that the highly complex BioModel, which involves 184 well-calibrated model parameters, represents a promising foundation for AD process optimization.

Figure 5 .
Figure 5. Relative abundance of the bacterial community.

Figure 5 .
Figure 5. Relative abundance of the bacterial community.

Figure 7 .
Figure 7. Initial and optimized biogas flow rates.

Figure 8 .
Figure 8.Initial and optimized CH flow rates.

Figure 7 .
Figure 7. Initial and optimized biogas flow rates.

Figure 7 .
Figure 7. Initial and optimized biogas flow rates.

Figure 8 .
Figure 8.Initial and optimized CH flow rates.

Energies 2024 , 18 Figure 9 .
Figure 9.Initial and optimized H flow rates.The H S flow rate and H S content in biogas at initial and optimal states are presented in Figure10.The smallest H S production was reached in Case C. With respect to the initial state, the relative H S production rate was higher by about 114% in Case A and by about 22% in Case B. Only in Case C was the obtained relative H S production rate lower by about 20% when compared to the initial state.The lowest H S content in the produced biogas in Case C is the consequence of the interactions of low temperature and appropriate amounts of biological and inorganic additives, which influenced the pH value favorably.

Figure 10 .
Figure 10.Initial and optimized H S flow rates.The NH flow rate and the NH content in biogas for initial and optimal states are presented in Figure 11.The smallest NH production was reached in Case C. The relative NH production rate increased by about 270% in Case A and by about 43% in Case B with respect to the initial state; only Case C delivered the relative production rate of NH , which was about 80% lower than at the initial state.

Figure 9 . 18 Figure 9 .
Figure 9.Initial and optimized H 2 flow rates.The H 2 S flow rate and H 2 S content in biogas at initial and optimal states are presented in Figure10.The smallest H 2 S production was reached in Case C. With respect to the initial state, the relative H 2 S production rate was higher by about 114% in Case A and by about 22% in Case B. Only in Case C was the obtained relative H 2 S production rate lower by about 20% when compared to the initial state.The lowest H 2 S content in the produced biogas in Case C is the consequence of the interactions of low temperature and appropriate amounts of biological and inorganic additives, which influenced the pH value favorably.

Figure 10 .
Figure 10.Initial and optimized H S flow rates.The NH flow rate and the NH content in biogas for initial and optimal states are presented in Figure 11.The smallest NH production was reached in Case C. The relative NH production rate increased by about 270% in Case A and by about 43% in Case B with respect to the initial state; only Case C delivered the relative production rate of NH , which was about 80% lower than at the initial state.

Figure 10 .
Figure 10.Initial and optimized H 2 S flow rates.The NH 3 flow rate and the NH 3 content in biogas for initial and optimal states are presented in Figure11.The smallest NH 3 production was reached in Case C. The relative NH 3 production rate increased by about 270% in Case A and by about 43% in Case B with respect to the initial state; only Case C delivered the relative production rate of NH 3 , which was about 80% lower than at the initial state.

Figure 11 .
Figure 11.Initial and optimized NH flow rates.A comparison of the simulated pH value during the AD process at initial and optimal states in Cases A, B, C is presented in Figure12.The average pH value during the 365 days of the AD process was 7.7 for the initial design; this value is close to the experimental one.The optimized average pH values were 7.5 in Case A, 7.6 in Case B, and 7.7 in Case C.

Figure 12 .
Figure 12.Initial and optimized pH values.

Figure 11 . 18 Figure 11 .
Figure 11.Initial and optimized NH 3 flow rates.A comparison of the simulated pH value during the AD process at initial and optimal states in Cases A, B, C is presented in Figure12.The average pH value during the 365 days of the AD process was 7.7 for the initial design; this value is close to the experimental one.The optimized average pH values were 7.5 in Case A, 7.6 in Case B, and 7.7 in Case C.

Figure 12 .
Figure 12.Initial and optimized pH values.

Figure 12 .
Figure 12.Initial and optimized pH values.

Figure 13 .
Figure 13.Variations in production of biogas and its compounds.

Figure 14 .
Figure 14.Variation in contents of biogas compounds.

Figure 13 .
Figure 13.Variations in production of biogas and its compounds.

Figure 13 .
Figure 13.Variations in production of biogas and its compounds.

Figure 14 .
Figure 14.Variation in contents of biogas compounds.

Figure 14 .
Figure 14.Variation in contents of biogas compounds.

Table 1 . Composition of substrates in F-CS and the corresponding standards. F-CS PM CS CM FM FW Standard SIST
min − Q NH 3 , and Q CH 4 denote the flow rates of H 2 , NH 3 , and CH 4 , respectively; the symbols φ H 2 ,max and φ NH 3 ,max denote the prescribed maximal contents of H 2 S and NH 3 in biogas, while φ CH 4 ,min represents the minimal allowed part of CH 4 in the produced biogas; the symbols pH min and pH max denote the prescribed minimal and maximal pH values.

Table 2 .
Lower and upper limits, initial, and optimal values of design variables.