Reference Models (Model Reference)
In this demo, we will use a simple example to show how to use the Model block in Engee.
The link model technology itself is a link to another model using the Model block. Such models are used to create a hierarchy of the system model. Reference models are ideal for subsystem reuse, unit testing, parallel builds, and large systems.
To implement our demo, we will need two models: the main model and the link model.
In our example, we implemented a counter with two input ports using simple elements that determine the step and maximum counter values.
After that, we can proceed to the development of the main model, in which we will refer to the implemented counter using the Model block.
To connect the model, use the model selection function.
Now, in the file manager window that opens, select the model of the counter we have implemented.
As a result, we have a basic model with a subsystem that is stored in a separate file. With this implementation, we can reuse this counter multiple times within the same project. At the same time, by changing the logic in the reference subsystem, we will apply these changes to all blocks referring to the original model.
Now let's run our model and analyze the correctness of the counter.
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("model", @__DIR__)
We consider the pledged data.
Data = collect(simout["model/Model.Cnt"]);
Let's display the simulation results.
using Plots
plot(Data.time, Data.value, linetype=:steppre)
As we can see from the graph above, the counter actually increments in increments of one, and the maximum value of the counter is 5.
You can add an infinite number of such counters. The example below shows a model with two parallel counters.
In this case, when adding the block again, it is necessary to update the connectors for further work with the duplicate subsystem.
run_model("model_2", @__DIR__)
Data_1 = collect(simout["model_2/Model.Cnt"]);
Data_2 = collect(simout["model_2/Model-1.Cnt"]);
plot(Data_1.time, Data_1.value, linetype=:steppre)
plot!(Data_2.time, Data_2.value, linetype=:steppre)
As we can see, in this case, two counters work in parallel and have different maximum values.
Conclusion
In this example, we have analyzed the possibilities of using link models and shown how to apply them to your projects. This method of system design significantly simplifies the work on projects, as well as reduces the time spent on editing blocks in case of changes to the project.