From Workspace and To Workspace¶
In this demonstration we will describe the specifics of using From Workspace and To Workspace blocks. Our goal is to show how we can feed data into or read data from the model. For this purpose, we have implemented a simple model shown in the figure below.
Next, we will plug in the library needed to form the WorkspaceArray data structure.
First, we will create a DataFrame structure with time and data columns.
After that we create a WorkspaceArray object, the first parameter of which is the internal name of the database, and the second parameter is the data from the DataFrame structure.
using DataFrames
# Задаем данные:
t = [1.0, 2.0, 4.0];
d = rand(Float64, size(t));
df = DataFrame(time=t, value=d)
wa = WorkspaceArray(string(rand()), df)
Let's move on to running our model.
function run_model( name_model, path_to_folder )
Path = path_to_folder * "/" * name_model * ".engee"
if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
model = engee.open( name_model ) # Открыть модель
model_output = engee.run( model, verbose=true ); # Запустить модель
else
model = engee.load( Path, force=true ) # Загрузить модель
model_output = engee.run( model, verbose=true ); # Запустить модель
engee.close( name_model, force=true ); # Закрыть модель
end
return model_output
end
run_model("from_to_workspace", @__DIR__)
At the output we will also get the WorkspaceArray structure. Let's view its fields and compare them with the input data.
dump(out)
data = collect(out)
using Plots
plot(df.time,df.value) # Входные данные
plot!(data.time,data.value) # Выходные данные
As we can see from the comparison, as a result, the data we fed into the model was doubled.
Conclusion¶
We have demonstrated the options for transferring data from the workspace to models and back. These features of the environment greatly simplify your interaction with models.