MPPT framework based on MPC
Figure 4 shows the MPCbased MPPT framework. The predicted solar radiation and ambient temperature can be obtained from the historical observation data using a nonlinear regression method [3]. Monte Carlo simulations are implemented to generate a series of scenarios to capture the prediction uncertainties of solar radiation and ambient temperature [5]. Thus the fermentation temperature and biogas production rate in each time slot can be obtained from the multidimensional R–C thermodynamic model of the biogas digester and the hydrodynamic model of the hotwater circulation flow based on the prediction scenarios and input parameters.
During the optimization process, the control decision is obtained by solving the optimization problem at the current time while taking into account the uncertainties of solar radiation and ambient temperature of future horizons [29], while only the optimal control decision for the current time k is implemented as the actual control input [30].
Considering the inaccuracy of the predicted outputs obtained from the proposed model, a feedback mechanism is adopted based on the actual outputs of the solarboosted biogas generation system at the current time k to tune the multidimensional R–C thermodynamic model of the biogas digester and the hydrodynamic model of the hotwater circulation flow, as well as the prediction of solar radiation and ambient temperature.
Objective function
The optimization objective aims to minimize the difference between the maximum biogas production and the biogas production at the current time k, as well as the expected biogas production of all remaining future scenarios, which can be formulated as:
$$\min \left\{ {\left( {f_{{{\text{bio}} ,max}} {  }f_{{{\text{bio}} ,k,s}}^{ * } } \right)^{{2}} { + }\sum\limits_{t = k + \Delta k}^{{K_{{\text{end}}} }} {\sum\limits_{s = 1}^{{N_{s} }} {\pi_{s} \left( {f_{{{\text{bio}} ,max}} {  }f_{{{\text{bio}} ,t,s}}^{ * } } \right)^{{2}} } } } \right\}$$
(23)
$$T_{{{\text{d}} ,min}} \le T_{{{\text{d}} ,k}}^{ * } \le T_{{{\text{d}} ,max}}$$
(24)
where \(K_{{{\text{end}}}}\) represents the last time slot of the rolling horizon; \(N_{{\text{s}}}\) represents the total number of scenarios; \(\pi_{{\text{s}}}\) is the probability of scenario s; \(f_{{{\text{bio}},k,s}}\) is the calculated biogas production at time k; and \(f_{{{\text{bio}},{\text{max}}}}\) is the maximum biogas production of the mesophilic fermentation digestion.
System constraints

1.
Solar thermal collector
The flatplate solar collectors have simple mechanical structure and stable performance, and are widely used in household and industrial applications. They usually include a black absorber with a glass cover and insulation. While the glass cover with low iron content can increase light transmittance and reduce radiation loss, the insulation on the back and sides can reduce conduction losses. The plate can absorb and convert solar radiation into useable heat to heat the water up to 90 °C while the thermal efficiency can reach 70%. The useful energy \(E_{{{\text{PT}},k}}\) is calculated based on the energy balance as [31]:
$$E_{PT,k} = G_{PT,k} A_{{\text{s}}} \eta_{{\text{s}}} { = }C_{{{\text{water}} ,k}} Q_{{{\text{PT}},k}} \rho_{{\text{water}}} (T_{{{\text{PT}},k}}  T_{{{\text{out}},k}} )$$
(25)
$$0 \le T_{{{\text{PT}} ,k}} \le T_{{{\text{PT}} ,{\text{max}}}}$$
(26)
$$0 \le Q_{{{\text{PT}} ,k}} \Delta k \le V_{{{\text{PT}} ,{\text{max}}}}$$
(27)
$$U_{{{\text{PT}},\min }} \le U_{{{\text{PT}},k}} \le U_{{{\text{PT}},max}}$$
(28)
where \(G_{{{\text{PT}},k}}\) is the solar radiation at time k; \(A_{{\text{s}}}\) is the lighting area of the collector; \(\eta_{{\text{s}}}\) is the efficiency of the solar collector; \(C_{{{\text{water}}}}\) is the specific heat capacity of the hotwater in the solar thermal collector; \(V_{{{\text{PT}},{\text{max}}}}\) is the rated volume of the collector; \(U_{{{\text{PT}},{\text{min}}}}\) and \(U_{{{\text{PT}},{\text{max}}}}\) are the allowable pressure limits of the collector.

