*2.2. Thermodynamic Model*

To optimize the previous control strategy for a metal-air battery-based UPS, the thermal effect of each cell was modeled for a system of 180 cells per module. The heat in each cell was modeled using the Gibbs potential energy and the voltage from the cell as:

$$Q\_{\rm hant}(t\_k) = I\_{\rm cell}(t\_k)(G\_{\rm zinc} - V\_{\rm cell}(\mathbf{x}(t\_k)))\tag{4}$$

where *Qheat* is the heat, *Icell* is the current in the cell, *Gzinc* is the Gibbs potential of the zinc oxide reaction, *Vcell* is the voltage of the cell, and *tk* is the time at step *k*.

The cooling effect and performance of the fans in each cell were also divided to simulate along with the units. To calculate the heat coefficient on a plate for natural convection, we used the following equations:

$$Nu = \left\{ 0.825 + \frac{0.387 \text{Ra}^{\frac{1}{6}}}{\left[1 + \left(\frac{0.492}{Pr}\right)^{9.16}\right]^{\frac{8}{27}}} \right\}^2 \tag{5}$$

where *Nu* is the Nusselt number, *Ra* is the Rayleigh number for natural convection, and *Pr* is the Prandtl number, and:

$$\mathbf{C}\_{\text{heat}} = \mathbf{K}\_{\text{air}} \ast \frac{\mathbf{N}\mathbf{u}}{\mathbf{L}^\*}, \ \mathbf{L}^\* = \mathbf{L}\_H \times \frac{\mathbf{L}\_W}{2(\mathbf{L}\_H + \mathbf{L}\_W)} \tag{6}$$

where *Cheat* is the heat coefficient of the plate, *Kair* is the thermal conductivity of the air, and *LH* and *LW* are the height and width of the plate, respectively.

A diagram of the stack structure and thermal effect is presented in Figure 1.

**Figure 1.** Schematic of stack structure and thermo-dynamical mechanism.

The thermodynamics of each cell in the UPS module described in Figure 1 are modeled by the following equations:

*Qcase* = *end k*=1 (*Cceil*,*k*·*Aceil*,*k*·Δ*Tceil*,*<sup>k</sup>* + *Cfloor*,*k*·*Afloor*,*k*·<sup>Δ</sup>*Tfloor*,*<sup>k</sup>*) + *Cside*,1·*Aside*,1·Δ*Tside*,<sup>1</sup> + *Cside*,*end*·*Aside*,*end*·Δ*Tside*,*end* (7)

where *Cx*,*<sup>k</sup>* and *Ax*,*<sup>k</sup>* are the thermal conductivity and surface area of area *x* in *k*th cell, respectively; and:

$$T\_{k,t} = T\_{k,t-1} + \frac{d}{dT} \left( Q\_{\text{hant, k}} - Q\_{\text{casc, k}} - Q\_{\text{air}, k} - Q\_{\text{condact nar, k}} \right) \Delta T \tag{8}$$

$$Q\_{\text{conductor}\,\text{non},k} = Q\_{\text{conductor},k-1} + Q\_{\text{conductor},k+1} \tag{9}$$

where *Tk*,*<sup>t</sup>* is the temperature of the *k*th cell at time *t*, *Qcell*,*<sup>k</sup>* is the heat of the chemical reaction, *Qcase*,*<sup>k</sup>* is the (negative) heat of the natural cooling from the aluminum case, *Qair*,*<sup>k</sup>* is the negative heat forced by air-cooling, and *Qconduct near*,*k* is the negative heat caused by conduction to the neighboring cell.

#### *2.3. UPS Simulation and Fan Control*

Many UPS control studies have been conducted on the control of the circuit-level inverter, input, and output current to stabilize the voltage, e.g., [19–21]. Here, we assumed a stable electrical load and supply from the UPS model to the battery model, because our metal-air battery model focused on the power supply at the stack-level and on the operation time for a given electrical load. The main target of this study is the fan flow, which can be controlled during operation to improve the performance which includes operating time and stability of the UPS model. The system used in this study consists of stacked modules, which were modeled using the experimental data of the cell units. Thus, the system is a nonlinear discrete state-space model that can be defined simply as:

$$\mathbf{x}(t+1) = f(\mathbf{x}(t), \mathbf{u}(t)),\\\mathbf{y}(t) = \mathbf{g}(\mathbf{x}(t)). \ t = 1, \ 2, \ 3, \ \dots, \ t\_{\rm{cmd}} \tag{10}$$

Here, *x*(*t*) is the state, *y*(*t*) is the output, *u*(*t*) is the control input, *f* is the modeled system function computing the states of next step by the state of prior step, and *g* is the modeled system function computing the output by the state of this step.

The UPS model consists of a hybrid system that supplies stable electrical power. A lithium-ion battery that operates only initially is always connected to the main power system. A metal-air battery operates as the main source after it starts generating electric energy stably. Here, we developed a strategy to control the module containing the metal-air battery. The metal-air battery module is modeled by electrochemical formulas obtained from experimental data. The formula used to calculate the voltage in the cell is:

$$PV\_{\rm cell}(t\_k) = V\_{\rm acc} \left( \text{SOC}\_{t\_k} \right) \times PV\_{\rm x\_1}(\mathbf{x}\_1(t\_k)) \times PV\_{\rm x\_2}(\mathbf{x}\_2(t\_k)) \times PV\_{\rm xy}(\mathbf{x}\_3(t\_k)) \tag{11}$$

where *Vcell* is the voltage of the cell, *Vsoc* is the voltage output by the state-of-charge, *SOCtk* is the *SOC* on the time step *tk*, and *PVxk* is the voltage fraction in *xk*. Because the variables of the experiment for acquiring the cell data were reduced to three, we set only three state variables to calculate the voltage of the cell.

