In this tutorial , We will show how to use Python Create simple but practical digital twins , Lithium ion batteries will be our physical assets . This digital twinning will enable us to analyze and predict battery behavior , And can be integrated into any virtual asset management workflow . We will use Keras Building neural networks , Use plotly mapping .
Digital twins are industrial 4.0 An important part of , Its basic principle is to reproduce physical assets in the virtual world , To simulate its dynamics . Imagine , We have a pump somewhere in the city's water network . The pump consumes energy , Release energy in the form of water flow and pressure . The term " Reappear " It means creating a virtual object that can simulate this behavior .
The pump is connected to the pipeline 、 valve 、 Instruments and other accessories or subsystems , They are all part of the whole water pipe network system . These subsystems are connected to each other . Virtualizing a system requires performing the same work on all subsystems . after , We can simulate the whole system , Including its dependencies . The goal of virtual system is to imitate the physical world , To introduce changes 、 Evaluate performance or predict scenarios involving this asset or subsystem （ For example, in maintenance tasks ）.
As mentioned earlier , Digital twins are virtual objects representing subsystems . This " twin " Should be with " Physical twinning " Respond to input variables in the same way . This virtual object must integrate the model to do this . The most important feature of digital twinning is that the model can simulate " Physics " Behavior . please remember , When we say that " Physics ", We mean any real-world entity （ It can be a lithium ion battery , Water pump , A person , A city or a cat ）. Anything that can be modeled can be virtualized ：
Rechargeable lithium ion battery is a cutting-edge battery technology , Its electrochemistry depends on lithium ion . In addition to portable technical equipment , These batteries are also important assets for applications such as energy storage in electric vehicles and distribution networks . The key aspect of these batteries is their aging cost . After repeated charge and discharge cycle , The battery will deteriorate , Resulting in reduced charging capacity . This phenomenon has always been a key research field in the development of durable batteries . Its modeling is also a controversial topic . Battery degradation has an important impact on the planning and operation of these technologies .
The physical principle of battery life degradation is quite complex . In recent years , Some semi empirical degradation models of lithium ion batteries have been proposed , Used to measure battery life loss . Waste batteries are usually described as providing only their rated maximum capacity 80% The battery . This degradation can be described using the following empirical model ：
among L Is the battery life time ,L’ Is the initial battery life time ,fd Is the linear degradation rate per unit time and period . This rate is the discharge time t 、 Discharge cycle depth δ Of 、 Periodic average state of charge σ And unit temperature Tc Function of ：
Our model must predict the battery life based on the available information . however , We want to compare this model with the measurements made to determine the accuracy of the model . Let's pause here .
Many digital twins are not based on accurate physical models . They only use experimental data sets and machine learning algorithms . It's a cool way to do things . for example , They can use deep neural network models to capture the real dynamics of data . however , Extending this model to other objects requires working with a large number of data sets , In order to obtain a reliable general model . On the other hand , When the physical model works , We need less data to get an accurate general model .
We will use the real data of charge and discharge cycles of lithium-ion batteries to build our digital twin .
We will use NASA's data set （ Lithium ion battery aging data set ）. This data collection comes from NASA Ames The battery prognosis test station built by the Prediction Center （PCoE）. This data set is valuable for determining the accuracy of our physical model and improving its value . We will use batteries 5 Number related data . We're going to draw " Capacity " Function and number of cycles , And compare it with our physical model . Before we start , We'll change the variables L（ Battery life ） Replace with C（ Battery capacity ）. equation 1 Will be written as follows ：
among C Is the battery capacity ,C0 Is the initial battery capacity . about fd, We used the following approximation ：
among i Is the discharge cycle ,tc Battery measured during the cycle cell temperature ,ti Is the discharge time ,k Is an empirical constant , Value taking 0.13.
chart 2 Explain the results . Our model accurately predicts the observed values （ The average absolute error is 0.004）. The model shall collect battery capacity behavior , The capacity decreases slowly in the first cycle , Then accelerate after a certain point . These changes are subtle , Many engineers use simple linear models to approach this behavior . Our model is semi empirical , Including various adjustments , To avoid dealing with partial differential equations .
We can use it directly " Model " Create a digital twin . however , In order to apply machine learning , We will use it to improve the model based on the experimental data of NASA data set . The scheme is shown in the figure below .
We use the experimental data and the output of neural network model to improve the model .
#Define inputs and outputs # input: the simulation capacity X_in = (dfb['C. Capacity']) # output: difference between experimental values and simulation X_out = (dfb['Capacity']) - (dfb['C. Capacity']) X_in_train, X_in_test, X_out_train, X_out_test = train_test_split(X_in, X_out, test_size=0.33)
We use a very simple neural network ：
model = Sequential() model.add(Dense(64, activation='relu', input_shape=(1,))) model.add(Dense(32, activation='relu')) model.add(Dense(1))
epochs = 100 loss = 'mse' model.compile(optimizer = SGD(learning_rate=0.001), loss=loss, metrics=['mae'], #Mean Absolute Error ) history = model.fit(X_in_train, X_out_train, shuffle=True, epochs=epochs, batch_size=20, validation_data=(X_in_test, X_out_test), verbose=1)
Comparison results ：
As we can see in the picture above , The neural network learns the difference between the mathematical model and the experimental results . Now? , We can add this learning to our mathematical model to improve it ：
# Our digital twin by improving our model with experimental data X_twin = X_in + model.predict(X_in).reshape(-1)
Okay , We have digital twins （ Or mixed twins ）：
Final , In our virtual environment, we get a " twin " The battery , Its performance is expected to be similar to that of the actual battery . Next , I want to compare the mathematical model with the mathematical model of digital twins ：
The figure above shows how our digital twins moderately improve our model . The benefits of mixed digital twins are , It enables us to use semi empirical mathematical models , And use the experimental data to improve it . It has advantages over both , Especially the mathematical model , Because it can improve , More general （ Therefore, it can be applied to other batteries to obtain better accuracy than a separate machine learning model ）.
Through our digital twins , Can make predictions , In order to operate Lithium ion battery .
Digital twins are industrial 4.0 An emerging topic in the field . We have shown how to use Python Make the smallest digital twin . When we have experimental data sets , We can show " blend " Digital twins is a more realistic way to virtualize assets . Besides , Less data is needed to develop reliable models .
In the future , You can add more future experimental data to this digital twin , To improve more mathematical models .
Original link ：[Python Actual combat digital twin — BimAnt]http://www.bimant.com/blog/digital-twin-in-python/)