1 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 object-oriented 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 LiFePO4 battery. Hysteresis can be found according to the mismatch of the charge–discharge equilibrium potential curve of the LiFePO4 battery [14,15,16]. However, previous research has rarely considered the hysteresis voltage of the LiFePO4 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.

2 Dynamic Performance Analysis of a LiFePO4 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 LiFePO4 batteries can be divided into two aspects: EMF and overpotential. These are described separately in the following sections.

2.1 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 LiFePO4 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:

$${\text{Discharge:}}\quad V_{\text{H}} = \lambda (E_{\text{c}} - E_{\text{d}} )$$
(1)
$${\text{Charge:}}\quad V_{\text{H}} = (1 - \lambda )(E_{\text{c}} - E_{\text{d}} )$$
(2)
$${\text{EMF}} = \lambda E_{\text{c}} + (1 - \lambda ) \, E_{\text{d}}$$
(3)

The quantities Ed and Ec represent the equilibrium potentials of the battery discharge and charge, respectively. λ is the weight, and VH 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 VH.

2.2 Overpotential Characteristic Analysis

During the operation of a LiFePO4 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.

The rebound voltage is mainly related to the electrolyte conductivity. Because the electrolyte conductivity of a LiFePO4 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 LiFePO4 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 LiFePO4 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 LiFePO4 battery.

Table 1 Fitting errors of RC networks with different orders

3 Analysis and Modeling of LiFePO4 Battery Model

3.1 Description of LiFePO4 Battery Model

From the above analysis of LiFePO4 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 EB is composed of controlled voltage sources EMF and VH. The EMF source is controlled by VSOC, which represents the voltage of capacitance CCAP, and its value is equal to SOC. The capacitance CCAP represents the rated capacity of the battery. The controlled source VH represents the battery hysteresis voltage, which is jointly controlled by VSOC and the voltage VLH. The direction of VH is controlled by the voltage VLH across LH. The adjustable inductor LH is used to judge whether the battery was previously charging or discharging.

Fig. 1
figure 1

Equivalent circuit model of third-order RC network for LiFePO4 battery

As for the remaining quantities, R0 represents the ohmic resistance. R1, R2 and R3 are the polarization resistances, and C1, C2 and C3 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:

$$\left\{ {\begin{array}{*{20}l} {{\text{EMF}} = f_{1} (V_{\text{SOC}} )} \hfill \\ {V_{\text{H}} = f_{2} (V_{\text{SOC}} ,V_{\text{LH}} )} \hfill \\ {E_{\text{B}} = {\text{EMF}} + V_{\text{H}} } \hfill \\ \end{array} } \right.$$
(4)

Here,

$$V_{\text{SOC}} = {\text{Initial}}\,SOC + \frac{1}{{C_{\text{CAP}} }}\int {I_{\text{B}} {\text{d}}t} .$$

The formulation of the equivalent impedance is as follows:

$$\left\{ {\begin{array}{*{20}l} {C_{1} \cdot \frac{{{\text{d}}U_{1} }}{{{\text{d}}t}} + \frac{{U_{1} }}{{R_{1} }} = I_{\text{B}} } \hfill \\ {C_{2} \cdot \frac{{{\text{d}}U_{2} }}{{{\text{d}}t}} + \frac{{U_{2} }}{{R_{2} }} = I_{\text{B}} } \hfill \\ {C_{3} \cdot \frac{{{\text{d}}U_{3} }}{{{\text{d}}t}} + \frac{{U_{3} }}{{R_{3} }} = I_{\text{B}} } \hfill \\ {U_{0} = I_{\text{B}} R_{0} } \hfill \\ \end{array} } \right.$$
(5)

The quantity U0 is the terminal voltage of R0. U1, U2 and U3 are the terminal voltages of the R1C1, R2C2 and R3C3 series links, respectively. InitialSOC is the initial battery SOC, and the remaining parameters are consistent with those described above.

3.2 Modelica Model of LiFePO4 Battery

To establish a model that is consistent with a real vehicle, this study chose unified modeling based on Modelica to construct complex systems relating different areas. Traditional modeling tends to simulate and analyze the performance of a single domain. Examples are MATLAB and Simulink, where models cannot directly reflect topological relationships. Multi-domain unified modeling based on Modelica is compatible with graph-based modeling and with object-oriented and equation-based non-causal features. Furthermore, it has better simulation effects, such as in MWorks.

According 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 VH. 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.

Fig. 2
figure 2

Modelica model of LiFePO4 battery

3.3 Determination of Model Parameters

3.3.1 Parameter Estimation of Equivalent Voltage Source

The weights are determined sequentially according to Eqs. (1)–(3) and the hysteretic voltage of the LiFePO4 battery [17]. The hysteresis voltage is relatively stable in the platform region (SOC = 0.1~0.9), and the weight can be taken as λ = 0.5 when calculating VH. In the non-platform region (SOC = 0~0.1, 0.9~1), the relationship between the SOC and the weight λ is approximately linear. When VSOC = 0~0.1, λ = 1~0.5, and when VSOC = 0.9~1, λ = 0.5~0 [18].

In this study, the LiFePO4 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 LiFePO4 battery.

Fig. 3
figure 3

Relationships between OCV and SOC in charging and discharging processes for the LiFePO4 battery

The charge/discharge curves in Fig. 3 do not completely overlap. This indicates hysteresis in the LiFePO4 battery. The hysteresis voltage VH 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).

Table 2 Formulas for calculating charge–discharge hysteresis voltage VH and EMF for different SOCs

As shown in Fig. 4, it is better to model EMF and VH 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.

Fig. 4
figure 4

LiFePO4 battery EMF curve

3.3.2 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.

Table 3 HPPC pulse current
Fig. 5
figure 5

Voltage response during the HPPC test

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

$$R_{0} = \Delta U_{1} /I$$
(6)

where ΔU1 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:

$$\Delta U_{2} = U_{1} + U_{2} + U_{3} = U_{01} {\text{e}}^{{ - \frac{t}{{\tau_{1} }}}} + U_{02} {\text{e}}^{{ - \frac{t}{{\tau_{2} }}}} + U_{03} {\text{e}}^{{ - \frac{t}{{\tau_{3} }}}}$$
(7)

where ΔU2 is the total rebound voltage; U01, U02 and U03 are the initial polarization voltages; and τ1, τ2 and τ3 are the time constants of RC networks (τ = RC). The parameters U01, U02, U03, τ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

$$U(t) = U^{{\prime }} - IR_{1} \left( {1 - {\text{e}}^{{ - \frac{t}{{\tau_{1} }}}} } \right) - IR_{2} \left( {1 - {\text{e}}^{{ - \frac{t}{{\tau_{2} }}}} } \right) - IR_{3} \left( {1 - {\text{e}}^{{ - \frac{t}{{\tau_{3} }}}} } \right)$$
(8)

where U(t) is the voltage at any time during the voltage drop; U′ is the starting point after the voltage vertical drop and R1, R2 and R3 are the parameters to be determined. The experimental voltage data are fitted with MATLAB to obtain R1, R2 and R3. Further, the polarization capacitances C1, C2 and C3 can be obtained via τ1 = R1C1, τ2 = R2C2 and τ3 = R3C3.

According to the above, all the model parameters can be calculated:

R0 = 0.03 Ω, R1 = 0.003 Ω, C1 = 43,000 F, R2 = 0.0035 Ω, C2 = 50,000 F, R3 = 0.011 Ω, and C3 = 49,900 F.

4 Simulation and Analysis Based on Battery and Vehicle Models

4.1 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.

Fig. 6
figure 6

Simulation results 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.

4.2 Vehicle Simulation Analysis

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

4.2.1 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 LiFePO4 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 parameters and output of simulation data. The accessory module includes the word model, atmospheric model and road model. The word model mainly provides parameters such as gravitational acceleration for the entire vehicle. The road model mainly describes the basic road information and 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.

Fig. 7
figure 7

EV simulation model

Table 4 Partial list of EV model parameters

4.2.2 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.

Fig. 8
figure 8

Vehicle simulation results under NEDC

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.

5 Conclusions

By analyzing the dynamics of a LiFePO4 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 LiFePO4 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.