Modeling and Simulating a Battery for an Electric Vehicle Based on Modelica

Battery is the key technology to the development of electric vehicles, and most battery models are based on the electric vehicle simulation. In order to accurately study the performance of LiFePO4 batteries, an improved equivalent circuit model was established by analyzing the dynamic characteristics and contrasting different-order models of the battery. Compared to the traditional model, the impact of hysteresis voltage was considered, and the third-order resistance–capacitance (RC) network was introduced to better simulate internal battery polarization. The electromotive force, resistance, capacitance and other parameters were calibrated through battery charge and discharge experiments. This model was built by using Modelica, a modeling language for object-oriented multi-domain physical systems. MWorks was used to implement the cycle conditions and vehicle simulation. The results show that the third-order RC battery model with hysteretic voltage well reflects the dynamics of a LiFePO4 battery. The difference between the simulated and measured voltages is small, with a maximum error of 1.78%, average error of 0.23%. The validity and feasibility of the model are verified. It can be used in unified modeling and simulation of subsequent multi-domain systems of electric vehicles.


Introduction
An electric vehicle (EV) is a complex multi-domain physical system with mechanical, electronic and hydraulic components whose design needs coordinated modeling and simulation in multiple disciplines [1]. At present, there are two commonly used multi-domain modeling methods. One is the interface-based method. This method realizes co-simulation by using professional software in different fields and requires each software to have multi-domain interfaces. However, this leads to great difficulty in joint simulation when there are many design fields. The other method is directly using a unified multi-domain modeling language. This method can directly and clearly describe the coupling between physical systems in different domains, conveniently define interfaces and transfer information between system models in those domains. The simulation results are more reliable, so it has greater advantages and prospects in modeling multi-domain systems. One example is the language Modelica [2], which has been used to model and simulate complex multi-domain physical systems in recent years. Its model library covers electrical, mechanical, thermal, control and many other characteristics, providing a basis for unified description of physical systems [3]. Moreover, Modelica supports objectoriented non-causal modeling, which has standardization, openness and extensibility. Modelica is more accurate and efficient for complex physical modeling [4].
The battery is essential for the power, safety and economy of an EV. A good design of the battery management system improves battery life and ensures cruising range and vehicle safety [5]. The battery model is used to describe the dynamics of battery operation. The model is indispensable to estimate the battery state of charge (SOC) and simulate the battery management system of an EV. It is difficult to model and simulate the battery management process [6]. Generally, a battery model is divided into an electrochemical model, artificial neural network model and equivalent circuit model. The electrochemical model describes the chemical reactions at the molecular level inside the battery, and examples are the Shepherd and Unnewehr models [7,8]. The dynamic behavior of the battery is described by ordinary differential equations for each reaction. To attain proper accuracy with the model, many parameters are used to simulate the battery polarization. Because the electrochemistry of the battery is related to the environmental conditions, it is too complicated to achieve an accurate electrochemical model. Even if a more accurate model can be established under certain conditions, its application to actual working conditions is still limited [9]. An artificial neural network model makes full use of the nonlinear and self-learning characteristics of a neural network and combines experimental data to establish the relationships among various parameters of the battery system. Examples are the BP network and radial basis network [10]. The disadvantage is that a network needs a large amount of experimental data to predict the battery performance. The equivalent circuit model uses the resistance, capacitance, constant voltage source and other circuit elements to simulate battery dynamics. Commonly used equivalent circuit models include the Rint, RC, PNGV (Partnership for a New Generation of Vehicles) and Thevenin models [11]. The RC model only describes the battery polarization using the capacitance and does not reflect the resistance. The PNGV model is a standard model that simulates the complex internal relationships of the battery during charging and discharging, but the complexity of its algorithm makes simulation difficult. The Thevenin model reflects the internal capacitance and resistance of the battery, and its algorithm is relatively simple and easy to implement.
MWorks is a relatively mature simulation platform of Modelica in China. However, its library only has a model for static battery internal resistance and no model that can well describe the dynamic performance of a battery. Zhang et al. [12] established the Simulink model of the second-order RC equivalent circuit. The simulation error based on the Federal Urban Driving Schedule was less than 5%. Huang et al. [13] used Modelica to model the PNGV equivalent circuit with a simulation error of less than 2% relative to bench test results.
Hysteresis can be found according to the mismatch of the charge-discharge equilibrium potential curve of the LiFePO 4 battery. Hysteresis can be found according to the mismatch of the charge-discharge equilibrium potential curve of the LiFePO 4 battery [14][15][16]. However, previous research has rarely considered the hysteresis voltage of the LiFePO 4 battery. To eliminate the simulation error it generates, the mathematical relationship between hysteretic voltage, electromotive force (EMF) and SOC was established in this study. The overpotential errors of different-order RC networks were analyzed, and a more suitable third-order RC network was selected to fit the battery polarization. Compared with previous models, an improved third-order RC battery model with hysteresis voltage was established by using Modelica. The cycle conditions and vehicle simulation were implemented on MWorks. The validity and practicability of the model were fully verified, and it provides more effective unified modeling and simulation of the multi-domain system of the EV.