2.
Stratified heat storage tank
Solar energy has significant instability and discontinuity due to the changes of weather and other factors. Storage of solar energy is necessary when the fermentation temperature exceeds the optimal temperature, while the hotwater stored in the tank when the solar radiation intensity is sufficient can provide thermal feedback for the biogas digester in an underlit scene, such as a cloudy day or night.
A natural layered heat storage tank is adopted, and its specific structure is shown in Fig. 1. The tank is directly connected to the solar thermal collector where the outlet and return pipes are located above and below the tank, respectively. The inlet ports of the solar collector and the outlet ports of the biogas tank are located at the high temperature top of the tank whereas the outlet ports of the solar collector and the inlet ports of the biogas tank are located at the low temperature bottom of the tank. The density of water varies with temperature, so the returning water tends to flow up or down to the storage tank because its temperature is significantly different from the temperature at the top and bottom of the tank [32].
Assuming that the heat losses in and out of the water pipe are negligible, the energy balance of the heat storage tank is given as:
$$\begin{gathered} E_{{{\text{res}} ,total,k + 1}} = E_{{{\text{res}} ,total,k}} + E_{{{\text{res}} ,in,k}}  E_{{{\text{res}} ,out,k}}  E_{{{\text{res}} ,{\text{loss}},k}} {\kern 1pt} \hfill \\ \, = E_{{{\text{res}} ,total,k}} + m_{{{\text{res}},k}} C_{{{\text{water}}}} (T_{{{\text{res}} ,k + 1}}  T_{{{\text{res}} ,k}} ) \hfill \\ \end{gathered}$$
(29)
$$E_{{{\text{res}} ,{\text{loss}},k}} {\kern 1pt} = \theta_{{\text{hl}}} A_{{\text{res}}} (T_{{{\text{res}} ,k}}  T_{{{\text{out}} ,k}} )$$
(30)
$$E_{{{\text{res}} ,in,k}} = C_{{\text{water}}} Q_{{{\text{PTr}},k}} \rho_{{\text{water}}} (T_{{{\text{PT}} ,k}}  T_{{{\text{res}} ,k + 1}} )$$
(31)
$$E_{{{\text{res}} ,out,k}} = C_{{\text{water}}} Q_{{{\text{res}} ,out,k}} \rho_{{\text{water}}} (T_{{{\text{res}} ,k}}  T_{{{\text{d}},k + 1}} )$$
(32)
The operating constraints of the tank are:
$$m_{{{\text{res}} ,k + 1}} = m_{{{\text{res}} ,k}} + (Q_{{{\text{PTr}},k}}  Q_{{{\text{res}} ,{\text{out}} ,k}} )\rho_{{\text{water}}} \Delta k$$
(33)
$$E_{{{\text{res}} ,total,\min }} \le E_{res,total,k} \le E_{res,total,max}$$
(34)
$$U_{{{\text{res}} ,{\text{out}},\min }} \le U_{{res,{\text{out}},k}} \le U_{{res,{\text{out,}}max}}$$
(35)
$$U_{{{\text{res}} ,{\text{in}},\min }} \le U_{{\text{res,in,k}}} \le U_{{res,{\text{in,}}max}}$$
(36)
$$U_{{{\text{res}} ,{\text{out}},\min }} \le U_{{res,{\text{out}},k}} \le U_{{res,{\text{out,}}max}}$$
(37)
$$V_{{{\text{res}} ,min}} \rho_{{\text{water}}} \le m_{{{\text{res}} ,k}} \le V_{{{\text{res}} ,max}} \rho_{{\text{water}}}$$
(38)
where \(E_{{{\text{res}},{\text{total}},k}}\) and \(E_{{{\text{res}},{\text{loss}},k}}\) are the total heat and heat loss in the tank at time k, respectively; \(m_{{{\text{res}},k}}\) is the mass of the hotwater in the tank at time k;\({ }A_{{{\text{res}}}}\) is the surface area of the tank; \(E_{{{\text{res}},{\text{in}},k}}\) and \(E_{{{\text{res}},{\text{out}},k}}\) are the inlet and outlet heat in the tank at time k, respectively; \(T_{{{\text{out}},k}}\) is the temperature of the outside of the tank at time k; \(\theta_{{{\text{hl}}}}\) is the heat loss coefficient; \(U_{{{\text{res}},{\text{in}},{\text{min}}}}\), \(U_{{{\text{res}},{\text{in}},{\text{max}}}}\), \(U_{{{\text{res}},{\text{out}},{\text{min}}}}\) and \(U_{{{\text{res}}.{\text{out}},{\text{max}}}}\) are the allowable pressure limits at the inlet and outlet of the tank; \(V_{{{\text{res}},{\text{min}}}}\) and \(V_{{{\text{res}},{\text{max}}}}\) are the lower and upper limits of the hotwater volume, respectively.
Solution method

