# Generic Digital Twin Architecture for Industrial Energy Systems
## 4 Proof-of-Concept: Digital Twin Instantiation
### Use Case: Packed-Bed Thermal Energy Storage
#### 4.3.2 Simulation Service Invocation  
To provide some insights into the capability of our prototypical DT implementation, we show the procedure of loading a dynamic thermal model of the PBTES into the DT, train the model with available data, and use the model for a time-series prediction of the outlet temperature of the PBTES. The previously explained Simulation Service API is used to perform these tasks. The Simulation Service interacts with the Shared Knowledge base in the background to store and retrieve context information. This information is organized using the explained Base Service Ontology and the Simulation Service--Domain Ontology.  
Uploading a Simulation Model--The implemented Simulation Service allows for uploading new simulation models. As mentioned before, a \"Neural Net\" grey box model, which is implemented in Matlab is used. More details about the simulation model can be found in [38]. Figure 7 shows the sequence diagram of the upload process. For uploading a new model, the HTTP POST method is invoked on the endpoint with the URL /upload/model. As a parameter, the Matlab file is included in the HTTP body. The endpoint returns the internal path where the simulation model is stored. This path is needed afterward to access the specific model for training or prediction.  
Uploading a Dataset--The HTTP POST method is used to upload a new dataset by invoking the simulation service's upload/data endpoint. The internal file path is returned in the HTTP response. The returned path is used in order to train a model or to make predictions with the uploaded dataset. The procedure is shown in the sequence diagram in Figure 8.  
Figure 8: Sequence diagram for uploading a model at the service endpoint.  
Figure 7: Sequence diagram for uploading a dataset at the service endpoint.  
Train a Simulation Model--In order to train an uploaded simulation model with an uploaded dataset, the HTTP PUT method is invoked at the Simulation Service endpoint with the URL /train. The HTTP request holds the path to the uploaded training data and the model path as arguments. Additionally, simulation model parameters can also be forwarded as a dictionary. As a result of the training process, a new model description is returned in the JSON format and the information is also stored in the Shared Knowledge base. The old model is archived but can be used for predictions afterwards as well. The sequence is depicted in Figure 9, where just a small fraction of the returned information, formatted in JSON, is shown.  
Make a Prediction--In order to use the Simulation Service for predictions, the endpoint with the URL /predict has to be called using the HTTP GET method. Its arguments are the path to an input dataset and optionally a path to a model. If no path to a model is specified the service uses per default the most recently trained model to make predictions. The service endpoint returns the predictions in a JSON array as shown in Figure 10.  
In the presented use case of the PBTES, the output temperature is predicted by the Simulation Service for a specified input trajectory. The predicted loading cycle of the PBTES over time is shown in Figure 11. These prediction results could further be used for an optimized control strategy performed by the DT.  
Figure 10: Sequence diagram for using a model to predict a time series at simulation endpoint.  
Figure 9: Sequence diagram for training a simulation model at the service endpoint.