Dynamic Performance Analysis of a LiFePO 4 Battery
An EV battery is affected by environmental temperature, degree of aging and complex internal chemical reactions. Its characteristics are different under different external conditions, driving conditions and charging and discharging processes. The dynamics of LiFePO 4 batteries can be divided into two aspects: EMF and overpotential. These are described separately in the following sections.

Electromotive Force Characteristic Analysis
EMF refers to the potential difference between positive and negative electrodes when the whole battery system is in equilibrium. The equilibrium potential curves (OCV-SOC curves) for charging and discharging of a LiFePO 4 battery do not coincide, that is, hysteretic voltage exists [17]. To calculate the EMF, it is first necessary to obtain an experimental charge-discharge equilibrium potential curve. Then, using the electrochemical mechanism that produces hysteretic voltage, the EMF can be obtained by weighting the charge-discharge equilibrium potential: The quantities E d and E c represent the equilibrium potentials of the battery discharge and charge, respectively. λ is the weight, and V H is the difference between the charge/ discharge equilibrium potential and EMF. Therefore, the equivalent voltage source can be modeled separately according to the EMF and V H .

Overpotential Characteristic Analysis
During the operation of a LiFePO 4 power battery, the electrode reaction causes the electrode potential to deviate from the equilibrium potential, and the deviation value is the overpotential. The overpotential is mainly manifested in two aspects: the equivalent impedance of the battery and the rebound voltage [17]. The equivalent impedance causes a certain voltage drop when the current passes through the battery. This is externally represented by the equivalent internal resistance of the battery, which is mainly composed of two parts: ohmic resistance and polarization resistance. For a certain battery system, these can be considered to be constant within a particular temperature range and cycle. (1) The rebound voltage is mainly related to the electrolyte conductivity. Because the electrolyte conductivity of a LiFePO 4 battery is low, the electrolytes cannot replenish the lithium ions at a high discharge current, resulting in a voltage drop. When the battery stops discharging, the lithium ions undergo diffusion and phase transition, which causes the entire system to gradually return to equilibrium. The external performance is an orderly rise and fall of the open-circuit voltage, which is voltage rebound.
Generally, the overpotential of a LiFePO 4 battery shows both resistance and capacitance, so it can be realized with an RC network model. As shown in Table 1, the Electric Vehicle Research Center of Sun Yat-sen University has computed the simulation errors of the open-circuit voltage (OCV) relative to the measured values when RC networks with different orders are applied to the LiFePO 4 battery [17]. Because the calculated rebound characteristics of the first-order RC network are far from those of the actual battery, only the errors generated by the second-to fifth-order networks are compared. It can be seen in Table 1 that the higher the order of the RC network, the more accurate the fitting, but the corresponding model complexity is higher. Therefore, after consideration of all factors, a third-order RC network is chosen to represent the overpotential of the LiFePO 4 battery.

Description of LiFePO 4 Battery Model
From the above analysis of LiFePO 4 battery characteristics, the main dynamics considered in this paper include the equivalent voltage source reflecting the hysteresis voltage and the RC network reflecting the overpotential. [12]. A third-order RC battery model with hysteretic voltage was constructed as shown in Fig. 1. The equivalent voltage source E B is composed of controlled voltage sources EMF and V H . The EMF source is controlled by V SOC , which represents the voltage of capacitance C CAP , and its value is equal to SOC. The capacitance C CAP represents the rated capacity of the battery. The controlled source V H represents the battery hysteresis voltage, which is jointly controlled by V SOC and the voltage V LH . The direction of V H is controlled by the voltage V LH across L H . The adjustable inductor L H is used to judge whether the battery was previously charging or discharging. As for the remaining quantities, R 0 represents the ohmic resistance. R 1 , R 2 and R 3 are the polarization resistances, and C 1 , C 2 and C 3 are the polarization capacitances. From Kirchhoff's law, the following mathematical relationships can be obtained for the equivalent circuit.
The formulation of the equivalent voltage source is as follows: Here, The formulation of the equivalent impedance is as follows: The quantity U 0 is the terminal voltage of R 0 . U 1 , U 2 and U 3 are the terminal voltages of the R 1 C 1 , R 2 C 2 and R 3 C 3 series links, respectively. InitialSOC is the initial battery SOC, and the remaining parameters are consistent with those described above.

