# Energy-Water Management System Based on MPC for a Greenhouse in a Mapuche Indigenous Community
## 5 Model Predictive Control Strategies for the EWMS
### Medium-Term Water Management System  
The water management system supports medium-term irrigation management. Medium-term climate prediction (explained in Section 4.2) is used to obtain predictions of future climate data inside and outside the greenhouse. Then, these predicted data are used to calculate the reference evapotranspiration \(ET_{o}\) from the Penman-Monteith equation [27]:  
\[ET_{o}=\frac{0.408\Delta(k)(R_{n}(k)-G)+\gamma(k)\cdot\frac{C_{n}}{T_{gr}(k)+2 3\gamma}u_{2}(k)\cdot(e_{s}-e_{a})}{\Delta(k)+\gamma(k)(1+C_{d}u_{2}(k))}, \tag{35}\]  
where \(G\) is the soil heat flux, which at a day-scale timestep can be approximated as 0; \(R_{n}(k)\) is the net radiation observed in the greenhouse; \(T_{gr}(k)\) is the mean greenhouse temperature; \(u_{2}(k)\) is the wind speed at a height of 2 m; \(e_{s}(k)\) is the mean saturation vapor pressure; \(e_{a}(k)\) is the actual vapor pressure; \(\Delta\) is the slope of the saturation vapor pressure-temperature relationship; \(\gamma(k)\) is the psychrometric constant; and \(C_{n}\) and \(C_{d}\) are ASCE constants that vary based on the time frame--for a time frame of 1 day, the corresponding values are 900 and 0.34, respectively. With the reference value for evapotranspiration, the following elements can be calculated as:  
\[ET_{p}(k) =K_{c}\cdot ET_{o}(k),\] (36) \[ET_{a}(k) =K_{s}(k)\cdot K_{c}\cdot ET_{o}(k),\] (37) \[K_{s}(k) =\begin{cases}\frac{TAW-D_{r}(k)}{TAW-RAW(k)}\quad\text{if}\quad RAW (k)<D_{r}(k)\\ 1\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad \quad\quad\quad\quad\quad  
while complying with the condition  
\[0\leq D_{r}(k)\leq TAW. \tag{45}\]  
In (41)-(44), \(\theta_{FC}\) and \(\theta_{WP}\) are the field capacity and wilting point, respectively. The field capacity \(\theta_{FC}\) represents the amount of moisture in the soil after the excess water is drained, and the wilting point \(\theta_{WP}\) is the threshold for the amount of moisture at which any plant will wilt. \(\theta_{0}\) is the average soil water content; \(Z_{r}\) is the root depth, estimated through a linear function depending on the crop type; and \(I_{d}(k)\), \(DP(k)\), and \(CR(k)\) are the total irrigation, deep percolation, and capillary rise on day \(k\), respectively. Due to the enclosed nature of the greenhouse, rain and runoff were ignored. \(I(k)\) can be calculated using the irrigation volume \(\bar{V}(k)\) on day \(k\), the planted area \(A\), the irrigation efficiency \(\eta_{r}\), and the soil porosity \(p_{t}\). Based on the equations presented in this subsection for computing evapotranspiration, the system can be used for medium-term irrigation management, and the minimum amount of water necessary to maximize the relative yield \(Y_{r}\) of crops can be determined. To achieve this objective, the predictive controller must maximize  
\[J= Y_{r}-\gamma_{w}V_{r}=\prod_{j=1}^{28}\left[1-K_{y}(k+j)\left(1-\frac{ET_{ a}(k+j)}{\overline{ET}_{p}(k+j)}\right)\right]^{\frac{1}{28}}-\sum_{j=1}^{28} \gamma_{w}\frac{\bar{V}(k+j)}{28\bar{V}_{max}}, \tag{46}\]  
where \(K_{y}(h)\) is the yield response factor, which depends on the stage and crop. The objective function (46) consists of two factors: the relative yield \(Y_{r}\) and the relative water use \(V_{r}\). The relative yield is maximized when the relative evapotranspiration \(ET_{a}\) equals the potential evapotranspiration \(ET_{p}\). The controller can achieve this equality by providing a sufficient volume of water, as expressed in Equations (36)-(41). The second factor \(V_{r}\) is the average of the determined irrigation objectives \(\bar{V}(k)\) divided by the maximum amount of water that the system can use for irrigation in one day \(\bar{V}_{max}\). This maximum value can be determined based on water availability or the designed irrigation scheme. The yield factor is calculated as a geometric average to create a penalty for the lowest values, and the irrigation value is calculated as an arithmetic mean included to minimize total water use.