1.
Problem reformulation
MPPT is a nonlinear programming optimization problem which is difficult to solve directly using existing solvers because of the nonlinear differential thermodynamics and hydrodynamics. In such cases, the thermodynamicsbased R–C thermal network and the hydrodynamic networking model are reformulated to decrease the nonlinearity and computational burden.
As the multidimensional R–C thermal circuit model in (4)–(9) is highly nonlinear, the linearization method of the general nonlinear differential system in [33] is adopted to decrease the nonlinearity of the digesting thermodynamic equations. It has been demonstrated in [33] that this linearization will not result in noticeable error. This is because of the small fermentation temperature range of the biogas digester. Thus, the linearized state space form of the multidimensional R–C thermal model is discretized as:
$${\text{T}}_{k + 1,i} {\text{ = AT}}_{k,i} {\text{ + Bu}}_{k}$$
(39)
where \({\mathbf{T}}_{k,i} = \left[ {T_{{{\text{in}},k,i}} ,T_{{{\text{w}},k,i}} ,T_{{{\text{s}},k,i}} } \right]\) is the state vector representing the nodal temperatures of the R–C thermal model at time k; \({\mathbf{u}}_{k}\) denotes the input vector including solar energy injection and environmental temperature; A and B are the coefficient matrices which can be obtained from the capacitances and resistances of thermal circuital branches.
In order to decrease the nonlinearity of water flows in (10)(14), a linearization method in [5] is applied to linearize the hydrodynamic model of hotwater circulation flow. In Fig. 5, \(Q_{{{\text{d}},k}}\) is selected as an example to illustrate the linearization process. As seen, point O \(\left( {W_{4,k}^{0} ,Q_{{{\text{d}},k}}^{0} } \right)\) represents the base point, around which the hotwater flow equation is linearized, while point A \(\left( {W_{4,k} ,Q_{{{\text{d}},k}} } \right)\) and point B \(\left( {W_{4,k}^{{\text{L}}} ,Q_{{{\text{d}},k}} } \right)\) represent the current operating point and linear prediction point, respectively. \(W_{4,k}\) denotes the squared pressure drop. \(W_{4,k}\) and \(Q_{{{\text{d}},k}}\) are given as:
$$W_{{{4},k}} = U_{{{\text{d}} ,k}}^{{}}  U_{{{\text{val}} ,out,k}}^{{}}$$
(40)
$$Q_{{{\text{d}},k}} = \alpha_{{\text{bp}}} \sqrt {W_{{{4},k}} }$$
(41)
\(W_{4,k}^{{\text{L}}}\) can be obtained from the linearized water flow equations around point O, as:
$$W_{{{4},k}}^{{\text{L}}} = W_{{{4},k}}^{{0}} { + }{{\Delta Q_{{{\text{d}},k}} } \mathord{\left/ {\vphantom {{\Delta Q_{{{\text{d}},k}} } {\frac{{dQ_{{{\text{d}},k}} }}{{dW_{{{4},k}}^{{}} }}\left {_{0} } \right.}}} \right. \kern\nulldelimiterspace} {\frac{{dQ_{{{\text{d}},k}} }}{{dW_{{{4},k}}^{{}} }}\left {_{0} } \right.}}$$
(42)
$$\frac{{dQ_{{{\text{d}},k}} }}{{dW_{{{4},k}}^{{}} }}\left {_{{0}} } \right. = \frac{{\alpha_{4} }}{{2\sqrt {W_{{{4},k}}^{{0}} } }} = \frac{{\alpha_{4}^{2} }}{{2Q_{{{\text{d}},k}}^{0} }}$$
(43)
In addition, the capacitance and resistance parameters of the dynamic models can be derived from [12, 22, 27], and have been validated against the historical data (e.g., digestion temperature, outside temperature, thermal energy for digester heating, etc.) for parameter tuning [3].

2.
Solution procedures
Figure 6 illustrates the flowchart of the proposed MPPT method procedure. In this paper, an MPPT method is proposed to improve the fermentation temperature and biogas yield in extreme climates considering the thermodynamic and hydrodynamic effects, thereby enhancing the flexibility and resilience of the solarboosted biogas generation system. Specifically, for the multidimensional R–C thermal circuit model, the fermentation temperature is determined by all heat changes inside the digester, including the hot water injected into the digester, outside temperature, etc. For the hydrodynamic networking model, the solar water circulation is determined by all pressure changes inside the digester, including the pressure at the throttle valve outlet, heating water from renewables, etc. Based on the reformulated thermodynamicsbased R–C thermal network and the hydrodynamic networking model in Sect. 3.4, the MPCbased MPPT is adopted. The optimization problem is solved every 15 min in a 24h rolling horizon and only the first control step is implemented at the current time k. Considering the inaccuracy of the parameters and prediction data, a feedback mechanism is executed to adjust the control decisions of the next time slot. All the tests are performed via the commercial Matlab platform on a laptop with 1.8GHz Intel Core i7 CPU and 8 GB RAM, and solved with Yalmip solver CPLEX with their default settings. The optimized results of 24 h can be obtained and further analyzed to calculated the system performance index for comparative study.