#### **3. Control Modeling and Simulation**

## *3.1. The Conceptual Framework*

As mentioned above, the target of this research is the optimal control strategy of an UPS system based on metal-air battery. For simulating the system, the model is developed using iteration for time step using discrete calculation. The schematic diagram for controlling the UPS module is shown in Figure 2. The modeling of whole system is coded in Matlab, which is a commercial program from Mathworks (Natick, Massachusetts, USA).

**Figure 2.** Overall view of the UPS model with the proposed receding horizon control (RHC).

## *3.2. Receding Horizon Control*

The receding horizon control (RHC), also known as moving horizon control, is a feedback control strategy for nonlinear or linear plants with input and state constraints [22]. RHC is suitable for slow nonlinear systems, such as chemical processes, that can be solved sequentially [23]. Many studies have investigated UPS using a model predictive control (MPC), which is another name for RHC [24,25].

The typical electrical load for an UPS can be predicted with a few minutes of advance notice. However, predicting the electrical load continuously is unrealistic, because the conditions of environment of the system and the UPS model can change. Thus, it is common to adjust the system loads supplied by the UPS model according to the pre-scenario or situation of the UPS model, so that the electrical load can be predicted for few minutes from the time of operation. Because of this, RHC is applied to the optimal control proposed in this study. Usually, RHC analyzes the model in the prediction window using linear problem (LP) or a quadratic problem (QP). However, the UPS model of this study is composed of tables of the cell data. Therefore, the key to optimal control is to solve the target function within the prediction window. The target applied to the RHC prediction is the electrical load of the UPS in the system, and the state prediction can be expressed as:

$$\mathbf{x}(t\_{k+1} + i | t\_k) = f(\mathbf{x}(t\_{k+1} | t\_k), \mathbf{u}(t\_k + i | t\_k)) \tag{12}$$

$$\lg(t\_k + ilt\_k) = \lg(\mathbf{x}(t\_k + ilt\_k))\tag{13}$$

where *x*(*tk* + *i*|*tk*) is the state value of *x* predicted at time *tk* + *i* using the information available at time *tk*, *x*(*tk*) is the state at time *tk*, *y*(*tk*) is the cost value at time *tk*, and *f*, *g* are the functions for state and cost value, respectively.

The range of *i* (prediction window) at step *s* is <sup>Δ</sup>*Wpredict*,*s*. As seen in Figure 3, the range of optimal control in <sup>Δ</sup>*Wpredict*,*<sup>s</sup>* is set to <sup>Δ</sup>*Wsolver*,*<sup>s</sup>* (i.e., the solver window at step s) as:

$$J\_{s,s+N\_{\rm similar}} = \int\_{t\_k}^{t\_k + \Delta W\_{\rm solar}} g(\mathbf{x}(t|t\_k), \boldsymbol{\mu}(t|t\_k), t|t\_k) dt\_\prime \; \left(\mathcal{N}\_{\rm similar} = \frac{\Delta W\_{\rm solar}}{\Delta t\_{\rm similar}}\right) \tag{14}$$

where *Js*,*s*+*Nsimul* is the cost function of *sth* iteration. The solver means one iteration to solve the optimal control values under state variables.

**Figure 3.** Schematics of the prediction and solver window (Δ*Wsolver*,*k*, <sup>Δ</sup>*Wpredict*,*<sup>k</sup>*) in RHC. These parameters are calculated as recursive structure of RHC. The optimal control values are calculated on <sup>Δ</sup>*Wsolver*,1, <sup>Δ</sup>*Wsolver*,2, ... , <sup>Δ</sup>*Wsolver*,*<sup>k</sup>* within the iteration of <sup>Δ</sup>*Wprediction*,1.

Here, the cost function to be minimized for the metal-air battery-based UPS, *Js*, *s*+*Nsimul* , is the metal (zinc) consumption. In state variable of *x* in Equation (12), the temperature that has a major influence on the performance was included first. The equation to calculate the optimal control in the <sup>Δ</sup>*Wpredict*,*<sup>k</sup>* is:

$$u\_k^\* = \arg\min\_u \left\{ \int\_{t\_k}^{t\_k + \Delta W\_{\text{prdrit},k}} g(\mathbf{x}(t|t\_k), u(t|t\_k), t|t\_k) dt \right\} \quad (\upsilon\_{\text{min}} \le u \le \upsilon\_{\text{max}}) \tag{15}$$

Here, *u*∗*k*is the optimal control at step *k*, *vmin* is the minimum fan flow, and *vmax* its maximum.

Although the optimal control should be calculated in the <sup>Δ</sup>*Wpredict*,*k*, only the optimal control in <sup>Δ</sup>*Wsolver*,*<sup>k</sup>* was applied to the cost function, because in RHC the optimal control should be updated for each Δ*Wsolver*. The cost result and optimal cost are calculated as:

$$J^{RHC} = \sum\_{k=1}^{N\_{\text{total}}} J\_k^\* = \sum\_{k=1}^{N\_{\text{total}}} \int\_{t\_k}^{t\_k + \Delta \mathcal{W}\_{\text{solar}}} g\{\mathbf{x}(t), u\_k^\*(t), t\} dt,\ \mathcal{N}\_{\text{total}} = \frac{\text{Total time}}{\Delta \mathcal{W}\_{\text{solar}}} \tag{16}$$

where *JRHC* is the RHC cost result of the whole simulation, and *J*∗*k* is the optimal cost at step *k*. The prediction window covers the electrical system load needed to operate the RHC for a few minutes. After the UPS starts its operation, it is necessary to estimate the load and control the input in the <sup>Δ</sup>*Wpredict*,*k*.