Modelica Model of LiFePO 4 Battery
To establish a model that is consistent with a real vehicle, this study chose unified modeling based on Modelica to  Fig. 1 and Eqs. (4) and (5), the battery model is established using variable resistor, signal voltage, variable capacitor and other components in the Electrical Component Library of the Modelica Standard Library. In Fig. 2, components a, b, c and d are four table lookup modules, in which a, b and c represent the third-order RC network parameters of the battery model, and d is the hysteretic voltage V H . The battery internal resistance and EMF-related parameters are encapsulated in the core battery module. The model uses current as input, and p and n are the input ports. Then, the voltage and SOC could be obtained as output data to verify the model, as shown in Fig. 2.
In this study, the LiFePO 4 battery provided by the project partner company was used for related experiments.
The rated voltage of the battery is 3.2 V, and the rated capacity is 2.2 Ah. According to the manufacturer guidelines, when the battery is charged to 0.01 C with a constant voltage of 3.7 V at 25 ± 2 °C, it is recorded as 100% SOC. When the battery is discharged to the cutoff voltage of 2.5 V with a constant current of 0.5 A, it is recorded as 0% SOC. Subsequently, the battery SOC is adjusted by charging and discharging with a small current to a node where the battery SOC is 100%, 95%, 90%…… 10%, 5% and 0%. The corresponding OCV is recorded separately after standing for an hour. Figure 3 shows the relationship between charge/discharge OCV and SOC for the LiFePO 4 battery.
The charge/discharge curves in Fig. 3 do not completely overlap. This indicates hysteresis in the LiFePO 4 battery. The hysteresis voltage V H is determined by the electrochemical characteristics of the battery itself. The discharge equilibrium potential is always below the charge equilibrium potential at the same SOC. If the two potentials were not distinguished, the charge/discharge hysteresis voltage would cause a large error in the battery simulation and SOC estimation. Therefore, according to the charge/discharge potential curves and the electrochemical mechanism of the hysteresis voltage, the charge/discharge equilibrium potentials are weighted to obtain the battery EMF using Table 2 and Eq. (4).
As shown in Fig. 4, it is better to model EMF and V H separately and then combine them to achieve accurate test results. In the actual modeling, the battery EMF can be looked up in a table of values obtained from the EMF--SOC curve.

Parameter Estimation of Equivalent Impedance
The hybrid pulse power characterization (HPPC) test was carried out according to the Freedom CAR Battery Test Manual. The discharge current and voltage responses were recorded every 0.5 s to determine model parameters. Table 3 shows the pulse current of an HPPC test. Figure 5 shows the voltage response curve corresponding to pulse discharge.
From the HPPC test voltage curve, it can be concluded that: At the beginning of pulse discharge, the instantaneous vertical drop in voltage is caused by the ohmic internal resistance, so the internal resistance can be obtained via where ΔU 1 is the voltage caused by the ohmic internal resistance at the moment of discharge and I is the discharge current.
After the pulse discharge, the battery terminal voltage rises slowly, which is the voltage rebound. This is equivalent to the zero-input response of the RC network. From this, the following is obtained: where ΔU 2 is the total rebound voltage; U 01 , U 02 and U 03 are the initial polarization voltages; and τ 1 , τ 2 and τ 3 are the time constants of RC networks (τ = RC). The parameters U 01 , U 02 , U 03 , τ 1 , τ 2 and τ 3 need to be determined. The experimental voltage data are fitted with MATLAB to obtain τ 1 , τ 2 and τ 3 .
During the pulse discharge, the slow voltage drop is affected by the battery polarization. The polarization voltage is equivalent to the zero-state response of the RC network, thereby yielding where U(t) is the voltage at any time during the voltage drop; U′ is the starting point after the voltage vertical drop and R 1 , R 2 and R 3 are the parameters to be determined. The experimental voltage data are fitted with MATLAB to obtain R 1 , R 2 and R 3 . Further, the polarization capacitances C 1 , C 2 and C 3 can be obtained via τ 1 = R 1 C 1 , τ 2 = R 2 C 2 and τ 3 = R 3 C 3 .  According to the above, all the model parameters can be calculated:

Battery Simulation Analysis
The model was simulated in Urban Dynamometer Driving Schedule (UDDS) working conditions to verify its accuracy. UDDS working conditions were designed by the U.S. Environmental Protection Agency for light vehicles [19]. Figure 6a shows the battery current as a function of time. The discharge current is the input signal, and the terminal voltage response is the output. The simulated and measured voltage signals are compared in Fig. 6b, where the blue curve is the measured voltage and the red is the simulation. Figure 6c shows the error changes of simulated and measured voltage under UDDS. As shown in Fig. 6c, the error between the simulated and the measured voltage is small. The maximum error is 1.78%, and the average error is 0.23%. These results show that the model can accurately capture the battery dynamics.

Vehicle Simulation Analysis
To further verify the reliability and practicability of the battery model, it was used to simulate a whole electric vehicle.

Modelica Model of Electric Vehicle
The whole vehicle is divided into the power system module, mechanical component module, control module and other accessory modules by means of modular division. The power system module includes the battery pack and motor system. The battery pack is based on the LiFePO 4 battery model established in this paper. The gain module in the Modelica Standard Library is used to form the series-parallel connections required for the battery. The motor system model is based on the permanent magnet synchronous motor (PMSM), which integrates and encapsulates the built motor model and the motor controller. The mechanical component module includes the powertrain, brakes and chassis with wheel and suspension. The powertrain model is based on the vehicle transmission model, which transmits the motor signal to the wheel and suspension of the vehicle chassis through the defined interface under vehicle control. The control module mainly includes the driver control and vehicle control models. The vehicle control model is the key to simulating the vehicle because it realizes input of simulation gives the cyclic road condition in simulation, which is used to simulate the road resistance when the vehicle is running. The atmospheric model mainly refers to the external environmental conditions set when simulating a pure EV, including such factors as the air resistance exerted on the vehicle. Finally, the models were coupled and connected through the defined interfaces between different subject areas, and the multi-domain model of a pure EV was established in MWorks, as shown in Fig. 7. The parameters of the other components are taken from the literature [20][21][22]. Some simulation parameters are shown in Table 4.

Simulation Analysis of Driving Conditions
The vehicle model was simulated under New European Driving Cycle (NEDC) to verify the accuracy of the new battery model. By analyzing the NEDC of the simulation, the battery voltage, current, SOC and vehicle mileage are obtained, as shown in Fig. 8. Figure 8a, b shows the battery voltage and current curves, respectively, when the vehicle is simulated under NEDC. At the beginning, the battery SOC was set to 95%, at which time the voltage was 346.65 V. At the end of the simulation, the voltage dropped to 336.99 V. When the current is positive, the car is accelerating or at constant speed. When the current is negative, the car is in regenerative braking condition, and the battery pack is charged. The trends of the whole voltage and current agree with the dynamic theory of EVs.
As seen in Fig. 8c, the battery SOC decreases from 95 to 86% after the simulation. From Fig. 8d, the driving mileage of the whole simulation is calculated to 10.99 km, which is 0.06 km (0.54%) different from the theoretical driving mileage of 11.05 km. The energy consumption of the whole process is estimated to be 172 Wh/km. The results show that the established battery model has high accuracy and can be used for vehicle simulation tests.

Conclusions
By analyzing the dynamics of a LiFePO 4 battery for an EV, the influence of hysteresis voltage on model accuracy has been considered. A third-order RC network was used to better simulate the polarization inside the battery, and an improved battery model was established by using Modelica. The battery simulation under UDDS was implemented on the MWorks platform. The difference between the simulated and measured voltages is small, with a maximum error of 1.78%, average error of 0.23%. Subsequently, the whole EV system was simulated on the MWorks platform combined with the vehicle model, and the difference between the simulated and theoretical  results is 0.54%. This further verifies the effectiveness and practicability of the battery model. In conclusion, the third-order RC battery model with hysteretic voltage better reflects the dynamics of the LiFePO 4 battery. This battery model can be used to simulate EVs, providing a reference for unified modeling and simulation of their multi-domain systems. Later research will take into account the dynamic relationship between battery model parameters and SOC and consider the influence of temperature, so as to establish a multi-factor battery model, which will further improve the model accuracy.